-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathTweak.xm
206 lines (186 loc) · 7.83 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
#import <UIKit/UIKit.h>
#import <libcolorpicker.h>
#import <CoreFoundation/CoreFoundation.h>
#import <SpringBoard/SpringBoard.h>
#import <Foundation/Foundation.h>
#define kIdentifier @"com.lnx.showtouch"
#define kSettingsChangedNotification (CFStringRef)@"com.lnx.showtouch/ReloadPrefs"
#define kScreenRecordChanged (CFStringRef)@"captured"
#define kColorChangedNotification (CFStringRef)@"com.lnx.showtouch/colorChanged"
#define kSettingsResetNotification (CFStringRef)@"com.lnx.showtouch/settingsReset"
#define kColorPath @"/var/mobile/Library/Preferences/com.lnx.showtouch.color.plist"
#define kSettingsPath @"/var/mobile/Library/Preferences/com.lnx.showtouch.plist"
@interface TouchWindow : UIWindow
@property (nonatomic, strong) NSTimer *hideTimer;
@end
@implementation TouchWindow
-(BOOL)_ignoresHitTest {
return YES;
}
@end
static TouchWindow *touchWindow1;
static TouchWindow *touchWindow2;
static TouchWindow *touchWindow3;
static CAShapeLayer *circleShape;
static UIColor *touchColor;
static NSInteger enabled;
static CGFloat touchSize;
@interface UITouchesEvent : UIEvent
-(id)_windows;
@end
@interface UIApplication (STUIApp)
-(SBApplication*)_accessibilityFrontMostApplication;
@end
%hook UITouchesEvent
-(void)_setHIDEvent:(id)arg1 {
if (enabled == 1){
dispatch_async(dispatch_get_main_queue(), ^{
SBApplication *currentApplication = [[objc_getClass("SpringBoard") sharedApplication] _accessibilityFrontMostApplication];
NSMutableArray *currentTouches;
if (@available(iOS 11.0, *)) {
currentTouches = [[[self valueForKey:@"_allTouchesMutable"] allObjects] mutableCopy];
} else {
currentTouches = [[[self valueForKey:@"_touches"] allObjects] mutableCopy];
}
if (currentTouches.count == 0) {
dispatch_async(dispatch_get_main_queue(), ^{
touchWindow1.hidden = YES;
touchWindow2.hidden = YES;
touchWindow3.hidden = YES;
touchWindow1 = nil;
touchWindow2 = nil;
touchWindow3 = nil;
});
}
else {
if (currentTouches.count == 1) {
touchWindow2.hidden = YES;
touchWindow2 = nil;
touchWindow3.hidden = YES;
touchWindow3 = nil;
}
else if (currentTouches.count == 2) {
touchWindow3.hidden = YES;
touchWindow3 = nil;
}
for (int i = 0; i < currentTouches.count; i++) {
UITouch *touch = currentTouches[i];
NSLog(@"%@ - %@ - %@", currentApplication, [UIApplication sharedApplication], touch.window);
BOOL shouldShowTouch = NO;
if (@available(iOS 11.0, *)) {
NSLog(@"ios 11");
shouldShowTouch = YES;
}
else {
NSLog(@"ios 10");
if ((!currentApplication && [touch.window isKindOfClass:%c(FBRootWindow)]) || ![touch.window isKindOfClass:%c(FBRootWindow)]) {
shouldShowTouch = YES;
}
else {
shouldShowTouch = NO;
}
}
if (shouldShowTouch) {
CGPoint touchLocation = [[touch valueForKey:@"_locationInWindow"] CGPointValue];
switch (i) {
case 0: {
dispatch_async(dispatch_get_main_queue(), ^{
if (!touchWindow1) {
touchWindow1 = [[TouchWindow alloc] initWithFrame:CGRectMake(touchLocation.x, touchLocation.y, touchSize, touchSize)];
}
CGRect touchFrame = touchWindow1.bounds;
touchFrame.size.width = touchFrame.size.height = touchSize;
touchWindow1.bounds = touchFrame;
touchWindow1.backgroundColor = touchColor;
touchWindow1.center = CGPointMake(touchLocation.x, touchLocation.y);
touchWindow1.windowLevel = UIWindowLevelStatusBar + 100000;
touchWindow1.userInteractionEnabled = NO;
touchWindow1.layer.cornerRadius = touchWindow1.bounds.size.width / 2;
touchWindow1.hidden = NO;
});
break;
}
case 1: {
dispatch_async(dispatch_get_main_queue(), ^{
if (!touchWindow2) {
touchWindow2 = [[TouchWindow alloc] initWithFrame:CGRectMake(touchLocation.x, touchLocation.y, touchSize, touchSize)];
}
CGRect touchFrame = touchWindow2.bounds;
touchFrame.size.width = touchFrame.size.height = touchSize;
touchWindow2.bounds = touchFrame;
touchWindow2.backgroundColor = touchColor;
touchWindow2.center = CGPointMake(touchLocation.x, touchLocation.y);
touchWindow2.windowLevel = UIWindowLevelStatusBar + 100000;
touchWindow2.userInteractionEnabled = NO;
touchWindow2.layer.cornerRadius = touchWindow2.bounds.size.width / 2;
touchWindow2.hidden = NO;
});
break;
}
case 2: {
dispatch_async(dispatch_get_main_queue(), ^{
if (!touchWindow3) {
touchWindow3 = [[TouchWindow alloc] initWithFrame:CGRectMake(touchLocation.x, touchLocation.y, touchSize, touchSize)];
}
CGRect touchFrame = touchWindow3.bounds;
touchFrame.size.width = touchFrame.size.height = touchSize;
touchWindow3.bounds = touchFrame;
touchWindow3.backgroundColor = touchColor;
touchWindow3.center = CGPointMake(touchLocation.x, touchLocation.y);
touchWindow3.windowLevel = UIWindowLevelStatusBar + 100000;
touchWindow3.userInteractionEnabled = NO;
touchWindow3.layer.cornerRadius = touchWindow3.bounds.size.width / 2;
touchWindow3.hidden = NO;
});
break;
}
default:
break;
}
}
}
}
});
}
%orig;
}
%end
static void reloadColorPrefs() {
NSDictionary *preferences = [NSDictionary dictionaryWithContentsOfFile:kColorPath];
touchColor = [preferences objectForKey:@"touchColor"] ? LCPParseColorString([preferences objectForKey:@"touchColor"], @"#FFFFFF") : [UIColor redColor];
}
static void reloadPrefs() {
CFPreferencesAppSynchronize((CFStringRef)kIdentifier);
NSDictionary *prefs = nil;
if ([NSHomeDirectory() isEqualToString:@"/var/mobile"]) {
CFArrayRef keyList = CFPreferencesCopyKeyList((CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
if (keyList != nil) {
prefs = (NSDictionary *)CFBridgingRelease(CFPreferencesCopyMultiple(keyList, (CFStringRef)kIdentifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
if (prefs == nil)
prefs = [NSDictionary dictionary];
CFRelease(keyList);
}
} else {
prefs = [NSDictionary dictionaryWithContentsOfFile:kSettingsPath];
}
enabled = [prefs objectForKey:@"enabled"] ? [[prefs objectForKey:@"enabled"] integerValue] : 0;
touchSize = [prefs objectForKey:@"touchSize"] ? [[prefs objectForKey:@"touchSize"] floatValue] : 30;
}
%ctor {
reloadPrefs();
reloadColorPrefs();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)reloadPrefs, kSettingsChangedNotification, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)reloadColorPrefs, kColorChangedNotification, NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
NSLog(@"ios 11");
if (enabled == 2) {
if (@available(iOS 11.0, *)) {
[[NSNotificationCenter defaultCenter] addObserverForName: UIScreenCapturedDidChangeNotification
object: nil
queue: nil
usingBlock: ^ (NSNotification * notification) {
enabled = UIScreen.mainScreen.captured ? 1 : 0;
}];
} else {
}
}
}