@@ -69,32 +69,45 @@ static bool isDoubleTapEvent(CGEventType type, CGGesturePhase phase, uint64_t di
69
69
return type == dockSwipeEvent && phase == kCGGesturePhaseNone && direction == kIOHIDGestureMotionDoubleTap ;
70
70
}
71
71
72
- static void swizzle_handleEvent ( id self, SEL _cmd, CGEventRef event)
72
+ static void checkDockEvent ( CGEventRef event)
73
73
{
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)) {
80
83
#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" );
82
85
#endif
83
- mouseOverrideCount = 2 ;
86
+ mouseOverrideCount = 2 ;
84
87
85
- } else if (isDoubleTapEvent (type, phase, direction)) {
88
+ } else if (isDoubleTapEvent (type, phase, direction)) {
86
89
#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" );
88
91
#endif
89
- mouseOverrideCount = 2 ;
90
- }
92
+ mouseOverrideCount = 2 ;
91
93
}
92
-
94
+ }
95
+
96
+ static void swizzle_handleEvent (id self, SEL _cmd, CGEventRef event)
97
+ {
98
+ checkDockEvent (event);
93
99
void (*originalFunction)(id , SEL , CGEventRef) = (void (*)(id , SEL , CGEventRef))originalHandleEvent;
94
100
originalFunction (self, _cmd, event);
95
101
}
96
102
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 )
98
111
{
99
112
CGPoint result = CGSCurrentInputPointerPosition ();
100
113
@@ -114,14 +127,14 @@ bool swizzleMethod(NSString *className, SEL orig, IMP newMethod, IMP *originalFu
114
127
id targetClass = NSClassFromString (className);
115
128
116
129
if (!targetClass) {
117
- NSLog (@" forceFullDesktopBar error: Unable to find %@ class... cannot proceed " , className);
130
+ NSLog (@" forceFullDesktopBar error: Unable to find %@ class" , className);
118
131
return false ;
119
132
}
120
133
121
134
Method origMethod = class_getInstanceMethod (targetClass, orig);
122
135
123
136
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);
125
138
return false ;
126
139
}
127
140
@@ -132,28 +145,64 @@ bool swizzleMethod(NSString *className, SEL orig, IMP newMethod, IMP *originalFu
132
145
return true ;
133
146
}
134
147
135
- void macOS10_11Method ()
148
+ void macOS10_11Method (void )
136
149
{
137
150
swizzleMethod (@" WVExpose" ,
138
151
@selector (_missionControlSetupSpacesStripControllerForDisplay:showFullBar: ),
139
152
(IMP )swizzle_missionControlSetupSpacesStripControllerForDisplay,
140
153
&originalMissionControlSetupSpacesStripControllerForDisplay);
141
154
}
142
155
143
- void macOS10_13AndLaterMethod ( )
144
- {
156
+ bool swizzleWVExposeMethod ( void )
157
+ {
145
158
bool success = swizzleMethod (@" _TtC4Dock8WVExpose" , @selector (changeMode: ), (IMP )swizzle_changeMode,
146
159
&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 ;
149
170
}
150
171
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,
154
189
&originalHandleEvent);
155
190
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 ()) {
157
206
return ;
158
207
}
159
208
@@ -170,7 +219,27 @@ void macOS10_13AndLaterMethod()
170
219
171
220
gum_interceptor_begin_transaction (interceptor);
172
221
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 );
174
243
175
244
if (result != GUM_REPLACE_OK) {
176
245
NSLog (@" forceFullDesktopBar error: gum_interceptor_replace failed with result: %d ... cannot proceed" , result);
@@ -182,7 +251,7 @@ void macOS10_13AndLaterMethod()
182
251
NSLog (@" forceFullDesktopBar: successfully rebound CGSCurrentInputPointerPosition symbol" );
183
252
}
184
253
185
- __attribute__ ((constructor)) static void install()
254
+ __attribute__ ((constructor)) static void install(void )
186
255
{
187
256
NSLog (@" forceFullDesktopBar: dockInjection installed and running" );
188
257
0 commit comments