diff --git a/.hammerspoon/init.lua b/.hammerspoon/init.lua index 6123935..fefbf52 100644 --- a/.hammerspoon/init.lua +++ b/.hammerspoon/init.lua @@ -27,8 +27,29 @@ local apps = { local lastApp = nil local previousAppByKey = {} +local function areStartupModifiersReleased() + local modifiers = hs.eventtap.checkKeyboardModifiers() + + return not modifiers.ctrl and not modifiers.alt and not modifiers.cmd and not modifiers.shift +end + +local function afterStartupModifiersReleased(fn) + if areStartupModifiersReleased() then + fn() + return + end + + local timer = nil + timer = hs.timer.doEvery(0.02, function() + if areStartupModifiersReleased() then + timer:stop() + fn() + end + end) +end + local function bindAppLauncher(key, app) - hs.hotkey.bind(hyper, key, function() + local function launchOrToggleApp() local frontmost = hs.application.frontmostApplication() if frontmost and frontmost:bundleID() == app.bundleID then @@ -47,6 +68,12 @@ local function bindAppLauncher(key, app) end hs.application.launchOrFocusByBundleID(app.bundleID) + end + + -- Delay app launch/focus until startup modifiers are released so apps do + -- not see held Shift/Option/Command/Control during launch. + hs.hotkey.bind(hyper, key, function() end, function() + afterStartupModifiersReleased(launchOrToggleApp) end) end @@ -57,4 +84,4 @@ end -- Special actions hs.hotkey.bind(hyper, "\\", hs.reload) -hs.alert.show("Hammerspoon config loaded") \ No newline at end of file +hs.alert.show("Hammerspoon config loaded")