-
Notifications
You must be signed in to change notification settings - Fork 44
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
Feature/fuzzy stacked win detection #37
Conversation
- stackline/stackline.lua is now a proper module storing fields and methods in a table - Move global variables into stackline module - On every windowFocused event, check to see if screen has changed. If so, refresh stack indicators. The last point is what provides an MVP for multi-monitors support: - `stackline` only renders on the monitor that contains the focused window - Stacks on screens that do not contain the focused window do not have indicators - Because refreshing (query all windows, re-render all stack indicators) is kind of slow (500ms), rapidly switching screens is not a great experience I still think the "proper" solution will require updating the data model to track screens (at least) and potentially spaces. This will enable stackline to render on all screens. If spaces are modeled, it will additionally speed up the rendering of stack indicators when switching between spaces with stacks.
…before equality comparison.
hey @AdamWagner i tested this branch, here is my diff to make it work fixes fuzz rounding and clicks were registered only on top of the icon, probably magic offset should be calculated from config variables. Index: stackline/window.lua
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- stackline/window.lua (revision 3876f8de906e089f74f9a968dcd5fefeb1020195)
+++ stackline/window.lua (date 1600054643343)
@@ -361,11 +361,11 @@
local fuzzFactor = stackline.config:get('frameFuzz')
local roundToFuzzFactor = u.partial(u.roundToNearest, fuzzFactor)
+ print(hsWin:title())
local f = hsWin:frame():floor():gettable()
local ff = u.map(f, roundToFuzzFactor)
- print(hsWin:title(), 'round to neartest 5:', u.roundToNearest(5, 33))
u.p(f)
u.p(ff)
Index: lib/utils.lua
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lib/utils.lua (revision 3876f8de906e089f74f9a968dcd5fefeb1020195)
+++ lib/utils.lua (date 1600055571234)
@@ -366,7 +366,10 @@
end
end -- }}}
-function utils.roundToNearest(roundNum, num) -- {{{
+function utils.roundToNearest(num, roundNum) -- {{{
+ if num < roundNum then
+ return 0
+ end
if num % roundNum >= roundNum / 2 then
return num - num % roundNum + roundNum
else
Index: stackline/stackline.lua
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- stackline/stackline.lua (revision 3876f8de906e089f74f9a968dcd5fefeb1020195)
+++ stackline/stackline.lua (date 1600055571237)
@@ -42,7 +42,7 @@
showIcons = true,
enableTmpFixForHsBug = true,
- -- Window frames are rounded to fuzzFactor before equality comparison.
+ -- Window frames are rounded to fuzzFactor before equality comparison.
-- ~30 is needed to support stacks w/ iTerm
frameFuzz = 30,
}
@@ -106,12 +106,4 @@
stackline.refreshClickTracker()
end):start() -- }}}
--- Delayed start (stackline module needs to be loaded globally before it can reference its own methods)
--- TODO: Add instructions to README.md to call stackline:start(userPrefs) from init.lua, and remove this.
-hs.timer.doUntil(function() -- {{{
- return stackline.manager
-end, function()
- stackline.start()
-end, 0.1) -- }}}
-
return stackline
Index: stackline/stack.lua
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- stackline/stack.lua (revision 3876f8de906e089f74f9a968dcd5fefeb1020195)
+++ stackline/stack.lua (date 1600055571228)
@@ -20,7 +20,7 @@
end, -- }}}
frame = function(self) -- {{{
- -- All stacked windows have the same dimensions,
+ -- All stacked windows have the same dimensions,
-- so the 1st Hs window's frame is ~= to the stack's frame
-- TODO: Incorrect when the 1st window has min-size < stack width. See ./query.lua:104
return self.windows[1]._win:frame()
@@ -69,10 +69,12 @@
end, -- }}}
getWindowByPoint = function(self, point) -- {{{
+ local p = hs.geometry.copy(point)
+ p.y = point.y - 22
local foundWin = u.filter(self.windows, function(w)
local indicatorEls = w.indicator:canvasElements()
local wFrame = hs.geometry.rect(indicatorEls[1].frame)
- return point:inside(wFrame)
+ return p:inside(wFrame)
end)
if #foundWin > 0 then |
Thanks @Coobaha ! I have 3 questions about the diff. I'll start with the trickiest one :-) …fixes fuzz roundingFunction definition The diff swaps argument order in the function definition, but not at the call location. This change makes the number to round the first argument, and the amount to round by the second argument. I take responsibility for the crappy argument naming here :( The purpose of the args was not obvious. But since you say this diff works for you… I'm very curious to know how that's possible :-) -- lib/utils.lua:366
-function utils.roundToNearest(roundNum, num) -- {{{
+function utils.roundToNearest(num, roundNum) -- {{{
+ if num < roundNum then
+ return 0
+ end
if num % roundNum >= roundNum / 2 then
return num - num % roundNum + roundNum
else Call location In
Here we create a new function by partially applying
Here we apply our new function to make a 'fuzzy frame' by rounding each value in the Maybe I'm missing something? Or there are changes that didn't get included in the diff for some reason? …clicks were registered only on top of the iconThis second question is a much simpler, I think :-)
Is this change related to fuzzy window matching? Or, does make the clickable area of the window indicators bigger, so that it's easier to focus a window by clicking its icon? If it's related to fuzzy window matching, then I don't understand it. If it makes the clickable area of the window indicators bigger – then that's a neat idea! It's not essential for making I don't quite understand why shifting probably magic offset should be calculated from config variablesMade it to question number three! I totally agree that But I think maybe you were referring to the … I'm really sorry if I've just totally misunderstand a lot of things in your diff, but I'd like to understand :) |
…com/AdamWagner/stackline into feature/fuzzy-stacked-win-detection * 'feature/fuzzy-stacked-win-detection' of https://github.com/AdamWagner/stackline:
hey @AdamWagner my diff is very random, i was hacking around to make it work without really focusing on proper code :) Please pardon me if it confused you! I will test first case and will tell exact reasons why i swapped it soon. Regarding second question: basically icons very capturing clicks only when top part of icon was clicked. But configurable and magic number I only meant my -22px offset to shift clickable area. I bet that it can be calculated from other variables and logic of placing click indicators. |
@Coobaha I totally get it. Sorry for the homework assignment ;-) The thing is, though, you shouldn't need to make any changes. It should "just work", hehe. So if it doesn't, then I've probably made a mistake somewhere.
Odd, I cannot reproduce this behavior. When I click the bottom 1 - 2 pixels of an icon, the expected window focuses. Maybe we can revisit this icon-clicking issue after this branch is merged into master just to be sure we're testing the same code? This PR is currently up-to-date with my local version, btw. |
So issue with stack detection is happening when yabai space has padding Output with padding
Output without padding
iTerm height is different in this case 😢 |
Maybe stackId should be |
…to account for apps that constrain window size, got better results from simply increasing the frameFuzz factor all the way to 200 (without negative side effects)
Thanks for the update @Coobaha Using So, I totally rewrote how windows are grouped into stacks today. And then scrapped it ;-) The experimental change made everything way more complicated and led to much worse results (and non-deterministic bugs). Somewhat frustrated, I took a long shot by increasing the The change is live here if you want to check it out. PS – thanks for sharing the screen recording of clicking. Am I interpreting it correctly that you're able to click anywhere on an icon to focus a window now? |
with my changes (-22px) yea, click works just fine. Gif is without offset logic. I was clicking 2 and 4 icons top part, when 1 and 3 icon were clicked clicks were captured by 2 and 4 icons I will check the recent changes later, kudos for that 👍 |
@Coobaha any feedback on the updated fuzzy frame matching? |
Hey, I tested it around when you've made the changes but forgot to reply back 🙈 It was working fine, but I was not using stacks/stackline recently - so my testing was not that deep. |
Great to hear, thanks @Coobaha ! |
…com/AdamWagner/stackline into feature/fuzzy-stacked-win-detection * 'feature/fuzzy-stacked-win-detection' of https://github.com/AdamWagner/stackline: Revert update to handleSignal() in config.lua Remove 'self' lib dependency (convert stack.lua to vanilla oop pattern) Remove 'self' lib dependency (convert stack.lua to vanilla oop pattern) New: debug module with smart tbl → json encoding to enable hs data exploration on cli with jq, fx, jid, and gron. Independent ipc msg handlers tbl Use callback to merge yabai query response instead of polling Fix bug with hs.fnutils.reduce mutating its argument Guard against json decode error & try again
@AdamWagner sorry for pinging you back, but i found the root cause of wrong indicator positions/clicks - it depends on menubar. If it is hidden in settings - everything works as expected. If visible - extra offset is added. Please check attached video Kapture.2021-02-07.at.13.55.23.mp4 |
Support iTerm (and other apps that constrict window dimensions) by rounding window frames to (configurable) fuzzFactor before equality comparison.
Addresses need in #32.
Built on top of #36