summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWladimir Leuschner <[email protected]>2025-04-04 11:25:14 +0200
committerWladimir Leuschner <[email protected]>2025-05-14 19:00:09 +0200
commit6273e2e0edfc0eba148889158b2d06ad5a6eb0b9 (patch)
treef148cf8d64372e60fd6b3372f51999924094f77a
parenta7d8d3ecdd934b4fcce6fd2658f0ac6a38a7dde1 (diff)
WindowsQPA: Make custom titlebar respect swapped mouse buttons
Custom titlebar input handling is done on WM_NCHITTEST, which is handled at the WinAPI level. The WinAPI does not take into account the swapped mouse buttons when querying the state of VK_LEFTBUTTON and VK_RIGHTBUTTON with GetAsyncKeyState, so this behavior has to be implemented manually. In case of swapped mouse buttons, GetSystemMetrics(SM_SWAPBUTTON) will return true. This patch inverses the meaning of Right and Left buttons in case GetSystemMetrics(SM_SWAPBUTTON) returns true. Pick-to: 6.9 Change-Id: Ie46e130dc0bb49de318c8d04a3cc426f7a346b5b Reviewed-by: Tor Arne Vestbø <[email protected]> Reviewed-by: Zhao Yuhang <[email protected]>
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
index 77e0cbfcaa6..cf22783c286 100644
--- a/src/plugins/platforms/windows/qwindowswindow.cpp
+++ b/src/plugins/platforms/windows/qwindowswindow.cpp
@@ -3313,16 +3313,23 @@ bool QWindowsWindow::handleNonClientHitTest(const QPoint &globalPos, LRESULT *re
const int titleBarHeight = getTitleBarHeight_sys(savedDpi());
const int titleButtonWidth = titleBarHeight * 1.5;
int buttons = 1;
+ const bool mouseButtonsSwapped = GetSystemMetrics(SM_SWAPBUTTON);
+ auto mouseButtons = Qt::NoButton;
+ if (mouseButtonsSwapped)
+ mouseButtons = GetAsyncKeyState(VK_LBUTTON) != 0 ? Qt::RightButton : (GetAsyncKeyState(VK_RBUTTON) ? Qt::LeftButton : Qt::NoButton);
+ else
+ mouseButtons = GetAsyncKeyState(VK_LBUTTON) != 0 ? Qt::LeftButton : (GetAsyncKeyState(VK_RBUTTON) ? Qt::RightButton : Qt::NoButton);
+
if (globalPos.y() < geom.top() + titleBarHeight) {
if (m_data.flags.testFlags(Qt::WindowCloseButtonHint) || isDefaultTitleBar) {
if ((globalPos.x() > geom.right() - titleButtonWidth * buttons) && (globalPos.x() <= geom.right())) {
- if (GetAsyncKeyState(VK_LBUTTON))
+ if (mouseButtons == Qt::LeftButton)
*result = HTCLOSE;
}
buttons++;
} if (m_data.flags.testFlags(Qt::WindowMaximizeButtonHint) || isDefaultTitleBar) {
if ((globalPos.x() > geom.right() - titleButtonWidth * buttons) && (globalPos.x() <= geom.right() - titleButtonWidth * (buttons-1))){
- if (GetAsyncKeyState(VK_LBUTTON)) {
+ if (mouseButtons == Qt::LeftButton) {
if (IsZoomed(m_data.hwnd))
*result = HTSIZE;
else
@@ -3332,18 +3339,17 @@ bool QWindowsWindow::handleNonClientHitTest(const QPoint &globalPos, LRESULT *re
buttons++;
} if (m_data.flags.testFlags(Qt::WindowMinimizeButtonHint) || isDefaultTitleBar) {
if ((globalPos.x() > geom.right() - titleButtonWidth * buttons) && (globalPos.x() <= geom.right() - titleButtonWidth * (buttons-1))){
- if (GetAsyncKeyState(VK_LBUTTON))
+ if (mouseButtons == Qt::LeftButton)
*result = HTMINBUTTON;
}
buttons++;
} if ((isCustomized || isDefaultTitleBar) &&
*result == HTCLIENT){
QWindow* wnd = window();
- auto buttons = GetAsyncKeyState(VK_LBUTTON) != 0 ? Qt::LeftButton : Qt::NoButton;
- if (buttons != Qt::NoButton) {
- QMouseEvent event(QEvent::MouseButtonPress, localPos, globalPos, buttons, buttons, Qt::NoModifier);
+ if (mouseButtons != Qt::NoButton) {
+ QMouseEvent event(QEvent::MouseButtonPress, localPos, globalPos, mouseButtons, mouseButtons, Qt::NoModifier);
QGuiApplication::sendEvent(wnd, &event);
- if (!event.isAccepted() && GetAsyncKeyState(VK_RBUTTON))
+ if (!event.isAccepted() && mouseButtons == Qt::RightButton)
*result = HTSYSMENU;
else if (!event.isAccepted())
*result = HTCAPTION;