awesome/my.lua
changeset 8 0eae48be1d62
parent 7 03125e413ae3
child 9 56e80afa3e1c
--- a/awesome/my.lua	Mon Oct 27 12:54:34 2014 -0400
+++ b/awesome/my.lua	Fri Jan 02 21:50:10 2015 -0500
@@ -4,6 +4,7 @@
 require("vicious")
 require("wicked")
 require("beautiful")
+require("timer")
 
 local ipairs = ipairs
 local pairs = pairs
@@ -13,6 +14,7 @@
 local vicious = vicious
 local wicked = wicked
 local beautiful = beautiful
+local timer = timer
 
 local capi = {
    keygrabber = keygrabber,
@@ -171,10 +173,14 @@
    ["\t"] = "tab",
 }
 
+local ignored_mods = {
+   ["Mod2"] = true,
+}
+
 local function translate_key(mod, key)
    local skey = ""
    for m,v in pairs(mod) do
-      if v then 
+      if not ignored_mods[v] then 
          skey = skey .. v .. "+"
       end
    end
@@ -264,3 +270,44 @@
    return t
 end
 
+-- Install a sloppy-like focus with a timeout.
+
+function sloppy_toggle()
+   sloppy = not sloppy
+end
+
+function sloppy_mouse_enter(c)
+   if sloppy and
+      c ~= sloppy_last_client and
+      awful.client.focus.filter(c) and
+      awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
+   then
+      sloppy_timer:again()
+      sloppy_last_client = c
+   end
+end
+
+function sloppy_on_timeout()
+   if sloppy
+   then
+      local c = awful.mouse.client_under_pointer()
+      if c and
+         c == sloppy_last_client
+      then
+         capi.client.focus = c
+      end
+    end
+end
+
+sloppy = true
+sloppy_last_client = nil
+sloppy_timer = nil
+
+function sloppy_install(delay)
+   sloppy_timer = timer({ timeout = delay })
+   sloppy_timer:add_signal("timeout", sloppy_on_timeout)
+   sloppy_timer:start()
+   capi.client.add_signal("manage", function (c)
+                             c:add_signal("mouse::enter", sloppy_mouse_enter)
+   end)
+end