diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 81f0fedf8d..2fa26c1212 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -1834,6 +1834,7 @@ - (void)insertVimStateMessage NSDictionary *vimState = [NSDictionary dictionaryWithObjectsAndKeys: [[NSFileManager defaultManager] currentDirectoryPath], @"pwd", [NSNumber numberWithInt:p_mh], @"p_mh", + [NSNumber numberWithLong:p_mouset], @"p_mouset", [NSNumber numberWithBool:mmta], @"p_mmta", [NSNumber numberWithInt:numTabs], @"numTabs", [NSNumber numberWithInt:fuoptions_flags], @"fullScreenOptions", @@ -1925,12 +1926,12 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data 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..dd6f31f65a 100644 --- a/src/MacVim/MMTextViewHelper.h +++ b/src/MacVim/MMTextViewHelper.h @@ -15,6 +15,9 @@ #import #endif +#include +#include + #define BLUE(argb) ((argb & 0xff)/255.0f) #define GREEN(argb) (((argb>>8) & 0xff)/255.0f) @@ -61,6 +64,7 @@ - (void)doCommandBySelector:(SEL)selector; - (BOOL)performKeyEquivalent:(NSEvent *)event; - (void)scrollWheel:(NSEvent *)event; +- (uint64_t)getTick; - (void)mouseDown:(NSEvent *)event; - (void)mouseUp:(NSEvent *)event; - (void)mouseDragged:(NSEvent *)event; diff --git a/src/MacVim/MMTextViewHelper.m b/src/MacVim/MMTextViewHelper.m index 4de1dd1df7..92a3b8bd7b 100644 --- a/src/MacVim/MMTextViewHelper.m +++ b/src/MacVim/MMTextViewHelper.m @@ -364,6 +364,34 @@ - (void)scrollWheel:(NSEvent *)event } } +- (uint64_t)getTick +{ + // NOTE: See http://developer.apple.com/library/mac/qa/qa1398/_index.html + + static mach_timebase_info_data_t sTimebaseInfo; + + uint64_t absolute = mach_absolute_time(); + + // Convert to milliseconds. + + // If this is the first time we've run, get the timebase. + // We can use denom == 0 to indicate that sTimebaseInfo is + // uninitialised because it makes no sense to have a zero + // denominator is a fraction. + + if (sTimebaseInfo.denom == 0) { + (void) mach_timebase_info(&sTimebaseInfo); + } + + // Do the maths. We hope that the multiplication doesn't + // overflow; the price you pay for working in fixed point. + + uint64_t milliseconds = + ((absolute / 1000000) * sTimebaseInfo.numer) / sTimebaseInfo.denom; + + return milliseconds; +} + - (void)mouseDown:(NSEvent *)event { if ([self inputManagerHandleMouseEvent:event]) @@ -376,7 +404,18 @@ - (void)mouseDown:(NSEvent *)event int button = [event buttonNumber]; int flags = [event modifierFlags]; - int count = [event clickCount]; + int repeat = 0; + static uint64_t previousTick; + static dispatch_once_t onceToken; + dispatch_once (&onceToken, ^{ + previousTick = [self getTick]; + }); + uint64_t currentTick = [self getTick]; + id mouset = [[[self vimController] vimState] objectForKey:@"p_mouset"]; + if ((currentTick - previousTick) < [mouset longValue]) { + repeat = 1; + } + previousTick = currentTick; NSMutableData *data = [NSMutableData data]; // If desired, intepret Ctrl-Click as a right mouse click. @@ -394,7 +433,7 @@ - (void)mouseDown:(NSEvent *)event [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]; }