Skip to content

Commit 2ede84a

Browse files
authored
wayland: handle axis_value120 scroll events
This can be tested with the `application` example, looking at the events shown for mouse wheel movement. `wl_pointer::axis_discrete` isn't sent in version 8 or higher of `wl_pointer`. And `sctk` doesn't convert the `value120` events, so on compositors advertising version 8, only pixel scroll events were being sent. This sends `MouseScrollDelta::LineDelta` with a fractional value, without doing any accumulation. Given `LineDelta` contains `f32` values, this presumably is expected? Though it might be good to change the definition of `MouseScrollDelta` to include both discrete and pixel values, when the compositor sends both. I'm not familiar with how this works on non-Wayland backends though.
1 parent f046e77 commit 2ede84a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

winit-wayland/src/seat/pointer/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ impl PointerHandler for WinitState {
195195
// Get the current phase.
196196
let mut pointer_data = pointer.winit_data().inner.lock().unwrap();
197197

198+
let has_value120_scroll = horizontal.value120 != 0 || vertical.value120 != 0;
198199
let has_discrete_scroll = horizontal.discrete != 0 || vertical.discrete != 0;
199200

200201
// Figure out what to do about start/ended phases here.
@@ -206,7 +207,7 @@ impl PointerHandler for WinitState {
206207
} else {
207208
match pointer_data.phase {
208209
// Discrete scroll only results in moved events.
209-
_ if has_discrete_scroll => TouchPhase::Moved,
210+
_ if has_value120_scroll || has_discrete_scroll => TouchPhase::Moved,
210211
TouchPhase::Started | TouchPhase::Moved => TouchPhase::Moved,
211212
_ => TouchPhase::Started,
212213
}
@@ -217,7 +218,13 @@ impl PointerHandler for WinitState {
217218

218219
// Mice events have both pixel and discrete delta's at the same time. So prefer
219220
// the discrete values if they are present.
220-
let delta = if has_discrete_scroll {
221+
let delta = if has_value120_scroll {
222+
// NOTE: Wayland sign convention is the inverse of winit.
223+
MouseScrollDelta::LineDelta(
224+
(-horizontal.value120) as f32 / 120.,
225+
(-vertical.value120) as f32 / 120.,
226+
)
227+
} else if has_discrete_scroll {
221228
// NOTE: Wayland sign convention is the inverse of winit.
222229
MouseScrollDelta::LineDelta(
223230
(-horizontal.discrete) as f32,

winit/src/changelog/unreleased.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,4 @@ changelog entry.
268268
- On Windows, `Window::set_theme` will change the title bar color immediately now.
269269
- On Windows 11, prevent incorrect shifting when dragging window onto a monitor with different DPI.
270270
- On Web, device events are emitted regardless of cursor type.
271+
- On Wayland, `axis_value120` scroll events now generate `MouseScrollDelta::LineDelta`

0 commit comments

Comments
 (0)