From 0d7414d89a5986a335c76c1338ded8fb97fa14a4 Mon Sep 17 00:00:00 2001 From: ZeroSegFault <97321703+ZeroSegFault@users.noreply.github.com> Date: Tue, 21 Jul 2026 11:20:00 +1000 Subject: [PATCH] fix(mac): preserve mouse event numbers when dragging on macOS 27 --- src/lib/platform/OSXScreen.mm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index f4fd158f9..02196e3ed 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -61,6 +61,12 @@ enum static const double kCarbonLoopWaitTimeout = 10.0; +// Synthetic mouse button and drag events require event numbers on macOS 27 and later. +static inline bool needsEventNumber() +{ + return NSProcessInfo.processInfo.operatingSystemVersion.majorVersion >= 27; +} + int getSecureInputEventPID(); std::string getProcessName(int pid); @@ -463,6 +469,10 @@ void OSXScreen::postMouseEvent(CGPoint &pos) const CGEventRef event = CGEventCreateMouseEvent(nullptr, type, pos, static_cast(button)); + if (button != -1 && needsEventNumber()) { + CGEventSetIntegerValueField(event, kCGMouseEventNumber, m_mouseEventNumber); + } + // Dragging events also need the click state CGEventSetIntegerValueField(event, kCGMouseEventClickState, m_clickState); @@ -547,8 +557,7 @@ void OSXScreen::fakeMouseButton(ButtonID id, bool press) CGEventRef event = CGEventCreateMouseEvent(nullptr, type, pos, static_cast(index)); - if (NSProcessInfo.processInfo.operatingSystemVersion.majorVersion >= 27) { - // Apps that use Carbon APIs on macOS 27 requires an incrementing event number for each synthetic click + if (needsEventNumber()) { if (press) { if (m_mouseEventNumber == 0) { // For some unknown reason, the first click event number must be unique and greater (but in the same ballpark)