-
Notifications
You must be signed in to change notification settings - Fork 28
Add native-style screen edge snapping #161
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
Open
chid
wants to merge
1
commit into
pablopunk:main
Choose a base branch
from
chid:feature/screen-edge-snapping-squash
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+171
−8
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constrain edge snapping to screens near the cursor.
Line 253 iterates all
screenSnapRectsand can apply snaps for a different display if only one axis happens to align. On offset multi-monitor layouts this causes jumpy, incorrect snaps.Proposed fix
for screen in screenSnapRects { + guard screen.insetBy(dx: -snapDistance, dy: -snapDistance).contains(cursorCG) else { continue } // An edge shared with an adjacent display (where the cursor currently // sits) is an interior seam, not a real screen edge. Snapping there // traps the window at the boundary instead of letting it cross. let adjacentLeft = screenSnapRects.contains { $0 != screen && abs($0.maxX - screen.minX) <= tolerance && cursorCG.y >= $0.minY && cursorCG.y <= $0.maxY } let adjacentRight = screenSnapRects.contains { $0 != screen && abs($0.minX - screen.maxX) <= tolerance && cursorCG.y >= $0.minY && cursorCG.y <= $0.maxY } let adjacentAbove = screenSnapRects.contains { $0 != screen && abs($0.maxY - screen.minY) <= tolerance && cursorCG.x >= $0.minX && cursorCG.x <= $0.maxX } let adjacentBelow = screenSnapRects.contains { $0 != screen && abs($0.minY - screen.maxY) <= tolerance && cursorCG.x >= $0.minX && cursorCG.x <= $0.maxX }📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is an issue that I noticed that needs a bit of polish, but requires a lot of complexity to get right (as it would need to know the monitor layouts)
A simple solution to reduce the jerky behaviour would also be to have a dynamic guard (on position) or tolerance but fundamentally the snap behaviour and monitor move behaviour requires rework, alternatively you could have it so that snapping doesn't work on the boundaries between monitors.
In my view, I was able to 'work it out' after playing with it over a few minutes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chid, understood — thanks for the context. Theguardline I proposed is actually the "dynamic guard on position" you described: it's a single check that constrains snapping to only the display the cursor is near, without requiring any knowledge of the full monitor layout. It sidesteps the cross-axis false-positive without reworking the broader snap/move logic.That said, the existing adjacency-seam detection already handles the most important case (preventing the window from getting trapped at display boundaries), so the current behaviour is reasonable for an initial release.
If you'd like, I can open a follow-up issue to track the remaining polish (e.g. the cursor-proximity guard + any further multi-monitor move/snap rework) so it doesn't get lost.
🧠 Learnings used