Skip to content
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

Fix osx linux mouse wheel #462

Merged
merged 4 commits into from Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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