summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
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
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')
-rw-r--r--src/plugins/platforms/windows/qwindowsapplication.cpp14
-rw-r--r--src/plugins/platforms/windows/qwindowsapplication.h4
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.cpp12
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.h1
-rw-r--r--src/plugins/platforms/windows/qwindowsnativeinterface.cpp2
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.cpp54
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.h10
7 files changed, 72 insertions, 25 deletions
diff --git a/src/plugins/platforms/windows/qwindowsapplication.cpp b/src/plugins/platforms/windows/qwindowsapplication.cpp
index a27da7bac8..082db98a4f 100644
--- a/src/plugins/platforms/windows/qwindowsapplication.cpp
+++ b/src/plugins/platforms/windows/qwindowsapplication.cpp
@@ -45,6 +45,20 @@
QT_BEGIN_NAMESPACE
+void QWindowsApplication::setTouchWindowTouchType(QWindowsApplication::TouchWindowTouchTypes type)
+{
+ if (m_touchWindowTouchTypes == type)
+ return;
+ m_touchWindowTouchTypes = type;
+ if (auto ctx = QWindowsContext::instance())
+ ctx->registerTouchWindows();
+}
+
+QWindowsApplication::TouchWindowTouchTypes QWindowsApplication::touchWindowTouchType() const
+{
+ return m_touchWindowTouchTypes;
+}
+
QWindowsApplication::WindowActivationBehavior QWindowsApplication::windowActivationBehavior() const
{
return m_windowActivationBehavior;
diff --git a/src/plugins/platforms/windows/qwindowsapplication.h b/src/plugins/platforms/windows/qwindowsapplication.h
index e68de31880..309fc7151f 100644
--- a/src/plugins/platforms/windows/qwindowsapplication.h
+++ b/src/plugins/platforms/windows/qwindowsapplication.h
@@ -47,6 +47,9 @@ QT_BEGIN_NAMESPACE
class QWindowsApplication : public QPlatformInterface::Private::QWindowsApplication
{
public:
+ void setTouchWindowTouchType(TouchWindowTouchTypes type) override;
+ TouchWindowTouchTypes touchWindowTouchType() const override;
+
WindowActivationBehavior windowActivationBehavior() const override;
void setWindowActivationBehavior(WindowActivationBehavior behavior) override;
@@ -57,6 +60,7 @@ public:
private:
WindowActivationBehavior m_windowActivationBehavior = DefaultActivateWindow;
+ TouchWindowTouchTypes m_touchWindowTouchTypes = NormalTouch;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp
index b1658d4d8e..39278f31e8 100644
--- a/src/plugins/platforms/windows/qwindowscontext.cpp
+++ b/src/plugins/platforms/windows/qwindowscontext.cpp
@@ -366,12 +366,18 @@ bool QWindowsContext::initTouch(unsigned integrationOptions)
d->m_systemInfo |= QWindowsContext::SI_SupportsTouch;
// A touch device was plugged while the app is running. Register all windows for touch.
- if (QGuiApplicationPrivate::is_app_running) {
+ registerTouchWindows();
+
+ return true;
+}
+
+void QWindowsContext::registerTouchWindows()
+{
+ if (QGuiApplicationPrivate::is_app_running
+ && (d->m_systemInfo & QWindowsContext::SI_SupportsTouch) != 0) {
for (QWindowsWindow *w : qAsConst(d->m_windows))
w->registerTouchWindow();
}
-
- return true;
}
bool QWindowsContext::initTablet()
diff --git a/src/plugins/platforms/windows/qwindowscontext.h b/src/plugins/platforms/windows/qwindowscontext.h
index a825bfbfe5..0cc5f0f595 100644
--- a/src/plugins/platforms/windows/qwindowscontext.h
+++ b/src/plugins/platforms/windows/qwindowscontext.h
@@ -173,6 +173,7 @@ public:
bool initTouch();
bool initTouch(unsigned integrationOptions); // For calls from QWindowsIntegration::QWindowsIntegration() only.
+ void registerTouchWindows();
bool initTablet();
bool initPointer(unsigned integrationOptions);
bool disposeTablet();
diff --git a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp
index 7d5b9b218b..8483da7aff 100644
--- a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp
+++ b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp
@@ -258,8 +258,6 @@ QFont QWindowsNativeInterface::logFontToQFont(const void *logFont, int verticalD
QFunctionPointer QWindowsNativeInterface::platformFunction(const QByteArray &function) const
{
- if (function == QWindowsWindowFunctions::setTouchWindowTouchTypeIdentifier())
- return QFunctionPointer(QWindowsWindow::setTouchWindowTouchTypeStatic);
if (function == QWindowsWindowFunctions::setHasBorderInFullScreenIdentifier())
return QFunctionPointer(QWindowsWindow::setHasBorderInFullScreenStatic);
if (function == QWindowsWindowFunctions::setHasBorderInFullScreenDefaultIdentifier())
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()
diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h
index 8d47b5b4f3..27c225f626 100644
--- a/src/plugins/platforms/windows/qwindowswindow.h
+++ b/src/plugins/platforms/windows/qwindowswindow.h
@@ -42,6 +42,7 @@
#include <QtCore/qt_windows.h>
#include <QtCore/qpointer.h>
+#include "qwindowsapplication.h"
#include "qwindowscursor.h"
#include <qpa/qplatformwindow.h>
@@ -51,6 +52,8 @@
#include "qwindowsvulkaninstance.h"
#endif
+#include <optional>
+
QT_BEGIN_NAMESPACE
class QWindowsOleDropTarget;
@@ -125,6 +128,9 @@ class QWindowsBaseWindow : public QPlatformWindow
{
Q_DISABLE_COPY_MOVE(QWindowsBaseWindow)
public:
+ using TouchWindowTouchType = QPlatformInterface::Private::QWindowsApplication::TouchWindowTouchType;
+ using TouchWindowTouchTypes = QPlatformInterface::Private::QWindowsApplication::TouchWindowTouchTypes;
+
explicit QWindowsBaseWindow(QWindow *window) : QPlatformWindow(window) {}
WId winId() const override { return WId(handle()); }
@@ -153,6 +159,7 @@ protected:
QRect geometry_sys() const;
void setGeometry_sys(const QRect &rect) const;
QMargins frameMargins_sys() const;
+ std::optional<TouchWindowTouchTypes> touchWindowTouchTypes_sys() const;
void hide_sys();
void raise_sys();
void lower_sys();
@@ -348,8 +355,7 @@ public:
enum ScreenChangeMode { FromGeometryChange, FromDpiChange };
void checkForScreenChanged(ScreenChangeMode mode = FromGeometryChange);
- static void setTouchWindowTouchTypeStatic(QWindow *window, QWindowsWindowFunctions::TouchWindowTouchTypes touchTypes);
- void registerTouchWindow(QWindowsWindowFunctions::TouchWindowTouchTypes touchTypes = QWindowsWindowFunctions::NormalTouch);
+ void registerTouchWindow();
static void setHasBorderInFullScreenStatic(QWindow *window, bool border);
static void setHasBorderInFullScreenDefault(bool border);
void setHasBorderInFullScreen(bool border);