mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[feat] mouse middle button and wheel supported
This commit is contained in:
@@ -15,11 +15,22 @@ typedef enum {
|
|||||||
audio_capture,
|
audio_capture,
|
||||||
host_infomation
|
host_infomation
|
||||||
} ControlType;
|
} ControlType;
|
||||||
typedef enum { move = 0, left_down, left_up, right_down, right_up } MouseFlag;
|
typedef enum {
|
||||||
|
move = 0,
|
||||||
|
left_down,
|
||||||
|
left_up,
|
||||||
|
right_down,
|
||||||
|
right_up,
|
||||||
|
middle_down,
|
||||||
|
middle_up,
|
||||||
|
wheel_vertical,
|
||||||
|
wheel_horizontal
|
||||||
|
} MouseFlag;
|
||||||
typedef enum { key_down = 0, key_up } KeyFlag;
|
typedef enum { key_down = 0, key_up } KeyFlag;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t x;
|
size_t x;
|
||||||
size_t y;
|
size_t y;
|
||||||
|
size_t s;
|
||||||
MouseFlag flag;
|
MouseFlag flag;
|
||||||
} Mouse;
|
} Mouse;
|
||||||
|
|
||||||
|
|||||||
@@ -57,16 +57,40 @@ int MouseController::SendMouseCommand(RemoteAction remote_action) {
|
|||||||
memset(&event, 0, sizeof(event));
|
memset(&event, 0, sizeof(event));
|
||||||
gettimeofday(&event.time, NULL);
|
gettimeofday(&event.time, NULL);
|
||||||
|
|
||||||
if (remote_action.m.flag == MouseFlag::left_down) {
|
switch (remote_action.m.flag) {
|
||||||
SimulateKeyDown(uinput_fd_, BTN_LEFT);
|
case MouseFlag::left_down:
|
||||||
} else if (remote_action.m.flag == MouseFlag::left_up) {
|
SimulateKeyDown(uinput_fd_, BTN_LEFT);
|
||||||
SimulateKeyUp(uinput_fd_, BTN_LEFT);
|
break;
|
||||||
} else if (remote_action.m.flag == MouseFlag::right_down) {
|
case MouseFlag::left_up:
|
||||||
SimulateKeyDown(uinput_fd_, BTN_RIGHT);
|
SimulateKeyUp(uinput_fd_, BTN_LEFT);
|
||||||
} else if (remote_action.m.flag == MouseFlag::right_up) {
|
break;
|
||||||
SimulateKeyUp(uinput_fd_, BTN_RIGHT);
|
case MouseFlag::right_down:
|
||||||
} else {
|
SimulateKeyDown(uinput_fd_, BTN_RIGHT);
|
||||||
SetMousePosition(uinput_fd_, mouse_pos_x, mouse_pos_y);
|
break;
|
||||||
|
case MouseFlag::right_up:
|
||||||
|
SimulateKeyUp(uinput_fd_, BTN_RIGHT);
|
||||||
|
break;
|
||||||
|
case MouseFlag::middle_down:
|
||||||
|
SimulateKeyDown(uinput_fd_, BTN_MIDDLE);
|
||||||
|
break;
|
||||||
|
case MouseFlag::middle_up:
|
||||||
|
SimulateKeyUp(uinput_fd_, BTN_MIDDLE);
|
||||||
|
break;
|
||||||
|
case MouseFlag::wheel_vertical:
|
||||||
|
event.type = EV_REL;
|
||||||
|
event.code = REL_WHEEL;
|
||||||
|
event.value = remote_action.m.s;
|
||||||
|
write(uinput_fd_, &event, sizeof(event));
|
||||||
|
break;
|
||||||
|
case MouseFlag::wheel_horizontal:
|
||||||
|
event.type = EV_REL;
|
||||||
|
event.code = REL_HWHEEL;
|
||||||
|
event.value = remote_action.m.s;
|
||||||
|
write(uinput_fd_, &event, sizeof(event));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SetMousePosition(uinput_fd_, mouse_pos_x, mouse_pos_y);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,27 +27,60 @@ int MouseController::SendMouseCommand(RemoteAction remote_action) {
|
|||||||
int mouse_pos_y = remote_action.m.y * screen_height_ / pixel_height_;
|
int mouse_pos_y = remote_action.m.y * screen_height_ / pixel_height_;
|
||||||
|
|
||||||
if (remote_action.type == ControlType::mouse) {
|
if (remote_action.type == ControlType::mouse) {
|
||||||
CGEventRef mouse_event;
|
CGEventRef mouse_event = nullptr;
|
||||||
CGEventType mouse_type;
|
CGEventType mouse_type;
|
||||||
|
CGPoint mouse_point = CGPointMake(mouse_pos_x, mouse_pos_y);
|
||||||
|
|
||||||
if (remote_action.m.flag == MouseFlag::left_down) {
|
switch (remote_action.m.flag) {
|
||||||
mouse_type = kCGEventLeftMouseDown;
|
case MouseFlag::left_down:
|
||||||
} else if (remote_action.m.flag == MouseFlag::left_up) {
|
mouse_type = kCGEventLeftMouseDown;
|
||||||
mouse_type = kCGEventLeftMouseUp;
|
mouse_event = CGEventCreateMouseEvent(NULL, mouse_type, mouse_point,
|
||||||
} else if (remote_action.m.flag == MouseFlag::right_down) {
|
kCGMouseButtonLeft);
|
||||||
mouse_type = kCGEventRightMouseDown;
|
break;
|
||||||
} else if (remote_action.m.flag == MouseFlag::right_up) {
|
case MouseFlag::left_up:
|
||||||
mouse_type = kCGEventRightMouseUp;
|
mouse_type = kCGEventLeftMouseUp;
|
||||||
} else {
|
mouse_event = CGEventCreateMouseEvent(NULL, mouse_type, mouse_point,
|
||||||
mouse_type = kCGEventMouseMoved;
|
kCGMouseButtonLeft);
|
||||||
|
break;
|
||||||
|
case MouseFlag::right_down:
|
||||||
|
mouse_type = kCGEventRightMouseDown;
|
||||||
|
mouse_event = CGEventCreateMouseEvent(NULL, mouse_type, mouse_point,
|
||||||
|
kCGMouseButtonRight);
|
||||||
|
break;
|
||||||
|
case MouseFlag::right_up:
|
||||||
|
mouse_type = kCGEventRightMouseUp;
|
||||||
|
mouse_event = CGEventCreateMouseEvent(NULL, mouse_type, mouse_point,
|
||||||
|
kCGMouseButtonRight);
|
||||||
|
break;
|
||||||
|
case MouseFlag::middle_down:
|
||||||
|
mouse_type = kCGEventOtherMouseDown;
|
||||||
|
mouse_event = CGEventCreateMouseEvent(NULL, mouse_type, mouse_point,
|
||||||
|
kCGMouseButtonCenter);
|
||||||
|
break;
|
||||||
|
case MouseFlag::middle_up:
|
||||||
|
mouse_type = kCGEventOtherMouseUp;
|
||||||
|
mouse_event = CGEventCreateMouseEvent(NULL, mouse_type, mouse_point,
|
||||||
|
kCGMouseButtonCenter);
|
||||||
|
break;
|
||||||
|
case MouseFlag::wheel_vertical:
|
||||||
|
mouse_event = CGEventCreateScrollWheelEvent(
|
||||||
|
NULL, kCGScrollEventUnitLine, 2, remote_action.m.s, 0);
|
||||||
|
break;
|
||||||
|
case MouseFlag::wheel_horizontal:
|
||||||
|
mouse_event = CGEventCreateScrollWheelEvent(
|
||||||
|
NULL, kCGScrollEventUnitLine, 2, 0, remote_action.m.s);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mouse_type = kCGEventMouseMoved;
|
||||||
|
mouse_event = CGEventCreateMouseEvent(NULL, mouse_type, mouse_point,
|
||||||
|
kCGMouseButtonLeft);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mouse_event = CGEventCreateMouseEvent(NULL, mouse_type,
|
if (mouse_event) {
|
||||||
CGPointMake(mouse_pos_x, mouse_pos_y),
|
CGEventPost(kCGHIDEventTap, mouse_event);
|
||||||
kCGMouseButtonLeft);
|
CFRelease(mouse_event);
|
||||||
|
}
|
||||||
CGEventPost(kCGHIDEventTap, mouse_event);
|
|
||||||
CFRelease(mouse_event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -22,18 +22,43 @@ int MouseController::SendMouseCommand(RemoteAction remote_action) {
|
|||||||
ip.type = INPUT_MOUSE;
|
ip.type = INPUT_MOUSE;
|
||||||
ip.mi.dx = (LONG)remote_action.m.x;
|
ip.mi.dx = (LONG)remote_action.m.x;
|
||||||
ip.mi.dy = (LONG)remote_action.m.y;
|
ip.mi.dy = (LONG)remote_action.m.y;
|
||||||
if (remote_action.m.flag == MouseFlag::left_down) {
|
|
||||||
ip.mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE;
|
switch (remote_action.m.flag) {
|
||||||
} else if (remote_action.m.flag == MouseFlag::left_up) {
|
case MouseFlag::left_down:
|
||||||
ip.mi.dwFlags = MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE;
|
ip.mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE;
|
||||||
} else if (remote_action.m.flag == MouseFlag::right_down) {
|
break;
|
||||||
ip.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_ABSOLUTE;
|
case MouseFlag::left_up:
|
||||||
} else if (remote_action.m.flag == MouseFlag::right_up) {
|
ip.mi.dwFlags = MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE;
|
||||||
ip.mi.dwFlags = MOUSEEVENTF_RIGHTUP | MOUSEEVENTF_ABSOLUTE;
|
break;
|
||||||
} else {
|
case MouseFlag::right_down:
|
||||||
ip.mi.dwFlags = MOUSEEVENTF_MOVE;
|
ip.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_ABSOLUTE;
|
||||||
|
break;
|
||||||
|
case MouseFlag::right_up:
|
||||||
|
ip.mi.dwFlags = MOUSEEVENTF_RIGHTUP | MOUSEEVENTF_ABSOLUTE;
|
||||||
|
break;
|
||||||
|
case MouseFlag::middle_down:
|
||||||
|
ip.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN | MOUSEEVENTF_ABSOLUTE;
|
||||||
|
break;
|
||||||
|
case MouseFlag::middle_up:
|
||||||
|
ip.mi.dwFlags = MOUSEEVENTF_MIDDLEUP | MOUSEEVENTF_ABSOLUTE;
|
||||||
|
break;
|
||||||
|
case MouseFlag::wheel_vertical:
|
||||||
|
ip.mi.dwFlags = MOUSEEVENTF_WHEEL;
|
||||||
|
ip.mi.mouseData = remote_action.m.s;
|
||||||
|
break;
|
||||||
|
case MouseFlag::wheel_horizontal:
|
||||||
|
ip.mi.dwFlags = MOUSEEVENTF_HWHEEL;
|
||||||
|
ip.mi.mouseData = remote_action.m.s;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ip.mi.dwFlags = MOUSEEVENTF_MOVE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ip.mi.mouseData = 0;
|
|
||||||
|
ip.mi.mouseData = (remote_action.m.flag == MouseFlag::wheel_vertical ||
|
||||||
|
remote_action.m.flag == MouseFlag::wheel_horizontal)
|
||||||
|
? remote_action.m.s
|
||||||
|
: 0;
|
||||||
ip.mi.time = 0;
|
ip.mi.time = 0;
|
||||||
|
|
||||||
SetCursorPos(ip.mi.dx, ip.mi.dy);
|
SetCursorPos(ip.mi.dx, ip.mi.dy);
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ int Render::ProcessMouseEvent(SDL_Event &event) {
|
|||||||
remote_action.m.flag = MouseFlag::left_down;
|
remote_action.m.flag = MouseFlag::left_down;
|
||||||
} else if (SDL_BUTTON_RIGHT == event.button.button) {
|
} else if (SDL_BUTTON_RIGHT == event.button.button) {
|
||||||
remote_action.m.flag = MouseFlag::right_down;
|
remote_action.m.flag = MouseFlag::right_down;
|
||||||
|
} else if (SDL_BUTTON_MIDDLE == event.button.button) {
|
||||||
|
remote_action.m.flag = MouseFlag::middle_down;
|
||||||
}
|
}
|
||||||
SendDataFrame(props->peer_, (const char *)&remote_action,
|
SendDataFrame(props->peer_, (const char *)&remote_action,
|
||||||
sizeof(remote_action));
|
sizeof(remote_action));
|
||||||
@@ -83,12 +85,33 @@ int Render::ProcessMouseEvent(SDL_Event &event) {
|
|||||||
remote_action.m.flag = MouseFlag::left_up;
|
remote_action.m.flag = MouseFlag::left_up;
|
||||||
} else if (SDL_BUTTON_RIGHT == event.button.button) {
|
} else if (SDL_BUTTON_RIGHT == event.button.button) {
|
||||||
remote_action.m.flag = MouseFlag::right_up;
|
remote_action.m.flag = MouseFlag::right_up;
|
||||||
|
} else if (SDL_BUTTON_MIDDLE == event.button.button) {
|
||||||
|
remote_action.m.flag = MouseFlag::middle_up;
|
||||||
}
|
}
|
||||||
SendDataFrame(props->peer_, (const char *)&remote_action,
|
SendDataFrame(props->peer_, (const char *)&remote_action,
|
||||||
sizeof(remote_action));
|
sizeof(remote_action));
|
||||||
} else if (SDL_MOUSEMOTION == event.type) {
|
} else if (SDL_MOUSEMOTION == event.type) {
|
||||||
remote_action.type = ControlType::mouse;
|
remote_action.type = ControlType::mouse;
|
||||||
remote_action.m.flag = MouseFlag::move;
|
remote_action.m.flag = MouseFlag::move;
|
||||||
|
SendDataFrame(props->peer_, (const char *)&remote_action,
|
||||||
|
sizeof(remote_action));
|
||||||
|
} else if (SDL_MOUSEWHEEL == event.type) {
|
||||||
|
int scroll_x = event.wheel.x;
|
||||||
|
int scroll_y = event.wheel.y;
|
||||||
|
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
|
||||||
|
scroll_x = -scroll_x;
|
||||||
|
scroll_y = -scroll_y;
|
||||||
|
}
|
||||||
|
|
||||||
|
remote_action.type = ControlType::mouse;
|
||||||
|
if (scroll_x == 0) {
|
||||||
|
remote_action.m.flag = MouseFlag::wheel_vertical;
|
||||||
|
remote_action.m.s = scroll_y;
|
||||||
|
} else if (scroll_y == 0) {
|
||||||
|
remote_action.m.flag = MouseFlag::wheel_horizontal;
|
||||||
|
remote_action.m.s = scroll_x;
|
||||||
|
}
|
||||||
|
|
||||||
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