Skip to content

Commit 6434fdc

Browse files
committed
Update for macOS 14 and 15
1 parent 91bd085 commit 6434fdc

File tree

6 files changed

+3094
-358
lines changed

6 files changed

+3094
-358
lines changed

dockInjection/dockInjection.m

Lines changed: 97 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -69,32 +69,45 @@ static bool isDoubleTapEvent(CGEventType type, CGGesturePhase phase, uint64_t di
6969
return type == dockSwipeEvent && phase == kCGGesturePhaseNone && direction == kIOHIDGestureMotionDoubleTap;
7070
}
7171

72-
static void swizzle_handleEvent(id self, SEL _cmd, CGEventRef event)
72+
static void checkDockEvent(CGEventRef event)
7373
{
74-
if (event) {
75-
CGEventType type = CGEventGetType(event);
76-
CGGesturePhase phase = (CGGesturePhase)CGEventGetIntegerValueField(event, dockSwipeGestureMotion);
77-
uint64_t direction = (CGGesturePhase)CGEventGetIntegerValueField(event, dockSwipeGesturePhase);
78-
79-
if (isStartOfTrackpadSwipeUpEvent(type, phase, direction)) {
74+
if (!event) {
75+
return;
76+
}
77+
78+
CGEventType type = CGEventGetType(event);
79+
CGGesturePhase phase = (CGGesturePhase)CGEventGetIntegerValueField(event, dockSwipeGestureMotion);
80+
uint64_t direction = (CGGesturePhase)CGEventGetIntegerValueField(event, dockSwipeGesturePhase);
81+
82+
if (isStartOfTrackpadSwipeUpEvent(type, phase, direction)) {
8083
#ifdef VERBOSE
81-
NSLog(@"forceFullDesktopBar: Caught beginning of vertical swipe, will override pointer position");
84+
NSLog(@"forceFullDesktopBar: Caught beginning of vertical swipe, will override pointer position");
8285
#endif
83-
mouseOverrideCount = 2;
86+
mouseOverrideCount = 2;
8487

85-
} else if (isDoubleTapEvent(type, phase, direction)) {
88+
} else if (isDoubleTapEvent(type, phase, direction)) {
8689
#ifdef VERBOSE
87-
NSLog(@"forceFullDesktopBar: Caught magic mouse double tap, will override pointer position");
90+
NSLog(@"forceFullDesktopBar: Caught magic mouse double tap, will override pointer position");
8891
#endif
89-
mouseOverrideCount = 2;
90-
}
92+
mouseOverrideCount = 2;
9193
}
92-
94+
}
95+
96+
static void swizzle_handleEvent(id self, SEL _cmd, CGEventRef event)
97+
{
98+
checkDockEvent(event);
9399
void (*originalFunction)(id, SEL, CGEventRef) = (void (*)(id, SEL, CGEventRef))originalHandleEvent;
94100
originalFunction(self, _cmd, event);
95101
}
96102

97-
static CGPoint overrideCGSCurrentInputPointerPosition()
103+
static void swizzle_handleEventWithType(id self, SEL _cmd, CGEventRef event, CGEventType type)
104+
{
105+
checkDockEvent(event);
106+
void (*originalFunction)(id, SEL, CGEventRef, CGEventType) = (void (*)(id, SEL, CGEventRef, CGEventType))originalHandleEvent;
107+
originalFunction(self, _cmd, event, type);
108+
}
109+
110+
static CGPoint overrideCGSCurrentInputPointerPosition(void)
98111
{
99112
CGPoint result = CGSCurrentInputPointerPosition();
100113

@@ -114,14 +127,14 @@ bool swizzleMethod(NSString *className, SEL orig, IMP newMethod, IMP *originalFu
114127
id targetClass = NSClassFromString(className);
115128

116129
if (!targetClass) {
117-
NSLog(@"forceFullDesktopBar error: Unable to find %@ class... cannot proceed", className);
130+
NSLog(@"forceFullDesktopBar error: Unable to find %@ class", className);
118131
return false;
119132
}
120133

121134
Method origMethod = class_getInstanceMethod(targetClass, orig);
122135

123136
if (!origMethod) {
124-
NSLog(@"forceFullDesktopBar error: Unable to find target method in %@ class... cannot proceed", className);
137+
NSLog(@"forceFullDesktopBar error: Unable to find target method in %@ class", className);
125138
return false;
126139
}
127140

@@ -132,28 +145,64 @@ bool swizzleMethod(NSString *className, SEL orig, IMP newMethod, IMP *originalFu
132145
return true;
133146
}
134147

135-
void macOS10_11Method()
148+
void macOS10_11Method(void)
136149
{
137150
swizzleMethod(@"WVExpose",
138151
@selector(_missionControlSetupSpacesStripControllerForDisplay:showFullBar:),
139152
(IMP)swizzle_missionControlSetupSpacesStripControllerForDisplay,
140153
&originalMissionControlSetupSpacesStripControllerForDisplay);
141154
}
142155

143-
void macOS10_13AndLaterMethod()
144-
{
156+
bool swizzleWVExposeMethod(void)
157+
{
145158
bool success = swizzleMethod(@"_TtC4Dock8WVExpose", @selector(changeMode:), (IMP)swizzle_changeMode,
146159
&originalChangeMode);
147-
if (!success) {
148-
return;
160+
if (success) {
161+
return true;
162+
}
163+
164+
NSLog(@"forceFullDesktopBar: _TtC4Dock8WVExpose class not found, trying another...");
165+
166+
success = swizzleMethod(@"WVExpose", @selector(changeMode:), (IMP)swizzle_changeMode, &originalChangeMode);
167+
168+
if (success) {
169+
return true;
149170
}
150171

151-
success = swizzleMethod(@"DOCKGestures",
152-
@selector(handleEvent:),
153-
(IMP)swizzle_handleEvent,
172+
NSLog(@"forceFullDesktopBar: unable to swizzle WVExpose method, cannot proceed.");
173+
174+
return false;
175+
}
176+
177+
bool swizzleDOCKGesturesMethod(void)
178+
{
179+
bool success = swizzleMethod(@"DOCKGestures", @selector(handleEvent:), (IMP)swizzle_handleEvent,
180+
&originalHandleEvent);
181+
182+
if (success) {
183+
return true;
184+
}
185+
186+
NSLog(@"forceFullDesktopBar: unable to swizzle [DOCKGestures handleEvent:], trying another");
187+
188+
success = swizzleMethod(@"DOCKGestures", @selector(handleEvent:type:), (IMP)swizzle_handleEventWithType,
154189
&originalHandleEvent);
155190

156-
if (!success) {
191+
if (success) {
192+
return true;
193+
}
194+
195+
NSLog(@"forceFullDesktopBar: unable to swizzle DOCKGestures method, cannot proceed.");
196+
return false;
197+
}
198+
199+
void macOS10_13AndLaterMethod(void)
200+
{
201+
if (!swizzleWVExposeMethod()) {
202+
return;
203+
}
204+
205+
if (!swizzleDOCKGesturesMethod()) {
157206
return;
158207
}
159208

@@ -170,7 +219,27 @@ void macOS10_13AndLaterMethod()
170219

171220
gum_interceptor_begin_transaction(interceptor);
172221

173-
GumReplaceReturn result = gum_interceptor_replace(interceptor, (gpointer) gum_module_find_export_by_name (NULL, "CGSCurrentInputPointerPosition"), overrideCGSCurrentInputPointerPosition, NULL, NULL);
222+
GError *error = nil;
223+
GumModule *module = gum_module_load("/System/Library/CoreServices/Dock.app/Contents/MacOS/Dock", &error);
224+
225+
if (!module || error) {
226+
NSLog(@"forceFullDesktopBar error: gum_module_load failed ... cannot proceed");
227+
228+
if (error && error->message) {
229+
NSLog(@"forceFullDesktopBar error message: %s", error->message);
230+
}
231+
232+
return;
233+
}
234+
235+
GumAddress funcAddr = gum_module_find_export_by_name (module, "CGSCurrentInputPointerPosition");
236+
237+
if (!funcAddr) {
238+
NSLog(@"forceFullDesktopBar error: gum_module_find_export_by_name failed ... cannot proceed");
239+
return;
240+
}
241+
242+
GumReplaceReturn result = gum_interceptor_replace(interceptor, (gpointer) funcAddr, overrideCGSCurrentInputPointerPosition, NULL, NULL);
174243

175244
if (result != GUM_REPLACE_OK) {
176245
NSLog(@"forceFullDesktopBar error: gum_interceptor_replace failed with result: %d ... cannot proceed", result);
@@ -182,7 +251,7 @@ void macOS10_13AndLaterMethod()
182251
NSLog(@"forceFullDesktopBar: successfully rebound CGSCurrentInputPointerPosition symbol");
183252
}
184253

185-
__attribute__((constructor)) static void install()
254+
__attribute__((constructor)) static void install(void)
186255
{
187256
NSLog(@"forceFullDesktopBar: dockInjection installed and running");
188257

0 commit comments

Comments
 (0)