-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTweak.xm
119 lines (106 loc) · 4.84 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
#import <objc/runtime.h>
#import "DGTController.h"
#import "Interfaces.h"
static void loadPreferences() {
CFPreferencesAppSynchronize(CFSTR("com.phillipt.dragthingy"));
//enabled = [(id)CFPreferencesCopyAppValue(CFSTR("enabled"), CFSTR("com.phillipt.dragthingy")) boolValue];
}
/*
%hook SBIconController
- (void)_handleShortcutMenuPeek:(id)arg1 {
%log;
%orig;
}
%end
*/
%hook SBHomeScreenWindow
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* touch = [touches anyObject];
CGFloat pressure = MSHookIvar<CGFloat>(touch, "_previousPressure");
CGPoint convertedPoint = [self convertPoint:[touch locationInView:self] toView:((SBIconController*)[%c(SBIconController) sharedInstance]).contentView];
if ([[DGTController sharedInstance] selectionViewIsInvoked]) {
[[DGTController sharedInstance] selectionViewTouchMovedWithLocation:convertedPoint];
return;
}
//TODO adjust to user's 3DTouch setting
if (pressure > 300) {
NSLog(@"user force touched with pressure: %f", pressure);
[[DGTController sharedInstance] selectionViewTouchBeganWithLocation:convertedPoint];
return;
}
%orig;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ([[DGTController sharedInstance] selectionViewIsInvoked]) {
UITouch* touch = [touches anyObject];
CGPoint convertedPoint = [self convertPoint:[touch locationInView:self] toView:((SBIconController*)[%c(SBIconController) sharedInstance]).contentView];
[[DGTController sharedInstance] selectionViewTouchEndedWithLocation:convertedPoint withRecognizer:nil];
}
}
/*
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
if ([[DGTController sharedInstance] selectionViewIsInvoked]) {
UITouch* touch = [touches anyObject];
[[DGTController sharedInstance] selectionViewTouchEndedWithLocation:[touch locationInView:self] withRecognizer:nil];
}
}
*/
%end
%hook SBIconScrollView
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* touch = [touches anyObject];
CGFloat pressure = MSHookIvar<CGFloat>(touch, "_previousPressure");
CGPoint convertedPoint = [self convertPoint:[touch locationInView:self] toView:((SBIconController*)[%c(SBIconController) sharedInstance]).contentView];
if ([[DGTController sharedInstance] selectionViewIsInvoked]) {
[[DGTController sharedInstance] selectionViewTouchMovedWithLocation:convertedPoint];
//steal touch from scroll view
self.panGestureRecognizer.enabled = NO;
self.panGestureRecognizer.enabled = YES;
//steal touch from spotlight pan gesture recognizer
//find spotlight pan gesture recognizer
for (UIGestureRecognizer* rec in self.gestureRecognizers) {
NSArray* targets = MSHookIvar<NSArray*>(rec, "_targets");
if (targets.count > 0) {
id target = MSHookIvar<id>(targets[0], "_target");
if ([target isKindOfClass:%c(SBSearchScrollView)]) {
((UIScrollView*)target).panGestureRecognizer.enabled = NO;
((UIScrollView*)target).panGestureRecognizer.enabled = YES;
}
}
}
return;
}
//TODO adjust to user's 3DTouch setting
if (pressure > 500) {
NSLog(@"user force touched with pressure: %f", pressure);
[[DGTController sharedInstance] selectionViewTouchBeganWithLocation:convertedPoint];
return;
}
%orig;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ([[DGTController sharedInstance] selectionViewIsInvoked]) {
UITouch* touch = [touches anyObject];
CGPoint convertedPoint = [self convertPoint:[touch locationInView:self] toView:((SBIconController*)[%c(SBIconController) sharedInstance]).contentView];
[[DGTController sharedInstance] selectionViewTouchEndedWithLocation:convertedPoint withRecognizer:nil];
}
}
/*
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
if ([[DGTController sharedInstance] selectionViewIsInvoked]) {
UITouch* touch = [touches anyObject];
[[DGTController sharedInstance] selectionViewTouchEndedWithLocation:[touch locationInView:self] withRecognizer:nil];
}
}
*/
%end
%ctor {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
(CFNotificationCallback)loadPreferences,
CFSTR("com.phillipt.dragthingy/prefsChanged"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
loadPreferences();
//[[NSNotificationCenter defaultCenter] addObserver:[DGTController sharedInstance] selector:@selector(_keyWindowChanged) name:UIWindowDidBecomeKeyNotification object:nil];
}