Advertisement
majorsquirrel

rc.lua

Apr 18th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.93 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. -- Widgets
  10. require("vicious")
  11. -- Colors.lua for Widgets
  12. require("colors")
  13.  
  14. -- {{{ Error handling
  15. -- Check if awesome encountered an error during startup and fell back to
  16. -- another config (This code will only ever execute for the fallback config)
  17. if awesome.startup_errors then
  18.     naughty.notify({ preset = naughty.config.presets.critical,
  19.                      title = "Oops, there were errors during startup!",
  20.                      text = awesome.startup_errors })
  21. end
  22.  
  23. -- Handle runtime errors after startup
  24. do
  25.     local in_error = false
  26.     awesome.add_signal("debug::error", function (err)
  27.         -- Make sure we don't go into an endless error loop
  28.         if in_error then return end
  29.         in_error = true
  30.  
  31.         naughty.notify({ preset = naughty.config.presets.critical,
  32.                          title = "Oops, an error happened!",
  33.                          text = err })
  34.         in_error = false
  35.     end)
  36. end
  37. -- }}}
  38.  
  39. -- {{{ Variable definitions
  40. -- Themes define colours, icons, and wallpapers
  41. beautiful.init("/home/dragon/.config/awesome/themes/default/theme.lua")
  42. -- beautiful.init("~/.config/awesome/theme.lua")
  43. -- This is used later as the default terminal and editor to run.
  44. terminal = "urxvt"
  45. editor = os.getenv("EDITOR") or "vim"
  46. editor_cmd = terminal .. " -e " .. editor
  47.  
  48. -- Default modkey.
  49. -- Usually, Mod4 is the key with a logo between Control and Alt.
  50. -- If you do not like this or do not have such a key,
  51. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  52. -- However, you can use another modifier like Mod1, but it may interact with others.
  53. modkey = "Mod4"
  54.  
  55. -- Table of layouts to cover with awful.layout.inc, order matters.
  56. layouts =
  57. {
  58.     awful.layout.suit.tile,         --1
  59.     awful.layout.suit.tile.left,    --2
  60.     awful.layout.suit.floating,     --3
  61.     awful.layout.suit.tile.bottom,  --4
  62.     awful.layout.suit.tile.top,     --5
  63. }
  64. -- }}}
  65.  
  66. -- {{{ Tags
  67. -- Define a tag table which hold all screen tags.
  68. tags = {}
  69. for s = 1, screen.count() do
  70.     -- Each screen has its own tag table.
  71.     tags[s] = awful.tag({
  72.      "1:web", "2:term", "3:edit", "4:fm", "5:music", "6:files", "7:misc" }, s,
  73.     {layouts[1], layouts[1], layouts[1], -- Tags: 1, 2, 3
  74.      layouts[1], layouts[1], layouts[1], --       4, 5 ,6
  75.      layouts[1], layouts[1], layouts[1]  --       7, 8, 9
  76.     })
  77. end
  78. -- }}}
  79.  
  80. -- {{{ Menu
  81. -- Create a laucher widget and a main menu
  82. myawesomemenu = {
  83.    { "manual", terminal .. " -e man awesome" },
  84.    { "edit config", editor_cmd .. " " .. awesome.conffile },
  85.    { "restart", awesome.restart },
  86.    { "quit", awesome.quit }
  87. }
  88. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  89.                                     { "chrome", "chromium" },
  90.                                     { "files", "thunar" },
  91.                                     { "open terminal", terminal }
  92.                                   }
  93.                         })
  94.  
  95. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  96.                                      menu = mymainmenu })
  97. -- }}}
  98.  
  99. -- {{{ Wibox
  100.  
  101. -- Weather Widget
  102. weatherwidget = widget({ type = "textbox" })
  103. weather_t = awful.tooltip({ objects = { weatherwidget },})
  104.  
  105. vicious.register(weatherwidget, vicious.widgets.weather,
  106.                 function (widget, args)
  107.                     weather_t:set_text("City: " .. args["{city}"] .."\nWind: " .. args["{windmph}"] .. " mp/h " .. args["{wind}"] .. "\nSky: " .. args["{sky}"] .. "\nHumidity: " .. args["{humid}"] .. "%")
  108.                     return args["{tempc}"] .. "C"
  109.                 end, 1800, "CYXD")
  110.                 --'1800': check every 30 minutes.
  111.                 --'CYUL': the Montreal ICAO code.
  112.  
  113. -- Create a textclock widget
  114. mytextclock = awful.widget.textclock({ align = "right" })
  115.  dnicon = widget({ type = "imagebox" })
  116.  upicon = widget({ type = "imagebox" })
  117.  dnicon.image = image(beautiful.widget_net)
  118.  upicon.image = image(beautiful.widget_netup)
  119.  
  120. --Pacman Widget
  121. pacwidget = widget({ type = "textbox"})
  122.     vicious.register(pacwidget, vicious.widgets.pkg,"" .. colbred .. " pacman " .. coldef .. colwhi .. "$1 updates" .. coldef, 1200, "Arch")
  123.  
  124. -- CPU Widget
  125. cpuwidget = widget({ type = "textbox" })
  126.     vicious.register(cpuwidget, vicious.widgets.cpu, "" .. colbblu .. " cpu " .. coldef .. colwhi .. "$1" .. coldef, refresh_delay, "cpu_total")
  127.  
  128. --Battery Widget
  129. batwidget = widget({ type = "textbox" })
  130.     vicious.register(batwidget, vicious.widgets.bat,"" .. colcya .. "bat " .. coldef .. colbwhi .. "$1" .. " " .. "$2" .. "% " .. coldef .. "", 236, "BAT1" )
  131.  
  132. --Volume widget
  133. volwidget = widget({ type = "textbox" })
  134.     vicious.register(volwidget, vicious.widgets.volume,
  135.         function (widget, args)
  136.             if args[1] == 0 or args[2] == "รขโ„ขยฉ" then
  137.                 return "" .. colbcya .. "vol " .. coldef .. colbmag .. "mute" .. coldef .. ""
  138.             else
  139.                 return "" .. colbcya .. "vol " .. coldef .. colbwhi .. args[1] .. "% " .. coldef .. ""
  140.             end
  141.         end, 2, "Master" )
  142.     volwidget:buttons(
  143.         awful.util.table.join(
  144.             awful.button({ }, 1, function () awful.util.spawn("amixer -q sset Master toggle &")   end),
  145.             awful.button({ }, 3, function () awful.util.spawn( terminal .. " -e alsamixer")   end),
  146.             awful.button({ }, 4, function () awful.util.spawn("amixer -q sset Master 1%+ &") end),
  147.             awful.button({ }, 5, function () awful.util.spawn("amixer -q sset Master 1%- &") end)
  148.         )
  149.     )
  150.  
  151. --Wifi Widget
  152. wifiwidget = widget({ type = "textbox" })
  153.     vicious.register(wifiwidget, vicious.widgets.wifi, "" .. colbgre .. " wlan " .. coldef .. colwhi .. "${ssid}" .. ": " .. "${linp}" .. "%" .. coldef, refresh_delay, "wlan0")
  154.  
  155. -- MEM widget
  156. memwidget = widget({ type = "textbox" })
  157.     vicious.register(memwidget, vicious.widgets.mem, "" .. colbyel .. " mem " .. coldef .. colwhi .. "$1" .. coldef, refresh_delay, "MemTotal")
  158.  
  159. -- MPD Icon
  160. mpdicon = widget({ type = "imagebox" })
  161. mpdicon.image = image(beautiful.widget_mpd)
  162. -- Initialize MPD Widget
  163. mpdwidget = widget({ type = "textbox" })
  164. vicious.register(mpdwidget, vicious.widgets.mpd,
  165.     function (widget, args)
  166.         if args["{state}"] == "Stop" then
  167.             return " - "
  168.         else
  169.             return args["{Artist}"]..' - '.. args["{Title}"]
  170.         end
  171.     end, 10)
  172.  
  173. -- Spacers
  174. rbracket = widget({type = "textbox" })
  175. rbracket.text = "]"
  176. lbracket = widget({type = "textbox" })
  177. lbracket.text = "["
  178.  
  179. -- Separator
  180. separator = widget({ type = "textbox" })
  181. separator.text  = " :: "
  182.  
  183. -- Space
  184. space = widget({ type = "textbox" })
  185. space.text = " "
  186.  
  187. -- Create a systray
  188. mysystray = widget({ type = "systray" })
  189.  
  190. -- Create a wibox for each screen and add it
  191. mywibox = {}
  192. mybottomwibox = {}
  193. mystatusbar = {}
  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 c == client.focus then
  209.                                                   c.minimized = true
  210.                                               else
  211.                                                   if not c:isvisible() then
  212.                                                       awful.tag.viewonly(c:tags()[1])
  213.                                                   end
  214.                                                   -- This will also un-minimize
  215.                                                   -- the client, if needed
  216.                                                   client.focus = c
  217.                                                   c:raise()
  218.                                               end
  219.                                           end),
  220.                      awful.button({ }, 3, function ()
  221.                                               if instance then
  222.                                                   instance:hide()
  223.                                                   instance = nil
  224.                                               else
  225.                                                   instance = awful.menu.clients({ width=250 })
  226.                                               end
  227.                                           end),
  228.                      awful.button({ }, 4, function ()
  229.                                               awful.client.focus.byidx(1)
  230.                                               if client.focus then client.focus:raise() end
  231.                                           end),
  232.                      awful.button({ }, 5, function ()
  233.                                               awful.client.focus.byidx(-1)
  234.                                               if client.focus then client.focus:raise() end
  235.                                           end))
  236.  
  237. for s = 1, screen.count() do
  238.     -- Create a promptbox for each screen
  239.     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  240.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  241.     -- We need one layoutbox per screen.
  242.     mylayoutbox[s] = awful.widget.layoutbox(s)
  243.     mylayoutbox[s]:buttons(awful.util.table.join(
  244.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  245.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  246.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  247.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  248.     -- Create a taglist widget
  249.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  250.  
  251.     -- Create a tasklist widget
  252.     mytasklist[s] = awful.widget.tasklist(function(c)
  253.                                               return awful.widget.tasklist.label.currenttags(c, s)
  254.                                           end, mytasklist.buttons)
  255.  
  256.     -- Create the upper wibox
  257.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  258.     -- Add widgets to the wibox - order matters
  259.     mywibox[s].widgets = {
  260.         {
  261.             mylauncher,
  262.             mytaglist[s],
  263.             mypromptbox[s],
  264.             layout = awful.widget.layout.horizontal.leftright
  265.         },
  266.         mylayoutbox[s],
  267.     mytextclock,
  268.     weatherwidget,
  269.         space,
  270.         s == 1 and mysystray or nil,
  271.         mytasklist[s],
  272.         layout = awful.widget.layout.horizontal.rightleft
  273.     }
  274.      mybottomwibox[s] = awful.wibox({ position = "bottom", screen = s, border_width = 0, height = 18 })
  275.  
  276.      mybottomwibox[s].widgets = {
  277.      {
  278.         space, lbracket, space, cpuwidget, space, rbracket, space, lbracket, space, memwidget, space, rbracket, space, lbracket, space, batwidget, space, rbracket, space, lbracket, space, wifiwidget, space, rbracket, space, lbracket, space, pacwidget, space, rbracket,
  279.         layout = awful.widget.layout.horizontal.leftright
  280.      },
  281.      rbracket, space, mpdwidget, space, lbracket, rbracket, space, volwidget, space, lbracket,  
  282.         layout = awful.widget.layout.horizontal.rightleft
  283.       }
  284.    end
  285.  
  286. -- }}}
  287.  
  288. -- {{{ Mouse bindings
  289. root.buttons(awful.util.table.join(
  290.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  291.     awful.button({ }, 4, awful.tag.viewnext),
  292.     awful.button({ }, 5, awful.tag.viewprev)
  293. ))
  294. -- }}}
  295.  
  296. -- {{{ Key bindings
  297. globalkeys = awful.util.table.join(
  298.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  299.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  300.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  301.  
  302.     awful.key({ modkey,           }, "j",
  303.         function ()
  304.             awful.client.focus.byidx( 1)
  305.             if client.focus then client.focus:raise() end
  306.         end),
  307.     awful.key({ modkey,           }, "k",
  308.         function ()
  309.             awful.client.focus.byidx(-1)
  310.             if client.focus then client.focus:raise() end
  311.         end),
  312.     awful.key({ modkey,           }, "w", function () mymainmenu:show({keygrabber=true}) end),
  313.  
  314.     -- Layout manipulation
  315.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  316.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  317.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  318.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  319.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  320.     awful.key({ modkey,           }, "Tab",
  321.         function ()
  322.             awful.client.focus.history.previous()
  323.             if client.focus then
  324.                 client.focus:raise()
  325.             end
  326.         end),
  327.  
  328.     -- Volume Keys
  329.     awful.key({ }, "XF86AudioRaiseVolume", function ()
  330.        awful.util.spawn("amixer set Master 5%+") end),
  331.    awful.key({ }, "XF86AudioLowerVolume", function ()
  332.        awful.util.spawn("amixer set Master 5%-") end),
  333.    awful.key({ }, "XF86AudioMute", function ()
  334.        awful.util.spawn("amixer set Master toggle") end),
  335.  
  336.     -- Standard program
  337.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  338.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  339.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  340.  
  341.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  342.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  343.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  344.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  345.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  346.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  347.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  348.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  349.  
  350.     awful.key({ modkey, "Control" }, "n", awful.client.restore),
  351.  
  352.     -- Prompt
  353.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  354.  
  355.     awful.key({ modkey }, "x",
  356.         function ()
  357.                   awful.prompt.run({ prompt = "Run Lua code: " },
  358.                   mypromptbox[mouse.screen].widget,
  359.                   awful.util.eval, nil,
  360.                   awful.util.getdir("cache") .. "/history_eval")
  361.               end)
  362. )
  363.  
  364. clientkeys = awful.util.table.join(
  365.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  366.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  367.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  368.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  369.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  370.     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
  371.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  372.     awful.key({ modkey,           }, "n",
  373.         function (c)
  374.             -- The client currently has the input focus, so it cannot be
  375.             -- minimized, since minimized clients can't have the focus.
  376.             c.minimized = true
  377.         end),
  378.     awful.key({ modkey,           }, "m",
  379.         function (c)
  380.             c.maximized_horizontal = not c.maximized_horizontal
  381.             c.maximized_vertical   = not c.maximized_vertical
  382.         end)
  383. )
  384.  
  385. -- Compute the maximum number of digit we need, limited to 9
  386. keynumber = 0
  387. for s = 1, screen.count() do
  388.    keynumber = math.min(9, math.max(#tags[s], keynumber));
  389. end
  390.  
  391. -- Bind all key numbers to tags.
  392. -- Be careful: we use keycodes to make it works on any keyboard layout.
  393. -- This should map on the top row of your keyboard, usually 1 to 9.
  394. for i = 1, keynumber do
  395.     globalkeys = awful.util.table.join(globalkeys,
  396.         awful.key({ modkey }, "#" .. i + 9,
  397.                   function ()
  398.                         local screen = mouse.screen
  399.                         if tags[screen][i] then
  400.                             awful.tag.viewonly(tags[screen][i])
  401.                         end
  402.                   end),
  403.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  404.                   function ()
  405.                       local screen = mouse.screen
  406.                       if tags[screen][i] then
  407.                           awful.tag.viewtoggle(tags[screen][i])
  408.                       end
  409.                   end),
  410.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  411.                   function ()
  412.                       if client.focus and tags[client.focus.screen][i] then
  413.                           awful.client.movetotag(tags[client.focus.screen][i])
  414.                       end
  415.                   end),
  416.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  417.                   function ()
  418.                       if client.focus and tags[client.focus.screen][i] then
  419.                           awful.client.toggletag(tags[client.focus.screen][i])
  420.                       end
  421.                   end))
  422. end
  423.  
  424. clientbuttons = awful.util.table.join(
  425.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  426.     awful.button({ modkey }, 1, awful.mouse.client.move),
  427.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  428.  
  429. -- Set keys
  430. root.keys(globalkeys)
  431. -- }}}
  432.  
  433. -- {{{ Rules
  434. awful.rules.rules = {
  435.     -- All clients will match this rule.
  436.     { rule = { },
  437.       properties = { border_width = beautiful.border_width,
  438.                      border_color = beautiful.border_normal,
  439.                      focus = true,
  440.              size_hints_honor = false,
  441.                      keys = clientkeys,
  442.                      buttons = clientbuttons } },
  443.     { rule = { class = "MPlayer" },
  444.       properties = { floating = true } },
  445.     { rule = { class = "pinentry" },
  446.       properties = { floating = true } },
  447.     { rule = { class = "gimp" },
  448.       properties = { floating = true } },
  449.     -- Set Firefox to always map on tags number 2 of screen 1.
  450.     -- { rule = { class = "Firefox" },
  451.     --   properties = { tag = tags[1][2] } },
  452. }
  453. -- }}}
  454.  
  455. -- {{{ Signals
  456. -- Signal function to execute when a new client appears.
  457. client.add_signal("manage", function (c, startup)
  458.     -- Add a titlebar
  459.     -- awful.titlebar.add(c, { modkey = modkey })
  460.  
  461.     -- Enable sloppy focus
  462.     c:add_signal("mouse::enter", function(c)
  463.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  464.             and awful.client.focus.filter(c) then
  465.             client.focus = c
  466.         end
  467.     end)
  468.  
  469.     if not startup then
  470.         -- Set the windows at the slave,
  471.         -- i.e. put it at the end of others instead of setting it master.
  472.          awful.client.setslave(c)
  473.  
  474.         -- Put windows in a smart way, only if they does not set an initial position.
  475.         if not c.size_hints.user_position and not c.size_hints.program_position then
  476.             awful.placement.no_overlap(c)
  477.             awful.placement.no_offscreen(c)
  478.         end
  479.     end
  480. end)
  481.  
  482. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  483. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  484. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement