input/tablet: Use f64 for the target rectangle
Browse files at this commitadb5b3cd2cd6c5fadd555a52a531ba817dfc00beParent: 0650e7b1 changed file +12 -11
- src/input/mod.rs +12 -11
src/input/mod.rsmodified+12 -11
| @@ -299,14 +299,15 @@ impl State { | ||
| 299 | 299 | let device_output = device_output.as_ref(); |
| 300 | 300 | let (target_geo, keep_ratio, px, transform) = |
| 301 | 301 | if let Some(output) = device_output.or_else(|| self.niri.output_for_tablet()) { |
| 302 | + let geo = self.niri.global_space.output_geometry(output).unwrap(); | |
| 302 | 303 | ( |
| 303 | - self.niri.global_space.output_geometry(output).unwrap(), | |
| 304 | + geo.to_f64(), | |
| 304 | 305 | true, |
| 305 | 306 | 1. / output.current_scale().fractional_scale(), |
| 306 | 307 | output.current_transform(), |
| 307 | 308 | ) |
| 308 | 309 | } else { |
| 309 | - let geo = self.global_bounding_rectangle()?; | |
| 310 | + let geo = self.global_bounding_rectangle()?.to_f64(); | |
| 310 | 311 | |
| 311 | 312 | // FIXME: this 1 px size should ideally somehow be computed for the rightmost output |
| 312 | 313 | // corresponding to the position on the right when clamping. |
| @@ -319,19 +320,19 @@ impl State { | ||
| 319 | 320 | |
| 320 | 321 | let mut pos = { |
| 321 | 322 | let size = transform.invert().transform_size(target_geo.size); |
| 322 | - transform.transform_point_in(event.position_transformed(size), &size.to_f64()) | |
| 323 | + transform.transform_point_in(event.position_transformed(size.to_i32_round()), &size) | |
| 323 | 324 | }; |
| 324 | 325 | |
| 325 | 326 | if keep_ratio { |
| 326 | - pos.x /= target_geo.size.w as f64; | |
| 327 | - pos.y /= target_geo.size.h as f64; | |
| 327 | + pos.x /= target_geo.size.w; | |
| 328 | + pos.y /= target_geo.size.h; | |
| 328 | 329 | |
| 329 | 330 | let device = event.device(); |
| 330 | 331 | if let Some(device) = (&device as &dyn Any).downcast_ref::<input::Device>() { |
| 331 | 332 | if let Some(data) = self.niri.tablets.get(device) { |
| 332 | 333 | // This code does the same thing as mutter with "keep aspect ratio" enabled. |
| 333 | 334 | let size = transform.invert().transform_size(target_geo.size); |
| 334 | - let output_aspect_ratio = size.w as f64 / size.h as f64; | |
| 335 | + let output_aspect_ratio = size.w / size.h; | |
| 335 | 336 | let ratio = data.aspect_ratio / output_aspect_ratio; |
| 336 | 337 | |
| 337 | 338 | if ratio > 1. { |
| @@ -342,13 +343,13 @@ impl State { | ||
| 342 | 343 | } |
| 343 | 344 | }; |
| 344 | 345 | |
| 345 | - pos.x *= target_geo.size.w as f64; | |
| 346 | - pos.y *= target_geo.size.h as f64; | |
| 346 | + pos.x *= target_geo.size.w; | |
| 347 | + pos.y *= target_geo.size.h; | |
| 347 | 348 | } |
| 348 | 349 | |
| 349 | - pos.x = pos.x.clamp(0.0, target_geo.size.w as f64 - px); | |
| 350 | - pos.y = pos.y.clamp(0.0, target_geo.size.h as f64 - px); | |
| 351 | - Some(pos + target_geo.loc.to_f64()) | |
| 350 | + pos.x = pos.x.clamp(0.0, target_geo.size.w - px); | |
| 351 | + pos.y = pos.y.clamp(0.0, target_geo.size.h - px); | |
| 352 | + Some(pos + target_geo.loc) | |
| 352 | 353 | } |
| 353 | 354 | |
| 354 | 355 | fn is_inhibiting_shortcuts(&self) -> bool { |