From addf7398e590c1011883e0d269fd01e06c5bb877 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Fri, 19 Sep 2008 17:50:07 +0200 Subject: [PATCH] Don't coalesce scroll wheel events Since the backend now pops off all input events at once whenever it tends to the run-loop, it is no longer necessary to coalesce scroll wheel events. In fact, without coalescing the scroll wheel (or track pad) feels a lot smoother. --- src/MacVim/MMTextViewHelper.h | 1 - src/MacVim/MMTextViewHelper.m | 49 ++++++++++++------------------------------- 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/src/MacVim/MMTextViewHelper.h b/src/MacVim/MMTextViewHelper.h index 2213ee1b..ef7e1798 100644 --- a/src/MacVim/MMTextViewHelper.h +++ b/src/MacVim/MMTextViewHelper.h @@ -30,7 +30,6 @@ enum { BOOL isAutoscrolling; int mouseShape; NSTrackingRectTag trackingRectTag; - float scrollWheelAccumulator; } - (void)setTextView:(id)view; diff --git a/src/MacVim/MMTextViewHelper.m b/src/MacVim/MMTextViewHelper.m index 77f3314b..08e4f70a 100644 --- a/src/MacVim/MMTextViewHelper.m +++ b/src/MacVim/MMTextViewHelper.m @@ -33,10 +33,6 @@ static NSTimeInterval MMDragTimerMinInterval = 0.01; // The number of pixels in which the drag timer interval changes static float MMDragAreaSize = 73.0f; -// Number of seconds to delay before sending scroll wheel events. (A delay of -// 0.05 seconds equals an update frequency of 20 Hz.) -static NSTimeInterval MMScrollWheelDelay = 0.05; - @interface MMTextViewHelper (Private) - (MMWindowController *)windowController; @@ -48,7 +44,6 @@ static NSTimeInterval MMScrollWheelDelay = 0.05; - (void)dragTimerFired:(NSTimer *)timer; - (void)setCursor; - (NSRect)trackingRect; -- (void)handleScrollWheelEvent:(id)event; @end @@ -271,16 +266,20 @@ static NSTimeInterval MMScrollWheelDelay = 0.05; if ([event deltaY] == 0) return; - // Don't send the event straight away because lots of these events may be - // received in rapid succession. Instead, accumulate the events and send - // off the scroll total at a predetermined maximum rate. This avoids - // clogging up the DO messaging system on faster machines. - if (0 == scrollWheelAccumulator) - [self performSelector:@selector(handleScrollWheelEvent:) - withObject:event - afterDelay:MMScrollWheelDelay]; + int row, col; + NSPoint pt = [textView convertPoint:[event locationInWindow] fromView:nil]; + if ([textView convertPoint:pt toRow:&row column:&col]) { + int flags = [event modifierFlags]; + float dy = [event deltaY]; + NSMutableData *data = [NSMutableData data]; - scrollWheelAccumulator += [event deltaY]; + [data appendBytes:&row length:sizeof(int)]; + [data appendBytes:&col length:sizeof(int)]; + [data appendBytes:&flags length:sizeof(int)]; + [data appendBytes:&dy length:sizeof(float)]; + + [[self vimController] sendMessage:ScrollWheelMsgID data:data]; + } } - (void)mouseDown:(NSEvent *)event @@ -713,26 +712,4 @@ static NSTimeInterval MMScrollWheelDelay = 0.05; return rect; } -- (void)handleScrollWheelEvent:(id)event -{ - if (0 == scrollWheelAccumulator) - return; - - int row, col; - NSPoint pt = [textView convertPoint:[event locationInWindow] fromView:nil]; - if ([textView convertPoint:pt toRow:&row column:&col]) { - int flags = [event modifierFlags]; - NSMutableData *data = [NSMutableData data]; - - [data appendBytes:&row length:sizeof(int)]; - [data appendBytes:&col length:sizeof(int)]; - [data appendBytes:&flags length:sizeof(int)]; - [data appendBytes:&scrollWheelAccumulator length:sizeof(float)]; - - [[self vimController] sendMessage:ScrollWheelMsgID data:data]; - } - - scrollWheelAccumulator = 0; -} - @end // MMTextViewHelper (Private) -- 2.11.4.GIT