mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[fix] use relative percentage-based mouse mapping instead of absolute positions
This commit is contained in:
@@ -28,8 +28,8 @@ typedef enum {
|
|||||||
} MouseFlag;
|
} MouseFlag;
|
||||||
typedef enum { key_down = 0, key_up } KeyFlag;
|
typedef enum { key_down = 0, key_up } KeyFlag;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int x;
|
float x;
|
||||||
int y;
|
float y;
|
||||||
int s;
|
int s;
|
||||||
MouseFlag flag;
|
MouseFlag flag;
|
||||||
} Mouse;
|
} Mouse;
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ int MouseController::Init(int screen_width, int screen_height) {
|
|||||||
int MouseController::Destroy() { return 0; }
|
int MouseController::Destroy() { return 0; }
|
||||||
|
|
||||||
int MouseController::SendMouseCommand(RemoteAction remote_action) {
|
int MouseController::SendMouseCommand(RemoteAction remote_action) {
|
||||||
int mouse_pos_x = remote_action.m.x;
|
int mouse_pos_x = remote_action.m.x * screen_width_;
|
||||||
int mouse_pos_y = remote_action.m.y;
|
int mouse_pos_y = remote_action.m.y * screen_height_;
|
||||||
|
|
||||||
if (remote_action.type == ControlType::mouse) {
|
if (remote_action.type == ControlType::mouse) {
|
||||||
struct input_event event;
|
struct input_event event;
|
||||||
|
|||||||
@@ -12,19 +12,14 @@ int MouseController::Init(int screen_width, int screen_height) {
|
|||||||
screen_width_ = screen_width;
|
screen_width_ = screen_width;
|
||||||
screen_height_ = screen_height;
|
screen_height_ = screen_height;
|
||||||
|
|
||||||
pixel_width_ =
|
|
||||||
CGDisplayModeGetPixelWidth(CGDisplayCopyDisplayMode(CGMainDisplayID()));
|
|
||||||
pixel_height_ =
|
|
||||||
CGDisplayModeGetPixelHeight(CGDisplayCopyDisplayMode(CGMainDisplayID()));
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MouseController::Destroy() { return 0; }
|
int MouseController::Destroy() { return 0; }
|
||||||
|
|
||||||
int MouseController::SendMouseCommand(RemoteAction remote_action) {
|
int MouseController::SendMouseCommand(RemoteAction remote_action) {
|
||||||
int mouse_pos_x = remote_action.m.x * screen_width_ / pixel_width_;
|
int mouse_pos_x = remote_action.m.x * screen_width_;
|
||||||
int mouse_pos_y = remote_action.m.y * screen_height_ / pixel_height_;
|
int mouse_pos_y = remote_action.m.y * screen_height_;
|
||||||
|
|
||||||
if (remote_action.type == ControlType::mouse) {
|
if (remote_action.type == ControlType::mouse) {
|
||||||
CGEventRef mouse_event = nullptr;
|
CGEventRef mouse_event = nullptr;
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ class MouseController : public DeviceController {
|
|||||||
private:
|
private:
|
||||||
int screen_width_ = 0;
|
int screen_width_ = 0;
|
||||||
int screen_height_ = 0;
|
int screen_height_ = 0;
|
||||||
|
|
||||||
int pixel_width_ = 0;
|
|
||||||
int pixel_height_ = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -20,8 +20,8 @@ int MouseController::SendMouseCommand(RemoteAction remote_action) {
|
|||||||
|
|
||||||
if (remote_action.type == ControlType::mouse) {
|
if (remote_action.type == ControlType::mouse) {
|
||||||
ip.type = INPUT_MOUSE;
|
ip.type = INPUT_MOUSE;
|
||||||
ip.mi.dx = (LONG)remote_action.m.x;
|
ip.mi.dx = (LONG)(remote_action.m.x * screen_width_);
|
||||||
ip.mi.dy = (LONG)remote_action.m.y;
|
ip.mi.dy = (LONG)(remote_action.m.y * screen_height_);
|
||||||
|
|
||||||
switch (remote_action.m.flag) {
|
switch (remote_action.m.flag) {
|
||||||
case MouseFlag::left_down:
|
case MouseFlag::left_down:
|
||||||
|
|||||||
@@ -62,13 +62,11 @@ int Render::ProcessMouseEvent(SDL_Event &event) {
|
|||||||
last_mouse_event.button.x = event.button.x;
|
last_mouse_event.button.x = event.button.x;
|
||||||
last_mouse_event.button.y = event.button.y;
|
last_mouse_event.button.y = event.button.y;
|
||||||
|
|
||||||
ratio_x = (float)props->video_width_ / (float)render_width;
|
|
||||||
ratio_y = (float)props->video_height_ / (float)render_height;
|
|
||||||
|
|
||||||
remote_action.m.x =
|
remote_action.m.x =
|
||||||
(size_t)((event.button.x - props->stream_render_rect_.x) * ratio_x);
|
(float)(event.button.x - props->stream_render_rect_.x) / render_width;
|
||||||
remote_action.m.y =
|
remote_action.m.y =
|
||||||
(size_t)((event.button.y - props->stream_render_rect_.y) * ratio_y);
|
(float)(event.button.y - props->stream_render_rect_.y) /
|
||||||
|
render_height;
|
||||||
|
|
||||||
if (SDL_MOUSEBUTTONDOWN == event.type) {
|
if (SDL_MOUSEBUTTONDOWN == event.type) {
|
||||||
remote_action.type = ControlType::mouse;
|
remote_action.type = ControlType::mouse;
|
||||||
@@ -123,14 +121,11 @@ int Render::ProcessMouseEvent(SDL_Event &event) {
|
|||||||
|
|
||||||
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;
|
||||||
ratio_x = (float)props->video_width_ / (float)render_width;
|
|
||||||
ratio_y = (float)props->video_height_ / (float)render_height;
|
|
||||||
remote_action.m.x =
|
remote_action.m.x =
|
||||||
(size_t)((last_mouse_event.button.x - props->stream_render_rect_.x) *
|
(float)(event.button.x - props->stream_render_rect_.x) / render_width;
|
||||||
ratio_x);
|
|
||||||
remote_action.m.y =
|
remote_action.m.y =
|
||||||
(size_t)((last_mouse_event.button.y - props->stream_render_rect_.y) *
|
(float)(event.button.y - props->stream_render_rect_.y) /
|
||||||
ratio_y);
|
render_height;
|
||||||
|
|
||||||
SendDataFrame(props->peer_, (const char *)&remote_action,
|
SendDataFrame(props->peer_, (const char *)&remote_action,
|
||||||
sizeof(remote_action));
|
sizeof(remote_action));
|
||||||
|
|||||||
Reference in New Issue
Block a user