Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 17.53 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -- Awesome config (~/.config/awesome/rc.lua)
  2. -- mu @ freenode
  3.  
  4. require("awful")
  5. require("awful.autofocus")
  6. require("awful.rules")
  7. require("beautiful")
  8. require("naughty")
  9. require("vicious")
  10. require("eminent")
  11.  
  12. -- {{{ Variables
  13. beautiful.init(awful.util.getdir("config") .. "/themes/Mine/theme.lua")
  14.  
  15. terminal = "urxvtc"
  16. editor = "gedit"
  17. editor_cmd = terminal .. " -e " .. editor
  18. web_browser = "jumanji"
  19. file_browser = "ranger"
  20.  
  21. modkey = "Mod4"
  22.  
  23. layouts =
  24. {
  25.     awful.layout.suit.tile,
  26.     awful.layout.suit.floating,
  27.     awful.layout.suit.tile.left,
  28.     awful.layout.suit.tile.bottom,
  29.     awful.layout.suit.tile.top,
  30.     awful.layout.suit.fair,
  31.     awful.layout.suit.fair.horizontal,
  32. }
  33. -- }}}
  34.  
  35. -- {{{ Tags
  36. tags = { names = { "term", "www", "chat", "media", "tor", "design", "dev", "vbox" },
  37.          layout = { layouts[1], layouts[4], layouts[6], layouts[2],
  38. layouts[1], layouts[7], layouts[1], layouts[2] } }
  39.  
  40. for s = 1, screen.count() do
  41.     tags[s] = awful.tag(tags.names, s, tags.layout)
  42. end
  43. -- }}}
  44.  
  45. -- {{{ Widgets
  46.  
  47. -- Containers
  48. topbar = {}
  49. bottombar = {}
  50.  
  51. -- Generic widgets
  52. clock = awful.widget.textclock({align = "right"}, "%a %b %d, %I:%M %p")
  53. mysystray = widget({ type = "systray" })
  54. seperator = widget({ type = "textbox" })
  55. seperator.text = " | "
  56. spacer = widget({ type = "textbox" })
  57. spacer.width = 6
  58. netwidget = widget({ type = "textbox" })
  59.  
  60. -- Set all the icons needed
  61. cpuicon = widget ({ type = "textbox" })
  62. cpuicon.bg_image = image(beautiful.widget_cpu)
  63. cpuicon.bg_align = "middle"
  64. cpuicon.width = 8
  65. tempicon = widget ({ type = "textbox" })
  66. tempicon.bg_image = image(beautiful.widget_temp)
  67. tempicon.bg_align = "middle"
  68. tempicon.width = 8
  69. memicon = widget ({ type = "textbox" })
  70. memicon.bg_image = image(beautiful.widget_mem)
  71. memicon.bg_align = "middle"
  72. memicon.width = 8
  73. spkricon = widget ({ type = "textbox" })
  74. spkricon.bg_image = image(beautiful.widget_spkr)
  75. spkricon.bg_align = "middle"
  76. spkricon.width = 8
  77. netdownicon = widget ({ type = "textbox" })
  78. netdownicon.bg_image = image(beautiful.widget_netdown)
  79. netdownicon.bg_align = "middle"
  80. netdownicon.width = 8
  81. netupicon = widget ({ type = "textbox" })
  82. netupicon.bg_image = image(beautiful.widget_netup)
  83. netupicon.bg_align = "middle"
  84. netupicon.width = 8
  85. mailicon = widget ({ type = "textbox" })
  86. mailicon.bg_image = image(beautiful.widget_mail)
  87. mailicon.bg_align = "middle"
  88. mailicon.width = 8
  89. pacicon = widget ({ type = "textbox" })
  90. pacicon.bg_image = image(beautiful.widget_pacman)
  91. pacicon.bg_align = "middle"
  92. pacicon.width = 8
  93. clockicon = widget ({ type = "textbox" })
  94. clockicon.bg_image = image(beautiful.widget_clock)
  95. clockicon.bg_align = "middle"
  96. clockicon.width = 8
  97. mpdicon = widget ({ type = "textbox" })
  98. mpdicon.bg_align = "middle"
  99.  
  100. -- Create some widgets...
  101. cpuinfo = widget ({ type = "textbox" })
  102. cputemp = widget ({ type = "textbox" })
  103. meminfo = widget ({ type = "textbox" })
  104. spkrinfo = widget ({ type = "textbox" })
  105. netdowninfo = widget ({ type = "textbox" })
  106. netupinfo = widget ({ type = "textbox" })
  107. mailinfo = widget ({ type = "textbox" })
  108. pacinfo = widget ({ type = "textbox" })
  109. mpdinfo = widget ({ type = "textbox" })
  110.  
  111. -- ... And register them
  112. vicious.register(cpuinfo, vicious.widgets.cpu, "$1% / $2%")
  113. vicious.register(cputemp, vicious.widgets.thermal, "$1 C", 19, "thermal_zone0")
  114. vicious.cache(vicious.widgets.mem)
  115. vicious.register(meminfo, vicious.widgets.mem, "$1% ($2Mb)", 5)
  116. vicious.cache(vicious.widgets.volume)
  117. vicious.register(spkrinfo, vicious.widgets.volume, "$1", 11, "Speaker")
  118. vicious.cache(vicious.widgets.net)
  119. vicious.register(netdowninfo, vicious.widgets.net, "${wlan0 down_kb}", 3)
  120. vicious.register(netupinfo, vicious.widgets.net, "${wlan0 up_kb}", 3)
  121. vicious.register(netwidget, vicious.widgets.net, '<span color="#FFFFFF">${eth0 down_kb}</span> <span color="#FFFFFF">${eth0 up_kb}</span>', 3)
  122. vicious.register(mailinfo, vicious.widgets.gmail,
  123.   function (widget, args)
  124.     if args["{count}"] == 0 then
  125.       mailicon.bg_image = image(beautiful.widget_mail)
  126.       return 0
  127.     else
  128.       mailicon.bg_image = image(beautiful.widget_newmail)
  129.       return args["{count}"]
  130.     end
  131.   end, 61)
  132. vicious.register(pacinfo, vicious.widgets.pkg,
  133.   function (widget, args)
  134.     if args[1] == 0 then
  135.       pacicon.bg_image = image(beautiful.widget_pacman)
  136.       return 0
  137.     else
  138.       pacicon.bg_image = image(beautiful.widget_newpackage)
  139.       return args[1]
  140.     end
  141.   end, 301, "Arch")
  142.  
  143.  
  144. -- MPD widget. Hides icon and text when nothing is playing.
  145. vicious.register(mpdinfo, vicious.widgets.mpd,
  146.   function (widget, args)
  147.     if args["{state}"] == "Stop" then
  148.       mpdicon.bg_image = nil
  149.       mpdicon.width = 0
  150.       return ""
  151.     else
  152.       mpdicon.bg_image = image(beautiful.widget_mpd)
  153.       mpdicon.width = 8
  154.       return "MPD: " .. args["{Artist}"] .. ' - ' .. args["{Title}"]
  155.     end
  156.   end)
  157.  
  158.  
  159. -- Create a wibox for each screen and add it
  160. mylayoutbox = {}
  161. mytaglist = {}
  162. mypromptbox = {}
  163. mytaglist.buttons = awful.util.table.join(
  164.                     awful.button({ }, 1, awful.tag.viewonly),
  165.                     awful.button({ modkey }, 1, awful.client.movetotag),
  166.                     awful.button({ }, 3, awful.tag.viewtoggle),
  167.                     awful.button({ modkey }, 3, awful.client.toggletag),
  168.                     awful.button({ }, 4, awful.tag.viewnext),
  169.                     awful.button({ }, 5, awful.tag.viewprev)
  170.                     )
  171. mytasklist = {}
  172. mytasklist.buttons = awful.util.table.join(
  173.                      awful.button({ }, 1, function (c)
  174.                                               if not c:isvisible() then
  175.                                                   awful.tag.viewonly(c:tags()[1])
  176.                                               end
  177.                                               client.focus = c
  178.                                               c:raise()
  179.                                           end),
  180.                      awful.button({ }, 3, function ()
  181.                                               if instance then
  182.                                                   instance:hide()
  183.                                                   instance = nil
  184.                                               else
  185.                                                   instance = awful.menu.clients({ width=250 })
  186.                                               end
  187.                                           end),
  188.                      awful.button({ }, 4, function ()
  189.                                               awful.client.focus.byidx(1)
  190.                                               if client.focus then client.focus:raise() end
  191.                                           end),
  192.                      awful.button({ }, 5, function ()
  193.                                               awful.client.focus.byidx(-1)
  194.                                               if client.focus then client.focus:raise() end
  195.                                           end))
  196.  
  197. for s = 1, screen.count() do
  198.     -- Set a screen margin, for borders
  199.     awful.screen.padding( screen[s], {top = 1, bottom = 1} )
  200.  
  201.     -- Create a promptbox for each screen
  202.     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  203.  
  204.     -- Create the layout box, taglist, and tasklist widgets
  205.     mylayoutbox[s] = awful.widget.layoutbox(s)
  206.     mylayoutbox[s]:buttons(awful.util.table.join(
  207.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  208.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  209.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  210.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  211.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  212.     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.label.currenttags, mytasklist.buttons)
  213.  
  214.     -- Create the bars
  215.     topbar[s] = awful.wibox({
  216.                 position = "top", screen = s, height = 14,
  217.                 fg = beautiful.fg_normal, bg = beautiful.bg_normal,
  218.                 border_width = beautiful.border_width,
  219.                 border_color = beautiful.border_normal,
  220.                 cursor = "/usr/share/themes/Human/cursor.theme"
  221.     })
  222.     bottombar[s] = awful.wibox({
  223.                 position = "bottom", screen = s, height = 14,
  224.                 fg = beautiful.fg_normal, bg = beautiful.bg_normal,
  225.                 border_width = beautiful.border_width,
  226.                 border_color = beautiful.border_normal
  227.     })
  228.  
  229.     -- Create a table of widgets
  230.     right_aligned = { layout = awful.widget.layout.horizontal.rightleft}
  231.     if s == 1 then table.insert(right_aligned, mysystray) end
  232.     table.insert(right_aligned, mylayoutbox[s])
  233.     topbar[s].widgets = {
  234.         mytaglist[s],
  235.         mypromptbox[s],
  236.         right_aligned,
  237.         mytasklist[s],
  238.         layout = awful.widget.layout.horizontal.leftright,
  239.         height = 14
  240.     }
  241.     bottombar[s].widgets = {
  242.         { mpdicon, spacer, mpdinfo,
  243.           layout = awful.widget.layout.horizontal.leftright
  244.         },
  245.         {spacer, cpuicon, spacer, cpuinfo, seperator, tempicon, spacer, cputemp,
  246.         seperator, memicon, spacer, meminfo, seperator, spkricon, spacer,
  247.         spkrinfo, spacer, mpdicon, spacer, mpdinfo, seperator,
  248.         netdownicon, spacer, netwidget, spacer, netupicon, spacer,
  249.         seperator, mailicon, spacer, mailinfo, seperator,
  250.         pacicon, spacer, pacinfo,
  251.                 seperator, clockicon, spacer, clock, spacer,
  252.         layout = awful.widget.layout.horizontal.rightleft,
  253.         height = 13},
  254.         layout = awful.widget.layout.horizontal.leftright, height = 13
  255.    }
  256. end
  257. -- }}}
  258.  
  259. -- {{{ Mouse bindings
  260. root.buttons(awful.util.table.join(
  261.     awful.button({ }, 3, function() end ),
  262.     awful.button({ }, 4, awful.tag.viewnext),
  263.     awful.button({ }, 5, awful.tag.viewprev)
  264. ))
  265. -- }}}
  266.  
  267. -- {{{ Key bindings
  268. globalkeys = awful.util.table.join(
  269.     -- Program shortcuts
  270.     awful.key({ modkey,  }, "Return", function () awful.util.spawn(terminal) end),
  271.     awful.key({ modkey,           }, "x", function () awful.util.spawn_with_shell( "exe=`dmenu -fa 'Envy Code R:10' -nb '#D4D4D4' -nf '#333333' -sb '#D4D4D4' -sf '#0081DE'` && exec $exe" ) end),
  272.     awful.key({ modkey,           }, "p", function () awful.util.spawn(file_browser) end),
  273.     awful.key({ modkey,           }, "c", function () awful.util.spawn(web_browser) end),
  274.  
  275.     -- Prompt
  276.     --awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  277.  
  278.     -- Layout presets (dwm-style)
  279.     awful.key({ modkey,           }, "f", function () awful.layout.set( awful.layout.suit.floating ) end),
  280.     awful.key({ modkey,           }, "t", function () awful.layout.set( awful.layout.suit.tile     ) end),
  281.  
  282.     -- Standard keys
  283.  
  284.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  285.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  286.  
  287.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  288.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  289.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  290.  
  291.    -- awful.key({ modkey,           }, "j",
  292.    --     function ()
  293.    --         awful.client.focus.byidx( 1)
  294.    --         if client.focus then client.focus:raise() end
  295.    --     end),
  296.    -- awful.key({ modkey,           }, "k",
  297.    --     function ()
  298.    --         awful.client.focus.byidx(-1)
  299.    --         if client.focus then client.focus:raise() end
  300.    --     end),
  301.    -- awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  302.    -- awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  303.    -- awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  304.    -- awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  305.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  306.     awful.key({ modkey,           }, "Tab",
  307.         function ()
  308.             awful.client.focus.history.previous()
  309.             if client.focus then
  310.                 client.focus:raise()
  311.             end
  312.         end),
  313.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  314.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  315.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  316.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  317.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  318.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  319.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  320.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end)
  321.  
  322.  
  323.     -- Lua Prompt
  324.     -- awful.key({ modkey }, "x",
  325.     --          function ()
  326.     --              awful.prompt.run({ prompt = "Run Lua code: " },
  327.     --              mypromptbox[mouse.screen].widget,
  328.     --              awful.util.eval, nil,
  329.     --              awful.util.getdir("cache") .. "/history_eval")
  330.     --          end)
  331. )
  332.  
  333. clientkeys = awful.util.table.join(
  334.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  335.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  336.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  337.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  338.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  339.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  340.     awful.key({ modkey,           }, "n",      function (c) c.minimized = not c.minimized    end),
  341.     awful.key({ modkey,           }, "m",
  342.         function (c)
  343.             c.maximized_horizontal = not c.maximized_horizontal
  344.             c.maximized_vertical   = not c.maximized_vertical
  345.         end)
  346. )
  347.  
  348. -- Compute the maximum number of digit we need, limited to 9
  349. keynumber = 0
  350. for s = 1, screen.count() do
  351.    keynumber = math.min(9, math.max(#tags[s], keynumber));
  352. end
  353.  
  354. -- Bind all key numbers to tags.
  355. -- Be careful: we use keycodes to make it works on any keyboard layout.
  356. -- This should map on the top row of your keyboard, usually 1 to 9.
  357. for i = 1, keynumber do
  358.     globalkeys = awful.util.table.join(globalkeys,
  359.         awful.key({ modkey }, "#" .. i + 9,
  360.                   function ()
  361.                         local screen = mouse.screen
  362.                         if tags[screen][i] then
  363.                             awful.tag.viewonly(tags[screen][i])
  364.                         end
  365.                   end),
  366.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  367.                   function ()
  368.                       local screen = mouse.screen
  369.                       if tags[screen][i] then
  370.                           awful.tag.viewtoggle(tags[screen][i])
  371.                       end
  372.                   end),
  373.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  374.                   function ()
  375.                       if client.focus and tags[client.focus.screen][i] then
  376.                           awful.client.movetotag(tags[client.focus.screen][i])
  377.                       end
  378.                   end),
  379.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  380.                   function ()
  381.                       if client.focus and tags[client.focus.screen][i] then
  382.                           awful.client.toggletag(tags[client.focus.screen][i])
  383.                       end
  384.                   end))
  385. end
  386.  
  387. clientbuttons = awful.util.table.join(
  388.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  389.     awful.button({ modkey }, 1, awful.mouse.client.move),
  390.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  391.  
  392. -- Set keys
  393. root.keys(globalkeys)
  394. -- }}}
  395.  
  396. -- {{{ Rules
  397. awful.rules.rules = {
  398.     -- All clients will match this rule.
  399.     { rule = { },
  400.       properties = { border_width = beautiful.border_width,
  401.                      border_color = beautiful.border_normal,
  402.                      focus = true, size_hints_honor = false,
  403.                      keys = clientkeys,
  404.                      buttons = clientbuttons } },
  405.     { rule = { class = "MPlayer" },
  406.       properties = { floating = true } },
  407. }
  408. -- }}}
  409.  
  410. -- {{{ Signals
  411. -- Signal function to execute when a new client appears.
  412. client.add_signal("manage", function (c, startup)
  413.     -- Enable sloppy focus
  414.     c:add_signal("mouse::enter", function(c)
  415.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  416.             and awful.client.focus.filter(c) then
  417.             client.focus = c
  418.         end
  419.     end)
  420.  
  421.     if not startup then
  422.         -- Set the windows at the slave,
  423.         -- i.e. put it at the end of others instead of setting it master.
  424.         -- awful.client.setslave(c)
  425.  
  426.         -- Put windows in a smart way, only if they does not set an initial position.
  427.         if not c.size_hints.user_position and not c.size_hints.program_position then
  428.             awful.placement.no_overlap(c)
  429.             awful.placement.no_offscreen(c)
  430.         end
  431.     end
  432. end)
  433.  
  434. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  435. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  436. -- }}}