Add my.sloppy
authorFabien Ninoles <fabien@tzone.org>
Fri, 02 Jan 2015 21:50:10 -0500
changeset 8 0eae48be1d62
parent 7 03125e413ae3
child 9 56e80afa3e1c
Add my.sloppy Deactivate shifty.sloppy and add my own sloppy (with timer). Also add some minor fixes and improvements.
awesome/my.lua
awesome/rc.lua
--- 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
--- a/awesome/rc.lua	Mon Oct 27 12:54:34 2014 -0400
+++ b/awesome/rc.lua	Fri Jan 02 21:50:10 2015 -0500
@@ -45,6 +45,7 @@
 
 -- This is used later as the default terminal and editor to run.
 terminal = "x-terminal-emulator"
+-- terminal = "terminology"
 editor = os.getenv("EDITOR") or "editor"
 editor_cmd = terminal .. " -e " .. editor
 browser = "iceweasel"
@@ -54,6 +55,9 @@
 filemanager = "pcmanfm"
 lookup = "pcmanfm -f"
 calculator = "galculator"
+-- Logout method
+-- logout = awesome.quit
+logout = my.mkspawn("obsession-logout")
 
 -- Default modkey.
 -- Usually, Mod4 is the key with a logo between Control and Alt.
@@ -89,6 +93,9 @@
 -- Define if we want to use titlebar on all applications.
 use_titlebar = true
 
+-- Remove the focus follow mouse install by shifty.
+shifty.config.sloppy = false
+
 -- Shifty configured tags.
 shifty.config.tags = {
    w1 = {
@@ -105,33 +112,33 @@
       mwfact      = 0.65,
       exclusive   = true,
       max_clients = 1,
-      position    = 4,
+      position    = 2,
       spawn       = browser,
    },
    mail = {
       layout    = awful.layout.suit.tile,
       mwfact    = 0.55,
       exclusive = false,
-      position  = 5,
+      position  = 3,
       spawn     = mail,
       slave     = true
    },
+   steam = {
+      layout      = awful.layout.suit.float,
+      mwfact      = 0.65,
+      exclusive   = true,
+      spawn       = "steam",
+      position    = 4,
+   },
    media = {
       layout    = awful.layout.suit.float,
       exclusive = false,
-      position  = 8,
+      position  = 5,
       spawn     = musicplayer
    },
    office = {
       layout   = awful.layout.suit.tile,
-      position = 9,
-   },
-   steam = {
-      layout      = awful.layout.suit.max,
-      mwfact      = 0.65,
-      exclusive   = true,
-      spawn       = "steam",
-      position    = 6,
+      position = 6,
    },
 }
 
@@ -208,6 +215,10 @@
       tag = "steam",
    },
    {
+      match = { "kupfer.py" },
+      slave = true,
+   },
+   {
       match = {""},
       buttons = awful.util.table.join(
          awful.button({}, 1, function (c) client.focus = c; c:raise() end),
@@ -215,6 +226,8 @@
                client.focus = c
                c:raise()
                awful.mouse.client.move(c)
+               -- awful.mouse.client.dragtotag.border(c)
+               -- awful.mouse.client.dragtotag.widget(c)
          end),
          awful.button({modkey}, 3, awful.mouse.client.resize)
       )
@@ -230,7 +243,7 @@
 --  * run : function to exec when shifty creates a new tag
 --  * all other parameters (e.g. layout, mwfact) follow awesome's tag API
 shifty.config.defaults = {
-   layout = awful.layout.suit.tile.bottom,
+   layout = awful.layout.suit.tile,
    ncol = 1,
    mwfact = 0.60,
    floatBars = true,
@@ -388,7 +401,7 @@
             function () awful.tag.viewprev(); return true; end),
    my.make_key("Down", "View next", 
             function () awful.tag.viewnext(); return true; end),
-   my.make_key("Shift+Up", "Move tag left", 
+   my.make_key("Shift+Up", "Move tag right", 
             function()
                local t = awful.tag.selected()
                local s = awful.util.cycle(screen.count(), t.screen + 1)
@@ -397,10 +410,10 @@
                awful.tag.viewonly(t)
                return true
    end),
-   my.make_key("Shift+Right", "Move tag left", 
+   my.make_key("Shift+Down", "Move tag left", 
             function()
                local t = awful.tag.selected()
-               local s = awful.util.cycle(screen.count(), t.screen + 1)
+               local s = awful.util.cycle(screen.count(), t.screen - 1)
                awful.tag.history.restore()
                t = shifty.tagtoscr(s, t)
                awful.tag.viewonly(t)
@@ -418,8 +431,9 @@
    --                for client.
    --                my.kill_all(function (c)
    my.make_key("r", "Restart", awesome.restart),
-   my.make_key("q", "Quit", awesome.quit),
+   my.make_key("q", "Quit", logout),
    my.make_key("t", "Terminal", my.mkspawn(terminal)),
+   my.make_key("f", "Toggle sloppy mouse", my.sloppy_toggle)
 }
 
 local layout_keys = {
@@ -590,21 +604,21 @@
    globalkeys = awful.util.table.join(
       globalkeys,
       awful.key({modkey}, k, function()
-            local t =  awful.tag.viewonly(shifty.getpos(i))
+            local t =  awful.tag.viewonly(shifty.getpos(i-1))
       end),
       awful.key({modkey, "Control"}, k, function()
-            local t = shifty.getpos(i)
+            local t = shifty.getpos(i-1)
             t.selected = not t.selected
       end),
       awful.key({modkey, "Control", "Shift"}, k, function()
             if client.focus then
-               awful.client.toggletag(shifty.getpos(i))
+               awful.client.toggletag(shifty.getpos(i-1))
             end
       end),
       -- move clients to other tags
       awful.key({modkey, "Shift"}, k, function()
             if client.focus then
-               t = shifty.getpos(i)
+               t = shifty.getpos(i-1)
                awful.client.movetotag(t)
                awful.tag.viewonly(t)
             end
@@ -629,6 +643,7 @@
 -- Hook function to execute when focusing a client.
 client.add_signal("focus", 
                   function(c)
+                     -- my.notify_error("Client focus:\n" .. debug.traceback())
                      if not awful.client.ismarked(c) then
                         c.border_color = beautiful.border_focus
                         c.opacity = 1.0
@@ -643,3 +658,4 @@
                      end
 end)
 
+my.sloppy_install(0.5)