Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hs.keycodes.inputSourceChanged firing is delayed in apps other than HS itself #1499

Open
decadent opened this issue Jul 24, 2017 · 1 comment

Comments

@decadent
Copy link

I'm using Hammerspoon 0.9.55 on OSX El Capitan.

In short, hs.keycodes.inputSourceChanged events aren't delivered until the next one comes in.

To reproduce, you'll need more than one input source, of course. The code is as follows:

math.randomseed(os.time())

local charset = {}
-- qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890
for i = 48,  57 do table.insert(charset, string.char(i)) end
for i = 65,  90 do table.insert(charset, string.char(i)) end
for i = 97, 122 do table.insert(charset, string.char(i)) end

-- this is used only to see new console messages easily
function randomString(length)
  if length > 0 then
    return randomString(length - 1) .. charset[math.random(1, #charset)]
  else
    return ""
  end
end

-----------------------------

foo = hs.distributednotifications.new(
    function(name, object, userInfo)
        print("notification: " .. name .. "\n")
    end,
    -- or 'AppleSelectedInputSourcesChangedNotification'
    'com.apple.Carbon.TISNotifySelectedKeyboardInputSourceChanged'
)
foo:start()

hs.keycodes.inputSourceChanged(function()
    print("changed the layout to " .. hs.keycodes.currentSourceID() .. "; " .. randomString(6) .. "\n")
end)

Now, when the focused window is Hammerspoon, both system notification and inputSourceChanged are delivered at once when the input source is changed, with inputSourceChanged coming in after the system notifications. However, if you switch to another application and change the input source, the first inputSourceChanged event is not delivered, and then new events fire before the system notification. Finally, if you switch back to Hammerspoon, one inputSourceChanged is fired immediately out of nowhere. All of this suggests that inputSourceChanged events are delayed until the next one comes.

I've tried hiding Hammerspoon altogether and using alerts instead of the console, nothing changes. The last event is delivered when I click the menu icon.

The obvious workaround is obvious: subscribe to the system notifications instead of inputSourceChanged. So I guess it's not a pressing issue, but hs.keycodes.inputSourceChanged is still pretty much broken.

@vbauerster
Copy link

I can confirm it's still the same with Version 0.9.75 (0.9.75).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants