diff --git a/src/device_controller/keyboard/linux/keyboard_capturer.cpp b/src/device_controller/keyboard/linux/keyboard_capturer.cpp index 3da438e..0a211a4 100644 --- a/src/device_controller/keyboard/linux/keyboard_capturer.cpp +++ b/src/device_controller/keyboard/linux/keyboard_capturer.cpp @@ -51,7 +51,16 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void* user_ptr) { } int KeyboardCapturer::Unhook() { + g_on_key_action = nullptr; + g_user_ptr = nullptr; + running_ = false; + + if (display_) { + XSelectInput(display_, DefaultRootWindow(display_), 0); + XFlush(display_); + } + return 0; } diff --git a/src/device_controller/keyboard/mac/keyboard_capturer.cpp b/src/device_controller/keyboard/mac/keyboard_capturer.cpp index efbdaf3..6ca9b60 100644 --- a/src/device_controller/keyboard/mac/keyboard_capturer.cpp +++ b/src/device_controller/keyboard/mac/keyboard_capturer.cpp @@ -10,6 +10,10 @@ static void* g_user_ptr = nullptr; CGEventRef eventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void* userInfo) { + if (!g_on_key_action) { + return event; + } + KeyboardCapturer* keyboard_capturer = (KeyboardCapturer*)userInfo; if (!keyboard_capturer) { LOG_ERROR("keyboard_capturer is nullptr"); @@ -120,12 +124,23 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void* user_ptr) { } int KeyboardCapturer::Unhook() { + g_on_key_action = nullptr; + g_user_ptr = nullptr; + + if (event_tap_) { + CGEventTapEnable(event_tap_, false); + } + if (run_loop_source_) { + CFRunLoopRemoveSource(CFRunLoopGetCurrent(), run_loop_source_, + kCFRunLoopCommonModes); CFRelease(run_loop_source_); + run_loop_source_ = nullptr; } if (event_tap_) { CFRelease(event_tap_); + event_tap_ = nullptr; } return 0; diff --git a/src/device_controller/keyboard/windows/keyboard_capturer.cpp b/src/device_controller/keyboard/windows/keyboard_capturer.cpp index a2682e6..30ddad4 100644 --- a/src/device_controller/keyboard/windows/keyboard_capturer.cpp +++ b/src/device_controller/keyboard/windows/keyboard_capturer.cpp @@ -39,7 +39,12 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void* user_ptr) { } int KeyboardCapturer::Unhook() { - UnhookWindowsHookEx(keyboard_hook_); + if (keyboard_hook_) { + g_on_key_action = nullptr; + g_user_ptr = nullptr; + UnhookWindowsHookEx(keyboard_hook_); + keyboard_hook_ = nullptr; + } return 0; } diff --git a/src/gui/render.cpp b/src/gui/render.cpp index aab12eb..9d92b2e 100644 --- a/src/gui/render.cpp +++ b/src/gui/render.cpp @@ -1340,6 +1340,7 @@ void Render::ProcessSdlEvent(const SDL_Event& event) { is_client_mode_ = false; reload_recent_connections_ = true; fullscreen_button_pressed_ = false; + start_keyboard_capturer_ = false; just_created_ = false; recent_connection_image_save_time_ = SDL_GetTicks(); } else {