Repository: Hammerspoon/hammerspoon

Issue #2580: hs.window.filter missing events when apps are first launched
Created: 2020-10-29T18:22:58Z
Hammerspoon 0.9.81
macOS 10.15.7

I pulled a bunch of hair out (don't have much to spare!) before searching thru the issues here and realizing that this might be part of a bigger-picture bug in the OS, in Lua, or HS itself.
In a nutshell, I'm using window.filter:subscribe() to temporarily disable certain hotkeys while in certain apps. I don't know of a better way to do this. Here's a simplified snippet of how I'm doing it:
-- keybinds.lua

local l_debug = 4 -- debug loglevel
local log = hs.logger.new('keybinds', l_debug)

local activateEvents = {
  'windowCreated',
  'windowFocused',
  'windowOnScreen',
  'windowVisible',
  'windowUnhidden',
  'windowUnminimized'
}
local deactivateEvents = {
  'windowDestroyed',
  'windowUnfocused',
  'windowNotOnScreen',
  'windowNotVisible',
  'windowHidden',
  'windowMinimized'
}

local f12 = hs.hotkey.bind(nil, "f12", function()
  hs.alert.show("F12 hotkey fired",1)
end)

local f12_disable_apps = {
  Serial = {activeApplication=true},
  TeamViewer = {activeApplication=true},
  ["Parallels Desktop"] = {activeApplication=true},
  default = false
}

local wf_f12 = hs.window.filter.new(f12_disable_apps, 'keybinds', l_debug)
wf_f12:subscribe(activateEvents, function()
  if f12.enabled then
    f12:disable()
    hs.alert.show("F12 disabled",1)
  else
    log.i('received a disable signal but HS says the hotkey is already disabled')
  end
end)
wf_f12:subscribe(deactivateEvents, function()
  if not f12.enabled then
    f12:enable()
    hs.alert.show("F12 enabled",1)
  else
    log.i('received an enable signal but HS says the hotkey is already enabled')
  end
end)
It's not working when the apps are first launched, but DOES work if I switch to another app and then back to one of the blacklisted apps. I played with a few different flavors of this, but couldn't get any of them to work. I even compiled the master branch to see if any recent commits changed things (no)...which brings me back here.
I found these issues which seem like they're related:
#2465 - window/filter.lua throws "attempt to index a nil value" when trying to start a global watcher
#2474 - Window filter subscribe is broken on 0.9.79
#2524 - hs.window.filter.defaultCurrentSpace:getWindows() sometimes missing some windows
#2552 - [WIP] Fix hs.window.filter 0.9.81
Anyone know what's going on with this?

Duplicate issue #2682: New windows are often not picked up by window filters
Created: 2021-02-15T14:37:06Z
I have a few window filters ('hs.window.filter') that I regularly use since several years back. In the latest releases of Hammerspoon, more and more often it seems that new windows are not picked up by the window filters, even though they should match. This used to work perfectly. I have noticed the effect in many different applications (the MS Office suite, IntelliJ IDEA, among others). A work-around that always works is to tell Hammerspoon to re-read it's configuration, so it seems as though the filters pick up the relevant windows at startup, but then fails to register new windows.

Closing comment (2021-02-16T05:52:56Z): Duplicate of #2580?