Compare commits

..

2 Commits

5 changed files with 11 additions and 52 deletions

View File

@@ -51,16 +51,7 @@ 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;
} }

View File

@@ -10,10 +10,6 @@ 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");
@@ -124,23 +120,12 @@ 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;

View File

@@ -39,12 +39,7 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void* user_ptr) {
} }
int KeyboardCapturer::Unhook() { int KeyboardCapturer::Unhook() {
if (keyboard_hook_) { UnhookWindowsHookEx(keyboard_hook_);
g_on_key_action = nullptr;
g_user_ptr = nullptr;
UnhookWindowsHookEx(keyboard_hook_);
keyboard_hook_ = nullptr;
}
return 0; return 0;
} }

View File

@@ -1340,7 +1340,6 @@ 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 {

View File

@@ -1,5 +1,3 @@
#include <cmath>
#include "device_controller.h" #include "device_controller.h"
#include "localization.h" #include "localization.h"
#include "platform.h" #include "platform.h"
@@ -103,39 +101,28 @@ int Render::ProcessMouseEvent(const SDL_Event& event) {
last_mouse_event.button.y >= props->stream_render_rect_.y && last_mouse_event.button.y >= props->stream_render_rect_.y &&
last_mouse_event.button.y <= props->stream_render_rect_.y + last_mouse_event.button.y <= props->stream_render_rect_.y +
props->stream_render_rect_.h) { props->stream_render_rect_.h) {
float scroll_x = event.wheel.x; int scroll_x = event.wheel.x;
float scroll_y = event.wheel.y; int scroll_y = event.wheel.y;
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) { if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
scroll_x = -scroll_x; scroll_x = -scroll_x;
scroll_y = -scroll_y; scroll_y = -scroll_y;
} }
remote_action.type = ControlType::mouse; remote_action.type = ControlType::mouse;
if (scroll_x == 0) {
auto roundUp = [](float value) -> int {
if (value > 0) {
return static_cast<int>(std::ceil(value));
} else if (value < 0) {
return static_cast<int>(std::floor(value));
}
return 0;
};
if (std::abs(scroll_y) >= std::abs(scroll_x)) {
remote_action.m.flag = MouseFlag::wheel_vertical; remote_action.m.flag = MouseFlag::wheel_vertical;
remote_action.m.s = roundUp(scroll_y); remote_action.m.s = scroll_y;
} else { } else if (scroll_y == 0) {
remote_action.m.flag = MouseFlag::wheel_horizontal; remote_action.m.flag = MouseFlag::wheel_horizontal;
remote_action.m.s = roundUp(scroll_x); remote_action.m.s = scroll_x;
} }
render_width = props->stream_render_rect_.w; render_width = props->stream_render_rect_.w;
render_height = props->stream_render_rect_.h; render_height = props->stream_render_rect_.h;
remote_action.m.x = remote_action.m.x =
(float)(last_mouse_event.button.x - props->stream_render_rect_.x) / (float)(event.button.x - props->stream_render_rect_.x) / render_width;
render_width;
remote_action.m.y = remote_action.m.y =
(float)(last_mouse_event.button.y - props->stream_render_rect_.y) / (float)(event.button.y - props->stream_render_rect_.y) /
render_height; render_height;
std::string msg = remote_action.to_json(); std::string msg = remote_action.to_json();
@@ -238,6 +225,8 @@ void Render::OnReceiveVideoBufferCb(const XVideoFrame* video_frame,
props->video_height_ = video_frame->height; props->video_height_ = video_frame->height;
props->video_size_ = video_frame->size; props->video_size_ = video_frame->size;
LOG_ERROR("receive: {}x{}", props->video_width_, props->video_height_);
if (need_to_update_render_rect) { if (need_to_update_render_rect) {
render->UpdateRenderRect(); render->UpdateRenderRect();
} }