Skip to content

Commit

Permalink
wayland: enhance pointer event handling for scroll input
Browse files Browse the repository at this point in the history
  • Loading branch information
gokselk committed Jan 1, 2025
1 parent 6f375e2 commit 55b7c9f
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions window/src/os/wayland/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use smithay_client_toolkit::seat::pointer::{
PointerData, PointerDataExt, PointerEvent, PointerEventKind, PointerHandler,
};
use wayland_client::backend::ObjectId;
use wayland_client::protocol::wl_pointer::{ButtonState, WlPointer};
use wayland_client::protocol::wl_pointer::{AxisSource, ButtonState, WlPointer};
use wayland_client::protocol::wl_seat::WlSeat;
use wayland_client::{Connection, Proxy, QueueHandle};
use wezterm_input_types::MousePress;
Expand Down Expand Up @@ -157,12 +157,29 @@ impl PendingMouse {
PointerEventKind::Axis {
horizontal,
vertical,
source,
..
} => {
let changed = self.scroll.is_none();
let (x, y) = self.scroll.take().unwrap_or((0., 0.));
self.scroll
.replace((x + horizontal.absolute, y + vertical.absolute));

// Handle scroll based on the input source
let (scroll_x, scroll_y) = match source {
// For mouse wheels, use discrete values when available
Some(AxisSource::Wheel) => {
if vertical.discrete != 0 {
(horizontal.discrete as f64, vertical.discrete as f64)
} else {
// Standard wheel click is 15 degrees
(horizontal.absolute / 15.0, vertical.absolute / 15.0)
}
}
// For touchpads and other devices, use a 10x scale
// This is a bit arbitrary, but it's a good starting point
_ => (horizontal.absolute / 10.0, vertical.absolute / 10.0),
};

self.scroll.replace((x + scroll_x, y + scroll_y));
changed
}
}
Expand Down

0 comments on commit 55b7c9f

Please sign in to comment.