mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-12-17 04:26:47 +08:00
[fix] release keyboard hook after remote control disconnects, refs #23
This commit is contained in:
@@ -51,7 +51,16 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void* user_ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int KeyboardCapturer::Unhook() {
|
int KeyboardCapturer::Unhook() {
|
||||||
|
g_on_key_action = nullptr;
|
||||||
|
g_user_ptr = nullptr;
|
||||||
|
|
||||||
running_ = false;
|
running_ = false;
|
||||||
|
|
||||||
|
if (display_) {
|
||||||
|
XSelectInput(display_, DefaultRootWindow(display_), 0);
|
||||||
|
XFlush(display_);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ static void* g_user_ptr = nullptr;
|
|||||||
|
|
||||||
CGEventRef eventCallback(CGEventTapProxy proxy, CGEventType type,
|
CGEventRef eventCallback(CGEventTapProxy proxy, CGEventType type,
|
||||||
CGEventRef event, void* userInfo) {
|
CGEventRef event, void* userInfo) {
|
||||||
|
if (!g_on_key_action) {
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
KeyboardCapturer* keyboard_capturer = (KeyboardCapturer*)userInfo;
|
KeyboardCapturer* keyboard_capturer = (KeyboardCapturer*)userInfo;
|
||||||
if (!keyboard_capturer) {
|
if (!keyboard_capturer) {
|
||||||
LOG_ERROR("keyboard_capturer is nullptr");
|
LOG_ERROR("keyboard_capturer is nullptr");
|
||||||
@@ -120,12 +124,23 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void* user_ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int KeyboardCapturer::Unhook() {
|
int KeyboardCapturer::Unhook() {
|
||||||
|
g_on_key_action = nullptr;
|
||||||
|
g_user_ptr = nullptr;
|
||||||
|
|
||||||
|
if (event_tap_) {
|
||||||
|
CGEventTapEnable(event_tap_, false);
|
||||||
|
}
|
||||||
|
|
||||||
if (run_loop_source_) {
|
if (run_loop_source_) {
|
||||||
|
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), run_loop_source_,
|
||||||
|
kCFRunLoopCommonModes);
|
||||||
CFRelease(run_loop_source_);
|
CFRelease(run_loop_source_);
|
||||||
|
run_loop_source_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event_tap_) {
|
if (event_tap_) {
|
||||||
CFRelease(event_tap_);
|
CFRelease(event_tap_);
|
||||||
|
event_tap_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -39,7 +39,12 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void* user_ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int KeyboardCapturer::Unhook() {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1340,6 +1340,7 @@ void Render::ProcessSdlEvent(const SDL_Event& event) {
|
|||||||
is_client_mode_ = false;
|
is_client_mode_ = false;
|
||||||
reload_recent_connections_ = true;
|
reload_recent_connections_ = true;
|
||||||
fullscreen_button_pressed_ = false;
|
fullscreen_button_pressed_ = false;
|
||||||
|
start_keyboard_capturer_ = false;
|
||||||
just_created_ = false;
|
just_created_ = false;
|
||||||
recent_connection_image_save_time_ = SDL_GetTicks();
|
recent_connection_image_save_time_ = SDL_GetTicks();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user