Skip to content

Commit

Permalink
Merge pull request #462 from OpenSmalltalk/fix_osx_linux_mouse_wheel
Browse files Browse the repository at this point in the history
Fix osx linux mouse wheel
  • Loading branch information
nicolas-cellier-aka-nice committed Dec 28, 2019
2 parents 48af339 + 9d26c97 commit 83e43ee
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
60 changes: 51 additions & 9 deletions platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m
Expand Up @@ -263,32 +263,74 @@ - (void) recordMouseEvent:(NSEvent *)theEvent fromView: (NSView <sqSqueakOSXView
- (void) recordWheelEvent:(NSEvent *) theEvent fromView: (NSView <sqSqueakOSXView> *) 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;
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions platforms/unix/vm/sqUnixEvent.c
Expand Up @@ -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);
Expand Down

0 comments on commit 83e43ee

Please sign in to comment.