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

x11: emit mouse wheel events, drop the ctrl+arrow workaround #303

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 12 additions & 11 deletions platforms/unix/vm-display-X11/sqUnixX11.c
Expand Up @@ -3682,17 +3682,18 @@ static void handleEvent(XEvent *evt)
buttonState |= x2sqButton(evt->xbutton.button);
recordMouseEvent();
break;
case 4: case 5: case 6: case 7: /* mouse wheel */
{
int keyCode = mouseWheel2Squeak[evt->xbutton.button - 4];
/* Set every meta bit to distinguish the fake event from a real
* right/left arrow.
*/
int modifiers = modifierState | CtrlKeyBit | OptionKeyBit | CommandKeyBit | ShiftKeyBit);
recordKeyboardEvent(keyCode, EventKeyDown, modifiers, keyCode);
recordKeyboardEvent(keyCode, EventKeyChar, modifiers, keyCode);
recordKeyboardEvent(keyCode, EventKeyUp, modifiers, keyCode);
}
#define MOUSE_WHEEL_INCREMENT 120
case 4: /* mouse wheel up */
recordMouseWheelEvent(0, 120);
break;
case 5: /* mouse wheel down */
recordMouseWheelEvent(0, -120);
break;
case 6: /* mouse wheel right */
recordMouseWheelEvent(-120, 0);
break;
case 7: /* mouse wheel left */
recordMouseWheelEvent(120, 0);
break;
default:
ioBeep();
Expand Down
12 changes: 12 additions & 0 deletions platforms/unix/vm/sqUnixEvent.c
Expand Up @@ -116,6 +116,10 @@ static sqInputEvent *allocateInputEvent(int eventType)
(sqMouseEvent *)allocateInputEvent(EventTypeMouse) \
)

#define allocateMouseWheelEvent() ( \
(sqMouseEvent *)allocateInputEvent(EventTypeMouseWheel) \
)

#define allocateKeyboardEvent() ( \
(sqKeyboardEvent *)allocateInputEvent(EventTypeKeyboard) \
)
Expand Down Expand Up @@ -166,6 +170,14 @@ static void signalInputEvent(void)
signalSemaphoreWithIndex(inputEventSemaIndex);
}

static void recordMouseWheelEvent(int dx, int dy) {
sqMouseEvent *evt = allocateMouseWheelEvent();
evt->x = dx;
evt->y = dy;
// VM reads fifth (4th 0-based) field for event's modifiers
evt->buttons = (getButtonState() >> 3);
signalInputEvent();
}

static void recordMouseEvent(void)
{
Expand Down