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.
This commit is contained in:
parent
0fa318ca7e
commit
0b985cefdb
2 changed files with 22 additions and 16 deletions
|
|
@ -132,6 +132,9 @@ pub struct Button<D: Display, K: Keyboard> {
|
|||
longpress: Duration,
|
||||
repeat: Duration,
|
||||
r_square: f64,
|
||||
|
||||
x_scale: f64,
|
||||
y_scale: f64,
|
||||
}
|
||||
|
||||
const PART_TL: usize = 1;
|
||||
|
|
@ -185,6 +188,9 @@ impl<D: Display, K: Keyboard> Button<D, K> {
|
|||
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<D: Display, K: Keyboard> Button<D, K> {
|
|||
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<Instant>
|
||||
{
|
||||
let id = *self.timers.front()?;
|
||||
|
|
@ -326,6 +338,8 @@ impl<D: Display, K: Keyboard> Button<D, K> {
|
|||
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<D: Display, K: Keyboard> Button<D, K> {
|
|||
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.
|
||||
|
|
|
|||
|
|
@ -38,9 +38,6 @@ pub struct Seat<D: Display, K: Keyboard, T> {
|
|||
|
||||
button: Button<D, K>,
|
||||
|
||||
x_scale: f64,
|
||||
y_scale: f64,
|
||||
|
||||
mouse_x: f64,
|
||||
mouse_y: f64,
|
||||
actions: Vec<TouchAction>,
|
||||
|
|
@ -66,9 +63,6 @@ impl<D: Display, K: Keyboard,
|
|||
|
||||
button,
|
||||
|
||||
x_scale: 0.0,
|
||||
y_scale: 0.0,
|
||||
|
||||
mouse_x: 0.0,
|
||||
mouse_y: 0.0,
|
||||
actions,
|
||||
|
|
@ -117,6 +111,12 @@ impl<D: Display, K: Keyboard,
|
|||
self.button.set_text_supported(text_supp)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn set_scale(&mut self, x_scale: f64, y_scale: f64)
|
||||
{
|
||||
self.button.set_scale(x_scale, y_scale);
|
||||
}
|
||||
|
||||
pub fn set_capabilities(&mut self, caps: wl_seat::Capability)
|
||||
{
|
||||
if caps.contains(wl_seat::Capability::Pointer) {
|
||||
|
|
@ -128,16 +128,8 @@ impl<D: Display, K: Keyboard,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_scale(&mut self, x_scale: f64, y_scale: f64)
|
||||
{
|
||||
self.x_scale = x_scale;
|
||||
self.y_scale = y_scale;
|
||||
}
|
||||
|
||||
pub fn ptr_motion(&mut self, x: f64, y: f64)
|
||||
{
|
||||
let (x, y) = (x * self.x_scale, y * self.y_scale);
|
||||
|
||||
self.mouse_x = x;
|
||||
self.mouse_y = y;
|
||||
|
||||
|
|
@ -164,7 +156,6 @@ impl<D: Display, K: Keyboard,
|
|||
pub fn touch_press(&mut self, id: u32, x: f64, y: f64)
|
||||
{
|
||||
let id = id as usize + 1;
|
||||
let (x, y) = (x * self.x_scale, y * self.y_scale);
|
||||
let act = TouchAction { id, act: PressAction::Press(x, y), };
|
||||
self.actions.push(act);
|
||||
}
|
||||
|
|
@ -172,7 +163,6 @@ impl<D: Display, K: Keyboard,
|
|||
pub fn touch_pos(&mut self, id: u32, x: f64, y: f64)
|
||||
{
|
||||
let id = id as usize + 1;
|
||||
let (x, y) = (x * self.x_scale, y * self.y_scale);
|
||||
let act = TouchAction { id, act: PressAction::Pos(x, y), };
|
||||
self.actions.push(act);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue