Jedipottsy

awesome wm rc.lua

Mar 10th, 2011
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.16 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. require("wicked")
  8. require("vicious")
  9. -- Theme handling library
  10. require("beautiful")
  11. -- Notification library require("naughty")
  12.  
  13. -- {{{ Variable definitions
  14. -- Themes define colours, icons, and wallpapers
  15. beautiful.init("/home/jedipottsy/.config/awesome/themes/pastel/theme.lua")
  16.  
  17. -- This is used later as the default terminal and editor to run.
  18. terminal = "urxvtc"
  19. editor = os.getenv("EDITOR") or "nano"
  20. editor_cmd = terminal .. " -e " .. editor
  21.  
  22. -- Default modkey.
  23. -- Usually, Mod4 is the key with a logo between Control and Alt.
  24. -- If you do not like this or do not have such a key,
  25. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  26. -- However, you can use another modifier like Mod1, but it may interact with others.
  27. modkey = "Mod4"
  28.  
  29. -- Table of layouts to cover with awful.layout.inc, order matters.
  30. layouts =
  31. {
  32.     awful.layout.suit.tile,
  33.     awful.layout.suit.tile.left,
  34.     awful.layout.suit.tile.bottom,
  35.     awful.layout.suit.tile.top,
  36.     awful.layout.suit.fair,
  37.     awful.layout.suit.fair.horizontal,
  38.     awful.layout.suit.max,
  39. }
  40. -- }}}
  41.  
  42. -- {{{ Tags
  43. -- Define a tag table which hold all screen tags.
  44. tags = {
  45.     names = { "main", "web", "terminal", "social", "music" },
  46.     layout = { layouts[1], layouts[7], layouts[1], layouts[1], layouts[7] }
  47. }
  48. for s = 1, screen.count() do
  49.     -- Each screen has its own tag table.
  50.     tags[s] = awful.tag(tags.names, s, tags.layout)
  51. end
  52. -- }}}
  53.  
  54. -- {{{ Menu
  55. -- Create a laucher widget and a main menu
  56. myawesomemenu = {
  57.    { "manual", terminal .. " -e man awesome" },
  58.    { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
  59.    { "reload", awesome.restart },
  60.    { "lock", terminal .. " -e xscreensaver-command --lock" },
  61.    { "restart", terminal .. " -e sudo shutdown -r now" },
  62.    { "shutdown", terminal .. " -e sudo shutdown -h now" },
  63.    { "quit", awesome.quit }
  64. }
  65.  
  66. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  67.                                     { "open terminal", terminal }
  68.                                   }
  69.                         })
  70.  
  71. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  72.                                      menu = mymainmenu })
  73. -- }}}
  74.  
  75. -- {{{ Wibox
  76. -- Create a textclock widget
  77. mytextclock = awful.widget.textclock()
  78.  
  79. -- Create a wibox for each screen and add it
  80. mywibox = {}
  81. mypromptbox = {}
  82. mylayoutbox = {}
  83. mytaglist = {}
  84. mytaglist.buttons = awful.util.table.join(
  85.                     awful.button({ }, 1, awful.tag.viewonly),
  86.                     awful.button({ modkey }, 1, awful.client.movetotag),
  87.                     awful.button({ }, 3, awful.tag.viewtoggle),
  88.                     awful.button({ modkey }, 3, awful.client.toggletag),
  89.                     awful.button({ }, 4, awful.tag.viewnext),
  90.                     awful.button({ }, 5, awful.tag.viewprev)
  91.                     )
  92. mytasklist = {}
  93. mytasklist.buttons = awful.util.table.join(
  94.                      awful.button({ }, 1, function (c)
  95.                                               if not c:isvisible() then
  96.                                                   awful.tag.viewonly(c:tags()[1])
  97.                                               end
  98.                                               client.focus = c
  99.                                               c:raise()
  100.                                           end),
  101.                      awful.button({ }, 3, function ()
  102.                                               if instance then
  103.                                                   instance:hide()
  104.                                                   instance = nil
  105.                                               else
  106.                                                   instance = awful.menu.clients({ width=250 })
  107.                                               end
  108.                                           end),
  109.                      awful.button({ }, 4, function ()
  110.                                               awful.client.focus.byidx(1)
  111.                                               if client.focus then client.focus:raise() end
  112.                                           end),
  113.                      awful.button({ }, 5, function ()
  114.                                               awful.client.focus.byidx(-1)
  115.                                               if client.focus then client.focus:raise() end
  116.                                           end))
  117.  
  118. for s = 1, screen.count() do
  119.     -- Create a promptbox for each screen
  120.     mypromptbox[s] = awful.widget.prompt()
  121.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  122.     -- We need one layoutbox per screen.
  123.     mylayoutbox[s] = awful.widget.layoutbox(s)
  124.     mylayoutbox[s]:buttons(awful.util.table.join(
  125.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  126.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  127.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  128.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  129.     -- Create a taglist widget
  130.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  131.  
  132.     -- Create a tasklist widget
  133.     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  134.  
  135.     -- Create the wibox
  136.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  137.  
  138.     -- Widgets that are aligned to the left
  139.     local left_layout = wibox.layout.fixed.horizontal()
  140.     left_layout:add(mytaglist[s])
  141.     left_layout:add(mypromptbox[s])
  142.  
  143.     -- Widgets that are aligned to the right
  144.     local right_layout = wibox.layout.fixed.horizontal()
  145.     if s == 1 then right_layout:add(wibox.widget.systray()) end
  146.     right_layout:add(mytextclock)
  147.     right_layout:add(mylayoutbox[s])
  148.  
  149.     -- Now bring it all together (with the tasklist in the middle)
  150.     local layout = wibox.layout.align.horizontal()
  151.     layout:set_left(left_layout)
  152.     layout:set_middle(mytasklist[s])
  153.     layout:set_right(right_layout)
  154.  
  155.     mywibox[s]:set_widget(layout)
  156. end
  157. -- }}}
  158.  
  159. -- {{{ Mouse bindings
  160. root.buttons(awful.util.table.join(
  161.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  162.     awful.button({ }, 4, awful.tag.viewnext),
  163.     awful.button({ }, 5, awful.tag.viewprev)
  164. ))
  165. -- }}}
  166.  
  167. -- {{{ Key bindings
  168. globalkeys = awful.util.table.join(
  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.     -- Applications
  205.  
  206.     awful.key({ modkey,       }, "e", function ()
  207. awful.util.spawn("chromium-browser") end),
  208.  
  209.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  210.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  211.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  212.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  213.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  214.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  215.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  216.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  217.  
  218.     awful.key({ modkey, "Control" }, "n", awful.client.restore),
  219.  
  220.     -- Prompt
  221.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  222.  
  223.     awful.key({ modkey }, "x",
  224.               function ()
  225.                   awful.prompt.run({ prompt = "Run Lua code: " },
  226.                   mypromptbox[mouse.screen].widget,
  227.                   awful.util.eval, nil,
  228.                   awful.util.getdir("cache") .. "/history_eval")
  229.               end)
  230. )
  231.  
  232. clientkeys = awful.util.table.join(
  233.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  234.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  235.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  236.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  237.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  238.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  239.     awful.key({ modkey,           }, "n",      function (c) c.minimized = not c.minimized    end),
  240.     awful.key({ modkey,           }, "m",
  241.         function (c)
  242.             c.maximized_horizontal = not c.maximized_horizontal
  243.             c.maximized_vertical   = not c.maximized_vertical
  244.         end)
  245. )
  246.  
  247. -- Compute the maximum number of digit we need, limited to 9
  248. keynumber = 0
  249. for s = 1, screen.count() do
  250.    keynumber = math.min(9, math.max(#tags[s], keynumber));
  251. end
  252.  
  253. -- Bind all key numbers to tags.
  254. -- Be careful: we use keycodes to make it works on any keyboard layout.
  255. -- This should map on the top row of your keyboard, usually 1 to 9.
  256. for i = 1, keynumber do
  257.     globalkeys = awful.util.table.join(globalkeys,
  258.         awful.key({ modkey }, "#" .. i + 9,
  259.                   function ()
  260.                         local screen = mouse.screen
  261.                         if tags[screen][i] then
  262.                             awful.tag.viewonly(tags[screen][i])
  263.                         end
  264.                   end),
  265.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  266.                   function ()
  267.                       local screen = mouse.screen
  268.                       if tags[screen][i] then
  269.                           awful.tag.viewtoggle(tags[screen][i])
  270.                       end
  271.                   end),
  272.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  273.                   function ()
  274.                       if client.focus and tags[client.focus.screen][i] then
  275.                           awful.client.movetotag(tags[client.focus.screen][i])
  276.                       end
  277.                   end),
  278.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  279.                   function ()
  280.                       if client.focus and tags[client.focus.screen][i] then
  281.                           awful.client.toggletag(tags[client.focus.screen][i])
  282.                       end
  283.                   end))
  284. end
  285.  
  286. clientbuttons = awful.util.table.join(
  287.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  288.     awful.button({ modkey }, 1, awful.mouse.client.move),
  289.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  290.  
  291. -- Set keys
  292. root.keys(globalkeys)
  293. -- }}}
  294.  
  295. -- {{{ Rules
  296. awful.rules.rules = {
  297.     -- All clients will match this rule.
  298.    { rule = { },
  299.       properties = { border_width = beautiful.border_width,
  300.                      border_color = beautiful.border_normal,
  301.                      focus = true,
  302.                      keys = clientkeys,
  303.                      buttons = clientbuttons } },
  304.     { rule = { class = "MPlayer" },
  305.       properties = { floating = true } },
  306.     { rule = { class = "pinentry" },
  307.       properties = { floating = true } },
  308.     { rule = { class = "gimp" },
  309.       properties = { floating = true } },
  310.  
  311.    { rule = { class = "chrome" } ,
  312.       properties = { tag = tags[1][1] , switchtotag = true } }
  313.  
  314.     -- Set Firefox to always map on tags number 2 of screen 1.
  315.     -- { rule = { class = "Firefox" },
  316.     --   properties = { tag = tags[1][2] } },
  317. }
  318. -- }}}
  319.  
  320. -- {{{ Signals
  321. -- Signal function to execute when a new client appears.
  322. client.connect_signal("manage", function (c, startup)
  323.     -- Enable sloppy focus
  324.     c:connect_signal("mouse::enter", function(c)
  325.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  326.             and awful.client.focus.filter(c) then
  327.             client.focus = c
  328.         end
  329.     end)
  330.  
  331.     if not startup then
  332.         -- Set the windows at the slave,
  333.         -- i.e. put it at the end of others instead of setting it master.
  334.         -- awful.client.setslave(c)
  335.  
  336.         -- Put windows in a smart way, only if they does not set an initial position.
  337.         if not c.size_hints.user_position and not c.size_hints.program_position then
  338.             awful.placement.no_overlap(c)
  339.             awful.placement.no_offscreen(c)
  340.         end
  341.     end
  342. end)
  343.  
  344. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  345. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  346. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment