From 4773fc20a6e622c9405016c477928e1d382aa5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 18 Oct 2024 19:57:21 +0200 Subject: [PATCH] Platform: expose MouseButton4 and 5 in EmscriptenApplication. And the spec is again a total mess, as those are listed in the singular button field, but not the buttons bitmask. --- src/Magnum/Platform/EmscriptenApplication.cpp | 17 +++++++++++++++++ src/Magnum/Platform/EmscriptenApplication.h | 8 +++++++- .../Platform/Test/EmscriptenApplicationTest.cpp | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index 4ea6a96ab..c87c531a6 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -512,6 +512,10 @@ EmscriptenApplication::Pointer buttonToPointer(const std::int32_t button) { return EmscriptenApplication::Pointer::MouseMiddle; case 2: return EmscriptenApplication::Pointer::MouseRight; + case 3: + return EmscriptenApplication::Pointer::MouseButton4; + case 4: + return EmscriptenApplication::Pointer::MouseButton5; } /* W3C spec allows other, platform-specific buttons: @@ -532,6 +536,19 @@ EmscriptenApplication::Pointers buttonsToPointers(const std::uint32_t buttons) { pointers |= EmscriptenApplication::Pointer::MouseMiddle; if(buttons & (1 << 1)) pointers |= EmscriptenApplication::Pointer::MouseRight; + /* https://www.w3.org/TR/uievents/#dom-mouseevent-buttons doesn't list + those even though the X1 and X2 buttons from + https://www.w3.org/TR/uievents/#dom-mouseevent-button + don't have any matching value here. In addition to the order swap and + the spec trying to describe bit flags in a *really* roundabout and + complicated way, this isn't entirely surprising. Chrome reports the + extra buttons, and the bit flags match here as well, so assume that's + correct. Firefox doesn't report X1 and X2 at all, so they're not present + here either. */ + if(buttons & (1 << 3)) + pointers |= EmscriptenApplication::Pointer::MouseButton4; + if(buttons & (1 << 4)) + pointers |= EmscriptenApplication::Pointer::MouseButton5; return pointers; } diff --git a/src/Magnum/Platform/EmscriptenApplication.h b/src/Magnum/Platform/EmscriptenApplication.h index 222030ef8..23e8e1201 100644 --- a/src/Magnum/Platform/EmscriptenApplication.h +++ b/src/Magnum/Platform/EmscriptenApplication.h @@ -1057,7 +1057,13 @@ enum class EmscriptenApplication::Pointer: UnsignedByte { MouseMiddle = 1 << 1, /** Right mouse button */ - MouseRight = 1 << 2 + MouseRight = 1 << 2, + + /** Fourth mouse button, such as wheel left */ + MouseButton4 = 1 << 3, + + /** Fourth mouse button, such as wheel right */ + MouseButton5 = 1 << 4, }; CORRADE_ENUMSET_OPERATORS(EmscriptenApplication::Pointers) diff --git a/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp b/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp index 8b8f12ad9..d6d82fbad 100644 --- a/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp +++ b/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp @@ -73,6 +73,8 @@ static Debug& operator<<(Debug& debug, Application::Pointer value) { _c(MouseLeft) _c(MouseMiddle) _c(MouseRight) + _c(MouseButton4) + _c(MouseButton5) #undef _c } @@ -113,6 +115,8 @@ Debug& operator<<(Debug& debug, Application::Pointers value) { Application::Pointer::MouseLeft, Application::Pointer::MouseMiddle, Application::Pointer::MouseRight, + Application::Pointer::MouseButton4, + Application::Pointer::MouseButton5, }); }