summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/kernel/qguiapplication_p.h15
-rw-r--r--src/platformheaders/windowsfunctions/qwindowswindowfunctions.qdoc30
-rw-r--r--src/platformheaders/windowsfunctions/qwindowswindowfunctions_p.h20
-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
10 files changed, 87 insertions, 75 deletions
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index b79dbd317f..8080d7801d 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -382,6 +382,17 @@ struct Q_GUI_EXPORT QWindowsApplication
AlwaysActivateWindow
};
+ enum TouchWindowTouchType {
+ NormalTouch = 0x00000000,
+ FineTouch = 0x00000001,
+ WantPalmTouch = 0x00000002
+ };
+
+ Q_DECLARE_FLAGS(TouchWindowTouchTypes, TouchWindowTouchType)
+
+ virtual void setTouchWindowTouchType(TouchWindowTouchTypes type) = 0;
+ virtual TouchWindowTouchTypes touchWindowTouchType() const = 0;
+
virtual WindowActivationBehavior windowActivationBehavior() const = 0;
virtual void setWindowActivationBehavior(WindowActivationBehavior behavior) = 0;
@@ -394,6 +405,10 @@ struct Q_GUI_EXPORT QWindowsApplication
} // QPlatformInterface::Private
+#if defined(Q_OS_WIN)
+Q_DECLARE_OPERATORS_FOR_FLAGS(QPlatformInterface::Private::QWindowsApplication::TouchWindowTouchTypes)
+#endif
+
QT_END_NAMESPACE
#endif // QGUIAPPLICATION_P_H
diff --git a/src/platformheaders/windowsfunctions/qwindowswindowfunctions.qdoc b/src/platformheaders/windowsfunctions/qwindowswindowfunctions.qdoc
index b848df2d09..f211165936 100644
--- a/src/platformheaders/windowsfunctions/qwindowswindowfunctions.qdoc
+++ b/src/platformheaders/windowsfunctions/qwindowswindowfunctions.qdoc
@@ -42,36 +42,6 @@
*/
/*!
- \enum QWindowsWindowFunctions::TouchWindowTouchType
-
- This enum represents the supported TouchWindow touch flags for RegisterTouchWindow().
-
- \value NormalTouch
- \value FineTouch
- \value WantPalmTouch
-*/
-
-/*!
- \typedef QWindowsWindowFunctions::SetTouchWindowTouchType
-
- This is the typedef for the function returned by QGuiApplication::platformFunction when passed setTouchWindowTouchTypeIdentifier.
-*/
-
-/*!
- \fn QByteArray QWindowsWindowFunctions::setTouchWindowTouchTypeIdentifier()
-
- This function returns the bytearray that can be used to query
- QGuiApplication::platformFunction to retrieve the SetTouchWindowTouchType function.
-*/
-
-/*!
- \fn void QWindowsWindowFunctions::setTouchWindowTouchType(QWindow *window, TouchWindowTouchTypes type)
-
- This is a convenience function that can be used directly instead of resolving the function pointer.
- \a window and \a type will be relayed to the function retrieved by QGuiApplication
-*/
-
-/*!
\typedef QWindowsWindowFunctions::SetHasBorderInFullScreen
This is the typedef for the function returned by QGuiApplication::platformFunction when passed setHasBorderInFullScreenIdentifier.
diff --git a/src/platformheaders/windowsfunctions/qwindowswindowfunctions_p.h b/src/platformheaders/windowsfunctions/qwindowswindowfunctions_p.h
index 6b06b40084..780be22a05 100644
--- a/src/platformheaders/windowsfunctions/qwindowswindowfunctions_p.h
+++ b/src/platformheaders/windowsfunctions/qwindowswindowfunctions_p.h
@@ -60,24 +60,6 @@ class QWindow;
class QWindowsWindowFunctions {
public:
- enum TouchWindowTouchType {
- NormalTouch = 0x00000000,
- FineTouch = 0x00000001,
- WantPalmTouch = 0x00000002
- };
-
- Q_DECLARE_FLAGS(TouchWindowTouchTypes, TouchWindowTouchType)
-
- typedef void (*SetTouchWindowTouchType)(QWindow *window, QWindowsWindowFunctions::TouchWindowTouchTypes touchType);
- static const QByteArray setTouchWindowTouchTypeIdentifier() { return QByteArrayLiteral("WindowsSetTouchWindowTouchType"); }
-
- static void setTouchWindowTouchType(QWindow *window, TouchWindowTouchTypes type)
- {
- SetTouchWindowTouchType func = reinterpret_cast<SetTouchWindowTouchType>(QGuiApplication::platformFunction(setTouchWindowTouchTypeIdentifier()));
- if (func)
- func(window, type);
- }
-
typedef void (*SetHasBorderInFullScreen)(QWindow *window, bool border);
static const QByteArray setHasBorderInFullScreenIdentifier() { return QByteArrayLiteral("WindowsSetHasBorderInFullScreen"); }
static void setHasBorderInFullScreen(QWindow *window, bool border)
@@ -98,8 +80,6 @@ public:
};
-Q_DECLARE_OPERATORS_FOR_FLAGS(QWindowsWindowFunctions::TouchWindowTouchTypes)
-
QT_END_NAMESPACE
#endif // QWINDOWSWINDOWFUNCTIONS_H
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);