Advertisement
Guest User

rc.default

a guest
Apr 12th, 2011
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.80 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.  
  12. -- {{{ Variable definitions
  13. -- Themes define colours, icons, and wallpapers
  14. beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  15.  
  16. -- This is used later as the default terminal and editor to run.
  17. terminal = "xterm"
  18. editor = os.getenv("EDITOR") or "nano"
  19. editor_cmd = terminal .. " -e " .. editor
  20.  
  21. -- Default modkey.
  22. -- Usually, Mod4 is the key with a logo between Control and Alt.
  23. -- If you do not like this or do not have such a key,
  24. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  25. -- However, you can use another modifier like Mod1, but it may interact with others.
  26. modkey = "Mod4"
  27.  
  28. -- Table of layouts to cover with awful.layout.inc, order matters.
  29. layouts =
  30. {
  31.     awful.layout.suit.floating,
  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.spiral,
  39.     awful.layout.suit.spiral.dwindle,
  40.     awful.layout.suit.max,
  41.     awful.layout.suit.max.fullscreen,
  42.     awful.layout.suit.magnifier
  43. }
  44. -- }}}
  45.  
  46. -- {{{ Tags
  47. -- Define a tag table which hold all screen tags.
  48. tags = {}
  49. for s = 1, screen.count() do
  50.     -- Each screen has its own tag table.
  51.     tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
  52. end
  53. -- }}}
  54.  
  55. -- {{{ Menu
  56. -- Create a laucher widget and a main menu
  57. myawesomemenu = {
  58.    { "manual", terminal .. " -e man awesome" },
  59.    { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
  60.    { "restart", awesome.restart },
  61.    { "quit", awesome.quit }
  62. }
  63.  
  64. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  65.                                     { "open terminal", terminal }
  66.                                   }
  67.                         })
  68.  
  69. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  70.                                      menu = mymainmenu })
  71. -- }}}
  72.  
  73. -- {{{ Wibox
  74. -- Create a textclock widget
  75. mytextclock = awful.widget.textclock()
  76.  
  77. -- Create a wibox for each screen and add it
  78. mywibox = {}
  79. mypromptbox = {}
  80. mylayoutbox = {}
  81. mytaglist = {}
  82. mytaglist.buttons = awful.util.table.join(
  83.                     awful.button({ }, 1, awful.tag.viewonly),
  84.                     awful.button({ modkey }, 1, awful.client.movetotag),
  85.                     awful.button({ }, 3, awful.tag.viewtoggle),
  86.                     awful.button({ modkey }, 3, awful.client.toggletag),
  87.                     awful.button({ }, 4, awful.tag.viewnext),
  88.                     awful.button({ }, 5, awful.tag.viewprev)
  89.                     )
  90. mytasklist = {}
  91. mytasklist.buttons = awful.util.table.join(
  92.                      awful.button({ }, 1, function (c)
  93.                                               if not c:isvisible() then
  94.                                                   awful.tag.viewonly(c:tags()[1])
  95.                                               end
  96.                                               client.focus = c
  97.                                               c:raise()
  98.                                           end),
  99.                      awful.button({ }, 3, function ()
  100.                                               if instance then
  101.                                                   instance:hide()
  102.                                                   instance = nil
  103.                                               else
  104.                                                   instance = awful.menu.clients({ width=250 })
  105.                                               end
  106.                                           end),
  107.                      awful.button({ }, 4, function ()
  108.                                               awful.client.focus.byidx(1)
  109.                                               if client.focus then client.focus:raise() end
  110.                                           end),
  111.                      awful.button({ }, 5, function ()
  112.                                               awful.client.focus.byidx(-1)
  113.                                               if client.focus then client.focus:raise() end
  114.                                           end))
  115.  
  116. for s = 1, screen.count() do
  117.     -- Create a promptbox for each screen
  118.     mypromptbox[s] = awful.widget.prompt()
  119.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  120.     -- We need one layoutbox per screen.
  121.     mylayoutbox[s] = awful.widget.layoutbox(s)
  122.     mylayoutbox[s]:buttons(awful.util.table.join(
  123.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  124.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  125.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  126.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  127.     -- Create a taglist widget
  128.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  129.  
  130.     -- Create a tasklist widget
  131.     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  132.  
  133.     -- Create the wibox
  134.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  135.  
  136.     -- Widgets that are aligned to the left
  137.     local left_layout = wibox.layout.fixed.horizontal()
  138.     left_layout:add(mylauncher)
  139.     left_layout:add(mytaglist[s])
  140.     left_layout:add(mypromptbox[s])
  141.  
  142.     -- Widgets that are aligned to the right
  143.     local right_layout = wibox.layout.fixed.horizontal()
  144.     if s == 1 then right_layout:add(wibox.widget.systray()) end
  145.     right_layout:add(mytextclock)
  146.     right_layout:add(mylayoutbox[s])
  147.  
  148.     -- Now bring it all together (with the tasklist in the middle)
  149.     local layout = wibox.layout.align.horizontal()
  150.     layout:set_left(left_layout)
  151.     layout:set_middle(mytasklist[s])
  152.     layout:set_right(right_layout)
  153.  
  154.     mywibox[s]:set_widget(layout)
  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({ modkey,           }, "Left",   awful.tag.viewprev       ),
  169.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  170.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  171.  
  172.     awful.key({ modkey,           }, "j",
  173.         function ()
  174.             awful.client.focus.byidx( 1)
  175.             if client.focus then client.focus:raise() end
  176.         end),
  177.     awful.key({ modkey,           }, "k",
  178.         function ()
  179.             awful.client.focus.byidx(-1)
  180.             if client.focus then client.focus:raise() end
  181.         end),
  182.     awful.key({ modkey,           }, "w", function () mymainmenu:show({keygrabber=true}) end),
  183.  
  184.     -- Layout manipulation
  185.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  186.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  187.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  188.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  189.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  190.     awful.key({ modkey,           }, "Tab",
  191.         function ()
  192.             awful.client.focus.history.previous()
  193.             if client.focus then
  194.                 client.focus:raise()
  195.             end
  196.         end),
  197.  
  198.     -- Standard program
  199.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  200.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  201.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  202.  
  203.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  204.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  205.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  206.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  207.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  208.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  209.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  210.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  211.  
  212.     awful.key({ modkey, "Control" }, "n", awful.client.restore),
  213.  
  214.     -- Prompt
  215.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  216.  
  217.     awful.key({ modkey }, "x",
  218.               function ()
  219.                   awful.prompt.run({ prompt = "Run Lua code: " },
  220.                   mypromptbox[mouse.screen].widget,
  221.                   awful.util.eval, nil,
  222.                   awful.util.getdir("cache") .. "/history_eval")
  223.               end)
  224. )
  225.  
  226. clientkeys = awful.util.table.join(
  227.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  228.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  229.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  230.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  231.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  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.connect_signal("manage", function (c, startup)
  313.     -- Enable sloppy focus
  314.     c:connect_signal("mouse::enter", function(c)
  315.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  316.             and awful.client.focus.filter(c) then
  317.             client.focus = c
  318.         end
  319.     end)
  320.  
  321.     if not startup then
  322.         -- Set the windows at the slave,
  323.         -- i.e. put it at the end of others instead of setting it master.
  324.         -- awful.client.setslave(c)
  325.  
  326.         -- Put windows in a smart way, only if they does not set an initial position.
  327.         if not c.size_hints.user_position and not c.size_hints.program_position then
  328.             awful.placement.no_overlap(c)
  329.             awful.placement.no_offscreen(c)
  330.         end
  331.     end
  332. end)
  333.  
  334. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  335. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  336. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement