-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTweak.xm
354 lines (276 loc) · 7.86 KB
/
Tweak.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
const CGFloat firmware = [[UIDevice currentDevice].systemVersion floatValue];
static bool kEnabled = YES;
static bool kiPadCapable = YES;
//This rotates most apps. May cause issues in some apps on some devices (beta feature)
static bool kWantsDeviceIdiom1;
// fake device into thinking it's iPad (beta feature)
static bool kWantsLockscreenRotation = YES;
//Lockscreen rotation
static bool kWantsIpadStyle = YES;
//landscape iPad rotation style
static bool kIphoneStyleRotation = YES;
//iPhone plus rotation style
static bool kCCisAlwaysRotated = YES;
//iOS 10 CC always shifted
static bool kWantsDragging = YES;
//Can rotate while dragging icons
static bool kHideLabels;
static bool twoRowTweakInstalled; //currently only checking for Docky
static bool kWantsCustomDock; //Wants 12 icon dock (iOS 10-12.4.x only) FolderControllerXII and FCXIII both have custom number of icons in dock.
static bool kRotateMoreApps;
/*This is one of the main methods that rotates apps and makes them more like iPad, but it incorrectly splits or crashes some on compact devices and iPhoneX. Might need to use an AppList for this at some point. */
%hook SBApplication
-(BOOL)isMedusaCapable {
if(kEnabled && kiPadCapable) {
return YES;
}
return %orig;
}
%end
//iOS 11.0-12.4.x only method
%hook SBHomeScreenViewController
-(bool)homeScreenAutorotatesEvenWhenIconIsDragging {
if(kEnabled && kWantsDragging) {
return TRUE;
}
return %orig;
}
-(void)setHomeScreenAutorotatesEvenWhenIconIsDragging:(bool)arg1 {
if(kEnabled && kWantsDragging) {
arg1= TRUE;
return %orig(arg1);
}
return %orig;
}
%end
//Lockscreen rotation
%hook SBDashBoardViewController
-(bool) shouldAutorotate {
if(kEnabled && kWantsLockscreenRotation) {
return TRUE;
}
return %orig;
}
%end
%hook SBMedusaSettings
-(bool)anyRotationDebuggingEnabled {
if(kEnabled) {
return TRUE;
}
return %orig;
}
%end
/*
Normal iOS 11 plus style rotation with verticle dock is automatically picked if enabled is on. iPad style is picked if stacked is on.
*/
%hook SpringBoard
-(long long) homeScreenRotationStyle {
if(kEnabled && kWantsIpadStyle) {
return 1;
//iPad rotation style
}
else if(kEnabled) {
return 2;
}
else {
return %orig;
}
}
%end
//works on some apps, about to try hooking the class for all instances
//this method is experimental- not in any public builds yet
%hook UIViewController
-(bool)_ignoreAppSupportedOrientations {
if(kEnabled && kRotateMoreApps) {
return 1;
}
return %orig;
}
%end
%hook SBRootIconListView
-(double)topIconInset {
if(kEnabled && kWantsIpadStyle) {
return twoRowTweakInstalled ? 20.f : 0.0009f;
//if two row tweak(Docky) is installed return 20.f else return 0.0009f
}
return %orig;
}
- (double)bottomIconInset {
if(kEnabled && kWantsIpadStyle) {
return 0.0009;
}
return %orig;
}
%end
%hook SBIconListView
-(long long)orientation {
if(kEnabled && kWantsIpadStyle) {
return 1;
}
return %orig;
}
%end
//This method hides the labels by setting scale to zero
%hook SBIconLabelImageParametersBuilder
- (double)_scale {
if(kEnabled && kHideLabels) {
return 0;
}
return %orig;
}
%end
%hook SBIconView
-(void) setLabelAccessoryViewHidden:(bool)arg1 { //Hides the cloud for offloaded apps, new-install dots...looks cleaner
if(kEnabled && kHideLabels) {
arg1= YES;
return %orig(arg1);
}
return %orig;
}
-(void) setIconLabelAlpha:(double)arg1 {
if(kEnabled && kHideLabels) {
arg1= 0; //hide labels by making transparent or zero alpha
return %orig(arg1);
}
return %orig;
}
%end
%hook SBMainSwitcherViewController
- (bool)shouldAutorotate {
if(kEnabled) {
return 1;
}
return %orig;
}
%end
%hook SBRootFolderController
- (bool)_shouldSlideDockOutDuringRotationFromOrientation:(long long)arg1 toOrientation:(long long)arg2 {
if(kEnabled && kWantsIpadStyle) {
arg1 = 2;
return YES;
%orig;
}
return %orig;
}
%end
%group iOS13UP
%hook SBRootFolderDockIconListView
+(NSInteger)rotationAnchor {
if(kEnabled) {
return 0;
}
return %orig;
}
%end
%hook SBDockIconListView
+(NSInteger)rotationAnchor {
if(kEnabled) {
return 0;
}
return %orig;
}
%end
%hook SBRootFolderController
-(BOOL)isDockPinnedForRotation {
if(kEnabled && kWantsIpadStyle) {
return 0;
}
else if(kEnabled) {
return 1;
}
else {
return %orig;
}
}
%end
%end //end of group iOS13UP
// sideways CC for ios 10, this isn't updated for iOS 11+ yet
%hook CCUIControlCenterPageContainerViewController
-(long long) layoutStyle {
if(kCCisAlwaysRotated && kEnabled) {
return 1;
}
return %orig;
}
%end
// 12 icon dock for iOS 10-12.4.x
%hook SBDockIconListView
+ (unsigned long long)maxIcons {
if(!kEnabled || !kWantsCustomDock) {
return %orig;
}
else if(kEnabled && kWantsCustomDock && (firmware <13.0)) {
return 13; //Allows up to 12 icons or folder icons in the dock at once.
}
else {
return %orig;
}
}
- (bool)allowsAddingIconCount:(unsigned long long)count {
if(kEnabled && kWantsCustomDock && (firmware < 13.0) && (count < 13)) {
return 1;
%orig;
}
return %orig;
}
%end
//Just added last update
%hook UIClientRotationContext
-(void)setupRotationOrderingKeyboardInAfterRotation:(bool)arg1 {
if(kEnabled) {
arg1= YES;
return %orig(arg1);
}
return %orig;
}
%end
//handle prefs with user defaults
static void
loadPrefs() {
static NSUserDefaults *prefs = [[NSUserDefaults alloc]
initWithSuiteName:@"com.i0stweak3r.autorotate"];
kEnabled = [prefs boolForKey:@"enabled"];
kWantsCustomDock = ([prefs boolForKey:@"wantsCustomDock"] && (firmware <13.0)) ? [prefs boolForKey:@"wantsCustomDock"] : NO;
kHideLabels = [prefs boolForKey:@"hideLabels"];
kWantsLockscreenRotation = [prefs boolForKey:@"key1"];
kWantsIpadStyle = [prefs boolForKey:@"key2"];
//iPadStyleRotation
kIphoneStyleRotation = [prefs boolForKey:@"key3"];
//defaults to this style if neither stye are selected, not really needed.
kCCisAlwaysRotated = [prefs boolForKey:@"key31"];
//iOS 10 only so far.
// Beta methods for rotating more apps and having more "medusa" capabilities.
kiPadCapable = [prefs boolForKey:@"iPadCapable"];
kWantsDeviceIdiom1 =[prefs boolForKey:@"wantsDeviceIdiom1"];
kRotateMoreApps = [prefs boolForKey@"rotateMoreApps"];
// Allows rotation while in icon editing mode on iOS 11-12.4.x. Found a similar method for 13+ just need to add it.
kWantsDragging = [prefs boolForKey:@"wantsDragging"];
}
%ctor {
CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(), NULL,
(CFNotificationCallback)loadPrefs,
CFSTR("com.i0stweak3r.autorotate/saved"), NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
loadPrefs();
if([[NSFileManager defaultManager] fileExistsAtPath:@"/Library/MobileSubstrate/DynamicLibraries/me.nepeta.docky.dylib"]) {
twoRowTweakInstalled = YES;
}
else { twoRowTweakInstalled = NO; }
%init; //ungrouped
if(firmware >= 13) {
%init(iOS13UP);
}
} //end of %ctor
/*
Skipping IconSupport, not working for A12 to have more then 4 icons in dock, and I prefer IconState now anyways.
If I add iOS 13-14 custom dock support I'll use Nepeta's IconState
// Register with IconSupport.
void *h = dlopen("/Library/MobileSubstrate/DynamicLibraries/IconSupport.dylib", RTLD_NOW);
if (h) {
[[objc_getClass("ISIconSupport") sharedInstance] addExtension:@"AutoRotate"];
}
*/