Permalink
Browse files

Fix bug where right click didn't take if you do it too fast after a d…

…ouble click.
  • Loading branch information...
1 parent 2a8210b commit 334bda1f73a4fe14849d4e1e5aaea28ff7a968eb @gnachman gnachman committed Jan 16, 2012
Showing with 38 additions and 10 deletions.
  1. +1 −0 PTYTextView.m
  2. +2 −0 PointerController.h
  3. +35 −10 PointerController.m
View
@@ -2752,6 +2752,7 @@ - (void)extendSelectionToX:(int)x y:(int)y
// Returns yes if [super mouseDown:event] should be run by caller.
- (BOOL)mouseDownImpl:(NSEvent*)event
{
+ [pointer_ notifyLeftMouseDown];
mouseDownIsThreeFingerClick_ = NO;
if (([event modifierFlags] & kDragPaneModifiers) == kDragPaneModifiers) {
[[MovePaneController sharedInstance] beginDrag:[dataSource session]];
View
@@ -41,6 +41,7 @@
@interface PointerController : NSObject {
NSObject<PointerControllerDelegate> *delegate_;
int mouseDownButton_;
+ int clicks_;
}
@property (nonatomic, assign) NSObject<PointerControllerDelegate> *delegate;
@@ -50,5 +51,6 @@
- (void)swipeWithEvent:(NSEvent *)event;
- (BOOL)eventEmulatesRightClick:(NSEvent *)event;
- (BOOL)viewShouldTrackTouches;
+- (void)notifyLeftMouseDown;
@end
View
@@ -75,58 +75,83 @@ - (BOOL)viewShouldTrackTouches
[PointerPrefsController haveThreeFingerTapEvents];
}
+// Caller is responsible to check that it's a single click
- (BOOL)eventEmulatesRightClick:(NSEvent *)event
{
return ![[PreferencePanel sharedInstance] passOnControlLeftClick] &&
[event buttonNumber] == 0 &&
- [event clickCount] == 1 &&
([event modifierFlags] & (NSControlKeyMask | NSCommandKeyMask | NSAlternateKeyMask | NSShiftKeyMask)) == NSControlKeyMask;
}
-- (NSString *)actionForEvent:(NSEvent *)event withTouches:(int)numTouches
+- (NSString *)actionForEvent:(NSEvent *)event
+ clicks:(int)clicks
+ withTouches:(int)numTouches
{
- if ([self eventEmulatesRightClick:event]) {
+ if (clicks == 1 && [self eventEmulatesRightClick:event]) {
// Ctrl-click emulates right button
return [PointerPrefsController actionWithButton:1 numClicks:1 modifiers:0];
}
if (numTouches <= 2) {
return [PointerPrefsController actionWithButton:[event buttonNumber]
- numClicks:[event clickCount]
+ numClicks:clicks
modifiers:[event modifierFlags]];
} else {
return [PointerPrefsController actionForTapWithTouches:numTouches
modifiers:[event modifierFlags]];
}
}
-- (NSString *)argumentForEvent:(NSEvent *)event withTouches:(int)numTouches
+- (NSString *)argumentForEvent:(NSEvent *)event
+ clicks:(int)clicks
+ withTouches:(int)numTouches
{
- if ([self eventEmulatesRightClick:event]) {
+ if (clicks == 1 && [self eventEmulatesRightClick:event]) {
// Ctrl-click emulates right button
return [PointerPrefsController argumentWithButton:1
numClicks:1
modifiers:0];
}
if (numTouches <= 2) {
return [PointerPrefsController argumentWithButton:[event buttonNumber]
- numClicks:[event clickCount]
+ numClicks:clicks
modifiers:[event modifierFlags]];
} else {
return [PointerPrefsController argumentForTapWithTouches:numTouches
modifiers:[event modifierFlags]];
}
}
+- (void)notifyLeftMouseDown
+{
+ mouseDownButton_ = 0;
+}
+
+
- (BOOL)mouseDown:(NSEvent *)event withTouches:(int)numTouches
{
+ // A double left click plus an immediate right click reports a triple right
+ // click! So we keep our own click count and use the lower of the OS's
+ // value and ours. Theirs is lower when the time between clicks is long.
+ if ([event buttonNumber] != mouseDownButton_) {
+ clicks_ = 1;
+ } else {
+ clicks_++;
+ }
+ clicks_ = MIN(clicks_, [event clickCount]);
mouseDownButton_ = [event buttonNumber];
- return [self actionForEvent:event withTouches:numTouches] != nil;
+ return [self actionForEvent:event
+ clicks:clicks_
+ withTouches:numTouches] != nil;
}
- (BOOL)mouseUp:(NSEvent *)event withTouches:(int)numTouches
{
- NSString *argument = [self argumentForEvent:event withTouches:numTouches];
- NSString *action = [self actionForEvent:event withTouches:numTouches];
+ NSString *argument = [self argumentForEvent:event
+ clicks:clicks_
+ withTouches:numTouches];
+ NSString *action = [self actionForEvent:event
+ clicks:clicks_
+ withTouches:numTouches];
if (action) {
[self performAction:action forEvent:event withArgument:argument];
return YES;

0 comments on commit 334bda1

Please sign in to comment.