diff --git a/platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m b/platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m index 37a0294102..c079e8a313 100644 --- a/platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m +++ b/platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m @@ -263,32 +263,74 @@ - (void) recordMouseEvent:(NSEvent *)theEvent fromView: (NSView *) aView{ [self recordMouseEvent: theEvent fromView: aView]; + static float prevXDelta = 0; + static float prevYDelta = 0; + static int prevXTime = 0; + static int prevYTime = 0; +#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) + CGFloat x = [theEvent scrollingDeltaX]; + CGFloat y = [theEvent scrollingDeltaY]; + /* Convert event units into scrolling units + Assume that 1 event unit corresponds to a single wheel mouse notch + A single notch evaluates to 120 scrolling units */ + float xDelta = x * 120; + float yDelta = y * 120; + if ([theEvent respondsToSelector:@selector(hasPreciseScrollingDeltas)]) { + if ([theEvent hasPreciseScrollingDeltas]) { + /* Note: in case of precise scrolling x,y are given in points + Assume that 120 scrolling units corresponds to 3 lines delta + that is 40 points for a 13.3 point line grid + hence the factor 3 */ + xDelta = x * 3; + yDelta = y * 3; + } + } +#else CGFloat x = [theEvent deltaX]; CGFloat y = [theEvent deltaY]; - + float xDelta = x * 120; + float yDelta = y * 120; +#endif + /* accumulate enough delta before sending the event to the image */ + int now = ioMSecs(); + if( xDelta != 0 ) { + prevXDelta = ( now - prevXTime < 500) ? prevXDelta + xDelta : xDelta; + prevXTime = now; + } + if( yDelta != 0 ) { + prevYDelta = ( now - prevYTime < 500) ? prevYDelta + yDelta : yDelta; + prevYTime = now; + } if (sendWheelEvents) { + float limit = 20; + if (-limit < prevXDelta && prevXDelta < limit && -limit < prevYDelta && prevYDelta < limit ) return; sqMouseEvent evt; memset(&evt,0,sizeof(evt)); evt.type = EventTypeMouseWheel; evt.timeStamp = ioMSecs(); - evt.x = x * 32; - evt.y = y * 32; + evt.x = prevXDelta; + evt.y = prevYDelta; - //printf("x:%f y:%f ex:%ld ey:%ld\n", x, y, evt.x, evt.y); + prevXDelta = 0; + prevYDelta = 0; int buttonAndModifiers = [self mapMouseAndModifierStateToSqueakBits: theEvent]; - evt.buttons = buttonAndModifiers >> 3; + evt.buttons = buttonAndModifiers & 7; + evt.modifiers = buttonAndModifiers >> 3; evt.windowIndex = aView.windowLogic.windowIndex; [self pushEventToQueue:(sqInputEvent *) &evt]; } else { - if (x != 0.0f) { - [self fakeMouseWheelKeyboardEventsKeyCode: (x < 0 ? 124 : 123) ascii: (x < 0 ? 29 : 28) windowIndex: aView.windowLogic.windowIndex]; + float limit = 120; + if (prevXDelta <= -limit || limit <= prevXDelta) { + [self fakeMouseWheelKeyboardEventsKeyCode: (prevXDelta < 0 ? 124 : 123) ascii: (prevXDelta < 0 ? 29 : 28) windowIndex: aView.windowLogic.windowIndex]; + prevXDelta = 0; } - if (y != 0.0f) { - [self fakeMouseWheelKeyboardEventsKeyCode: (y < 0 ? 125 : 126) ascii: (y < 0 ? 31 : 30) windowIndex: aView.windowLogic.windowIndex]; + if (prevYDelta <= -limit || limit <= prevYDelta) { + [self fakeMouseWheelKeyboardEventsKeyCode: (prevYDelta < 0 ? 125 : 126) ascii: (prevYDelta < 0 ? 31 : 30) windowIndex: aView.windowLogic.windowIndex]; + prevYDelta = 0; } } } diff --git a/platforms/unix/vm/sqUnixEvent.c b/platforms/unix/vm/sqUnixEvent.c index f51a5d9c61..785ecdc64c 100644 --- a/platforms/unix/vm/sqUnixEvent.c +++ b/platforms/unix/vm/sqUnixEvent.c @@ -183,11 +183,14 @@ static void recordMouseEvent(void) static void recordMouseWheelEvent(int dx, int dy) { + int state= getButtonState(); sqMouseEvent *evt= allocateMouseWheelEvent(); evt->x= dx; evt->y= dy; - // VM reads fifth (4th 0-based) field for event's modifiers - evt->buttons= (getButtonState() >> 3); + evt->buttons= (state & 0x7); + evt->modifiers= (state >> 3); + evt->nrClicks= + evt->windowIndex= 0; signalInputEvent(); #if DEBUG_MOUSE_EVENTS printf("EVENT (recordMouseWheelEvent): time: %d mouse dx %d dy %d", evt->timeStamp, dx, dy);