Skip to content

Commit

Permalink
linux: Various X11 scroll improvements (#18484)
Browse files Browse the repository at this point in the history
Closes  #14089, #14416, #15970, #17230, #18485

Release Notes:

- Fixed some cases where Linux X11 mouse scrolling doesn't work at all
(#14089, ##15970, #17230)
- Fixed handling of switching between Linux X11 devices used for
scrolling (#14416, #18485)

Change details:

Also includes the commit from PR #18317 so I don't have to deal with
merge conflicts.

* Now uses valuator info from slave pointers rather than master. This
hopefully fixes remaining cases where scrolling is fully
broken. #14089,
#15970,
#17230

* Per-device recording of "last scroll position" used to calculate
deltas. This meant that swithing scroll devices would cause a sudden
jump of scroll position, often to the beginning or end of the
file (#14416).

* Re-queries device metadata when devices change, so that newly
plugged in devices will work, and re-use of device-ids don't use old
metadata with a new device.

* xinput 2 documentation describes support for multiple master
devices. I believe this implementation will support that, since now it
just uses `DeviceInfo` from slave devices. The concept of master
devices is only used in registering for events.

* Uses popcount+bit masking to resolve axis indexes, instead of
iterating bit indices.

---------

Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
  • Loading branch information
mgsloan and mrnugget authored Oct 1, 2024
1 parent 72be8c5 commit 527c909
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 143 deletions.
2 changes: 1 addition & 1 deletion crates/gpui/src/platform/linux/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use crate::{

use super::x11::X11Client;

pub(crate) const SCROLL_LINES: f64 = 3.0;
pub(crate) const SCROLL_LINES: f32 = 3.0;

// Values match the defaults on GTK.
// Taken from https://github.com/GNOME/gtk/blob/main/gtk/gtksettings.c#L320
Expand Down
8 changes: 4 additions & 4 deletions crates/gpui/src/platform/linux/wayland/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1634,10 +1634,10 @@ impl Dispatch<wl_pointer::WlPointer, ()> for WaylandClientStatePtr {
let scroll_delta = state.discrete_scroll_delta.get_or_insert(point(0.0, 0.0));
match axis {
wl_pointer::Axis::VerticalScroll => {
scroll_delta.y += discrete as f32 * axis_modifier * SCROLL_LINES as f32;
scroll_delta.y += discrete as f32 * axis_modifier * SCROLL_LINES;
}
wl_pointer::Axis::HorizontalScroll => {
scroll_delta.x += discrete as f32 * axis_modifier * SCROLL_LINES as f32;
scroll_delta.x += discrete as f32 * axis_modifier * SCROLL_LINES;
}
_ => unreachable!(),
}
Expand All @@ -1662,10 +1662,10 @@ impl Dispatch<wl_pointer::WlPointer, ()> for WaylandClientStatePtr {
let wheel_percent = value120 as f32 / 120.0;
match axis {
wl_pointer::Axis::VerticalScroll => {
scroll_delta.y += wheel_percent * axis_modifier * SCROLL_LINES as f32;
scroll_delta.y += wheel_percent * axis_modifier * SCROLL_LINES;
}
wl_pointer::Axis::HorizontalScroll => {
scroll_delta.x += wheel_percent * axis_modifier * SCROLL_LINES as f32;
scroll_delta.x += wheel_percent * axis_modifier * SCROLL_LINES;
}
_ => unreachable!(),
}
Expand Down
Loading

0 comments on commit 527c909

Please sign in to comment.