Created
July 16, 2012 12:44
-
-
Save saitoha/3122484 to your computer and use it in GitHub Desktop.
Support urxvt/SGR mouse reporting and "any event tracking mode". for MouseTerm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/MTView.h b/MTView.h | |
| index 490a8d6..2373679 100644 | |
| --- a/MTView.h | |
| +++ b/MTView.h | |
| @@ -13,6 +13,7 @@ | |
| - (BOOL) MouseTerm_shouldIgnore: (NSEvent*) event button: (MouseButton) button; | |
| - (BOOL) MouseTerm_shouldIgnoreDown: (NSEvent*) event | |
| button: (MouseButton) button; | |
| +- (BOOL) MouseTerm_shouldIgnoreMoved: (NSEvent*) event; | |
| - (Position) MouseTerm_currentPosition: (NSEvent*) event; | |
| - (BOOL) MouseTerm_buttonDown: (NSEvent*) event button: (MouseButton) button; | |
| - (BOOL) MouseTerm_buttonDragged: (NSEvent*) event | |
| @@ -20,6 +21,7 @@ | |
| - (BOOL) MouseTerm_buttonUp: (NSEvent*) event | |
| button: (MouseButton) button; | |
| - (void) MouseTerm_mouseDown: (NSEvent*) event; | |
| +- (void) MouseTerm_mouseMoved: (NSEvent*) event; | |
| - (void) MouseTerm_mouseDragged: (NSEvent*) event; | |
| - (void) MouseTerm_mouseUp: (NSEvent*) event; | |
| - (void) MouseTerm_rightMouseDown: (NSEvent*) event; | |
| diff --git a/MTView.m b/MTView.m | |
| index 65fab5d..a57c7a2 100644 | |
| --- a/MTView.m | |
| +++ b/MTView.m | |
| @@ -126,6 +126,16 @@ static BOOL enabled = YES; | |
| return NO; | |
| } | |
| +- (BOOL) MouseTerm_shouldIgnoreMoved: (NSEvent*) event | |
| +{ | |
| + // check if the mouse location is in the bounds of window. | |
| + NSPoint location = [event locationInWindow]; | |
| + NSRect bounds = [(NSView*) self bounds]; | |
| + if (NSPointInRect(location, bounds)) | |
| + return NO; | |
| + return YES; | |
| +} | |
| + | |
| - (Position) MouseTerm_currentPosition: (NSEvent*) event | |
| { | |
| linecount_t scrollback = | |
| @@ -141,11 +151,12 @@ static BOOL enabled = YES; | |
| // pos.x may not indicate correct coordinate value if the tail | |
| // cells of line buffer are empty, so we calculate it from the cell size. | |
| CGSize size = [(TTView*) self cellSize]; | |
| - pos.x = (int)round(viewloc.x / size.width); | |
| + pos.x = (linecount_t)round(viewloc.x / size.width); | |
| // treat negative position value as 1. | |
| - pos.x = MAX(1, pos.x); | |
| - pos.y = MAX(1, pos.y); | |
| + pos.x = MAX(1, (int)pos.x); | |
| + pos.y = MAX(1, (int)pos.y); | |
| + | |
| return pos; | |
| } | |
| @@ -182,6 +193,38 @@ ignored: | |
| return NO; | |
| } | |
| +- (BOOL) MouseTerm_buttonMoved: (NSEvent*) event | |
| +{ | |
| + if ([self MouseTerm_shouldIgnoreMoved: event]) | |
| + goto ignored; | |
| + | |
| + MTShell* shell = [[(TTView*) self controller] shell]; | |
| + switch ([shell MouseTerm_getMouseMode]) | |
| + { | |
| + case NO_MODE: | |
| + goto ignored; | |
| + case NORMAL_MODE: | |
| + case HILITE_MODE: | |
| + case BUTTON_MODE: | |
| + goto handled; | |
| + case ALL_MODE: | |
| + { | |
| + NSData* data = [self MouseTerm_codeForEvent: event | |
| + button: MOUSE_RELEASE + 32 | |
| + motion: NO | |
| + release: NO]; | |
| + [(TTShell*) shell writeData: data]; | |
| + goto handled; | |
| + } | |
| + } | |
| +handled: | |
| + [(TTView*) self clearTextSelection]; | |
| + return YES; | |
| +ignored: | |
| + return NO; | |
| +} | |
| + | |
| + | |
| - (BOOL) MouseTerm_buttonDragged: (NSEvent*) event button: (MouseButton) button | |
| { | |
| if ([self MouseTerm_shouldIgnoreDown: event button: button]) | |
| @@ -257,6 +300,11 @@ ignored: | |
| [self MouseTerm_mouseDown: event]; | |
| } | |
| +- (void) MouseTerm_mouseMoved: (NSEvent*) event | |
| +{ | |
| + [self MouseTerm_buttonMoved: event]; | |
| +} | |
| + | |
| - (void) MouseTerm_mouseDragged: (NSEvent*) event | |
| { | |
| MouseButton button; | |
| diff --git a/MouseTerm.m b/MouseTerm.m | |
| index a02dab6..e2f2e3e 100644 | |
| --- a/MouseTerm.m | |
| +++ b/MouseTerm.m | |
| @@ -100,6 +100,7 @@ NSMutableDictionary* MouseTerm_ivars = nil; | |
| SWIZZLE(shell, @selector(writeData:), @selector(MouseTerm_writeData:)); | |
| SWIZZLE(view, @selector(scrollWheel:), @selector(MouseTerm_scrollWheel:)); | |
| SWIZZLE(view, @selector(mouseDown:), @selector(MouseTerm_mouseDown:)); | |
| + SWIZZLE(view, @selector(mouseMoved:), @selector(MouseTerm_mouseMoved:)); | |
| SWIZZLE(view, @selector(mouseDragged:), | |
| @selector(MouseTerm_mouseDragged:)); | |
| SWIZZLE(view, @selector(mouseUp:), @selector(MouseTerm_mouseUp:)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment