Skip to content

Commit

Permalink
#1801 replicate consumed mouse-click when no mouse-drag action is ini…
Browse files Browse the repository at this point in the history
…tiated
  • Loading branch information
koekeishiya committed Feb 21, 2024
1 parent a3dd1db commit cd940f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/mouse_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ static MOUSE_HANDLER(mouse_handler)
event_loop_post(&g_event_loop, MOUSE_DOWN, (void *) CFRetain(event), mod);

mouse_state->consume_mouse_click = mod == mouse_state->modifier;
if (mouse_state->consume_mouse_click) return NULL;
if (mouse_state->consume_mouse_click) {
mouse_state->consumed_event = (CGEventRef) CFRetain(event);
return NULL;
}
} break;
case kCGEventLeftMouseUp:
case kCGEventRightMouseUp: {
Expand All @@ -65,18 +68,9 @@ static MOUSE_HANDLER(mouse_handler)

if (mouse_state->consume_mouse_click) {
if (!mouse_state->drag_detected) {
CGPoint point = CGEventGetLocation(event);

if (type == kCGEventLeftMouseUp) {
CGPostMouseEvent(point, false, 1, true);
CGPostMouseEvent(point, false, 1, false);
} else {
CGEventRef mouse_event = CGEventCreateMouseEvent(NULL, kCGEventRightMouseDown, point, kCGMouseButtonRight);
CGEventPost(kCGHIDEventTap, mouse_event);
CGEventSetType(mouse_event, type);
CGEventPost(kCGHIDEventTap, mouse_event);
CFRelease(mouse_event);
}
CGEventTapPostEvent(proxy, mouse_state->consumed_event);
CGEventTapPostEvent(proxy, event);
CFRelease(mouse_state->consumed_event);
}

mouse_state->drag_detected = false;
Expand Down
1 change: 1 addition & 0 deletions src/mouse_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct mouse_state
CFRunLoopSourceRef runloop_source;
bool consume_mouse_click;
bool drag_detected;
CGEventRef consumed_event;
enum mouse_mode action1;
enum mouse_mode action2;
volatile uint8_t modifier;
Expand Down

0 comments on commit cd940f5

Please sign in to comment.