From 3a678a664f784a06212ad336cd4f700e0a01d15e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 20 Aug 2023 18:14:55 +0100 Subject: [PATCH 1/4] Removed misleading comments --- include/vsg/ui/PointerEvent.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/vsg/ui/PointerEvent.h b/include/vsg/ui/PointerEvent.h index 68dadbf1f..1a9678a4e 100644 --- a/include/vsg/ui/PointerEvent.h +++ b/include/vsg/ui/PointerEvent.h @@ -25,8 +25,8 @@ namespace vsg BUTTON_MASK_1 = 256, BUTTON_MASK_2 = 512, BUTTON_MASK_3 = 1024, - BUTTON_MASK_4 = 2048, /// mouse wheel up - BUTTON_MASK_5 = 4096 /// mouse wheel down + BUTTON_MASK_4 = 2048, + BUTTON_MASK_5 = 4096 }; /// PointerEvent is a base class for mouse pointer events From efb55cf7b43ead936dd0d6800010f4d009078b28 Mon Sep 17 00:00:00 2001 From: LeeRiva <76054616+LeeRiva@users.noreply.github.com> Date: Sun, 20 Aug 2023 18:15:40 +0100 Subject: [PATCH 2/4] Added support for XBUTTTON's 1 and 2. --- include/vsg/platform/win32/Win32_Window.h | 36 +++++++++++++++++++---- src/vsg/platform/win32/Win32_Window.cpp | 11 ++++--- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/include/vsg/platform/win32/Win32_Window.h b/include/vsg/platform/win32/Win32_Window.h index 4c85766ee..cccc5a6d1 100644 --- a/include/vsg/platform/win32/Win32_Window.h +++ b/include/vsg/platform/win32/Win32_Window.h @@ -119,16 +119,40 @@ namespace vsgWin32 return static_cast(mask); } - inline uint32_t getButtonDownEventDetail(UINT buttonMsg) + inline uint32_t getButtonDownEventDetail(UINT buttonMsg, WORD wParamHi) { - return buttonMsg == WM_LBUTTONDOWN ? 1 : (buttonMsg == WM_MBUTTONDOWN ? 2 : buttonMsg == WM_RBUTTONDOWN ? 3 - : (buttonMsg == WM_XBUTTONDOWN ? 4 : 0)); // need to determine x1, x2 + switch (buttonMsg) + { + case WM_LBUTTONDOWN: return 1; + case WM_MBUTTONDOWN: return 2; + case WM_RBUTTONDOWN: return 3; + case WM_XBUTTONDOWN: + if (wParamHi == XBUTTON1) + return 4; + else if (wParamHi == XBUTTON2) + return 5; + else return 0; + default: + return 0; + } } - inline uint32_t getButtonUpEventDetail(UINT buttonMsg) + inline uint32_t getButtonUpEventDetail(UINT buttonMsg, WORD wParamHi) { - return buttonMsg == WM_LBUTTONUP ? 1 : (buttonMsg == WM_MBUTTONUP ? 2 : buttonMsg == WM_RBUTTONUP ? 3 - : (buttonMsg == WM_XBUTTONUP ? 4 : 0)); + switch (buttonMsg) + { + case WM_LBUTTONUP: return 1; + case WM_MBUTTONUP: return 2; + case WM_RBUTTONUP: return 3; + case WM_XBUTTONUP: + if (wParamHi == XBUTTON1) + return 4; + else if (wParamHi == XBUTTON2) + return 5; + else return 0; + default: + return 0; + } } /// Win32_Window implements Win32 specific window creation, event handling and vulkan Surface setup. diff --git a/src/vsg/platform/win32/Win32_Window.cpp b/src/vsg/platform/win32/Win32_Window.cpp index d8e5ea3ac..445eca7dc 100644 --- a/src/vsg/platform/win32/Win32_Window.cpp +++ b/src/vsg/platform/win32/Win32_Window.cpp @@ -566,24 +566,27 @@ LRESULT Win32_Window::handleWin32Messages(UINT msg, WPARAM wParam, LPARAM lParam case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: + case WM_XBUTTONDOWN: case WM_LBUTTONDBLCLK: case WM_MBUTTONDBLCLK: - case WM_RBUTTONDBLCLK: { + case WM_RBUTTONDBLCLK: + case WM_XBUTTONDBLCLK: { int32_t mx = GET_X_LPARAM(lParam); int32_t my = GET_Y_LPARAM(lParam); - bufferedEvents.emplace_back(vsg::ButtonPressEvent::create(this, event_time, mx, my, getButtonMask(wParam), getButtonDownEventDetail(msg))); + bufferedEvents.emplace_back(vsg::ButtonPressEvent::create(this, event_time, mx, my, getButtonMask(wParam), getButtonDownEventDetail(msg, HIWORD(wParam)))); //::SetCapture(_window); } break; case WM_LBUTTONUP: case WM_MBUTTONUP: - case WM_RBUTTONUP: { + case WM_RBUTTONUP: + case WM_XBUTTONUP: { int32_t mx = GET_X_LPARAM(lParam); int32_t my = GET_Y_LPARAM(lParam); - bufferedEvents.emplace_back(vsg::ButtonReleaseEvent::create(this, event_time, mx, my, getButtonMask(wParam), getButtonUpEventDetail(msg))); + bufferedEvents.emplace_back(vsg::ButtonReleaseEvent::create(this, event_time, mx, my, getButtonMask(wParam), getButtonUpEventDetail(msg, HIWORD(wParam)))); //::ReleaseCapture(); // should only release once all mouse buttons are released ?? break; From 1d8c7d3fa00fc163ed4645eaf2f505108bde22dc Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 20 Aug 2023 20:19:42 +0100 Subject: [PATCH 3/4] Added remapping of the 8 & 9 buttons to 4 and 5 to be consistent with Window XButtons --- src/vsg/platform/xcb/Xcb_Window.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/vsg/platform/xcb/Xcb_Window.cpp b/src/vsg/platform/xcb/Xcb_Window.cpp index 076b53406..bc581516b 100644 --- a/src/vsg/platform/xcb/Xcb_Window.cpp +++ b/src/vsg/platform/xcb/Xcb_Window.cpp @@ -702,10 +702,10 @@ bool Xcb_Window::pollEvents(UIEvents& events) case (XCB_BUTTON_PRESS): { auto button_press = reinterpret_cast(event); - vsg::clock::time_point event_time = _first_xcb_time_point + std::chrono::milliseconds(button_press->time - _first_xcb_timestamp); - if (button_press->same_screen) { + vsg::clock::time_point event_time = _first_xcb_time_point + std::chrono::milliseconds(button_press->time - _first_xcb_timestamp); + // X11/Xcb treat scroll wheel up/down as button 4 and 5 so handle these as such if (button_press->detail == 4) { @@ -717,9 +717,15 @@ bool Xcb_Window::pollEvents(UIEvents& events) } else { - uint16_t pressedButtonMask = 1 << (7 + button_press->detail); + uint16_t button = button_press->detail; + + // remap 8, 9 tp 4 and 5 to be consistent with Windows treatment of the XButtons + if (button==8) button = 4; + if (button==9) button = 5; + + uint16_t pressedButtonMask = BUTTON_MASK_1 << (button-1); uint16_t newButtonMask = maskButtons(button_press->state) | pressedButtonMask; - bufferedEvents.emplace_back(vsg::ButtonPressEvent::create(this, event_time, button_press->event_x, button_press->event_y, vsg::ButtonMask(newButtonMask), button_press->detail)); + bufferedEvents.emplace_back(vsg::ButtonPressEvent::create(this, event_time, button_press->event_x, button_press->event_y, vsg::ButtonMask(newButtonMask), button)); } } @@ -732,9 +738,16 @@ bool Xcb_Window::pollEvents(UIEvents& events) if (button_release->same_screen && button_release->detail != 4 && button_release->detail != 5) { vsg::clock::time_point event_time = _first_xcb_time_point + std::chrono::milliseconds(button_release->time - _first_xcb_timestamp); - uint16_t releasedButtonMask = 1 << (7 + button_release->detail); + + uint16_t button = button_release->detail; + + // remap 8, 9 tp 4 and 5 to be consistent with Windows treatment of the XButtons + if (button==8) button = 4; + if (button==9) button = 5; + + uint16_t releasedButtonMask = BUTTON_MASK_1 << (button-1); uint16_t newButtonMask = maskButtons(button_release->state) & ~releasedButtonMask; - bufferedEvents.emplace_back(vsg::ButtonReleaseEvent::create(this, event_time, button_release->event_x, button_release->event_y, vsg::ButtonMask(newButtonMask), button_release->detail)); + bufferedEvents.emplace_back(vsg::ButtonReleaseEvent::create(this, event_time, button_release->event_x, button_release->event_y, vsg::ButtonMask(newButtonMask), button)); } break; From 1a5f0c9420685e9e69ddb64a53cc19b25ffe6708 Mon Sep 17 00:00:00 2001 From: LeeRiva <76054616+LeeRiva@users.noreply.github.com> Date: Mon, 21 Aug 2023 09:43:54 +0200 Subject: [PATCH 4/4] [FIXED] typos --- src/vsg/platform/xcb/Xcb_Window.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vsg/platform/xcb/Xcb_Window.cpp b/src/vsg/platform/xcb/Xcb_Window.cpp index bc581516b..44dae69d7 100644 --- a/src/vsg/platform/xcb/Xcb_Window.cpp +++ b/src/vsg/platform/xcb/Xcb_Window.cpp @@ -719,7 +719,7 @@ bool Xcb_Window::pollEvents(UIEvents& events) { uint16_t button = button_press->detail; - // remap 8, 9 tp 4 and 5 to be consistent with Windows treatment of the XButtons + // remap 8, 9 to 4 and 5 to be consistent with Windows treatment of the XButtons if (button==8) button = 4; if (button==9) button = 5; @@ -741,7 +741,7 @@ bool Xcb_Window::pollEvents(UIEvents& events) uint16_t button = button_release->detail; - // remap 8, 9 tp 4 and 5 to be consistent with Windows treatment of the XButtons + // remap 8, 9 to 4 and 5 to be consistent with Windows treatment of the XButtons if (button==8) button = 4; if (button==9) button = 5;