Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 3rd, 2013  |  syntax: Lua  |  size: 11.81 KB  |  views: 698  |  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. -- Awesomewm configuration
  2. -- Standard awesome library
  3. local gears = require("gears")
  4. local awful = require("awful")
  5. awful.rules = require("awful.rules")
  6. autofocus = require("awful.autofocus")
  7. ewmh = require("awful.ewmh")
  8. -- Theme handling library
  9. local beautiful = require("beautiful")
  10. -- Notifications
  11. --local naughty = require("naughty")
  12.  
  13. -- {{{ Variable definitions
  14. -- Themes define colours, icons, and wallpapers
  15. beautiful.init(awful.util.getdir("config") .. "/theme.lua")
  16. --beautiful.init("/usr/share/awesome/themes/zenburn/theme.lua")
  17.  
  18. terminal = "konsole"
  19. editor = os.getenv("EDITOR") or "vim"
  20. editor_cmd = terminal .. " -e " .. editor
  21. modkey = "Mod4"
  22.  
  23. -- Table of layouts to cover with awful.layout.inc, order matters.
  24. -- Look for more layouts in apidoc or standard config
  25. local layouts =
  26. {
  27. awful.layout.suit.tile,
  28. awful.layout.suit.floating,
  29. awful.layout.suit.max.fullscreen,
  30. awful.layout.suit.fair
  31. }
  32. -- }}}
  33.  
  34. -- {{{ Tags
  35. -- Define a tag table which hold all screen tags.
  36. tags = {}
  37. for s = 1, screen.count() do
  38. -- Each screen has its own tag table.
  39. tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
  40. end
  41. -- }}}
  42.  
  43. -- {{{ Key bindings
  44. globalkeys = awful.util.table.join(
  45. awful.key({ modkey,           }, "Left",   function () awful.tag.viewprev() end),
  46. awful.key({ modkey,           }, "Right",  function () awful.tag.viewnext() end),
  47. awful.key({ modkey,           }, "j",
  48.     function ()
  49.         awful.client.focus.byidx( 1)
  50.         if client.focus then client.focus:raise() end
  51.     end),
  52. awful.key({ modkey,           }, "k",
  53.     function ()
  54.         awful.client.focus.byidx(-1)
  55.         if client.focus then client.focus:raise() end
  56.     end),
  57.  
  58. -- Layout manipulation
  59. awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  60. awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  61. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  62. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  63. awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  64. awful.key({ modkey,           }, "Tab",
  65.     function ()
  66.         awful.client.focus.history.previous()
  67.         if client.focus then
  68.             client.focus:raise()
  69.         end
  70.     end),
  71.  
  72. -- Standard program
  73. awful.key({ modkey, "Control" }, "r", awesome.restart),
  74. awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  75. awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  76. awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  77. awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  78. awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  79. awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  80. awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  81. awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  82. awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  83. -- TODO Toggle between floating and tile
  84. awful.key({ modkey,           }, "a",     function () awful.layout.set(awful.layout.suit.tile,nil) end),
  85. awful.key({ modkey,           }, "t",     function () awful.layout.set(awful.layout.suit.floating,nil) end),
  86.  
  87. awful.key({ modkey, "Control" }, "n", awful.client.restore)
  88. )
  89.  
  90. clientkeys = awful.util.table.join(
  91. awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  92. awful.key({ modkey,           }, "c",      function (c) c:kill()                         end),
  93. awful.key({ modkey,           }, "x",      awful.client.toggletag(awful.tag.selected(mouse.screen))    ),
  94. awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  95. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  96. awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  97. awful.key({ modkey,           }, "n",
  98.     function (c)
  99.         -- The client currently has the input focus, so it cannot be
  100.         -- minimized, since minimized clients can't have the focus.
  101.         c.minimized = true
  102.     end),
  103. awful.key({ modkey,           }, "m",
  104.     function (c)
  105.         -- No, don't maximize. Maximizing doesn't make sense here
  106.         --c.maximized_horizontal = not c.maximized_horizontal
  107.         --c.maximized_vertical   = not c.maximized_vertical
  108.         c.maximized_horizontal = false
  109.         c.maximized_vertical   = false
  110.     end)
  111. )
  112.  
  113. -- Bind all key numbers to tags.
  114. -- Be careful: we use keycodes to make it works on any keyboard layout.
  115. -- This should map on the top row of your keyboard, usually 1 to 9.
  116. for i = 1, 9 do
  117. globalkeys = awful.util.table.join(globalkeys,
  118.     awful.key({ modkey }, "#" .. i + 9,
  119.               function ()
  120.                     local screen = mouse.screen
  121.                     local tag = awful.tag.gettags(screen)[i]
  122.                     if tag then
  123.                        awful.tag.viewonly(tag)
  124.                     end
  125.               end),
  126.     awful.key({ modkey, "Control" }, "#" .. i + 9,
  127.               function ()
  128.                   local screen = mouse.screen
  129.                   local tag = awful.tag.gettags(screen)[i]
  130.                   if tag then
  131.                      awful.tag.viewtoggle(tag)
  132.                   end
  133.               end),
  134.     awful.key({ modkey, "Shift" }, "#" .. i + 9,
  135.               function ()
  136.                   local tag = awful.tag.gettags(client.focus.screen)[i]
  137.                   if client.focus and tag then
  138.                       awful.client.movetotag(tag)
  139.                  end
  140.               end),
  141.     awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  142.               function ()
  143.                   local tag = awful.tag.gettags(client.focus.screen)[i]
  144.                   if client.focus and tag then
  145.                       awful.client.toggletag(tag)
  146.                   end
  147.               end))
  148. end
  149.  
  150. clientbuttons = awful.util.table.join(
  151. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  152. awful.button({ modkey }, 1, awful.mouse.client.move),
  153. awful.button({ modkey }, 3, awful.mouse.client.resize))
  154.  
  155. -- Set keys
  156. root.keys(globalkeys)
  157. -- }}}
  158.  
  159. -- {{{ Rules
  160. -- TODO: Cleanup
  161. awful.rules.rules = {
  162. { rule = { },
  163.   properties = { border_width = beautiful.border_width,
  164.                  border_color = beautiful.border_normal,
  165.                  focus = awful.client.focus.filter,
  166.                  keys = clientkeys,
  167.                  size_hints_honor = true,
  168.                  buttons = clientbuttons } },
  169. { rule = { class = "Yakuake" },
  170.   properties = { floating = true, ontop = true, above = true,size_hints_honor = true, width=1366, maximized_horizontal = true } },
  171. { rule = { class = "Plasma" },
  172.   properties = { floating = true,sticky=true, size_hints_honor = true } },
  173. --{ rule = { class = "Plasma", type = "dock" },
  174.   --properties = { x = 0, y = 0, size_hints_honor = false } },
  175. { rule_any = { class = { "Plasma-desktop", "gimp", "pinentry", "MPlayer" },
  176.   properties = { floating = true, size_hints_honor = true,maximized_horizontal = false, maximized_vertical = false } } },
  177. { rule = { class = "krunner" },
  178.   properties = { focus = true, ontop = true, size_hints_honor = false } },
  179. { rule = { class = "Steam" },
  180.   properties = { tag = tags[1][4] } },
  181. { rule = { class = "Firefox" },
  182.   properties = { tag = tags[1][2] } },
  183. -- Flashplayer
  184. { rule = { class = "Plugin-container" }, properties = { floating = true } },
  185. { rule = { type = "desktop" },
  186.   properties = { ontop = false, above = false, below = true, border_width = 0 }
  187. }
  188. }
  189. zeroborderrule = { class = {"Plasma-desktop", "gimp", "pinentry", "MPlayer", "Yakuake", "Plasma"} }
  190. zbtable = { rule_any = zeroborderrule, properties = { border_width = 0 } }
  191. for k,v in pairs(zbtable) do awful.rules.rules[k] = v end
  192. --table.insert(awful.rules.rules, zeroborderrule)
  193. -- }}}
  194.  
  195. -- {{{ Signals
  196. -- Signal function to execute when a new client appears.
  197. client.connect_signal("manage", function (c, startup)
  198.     -- Enable sloppy focus
  199.     c:connect_signal("mouse::enter", function(c)
  200.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  201.             and awful.client.focus.filter(c) then
  202.             client.focus = c
  203.         end
  204.     end)
  205.  
  206.     if not startup then
  207.         -- Set the windows at the slave,
  208.         -- i.e. put it at the end of others instead of setting it master.
  209.         -- awful.client.setslave(c)
  210.  
  211.         -- Put windows in a smart way, only if they does not set an initial position.
  212.         if not c.size_hints.user_position and not c.size_hints.program_position then
  213.                 awful.placement.no_overlap(c)
  214.                 awful.placement.no_offscreen(c)
  215.         end
  216.     else -- On startup
  217.         smartborders(c)
  218.     end
  219.     -- Move the desktop to the bottom so it doesn't get focus on tag switching
  220.     -- FIXME: Doesn't work perfectly (breaks when awesome is restarted)
  221.     if c.class == "Plasma" and c.type == "desktop" then
  222.             c:lower()
  223.             --c:unmanage() -- essentially kill it
  224.     end
  225.     -- Move plasmoids under the mouse (without going offscreen) and size them according to their requirements (specified in _minimum_ size hints)
  226.     -- TODO: Avoid struts (probably not struts per se)
  227.     if c.class == "Plasma-desktop" and c.type ~= "dock" and c.skip_taskbar then
  228.             c:geometry( { width = c.size_hints.min_width, height = c.size_hints.min_height } )
  229.             awful.placement.under_mouse(c)
  230.             awful.placement.no_offscreen(c)
  231.             -- FIXME: This has no effect (46 is the width of the plasma panel)
  232.             --c:geometry( { x = c.x + 46 } )
  233.     end
  234.         -- Titlebars could go here
  235. end)
  236.  
  237. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  238. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  239.  
  240. -- Smartborders - don't show borders for the only visible (bordered) window
  241. smartborders = function(c)
  242.     if c then
  243.        if awful.rules.match_any(c, zeroborderrule) then
  244.           -- We've got a non-bordered window, this won't change anything
  245.           c.border_width = 0
  246.           return
  247.        end
  248.     end
  249.     for s = 1, screen.count() do
  250.         local ts = 0
  251.         for _, t in ipairs(awful.tag.selectedlist(s)) do
  252.             for _, cl in ipairs(t:clients()) do
  253.                 -- Only windows that should be bordered count here, so reset them
  254.                if (not awful.rules.match_any(cl, zeroborderrule)) and cl.type ~= "dock" and cl.type ~= "desktop" then
  255.                    ts = ts + 1
  256.                 end
  257.             end
  258.         end
  259.         if ts < 2 then
  260.             for _, t in ipairs(awful.tag.selectedlist(s)) do
  261.                 for _, cl in ipairs(t:clients()) do
  262.                     cl.border_width = 0
  263.                 end
  264.             end
  265.         else -- Need to reset borders as we have more than one window that should be bordered
  266.            for _, t in ipairs(awful.tag.selectedlist(s)) do
  267.               for _, cl in ipairs(t:clients()) do
  268.                  if not awful.rules.match_any(cl, zeroborderrule) then
  269.                    cl.border_width = beautiful.border_width
  270.                  else
  271.                    cl.border_width = 0
  272.                  end
  273.               end
  274.            end
  275.         end
  276.     end
  277. end
  278.  
  279. client.connect_signal("tagged",   smartborders)
  280. client.connect_signal("untagged", smartborders)
  281. -- For when a tag is added or removed (multiple tags)
  282. for s = 1 , screen.count() do
  283.     awful.tag.attached_connect_signal(s, "property::selected", smartborders)
  284.     screen[s]:connect_signal("tag::attach", smartborders)
  285.     screen[s]:connect_signal("tag::detach", smartborders)
  286. end
  287.  
  288. -- }}}