Guest User

rc.lua

a guest
Feb 26th, 2012
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.36 KB | None | 0 0
  1. require("awful")
  2. require("awful.autofocus")
  3. require("awful.rules")
  4. require("beautiful")
  5. require("naughty")
  6. require("vicious")
  7. require("bashets")
  8.  
  9. main_color = "#597AFF"
  10.  
  11.  
  12. beautiful.init("/usr/share/awesome/themes/zenburn.lua")
  13. bashets.set_script_path("/home/riso/.config/awesome/")
  14.  
  15. terminal = "urxvt"
  16. editor = os.getenv("EDITOR") or "vim"
  17. editor_cmd = terminal .. " -e " .. editor
  18.  
  19. modkey = "Mod4"
  20. modkey1 = "Multi_key"
  21. awful.font = "trebuchet 8"
  22.  
  23. layouts =
  24. {
  25.     awful.layout.suit.floating,
  26.     awful.layout.suit.tile,
  27.     awful.layout.suit.tile.bottom,
  28.     awful.layout.suit.fair.horizontal,
  29.     awful.layout.suit.max,
  30. }
  31.  
  32. tags = {
  33.     names = { "main", "www", "development", "apps", "skype" },
  34.     layout = { layouts[2], layouts[1], layouts[2], layouts[1], layouts[1] }
  35. }
  36. for s = 1, screen.count() do
  37. tags[s] = awful.tag(tags.names, s, tags.layout)
  38. end
  39.  
  40.  
  41. myawesomemenu = {
  42.    { "manual", terminal .. " -e man awesome" },
  43.    { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
  44.    { "restart", awesome.restart },
  45.    { "quit", awesome.quit }
  46. }
  47.  
  48. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  49.                                     { "open terminal", terminal }
  50.                                   }
  51.                         })
  52.  
  53. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  54.                                      menu = mymainmenu })
  55.  
  56.  
  57.  
  58. -- date --
  59. date = widget({ type = "textbox", name = "date" })
  60. bashets.register("/home/riso/.config/awesome/date.sh", {widget = date})
  61.  
  62.  
  63. -- Volume level
  64. volicon = widget({ type = "imagebox" })
  65. volicon.image = image("/home/riso/.config/awesome/icons/vol.png")
  66. volwidget = widget({ type = "textbox" })
  67. vicious.cache(vicious.widgets.volume)
  68. vicious.register(volwidget, vicious.widgets.volume, " $1%", 2, "Master")
  69.  
  70.  
  71. mygmail = widget({ type = "textbox" })
  72. vicious.register(mygmail, vicious.widgets.gmail, "<span color='#fff'>Mail: ${count} ${subject} </span>", 20)
  73.  
  74.  
  75. appstart = widget({ type = "imagebox" })
  76. appstart.image = image("/home/riso/.config/awesome/icons1/mail.png")
  77. appstart:buttons(awful.util.table.join(      
  78. awful.button({ }, 1, function () awful.util.spawn_with_shell("chromium --app=http://gmail.com")  end)
  79.                 ))
  80. --Icons
  81. cpu_icon = widget({ type = "imagebox" })
  82. cpu_icon.image = image("/home/riso/.config/awesome/icons/cpu.png")
  83.  
  84. mem_icon = widget({ type = "imagebox" })
  85. mem_icon.image = image("/home/riso/.config/awesome/icons/mem.png")
  86.  
  87. fs_icon = widget({ type = "imagebox" })
  88. fs_icon.image = image("/home/riso/.config/awesome/icons/disk.png")
  89.  
  90. vol_icon = widget({ type = "imagebox" })
  91. vol_icon.image = image("/home/riso/.config/awesome/icons/vol.png")
  92.  
  93. -- SPACER --
  94. spacer    = widget({ type = "textbox"  })
  95. spacer1 = widget({ type = "textbox" })
  96. -- SEPARATOR --
  97. separator = widget({ type = "imagebox" })
  98. slash = widget({ type = "textbox" })
  99. slash.text  = "/"
  100. spacer.text     = "  "
  101. spacer1.text    = "  ::  "
  102. separator.image = image(beautiful.widget_sep)
  103.  
  104. -- SPOILER--
  105. spoiler = widget({ type = "textbox"})
  106. spoiler.text = '<span color="'.. main_color ..'"> | </span>'
  107.  
  108.  -- cpu --
  109. cpu = widget({ type = "textbox" })
  110. cpu.width = "40"
  111. vicious.register(cpu, vicious.widgets.cpu, "$1%", 1)
  112.  -- mem --
  113. mem = widget({ type = "textbox" })
  114. vicious.register(mem, vicious.widgets.mem, "$1% ($2MB)", 13)
  115. -- fs_new --
  116. fs_new = widget({ type = "textbox" } )
  117. vicious.register(fs_new, vicious.widgets.fs, "system: ${/ used_gb}GB / ${/ size_gb}GB | D: ${/d used_gb}GB / ${/d size_gb}GB | home: ${/home used_gb}GB / ${/home size_gb}GB")
  118.  
  119. -- Create a systray
  120. mysystray = widget({ type = "systray" })
  121.  
  122. -- Create a wibox for each screen and add it
  123. mywibox = {}
  124. mydownbox = {}
  125. mypromptbox = {}
  126. mylayoutbox = {}
  127. mytaglist = {}
  128. mytaglist.buttons = awful.util.table.join(
  129.                     awful.button({ }, 1, awful.tag.viewonly),
  130.                     awful.button({ modkey }, 1, awful.client.movetotag),
  131.                     awful.button({ }, 3, awful.tag.viewtoggle),
  132.                     awful.button({ modkey }, 3, awful.client.toggletag),
  133.                     awful.button({ }, 4, awful.tag.viewnext),
  134.                     awful.button({ }, 5, awful.tag.viewprev)
  135.                     )
  136. mytasklist = {}
  137. mytasklist.buttons = awful.util.table.join(
  138.                      awful.button({ }, 1, function (c)
  139.                                               if not c:isvisible() then
  140.                                                   awful.tag.viewonly(c:tags()[1])
  141.                                               end
  142.                                               client.focus = c
  143.                                               c:raise()
  144.                                           end),
  145.                      awful.button({ }, 3, function ()
  146.                                               if instance then
  147.                                                   instance:hide()
  148.                                                   instance = nil
  149.                                               else
  150.                                                   instance = awful.menu.clients({ width=250 })
  151.                                               end
  152.                                           end),
  153.                      awful.button({ }, 4, function ()
  154.                                               awful.client.focus.byidx(1)
  155.                                               if client.focus then client.focus:raise() end
  156.                                           end),
  157.                      awful.button({ }, 5, function ()
  158.                                               awful.client.focus.byidx(-1)
  159.                                               if client.focus then client.focus:raise() end
  160.                                           end))
  161.  
  162. for s = 1, screen.count() do
  163.     -- Create a promptbox for each screen
  164.     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  165.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  166.     -- We need one layoutbox per screen.
  167.     mylayoutbox[s] = awful.widget.layoutbox(s)
  168.     mylayoutbox[s]:buttons(awful.util.table.join(
  169.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  170.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  171.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  172.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  173.     -- Create a taglist widget
  174.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  175.  
  176.     -- Create a tasklist widget
  177.     mytasklist[s] = awful.widget.tasklist(function(c)
  178.                                               return awful.widget.tasklist.label.currenttags(c, s)
  179.                                           end, mytasklist.buttons)
  180.  
  181.     -- Create the wibox
  182.     mywibox[s] = awful.wibox({ position = "top", screen = s, height = 17 })
  183.     mydownbox[s] = awful.wibox({ position = "bottom", screen = s, height = 17 })
  184.     -- Add widgets to the wibox - order matters
  185.     mywibox[s].widgets = {
  186.         {
  187.             mylauncher, spacer,
  188.             mytaglist[s],
  189.             mylayoutbox[s], spacer,
  190.             mypromptbox[s],
  191.             layout = awful.widget.layout.horizontal.leftright
  192.       },
  193.        
  194.         spacer, date, spacer1, volwidget, volicon, spacer1,
  195.         s == 1 and mysystray or nil,
  196.         mytasklist[s],
  197.         layout = awful.widget.layout.horizontal.rightleft
  198.     }
  199.    
  200.     mydownbox[s].widgets = {
  201.    
  202.         spacer, cpu, cpu_icon,
  203.     spacer1, mem, mem_icon, spacer1, fs_new, fs_icon, spacer,
  204.    
  205.         { layout = awful.widget.layout.horizontal.leftright, spacer, appstart, spacer, mygmail, },
  206.         layout = awful.widget.layout.horizontal.rightleft,}
  207. end
  208.  
  209. bashets.start()
  210.  
  211.  
  212.  
  213. -- {{{ Mouse bindings
  214. root.buttons(awful.util.table.join(
  215.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  216.     awful.button({ }, 4, awful.tag.viewnext),
  217.     awful.button({ }, 5, awful.tag.viewprev)
  218. ))
  219. -- }}}
  220.  
  221. -- {{{ Key bindings
  222. globalkeys = awful.util.table.join(
  223.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  224.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  225.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  226. -- users --
  227. awful.key({ modkey,               }, "F8",     function () awful.util.spawn("amixer set Master 5dB-") end),
  228. awful.key({ modkey,               }, "F9",     function () awful.util.spawn("amixer set Master 5dB+") end),
  229. awful.key({ modkey, "Shift"       }, "f",      function () awful.util.spawn("firefox") end),
  230. awful.key({ modkey, "Shift"       }, "s",      function () awful.util.spawn("skype") end),
  231. awful.key({ modkey,        }, "Left",       function () awful.util.spawn("ncmpcpp next") end),
  232. awful.key({ modkey,        }, "Right",      function () awful.util.spawn("ncmpcpp prev") end),
  233. awful.key({ modkey,        }, "Down",       function () awful.util.spawn("ncmpcpp stop") end),
  234. awful.key({ modkey,        }, "n",      function () awful.util.spawn("urxvt -e ncmpcpp") end),
  235. awful.key({ modkey,  "Shift"       }, "h",      function () awful.util.spawn("urxvt -e htop") end),
  236. awful.key({ modkey, "Shift"        }, "m",      function () awful.util.spawn("chromium --app=http://gmail.com") end),
  237. awful.key({ modkey,        }, "g",      function () awful.util.spawn("gthumb") end),
  238. awful.key({ modkey,        }, "F4",      function () awful.util.spawn("sudo halt") end),
  239. --awful.key({ modkey1,              }, "F8",     function () awful.util.spawn("amixer set Master 5dB-") end),
  240. --awful.key({ modkey1,              }, "F9",     function () awful.util.spawn("amixer set Master 5dB+") end),
  241.  
  242.     awful.key({ modkey,           }, "j",
  243.         function ()
  244.             awful.client.focus.byidx( 1)
  245.             if client.focus then client.focus:raise() end
  246.         end),
  247.     awful.key({ modkey,           }, "k",
  248.         function ()
  249.             awful.client.focus.byidx(-1)
  250.             if client.focus then client.focus:raise() end
  251.         end),
  252.     awful.key({ modkey,           }, "w", function () mymainmenu:show({keygrabber=true}) end),
  253.  
  254.     -- Layout manipulation
  255.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  256.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  257.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  258.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  259.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  260.     awful.key({ modkey,           }, "Tab",
  261.         function ()
  262.             awful.client.focus.history.previous()
  263.             if client.focus then
  264.                 client.focus:raise()
  265.             end
  266.         end),
  267.  
  268.     -- Standard program
  269.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  270.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  271.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  272.  
  273.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  274.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  275.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  276.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  277.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  278.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  279.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  280.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  281.  
  282.     -- Prompt
  283.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  284.  
  285.     awful.key({ modkey }, "x",
  286.               function ()
  287.                   awful.prompt.run({ prompt = "Run Lua code: " },
  288.                   mypromptbox[mouse.screen].widget,
  289.                   awful.util.eval, nil,
  290.                   awful.util.getdir("cache") .. "/history_eval")
  291.               end)
  292. )
  293.  
  294. clientkeys = awful.util.table.join(
  295.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  296.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  297.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  298.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  299.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  300.     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
  301.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  302.     awful.key({ modkey,           }, "n",      function (c) c.minimized = not c.minimized    end),
  303.     awful.key({ modkey,           }, "m",
  304.         function (c)
  305.             c.maximized_horizontal = not c.maximized_horizontal
  306.             c.maximized_vertical   = not c.maximized_vertical
  307.         end)
  308. )
  309.  
  310. -- Compute the maximum number of digit we need, limited to 9
  311. keynumber = 0
  312. for s = 1, screen.count() do
  313.    keynumber = math.min(9, math.max(#tags[s], keynumber));
  314. end
  315.  
  316. -- Bind all key numbers to tags.
  317. -- Be careful: we use keycodes to make it works on any keyboard layout.
  318. -- This should map on the top row of your keyboard, usually 1 to 9.
  319. for i = 1, keynumber do
  320.     globalkeys = awful.util.table.join(globalkeys,
  321.         awful.key({ modkey }, "#" .. i + 9,
  322.                   function ()
  323.                         local screen = mouse.screen
  324.                         if tags[screen][i] then
  325.                             awful.tag.viewonly(tags[screen][i])
  326.                         end
  327.                   end),
  328.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  329.                   function ()
  330.                       local screen = mouse.screen
  331.                       if tags[screen][i] then
  332.                           awful.tag.viewtoggle(tags[screen][i])
  333.                       end
  334.                   end),
  335.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  336.                   function ()
  337.                       if client.focus and tags[client.focus.screen][i] then
  338.                           awful.client.movetotag(tags[client.focus.screen][i])
  339.                       end
  340.                   end),
  341.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  342.                   function ()
  343.                       if client.focus and tags[client.focus.screen][i] then
  344.                           awful.client.toggletag(tags[client.focus.screen][i])
  345.                       end
  346.                   end))
  347. end
  348.  
  349. clientbuttons = awful.util.table.join(
  350.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  351.     awful.button({ modkey }, 1, awful.mouse.client.move),
  352.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  353.  
  354. -- Set keys
  355. root.keys(globalkeys)
  356. -- }}}
  357.  
  358. -- {{{ Rules
  359. awful.rules.rules = {
  360. size_hints_honor = false,
  361.     -- All clients will match this rule.
  362.     { rule = { },
  363.       properties = { border_width = beautiful.border_width,
  364.                      border_color = beautiful.border_normal,
  365.                      focus = true,
  366.                      keys = clientkeys,
  367.                      buttons = clientbuttons } },
  368.  
  369.     { rule = { class = "gimp" },
  370.     properties = { floating = true } },
  371.  
  372.     { rule = { class = "Firefox"},
  373.     properties = { tag = tags[1][2] } },
  374.  
  375.     { rule = { class = "Gthumb"},
  376.     properties = { tag = tags[1][4], floating = true } },
  377.    
  378.         { rule = { class = "MPlayer" },
  379.       properties = { floating = true } },
  380.  
  381.     {rule = { class = "Download"},
  382.     properties = { floating = true} },
  383.        
  384.     { rule = { class = "feh" },
  385.       properties = { floating = true } },
  386.  
  387.  
  388.     { rule = { class = "Deluge"},
  389.     properties = { floating = true } },
  390.  
  391.     { rule = { class = "Skype"},
  392.     properties = { tag = tags[1][5] } },
  393.     }
  394. -- }}}
  395.  
  396. -- {{{ Signals
  397. -- Signal function to execute when a new client appears.
  398. client.add_signal("manage", function (c, startup)
  399.     c.size_hints_honor = false
  400.     -- Add a titlebar
  401.     -- awful.titlebar.add(c, { modkey = modkey })
  402.  
  403.     -- Enable sloppy focus
  404.     c:add_signal("mouse::enter", function(c)
  405.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  406.             and awful.client.focus.filter(c) then
  407.             client.focus = c
  408.         end
  409.     end)
  410.  
  411.     if not startup then
  412.         -- Set the windows at the slave,
  413.         -- i.e. put it at the end of others instead of setting it master.
  414.         -- awful.client.setslave(c)
  415.  
  416.         -- Put windows in a smart way, only if they does not set an initial position.
  417.         if not c.size_hints.user_position and not c.size_hints.program_position then
  418.             awful.placement.no_overlap(c)
  419.             awful.placement.no_offscreen(c)
  420.         end
  421.     end
  422. end)
  423.  
  424. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  425. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  426. -- }}}
  427. -- Автозапуск
  428. function autostart(dir)
  429.     if not dir then
  430.         do return nil end
  431.     end
  432.     local fd = io.popen("ls -1 -F " .. dir)
  433.     if not fd then
  434.         do return nil end
  435.     end
  436.     for file in fd:lines() do
  437.         local c= string.sub(file,-1)   -- последний символ
  438.         if c=='*' then  -- исполнямые файлы
  439.             executable = string.sub( file, 1,-2 )
  440.             print("Автозапуск Awesome: Запускается: " .. executable)
  441.             awful.util.spawn_with_shell(dir .. "/" .. executable .. "") -- запуск в фоновом режиме
  442.         elseif c=='@' then  -- символьные ссылки
  443.             print("Автозапуск Awesome: Игнорируется символьная ссылка: " .. file)
  444.         else
  445.             print ("Автозапуск Awesome: Игнорируется неисполняемый файл " .. file)
  446.         end
  447.     end
  448.     io.close(fd)
  449. end
  450.  
  451. autostart_dir = os.getenv("HOME") .. "/.config/awesome/autorun"
  452. autostart(autostart_dir)
Advertisement
Add Comment
Please, Sign In to add comment