From ac98b6e4ea46835d01b4c8f35b566a92136c90fe Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 22 Jul 2020 06:29:20 +0200 Subject: Windows QPA: Move the touch types API from platformheaders into QtGui MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- src/plugins/platforms/windows/qwindowswindow.cpp | 54 ++++++++++++++++-------- 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'src/plugins/platforms/windows/qwindowswindow.cpp') 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_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(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() -- cgit v1.2.3