Skip to content

Commit b02ffe7

Browse files
authored
Fix #62: Icon not clickable with multi-monitor layout (#81)
1 parent c7f4e19 commit b02ffe7

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

stackline/stack.lua

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,36 @@ function Stack:deleteAllIndicators() -- {{{
6565
end)
6666
end -- }}}
6767

68-
function Stack:getWindowByPoint(point) -- {{{
69-
local foundWin = u.filter(self.windows, function(w)
70-
local frame = w.indicator and w.indicator:canvasElements()[1].frame
71-
if not frame then return false end
72-
return point:inside(frame) -- NOTE: frame *must* be a hs.geometry.rect instance
73-
end)
68+
function Stack:getWindowByPoint(p)
69+
if p.x < 0 or p.y < 0 then
70+
-- FIX: https://github.com/AdamWagner/stackline/issues/62
71+
-- NOTE: Window indicator frame coordinates are relative to the window's screen.
72+
-- So, if click point has negative X or Y vals, then convert its coordinates
73+
-- to relative to the clicked screen before comparing to window indicator frames.
74+
-- TODO: Clean this up after fix is confirmed
75+
76+
-- Get the screen with frame that contains point 'p'
77+
local function findClickedScreen(_p) -- {{{
78+
return table.unpack(
79+
u.filter(hs.screen.allScreens(), function(s)
80+
return _p:inside(s:frame())
81+
end)
82+
)
83+
end -- }}}
7484

75-
if #foundWin > 0 then
76-
return foundWin[1]
85+
local clickedScren = findClickedScreen(p)
86+
p = clickedScren
87+
and clickedScren:absoluteToLocal(p)
88+
or p
7789
end
90+
91+
return table.unpack(
92+
u.filter(self.windows, function(w)
93+
local indicatorFrame = w.indicator and w.indicator:canvasElements()[1].frame
94+
if not indicatorFrame then return false end
95+
return p:inside(indicatorFrame) -- NOTE: frame *must* be a hs.geometry.rect instance
96+
end)
97+
)
7898
end
7999

80100
return Stack

0 commit comments

Comments
 (0)