Advertisement
Guest User

Untitled

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