diff options
author | Jesse Luehrs <doy@stripe.com> | 2018-12-05 08:13:34 -0800 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2018-12-05 08:14:12 -0800 |
commit | 4f05efa85b7ee9e080537e70c427f78dd8df5131 (patch) | |
tree | bae422727cf08b44f0f0e26d751aeaa714b82b9b | |
parent | 020e815a31e9282c1e7e0040d8ea8646aecbc2b4 (diff) | |
download | conf-4f05efa85b7ee9e080537e70c427f78dd8df5131.tar.gz conf-4f05efa85b7ee9e080537e70c427f78dd8df5131.zip |
simplify frontmost application tracking
-rw-r--r-- | hammerspoon/init.lua | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/hammerspoon/init.lua b/hammerspoon/init.lua index 380e540..40e74e4 100644 --- a/hammerspoon/init.lua +++ b/hammerspoon/init.lua @@ -108,7 +108,6 @@ end) -- hs.eventtap.keyStroke({"cmd", "option"}, "i") -- end) -possibly_active_apps = {} current_app_name = nil function enter_bindings(name) @@ -126,23 +125,15 @@ function exit_bindings(name) end -- the application watcher receives notifications about new apps being --- activated before the old apps are deactivated, so we have to hack around --- that a bit +-- activated before the old apps are deactivated, so we can't rely on +-- deactivated events. this should be fine because there should always be an +-- active app (at the very least, Finder) current_application_watcher = hs.application.watcher.new(function(name, event_type, app) if event_type == hs.application.watcher.activated then - possibly_active_apps[app:pid()] = app - elseif event_type == hs.application.watcher.deactivated then - possibly_active_apps[app:pid()] = nil - end - - apps = {} - for _, v in pairs(possibly_active_apps) do - table.insert(apps, v) - end - - if #apps == 1 and apps[1]:name() ~= current_app_name then - exit_bindings(current_app_name) - enter_bindings(apps[1]:name()) + if current_app_name ~= app:name() then + exit_bindings(current_app_name) + enter_bindings(app:name()) + end end end) enter_bindings(hs.application.frontmostApplication():name()) |