Advertisement
Guest User

Untitled

a guest
Apr 21st, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.50 KB | None | 0 0
  1. -- Standard awesome library
  2. require("awful")
  3. require("awful.autofocus")
  4. require("awful.rules")
  5. -- Widget and layout library
  6. require("wibox")
  7. -- Theme handling library
  8. require("beautiful")
  9. -- Notification library
  10. require("naughty")
  11. require("vicious")
  12. require("menubar")
  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.connect_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("/usr/local/share/awesome/themes/zenburn/theme.lua")
  42. theme.border_focus = "#ff6666"
  43.  
  44. -- This is used later as the default terminal and editor to run.
  45. terminal = "xfce4-terminal"
  46. editor = os.getenv("EDITOR") or "nano"
  47. editor_cmd = terminal .. " -e " .. editor
  48.  
  49. -- Default modkey.
  50. -- Usually, Mod4 is the key with a logo between Control and Alt.
  51. -- If you do not like this or do not have such a key,
  52. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  53. -- However, you can use another modifier like Mod1, but it may interact with others.
  54. modkey = "Mod1"
  55.  
  56. -- Table of layouts to cover with awful.layout.inc, order matters.
  57. layouts =
  58. {
  59.     awful.layout.suit.floating,
  60.     awful.layout.suit.tile,
  61.     awful.layout.suit.tile.left,
  62.     awful.layout.suit.tile.bottom,
  63.     awful.layout.suit.tile.top,
  64.     awful.layout.suit.fair,
  65.     awful.layout.suit.fair.horizontal,
  66.     --awful.layout.suit.spiral,
  67.     --awful.layout.suit.spiral.dwindle,
  68.     awful.layout.suit.max,
  69.     awful.layout.suit.max.fullscreen,
  70.     --awful.layout.suit.magnifier
  71. }
  72. -- }}}
  73.  
  74. -- {{{ Tags
  75. -- Define a tag table which hold all screen tags.
  76. tags = {}
  77. for s = 1, screen.count() do
  78.     -- Each screen has its own tag table.
  79.     tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[2])
  80. end
  81. -- }}}
  82. awful.tag.setmwfact(0.75, tags[1][4])
  83. awful.tag.setncol(2, tags[1][4])
  84. -- {{{ Menu
  85. -- Create a laucher widget and a main menu
  86. myawesomemenu = {
  87.    { "manual", terminal .. " -e man awesome" },
  88.    { "edit config", editor_cmd .. " " .. awesome.conffile },
  89.    { "restart", awesome.restart },
  90.    { "quit", awesome.quit }
  91. }
  92.  
  93. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  94.                                     { "open terminal", terminal }
  95.                                   }
  96.                         })
  97.  
  98. --mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  99. --                                     menu = mymainmenu })
  100.  
  101. -- Menubar configuration
  102. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  103. -- }}}
  104.  
  105. -- {{{ Wibox
  106. netwidget = wibox.widget.textbox()
  107. vicious.register(netwidget, vicious.widgets.net, '<span color="#CC9393">${eth0 down_kb}</span> <span color="#7F9F7F">${eth0 up_kb}</span>', 3)
  108. memwidget = wibox.widget.textbox()
  109. vicious.register(memwidget, vicious.widgets.mem, 'Mem:$1% ($2Mb)', 13)
  110. cpuwidget = wibox.widget.textbox()
  111. vicious.register(cpuwidget, vicious.widgets.cpu, 'CPU:$1%', 1)
  112.  
  113. ctmpwidget0 = wibox.widget.textbox()
  114. vicious.register(ctmpwidget0, vicious.widgets.thermal, '$1°C ', 10, {"temp1_input", "core"})
  115. ctmpwidget1 = wibox.widget.textbox()
  116. vicious.register(ctmpwidget1, vicious.widgets.thermal, '$1°C ', 10, {"temp2_input", "core"})
  117. ctmpwidget2 = wibox.widget.textbox()
  118. vicious.register(ctmpwidget2, vicious.widgets.thermal, '$1°C ', 10, {"temp3_input", "core"})
  119. ctmpwidget3 = wibox.widget.textbox()
  120. vicious.register(ctmpwidget3, vicious.widgets.thermal, '$1°C ', 10, {"temp4_input", "core"})
  121.  
  122.  
  123. wthwidget = wibox.widget.textbox()
  124. vicious.register(wthwidget, vicious.widgets.weather, '${city}: W:${wind} ${windkmh}km/h ${tempc}°C ${humid}%', 3600, "UUYY")
  125. mpdwidget = wibox.widget.textbox()
  126. vicious.register(mpdwidget, vicious.widgets.mpd, '${Artist} — ${Title} [${Album}]', 5)
  127. separator = wibox.widget.textbox()
  128. separator:set_text(" :: ")
  129.  
  130. -- Create a textclock widget
  131. mytextclock = awful.widget.textclock()
  132.  
  133. -- Create a wibox for each screen and add it
  134. mywibox = {}
  135. mypromptbox = {}
  136. mylayoutbox = {}
  137. mytaglist = {}
  138. mytaglist.buttons = awful.util.table.join(
  139.                     awful.button({ }, 1, awful.tag.viewonly),
  140.                     awful.button({ modkey }, 1, awful.client.movetotag),
  141.                     awful.button({ }, 3, awful.tag.viewtoggle),
  142.                     awful.button({ modkey }, 3, awful.client.toggletag),
  143.                     awful.button({ }, 4, awful.tag.viewnext),
  144.                     awful.button({ }, 5, awful.tag.viewprev)
  145.                     )
  146. mytasklist = {}
  147. mytasklist.buttons = awful.util.table.join(
  148.                      awful.button({ }, 1, function (c)
  149.                                               if c == client.focus then
  150.                                                   c.minimized = true
  151.                                               else
  152.                                                   if not c:isvisible() then
  153.                                                       awful.tag.viewonly(c:tags()[1])
  154.                                                   end
  155.                                                   -- This will also un-minimize
  156.                                                   -- the client, if needed
  157.                                                   client.focus = c
  158.                                                   c:raise()
  159.                                               end
  160.                                           end),
  161.                      awful.button({ }, 3, function ()
  162.                                               if instance then
  163.                                                   instance:hide()
  164.                                                   instance = nil
  165.                                               else
  166.                                                   instance = awful.menu.clients({ width=250 })
  167.                                               end
  168.                                           end),
  169.                      awful.button({ }, 4, function ()
  170.                                               awful.client.focus.byidx(1)
  171.                                               if client.focus then client.focus:raise() end
  172.                                           end),
  173.                      awful.button({ }, 5, function ()
  174.                                               awful.client.focus.byidx(-1)
  175.                                               if client.focus then client.focus:raise() end
  176.                                           end))
  177.  
  178. for s = 1, screen.count() do
  179.     -- Create a promptbox for each screen
  180.     mypromptbox[s] = awful.widget.prompt()
  181.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  182.     -- We need one layoutbox per screen.
  183.     mylayoutbox[s] = awful.widget.layoutbox(s)
  184.     mylayoutbox[s]:buttons(awful.util.table.join(
  185.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  186.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  187.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  188.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  189.     -- Create a taglist widget
  190.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  191.  
  192.     -- Create a tasklist widget
  193.     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  194.  
  195.     -- Create the wibox
  196.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  197.  
  198.     -- Widgets that are aligned to the left
  199.     local left_layout = wibox.layout.fixed.horizontal()
  200.  
  201.     left_layout:add(mytaglist[s])
  202.     left_layout:add(mypromptbox[s])
  203.     left_layout:add(separator)
  204.     left_layout:add(cpuwidget)
  205.     left_layout:add(separator)
  206.     left_layout:add(ctmpwidget0)
  207.     left_layout:add(ctmpwidget1)
  208.     left_layout:add(ctmpwidget2)
  209.     left_layout:add(ctmpwidget3)
  210.     left_layout:add(separator)
  211.     left_layout:add(memwidget)
  212.     left_layout:add(separator)
  213.     left_layout:add(netwidget)
  214.     left_layout:add(separator)
  215.     left_layout:add(mpdwidget)
  216.     left_layout:add(separator)
  217.  
  218.     -- Widgets that are aligned to the right
  219.     local right_layout = wibox.layout.fixed.horizontal()
  220.     if s == 1 then right_layout:add(wibox.widget.systray()) end
  221.     right_layout:add(separator)
  222.     right_layout:add(wthwidget)
  223.     right_layout:add(separator)
  224.     right_layout:add(mytextclock)
  225.     right_layout:add(mylayoutbox[s])
  226.  
  227.     -- Now bring it all together (with the tasklist in the middle)
  228.     local layout = wibox.layout.align.horizontal()
  229.     layout:set_left(left_layout)
  230.     layout:set_middle(mytasklist[s])
  231.     layout:set_right(right_layout)
  232.  
  233.     mywibox[s]:set_widget(layout)
  234. end
  235. -- }}}
  236.  
  237. -- {{{ Mouse bindings
  238. root.buttons(awful.util.table.join(
  239.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  240.     awful.button({ }, 4, awful.tag.viewnext),
  241.     awful.button({ }, 5, awful.tag.viewprev)
  242. ))
  243. -- }}}
  244.  
  245. -- {{{ Key bindings
  246. globalkeys = awful.util.table.join(
  247.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  248.  
  249.     awful.key({ modkey,           }, "j",
  250.         function ()
  251.             awful.client.focus.byidx( 1)
  252.             if client.focus then client.focus:raise() end
  253.         end),
  254.     awful.key({ modkey,           }, "k",
  255.         function ()
  256.             awful.client.focus.byidx(-1)
  257.             if client.focus then client.focus:raise() end
  258.         end),
  259.     awful.key({ modkey,           }, "w", function () mymainmenu:show() end),
  260.  
  261.     -- Layout manipulation
  262.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  263.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  264.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  265.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  266.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  267.     awful.key({ modkey,           }, "Tab",
  268.         function ()
  269.             awful.client.focus.history.previous()
  270.             if client.focus then
  271.                 client.focus:raise()
  272.             end
  273.         end),
  274.  
  275.     -- Standard program
  276.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  277.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  278.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  279.  
  280.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  281.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  282.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  283.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  284.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  285.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  286.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  287.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  288.     awful.key({ modkey, "Control" }, "Delete",function () awful.util.spawn("xscreensaver-command -lock") end),
  289.  
  290.     -- Menubar
  291.     awful.key({ modkey }, "p", function()
  292.         awful.util.spawn("dmenu_run -i -p 'Run command:' -nb '" ..
  293.         beautiful.bg_normal .. "' -nf '" .. beautiful.fg_normal ..
  294.         "' -sb '" .. beautiful.bg_focus ..
  295.         "' -sf '" .. beautiful.fg_focus .. "'")
  296.     end),
  297.     awful.key({}, "#173", function () awful.util.spawn("mpc prev") end ),
  298.     awful.key({}, "#171", function () awful.util.spawn("mpc next") end ),
  299.     awful.key({}, "#172", function () awful.util.spawn("mpc toggle") end ),
  300.     awful.key({}, "#174", function () awful.util.spawn("mpc stop") end ),
  301.     awful.key({}, "#122", function () awful.util.spawn("mpc volume -5") end ),
  302.     awful.key({}, "#123", function () awful.util.spawn("mpc volume +5") end )
  303. )
  304.  
  305. clientkeys = awful.util.table.join(
  306.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  307.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  308.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  309.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  310.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  311.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  312.     awful.key({ modkey,           }, "m",
  313.         function (c)
  314.             c.maximized_horizontal = not c.maximized_horizontal
  315.             c.maximized_vertical   = not c.maximized_vertical
  316.         end)
  317. )
  318.  
  319. -- Compute the maximum number of digit we need, limited to 9
  320. keynumber = 0
  321. for s = 1, screen.count() do
  322.    keynumber = math.min(9, math.max(#tags[s], keynumber));
  323. end
  324.  
  325. -- Bind all key numbers to tags.
  326. -- Be careful: we use keycodes to make it works on any keyboard layout.
  327. -- This should map on the top row of your keyboard, usually 1 to 9.
  328. for i = 1, keynumber do
  329.     globalkeys = awful.util.table.join(globalkeys,
  330.         awful.key({ modkey }, "#" .. i + 9,
  331.                   function ()
  332.                         local screen = mouse.screen
  333.                         if tags[screen][i] then
  334.                             awful.tag.viewonly(tags[screen][i])
  335.                         end
  336.                   end),
  337.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  338.                   function ()
  339.                       local screen = mouse.screen
  340.                       if tags[screen][i] then
  341.                           awful.tag.viewtoggle(tags[screen][i])
  342.                       end
  343.                   end),
  344.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  345.                   function ()
  346.                       if client.focus and tags[client.focus.screen][i] then
  347.                           awful.client.movetotag(tags[client.focus.screen][i])
  348.                       end
  349.                   end),
  350.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  351.                   function ()
  352.                       if client.focus and tags[client.focus.screen][i] then
  353.                           awful.client.toggletag(tags[client.focus.screen][i])
  354.                       end
  355.                   end))
  356. end
  357.  
  358. clientbuttons = awful.util.table.join(
  359.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  360.     awful.button({ modkey }, 1, awful.mouse.client.move),
  361.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  362.  
  363. -- Set keys
  364. root.keys(globalkeys)
  365. -- }}}
  366.  
  367. -- {{{ Rules
  368. awful.rules.rules = {
  369.     -- All clients will match this rule.
  370.     { rule = { },
  371.       properties = { border_width = beautiful.border_width,
  372.                      border_color = beautiful.border_normal,
  373.                      focus = true,
  374.                      keys = clientkeys,
  375.                      size_hints_honor = false,
  376.                      buttons = clientbuttons } },
  377.     { rule = { class = "MPlayer" },
  378.       properties = { floating = true } },
  379.     { rule = { class = "Exe" },
  380.       properties = { floating = true } },
  381.     { rule = { class = "pinentry" },
  382.       properties = { floating = true } },
  383.     { rule = { class = "gimp" },
  384.       properties = { floating = true } },
  385.     { rule = { class = "Gimp" },
  386.       properties = { },
  387.       callback = awful.client.setmaster },
  388.     { rule = { },
  389.       properties = { },
  390.       callback = awful.client.setslave },
  391.     -- Set Firefox to always map on tags number 2 of screen 1.
  392.     -- { rule = { class = "Firefox" },
  393.     --   properties = { tag = tags[1][2] } },
  394. }
  395. -- }}}
  396.  
  397. -- {{{ Signals
  398. -- Signal function to execute when a new client appears.
  399. client.connect_signal("manage", function (c, startup)
  400.     -- Enable sloppy focus
  401.     c:connect_signal("mouse::enter", function(c)
  402.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  403.             and awful.client.focus.filter(c) then
  404.             client.focus = c
  405.         end
  406.     end)
  407.  
  408.     if not startup then
  409.         -- Set the windows at the slave,
  410.         -- i.e. put it at the end of others instead of setting it master.
  411.         -- awful.client.setslave(c)
  412.  
  413.         -- Put windows in a smart way, only if they does not set an initial position.
  414.         if not c.size_hints.user_position and not c.size_hints.program_position then
  415.             awful.placement.no_overlap(c)
  416.             awful.placement.no_offscreen(c)
  417.         end
  418.     end
  419. end)
  420.  
  421. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  422. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  423. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement