From c1d2124102f1dc29c7daa2d21532fa6f170477c5 Mon Sep 17 00:00:00 2001 From: y5nw <37980625+y5nw@users.noreply.github.com> Date: Sun, 20 Apr 2025 20:20:33 +0200 Subject: [PATCH] SDL: Send events for X1 and X2 mouse buttons (#16025) --- irr/src/CIrrDeviceSDL.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/irr/src/CIrrDeviceSDL.cpp b/irr/src/CIrrDeviceSDL.cpp index 536eda96e..28a92f450 100644 --- a/irr/src/CIrrDeviceSDL.cpp +++ b/irr/src/CIrrDeviceSDL.cpp @@ -766,12 +766,7 @@ bool CIrrDeviceSDL::run() SDL_Keymod keymod = SDL_GetModState(); irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; - irrevent.MouseInput.X = static_cast(SDL_event.button.x * ScaleX); - irrevent.MouseInput.Y = static_cast(SDL_event.button.y * ScaleY); - irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0; - irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0; - - irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; + irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; // value to be ignored #ifdef _IRR_EMSCRIPTEN_PLATFORM_ // Handle mouselocking in emscripten in Windowed mode. @@ -834,11 +829,29 @@ bool CIrrDeviceSDL::run() MouseButtonStates &= ~irr::EMBSM_MIDDLE; } break; + + // Since Irrlicht does not have event types for X1/X2 buttons, we simply pass + // those as keycodes instead. This is relatively hacky but avoids the effort of + // adding more mouse events that will be discarded anyway once we switch to SDL + case SDL_BUTTON_X1: + irrevent.EventType = irr::EET_KEY_INPUT_EVENT; + irrevent.KeyInput.Key = irr::KEY_XBUTTON1; + break; + + case SDL_BUTTON_X2: + irrevent.EventType = irr::EET_KEY_INPUT_EVENT; + irrevent.KeyInput.Key = irr::KEY_XBUTTON2; + break; } - irrevent.MouseInput.ButtonStates = MouseButtonStates; - - if (irrevent.MouseInput.Event != irr::EMIE_MOUSE_MOVED) { + bool shift = (keymod & KMOD_SHIFT) != 0; + bool control = (keymod & KMOD_CTRL) != 0; + if (irrevent.EventType == irr::EET_MOUSE_INPUT_EVENT && irrevent.MouseInput.Event != irr::EMIE_MOUSE_MOVED) { + irrevent.MouseInput.ButtonStates = MouseButtonStates; + irrevent.MouseInput.X = static_cast(SDL_event.button.x * ScaleX); + irrevent.MouseInput.Y = static_cast(SDL_event.button.y * ScaleY); + irrevent.MouseInput.Shift = shift; + irrevent.MouseInput.Control = control; postEventFromUser(irrevent); if (irrevent.MouseInput.Event >= EMIE_LMOUSE_PRESSED_DOWN && irrevent.MouseInput.Event <= EMIE_MMOUSE_PRESSED_DOWN) { @@ -851,6 +864,12 @@ bool CIrrDeviceSDL::run() postEventFromUser(irrevent); } } + } else if (irrevent.EventType == irr::EET_KEY_INPUT_EVENT) { + irrevent.KeyInput.Char = 0; + irrevent.KeyInput.PressedDown = SDL_event.type == SDL_MOUSEBUTTONDOWN; + irrevent.KeyInput.Shift = shift; + irrevent.KeyInput.Control = control; + postEventFromUser(irrevent); } break; }