Merge pull request #3854 from chiehw/release
Release modifier when multi conn
This commit is contained in:
		
						commit
						582e025145
					
				| @ -365,6 +365,21 @@ pub fn get_keyboard_mode_enum() -> KeyboardMode { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[inline] | ||||
| pub fn is_modifier(key: &rdev::Key) -> bool { | ||||
|     matches!( | ||||
|         key, | ||||
|         Key::ShiftLeft | ||||
|             | Key::ShiftRight | ||||
|             | Key::ControlLeft | ||||
|             | Key::ControlRight | ||||
|             | Key::MetaLeft | ||||
|             | Key::MetaRight | ||||
|             | Key::Alt | ||||
|             | Key::AltGr | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
| #[inline] | ||||
| #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
| fn is_numpad_key(event: &Event) -> bool { | ||||
| @ -991,3 +1006,13 @@ pub fn translate_keyboard_mode(peer: &str, event: &Event, key_event: KeyEvent) - | ||||
|     } | ||||
|     events | ||||
| } | ||||
| 
 | ||||
| #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
| pub fn keycode_to_rdev_key(keycode: u32) -> Key { | ||||
|     #[cfg(target_os = "windows")] | ||||
|     return rdev::win_key_from_scancode(keycode); | ||||
|     #[cfg(target_os = "linux")] | ||||
|     return rdev::linux_key_from_code(keycode); | ||||
|     #[cfg(target_os = "macos")] | ||||
|     return rdev::macos_key_from_code(keycode.try_into().unwrap_or_default()); | ||||
| } | ||||
|  | ||||
| @ -5,12 +5,12 @@ mod cn; | ||||
| mod cs; | ||||
| mod da; | ||||
| mod de; | ||||
| mod el; | ||||
| mod en; | ||||
| mod eo; | ||||
| mod es; | ||||
| mod fa; | ||||
| mod fr; | ||||
| mod el; | ||||
| mod hu; | ||||
| mod id; | ||||
| mod it; | ||||
|  | ||||
| @ -37,7 +37,7 @@ pub fn breakdown_callback() { | ||||
|     #[cfg(target_os = "linux")] | ||||
|     crate::input_service::clear_remapped_keycode(); | ||||
|     #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
|     crate::input_service::release_modifiers(); | ||||
|     crate::input_service::release_device_modifiers(); | ||||
| } | ||||
| 
 | ||||
| // Android
 | ||||
|  | ||||
| @ -39,6 +39,7 @@ use sha2::{Digest, Sha256}; | ||||
| #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
| use std::sync::atomic::Ordering; | ||||
| use std::{ | ||||
|     collections::HashSet, | ||||
|     num::NonZeroI64, | ||||
|     sync::{atomic::AtomicI64, mpsc as std_mpsc}, | ||||
| }; | ||||
| @ -132,6 +133,7 @@ pub struct Connection { | ||||
|     voice_call_request_timestamp: Option<NonZeroI64>, | ||||
|     audio_input_device_before_voice_call: Option<String>, | ||||
|     options_in_login: Option<OptionMessage>, | ||||
|     pressed_modifiers: HashSet<rdev::Key>, | ||||
| } | ||||
| 
 | ||||
| impl ConnInner { | ||||
| @ -243,6 +245,7 @@ impl Connection { | ||||
|             voice_call_request_timestamp: None, | ||||
|             audio_input_device_before_voice_call: None, | ||||
|             options_in_login: None, | ||||
|             pressed_modifiers: Default::default(), | ||||
|         }; | ||||
|         #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
|         tokio::spawn(async move { | ||||
| @ -618,7 +621,6 @@ impl Connection { | ||||
|         } | ||||
|         #[cfg(target_os = "linux")] | ||||
|         clear_remapped_keycode(); | ||||
|         release_modifiers(); | ||||
|         log::info!("Input thread exited"); | ||||
|     } | ||||
| 
 | ||||
| @ -1357,6 +1359,30 @@ impl Connection { | ||||
|                         } else { | ||||
|                             me.press | ||||
|                         }; | ||||
| 
 | ||||
|                         let key = match me.mode.enum_value_or_default() { | ||||
|                             KeyboardMode::Map => { | ||||
|                                 Some(crate::keyboard::keycode_to_rdev_key(me.chr())) | ||||
|                             } | ||||
|                             KeyboardMode::Translate => { | ||||
|                                 if let Some(key_event::Union::Chr(code)) = me.union { | ||||
|                                     Some(crate::keyboard::keycode_to_rdev_key(code & 0x0000FFFF)) | ||||
|                                 } else { | ||||
|                                     None | ||||
|                                 } | ||||
|                             } | ||||
|                             _ => None, | ||||
|                         } | ||||
|                         .filter(crate::keyboard::is_modifier); | ||||
| 
 | ||||
|                         if let Some(key) = key { | ||||
|                             if is_press { | ||||
|                                 self.pressed_modifiers.insert(key); | ||||
|                             } else { | ||||
|                                 self.pressed_modifiers.remove(&key); | ||||
|                             } | ||||
|                         } | ||||
| 
 | ||||
|                         if is_press { | ||||
|                             match me.union { | ||||
|                                 Some(key_event::Union::Unicode(_)) | ||||
| @ -2011,6 +2037,14 @@ impl Connection { | ||||
|             }) | ||||
|             .count(); | ||||
|     } | ||||
| 
 | ||||
|     #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
|     fn release_pressed_modifiers(&mut self) { | ||||
|         for modifier in self.pressed_modifiers.iter() { | ||||
|             rdev::simulate(&rdev::EventType::KeyRelease(*modifier)).ok(); | ||||
|         } | ||||
|         self.pressed_modifiers.clear(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| pub fn insert_switch_sides_uuid(id: String, uuid: uuid::Uuid) { | ||||
| @ -2208,3 +2242,10 @@ impl Default for PortableState { | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl Drop for Connection { | ||||
|     fn drop(&mut self) { | ||||
|         #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||
|         self.release_pressed_modifiers(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -551,7 +551,7 @@ fn record_key_to_key(record_key: u64) -> Option<Key> { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| pub fn release_modifiers() { | ||||
| pub fn release_device_modifiers() { | ||||
|     let mut en = ENIGO.lock().unwrap(); | ||||
|     for modifier in [ | ||||
|         Key::Shift, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user