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

Improve Wayland scroll behavior #6533

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking that adding a couple of config options would be a good idea, at least until we can dial things in to be great by default.

Over in this other PR:

  • Add Wayland Scroll Factor #5104
    a general scroll factor was added; I don't really want to do that, but that PR does show how you can add a config option and plumb it through.

I'm thinking that perhaps it would be good to add:

  • wayland_scroll_wheel_factor
  • wayland_scroll_finger_factor
  • wayland_scroll_continuous_factor
  • wayland_scroll_tilt_factor
  • wayland_scroll_unknown_source_factor

eg: one option for each of the possible axis source enum values, and one for the unknown source case.

I'm not 100% sure how to reconcile the discrete vs. absolute cases for the wheel. Do we permute these options so that we have eg: wayland_scroll_wheel_discrete_factor and wayland_scroll_wheel_absolute_factor ?
Those could default to 1 and 15 to match the logic above, but that would allow the user to fine tune this stuff if necessary.

}
}
// 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