65
65
-- ┌──────────────────────────────────┐
66
66
-- │ Query window state subscriptions │
67
67
-- └──────────────────────────────────┘
68
+
69
+ local options = {fixSameAppHammerspoonBug = true }
70
+
68
71
-- callback args: window, app, event
69
72
wfd :subscribe (added_changed , function ()
70
73
queryWindowState :start ()
@@ -81,21 +84,41 @@ stacksMgr:update()
81
84
-- │ Update indicators subscriptions │
82
85
-- └─────────────────────────────────┘
83
86
84
- -- DONE: rather than subscribing to windowFocused here, do it only for
85
- -- windows within a stack. This will shorten the update process for focus
86
- -- changes, since we *only* need to update the indicators, not query for new
87
- -- window state entirely.
88
- -- wf.windowFocused,
89
- -- wf.windowUnfocused,
87
+ function unfocusOtherAppWindows (win ) -- {{{
88
+ -- Fix HS bug: windowUnfocused event not fired for same-app windows
89
+ -- https://github.com/Hammerspoon/hammerspoon/issues/2400
90
+ -- NOTE: substantially slows down indicator redraw when focus changes :<
91
+ -- So much so that it probably makes sense to store a "has >1 win
92
+ -- from app" field on each stack
93
+
94
+ -- Related:
95
+ -- ./stack.lua:22
96
+ -- ./stack.lua:30
97
+
98
+ -- v1: Search for stack by window:
99
+ -- E.g., local stack = stacksMgr:findStackByWindow(stackedWin)
100
+ -- v2: Lookup stack from window instead of searching by window ID:
101
+ -- local stack = stackedWin.stack
102
+ -- v3: Store `otherAppWindows` directly on window:
90
103
91
- -- DONE: Parameterize Activate / Deactivate by reading event
104
+ -- See ./stack.lua:22
105
+ each (win .otherAppWindows , function (w )
106
+ w :drawIndicator ({shouldFade = false })
107
+ end )
108
+
109
+ end -- }}}
92
110
93
111
function redrawWinIndicator (hsWin , appName , event )
94
112
local id = hsWin :id ()
95
113
print (event :gsub (' window' , ' ' ), appName , id )
96
114
local stackedWin = stacksMgr :findWindow (id )
97
115
if stackedWin then -- if not found, then focused win is not stacked
98
116
stackedWin :drawIndicator ({shouldFade = false }) -- draw instantly on focus change
117
+
118
+ if options .fixSameAppHammerspoonBug then
119
+ unfocusOtherAppWindows (stackedWin )
120
+ end
121
+
99
122
end
100
123
end
101
124
0 commit comments