From 5ed07230b8811c9ed612030fee2ae339189815fb Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Wed, 20 Nov 2024 13:13:07 -0800 Subject: [PATCH 1/2] input: Define function for transforming touch/tablet event position --- src/input/mod.rs | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index d36edc66..0c3e4ce2 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1143,13 +1143,7 @@ impl State { return; }; - let geometry = output.geometry(); - - let position = geometry.loc.to_f64() - + event - .position_transformed(geometry.size.as_logical()) - .as_global(); - + let position = transform_output_mapped_position(&output, &event); let under = State::surface_under(position, &output, &mut *shell) .map(|(target, pos)| (target, pos.as_logical())); @@ -1180,13 +1174,7 @@ impl State { return; }; - let geometry = output.geometry(); - - let position = geometry.loc.to_f64() - + event - .position_transformed(geometry.size.as_logical()) - .as_global(); - + let position = transform_output_mapped_position(&output, &event); let under = State::surface_under(position, &output, &mut *shell) .map(|(target, pos)| (target, pos.as_logical())); @@ -1269,13 +1257,8 @@ impl State { else { return; }; - let geometry = output.geometry(); - - let position = event - .position_transformed(geometry.size.as_logical()) - .as_global() - + geometry.loc.to_f64(); + let position = transform_output_mapped_position(&output, &event); let under = State::surface_under(position, &output, &mut *shell) .map(|(target, pos)| (target, pos.as_logical())); @@ -1338,13 +1321,8 @@ impl State { else { return; }; - let geometry = output.geometry(); - - let position = event - .position_transformed(geometry.size.as_logical()) - .as_global() - + geometry.loc.to_f64(); + let position = transform_output_mapped_position(&output, &event); let under = State::surface_under(position, &output, &mut *shell) .map(|(target, pos)| (target, pos.as_logical())); @@ -2161,6 +2139,19 @@ fn cursor_sessions_for_output( .chain(output.cursor_sessions().into_iter()) } +fn transform_output_mapped_position<'a, B, E>(output: &Output, event: &E) -> Point +where + B: InputBackend, + E: AbsolutePositionEvent, + B::Device: 'static, +{ + let geometry = output.geometry(); + event + .position_transformed(geometry.size.as_logical()) + .as_global() + + geometry.loc.to_f64() +} + // TODO Is it possible to determine mapping for external touchscreen? // Support map_to_region like sway? fn mapped_output_for_device<'a, D: Device + 'static>( From b16086037f10d3f60f1137ef99629ecb621e2be1 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Wed, 20 Nov 2024 13:21:09 -0800 Subject: [PATCH 2/2] input: Apply output transform to touch/tablet events --- src/input/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 0c3e4ce2..8b40908e 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -2146,10 +2146,14 @@ where B::Device: 'static, { let geometry = output.geometry(); - event - .position_transformed(geometry.size.as_logical()) - .as_global() - + geometry.loc.to_f64() + let transform = output.current_transform(); + let size = transform + .invert() + .transform_size(geometry.size.as_logical()); + geometry.loc.to_f64() + + transform + .transform_point_in(event.position_transformed(size), &size.to_f64()) + .as_global() } // TODO Is it possible to determine mapping for external touchscreen?