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

Scroll windows when swiping on trackpad #63

Merged
merged 1 commit into from
Jan 18, 2025
Merged

Scroll windows when swiping on trackpad #63

merged 1 commit into from
Jan 18, 2025

Conversation

mogenson
Copy link
Owner

For each space, cache the virtual window x positions. That's the position the window would be if it were tiled infinitely in each direction (left and right) of the screen. These virtual positions can be negative. In reality, windows that extend past the visible screen are stashed in a one pixel wide margin.

Add a swipe.lua helper utility to detect touches on the trackpad, determine when a swipe gesture begins and ends, and calculate the average delta x and y position changes.

Note, we're unable to handle mouse scroll wheel movements because there is no begin or end event.

In a swipe handler, find the focused window and space and cache the screen geometry to use for future moved updates in the same swipe gesture. Calculate the new x position for each window in the space, bound them to not go past the screen margins, and use window:setTopLeft() to avoid the animation duration. Disable the window moved watcher while a swipe gesture is in progress, and windows are being scrolled.

When a swipe is done, if the focused window has been moved off screen, snap focus to the on screen window closest to the focused window. Then retile to ensure the focused window is completely on screen.

@mogenson mogenson force-pushed the smooth-scrolling branch 2 times, most recently from f6d29c7 to 0c12af8 Compare January 10, 2025 19:44
@mogenson
Copy link
Owner Author

Todo: consider using a simple hash technique to avoid generating and sending a UUID string in the gesture callback.

Eg. Xor

def xor_hash(arr):
    hash_value = 0
    for x in arr:
        hash_value ^= x
    return hash_value

my_array = [1, 2, 3, 4]
hash_value = xor_hash(my_array) 

For each space, cache the virtual window x positions. That's the
position the window would be if it were tiled infinitely in each
direction (left and right) of the screen. These virtual positions can be
negative. In reality, windows that extend past the visible screen are
stashed in a one pixel wide margin.

Add a swipe.lua helper utility to detect touches on the trackpad,
determine when a swipe gesture begins and ends, and calculate the
average delta x and y position changes.

Note, we're unable to handle mouse scroll wheel movements because there
is no begin or end event.

In a swipe handler, find the focused window and space and cache the
screen geometry to use for future moved updates in the same swipe
gesture. Calculate the new x position for each window in the space,
bound them to not go past the screen margins, and use
window:setTopLeft() to avoid the animation duration. Disable the window
moved watcher while a swipe gesture is in progress, and windows are
being scrolled.

When a swipe is done, if the focused window has been moved off screen,
snap focus to the on screen window closest to the focused window. Then
retile to ensure the focused window is completely on screen.
@mogenson mogenson merged commit 5f81257 into main Jan 18, 2025
1 check passed
@mogenson mogenson deleted the smooth-scrolling branch January 18, 2025 17:59
@ChrisW-B
Copy link

Hey just wanted to thank you for this! I've been using it for a day now and it works great and feels so much nicer than using your other gesture spoon, it's a great addition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants