Skip to content

Commit

Permalink
Make right mouse button configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnachman committed Nov 13, 2011
1 parent 5cac76b commit 694ce36
Show file tree
Hide file tree
Showing 7 changed files with 465 additions and 3,134 deletions.
5 changes: 5 additions & 0 deletions DefaultPointerActions.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Button,1,1,,</key>
<dict>
<key>Action</key>
<string>kContextMenuPointerAction</string>
</dict>
<key>Button,2,1,,</key>
<dict>
<key>Action</key>
Expand Down
3,487 changes: 389 additions & 3,098 deletions English.lproj/PreferencePanel.xib

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion EventMonitorView.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ - (void)mouseUp:(NSEvent *)theEvent

- (void)rightMouseUp:(NSEvent *)theEvent
{
[self showNotSupported];
int buttonNumber = 1;
int clickCount = [theEvent clickCount];
int modMask = [theEvent modifierFlags];
[pointerPrefs_ setButtonNumber:buttonNumber clickCount:clickCount modifiers:modMask];
[super mouseDown:theEvent];
}

- (void)otherMouseDown:(NSEvent *)theEvent
Expand Down
36 changes: 16 additions & 20 deletions PTYTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -2361,6 +2361,9 @@ - (void)otherMouseDragged:(NSEvent *)event

- (void)rightMouseDown:(NSEvent*)event
{
if ([pointer_ mouseDown:event withTouches:numTouches_]) {
return;
}
NSPoint locationInWindow, locationInTextView;
locationInWindow = [event locationInWindow];
locationInTextView = [self convertPoint: locationInWindow fromView: nil];
Expand Down Expand Up @@ -2399,6 +2402,9 @@ - (void)rightMouseDown:(NSEvent*)event

- (void)rightMouseUp:(NSEvent *)event
{
if ([pointer_ mouseUp:event withTouches:numTouches_]) {
return;
}
NSPoint locationInWindow, locationInTextView;
locationInWindow = [event locationInWindow];
locationInTextView = [self convertPoint: locationInWindow fromView: nil];
Expand Down Expand Up @@ -2687,6 +2693,10 @@ - (BOOL)mouseDownImpl:(NSEvent*)event
}
return NO;
}
if ([pointer_ eventEmulatesRightClick:event]) {
[pointer_ mouseDown:event withTouches:numTouches_];
return NO;
}
const BOOL altPressed = ([event modifierFlags] & NSAlternateKeyMask) != 0;
const BOOL cmdPressed = ([event modifierFlags] & NSCommandKeyMask) != 0;
const BOOL shiftPressed = ([event modifierFlags] & NSShiftKeyMask) != 0;
Expand Down Expand Up @@ -2920,6 +2930,10 @@ - (void)mouseUp:(NSEvent *)event
}
dragOk_ = NO;
trouterDragged = NO;
if ([pointer_ eventEmulatesRightClick:event]) {
[pointer_ mouseUp:event withTouches:numTouches_];
return;
}
PTYTextView* frontTextView = [[iTermController sharedInstance] frontTextView];
const BOOL cmdPressed = ([event modifierFlags] & NSCommandKeyMask) != 0;
if (!cmdPressed &&
Expand Down Expand Up @@ -3656,26 +3670,8 @@ - (BOOL)_haveShortSelection
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
if (theEvent) {
// Not for "synthetic" events, as the session title view sends.
PTYTextView* frontTextView = [[iTermController sharedInstance] frontTextView];
NSRect visibleRect = [[self enclosingScrollView] documentVisibleRect];
NSPoint locationInWindow = [theEvent locationInWindow];
NSPoint locationInTextView = [self convertPoint:locationInWindow fromView:nil];
VT100Terminal *terminal = [dataSource terminal];
MouseMode mm = [terminal mouseMode];
if (frontTextView == self &&
([self xtermMouseReporting]) &&
(mm == MOUSE_REPORTING_NORMAL ||
mm == MOUSE_REPORTING_BUTTON_MOTION ||
mm == MOUSE_REPORTING_ALL_MOTION) &&
(locationInTextView.y > visibleRect.origin.y) &&
[[frontTextView->dataSource session] tab] == [[dataSource session] tab] &&
[theEvent type] == NSLeftMouseDown &&
([theEvent modifierFlags] & NSControlKeyMask) &&
[[PreferencePanel sharedInstance] passOnControlLeftClick]) {
// All the many conditions are met for having the click passed on via xterm mouse reporting.
return nil;
}
// Context menu is opened by the PointerController, not organically.
return nil;
}
NSMenu *theMenu;

Expand Down
5 changes: 3 additions & 2 deletions PointerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@

@property (nonatomic, assign) NSObject<PointerControllerDelegate> *delegate;

- (void)mouseDown:(NSEvent *)event withTouches:(int)numTouches;
- (void)mouseUp:(NSEvent *)event withTouches:(int)numTouches;
- (BOOL)mouseDown:(NSEvent *)event withTouches:(int)numTouches;
- (BOOL)mouseUp:(NSEvent *)event withTouches:(int)numTouches;
- (void)swipeWithEvent:(NSEvent *)event;
- (BOOL)eventEmulatesRightClick:(NSEvent *)event;

@end
58 changes: 46 additions & 12 deletions PointerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "PointerController.h"
#import "PointerPrefsController.h"
#import "PreferencePanel.h"

@implementation PointerController

Expand Down Expand Up @@ -66,30 +67,63 @@ - (void)performAction:(NSString *)action
}
}

