Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win32 xbutton support #921

Merged
merged 5 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions include/vsg/platform/win32/Win32_Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,40 @@ namespace vsgWin32
return static_cast<vsg::ButtonMask>(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.
Expand Down
4 changes: 2 additions & 2 deletions include/vsg/ui/PointerEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/vsg/platform/win32/Win32_Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 19 additions & 6 deletions src/vsg/platform/xcb/Xcb_Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,10 @@ bool Xcb_Window::pollEvents(UIEvents& events)
case (XCB_BUTTON_PRESS): {
auto button_press = reinterpret_cast<const xcb_button_press_event_t*>(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)
{
Expand All @@ -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 to 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));
}
}

Expand All @@ -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 to 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;
Expand Down
Loading