Skip to content
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

add snapping to floating windows #8088

Merged
merged 10 commits into from
Oct 21, 2024
Merged

add snapping to floating windows #8088

merged 10 commits into from
Oct 21, 2024

Conversation

myQwil
Copy link
Contributor

@myQwil myQwil commented Oct 11, 2024

Describe your PR, what does it fix/add?

While moving and resizing floating windows, edges and corners will snap to the edges/corners of the monitor or other windows when they get close enough to each other.

It started as an update to @shadowmax31 's PR #3236 , but was eventually changed to behave more similarly to KWin's snapping feature.

It comes with 3 options:

general:snap:enabled - whether it's enabled, off by default

general:snap:window_gap - minimum gap in pixels between windows before snapping. Setting to 0 effectively turns off this method of snapping.

general:snap:monitor_gap - minimum gap in pixels between window and monitor edges before snapping. Again, setting it to 0 effectively turns it off.

Here's a video of it with these settings:

general:snap {
    enabled = true
    window_gap = 25 # pixels
    monitor_gap = 10 # pixels
}
2024-10-11.18-28-50.mp4

Is there anything you want to mention? (unchecked code, possible bugs, found problems, breaking compatibility, etc.)

Not that I can think of.

Is it ready for merging, or does it need work?

Ready to merge.

@myQwil myQwil force-pushed the snap-floating branch 6 times, most recently from 3f26ef3 to f59c049 Compare October 12, 2024 11:26
Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat feat

@myQwil myQwil changed the title add snapping to floating windows WIP: add snapping to floating windows Oct 12, 2024
@myQwil myQwil force-pushed the snap-floating branch 4 times, most recently from 63a2149 to c6597a0 Compare October 14, 2024 01:43
@myQwil myQwil changed the title WIP: add snapping to floating windows add snapping to floating windows Oct 14, 2024
@myQwil myQwil changed the title add snapping to floating windows WIP: add snapping to floating windows Oct 14, 2024
Works for both moving and resizing of windows.
It comes with 3 options:

`general:snap:enabled` - whether it's enabled, off by default

`general:snap:window_gap` - minimum gap in pixels between windows before
snapping. Setting to 0 effectively turns off this method of snapping.

`general:snap:monitor_gap` - minimum gap in pixels between window and
monitor edges before snapping. Again, setting it to 0 effectively turns
it off.
The approach of performing corner snaps after each individual edge snap
results in far fewer scenarios where snapping can occur.

After trying it out for a while, I found that I prefer an approach
that's more prone to snapping.
@myQwil myQwil changed the title WIP: add snapping to floating windows add snapping to floating windows Oct 18, 2024
@vaxerski
Copy link
Member

tag me for review when ready

@myQwil
Copy link
Contributor Author

myQwil commented Oct 18, 2024

@vaxerski ready for review.

EDIT: Sorry, one more change incoming. I've been working under the assumption that all windows share the same border size

- add new line between functions
- use std::function typedef for SnapFn and make snap functions static
- avoid uninitialized variable declarations.
- change ignore condition m_bIsX11 to isX11OverrideRedirect()
- use braces for CBox and Vector2D declarations.
- add SNAP_INVALID to eSnapEdge enum
- use bitshift notation for eSnapEdge and eRectCorner
- make performSnap a non-member function.
Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, wiki mr needed

@vaxerski vaxerski merged commit 4093b99 into hyprwm:main Oct 21, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants