-
Notifications
You must be signed in to change notification settings - Fork 4
/
Pivot.xm
374 lines (267 loc) · 6.84 KB
/
Pivot.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#include "Pivot.h"
#pragma mark Globals
NSDictionary *prefs = nil;
// 0: Disabled
// 1: Plus Style
// 2: iPad Style
static int _pfMode = 1;
static BOOL _pfDontRotateWallpaper = YES;
static BOOL _pfMedusa = YES;
static BOOL _pfInvert = YES;
static CGFloat _pfVPad = 5;
// 2 = Plus Style
// 1 = iPad Style
// Anything else disables it.
static int _rtRotationStyle = 2;
%group iOS6to12
%hook SBRootIconListView
+ (NSUInteger)iconColumnsForInterfaceOrientation:(NSInteger)arg1
{
if (UIDeviceOrientationIsLandscape(arg1))
return [%c(SBRootIconListView) iconRowsForInterfaceOrientation:1];
return %orig;
}
+ (NSUInteger)iconRowsForInterfaceOrientation:(NSInteger)arg1
{
if (UIDeviceOrientationIsLandscape(arg1))
return [%c(SBRootIconListView) iconColumnsForInterfaceOrientation:1];
return %orig;
}
- (NSUInteger)iconRowsForSpacingCalculation
{
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
return [%c(SBRootIconListView) iconColumnsForInterfaceOrientation:1];
return %orig;
}
+ (NSUInteger)maxVisibleIconRowsInterfaceOrientation:(NSInteger)arg1
{
if (UIDeviceOrientationIsLandscape(arg1))
return [%c(SBRootIconListView) iconColumnsForInterfaceOrientation:1];
return %orig;
}
%end
%end
%group iOS7Down
%hook SBOrientationLockManager
- (void)setLockOverrideEnabled:(BOOL)enabled forReason:(NSString *)reason
{
if ([reason isEqualToString:@"SBOrientationLockForSwitcher"])
enabled = NO;
%orig();
}
%end
%end
%group iOS7Up
%hook SBWallpaperController
-(BOOL)_isAcceptingOrientationChangesFromSource:(NSInteger)arg
{
return (!_pfDontRotateWallpaper);
}
%end
%end
%group iOS8Up
%hook SpringBoard
- (NSUInteger)homeScreenRotationStyle
{
return _rtRotationStyle;
}
- (BOOL)homeScreenSupportsRotation
{
return (_rtRotationStyle != 0);
}
%end
%end
%group iOS9Up
%hook SpringBoard
- (BOOL)supportsPortraitUpsideDownOrientation
{
return _pfInvert;
}
%end
%hook SBApplication
- (BOOL)isMedusaCapable
{
if (_pfMedusa)
{
return YES;
}
return %orig;
}
%end
%hook SBHomeScreenViewController
- (BOOL)homeScreenAutorotatesEvenWhenIconIsDragging
{
if (_pfMode !=0)
{
return TRUE;
}
return %orig;
}
- (void)setHomeScreenAutorotatesEvenWhenIconIsDragging:(BOOL)arg1
{
if (_pfMode !=0)
{
arg1 = TRUE;
return %orig(arg1);
}
return %orig;
}
%end
%end
%group iOS10Up
%hook SBDashBoardViewController
- (BOOL)shouldAutorotate
{
if(_pfMode != 0)
{
return TRUE;
}
return %orig;
}
%end
%hook SBCoverSheetWindow
- (BOOL)_shouldAutorotateToInterfaceOrientation:(NSInteger)arg checkForDismissal:(BOOL)arg1 isRotationDisabled:(BOOL *)arg2
{
BOOL x = %orig;
return (_pfMode != 0) ? YES : x;
}
- (BOOL)_shouldAutorotateToInterfaceOrientation:(NSInteger)arg
{
BOOL x = %orig;
return (_pfMode != 0) ? YES : x;
}
%end
%hook SBCoverSheetPrimarySlidingViewController
- (BOOL)shouldAutorotate
{
return (_pfMode != 0) ? YES : %orig;
}
%end
%hook CSCoverSheetViewController
- (BOOL)shouldAutorotate
{
return (_pfMode != 0) ? YES : %orig;
}
- (BOOL)shouldAutorotateForSource:(int)arg
{
return (_pfMode != 0) ? YES : %orig(arg);
}
%end
@interface SparkAlwaysOnWindow : UIWindow
@end
@interface PivotSparkRotationController : UIViewController
@end
@implementation PivotSparkRotationController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
@end
%hook SparkAlwaysOnWindow
- (id)initWithFrame:(CGRect)frame
{
id x = %orig;
self.rootViewController = [[PivotSparkRotationController alloc] init];
return x;
}
%end
%end
%group iOS13
%hook SBIconListGridLayoutConfiguration
- (UIEdgeInsets)landscapeLayoutInsets
{
UIEdgeInsets x = %orig;
NSUInteger rows = MSHookIvar<NSUInteger>(self, "_numberOfPortraitRows");
NSUInteger columns = MSHookIvar<NSUInteger>(self, "_numberOfPortraitColumns");
BOOL i = ( !( rows == 3 && columns == 3 ) && !( rows <=2 && columns <=5));
CGFloat h = [(SBIconController *)[%c(SBIconController) sharedInstance] _rootFolderController].dockHeight - 10;
if (i)
{
return UIEdgeInsetsMake(
5,
x.left + h,
5, // * 2 because regularly it was too slow
x.right + h*0.5
);
}
else
return x;
}
%end
%end
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//
//
// Pivot Preferences
// #pragma Preferences
//
//
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
static void *observer = NULL;
static void reloadPrefs()
{
if ([NSHomeDirectory() isEqualToString:@"/var/mobile"])
{
CFArrayRef keyList = CFPreferencesCopyKeyList((CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
if (keyList)
{
prefs = (NSDictionary *)CFBridgingRelease(CFPreferencesCopyMultiple(keyList, (CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
if (!prefs)
{
prefs = [NSDictionary new];
}
CFRelease(keyList);
}
}
else
{
prefs = [NSDictionary dictionaryWithContentsOfFile:kSettingsPath];
}
}
static void preferencesChanged()
{
CFPreferencesAppSynchronize((CFStringRef)kIdentifier);
reloadPrefs();
_pfMode = [[prefs valueForKey:@"rotationMode"] integerValue] ?: 1;
_pfDontRotateWallpaper = [prefs objectForKey:@"lockWallpaper"] ? [[prefs valueForKey:@"lockWallpaper"] boolValue] : YES;
_pfMedusa = [prefs objectForKey:@"medusa"] ? [[prefs valueForKey:@"medusa"] boolValue] : YES;
_pfInvert = [prefs objectForKey:@"invert"] ? [[prefs valueForKey:@"invert"] boolValue] : YES;
_pfVPad = [[prefs valueForKey:@"verticalPad"] floatValue] ?: 5.0;
if (_pfMode == 1) _rtRotationStyle = 2;
else if (_pfMode == 2) _rtRotationStyle = 1;
else _rtRotationStyle = 0;
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//
//
// Pivot Constructor
// #pragma ctor
//
//
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
%ctor
{
preferencesChanged();
CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(),
&observer,
(CFNotificationCallback)preferencesChanged,
kSettingsChangedNotification,
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately
);
if (kCFCoreFoundationVersionNumber > 840)
%init(iOS7Up);
if (kCFCoreFoundationVersionNumber < 1000)
%init(iOS7Down);
if (kCFCoreFoundationVersionNumber > 1000)
%init(iOS8Up);
if (kCFCoreFoundationVersionNumber > 1200)
%init(iOS9Up);
if (kCFCoreFoundationVersionNumber > 1300)
%init(iOS10Up);
if (kCFCoreFoundationVersionNumber > 1600)
%init(iOS13);
else
%init(iOS6to12);
}