forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventMonitorView.m
154 lines (131 loc) · 4.83 KB
/
EventMonitorView.m
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
//
// EventMonitorView.m
// iTerm
//
// Created by George Nachman on 11/9/11.
// Copyright (c) 2011 George Nachman. All rights reserved.
//
#import "EventMonitorView.h"
#import "FutureMethods.h"
#import "iTermApplicationDelegate.h"
#import "NSEvent+iTerm.h"
#import "PointerPrefsController.h"
#import "ThreeFingerTapGestureRecognizer.h"
@implementation EventMonitorView {
IBOutlet PointerPrefsController *pointerPrefs_;
IBOutlet NSTextField *label_;
int numTouches_;
ThreeFingerTapGestureRecognizer *_threeFingerTapGestureRecognizer;
NSInteger _maximumStage;
}
- (void)awakeFromNib {
self.allowedTouchTypes = NSTouchTypeMaskIndirect;
[self setWantsRestingTouches:YES];
_threeFingerTapGestureRecognizer =
[[ThreeFingerTapGestureRecognizer alloc] initWithTarget:self
selector:@selector(threeFingerTap:)];
}
- (void)dealloc {
[_threeFingerTapGestureRecognizer disconnectTarget];
}
- (void)touchesBeganWithEvent:(NSEvent *)ev {
numTouches_ = [[ev touchesMatchingPhase:(NSTouchPhaseBegan | NSTouchPhaseStationary)
inView:self] count];
[_threeFingerTapGestureRecognizer touchesBeganWithEvent:ev];
DLog(@"EventMonitorView touchesBeganWithEvent:%@; numTouches=%d", ev, numTouches_);
}
- (void)touchesEndedWithEvent:(NSEvent *)ev {
numTouches_ = [[ev touchesMatchingPhase:NSTouchPhaseStationary
inView:self] count];
[_threeFingerTapGestureRecognizer touchesEndedWithEvent:ev];
DLog(@"EventMonitorView touchesEndedWithEvent:%@; numTouches=%d", ev, numTouches_);
}
- (void)touchesCancelledWithEvent:(NSEvent *)ev {
numTouches_ = 0;
[_threeFingerTapGestureRecognizer touchesCancelledWithEvent:ev];
DLog(@"EventMonitorView touchesCancelledWithEvent:%@; numTouches=%d", ev, numTouches_);
}
- (void)showNotSupported
{
[label_ setStringValue:@"You can't customize that button"];
[label_ performSelector:@selector(setStringValue:) withObject:@"Click or Tap Here to Set Input Fields" afterDelay:1];
}
- (void)mouseUp:(NSEvent *)theEvent {
if ([_threeFingerTapGestureRecognizer mouseUp:theEvent]) {
DLog(@"Three finger trap gesture recognizer cancels mouseUp");
return;
}
DLog(@"EventMonitorView mouseUp:%@", theEvent);
if (numTouches_ == 3) {
[pointerPrefs_ setGesture:kThreeFingerClickGesture
modifiers:[theEvent it_modifierFlags]];
} else if (_maximumStage < 2) {
[self showNotSupported];
}
_maximumStage = 0;
}
- (void)mouseDown:(NSEvent *)event {
if ([_threeFingerTapGestureRecognizer mouseDown:event]) {
DLog(@"Three finger trap gesture recognizer cancels mouseDown");
return;
} else {
[super mouseDown:event];
}
}
- (void)pressureChangeWithEvent:(NSEvent *)event {
ITERM_IGNORE_PARTIAL_BEGIN
if ([event respondsToSelector:@selector(stage)]) {
_maximumStage = MAX(_maximumStage, event.stage);
if (event.stage == 2) {
[pointerPrefs_ setGesture:kForceTouchSingleClick modifiers:[event it_modifierFlags]];
}
}
ITERM_IGNORE_PARTIAL_END
}
- (void)rightMouseDown:(NSEvent*)event {
if ([_threeFingerTapGestureRecognizer rightMouseDown:event]) {
DLog(@"Three finger trap gesture recognizer cancels rightMouseDown");
return;
} else {
[super rightMouseDown:event];
}
}
- (void)rightMouseUp:(NSEvent *)theEvent {
if ([_threeFingerTapGestureRecognizer rightMouseUp:theEvent]) {
DLog(@"Three finger trap gesture recognizer cancels rightMouseUp");
return;
}
DLog(@"EventMonitorView rightMouseUp:%@", theEvent);
int buttonNumber = 1;
int clickCount = [theEvent clickCount];
int modMask = [theEvent it_modifierFlags];
[pointerPrefs_ setButtonNumber:buttonNumber clickCount:clickCount modifiers:modMask];
[super mouseDown:theEvent];
}
- (void)otherMouseDown:(NSEvent *)theEvent
{
DLog(@"EventMonitorView otherMouseDown:%@", theEvent);
int buttonNumber = [theEvent buttonNumber];
int clickCount = [theEvent clickCount];
int modMask = [theEvent it_modifierFlags];
[pointerPrefs_ setButtonNumber:buttonNumber clickCount:clickCount modifiers:modMask];
[super mouseDown:theEvent];
}
- (void)drawRect:(NSRect)dirtyRect
{
if (@available(macOS 10.14, *)) {
[[NSColor controlBackgroundColor] set];
NSRectFill(dirtyRect);
[[NSColor separatorColor] set];
} else {
[[NSColor whiteColor] set];
NSRectFill(dirtyRect);
[[NSColor blackColor] set];
}
NSFrameRect(NSMakeRect(0, 0, self.frame.size.width, self.frame.size.height));
[super drawRect:dirtyRect];
}
- (void)threeFingerTap:(NSEvent *)event {
[pointerPrefs_ setGesture:kThreeFingerClickGesture modifiers:[event it_modifierFlags]];
}
@end