summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowswindow.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-22 06:29:20 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-22 17:46:09 +0000
commitac98b6e4ea46835d01b4c8f35b566a92136c90fe (patch)
tree18230c81ef0139f9c3fed87f886566ec7fc5d628 /src/plugins/platforms/windows/qwindowswindow.cpp
parent034427a45a0f220d6a7e38bac4c70cfd60b07982 (diff)
Windows QPA: Move the touch types API from platformheaders into QtGui
Change TouchWindowTouchType(s) to be (global) property of QGuiApplication's native Windows interface since it does not make sense to set it per window. It appears the previous code setting the types per Window has never worked since registerTouchWindow() bailed out due to the checks for the flags TouchRegistered and IsTouchWindow() (setting in HCBT_CREATEWND). In addition, registering windows for touch after plugging in a device would not observe the setting. Move the checks around to make this work. Task-number: QTBUG-41433 Task-number: QTBUG-48849 Task-number: QTBUG-83252 Change-Id: I4306fdf13208f6eef22655875f3bd1769270e617 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowswindow.cpp')
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.cpp54
1 files changed, 36 insertions, 18 deletions
diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
index 8df4bb3428..cd234e22b7 100644
--- a/src/plugins/platforms/windows/qwindowswindow.cpp
+++ b/src/plugins/platforms/windows/qwindowswindow.cpp
@@ -1128,6 +1128,20 @@ QMargins QWindowsBaseWindow::frameMargins_sys() const
return QWindowsGeometryHint::frame(handle(), style(), exStyle());
}
+std::optional<QWindowsBaseWindow::TouchWindowTouchTypes>
+ QWindowsBaseWindow::touchWindowTouchTypes_sys() const
+{
+ ULONG touchFlags = 0;
+ if (IsTouchWindow(handle(), &touchFlags) == FALSE)
+ return {};
+ TouchWindowTouchTypes result;
+ if ((touchFlags & TWF_FINETOUCH) != 0)
+ result.setFlag(TouchWindowTouchType::FineTouch);
+ if ((touchFlags & TWF_WANTPALM) != 0)
+ result.setFlag(TouchWindowTouchType::WantPalmTouch);
+ return result;
+}
+
void QWindowsBaseWindow::hide_sys() // Normal hide, do not activate other windows.
{
SetWindowPos(handle(), nullptr , 0, 0, 0, 0,
@@ -1345,7 +1359,11 @@ QWindowsWindow::QWindowsWindow(QWindow *aWindow, const QWindowsWindowData &data)
#endif
updateDropSite(window()->isTopLevel());
- registerTouchWindow();
+ // Register touch unless if the flags are already set by a hook
+ // such as HCBT_CREATEWND
+ if (!touchWindowTouchTypes_sys().has_value())
+ registerTouchWindow();
+
const qreal opacity = qt_window_private(aWindow)->opacity;
if (!qFuzzyCompare(opacity, qreal(1.0)))
setOpacity(opacity);
@@ -3040,28 +3058,28 @@ void QWindowsWindow::invalidateSurface()
#endif // QT_NO_OPENGL
}
-void QWindowsWindow::setTouchWindowTouchTypeStatic(QWindow *window, QWindowsWindowFunctions::TouchWindowTouchTypes touchTypes)
+void QWindowsWindow::registerTouchWindow()
{
- if (!window->handle())
+ if ((QWindowsContext::instance()->systemInfo() & QWindowsContext::SI_SupportsTouch) == 0)
return;
- static_cast<QWindowsWindow *>(window->handle())->registerTouchWindow(touchTypes);
-}
-void QWindowsWindow::registerTouchWindow(QWindowsWindowFunctions::TouchWindowTouchTypes touchTypes)
-{
- if ((QWindowsContext::instance()->systemInfo() & QWindowsContext::SI_SupportsTouch)
- && !testFlag(TouchRegistered)) {
- ULONG touchFlags = 0;
- const bool ret = IsTouchWindow(m_data.hwnd, &touchFlags);
- // Return if it is not a touch window or the flags are already set by a hook
- // such as HCBT_CREATEWND
- if (ret || touchFlags != 0)
+ // Initially register or re-register to change the flags
+ const auto touchTypes = QWindowsIntegration::instance()->touchWindowTouchType();
+ if (testFlag(TouchRegistered)) {
+ const auto currentTouchTypes = touchWindowTouchTypes_sys();
+ if (currentTouchTypes.has_value() && currentTouchTypes.value() == touchTypes)
return;
- if (RegisterTouchWindow(m_data.hwnd, ULONG(touchTypes)))
- setFlag(TouchRegistered);
- else
- qErrnoWarning("RegisterTouchWindow() failed for window '%s'.", qPrintable(window()->objectName()));
}
+
+ ULONG touchFlags = 0;
+ if (touchTypes.testFlag(TouchWindowTouchType::FineTouch))
+ touchFlags |= TWF_FINETOUCH;
+ if (touchTypes.testFlag(TouchWindowTouchType::WantPalmTouch))
+ touchFlags |= TWF_WANTPALM;
+ if (RegisterTouchWindow(m_data.hwnd, touchFlags))
+ setFlag(TouchRegistered);
+ else
+ qErrnoWarning("RegisterTouchWindow() failed for window '%s'.", qPrintable(window()->objectName()));
}
void QWindowsWindow::aboutToMakeCurrent()