Skip to content

Commit

Permalink
Fix bug where right click didn't take if you do it too fast after a d…
Browse files Browse the repository at this point in the history
…ouble click.
  • Loading branch information
gnachman committed Jan 16, 2012
1 parent 2a8210b commit 334bda1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions PTYTextView.m
Expand Up @@ -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]];
Expand Down
2 changes: 2 additions & 0 deletions PointerController.h
Expand Up @@ -41,6 +41,7 @@
@interface PointerController : NSObject {
NSObject<PointerControllerDelegate> *delegate_;
int mouseDownButton_;
int clicks_;
}

@property (nonatomic, assign) NSObject<PointerControllerDelegate> *delegate;
Expand All @@ -50,5 +51,6 @@
- (void)swipeWithEvent:(NSEvent *)event;
- (BOOL)eventEmulatesRightClick:(NSEvent *)event;
- (BOOL)viewShouldTrackTouches;
- (void)notifyLeftMouseDown;

@end
45 changes: 35 additions & 10 deletions PointerController.m
Expand Up @@ -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;
Expand Down

0 comments on commit 334bda1

Please sign in to comment.