Guest User

rc.lua

a guest
Apr 13th, 2012
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.19 KB | None | 0 0
  1. -- Standard awesome library
  2. require("awful")
  3. require("awful.autofocus")
  4. require("awful.rules")
  5. -- Theme handling library
  6. require("beautiful")
  7. -- Notification library
  8. require("naughty")
  9. -- require("tabulous")
  10. -- Widgets library
  11. require("wicked")
  12. require("vicious")
  13.  
  14. os.setlocale(os.getenv("LANG"))
  15. -- {{{ Variable definitions
  16. -- Themes define colours, icons, and wallpapers
  17. -- The default is a dark theme
  18. theme_path = "/home/el-light/.config/awesome/themes/default/theme.lua"
  19. -- Uncommment this for a lighter theme
  20. -- theme_path = "/usr/share/awesome/themes/sky/theme.lua"
  21.  
  22. -- Actually load theme
  23. beautiful.init(theme_path)
  24.  
  25. -- This is used later as the default terminal and editor to run.
  26. terminal = "uxterm"
  27. editor = os.getenv("EDITOR") or "vim"
  28. editor_cmd = terminal .. " -e " .. editor
  29.  
  30. -- Autorun programs
  31. --autorun = true
  32. --autorunApps =
  33. --{
  34. --  "xset b off",
  35. --  "xcompmgr -c -F -f -o.55 &",
  36. --  "xcompmgr -a &",
  37. --}
  38. --if autorun then
  39. --   for app = 1, #autorunApps do
  40. --       awful.util.spawn(autorunApps[app])
  41. --   end
  42. --end
  43.  
  44. -- Default modkey.
  45. -- Usually, Mod4 is the key with a logo between Control and Alt.
  46. -- If you do not like this or do not have such a key,
  47. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  48. -- However, you can use another modifier like Mod1, but it may interact with others.
  49. modkey = "Mod4"
  50.  
  51. -- Table of layouts to cover with awful.layout.inc, order matters.
  52. layouts =
  53. {
  54.     awful.layout.suit.floating,
  55.     awful.layout.suit.tile,
  56.     awful.layout.suit.tile.left,
  57.     awful.layout.suit.tile.bottom,
  58.     awful.layout.suit.tile.top,
  59.     awful.layout.suit.fair,
  60.     awful.layout.suit.fair.horizontal,
  61.     awful.layout.suit.spiral,
  62.     awful.layout.suit.spiral.dwindle,
  63.     awful.layout.suit.max,
  64.     awful.layout.suit.max.fullscreen,
  65.     awful.layout.suit.magnifier
  66. }
  67. -- }}}
  68.  
  69. -- Define if we want to use titlebar on all applications.
  70. use_titlebar = false
  71.  
  72. -- {{{ Tags
  73. tags = {
  74.   names  = { "TERM", "WEB", "FM", "EDT", "DOC", "IM", "GRPH", "MSC", "NIl", },
  75.   layout = { layouts[4], layouts[10], layouts[10], layouts[4], layouts[10], layouts[3], layouts[3], layouts[12], layouts[10]}
  76.   }
  77.  
  78. for s = 1, screen.count() do
  79.     tags[s] = awful.tag(tags.names, s, tags.layout)
  80. end
  81.  
  82. -- }}}
  83.  
  84. -- {{{ Menu
  85. awmenu = {
  86.     { "manual", terminal .. " -e man awesome" },
  87.     { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
  88.     { "restart", awesome.restart },
  89.     { "quit", awesome.quit }
  90. }
  91.  
  92. sysmenu = {
  93. --   { "hibernate", "sudo pm-hibernate" },
  94.    { "reboot", "sudo reboot" },
  95.    { "halt", "sudo halt" }
  96. }
  97.  
  98. mymainmenu = awful.menu.new({ items = {
  99.     { "Firefox", "firefox" },
  100.  
  101. --    { "Gajim", "gajim" },
  102. --    { "Pidgin", "pidgin" },
  103. --
  104. --    { "GVIM", "gvim" },
  105. --    { "Geany", "geany" },
  106. --
  107. --    { "URxvt", "urxvt" },
  108.     { "Xterm", "uxterm" },
  109.     { "ALSA mixer", terminal .. " -e alsamixer" },
  110. --
  111. --    { "DigiKam", "digikam" },
  112.     { "The GIMP", "gimp" },
  113. --
  114. --    { "FBReader", "FBReader" },
  115. --    { "Office", officemenu },
  116. --
  117. --    { "PCmanFM", "pcmanfm" },
  118. ---    { "Skype", "skype" },
  119.  --
  120. --    { "GQView", "gqview" },
  121. --    { "Xcalc", "xcalc" },
  122. --    { "OpenTTD", "openttd" },
  123.     { "Awesome", awmenu },
  124.     { "System", sysmenu }
  125. } })
  126.  
  127. -- }}}
  128.  
  129. -- {{{ Wibox
  130. -- Create a textclock widget
  131. mytextclock = awful.widget.textclock({ align = "right" })
  132.  
  133. -- Spacer and separator
  134. spacer = widget({ type = "textbox"})
  135. separator = widget({ type = "textbox"})
  136. spacer.text = " "
  137. separator.text = " <span color=\"#a8a8a8\">::</span> "
  138.  
  139. ---------------------------------------------------------
  140.  
  141. -- Widgets {{{
  142. -- Create a netwidget
  143. netwidget = widget({ type = "textbox" })
  144. vicious.register(netwidget, vicious.widgets.net, "<span color=\"#FF791F\">UP</span> ${eth0 up_kb}/${wlan0 up_kb} kb/s <span color=\"#FF791F\">DOWN</span> ${eth0 down_kb}/${wlan0 down_kb} kb/s", 1)
  145.  
  146. -- Create a memwidget
  147. memwidget = widget({ type = "textbox" })
  148. vicious.register(memwidget, vicious.widgets.mem, "<span color=\"#FF791F\">MEM</span> $2MB", 3)
  149.  
  150. -- Create a cpuwidget
  151. cpuwidget = widget({ type = "textbox" })
  152. tzswidget = widget({ type = "textbox" })
  153. cpufreqwidget0 = widget({ type = "textbox" })
  154. cpufreqwidget1 = widget({ type = "textbox" })
  155. vicious.register(cpuwidget, vicious.widgets.cpu, "<span color=\"#FF791F\">CPU</span> $1%" , 3)
  156. vicious.register(tzswidget, vicious.widgets.thermal, "<span color=\"#FF791F\">T</span> $1C", 2, "thermal_zone0")
  157. vicious.register(cpufreqwidget0, vicious.widgets.cpufreq, "<span color=\"#FF791F\">F</span> $2/", 1, "cpu0")
  158. vicious.register(cpufreqwidget1, vicious.widgets.cpufreq, "$2 GHz", 1, "cpu1")
  159.  
  160. -- Create a battery state widget
  161. batwidget = widget({ type = "textbox" })
  162. vicious.register(batwidget, vicious.widgets.bat, "<span color=\"#FF791F\">BAT $1</span>$2% <span color=\"#FF791F\">T</span> $3h", 3, "BAT0")
  163.  
  164. -- Create a mpd widget
  165. --mpdwidget = widget({ type = "textbox" })
  166. --vicious.register(mpdwidget, vicious.widgets.mpd, "%state", 3)
  167.   mpdwidget = widget({ type = "textbox" })
  168.   vicious.register(mpdwidget, vicious.widgets.mpd,
  169.     function (widget, args)
  170.       if   args["{state}"] == "Stop" then return "<span color=\"#FF791F\">MPD:</span> Stop"
  171.       else return '<span color=\"#FF791F\">MPD:</span> '..
  172.              args["{Artist}"]..' - '..args["{Title}"]..' : ('..args["{state}"]..')'
  173.       end
  174.     end)
  175.  
  176. --keyboard layout indicator
  177. function get_layout()
  178.     local filedescriptor = io.popen("skb a")
  179.     local value = filedescriptor:read()
  180.     filedescriptor:close()
  181.     return value
  182. end
  183.  
  184. keylayout = widget({type = 'textbox', name="keylayout", align = 'right'})
  185.  
  186. ---------------------------------------------------------
  187. -- }}}
  188.  
  189. -- Create a systray
  190. mysystray = widget({ type = "systray" })
  191.  
  192. -- Create a wibox for each screen and add it
  193. mywibox = {}
  194. mypromptbox = {}
  195. mylayoutbox = {}
  196. mytaglist = {}
  197. mytaglist.buttons = awful.util.table.join(
  198.                     awful.button({ }, 1, awful.tag.viewonly),
  199.                     awful.button({ modkey }, 1, awful.client.movetotag),
  200.                     awful.button({ }, 3, awful.tag.viewtoggle),
  201.                     awful.button({ modkey }, 3, awful.client.toggletag),
  202.                     awful.button({ }, 4, awful.tag.viewnext),
  203.                     awful.button({ }, 5, awful.tag.viewprev)
  204.                     )
  205. mytasklist = {}
  206. mytasklist.buttons = awful.util.table.join(
  207.                      awful.button({ }, 1, function (c)
  208.                                               if not c:isvisible() then
  209.                                                   awful.tag.viewonly(c:tags()[1])
  210.                                               end
  211.                                               client.focus = c
  212.                                               c:raise()
  213.                                           end),
  214.                      awful.button({ }, 3, function ()
  215.                                               if instance then
  216.                                                   instance:hide()
  217.                                                   instance = nil
  218.                                               else
  219.                                                   instance = awful.menu.clients({ width=250 })
  220.                                               end
  221.                                           end),
  222.                      awful.button({ }, 4, function ()
  223.                                               awful.client.focus.byidx(1)
  224.                                               if client.focus then client.focus:raise() end
  225.                                           end),
  226.                      awful.button({ }, 5, function ()
  227.                                               awful.client.focus.byidx(-1)
  228.                                               if client.focus then client.focus:raise() end
  229.                                           end))
  230.  
  231. for s = 1, screen.count() do
  232.     -- Create a promptbox for each screen
  233.     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  234.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  235.     -- We need one layoutbox per screen.
  236.     mylayoutbox[s] = awful.widget.layoutbox(s)
  237.     mylayoutbox[s]:buttons(awful.util.table.join(
  238.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  239.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  240.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  241.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  242.     -- Create a taglist widget
  243.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  244.  
  245.     -- Create a tasklist widget
  246.     mytasklist[s] = awful.widget.tasklist(function(c)
  247.                                               return awful.widget.tasklist.label.currenttags(c, s)
  248.                                           end, mytasklist.buttons)
  249.  
  250.     -- Create the wibox
  251.     mywibox[s] = {}
  252.     mywibox[s][1] = awful.wibox({ position = "top", height = 12, screen = s })  
  253.  
  254.     -- Add widgets to the wibox - order matters
  255.     mywibox[s][1].widgets = {
  256.         {
  257.             mytaglist[s], mypromptbox[s],
  258.             layout = awful.widget.layout.horizontal.leftright
  259.         },  
  260.         mytextclock, spacer, keylayout, spacer, s == 1 and mysystray or nil, mytasklist[s],
  261.             layout = awful.widget.layout.horizontal.rightleft
  262.     }
  263.     -- Create a second wibox
  264.  
  265.      mywibox[s][2] = awful.wibox({ position = "bottom", height = 12, screen = s })  
  266.  
  267.     -- Add widgets to the wibox - order matters
  268.  
  269.         mywibox[s][2].widgets = {
  270.                 {
  271. --              mylayoutbox[s],
  272.                 spacer,
  273.                 mpdwidget,
  274.                 layout = awful.widget.layout.horizontal.leftright
  275.                 },
  276.                 spacer,
  277.                 batwidget,
  278.                 separator,
  279.                 memwidget,
  280.                 separator,
  281.                 cpufreqwidget1,
  282.                 cpufreqwidget0,
  283.                 spacer,
  284.                 tzswidget,
  285.                 spacer,
  286.                 cpuwidget,
  287.                 separator,
  288.                 netwidget,
  289.                 layout = awful.widget.layout.horizontal.rightleft,
  290.     }
  291. end
  292. -- }}}
  293.  
  294. -- Keyboard map indicator and changer
  295.     kbdcfg = {}
  296.     kbdcfg.cmd = "setxkbmap"
  297.     kbdcfg.layout = { { "us", "" }, { "ru", "" } }
  298.     kbdcfg.current = 1  -- us is our default layout
  299.     kbdcfg.widget = widget({ type = "textbox", align = "right" })
  300.     kbdcfg.widget.text = " " .. kbdcfg.layout[kbdcfg.current][1] .. " "
  301.     kbdcfg.switch = function ()
  302.        kbdcfg.current = kbdcfg.current % #(kbdcfg.layout) + 1
  303.        local t = kbdcfg.layout[kbdcfg.current]      
  304.        kbdcfg.widget.text = " " .. t[1] .. " "
  305.        os.execute( kbdcfg.cmd .. " " .. t[1] .. " " .. t[2] )
  306.     end
  307.    
  308. -- {{{ Mouse bindings
  309. root.buttons(awful.util.table.join(
  310.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  311.     awful.button({ }, 4, awful.tag.viewnext),
  312.     awful.button({ }, 5, awful.tag.viewprev)
  313. ))
  314. -- }}}
  315.  
  316. -- {{{ Key bindings
  317. globalkeys = awful.util.table.join(
  318.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  319.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  320.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  321.  
  322.     awful.key({ modkey,           }, "j",
  323.         function ()
  324.             awful.client.focus.byidx( 1)
  325.             if client.focus then client.focus:raise() end
  326.         end),
  327.     awful.key({ modkey,           }, "k",
  328.         function ()
  329.             awful.client.focus.byidx(-1)
  330.             if client.focus then client.focus:raise() end
  331.         end),
  332.     awful.key({ modkey,           }, "w", function () mymainmenu:show(true)        end),
  333.  
  334.     -- Layout manipulation
  335.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  336.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  337.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  338.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  339.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  340.     awful.key({ modkey,           }, "Tab",
  341.         function ()
  342.             awful.client.focus.history.previous()
  343.             if client.focus then
  344.                 client.focus:raise()
  345.             end
  346.         end),
  347.  
  348.     -- Standard program
  349.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  350.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  351.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  352.  
  353.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  354.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  355.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  356.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  357.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  358.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  359.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  360.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  361.     awful.key({ }, "Control", "Shift_R", function () kbdcfg.switch() end),
  362.  
  363.     -- Prompt
  364.     awful.key({ modkey },            "F2",     function () mypromptbox[mouse.screen]:run() end),
  365.  
  366.     awful.key({ modkey }, "x",
  367.               function ()
  368.                   awful.prompt.run({ prompt = "Run Lua code: " },
  369.                   mypromptbox[mouse.screen].widget,
  370.                   awful.util.eval, nil,
  371.                   awful.util.getdir("cache") .. "/history_eval")
  372.               end)
  373. )
  374.  
  375. clientkeys = awful.util.table.join(
  376.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  377.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  378.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  379.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  380.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  381.     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
  382.     awful.key({ modkey,           }, "n",      function (c) c.minimized = not c.minimized    end),
  383.     awful.key({ modkey,           }, "m",
  384.         function (c)
  385.             c.maximized_horizontal = not c.maximized_horizontal
  386.             c.maximized_vertical   = not c.maximized_vertical
  387.         end)
  388. )
  389.  
  390. -- Compute the maximum number of digit we need, limited to 9
  391. keynumber = 0
  392. for s = 1, screen.count() do
  393.    keynumber = math.min(9, math.max(#tags[s], keynumber));
  394. end
  395.  
  396. -- Bind all key numbers to tags.
  397. -- Be careful: we use keycodes to make it works on any keyboard layout.
  398. -- This should map on the top row of your keyboard, usually 1 to 9.
  399. for i = 1, keynumber do
  400.     globalkeys = awful.util.table.join(globalkeys,
  401.         awful.key({ modkey }, "#" .. i + 9,
  402.                   function ()
  403.                         local screen = mouse.screen
  404.                         if tags[screen][i] then
  405.                             awful.tag.viewonly(tags[screen][i])
  406.                         end
  407.                   end),
  408.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  409.                   function ()
  410.                       local screen = mouse.screen
  411.                       if tags[screen][i] then
  412.                           awful.tag.viewtoggle(tags[screen][i])
  413.                       end
  414.                   end),
  415.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  416.                   function ()
  417.                       if client.focus and tags[client.focus.screen][i] then
  418.                           awful.client.movetotag(tags[client.focus.screen][i])
  419.                       end
  420.                   end),
  421.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  422.                   function ()
  423.                       if client.focus and tags[client.focus.screen][i] then
  424.                           awful.client.toggletag(tags[client.focus.screen][i])
  425.                       end
  426.                   end))
  427. end
  428.  
  429. clientbuttons = awful.util.table.join(
  430.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  431.     awful.button({ modkey }, 1, awful.mouse.client.move),
  432.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  433.  
  434. -- Set keys
  435. root.keys(globalkeys)
  436. -- }}}
  437.  
  438. -- {{{ Rules
  439. awful.rules.rules = {
  440.     -- All clients will match this rule.
  441.     { rule = { },
  442.       properties = { border_width = beautiful.border_width,
  443.                      border_color = beautiful.border_normal,
  444.                      focus = true,
  445.                      keys = clientkeys,
  446.                      buttons = clientbuttons } },
  447.     { rule = { class = "MPlayer" },
  448.       properties = { floating = true } },
  449.     { rule = { class = "pinentry" },
  450.       properties = { floating = true } },
  451.     { rule = { class = "GIMP" },
  452.       properties = { floating = true, tag = tags[1][7] } },
  453.      { rule = { class = "Dia" },
  454.       properties = { floating = false, tag = tags[1][7] } },
  455.      { rule = { class = "Gwenview" },
  456.       properties = { tag = tags[1][7] } },  
  457.     { rule = { class = "Krusader" },
  458.       properties = { tag = tags[1][3] } },
  459.     { rule = { class = "uxterm" },
  460.       properties = { floating = false } },
  461.     -- Set Firefox to always map on tags number 2 of screen 1.
  462.     { rule = { class = "Firefox" },
  463.       properties = { tag = tags[1][2] } },
  464.     { rule = { class = "Namoroka" },
  465.       properties = { tag = tags[1][2] } },
  466.     { rule = { class = "psi" },
  467.       properties = { floating = false, tag = tags[1][6] } },
  468.     { rule = { class = "Gmpc" },
  469.       properties = { floating = false, tag = tags[1][8] } },
  470.     { rule = { class = "OpenOffice.org" },
  471.       properties = { tag = tags[1][5] } },
  472. }
  473. -- }}}
  474.  
  475. -- {{{ Signals
  476. -- Signal function to execute when a new client appears.
  477. client.add_signal("manage", function (c, startup)
  478.     -- Add a titlebar
  479.     -- awful.titlebar.add(c, { modkey = modkey })
  480.     c.size_hints_honor = false
  481.     -- Enable sloppy focus
  482.     c:add_signal("mouse::enter", function(c)
  483.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  484.             and awful.client.focus.filter(c) then
  485.             client.focus = c
  486.         end
  487.     end)
  488.  
  489.     if not startup then
  490.         -- Set the windows at the slave,
  491.         -- i.e. put it at the end of others instead of setting it master.
  492.         -- awful.client.setslave(c)
  493.  
  494.         -- Put windows in a smart way, only if they does not set an initial position.
  495.         if not c.size_hints.user_position and not c.size_hints.program_position then
  496.             awful.placement.no_overlap(c)
  497.             awful.placement.no_offscreen(c)
  498.         end
  499.     end
  500. end)
  501.  
  502. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  503. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  504.  
  505. awful.hooks.timer.register(1,  function() keylayout.text = get_layout() end)
  506. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment