From 0b985cefdbebf2d62a4f7de55472f9111d59c80d Mon Sep 17 00:00:00 2001 From: Richard Acayan Date: Mon, 30 Sep 2024 22:08:53 -0400 Subject: [PATCH] core: move scaling of input positions into core The core may need to control the scale of the input positions to layout positions, such as when the layout is changed. Handle the scaling of input positions in the button of the keyboard. --- src/core/button.rs | 16 ++++++++++++++++ src/wayland/seat.rs | 22 ++++++---------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/core/button.rs b/src/core/button.rs index d0171f4..f0f156a 100644 --- a/src/core/button.rs +++ b/src/core/button.rs @@ -132,6 +132,9 @@ pub struct Button { longpress: Duration, repeat: Duration, r_square: f64, + + x_scale: f64, + y_scale: f64, } const PART_TL: usize = 1; @@ -185,6 +188,9 @@ impl Button { longpress: Duration::from_millis(cfg.longpress_ms()), repeat: Duration::from_millis(cfg.repeat_ms()), r_square: 0.25, + + x_scale: 0.0, + y_scale: 0.0, } } @@ -224,6 +230,12 @@ impl Button { self.layout.update_keys_supported(&self.kbd) } + pub fn set_scale(&mut self, x_scale: f64, y_scale: f64) + { + self.x_scale = x_scale; + self.y_scale = y_scale; + } + pub fn next_time(&self) -> Option { let id = *self.timers.front()?; @@ -326,6 +338,8 @@ impl Button { return; } + let (x, y) = (x * self.x_scale, y * self.y_scale); + let key = match self.layout.locate_key_mut(x, y) { Some(k) => k, // Ignore the press if it is not for a key. @@ -428,6 +442,8 @@ impl Button { None => return, }; + let (x, y) = (x * self.x_scale, y * self.y_scale); + let (dx, dy) = (x - press.x1, y - press.y1); if dx * dx + dy * dy < self.r_square { // We only need to make changes when the key is being dragged. diff --git a/src/wayland/seat.rs b/src/wayland/seat.rs index 8a8a71f..9771a6a 100644 --- a/src/wayland/seat.rs +++ b/src/wayland/seat.rs @@ -38,9 +38,6 @@ pub struct Seat { button: Button, - x_scale: f64, - y_scale: f64, - mouse_x: f64, mouse_y: f64, actions: Vec, @@ -66,9 +63,6 @@ impl