Skip to content

Use 'mousetime' to recognize multi clicks #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/MacVim/MMBackend.m
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/MacVim/MMTextViewHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#import <Carbon/Carbon.h>
#endif

#include <mach/mach.h>
#include <mach/mach_time.h>


#define BLUE(argb) ((argb & 0xff)/255.0f)
#define GREEN(argb) (((argb>>8) & 0xff)/255.0f)
Expand Down Expand Up @@ -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;
Expand Down
43 changes: 41 additions & 2 deletions src/MacVim/MMTextViewHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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.
Expand All @@ -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];
}
Expand Down