Advertisement
Guest User

Untitled

a guest
Aug 26th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.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("vicious")
  10.  
  11. -- {{{ Error handling
  12. -- Check if awesome encountered an error during startup and fell back to
  13. -- another config (This code will only ever execute for the fallback config)
  14. if awesome.startup_errors then
  15.     naughty.notify({ preset = naughty.config.presets.critical,
  16.                      title = "Oops, there were errors during startup!",
  17.                      text = awesome.startup_errors })
  18. end
  19.  
  20. -- Handle runtime errors after startup
  21. do
  22.     local in_error = false
  23.     awesome.add_signal("debug::error", function (err)
  24.         -- Make sure we don't go into an endless error loop
  25.         if in_error then return end
  26.         in_error = true
  27.  
  28.         naughty.notify({ preset = naughty.config.presets.critical,
  29.                          title = "Oops, an error happened!",
  30.                          text = err })
  31.         in_error = false
  32.     end)
  33. end
  34. -- }}}
  35.  
  36. -- {{{ Variable definitions
  37. -- Themes define colours, icons, and wallpapers
  38. beautiful.init("/home/y/.config/awesome/zenburn/theme.lua")
  39.  
  40. -- This is used later as the default terminal and editor to run.
  41. terminal = "urxvtc"
  42. editor = "vim"
  43. editor_cmd = terminal .. " -e " .. editor
  44.  
  45. -- Default modkey.
  46. -- Usually, Mod4 is the key with a logo between Control and Alt.
  47. -- If you do not like this or do not have such a key,
  48. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  49. -- However, you can use another modifier like Mod1, but it may interact with others.
  50. modkey = "Mod4"
  51.  
  52. -- Table of layouts to cover with awful.layout.inc, order matters.
  53. layouts =
  54. {
  55. --    awful.layout.suit.floating,
  56.     awful.layout.suit.tile,
  57.     awful.layout.suit.tile.left,
  58.     awful.layout.suit.tile.bottom,
  59.     awful.layout.suit.tile.top,
  60.     awful.layout.suit.fair,
  61.     awful.layout.suit.fair.horizontal,
  62. --    awful.layout.suit.spiral,
  63. --    awful.layout.suit.spiral.dwindle,
  64.     awful.layout.suit.max,
  65.     awful.layout.suit.max.fullscreen,
  66.     awful.layout.suit.magnifier
  67. }
  68. -- }}}
  69.  
  70. -- {{{ Tags
  71. -- Define a tag table which hold all screen tags.
  72. tags = {}
  73. for s = 1, screen.count() do
  74.     -- Each screen has its own tag table.
  75.     tags[s] = awful.tag({ "firefox", "terms", "im", 4, 5 }, s, layouts[1])
  76. end
  77. -- }}}
  78.  
  79. -- {{{ Menu
  80. -- Create a laucher widget and a main menu
  81. myawesomemenu = {
  82.    { "manual", terminal .. " -e man awesome" },
  83.    { "edit config", editor_cmd .. " " .. awesome.conffile },
  84.    { "restart", awesome.restart },
  85.    { "quit", awesome.quit }
  86. }
  87.  
  88. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  89.                                     { "open terminal", terminal }
  90.                                   }
  91.                         })
  92.  
  93. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  94.                                      menu = mymainmenu, layout = awful.widget.layout.vertical.flex })
  95. -- }}}
  96.  
  97. -- {{{ Wibox
  98. -- Create a textclock widget
  99. mytextclock = awful.widget.textclock({ layout = awful.widget.layout.vertical.flex })
  100.  
  101. -- Create a systray
  102. mysystray = widget({ type = "systray", layout = awful.widget.layout.vertical.flex })
  103.  
  104. -- Create a wibox for each screen and add it
  105. mywibox = {}
  106. mypromptbox = {}
  107. mylayoutbox = {}
  108. mytaglist = {}
  109. mytaglist.buttons = awful.util.table.join(
  110.                     awful.button({ }, 1, awful.tag.viewonly),
  111.                     awful.button({ modkey }, 1, awful.client.movetotag),
  112.                     awful.button({ }, 3, awful.tag.viewtoggle),
  113.                     awful.button({ modkey }, 3, awful.client.toggletag),
  114.                     awful.button({ }, 4, awful.tag.viewnext),
  115.                     awful.button({ }, 5, awful.tag.viewprev)
  116.                     )
  117. mytasklist = {}
  118. mytasklist.buttons = awful.util.table.join(
  119.                      awful.button({ }, 1, function (c)
  120.                                               if c == client.focus then
  121.                                                   c.minimized = true
  122.                                               else
  123.                                                   if not c:isvisible() then
  124.                                                       awful.tag.viewonly(c:tags()[1])
  125.                                                   end
  126.                                                   -- This will also un-minimize
  127.                                                   -- the client, if needed
  128.                                                   client.focus = c
  129.                                                   c:raise()
  130.                                               end
  131.                                           end),
  132.                      awful.button({ }, 3, function ()
  133.                                               if instance then
  134.                                                   instance:hide()
  135.                                                   instance = nil
  136.                                               else
  137.                                                   instance = awful.menu.clients({ width=250 })
  138.                                               end
  139.                                           end),
  140.                      awful.button({ }, 4, function ()
  141.                                               awful.client.focus.byidx(1)
  142.                                               if client.focus then client.focus:raise() end
  143.                                           end),
  144.                      awful.button({ }, 5, function ()
  145.                                               awful.client.focus.byidx(-1)
  146.                                               if client.focus then client.focus:raise() end
  147.                                           end))
  148.  
  149. for s = 1, screen.count() do
  150.     -- Create a promptbox for each screen
  151.     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.vertical.downtop })
  152.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  153.     -- We need one layoutbox per screen.
  154.     mylayoutbox[s] = awful.widget.layoutbox(s)
  155.     mylayoutbox[s]:buttons(awful.util.table.join(
  156.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  157.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  158.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  159.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  160.     -- Create a taglist widget
  161.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  162.  
  163.     -- Create a tasklist widget
  164.     mytasklist[s] = awful.widget.tasklist(function(c)
  165.                                               return awful.widget.tasklist.label.currenttags(c, s)
  166.                                           end, mytasklist.buttons)
  167.     batwidget = awful.widget.progressbar()
  168.     batwidget:set_width(8)
  169.     batwidget:set_height(14)
  170.     batwidget:set_vertical(true)
  171.     batwidget:set_background_color("#000000")
  172.     batwidget:set_border_color(nil)
  173.     batwidget:set_color("#00bfff")
  174.     vicious.register(batwidget, vicious.widgets.bat, '$1$2', 61, 'BAT0')
  175.     -- Create the wibox
  176.     mywibox[s] = awful.wibox({ position = "right", screen = s, width = "48",})
  177.     -- Add widgets to the wibox - order matters
  178.     mywibox[s].widgets = {
  179.         {
  180.             mylauncher,
  181.             mytaglist[s],
  182.             mypromptbox[s],
  183.             layout = awful.widget.layout.horizontal.leftright
  184.         },
  185.         mylayoutbox[s],
  186.         mytextclock,
  187.         batwidget,
  188.         s == 1 and mysystray or nil,
  189.         mytasklist[s],
  190.         layout = awful.widget.layout.horizontal.rightleft
  191.     }
  192. end
  193. -- }}}
  194.  
  195. -- {{{ Mouse bindings
  196. root.buttons(awful.util.table.join(
  197.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  198.     awful.button({ }, 4, awful.tag.viewnext),
  199.     awful.button({ }, 5, awful.tag.viewprev)
  200. ))
  201. -- }}}
  202.  
  203. -- {{{ Key bindings
  204. globalkeys = awful.util.table.join(
  205.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  206.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  207.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  208.  
  209.     awful.key({ modkey,           }, "j",
  210.         function ()
  211.             awful.client.focus.byidx( 1)
  212.             if client.focus then client.focus:raise() end
  213.         end),
  214.     awful.key({ modkey,           }, "k",
  215.         function ()
  216.             awful.client.focus.byidx(-1)
  217.             if client.focus then client.focus:raise() end
  218.         end),
  219.     awful.key({ modkey,           }, "w", function () mymainmenu:show({keygrabber=true}) end),
  220.  
  221.     -- Layout manipulation
  222.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  223.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  224.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  225.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  226.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  227.     awful.key({ modkey,           }, "Tab",
  228.         function ()
  229.             awful.client.focus.history.previous()
  230.             if client.focus then
  231.                 client.focus:raise()
  232.             end
  233.         end),
  234.  
  235.     -- Standard program
  236.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  237.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  238.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  239.  
  240.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  241.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  242.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  243.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  244.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  245.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  246.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  247.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  248.  
  249.     awful.key({ modkey, "Control" }, "n", awful.client.restore),
  250.  
  251.     -- Prompt
  252.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  253.  
  254.     awful.key({ modkey }, "x",
  255.               function ()
  256.                   awful.prompt.run({ prompt = "Run Lua code: " },
  257.                   mypromptbox[mouse.screen].widget,
  258.                   awful.util.eval, nil,
  259.                   awful.util.getdir("cache") .. "/history_eval")
  260.               end),
  261.     -- User added
  262.     awful.key({}, "#122", function () os.execute("amixer -c 0 -q set Master 3%- unmute") end),
  263.     awful.key({}, "#123", function () os.execute("amixer -c 0 -q set Master 3%+ unmute") end),
  264.     awful.key({}, "#121", function () os.execute("amixer -c 0 -q set Master toggle") end),
  265. --    awful.key({}, "#237", function () os.execute("kbd_backlight down") end),
  266. --    awful.key({}, "#238", function () os.execute("kbd_backlight up") end)
  267. )
  268.  
  269. clientkeys = awful.util.table.join(
  270.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  271.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  272.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  273.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  274.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  275.     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
  276.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  277.     awful.key({ modkey,           }, "n",
  278.         function (c)
  279.             -- The client currently has the input focus, so it cannot be
  280.             -- minimized, since minimized clients can't have the focus.
  281.             c.minimized = true
  282.         end),
  283.     awful.key({ modkey,           }, "m",
  284.         function (c)
  285.             c.maximized_horizontal = not c.maximized_horizontal
  286.             c.maximized_vertical   = not c.maximized_vertical
  287.         end)
  288. )
  289.  
  290. -- Compute the maximum number of digit we need, limited to 9
  291. keynumber = 0
  292. for s = 1, screen.count() do
  293.    keynumber = math.min(9, math.max(#tags[s], keynumber));
  294. end
  295.  
  296. -- Bind all key numbers to tags.
  297. -- Be careful: we use keycodes to make it works on any keyboard layout.
  298. -- This should map on the top row of your keyboard, usually 1 to 9.
  299. for i = 1, keynumber do
  300.     globalkeys = awful.util.table.join(globalkeys,
  301.         awful.key({ modkey }, "#" .. i + 9,
  302.                   function ()
  303.                         local screen = mouse.screen
  304.                         if tags[screen][i] then
  305.                             awful.tag.viewonly(tags[screen][i])
  306.                         end
  307.                   end),
  308.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  309.                   function ()
  310.                       local screen = mouse.screen
  311.                       if tags[screen][i] then
  312.                           awful.tag.viewtoggle(tags[screen][i])
  313.                       end
  314.                   end),
  315.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  316.                   function ()
  317.                       if client.focus and tags[client.focus.screen][i] then
  318.                           awful.client.movetotag(tags[client.focus.screen][i])
  319.                       end
  320.                   end),
  321.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  322.                   function ()
  323.                       if client.focus and tags[client.focus.screen][i] then
  324.                           awful.client.toggletag(tags[client.focus.screen][i])
  325.                       end
  326.                   end))
  327. end
  328.  
  329. clientbuttons = awful.util.table.join(
  330.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  331.     awful.button({ modkey }, 1, awful.mouse.client.move),
  332.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  333.  
  334. -- Set keys
  335. root.keys(globalkeys)
  336. -- }}}
  337.  
  338. -- {{{ Rules
  339. awful.rules.rules = {
  340.     -- All clients will match this rule.
  341.     { rule = { },
  342.       properties = { border_width = beautiful.border_width,
  343.                      border_color = beautiful.border_normal,
  344.                      focus = true,
  345.                      keys = clientkeys,
  346.                      buttons = clientbuttons } },
  347.     { rule = { class = "MPlayer" },
  348.       properties = { floating = true } },
  349.     { rule = { class = "pinentry" },
  350.       properties = { floating = true } },
  351.     { rule = { class = "gimp" },
  352.       properties = { floating = true } },
  353.     -- Set Firefox to always map on tags number 2 of screen 1.
  354.     -- { rule = { class = "Firefox" },
  355.     --   properties = { tag = tags[1][2] } },
  356. }
  357. -- }}}
  358.  
  359. -- {{{ Signals
  360. -- Signal function to execute when a new client appears.
  361. client.add_signal("manage", function (c, startup)
  362.     -- Add a titlebar
  363.     -- awful.titlebar.add(c, { modkey = modkey })
  364.  
  365.     -- Enable sloppy focus
  366.     c:add_signal("mouse::enter", function(c)
  367.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  368.             and awful.client.focus.filter(c) then
  369.             client.focus = c
  370.         end
  371.     end)
  372.  
  373.     if not startup then
  374.         -- Set the windows at the slave,
  375.         -- i.e. put it at the end of others instead of setting it master.
  376.         -- awful.client.setslave(c)
  377.  
  378.         -- Put windows in a smart way, only if they does not set an initial position.
  379.         if not c.size_hints.user_position and not c.size_hints.program_position then
  380.             awful.placement.no_overlap(c)
  381.             awful.placement.no_offscreen(c)
  382.         end
  383.     end
  384. end)
  385.  
  386. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  387. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  388. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement