input: apply output transform for tablet input (#737)
Browse files at this commit1 changed file +24 -18
- src/input/mod.rs +24 -18
src/input/mod.rsmodified+24 -18
| @@ -24,7 +24,7 @@ use smithay::input::pointer::{ | ||
| 24 | 24 | GrabStartData as PointerGrabStartData, MotionEvent, RelativeMotionEvent, |
| 25 | 25 | }; |
| 26 | 26 | use smithay::input::touch::{DownEvent, MotionEvent as TouchMotionEvent, UpEvent}; |
| 27 | -use smithay::utils::{Logical, Point, Rectangle, SERIAL_COUNTER}; | |
| 27 | +use smithay::utils::{Logical, Point, Rectangle, Transform, SERIAL_COUNTER}; | |
| 28 | 28 | use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint}; |
| 29 | 29 | use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait}; |
| 30 | 30 | |
| @@ -243,25 +243,30 @@ impl State { | ||
| 243 | 243 | where |
| 244 | 244 | I::Device: 'static, |
| 245 | 245 | { |
| 246 | - let (target_geo, keep_ratio, px) = if let Some(output) = self.niri.output_for_tablet() { | |
| 247 | - ( | |
| 248 | - self.niri.global_space.output_geometry(output).unwrap(), | |
| 249 | - true, | |
| 250 | - 1. / output.current_scale().fractional_scale(), | |
| 251 | - ) | |
| 252 | - } else { | |
| 253 | - let geo = self.global_bounding_rectangle()?; | |
| 246 | + let (target_geo, keep_ratio, px, transform) = | |
| 247 | + if let Some(output) = self.niri.output_for_tablet() { | |
| 248 | + ( | |
| 249 | + self.niri.global_space.output_geometry(output).unwrap(), | |
| 250 | + true, | |
| 251 | + 1. / output.current_scale().fractional_scale(), | |
| 252 | + output.current_transform(), | |
| 253 | + ) | |
| 254 | + } else { | |
| 255 | + let geo = self.global_bounding_rectangle()?; | |
| 254 | 256 | |
| 255 | - // FIXME: this 1 px size should ideally somehow be computed for the rightmost output | |
| 256 | - // corresponding to the position on the right when clamping. | |
| 257 | - let output = self.niri.global_space.outputs().next().unwrap(); | |
| 258 | - let scale = output.current_scale().fractional_scale(); | |
| 257 | + // FIXME: this 1 px size should ideally somehow be computed for the rightmost output | |
| 258 | + // corresponding to the position on the right when clamping. | |
| 259 | + let output = self.niri.global_space.outputs().next().unwrap(); | |
| 260 | + let scale = output.current_scale().fractional_scale(); | |
| 259 | 261 | |
| 260 | - // Do not keep ratio for the unified mode as this is what OpenTabletDriver expects. | |
| 261 | - (geo, false, 1. / scale) | |
| 262 | - }; | |
| 262 | + // Do not keep ratio for the unified mode as this is what OpenTabletDriver expects. | |
| 263 | + (geo, false, 1. / scale, Transform::Normal) | |
| 264 | + }; | |
| 263 | 265 | |
| 264 | - let mut pos = event.position_transformed(target_geo.size); | |
| 266 | + let mut pos = { | |
| 267 | + let size = transform.invert().transform_size(target_geo.size); | |
| 268 | + transform.transform_point_in(event.position_transformed(size), &size.to_f64()) | |
| 269 | + }; | |
| 265 | 270 | |
| 266 | 271 | if keep_ratio { |
| 267 | 272 | pos.x /= target_geo.size.w as f64; |
| @@ -271,7 +276,8 @@ impl State { | ||
| 271 | 276 | if let Some(device) = (&device as &dyn Any).downcast_ref::<input::Device>() { |
| 272 | 277 | if let Some(data) = self.niri.tablets.get(device) { |
| 273 | 278 | // This code does the same thing as mutter with "keep aspect ratio" enabled. |
| 274 | - let output_aspect_ratio = target_geo.size.w as f64 / target_geo.size.h as f64; | |
| 279 | + let size = transform.invert().transform_size(target_geo.size); | |
| 280 | + let output_aspect_ratio = size.w as f64 / size.h as f64; | |
| 275 | 281 | let ratio = data.aspect_ratio / output_aspect_ratio; |
| 276 | 282 | |
| 277 | 283 | if ratio > 1. { |