Fix dock-swipe gestures broken on macOS 27 #1924
Open
zhaoqiman wants to merge 1 commit into
Open
Conversation
…ed CGEvent offsets CGEventSetIOHIDEvent() attaches an IOHIDEvent to a CGEvent by poking the pointer into the opaque CGEvent/CGSEventRecord struct at hardcoded offsets (0x18 / 0xd0). Those offsets were never a stable ABI, and the struct layout shifted on macOS 27, so the pointer ends up at the wrong address and Dock never sees a real IOHIDEvent - which is why every synthetic dock-swipe gesture (Spaces, Mission Control, Show Desktop, Launchpad) silently stopped doing anything. See noah-nuebling#1871 and the pile of duplicates (noah-nuebling#1873, noah-nuebling#1878, noah-nuebling#1887, noah-nuebling#1891, noah-nuebling#1892, noah-nuebling#1919, ...). Now prefers Apple's own SLEventSetIOHIDEvent, resolved once via the project's existing MFLoadSymbol_native(kMFFrameworkSkyLight, ...) helper (Shared/Utility/PrivateFunctions) instead of a hand-rolled dlsym call. Also retains the IOHIDEventRef on this path, same as the old offset-writer did, since SLEventSetIOHIDEvent's retain contract isn't documented and an extra retain is safer than an under-retain. The offset-writer is kept as a fallback only for pre-macOS-27, where it was actually validated - on 27+ it's skipped instead of executed, since those offsets are already known to be wrong there and running it would provide no real safety net, just continued exposure to writing an unvalidated address. Tested on macOS 27 - Spaces/Mission Control/Show Desktop click-and-drag all work again after this. Same root cause as noah-nuebling#1920, noah-nuebling#1912, noah-nuebling#1916 (also switch to SLEventSetIOHIDEvent); related to noah-nuebling#1895, noah-nuebling#1918.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1871 and the duplicates (#1873, #1878, #1887, #1891, #1892, #1919, ...).
Problem
CGEventSetIOHIDEvent()attaches an IOHIDEvent to a CGEvent by poking the pointer into the opaque CGEvent/CGSEventRecord struct at hardcoded offsets (0x18 / 0xd0). Those offsets were never a stable ABI, and the struct layout shifted on macOS 27, so the pointer ends up at the wrong address and Dock never sees a real IOHIDEvent - which is why every synthetic dock-swipe gesture (Spaces, Mission Control, Show Desktop, Launchpad) silently stopped doing anything.Fix
Prefers Apple's own
SLEventSetIOHIDEvent, resolved once via the project's existingMFLoadSymbol_native(kMFFrameworkSkyLight, ...)helper (Shared/Utility/PrivateFunctions). Falls back to the offset-writer only pre-macOS-27, where it was actually validated - on 27+ it's skipped instead of executed, since it's already known to be broken there.Notes
Same root cause and fix direction as #1920 / #1912 / #1916 (swap to
SLEventSetIOHIDEvent). A couple of things that came up while testing, in case they're useful:MFLoadSymbol_native/kMFFrameworkSkyLightinstead of hand-rolling adlsymcall.CFRetains theIOHIDEventRefon the new path, matching what the old offset-writer already did -SLEventSetIOHIDEvent's retain contract isn't documented anywhere, andTouchSimulator.mcan repost some dock-swipe events up to 500ms later via a timer, so skipping the retain risks a use-after-free if the event isn't retained internally.Testing
Tested on macOS 27 - Spaces/Mission Control/Show Desktop click-and-drag all work again after this.