- (void)mouseDown:(NSEvent *)event withTouches:(int)numTouches
- (BOOL)eventEmulatesRightClick:(NSEvent *)event
{
mouseDownButton_ = [event buttonNumber];
return ![[PreferencePanel sharedInstance] passOnControlLeftClick] &&
[event buttonNumber] == 0 &&
[event clickCount] == 1 &&
([event modifierFlags] & (NSControlKeyMask | NSCommandKeyMask | NSAlternateKeyMask | NSShiftKeyMask)) == NSControlKeyMask;
}

- (void)mouseUp:(NSEvent *)event withTouches:(int)numTouches
- (NSString *)actionForEvent:(NSEvent *)event withTouches:(int)numTouches
{
NSString *action = nil;
NSString *argument = nil;
if ([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]
modifiers:[event modifierFlags]];
} else {
return [PointerPrefsController actionForTapWithTouches:numTouches
modifiers:[event modifierFlags]];
}
}

- (NSString *)argumentForEvent:(NSEvent *)event withTouches:(int)numTouches
{
if ([self eventEmulatesRightClick:event]) {
// Ctrl-click emulates right button
return [PointerPrefsController argumentWithButton:1
numClicks:1
modifiers:0];
}
if (numTouches <= 2) {
action = [PointerPrefsController actionWithButton:[event buttonNumber]
return [PointerPrefsController argumentWithButton:[event buttonNumber]
numClicks:[event clickCount]
modifiers:[event modifierFlags]];
argument = [PointerPrefsController argumentWithButton:[event buttonNumber]
numClicks:[event clickCount]
modifiers:[event modifierFlags]];
} else {
action = [PointerPrefsController actionForTapWithTouches:numTouches
return [PointerPrefsController argumentForTapWithTouches:numTouches
modifiers:[event modifierFlags]];
argument = [PointerPrefsController argumentForTapWithTouches:numTouches
modifiers:[event modifierFlags]];
}
}

- (BOOL)mouseDown:(NSEvent *)event withTouches:(int)numTouches
{
mouseDownButton_ = [event buttonNumber];
return [self actionForEvent:event withTouches:numTouches] != nil;
}

- (BOOL)mouseUp:(NSEvent *)event withTouches:(int)numTouches
{
NSString *argument = [self argumentForEvent:event withTouches:numTouches];
NSString *action = [self actionForEvent:event withTouches:numTouches];
if (action) {
[self performAction:action forEvent:event withArgument:argument];
return YES;
} else {
return NO;
}
}

Expand Down
2 changes: 1 addition & 1 deletion PointerPrefsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ - (void)setModifierButtons:(int)modMask

- (void)setButtonNumber:(int)buttonNumber clickCount:(int)clickCount modifiers:(int)modMask
{
if (buttonNumber >= 2 && clickCount > 0 && clickCount < 5) {
if (buttonNumber >= 1 && clickCount > 0 && clickCount < 5) {
[editButton_ selectItemWithTag:buttonNumber];
[editClickType_ selectItemWithTag:clickCount];
[self setModifierButtons:modMask];
Expand Down

0 comments on commit 694ce36

Please sign in to comment.