From 06663948d6d5194ed6c110d964a8b0e00fece33c Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Wed, 3 Apr 2024 01:59:24 +0300 Subject: [PATCH] wl: Fix mouse button indices Handle the first five pointer buttons by checking their exact button codes. Their values are used directly to avoid the need for to be present at build time. --- platform/wayland/cog-platform-wl.c | 36 +++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/platform/wayland/cog-platform-wl.c b/platform/wayland/cog-platform-wl.c index ba047e00..b046e6a1 100644 --- a/platform/wayland/cog-platform-wl.c +++ b/platform/wayland/cog-platform-wl.c @@ -345,18 +345,33 @@ pointer_on_button(void *data, return; } - CogWlPlatform *platform = (CogWlPlatform *) cog_platform_get(); + /* + * Button codes taken from . + */ + switch (button) { + case /* BTN_LEFT */ 0x110: + seat->pointer.button = 0; + break; + case /* BTN_MIDDLE */ 0x112: + seat->pointer.button = 1; + break; + case /* BTN_RIGHT */ 0x111: + seat->pointer.button = 2; + break; + case /* BTN_BACK */ 0x116: + case /* BTN_EXTRA */ 0x113: + seat->pointer.button = 3; + break; + case /* BTN_FORWARD */ 0x115: + case /* BTN_SIDE */ 0x114: + seat->pointer.button = 4; + break; + default: + g_debug("%s: Unhandled button %#" PRIx32 " in pointer %p, ignored.", G_STRFUNC, button, pointer); + return; + } seat->pointer.serial = serial; - - /* @FIXME: what is this for? - if (button >= BTN_MOUSE) - button = button - BTN_MOUSE + 1; - else - button = 0; - */ - - seat->pointer.button = !!state ? button : 0; seat->pointer.state = state; struct wpe_input_pointer_event event = { @@ -368,6 +383,7 @@ pointer_on_button(void *data, seat->pointer.state, }; + CogWlPlatform *platform = (CogWlPlatform *) cog_platform_get(); CogWlPopup *popup = platform->popup; if (popup && popup->wl_surface) { if (seat->pointer.surface == popup->wl_surface) {