diff --git a/wayvr/src/overlays/keyboard/builder.rs b/wayvr/src/overlays/keyboard/builder.rs index efd1e44c..a3749356 100644 --- a/wayvr/src/overlays/keyboard/builder.rs +++ b/wayvr/src/overlays/keyboard/builder.rs @@ -363,7 +363,7 @@ pub(super) fn create_keyboard_panel( }; let within_key_pos = data.metadata.get_mouse_pos_normalized(&common.alterables.transform_stack); - handle_press(app, &k, &k_label, &k_cap_type, &within_key_pos, state, button); + handle_press(app, &k, &k_label, &k_cap_type, &within_key_pos, state, button, button.device); on_press_anim(k.clone(), common, data); Ok(EventResult::Pass) } @@ -378,8 +378,11 @@ pub(super) fn create_keyboard_panel( let k_cap_type = key_cap_type.clone(); move |common, data, app, state| { let within_key_pos = data.metadata.get_mouse_pos_normalized(&common.alterables.transform_stack); + let CallbackMetadata::MousePosition(position) = data.metadata else { + panic!("CallbackMetadata should contain MousePosition!"); + }; - handle_mouse_motion(&k, &k_label, &k_cap_type, state, &within_key_pos); + handle_mouse_motion(&k, &k_label, &k_cap_type, state, &within_key_pos, position.device); Ok(EventResult::Pass) } }), diff --git a/wayvr/src/overlays/keyboard/mod.rs b/wayvr/src/overlays/keyboard/mod.rs index 6c1177a1..7475acf8 100644 --- a/wayvr/src/overlays/keyboard/mod.rs +++ b/wayvr/src/overlays/keyboard/mod.rs @@ -422,7 +422,14 @@ enum KeyButtonData { }, } -fn handle_mouse_motion(key: &KeyState, key_label: &Vec, key_cap_type: &KeyCapType, keyboard: &mut KeyboardState, within_key_pos: &Option) { +fn handle_mouse_motion( + key: &KeyState, + key_label: &Vec, + key_cap_type: &KeyCapType, + keyboard: &mut KeyboardState, + within_key_pos: &Option, + device: usize +) { if let Some(swipe_manager) = keyboard.swipe_typing_manager.as_mut() && *key_cap_type == KeyCapType::Letter { if !swipe_manager.is_current_swipe_empty() { match &key.button_state { @@ -432,7 +439,7 @@ fn handle_mouse_motion(key: &KeyState, key_label: &Vec, key_cap_type: &K if pos.x >= 0.0 && pos.x <= 1.0 && pos.y >= 0.0 && pos.y <= 1.0 { if let Some(label) = key_label.first() { - swipe_manager.add_swipe(pos, label.chars().next().unwrap_or_default()); + swipe_manager.add_swipe(pos, label.chars().next().unwrap_or_default(), device); } } } @@ -451,13 +458,14 @@ fn handle_press( within_key_pos: &Option, keyboard: &mut KeyboardState, button: MouseButtonEvent, + device: usize ) { match &key.button_state { KeyButtonData::Key { vk, pressed } => { if let Some(swipe_manager) = keyboard.swipe_typing_manager.as_mut() && *key_cap_type == KeyCapType::Letter { if let Some(pos) = within_key_pos { if let Some(label) = key_label.first() { - swipe_manager.add_swipe(pos, label.chars().next().unwrap_or_default()); + swipe_manager.add_swipe(pos, label.chars().next().unwrap_or_default(), device); } } } diff --git a/wayvr/src/overlays/keyboard/swipe_type.rs b/wayvr/src/overlays/keyboard/swipe_type.rs index 871f3d84..1929dc8c 100644 --- a/wayvr/src/overlays/keyboard/swipe_type.rs +++ b/wayvr/src/overlays/keyboard/swipe_type.rs @@ -19,6 +19,7 @@ pub struct SwipeTypingManager { clipboard: Clipboard, swipe_left_first_key: bool, first_swipe_char: char, + current_swipe_device: Option, // the pointer that started this swipe last_swiped_word: Option } impl SwipeTypingManager { @@ -69,6 +70,7 @@ impl SwipeTypingManager { clipboard: Clipboard::new()?, swipe_left_first_key: false, first_swipe_char: char::default(), + current_swipe_device: None, last_swiped_word: None }) } @@ -98,11 +100,13 @@ impl SwipeTypingManager { self.current_swipe = Vec::new(); self.first_swipe_char = char::default(); self.swipe_left_first_key = false; + self.current_swipe_device = None; } - fn start_swipe(&mut self, key_label: char) -> Instant{ + fn start_swipe(&mut self, key_label: char, device: usize) -> Instant{ let now = Instant::now(); self.swipe_start_time = Some(now); self.first_swipe_char = key_label.to_ascii_lowercase(); + self.current_swipe_device = Some(device); self.swipe_candidates = Vec::new(); now } @@ -112,7 +116,7 @@ impl SwipeTypingManager { pub fn is_current_swipe_empty(&self) -> bool { self.current_swipe.is_empty() } - pub fn add_swipe(&mut self, within_key_pos_normalized: &Vec2, key_label: char) { + pub fn add_swipe(&mut self, within_key_pos_normalized: &Vec2, key_label: char, device: usize) { if let Some(pos) = self.keyboard_gird.key_positions.get(&key_label.to_ascii_lowercase()) { if self.first_swipe_char != char::default() && self.first_swipe_char != key_label.to_ascii_lowercase() { self.swipe_left_first_key = true; @@ -122,9 +126,14 @@ impl SwipeTypingManager { //println!("char : {key_label} at pos: {key_pos}"); let start_time = match self.swipe_start_time { Some(time) => time, - None => self.start_swipe(key_label) + None => self.start_swipe(key_label, device) }; + // only allow the pointer that started the swipe to contribute to it + if let Some(current_device) = self.current_swipe_device && current_device != device{ + return; + } + let within_key_pos_from_center = Vec2 { x: within_key_pos_normalized.x - 0.5, y: 0.5 - within_key_pos_normalized.y,