From cef62541ce8aa574be2be802db9d913c5fe0ea90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 18 May 2013 09:21:26 +0200 Subject: [PATCH] Support mouse wheel events Emitting button/press release events on buttons 4 to 7 to emulate the vertical and horizontal scrolling. --- egl_wayland_backend.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/egl_wayland_backend.cpp b/egl_wayland_backend.cpp index 8b09267676..401b6b06f3 100644 --- a/egl_wayland_backend.cpp +++ b/egl_wayland_backend.cpp @@ -169,9 +169,27 @@ static void pointerHandleAxis(void *data, wl_pointer *pointer, uint32_t time, ui Q_UNUSED(data) Q_UNUSED(pointer) Q_UNUSED(time) - Q_UNUSED(axis) - Q_UNUSED(value) - // TODO: implement mouse wheel support + uint8_t xButton = 0; + const int delta = wl_fixed_to_int(value); + if (delta == 0) { + return; + } + switch (axis) { + case WL_POINTER_AXIS_VERTICAL_SCROLL: + xButton = delta > 0 ? XCB_BUTTON_INDEX_5 : XCB_BUTTON_INDEX_4; + break; + case WL_POINTER_AXIS_HORIZONTAL_SCROLL: + // no enum values defined for buttons larger than 5 + xButton = delta > 0 ? 7 : 6; + break; + default: + // doesn't exist + return; + } + for (int i = 0; i < qAbs(delta); ++i) { + xcb_test_fake_input(connection(), XCB_BUTTON_PRESS, xButton, XCB_TIME_CURRENT_TIME, XCB_WINDOW_NONE, 0, 0, 0); + xcb_test_fake_input(connection(), XCB_BUTTON_RELEASE, xButton, XCB_TIME_CURRENT_TIME, XCB_WINDOW_NONE, 0, 0, 0); + } } static void keyboardHandleKeymap(void *data, wl_keyboard *keyboard,