From cbd8ff0cb4d9414f5bb937ba284554730fbce50a Mon Sep 17 00:00:00 2001 From: Kazuki Sakamoto Date: Wed, 9 Dec 2015 14:43:54 -0800 Subject: [PATCH] Add MMUseMouseTime, Revise #77 `MMUseMouseTime` allows to override the time threshold for detecting multiple mouse down events using Vim `mousetime` option. $ defaults write org.vim.MacVim MMUseMouseTime -bool TRUE --- src/MacVim/MMBackend.m | 5 +++-- src/MacVim/MMTextViewHelper.h | 2 ++ src/MacVim/MMTextViewHelper.m | 24 ++++++++++++++++++++++-- src/MacVim/Miscellaneous.h | 1 + src/MacVim/Miscellaneous.m | 1 + 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 217119fb7a..c1c609a308 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -1844,6 +1844,7 @@ static void netbeansReadCallback(CFSocketRef s, [NSNumber numberWithBool:mmta], @"p_mmta", [NSNumber numberWithInt:numTabs], @"numTabs", [NSNumber numberWithInt:fuoptions_flags], @"fullScreenOptions", + [NSNumber numberWithLong:p_mouset], @"p_mouset", nil]; // Put the state before all other messages. @@ -1932,12 +1933,12 @@ static void netbeansReadCallback(CFSocketRef s, int col = *((int*)bytes); bytes += sizeof(int); int button = *((int*)bytes); bytes += sizeof(int); int flags = *((int*)bytes); bytes += sizeof(int); - int count = *((int*)bytes); bytes += sizeof(int); + int repeat = *((int*)bytes); bytes += sizeof(int); button = eventButtonNumberToVimMouseButton(button); if (button >= 0) { flags = eventModifierFlagsToVimMouseModMask(flags); - gui_send_mouse_event(button, col, row, count>1, flags); + gui_send_mouse_event(button, col, row, repeat, flags); } } else if (MouseUpMsgID == msgid) { if (!data) return; diff --git a/src/MacVim/MMTextViewHelper.h b/src/MacVim/MMTextViewHelper.h index 3017d7ca38..837f1c7e19 100644 --- a/src/MacVim/MMTextViewHelper.h +++ b/src/MacVim/MMTextViewHelper.h @@ -35,6 +35,8 @@ BOOL interpretKeyEventsSwallowedKey; NSEvent *currentEvent; NSMutableDictionary *signImages; + BOOL useMouseTime; + NSDate *mouseDownTime; // Input Manager NSRange imRange; diff --git a/src/MacVim/MMTextViewHelper.m b/src/MacVim/MMTextViewHelper.m index 01375b4386..07a5eb7af6 100644 --- a/src/MacVim/MMTextViewHelper.m +++ b/src/MacVim/MMTextViewHelper.m @@ -80,6 +80,11 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) signImages = [[NSMutableDictionary alloc] init]; + useMouseTime = + [[NSUserDefaults standardUserDefaults] boolForKey:MMUseMouseTimeKey]; + if (useMouseTime) + mouseDownTime = [[NSDate date] retain]; + return self; } @@ -91,6 +96,7 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) [markedText release]; markedText = nil; [markedTextAttributes release]; markedTextAttributes = nil; [signImages release]; signImages = nil; + [mouseDownTime release]; mouseDownTime = nil; #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if (asciiImSource) { @@ -380,7 +386,21 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) int button = [event buttonNumber]; int flags = [event modifierFlags]; - int count = [event clickCount]; + int repeat = 0; + + if (useMouseTime) { + // Use Vim mouseTime option to handle multiple mouse down events + NSDate *now = [[NSDate date] retain]; + id mouset = [[[self vimController] vimState] objectForKey:@"p_mouset"]; + NSTimeInterval interval = + [now timeIntervalSinceDate:mouseDownTime] * 1000.0; + if (interval < (NSTimeInterval)[mouset longValue]) + repeat = 1; + mouseDownTime = now; + } else { + repeat = [event clickCount] > 1; + } + NSMutableData *data = [NSMutableData data]; // If desired, intepret Ctrl-Click as a right mouse click. @@ -398,7 +418,7 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) [data appendBytes:&col length:sizeof(int)]; [data appendBytes:&button length:sizeof(int)]; [data appendBytes:&flags length:sizeof(int)]; - [data appendBytes:&count length:sizeof(int)]; + [data appendBytes:&repeat length:sizeof(int)]; [[self vimController] sendMessage:MouseDownMsgID data:data]; } diff --git a/src/MacVim/Miscellaneous.h b/src/MacVim/Miscellaneous.h index a8dbe98c50..f95fc7f1ee 100644 --- a/src/MacVim/Miscellaneous.h +++ b/src/MacVim/Miscellaneous.h @@ -55,6 +55,7 @@ extern NSString *MMUseInlineImKey; #endif // INCLUDE_OLD_IM_CODE extern NSString *MMSuppressTerminationAlertKey; extern NSString *MMNativeFullScreenKey; +extern NSString *MMUseMouseTimeKey; // Enum for MMUntitledWindowKey diff --git a/src/MacVim/Miscellaneous.m b/src/MacVim/Miscellaneous.m index 48bf169c51..6731c0a49c 100644 --- a/src/MacVim/Miscellaneous.m +++ b/src/MacVim/Miscellaneous.m @@ -47,6 +47,7 @@ NSString *MMUseInlineImKey = @"MMUseInlineIm"; #endif // INCLUDE_OLD_IM_CODE NSString *MMSuppressTerminationAlertKey = @"MMSuppressTerminationAlert"; NSString *MMNativeFullScreenKey = @"MMNativeFullScreen"; +NSString *MMUseMouseTimeKey = @"MMUseMouseTime";