From 00ea295a8f99770832573f204e1a78c8c2cd6390 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sun, 4 Feb 2024 19:51:36 +0100 Subject: [PATCH] input: implement wl_seat version 9 --- src/backend.rs | 2 ++ src/backends/metal.rs | 11 +++++++++-- src/backends/metal/input.rs | 2 ++ src/backends/metal/monitor.rs | 3 +++ src/backends/x.rs | 1 + src/cli/seat_test.rs | 20 +++++++++++++++----- src/ifs/jay_seat_events.rs | 5 +++++ src/ifs/wl_seat.rs | 2 +- src/ifs/wl_seat/event_handling.rs | 25 ++++++++++++++++++++----- src/ifs/wl_seat/pointer_owner.rs | 6 ++++-- src/ifs/wl_seat/wl_pointer.rs | 21 +++++++++++++++++---- src/libinput/device.rs | 1 - wire/jay_seat_events.txt | 5 +++++ wire/wl_pointer.txt | 5 +++++ 14 files changed, 89 insertions(+), 20 deletions(-) diff --git a/src/backend.rs b/src/backend.rs index 7ce76fea..47b604ac 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -196,6 +196,7 @@ pub enum InputEvent { AxisPx { dist: Fixed, axis: ScrollAxis, + inverted: bool, }, AxisSource { source: AxisSource, @@ -206,6 +207,7 @@ pub enum InputEvent { Axis120 { dist: i32, axis: ScrollAxis, + inverted: bool, }, AxisFrame { time_usec: u64, diff --git a/src/backends/metal.rs b/src/backends/metal.rs index 5326355d..f827087c 100644 --- a/src/backends/metal.rs +++ b/src/backends/metal.rs @@ -283,6 +283,7 @@ struct MetalInputDevice { events: SyncQueue, cb: CloneCell>>, name: CloneCell>, + natural_scrolling: Cell, // state pressed_keys: SmallMap, @@ -356,7 +357,7 @@ impl MetalInputDevice { dev.device().set_drag_lock_enabled(enabled); } if let Some(enabled) = self.natural_scrolling_enabled.get() { - dev.device().set_natural_scrolling_enabled(enabled); + self.do_set_natural_scrolling_enabled(&dev, enabled); } } @@ -377,6 +378,12 @@ impl MetalInputDevice { }); } } + + fn do_set_natural_scrolling_enabled(&self, dev: &RegisteredDevice, enabled: bool) { + dev.device().set_natural_scrolling_enabled(enabled); + self.natural_scrolling + .set(dev.device().natural_scrolling_enabled()); + } } impl InputDevice for MetalInputDevice { @@ -473,7 +480,7 @@ impl InputDevice for MetalInputDevice { fn set_natural_scrolling_enabled(&self, enabled: bool) { self.natural_scrolling_enabled.set(Some(enabled)); if let Some(dev) = self.inputdev.get() { - dev.device().set_natural_scrolling_enabled(enabled); + self.do_set_natural_scrolling_enabled(&dev, enabled); } } } diff --git a/src/backends/metal/input.rs b/src/backends/metal/input.rs index 2c30595d..6ca6f4e5 100644 --- a/src/backends/metal/input.rs +++ b/src/backends/metal/input.rs @@ -149,11 +149,13 @@ impl MetalBackend { InputEvent::Axis120 { dist: scroll as _, axis, + inverted: dev.natural_scrolling.get(), } } else { InputEvent::AxisPx { dist: Fixed::from_f64(scroll), axis, + inverted: dev.natural_scrolling.get(), } }; dev.event(ie); diff --git a/src/backends/metal/monitor.rs b/src/backends/metal/monitor.rs index 5c981f98..829ad07a 100644 --- a/src/backends/metal/monitor.rs +++ b/src/backends/metal/monitor.rs @@ -287,6 +287,7 @@ impl MetalBackend { events: Default::default(), cb: Default::default(), name: Default::default(), + natural_scrolling: Default::default(), pressed_keys: Default::default(), pressed_buttons: Default::default(), left_handed: Default::default(), @@ -336,6 +337,8 @@ impl MetalBackend { }; inputdev.device().set_slot(slot); dev.name.set(Rc::new(inputdev.device().name())); + dev.natural_scrolling + .set(inputdev.device().natural_scrolling_enabled()); dev.inputdev.set(Some(inputdev)); dev.apply_config(); slf.state diff --git a/src/backends/x.rs b/src/backends/x.rs index 074026fb..d2a96bb7 100644 --- a/src/backends/x.rs +++ b/src/backends/x.rs @@ -799,6 +799,7 @@ impl XBackend { seat.mouse_event(InputEvent::Axis120 { dist: val * AXIS_120, axis, + inverted: false, }); seat.mouse_event(InputEvent::AxisFrame { time_usec: now_usec(), diff --git a/src/cli/seat_test.rs b/src/cli/seat_test.rs index a58567f2..431e01a6 100644 --- a/src/cli/seat_test.rs +++ b/src/cli/seat_test.rs @@ -6,8 +6,8 @@ use { wire::{ jay_compositor::{GetSeats, Seat, SeatEvents}, jay_seat_events::{ - Axis120, AxisFrame, AxisPx, AxisSource, AxisStop, Button, Key, Modifiers, - PointerAbs, PointerRel, + Axis120, AxisFrame, AxisInverted, AxisPx, AxisSource, AxisStop, Button, Key, + Modifiers, PointerAbs, PointerRel, }, }, }, @@ -134,6 +134,9 @@ async fn run(seat_test: Rc) { AxisSource::handle(tc, se, ps.clone(), move |ps, ev| { ps.source.set(Some(ev.source)); }); + AxisInverted::handle(tc, se, ps.clone(), move |ps, ev| { + ps.inverted[ev.axis as usize].set(ev.inverted != 0); + }); AxisPx::handle(tc, se, ps.clone(), move |ps, ev| { ps.px[ev.axis as usize].set(Some(ev.dist)); }); @@ -152,6 +155,8 @@ async fn run(seat_test: Rc) { let stop_y = ps.stop[1].take(); let v120_x = ps.v120[0].take(); let v120_y = ps.v120[1].take(); + let inverted_x = ps.inverted[0].get(); + let inverted_y = ps.inverted[1].get(); if all || ev.seat == seat { if all { print!("Seat: {}, ", st.name(ev.seat)); @@ -175,9 +180,9 @@ async fn run(seat_test: Rc) { print!("Source: {}", source); need_comma = true; } - for (axis, px, steps, stop) in [ - ("horizontal", px_x, v120_x, stop_x), - ("vertical", px_y, v120_y, stop_y), + for (axis, px, steps, stop, inverted) in [ + ("horizontal", px_x, v120_x, stop_x, inverted_x), + ("vertical", px_y, v120_y, stop_y, inverted_y), ] { if px.is_some() || steps.is_some() || stop { comma!(); @@ -197,6 +202,11 @@ async fn run(seat_test: Rc) { print!("stop"); need_comma = true; } + if inverted { + comma!(); + print!("natural scrolling"); + need_comma = true; + } } println!(); } diff --git a/src/ifs/jay_seat_events.rs b/src/ifs/jay_seat_events.rs index 81918f93..42293735 100644 --- a/src/ifs/jay_seat_events.rs +++ b/src/ifs/jay_seat_events.rs @@ -98,6 +98,11 @@ impl JaySeatEvents { }); } if let Some(dist) = ps.px[axis].get() { + self.client.event(AxisInverted { + self_id: self.id, + axis: axis as _, + inverted: ps.inverted[axis].get() as _, + }); self.client.event(AxisPx { self_id: self.id, dist, diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index a0e04b53..0bccd0f8 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -902,7 +902,7 @@ impl Global for WlSeatGlobal { } fn version(&self) -> u32 { - 8 + 9 } fn break_loops(&self) { diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index c565049e..2225ac18 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -15,9 +15,9 @@ use { wl_keyboard::{self, WlKeyboard}, wl_pointer::{ self, PendingScroll, WlPointer, AXIS_DISCRETE_SINCE_VERSION, - AXIS_SOURCE_SINCE_VERSION, AXIS_STOP_SINCE_VERSION, - AXIS_VALUE120_SINCE_VERSION, POINTER_FRAME_SINCE_VERSION, WHEEL_TILT, - WHEEL_TILT_SINCE_VERSION, + AXIS_RELATIVE_DIRECTION_SINCE_VERSION, AXIS_SOURCE_SINCE_VERSION, + AXIS_STOP_SINCE_VERSION, AXIS_VALUE120_SINCE_VERSION, IDENTICAL, INVERTED, + POINTER_FRAME_SINCE_VERSION, WHEEL_TILT, WHEEL_TILT_SINCE_VERSION, }, zwp_pointer_constraints_v1::{ConstraintType, SeatConstraintStatus}, zwp_relative_pointer_v1::ZwpRelativePointerV1, @@ -199,8 +199,16 @@ impl WlSeatGlobal { } => self.button_event(time_usec, button, state), InputEvent::AxisSource { source } => self.pointer_owner.axis_source(source), - InputEvent::Axis120 { dist, axis } => self.pointer_owner.axis_120(dist, axis), - InputEvent::AxisPx { dist, axis } => self.pointer_owner.axis_px(dist, axis), + InputEvent::Axis120 { + dist, + axis, + inverted, + } => self.pointer_owner.axis_120(dist, axis, inverted), + InputEvent::AxisPx { + dist, + axis, + inverted, + } => self.pointer_owner.axis_px(dist, axis, inverted), InputEvent::AxisStop { axis } => self.pointer_owner.axis_stop(axis), InputEvent::AxisFrame { time_usec } => self.pointer_owner.frame(dev, self, time_usec), } @@ -613,6 +621,13 @@ impl WlSeatGlobal { } } if let Some(delta) = event.px[i].get() { + if p.seat.version >= AXIS_RELATIVE_DIRECTION_SINCE_VERSION { + let direction = match event.inverted[i].get() { + false => IDENTICAL, + true => INVERTED, + }; + p.send_axis_relative_direction(axis, direction); + } p.send_axis(time, axis, delta); } if p.seat.version >= AXIS_STOP_SINCE_VERSION && event.stop[i].get() { diff --git a/src/ifs/wl_seat/pointer_owner.rs b/src/ifs/wl_seat/pointer_owner.rs index 7e057ad6..79746990 100644 --- a/src/ifs/wl_seat/pointer_owner.rs +++ b/src/ifs/wl_seat/pointer_owner.rs @@ -40,12 +40,14 @@ impl PointerOwnerHolder { self.pending_scroll.source.set(Some(axis_source as _)); } - pub fn axis_120(&self, delta: i32, axis: ScrollAxis) { + pub fn axis_120(&self, delta: i32, axis: ScrollAxis, inverted: bool) { self.pending_scroll.v120[axis as usize].set(Some(delta)); + self.pending_scroll.inverted[axis as usize].set(inverted); } - pub fn axis_px(&self, delta: Fixed, axis: ScrollAxis) { + pub fn axis_px(&self, delta: Fixed, axis: ScrollAxis, inverted: bool) { self.pending_scroll.px[axis as usize].set(Some(delta)); + self.pending_scroll.inverted[axis as usize].set(inverted); } pub fn axis_stop(&self, axis: ScrollAxis) { diff --git a/src/ifs/wl_seat/wl_pointer.rs b/src/ifs/wl_seat/wl_pointer.rs index 67f5297d..6bd04cc0 100644 --- a/src/ifs/wl_seat/wl_pointer.rs +++ b/src/ifs/wl_seat/wl_pointer.rs @@ -28,16 +28,21 @@ pub const CONTINUOUS: u32 = 2; #[allow(dead_code)] pub const WHEEL_TILT: u32 = 3; +pub const IDENTICAL: u32 = 0; +pub const INVERTED: u32 = 1; + pub const POINTER_FRAME_SINCE_VERSION: u32 = 5; pub const AXIS_SOURCE_SINCE_VERSION: u32 = 5; pub const AXIS_DISCRETE_SINCE_VERSION: u32 = 5; pub const AXIS_STOP_SINCE_VERSION: u32 = 5; pub const WHEEL_TILT_SINCE_VERSION: u32 = 6; pub const AXIS_VALUE120_SINCE_VERSION: u32 = 8; +pub const AXIS_RELATIVE_DIRECTION_SINCE_VERSION: u32 = 9; #[derive(Default, Debug)] pub struct PendingScroll { pub v120: [Cell>; 2], + pub inverted: [Cell; 2], pub px: [Cell>; 2], pub stop: [Cell; 2], pub source: Cell>, @@ -51,6 +56,10 @@ impl PendingScroll { Cell::new(self.v120[0].take()), Cell::new(self.v120[1].take()), ], + inverted: [ + Cell::new(self.inverted[0].take()), + Cell::new(self.inverted[1].take()), + ], px: [Cell::new(self.px[0].take()), Cell::new(self.px[1].take())], stop: [ Cell::new(self.stop[0].take()), @@ -114,6 +123,14 @@ impl WlPointer { }) } + pub fn send_axis_relative_direction(&self, axis: u32, direction: u32) { + self.seat.client.event(AxisRelativeDirection { + self_id: self.id, + axis, + direction, + }) + } + pub fn send_axis(&self, time: u32, axis: u32, value: Fixed) { self.seat.client.event(Axis { self_id: self.id, @@ -123,12 +140,10 @@ impl WlPointer { }) } - #[allow(dead_code)] pub fn send_frame(&self) { self.seat.client.event(Frame { self_id: self.id }) } - #[allow(dead_code)] pub fn send_axis_source(&self, axis_source: u32) { self.seat.client.event(AxisSource { self_id: self.id, @@ -136,7 +151,6 @@ impl WlPointer { }) } - #[allow(dead_code)] pub fn send_axis_stop(&self, time: u32, axis: u32) { self.seat.client.event(AxisStop { self_id: self.id, @@ -145,7 +159,6 @@ impl WlPointer { }) } - #[allow(dead_code)] pub fn send_axis_discrete(&self, axis: u32, discrete: i32) { self.seat.client.event(AxisDiscrete { self_id: self.id, diff --git a/src/libinput/device.rs b/src/libinput/device.rs index 5d255247..b12f04bf 100644 --- a/src/libinput/device.rs +++ b/src/libinput/device.rs @@ -155,7 +155,6 @@ impl<'a> LibInputDevice<'a> { } } - #[allow(dead_code)] pub fn natural_scrolling_enabled(&self) -> bool { unsafe { libinput_device_config_scroll_get_natural_scroll_enabled(self.dev) != 0 } } diff --git a/wire/jay_seat_events.txt b/wire/jay_seat_events.txt index 43c27c82..c1ed9c65 100644 --- a/wire/jay_seat_events.txt +++ b/wire/jay_seat_events.txt @@ -60,3 +60,8 @@ msg modifiers = 10 { modifiers: u32, group: u32, } + +msg axis_inverted = 11 { + inverted: u32, + axis: u32, +} diff --git a/wire/wl_pointer.txt b/wire/wl_pointer.txt index a9cdd155..f564c293 100644 --- a/wire/wl_pointer.txt +++ b/wire/wl_pointer.txt @@ -66,3 +66,8 @@ msg axis_value120 = 9 { axis: u32, value120: i32, } + +msg axis_relative_direction = 10 { + axis: u32, + direction: u32, +}