Release modifier when multi conn
This commit is contained in:
		
							parent
							
								
									3ea92642d8
								
							
						
					
					
						commit
						0f72af6529
					
				| @ -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] | #[inline] | ||||||
| #[cfg(not(any(target_os = "android", target_os = "ios")))] | #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||||
| fn is_numpad_key(event: &Event) -> bool { | fn is_numpad_key(event: &Event) -> bool { | ||||||
| @ -984,3 +999,13 @@ pub fn translate_keyboard_mode(peer: &str, event: &Event, key_event: KeyEvent) - | |||||||
|     } |     } | ||||||
|     events |     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()); | ||||||
|  | } | ||||||
|  | |||||||
| @ -37,7 +37,7 @@ pub fn breakdown_callback() { | |||||||
|     #[cfg(target_os = "linux")] |     #[cfg(target_os = "linux")] | ||||||
|     crate::input_service::clear_remapped_keycode(); |     crate::input_service::clear_remapped_keycode(); | ||||||
|     #[cfg(not(any(target_os = "android", target_os = "ios")))] |     #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||||
|     crate::input_service::release_modifiers(); |     crate::input_service::release_device_modifiers(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Android
 | // Android
 | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ use crate::{ | |||||||
|         new_voice_call_request, new_voice_call_response, start_audio_thread, MediaData, MediaSender, |         new_voice_call_request, new_voice_call_response, start_audio_thread, MediaData, MediaSender, | ||||||
|     }, |     }, | ||||||
|     common::{get_default_sound_input, set_sound_input}, |     common::{get_default_sound_input, set_sound_input}, | ||||||
|  |     keyboard::{is_modifier, keycode_to_rdev_key}, | ||||||
|     video_service, |     video_service, | ||||||
| }; | }; | ||||||
| #[cfg(any(target_os = "android", target_os = "ios"))] | #[cfg(any(target_os = "android", target_os = "ios"))] | ||||||
| @ -39,6 +40,7 @@ use sha2::{Digest, Sha256}; | |||||||
| #[cfg(not(any(target_os = "android", target_os = "ios")))] | #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||||
| use std::sync::atomic::Ordering; | use std::sync::atomic::Ordering; | ||||||
| use std::{ | use std::{ | ||||||
|  |     collections::HashSet, | ||||||
|     num::NonZeroI64, |     num::NonZeroI64, | ||||||
|     sync::{atomic::AtomicI64, mpsc as std_mpsc}, |     sync::{atomic::AtomicI64, mpsc as std_mpsc}, | ||||||
| }; | }; | ||||||
| @ -132,6 +134,7 @@ pub struct Connection { | |||||||
|     voice_call_request_timestamp: Option<NonZeroI64>, |     voice_call_request_timestamp: Option<NonZeroI64>, | ||||||
|     audio_input_device_before_voice_call: Option<String>, |     audio_input_device_before_voice_call: Option<String>, | ||||||
|     options_in_login: Option<OptionMessage>, |     options_in_login: Option<OptionMessage>, | ||||||
|  |     pressed_modifiers: HashSet<rdev::Key>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl ConnInner { | impl ConnInner { | ||||||
| @ -243,6 +246,7 @@ impl Connection { | |||||||
|             voice_call_request_timestamp: None, |             voice_call_request_timestamp: None, | ||||||
|             audio_input_device_before_voice_call: None, |             audio_input_device_before_voice_call: None, | ||||||
|             options_in_login: None, |             options_in_login: None, | ||||||
|  |             pressed_modifiers: Default::default(), | ||||||
|         }; |         }; | ||||||
|         #[cfg(not(any(target_os = "android", target_os = "ios")))] |         #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||||
|         tokio::spawn(async move { |         tokio::spawn(async move { | ||||||
| @ -618,7 +622,6 @@ impl Connection { | |||||||
|         } |         } | ||||||
|         #[cfg(target_os = "linux")] |         #[cfg(target_os = "linux")] | ||||||
|         clear_remapped_keycode(); |         clear_remapped_keycode(); | ||||||
|         release_modifiers(); |  | ||||||
|         log::info!("Input thread exited"); |         log::info!("Input thread exited"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -1366,6 +1369,28 @@ impl Connection { | |||||||
|                         } else { |                         } else { | ||||||
|                             me.press |                             me.press | ||||||
|                         }; |                         }; | ||||||
|  | 
 | ||||||
|  |                         let key = match me.mode.unwrap() { | ||||||
|  |                             KeyboardMode::Map => Some(keycode_to_rdev_key(me.chr())), | ||||||
|  |                             KeyboardMode::Translate => { | ||||||
|  |                                 if let Some(key_event::Union::Chr(code)) = me.union.clone() { | ||||||
|  |                                     Some(keycode_to_rdev_key(code & 0x0000FFFF)) | ||||||
|  |                                 } else { | ||||||
|  |                                     None | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                             _ => None, | ||||||
|  |                         } | ||||||
|  |                         .filter(is_modifier); | ||||||
|  | 
 | ||||||
|  |                         if let Some(key) = key { | ||||||
|  |                             if is_press { | ||||||
|  |                                 self.pressed_modifiers.insert(key); | ||||||
|  |                             } else { | ||||||
|  |                                 self.pressed_modifiers.remove(&key); | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  | 
 | ||||||
|                         if is_press { |                         if is_press { | ||||||
|                             match me.union { |                             match me.union { | ||||||
|                                 Some(key_event::Union::Unicode(_)) |                                 Some(key_event::Union::Unicode(_)) | ||||||
| @ -2023,6 +2048,14 @@ impl Connection { | |||||||
|             }) |             }) | ||||||
|             .count(); |             .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) { | pub fn insert_switch_sides_uuid(id: String, uuid: uuid::Uuid) { | ||||||
| @ -2220,3 +2253,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(); |     let mut en = ENIGO.lock().unwrap(); | ||||||
|     for modifier in [ |     for modifier in [ | ||||||
|         Key::Shift, |         Key::Shift, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user