From 6ffa2cacb12b1659acdcf55a70d35eac8e241ee8 Mon Sep 17 00:00:00 2001 From: asur4s Date: Sun, 19 Mar 2023 19:02:59 -0700 Subject: [PATCH] Clean remapped keycodes when breakdown --- libs/hbb_common/src/platform/mod.rs | 13 ++++++++++++- src/core_main.rs | 3 ++- src/platform/mod.rs | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/libs/hbb_common/src/platform/mod.rs b/libs/hbb_common/src/platform/mod.rs index aa929ca99..c37c8aaf5 100644 --- a/libs/hbb_common/src/platform/mod.rs +++ b/libs/hbb_common/src/platform/mod.rs @@ -7,6 +7,8 @@ pub mod macos; use crate::{config::Config, log}; use std::process::exit; +static mut GLOBAL_CALLBACK: Option> = None; + extern "C" fn breakdown_signal_handler(sig: i32) { let mut stack = vec![]; backtrace::trace(|frame| { @@ -41,11 +43,20 @@ extern "C" fn breakdown_signal_handler(sig: i32) { ) .ok(); } + unsafe { + if let Some(callback) = &GLOBAL_CALLBACK { + callback() + } + } exit(0); } -pub fn register_breakdown_handler() { +pub fn register_breakdown_handler(callback: T) +where + T: Fn() + 'static, +{ unsafe { + GLOBAL_CALLBACK = Some(Box::new(callback)); libc::signal(libc::SIGSEGV, breakdown_signal_handler as _); } } diff --git a/src/core_main.rs b/src/core_main.rs index 76b630f88..d5e497060 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -1,3 +1,4 @@ +use crate::platform::breakdown_callback; use hbb_common::log; #[cfg(not(any(target_os = "android", target_os = "ios")))] use hbb_common::platform::register_breakdown_handler; @@ -38,7 +39,7 @@ pub fn core_main() -> Option> { i += 1; } #[cfg(not(any(target_os = "android", target_os = "ios")))] - register_breakdown_handler(); + register_breakdown_handler(breakdown_callback); #[cfg(target_os = "linux")] #[cfg(feature = "flutter")] { diff --git a/src/platform/mod.rs b/src/platform/mod.rs index f2b609d3f..ac5240dae 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -17,6 +17,7 @@ pub mod delegate; #[cfg(target_os = "linux")] pub mod linux; +use crate::input_service::clear_remapped_keycode; #[cfg(not(any(target_os = "android", target_os = "ios")))] use hbb_common::{message_proto::CursorData, ResultType}; #[cfg(not(target_os = "macos"))] @@ -41,6 +42,11 @@ pub fn is_xfce() -> bool { } } +pub fn breakdown_callback() { + #[cfg(target_os = "linux")] + clear_remapped_keycode() +} + // Android #[cfg(target_os = "android")] pub fn get_active_username() -> String {