From 9b255e368da6c291f46082c27620d9f96a1e0244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Noel?= Date: Sun, 11 Oct 2015 12:46:36 +0200 Subject: [PATCH] handle up to 8 buttons with SDL2 based on https://github.com/RobertBeckebans/RBDOOM-3-BFG/pull/213 it's buggy on Linux/X11 before 2.0.4, but it works fine on other platforms extra bonus: don't generate garbage events for unknown mouse buttons --- neo/sys/events.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/neo/sys/events.cpp b/neo/sys/events.cpp index 288d6c0b..93850150 100644 --- a/neo/sys/events.cpp +++ b/neo/sys/events.cpp @@ -628,6 +628,18 @@ sysEvent_t Sys_GetEvent() { mouse_polls.Append(mouse_poll_t(M_DELTAZ, -1)); break; #endif + default: +#if SDL_VERSION_ATLEAST(2, 0, 0) + // handle X1 button and above + if( ev.button.button <= 8 ) // doesn't support more than 8 mouse buttons + { + int buttonIndex = ev.button.button - SDL_BUTTON_LEFT; + res.evValue = K_MOUSE1 + buttonIndex; + mouse_polls.Append( mouse_poll_t( M_ACTION1 + buttonIndex, ev.button.state == SDL_PRESSED ? 1 : 0 ) ); + } + else +#endif + continue; // handle next event } res.evValue2 = ev.button.state == SDL_PRESSED ? 1 : 0;