From 23051ff7ec4e367baef0fd1ee79e976943b443c9 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 22 Mar 2013 16:23:36 +0100 Subject: [PATCH] Clean up touch window registration. Stop processing for Qt::Desktop windows (which caused RegisterTouchWindow() to fail with access denied) and set a flag to cleanly unregister. Change-Id: I3d10c93ec92536d3ab1c0503f088c40b0c08a01f Reviewed-by: Oliver Wolff --- .../platforms/windows/qwindowswindow.cpp | 20 +++++++++++++------ .../platforms/windows/qwindowswindow.h | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 6cbe3e8cf7..9b2b67619d 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -791,13 +791,16 @@ QWindowsWindow::QWindowsWindow(QWindow *aWindow, const WindowData &data) : m_iconSmall(0), m_iconBig(0) { - if (aWindow->surfaceType() == QWindow::OpenGLSurface) - setFlag(OpenGLSurface); // Clear the creation context as the window can be found in QWindowsContext's map. QWindowsContext::instance()->setWindowCreationContext(QSharedPointer()); QWindowsContext::instance()->addWindow(m_data.hwnd, this); + const Qt::WindowType type = aWindow->type(); + if (type == Qt::Desktop) + return; // No further handling for Qt::Desktop + if (aWindow->surfaceType() == QWindow::OpenGLSurface) + setFlag(OpenGLSurface); if (aWindow->isTopLevel()) { - switch (aWindow->type()) { + switch (type) { case Qt::Window: case Qt::Dialog: case Qt::Sheet: @@ -811,8 +814,13 @@ QWindowsWindow::QWindowsWindow(QWindow *aWindow, const WindowData &data) : } } #ifndef Q_OS_WINCE - if (QWindowsContext::instance()->systemInfo() & QWindowsContext::SI_SupportsTouch) - QWindowsContext::user32dll.registerTouchWindow(m_data.hwnd, 0); + if (QWindowsContext::instance()->systemInfo() & QWindowsContext::SI_SupportsTouch) { + if (QWindowsContext::user32dll.registerTouchWindow(m_data.hwnd, 0)) { + setFlag(TouchRegistered); + } else { + qErrnoWarning("RegisterTouchWindow() failed for window '%s'.", qPrintable(aWindow->objectName())); + } + } #endif // !Q_OS_WINCE setWindowState(aWindow->windowState()); const qreal opacity = qt_window_private(aWindow)->opacity; @@ -824,7 +832,7 @@ QWindowsWindow::~QWindowsWindow() { #ifndef Q_OS_WINCE QWindowSystemInterface::flushWindowSystemEvents(); - if (QWindowsContext::instance()->systemInfo() & QWindowsContext::SI_SupportsTouch) + if (testFlag(TouchRegistered)) QWindowsContext::user32dll.unregisterTouchWindow(m_data.hwnd); #endif // !Q_OS_WINCE destroyWindow(); diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 87397f1c1d..1148440f05 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -131,7 +131,8 @@ public: FrameStrutEventsEnabled = 0x200, SynchronousGeometryChangeEvent = 0x400, WithinSetStyle = 0x800, - WithinDestroy = 0x1000 + WithinDestroy = 0x1000, + TouchRegistered = 0x2000 }; struct WindowData