-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTweak.xm
201 lines (165 loc) · 5.95 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
#import <UIKit/UIKit.h>
#import "GTFingerTipView.h"
#import "GTFingerTipOverlayWindow.h"
#define FADE_DURATION 0.2
#define PREFS_LOCATION @"/var/mobile/Library/Preferences/com.samstone.gotappa.plist"
static BOOL fingerTipRemovalScheduled;
@interface UIWindow ()
- (UIWindow *)overlayWindow;
- (void)scheduleFingerTipRemoval;
- (void)cancelScheduledFingerTipRemoval;
- (void)removeInactiveFingerTips;
- (void)removeFingerTipWithHash:(NSUInteger)hash;
- (BOOL)shouldAutomaticallyRemoveFingerTipForTouch:(UITouch *)touch;
@end
%group MainGroup
%hook UIWindow
%new
- (UIWindow *)overlayWindow
{
static UIWindow *overlayWindow = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
overlayWindow = [[GTFingerTipOverlayWindow alloc] initWithFrame:self.frame];
overlayWindow.userInteractionEnabled = NO;
overlayWindow.windowLevel = UIWindowLevelStatusBar;
overlayWindow.backgroundColor = [UIColor clearColor];
overlayWindow.hidden = NO;
});
return overlayWindow;
}
#pragma mark UIWindow overrides
- (void)sendEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
for (UITouch *touch in [allTouches allObjects])
{
switch (touch.phase)
{
case UITouchPhaseBegan:
case UITouchPhaseMoved:
case UITouchPhaseStationary:
{
GTFingerTipView *touchView = (GTFingerTipView *)[[self overlayWindow] viewWithTag:touch.hash];
if (touchView && [touchView isFadingOut])
{
[touchView removeFromSuperview];
touchView = nil;
}
if (!touchView)
{
touchView = [[GTFingerTipView alloc] init];
[[self overlayWindow] addSubview:touchView];
[touchView release];
}
if ( ! [touchView isFadingOut])
{
touchView.center = [touch locationInView:[self overlayWindow]];
touchView.tag = touch.hash;
touchView.timestamp = touch.timestamp;
touchView.shouldAutomaticallyRemoveAfterTimeout = [self shouldAutomaticallyRemoveFingerTipForTouch:touch];
}
break;
}
case UITouchPhaseEnded:
case UITouchPhaseCancelled:
{
[self removeFingerTipWithHash:touch.hash];
break;
}
}
}
[self scheduleFingerTipRemoval];
%orig;
}
#pragma mark Fingertip View Handling
%new
- (void)scheduleFingerTipRemoval
{
if (fingerTipRemovalScheduled)
return;
fingerTipRemovalScheduled = YES;
[self performSelector:@selector(removeInactiveFingerTips) withObject:nil afterDelay:0.1];
}
%new
- (void)cancelScheduledFingerTipRemoval
{
fingerTipRemovalScheduled = YES;
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(removeInactiveFingerTips) object:nil];
}
%new
- (void)removeInactiveFingerTips
{
fingerTipRemovalScheduled = NO;
NSTimeInterval now = [[NSProcessInfo processInfo] systemUptime];
const CGFloat REMOVAL_DELAY = 0.2;
for (GTFingerTipView *touchView in [[self overlayWindow] subviews])
{
if ( ! [touchView isKindOfClass:[GTFingerTipView class]])
continue;
if (touchView.shouldAutomaticallyRemoveAfterTimeout && now > touchView.timestamp + REMOVAL_DELAY)
[self removeFingerTipWithHash:touchView.tag];
}
if ([[[self overlayWindow] subviews] count] > 0)
[self scheduleFingerTipRemoval];
}
%new
- (void)removeFingerTipWithHash:(NSUInteger)hash
{
GTFingerTipView *touchView = (GTFingerTipView *)[[self overlayWindow] viewWithTag:hash];
BOOL animationsWereEnabled = [UIView areAnimationsEnabled];
if ( ! [touchView isKindOfClass:[GTFingerTipView class]])
return;
if ([touchView isFadingOut])
return;
[UIView setAnimationsEnabled:YES];
[UIView animateWithDuration:FADE_DURATION
delay:0.1
options:0
animations:^{
touchView.frame = CGRectMake(
touchView.center.x - touchView.frame.size.width * 1.2 / 2,
touchView.center.y - touchView.frame.size.height * 1.2 / 2,
touchView.frame.size.width * 1.2,
touchView.frame.size.height * 1.2);
touchView.alpha = 0.0;
}
completion:^(BOOL finished){
[UIView setAnimationsEnabled:animationsWereEnabled];
touchView.fadingOut = YES;
[touchView removeFromSuperview];
}];
}
%new
- (BOOL)shouldAutomaticallyRemoveFingerTipForTouch:(UITouch *)touch
{
UIView *view = [touch view];
view = [view hitTest:[touch locationInView:view] withEvent:nil];
if ([[touch gestureRecognizers] count] == 0)
return YES;
while (view != nil)
{
if ([view isKindOfClass:[UITableViewCell class]])
{
for (UIGestureRecognizer *recognizer in [touch gestureRecognizers])
{
if ([recognizer isKindOfClass:[UISwipeGestureRecognizer class]])
return YES;
}
}
view = view.superview;
}
return NO;
}
%end
%end
%ctor {
NSDictionary *prefs = [NSDictionary dictionaryWithContentsOfFile:PREFS_LOCATION];
NSString *bundleID = [NSBundle mainBundle].bundleIdentifier;
NSLog(@"running in %@", bundleID);
if (!prefs || (
[prefs[@"enabled"] boolValue] &&
![bundleID isEqualToString:@"com.apple.camera"])) {
%init(MainGroup);
}
}