hammerspoon icon indicating copy to clipboard operation
hammerspoon copied to clipboard

`hs.window.filter.windowFocused` callback is not called sometimes

Open danielefongo opened this issue 3 years ago • 2 comments

Sometimes the hs.window.filter.windowFocused callback is not called when switching between application windows. I cannot understand how to reproduce this issue consistently, but I noticed that the callback start to be triggered again when I focus other apps windows and then go back to the interesting ones.

Below you can see an example of my configuration that sometimes does not work:

local wf = require('hs.window.filter')
wf.new(true):subscribe(wf.windowCreated, function(createdWindow)
    if (aCondition) then
        wf.new(function(win)
            return win == createdWindow
        end):subscribe(wf.windowFocused, function(focusedWindow)
            print("focus", focusedWindow:title())
        end)
    end
end)

I also tried to simplify the configuration, but I get the same problem:

wf.new(true):subscribe(wf.windowFocused, function(focusedWindow)
    print("focus", focusedWindow:title())
end)

danielefongo avatar Dec 19 '21 11:12 danielefongo

Edit:

The problem seems to be related to event emitting. I enabled debug mode for window filter module and I noticed the event works until the apps are registered on window filter:

2021-12-19 12:53:36: global window focus	Get Started
2021-12-19 12:53:37: 12:53:37                 emitting windowFocused 18360 (Code)
2021-12-19 12:53:37: global window focus	Get Started
2021-12-19 12:53:37:                          emitting windowFocused 16984 (Code)
[...]
2021-12-19 12:50:41: 12:50:41    wfilter: new app loginwindow registered
2021-12-19 12:50:41:             wfilter: new app AXVisualSupportAgent registered
[...]
2021-12-19 12:50:42:             wfilter: new app OSDUIHelper registered

After this log the focus event won't be emitted until I swap app focus.

danielefongo avatar Dec 19 '21 11:12 danielefongo

Adding to this thread that I also noticed a hang on the hammerspoon reload when using window.filter. After removing my window.filter call, my reload config is very quick.

AlgusDark avatar Jul 12 '22 12:07 AlgusDark