[fix] use relative percentage-based mouse mapping instead of absolute positions

This commit is contained in:
dijunkun
2025-04-27 14:02:20 +08:00
parent 4b9e86c424
commit c33e4bbe0e
6 changed files with 14 additions and 27 deletions

View File

@@ -49,8 +49,8 @@ int MouseController::Init(int screen_width, int screen_height) {
int MouseController::Destroy() { return 0; }
int MouseController::SendMouseCommand(RemoteAction remote_action) {
int mouse_pos_x = remote_action.m.x;
int mouse_pos_y = remote_action.m.y;
int mouse_pos_x = remote_action.m.x * screen_width_;
int mouse_pos_y = remote_action.m.y * screen_height_;
if (remote_action.type == ControlType::mouse) {
struct input_event event;

View File

@@ -12,19 +12,14 @@ int MouseController::Init(int screen_width, int screen_height) {
screen_width_ = screen_width;
screen_height_ = screen_height;
pixel_width_ =
CGDisplayModeGetPixelWidth(CGDisplayCopyDisplayMode(CGMainDisplayID()));
pixel_height_ =
CGDisplayModeGetPixelHeight(CGDisplayCopyDisplayMode(CGMainDisplayID()));
return 0;
}
int MouseController::Destroy() { return 0; }
int MouseController::SendMouseCommand(RemoteAction remote_action) {
int mouse_pos_x = remote_action.m.x * screen_width_ / pixel_width_;
int mouse_pos_y = remote_action.m.y * screen_height_ / pixel_height_;
int mouse_pos_x = remote_action.m.x * screen_width_;
int mouse_pos_y = remote_action.m.y * screen_height_;
if (remote_action.type == ControlType::mouse) {
CGEventRef mouse_event = nullptr;

View File

@@ -22,9 +22,6 @@ class MouseController : public DeviceController {
private:
int screen_width_ = 0;
int screen_height_ = 0;
int pixel_width_ = 0;
int pixel_height_ = 0;
};
#endif

View File

@@ -20,8 +20,8 @@ int MouseController::SendMouseCommand(RemoteAction remote_action) {
if (remote_action.type == ControlType::mouse) {
ip.type = INPUT_MOUSE;
ip.mi.dx = (LONG)remote_action.m.x;
ip.mi.dy = (LONG)remote_action.m.y;
ip.mi.dx = (LONG)(remote_action.m.x * screen_width_);
ip.mi.dy = (LONG)(remote_action.m.y * screen_height_);
switch (remote_action.m.flag) {
case MouseFlag::left_down: