Fix up focus-to shortcuts for new hammerspoon

Fri, 04 Jun 2021 23:35:16 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Fri, 04 Jun 2021 23:35:16 -0500
changeset 907
df71b104b773
parent 906
1e388dfbe200
child 908
fa7c0607c00e

Fix up focus-to shortcuts for new hammerspoon

.hammerspoon/init.lua file | annotate | diff | comparison | revisions
--- a/.hammerspoon/init.lua
+++ b/.hammerspoon/init.lua
@@ -6,23 +6,31 @@ local cmd      = hs.fnutils.partial(bind
 local cmdShift = hs.fnutils.partial(bindKey, {"cmd", "shift"})
 local cmdCtrl  = hs.fnutils.partial(bindKey, {"cmd", "ctrl"})
 
-function focusedWindow() return hs.window.focusedWindow() or hs.window.desktop() end
-function focusTo(direction) hs.window['focusWindow' .. direction](focusedWindow()) end
+function focusedWindow()
+  return hs.window.focusedWindow() or hs.window.desktop()
+end
+
+function focusTo(direction)
+  local fn = hs.getObjectMetatable('hs.window')['focusWindow' .. direction]
+  return function ()
+    fn(focusedWindow(), nil, nil, true)
+  end
+end
 
 -- and the key bindings
 cmdShift('r', hs.reload)
 
-cmd('k',  function () focusTo('North') end)
-cmd('up', function () focusTo('North') end)
+cmd('k',  focusTo('North'))
+cmd('up', focusTo('North'))
 
-cmd('j',    function () focusTo('South') end)
-cmd('down', function () focusTo('South') end)
+cmd('j',    focusTo('South'))
+cmd('down', focusTo('South'))
 
-cmd('h',    function () focusTo('West') end)
-cmd('left', function () focusTo('West') end)
+cmd('h',    focusTo('West'))
+cmd('left', focusTo('West'))
 
-cmd('l',     function () focusTo('East') end)
-cmd('right', function () focusTo('East') end)
+cmd('l',     focusTo('East'))
+cmd('right', focusTo('East'))
 
 cmdShift('up', function () focusedWindow():maximize() end)
 

mercurial