fix(mac): ensure background clicks work correctly on macOS 27

This commit is contained in:
Luiz Sardinha 2026-07-19 01:51:48 +02:00 committed by Nick Bolton
parent 48ee839357
commit d38c69c05d
2 changed files with 19 additions and 0 deletions

View file

@ -236,6 +236,9 @@ private:
mutable int32_t m_xCursor, m_yCursor; mutable int32_t m_xCursor, m_yCursor;
mutable bool m_cursorPosValid; mutable bool m_cursorPosValid;
// mouse event number (needed for macOS 27)
uint32_t m_mouseEventNumber = 0;
/* FIXME: this data structure is explicitly marked mutable due /* FIXME: this data structure is explicitly marked mutable due
to a need to track the state of buttons since the remote to a need to track the state of buttons since the remote
side only lets us know of change events, and because the side only lets us know of change events, and because the

View file

@ -547,6 +547,22 @@ void OSXScreen::fakeMouseButton(ButtonID id, bool press)
CGEventRef event = CGEventCreateMouseEvent(nullptr, type, pos, static_cast<CGMouseButton>(index)); CGEventRef event = CGEventCreateMouseEvent(nullptr, type, pos, static_cast<CGMouseButton>(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 (press) {
if (m_mouseEventNumber == 0) {
// For some unknown reason, the first click event number must be unique and greater (but in the same ballpark)
// than the last event number used by the system.
m_mouseEventNumber =
CGEventSourceCounterForEventType(kCGEventSourceStateHIDSystemState, kCGEventLeftMouseDown) +
CGEventSourceCounterForEventType(kCGEventSourceStateHIDSystemState, kCGEventRightMouseDown) +
CGEventSourceCounterForEventType(kCGEventSourceStateHIDSystemState, kCGEventOtherMouseDown);
}
++m_mouseEventNumber;
}
CGEventSetIntegerValueField(event, kCGMouseEventNumber, m_mouseEventNumber);
}
CGEventSetIntegerValueField(event, kCGMouseEventClickState, m_clickState); CGEventSetIntegerValueField(event, kCGMouseEventClickState, m_clickState);
// Fix for sticky keys // Fix for sticky keys