From 5a13aa0996f345e8c2c531d9403b39b4ac1b6730 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Tue, 7 Nov 2023 13:56:31 -0800 Subject: [PATCH] WIP wl-touch --- src/input/mod.rs | 93 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 1a8aea658..8ec9d03b7 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -23,9 +23,9 @@ use cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_session_v1::Inp #[allow(deprecated)] use smithay::{ backend::input::{ - Axis, AxisSource, Device, DeviceCapability, GestureBeginEvent, GestureEndEvent, - GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _, InputBackend, InputEvent, - KeyState, PointerAxisEvent, + AbsolutePositionEvent, Axis, AxisSource, Device, DeviceCapability, GestureBeginEvent, + GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _, InputBackend, + InputEvent, KeyState, PointerAxisEvent, TouchEvent, }, desktop::{layer_map_for_output, space::SpaceElement, WindowSurfaceType}, input::{ @@ -205,6 +205,7 @@ pub fn add_seat( .expect("Failed to load xkb configuration files"); } seat.add_pointer(); + seat.add_touch(); seat } @@ -1139,6 +1140,92 @@ impl State { ); } } + InputEvent::TouchDown { event, .. } => { + if let Some(seat) = self.common.seat_with_device(&event.device()).cloned() { + let current_output = seat.active_output(); + let geometry = current_output.geometry(); + + // XXX + let position = geometry.loc.to_f64() + + event + .position_transformed(geometry.size.as_logical()) + .as_global(); + + let overview = self.common.shell.overview_mode(); + let workspace = self.common.shell.workspaces.active_mut(¤t_output); + let under = State::surface_under( + position, + ¤t_output, + &self.common.shell.override_redirect_windows, + overview.0.clone(), + workspace, + self.common.session_lock.as_ref(), + ) + .map(|(target, pos)| (target, pos.as_logical())); + + if let Some((target, pos)) = under { + if let Some(wl_surface) = target.wl_surface() { + let serial = SERIAL_COUNTER.next_serial(); + let mut touch = seat.get_touch().unwrap(); + touch.down( + serial, + event.time() as u32, + &wl_surface, + position.as_logical() - pos.to_f64(), + event.slot(), + ); + } + } + } + } + InputEvent::TouchMotion { event, .. } => { + if let Some(seat) = self.common.seat_with_device(&event.device()).cloned() { + let current_output = seat.active_output(); + let geometry = current_output.geometry(); + + // XXX + let position = geometry.loc.to_f64() + + event + .position_transformed(geometry.size.as_logical()) + .as_global(); + + let overview = self.common.shell.overview_mode(); + let workspace = self.common.shell.workspaces.active_mut(¤t_output); + let under = State::surface_under( + position, + ¤t_output, + &self.common.shell.override_redirect_windows, + overview.0.clone(), + workspace, + self.common.session_lock.as_ref(), + ) + .map(|(target, pos)| (target, pos.as_logical())); + + if let Some((target, pos)) = under { + // XX surface changed? + let mut touch = seat.get_touch().unwrap(); + touch.motion( + event.time() as u32, + event.slot(), + position.as_logical() - pos.to_f64(), + ); + } + } + } + InputEvent::TouchUp { event, .. } => { + if let Some(seat) = self.common.seat_with_device(&event.device()) { + let serial = SERIAL_COUNTER.next_serial(); + let touch = seat.get_touch().unwrap(); + touch.up(serial, event.time() as u32, event.slot()); + } + } + InputEvent::TouchCancel { event, .. } => { + if let Some(seat) = self.common.seat_with_device(&event.device()) { + let touch = seat.get_touch().unwrap(); + touch.cancel(); + } + } + InputEvent::TouchFrame { event, .. } => {} _ => { /* TODO e.g. tablet or touch events */ } } }