Fix: Web remote desktop double-click not working for macOS clients

This commit is contained in:
yuanyuanxiang
2026-05-01 11:08:12 +02:00
parent cfa9b581fc
commit ed4b9eeb25
5 changed files with 40 additions and 29 deletions

View File

@@ -156,6 +156,8 @@ void InputHandler::handleMouseButton(CGMouseButton button, bool down, int x, int
CGEventRef event = CGEventCreateMouseEvent(NULL, eventType, point, button);
if (event) {
// clickState=1 for all single clicks
CGEventSetIntegerValueField(event, kCGMouseEventClickState, 1);
CGEventPost(kCGHIDEventTap, event);
CFRelease(event);
}
@@ -163,6 +165,13 @@ void InputHandler::handleMouseButton(CGMouseButton button, bool down, int x, int
void InputHandler::handleMouseDoubleClick(CGMouseButton button, int x, int y)
{
// WM_LBUTTONDBLCLK represents the second click of a double-click.
// The first click was already sent via WM_LBUTTONDOWN/WM_LBUTTONUP.
//
// We send complete down(2) + up(2) here because:
// - Web client: dblclick fires AFTER mouseup, no subsequent WM_LBUTTONUP
// - MFC client: WM_LBUTTONUP follows, but extra up(1) is harmless
CGPoint point = CGPointMake(x, y);
m_lastMousePos = point;
@@ -184,36 +193,24 @@ void InputHandler::handleMouseDoubleClick(CGMouseButton button, int x, int y)
break;
}
// First click (clickState=1)
CGEventRef down1 = CGEventCreateMouseEvent(NULL, downType, point, button);
CGEventRef up1 = CGEventCreateMouseEvent(NULL, upType, point, button);
// Send second click: down(2) + up(2)
CGEventRef down = CGEventCreateMouseEvent(NULL, downType, point, button);
CGEventRef up = CGEventCreateMouseEvent(NULL, upType, point, button);
if (down1 && up1) {
CGEventSetIntegerValueField(down1, kCGMouseEventClickState, 1);
CGEventSetIntegerValueField(up1, kCGMouseEventClickState, 1);
CGEventPost(kCGHIDEventTap, down1);
CGEventPost(kCGHIDEventTap, up1);
if (down) {
CGEventSetIntegerValueField(down, kCGMouseEventClickState, 2);
CGEventPost(kCGHIDEventTap, down);
CFRelease(down);
}
if (down1) CFRelease(down1);
if (up1) CFRelease(up1);
// Brief delay between clicks (50ms)
usleep(50000);
// Second click (clickState=2)
CGEventRef down2 = CGEventCreateMouseEvent(NULL, downType, point, button);
CGEventRef up2 = CGEventCreateMouseEvent(NULL, upType, point, button);
if (down2 && up2) {
CGEventSetIntegerValueField(down2, kCGMouseEventClickState, 2);
CGEventSetIntegerValueField(up2, kCGMouseEventClickState, 2);
CGEventPost(kCGHIDEventTap, down2);
CGEventPost(kCGHIDEventTap, up2);
if (up) {
CGEventSetIntegerValueField(up, kCGMouseEventClickState, 2);
CGEventPost(kCGHIDEventTap, up);
CFRelease(up);
}
if (down2) CFRelease(down2);
if (up2) CFRelease(up2);
// Note: For MFC client, an extra WM_LBUTTONUP will follow (sending up(1)),
// but this is harmless since mouse is already up.
}
void InputHandler::handleMouseWheel(int delta)