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

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 14.06 KB  |  hits: 19  |  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. -- 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.  
  10. -- {{{ Variable definitions
  11. -- Themes define colours, icons, and wallpapers
  12. beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  13.  
  14. -- This is used later as the default terminal and editor to run.
  15. terminal = "xterm"
  16. editor = os.getenv("EDITOR") or "nano"
  17. editor_cmd = terminal .. " -e " .. editor
  18.  
  19. -- Default modkey.
  20. -- Usually, Mod4 is the key with a logo between Control and Alt.
  21. -- If you do not like this or do not have such a key,
  22. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  23. -- However, you can use another modifier like Mod1, but it may interact with others.
  24. modkey = "Mod4"
  25.  
  26. -- Table of layouts to cover with awful.layout.inc, order matters.
  27. layouts =
  28. {
  29.     awful.layout.suit.floating,
  30.     awful.layout.suit.tile,
  31.     awful.layout.suit.tile.left,
  32.     awful.layout.suit.tile.bottom,
  33.     awful.layout.suit.tile.top,
  34.     awful.layout.suit.fair,
  35.     awful.layout.suit.fair.horizontal,
  36.     awful.layout.suit.spiral,
  37.     awful.layout.suit.spiral.dwindle,
  38.     awful.layout.suit.max,
  39.     awful.layout.suit.max.fullscreen,
  40.     awful.layout.suit.magnifier
  41. }
  42. -- }}}
  43.  
  44. -- {{{tags
  45. -- Define a tag table which will hold all screen tags.
  46. tags = {
  47.    names = { 1, 2, 3, 4, 5, 6, 7, "www", "irc"}
  48.    layout = { layouts=[1], layouts=[1], layouts=[1], layouts=[1], layouts=[1], layouts=[1], layouts=[1], layouts=[1], layouts=[1]
  49. }}
  50. for s = 1, screen.count() do
  51.    -- Each screen has its own tag table.
  52.    tags[s] = awful.tag(tags.names, s, tags.layout)
  53. end
  54. -- }}}
  55.  
  56. -- {{{ Menu
  57. -- Create a laucher widget and a main menu
  58. myawesomemenu = {
  59.    { "manual", terminal .. " -e man awesome" },
  60.    { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
  61.    { "restart", awesome.restart },
  62.    { "quit", awesome.quit }
  63. }
  64.  
  65. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  66.                                     { "open terminal", terminal }
  67.                                   }
  68.                         })
  69.  
  70. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  71.                                      menu = mymainmenu })
  72. -- }}}
  73.  
  74. -- {{{ Wibox
  75. -- Create a textclock widget
  76. mytextclock = awful.widget.textclock({ align = "right" })
  77.  
  78. -- Create a systray
  79. mysystray = widget({ type = "systray" })
  80.  
  81. -- Create a wibox for each screen and add it
  82. mywibox = {}
  83. mypromptbox = {}
  84. mylayoutbox = {}
  85. mytaglist = {}
  86. mytaglist.buttons = awful.util.table.join(
  87.                     awful.button({ }, 1, awful.tag.viewonly),
  88.                     awful.button({ modkey }, 1, awful.client.movetotag),
  89.                     awful.button({ }, 3, awful.tag.viewtoggle),
  90.                     awful.button({ modkey }, 3, awful.client.toggletag),
  91.                     awful.button({ }, 4, awful.tag.viewnext),
  92.                     awful.button({ }, 5, awful.tag.viewprev)
  93.                     )
  94. mytasklist = {}
  95. mytasklist.buttons = awful.util.table.join(
  96.                      awful.button({ }, 1, function (c)
  97.                                               if not c:isvisible() then
  98.                                                   awful.tag.viewonly(c:tags()[1])
  99.                                               end
  100.                                               client.focus = c
  101.                                               c:raise()
  102.                                           end),
  103.                      awful.button({ }, 3, function ()
  104.                                               if instance then
  105.                                                   instance:hide()
  106.                                                   instance = nil
  107.                                               else
  108.                                                   instance = awful.menu.clients({ width=250 })
  109.                                               end
  110.                                           end),
  111.                      awful.button({ }, 4, function ()
  112.                                               awful.client.focus.byidx(1)
  113.                                               if client.focus then client.focus:raise() end
  114.                                           end),
  115.                      awful.button({ }, 5, function ()
  116.                                               awful.client.focus.byidx(-1)
  117.                                               if client.focus then client.focus:raise() end
  118.                                           end))
  119.  
  120. for s = 1, screen.count() do
  121.     -- Create a promptbox for each screen
  122.     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  123.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  124.     -- We need one layoutbox per screen.
  125.     mylayoutbox[s] = awful.widget.layoutbox(s)
  126.     mylayoutbox[s]:buttons(awful.util.table.join(
  127.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  128.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  129.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  130.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  131.     -- Create a taglist widget
  132.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  133.  
  134.     -- Create a tasklist widget
  135.     mytasklist[s] = awful.widget.tasklist(function(c)
  136.                                               return awful.widget.tasklist.label.currenttags(c, s)
  137.                                           end, mytasklist.buttons)
  138.  
  139.     -- Create the wibox
  140.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  141.     -- Add widgets to the wibox - order matters
  142.     mywibox[s].widgets = {
  143.         {
  144.             mylauncher,
  145.             mytaglist[s],
  146.             mypromptbox[s],
  147.             layout = awful.widget.layout.horizontal.leftright
  148.         },
  149.         mylayoutbox[s],
  150.         mytextclock,
  151.         s == 1 and mysystray or nil,
  152.         mytasklist[s],
  153.         layout = awful.widget.layout.horizontal.rightleft
  154.     }
  155. end
  156. -- }}}
  157.  
  158. -- {{{ Mouse bindings
  159. root.buttons(awful.util.table.join(
  160.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  161.     awful.button({ }, 4, awful.tag.viewnext),
  162.     awful.button({ }, 5, awful.tag.viewprev)
  163. ))
  164. -- }}}
  165.  
  166. -- {{{ Key bindings
  167. globalkeys = awful.util.table.join(
  168.     awful.key({ }, "Print", function () awful.util.spawn("scrot -e 'mv $f ~/ 2>/dev/null'") end),
  169.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  170.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  171.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  172.  
  173.     awful.key({ modkey,           }, "j",
  174.         function ()
  175.             awful.client.focus.byidx( 1)
  176.             if client.focus then client.focus:raise() end
  177.         end),
  178.     awful.key({ modkey,           }, "k",
  179.         function ()
  180.             awful.client.focus.byidx(-1)
  181.             if client.focus then client.focus:raise() end
  182.         end),
  183.     awful.key({ modkey,           }, "w", function () mymainmenu:show({keygrabber=true}) end),
  184.  
  185.     -- Layout manipulation
  186.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  187.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  188.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  189.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  190.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  191.     awful.key({ modkey,           }, "Tab",
  192.         function ()
  193.             awful.client.focus.history.previous()
  194.             if client.focus then
  195.                 client.focus:raise()
  196.             end
  197.         end),
  198.  
  199.     -- Standard program
  200.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  201.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  202.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  203.  
  204.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  205.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  206.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  207.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  208.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  209.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  210.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  211.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  212.  
  213.     -- Prompt
  214.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  215.  
  216.     awful.key({ modkey }, "x",
  217.               function ()
  218.                   awful.prompt.run({ prompt = "Run Lua code: " },
  219.                   mypromptbox[mouse.screen].widget,
  220.                   awful.util.eval, nil,
  221.                   awful.util.getdir("cache") .. "/history_eval")
  222.               end)
  223. )
  224.  
  225. clientkeys = awful.util.table.join(
  226.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  227.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  228.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  229.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  230.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  231.     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
  232.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  233.     awful.key({ modkey,           }, "n",      function (c) c.minimized = not c.minimized    end),
  234.     awful.key({ modkey,           }, "m",
  235.         function (c)
  236.             c.maximized_horizontal = not c.maximized_horizontal
  237.             c.maximized_vertical   = not c.maximized_vertical
  238.         end)
  239. )
  240.  
  241. -- Compute the maximum number of digit we need, limited to 9
  242. keynumber = 0
  243. for s = 1, screen.count() do
  244.    keynumber = math.min(9, math.max(#tags[s], keynumber));
  245. end
  246.  
  247. -- Bind all key numbers to tags.
  248. -- Be careful: we use keycodes to make it works on any keyboard layout.
  249. -- This should map on the top row of your keyboard, usually 1 to 9.
  250. for i = 1, keynumber do
  251.     globalkeys = awful.util.table.join(globalkeys,
  252.         awful.key({ modkey }, "#" .. i + 9,
  253.                   function ()
  254.                         local screen = mouse.screen
  255.                         if tags[screen][i] then
  256.                             awful.tag.viewonly(tags[screen][i])
  257.                         end
  258.                   end),
  259.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  260.                   function ()
  261.                       local screen = mouse.screen
  262.                       if tags[screen][i] then
  263.                           awful.tag.viewtoggle(tags[screen][i])
  264.                       end
  265.                   end),
  266.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  267.                   function ()
  268.                       if client.focus and tags[client.focus.screen][i] then
  269.                           awful.client.movetotag(tags[client.focus.screen][i])
  270.                       end
  271.                   end),
  272.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  273.                   function ()
  274.                       if client.focus and tags[client.focus.screen][i] then
  275.                           awful.client.toggletag(tags[client.focus.screen][i])
  276.                       end
  277.                   end))
  278. end
  279.  
  280. clientbuttons = awful.util.table.join(
  281.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  282.     awful.button({ modkey }, 1, awful.mouse.client.move),
  283.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  284.  
  285. -- Set keys
  286. root.keys(globalkeys)
  287. -- }}}
  288.  
  289. -- {{{ Rules
  290. /awful.rules.rules = {
  291.     -- All clients will match this rule.
  292.     { rule = { },
  293.       properties = { border_width = beautiful.border_width,
  294.                      border_color = beautiful.border_normal,
  295.                      focus = true,
  296.                      keys = clientkeys,
  297.                      buttons = clientbuttons } },
  298.     { rule = { class = "MPlayer" },
  299.       properties = { floating = true } },
  300.     { rule = { class = "pinentry" },
  301.       properties = { floating = true } },
  302.     { rule = { class = "gimp" },
  303.       properties = { floating = true } },
  304.     -- Set Firefox to always map on tags number 2 of screen 1.
  305.     -- { rule = { class = "Firefox" },
  306.     --   properties = { tag = tags[1][2] } },
  307. }
  308. -- }}}
  309.  
  310. -- {{{ Signals
  311. -- Signal function to execute when a new client appears.
  312. client.add_signal("manage", function (c, startup)
  313.     -- Add a titlebar
  314.     -- awful.titlebar.add(c, { modkey = modkey })
  315.  
  316.     -- Enable sloppy focus
  317.     c:add_signal("mouse::enter", function(c)
  318.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  319.             and awful.client.focus.filter(c) then
  320.             client.focus = c
  321.         end
  322.     end)
  323.  
  324.     if not startup then
  325.         -- Set the windows at the slave,
  326.         -- i.e. put it at the end of others instead of setting it master.
  327.         -- awful.client.setslave(c)
  328.  
  329.         -- Put windows in a smart way, only if they does not set an initial position.
  330.         if not c.size_hints.user_position and not c.size_hints.program_position then
  331.             awful.placement.no_overlap(c)
  332.             awful.placement.no_offscreen(c)
  333.         end
  334.     end
  335. end)
  336.  
  337. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  338. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  339. -- }}}