diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-20 13:09:42 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-21 14:14:50 +0200 |
commit | 8e48184120f74c02447c8d96408c1c003cd7fd79 (patch) | |
tree | 497028e8f49aa8d2dfe8ecdfd4003eff3d538871 /src/plugins | |
parent | beab436d77476c93d50d8608c15b369044937d7f (diff) |
Start the native interface QWindowsApplication
Implement the static parts of QWindowsWindowFunctions.
Move some things around and make them static in tablet support
to make this easier.
Task-number: QTBUG-83252
Change-Id: I24c3b0b3c6548eb96c4f3285a4e46385a1e79ef5
Reviewed-by: André de la Rocha <andre.rocha@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins')
14 files changed, 172 insertions, 71 deletions
diff --git a/src/plugins/platforms/windows/.prev_CMakeLists.txt b/src/plugins/platforms/windows/.prev_CMakeLists.txt index ada50698cd..d2df21f951 100644 --- a/src/plugins/platforms/windows/.prev_CMakeLists.txt +++ b/src/plugins/platforms/windows/.prev_CMakeLists.txt @@ -11,6 +11,7 @@ qt_internal_add_plugin(QWindowsIntegrationPlugin main.cpp qtwindowsglobal.h qwin10helpers.cpp qwin10helpers.h + qwindowsapplication.cpp qwindowsapplication.h qwindowsbackingstore.cpp qwindowsbackingstore.h qwindowscombase.h qwindowscontext.cpp qwindowscontext.h diff --git a/src/plugins/platforms/windows/CMakeLists.txt b/src/plugins/platforms/windows/CMakeLists.txt index f0aa2a1980..094717a8f8 100644 --- a/src/plugins/platforms/windows/CMakeLists.txt +++ b/src/plugins/platforms/windows/CMakeLists.txt @@ -12,6 +12,7 @@ qt_internal_add_plugin(QWindowsIntegrationPlugin main.cpp qtwindowsglobal.h qwin10helpers.cpp qwin10helpers.h + qwindowsapplication.cpp qwindowsapplication.h qwindowsbackingstore.cpp qwindowsbackingstore.h qwindowscombase.h qwindowscontext.cpp qwindowscontext.h diff --git a/src/plugins/platforms/windows/qwindowsapplication.cpp b/src/plugins/platforms/windows/qwindowsapplication.cpp new file mode 100644 index 0000000000..a27da7bac8 --- /dev/null +++ b/src/plugins/platforms/windows/qwindowsapplication.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwindowsapplication.h" +#include "qwindowsclipboard.h" +#include "qwindowscontext.h" +#include "qwin10helpers.h" + + +QT_BEGIN_NAMESPACE + +QWindowsApplication::WindowActivationBehavior QWindowsApplication::windowActivationBehavior() const +{ + return m_windowActivationBehavior; +} + +void QWindowsApplication::setWindowActivationBehavior(WindowActivationBehavior behavior) +{ + m_windowActivationBehavior = behavior; +} + +bool QWindowsApplication::isTabletMode() const +{ +#if QT_CONFIG(clipboard) + if (const QWindowsClipboard *clipboard = QWindowsClipboard::instance()) + return qt_windowsIsTabletMode(clipboard->clipboardViewer()); +#endif + return false; +} + +bool QWindowsApplication::isWinTabEnabled() const +{ + auto ctx = QWindowsContext::instance(); + return ctx != nullptr && ctx->tabletSupport() != nullptr; +} + +bool QWindowsApplication::setWinTabEnabled(bool enabled) +{ + if (enabled == isWinTabEnabled()) + return true; + auto ctx = QWindowsContext::instance(); + if (!ctx) + return false; + return enabled ? ctx->initTablet() : ctx->disposeTablet(); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowsapplication.h b/src/plugins/platforms/windows/qwindowsapplication.h new file mode 100644 index 0000000000..e68de31880 --- /dev/null +++ b/src/plugins/platforms/windows/qwindowsapplication.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWINDOWSAPPLICATION_H +#define QWINDOWSAPPLICATION_H + +#include <QtGui/private/qguiapplication_p.h> + +QT_BEGIN_NAMESPACE + +class QWindowsApplication : public QPlatformInterface::Private::QWindowsApplication +{ +public: + WindowActivationBehavior windowActivationBehavior() const override; + void setWindowActivationBehavior(WindowActivationBehavior behavior) override; + + bool isTabletMode() const override; + + bool isWinTabEnabled() const override; + bool setWinTabEnabled(bool enabled) override; + +private: + WindowActivationBehavior m_windowActivationBehavior = DefaultActivateWindow; +}; + +QT_END_NAMESPACE + +#endif // QWINDOWSAPPLICATION_H diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 6744f917a4..b1658d4d8e 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -374,9 +374,8 @@ bool QWindowsContext::initTouch(unsigned integrationOptions) return true; } -bool QWindowsContext::initTablet(unsigned integrationOptions) +bool QWindowsContext::initTablet() { - Q_UNUSED(integrationOptions); #if QT_CONFIG(tabletevent) d->m_tabletSupport.reset(QWindowsTabletSupport::create()); return true; @@ -462,8 +461,7 @@ bool QWindowsContext::initPowerNotificationHandler() void QWindowsContext::setTabletAbsoluteRange(int a) { #if QT_CONFIG(tabletevent) - if (!d->m_tabletSupport.isNull()) - d->m_tabletSupport->setAbsoluteRange(a); + QWindowsTabletSupport::setAbsoluteRange(a); #else Q_UNUSED(a); #endif diff --git a/src/plugins/platforms/windows/qwindowscontext.h b/src/plugins/platforms/windows/qwindowscontext.h index 1e1edba000..a825bfbfe5 100644 --- a/src/plugins/platforms/windows/qwindowscontext.h +++ b/src/plugins/platforms/windows/qwindowscontext.h @@ -173,7 +173,7 @@ public: bool initTouch(); bool initTouch(unsigned integrationOptions); // For calls from QWindowsIntegration::QWindowsIntegration() only. - bool initTablet(unsigned integrationOptions); + bool initTablet(); bool initPointer(unsigned integrationOptions); bool disposeTablet(); @@ -223,7 +223,7 @@ public: QSharedPointer<QWindowCreationContext> setWindowCreationContext(const QSharedPointer<QWindowCreationContext> &ctx); QSharedPointer<QWindowCreationContext> windowCreationContext() const; - void setTabletAbsoluteRange(int a); + static void setTabletAbsoluteRange(int a); void setProcessDpiAwareness(QtWindows::ProcessDpiAwareness dpiAwareness); static int processDpiAwareness(); diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp index ea077bc695..aeafff9962 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsintegration.cpp @@ -139,7 +139,6 @@ struct QWindowsIntegrationPrivate ~QWindowsIntegrationPrivate(); unsigned m_options = 0; - int m_tabletAbsoluteRange = -1; QWindowsContext m_context; QPlatformFontDatabase *m_fontDatabase = nullptr; #if QT_CONFIG(clipboard) @@ -242,16 +241,16 @@ QWindowsIntegrationPrivate::QWindowsIntegrationPrivate(const QStringList ¶mL // Default to per-monitor awareness to avoid being scaled when monitors with different DPI // are connected to Windows 8.1 QtWindows::ProcessDpiAwareness dpiAwareness = QtWindows::ProcessPerMonitorDpiAware; - m_options = parseOptions(paramList, &m_tabletAbsoluteRange, &dpiAwareness); + int tabletAbsoluteRange = -1; + m_options = parseOptions(paramList, &tabletAbsoluteRange, &dpiAwareness); QWindowsFontDatabase::setFontOptions(m_options); + if (tabletAbsoluteRange >= 0) + QWindowsContext::setTabletAbsoluteRange(tabletAbsoluteRange); - if (m_context.initPointer(m_options)) { + if (m_context.initPointer(m_options)) QCoreApplication::setAttribute(Qt::AA_CompressHighFrequencyEvents); - } else { - m_context.initTablet(m_options); - if (m_tabletAbsoluteRange >= 0) - m_context.setTabletAbsoluteRange(m_tabletAbsoluteRange); - } + else + m_context.initTablet(); if (!dpiAwarenessSet) { // Set only once in case of repeated instantiations of QGuiApplication. if (!QCoreApplication::testAttribute(Qt::AA_PluginApplication)) { @@ -650,28 +649,6 @@ void QWindowsIntegration::beep() const MessageBeep(MB_OK); // For QApplication } -bool QWindowsIntegration::setWinTabEnabled(bool enabled) -{ - bool ret = false; - if (QWindowsIntegration *p = QWindowsIntegration::instance()) { - if (enabled) { - if (p->d->m_context.tabletSupport()) { - ret = true; - } else { - ret = p->d->m_context.initTablet(p->d->m_options); - if (ret && p->d->m_tabletAbsoluteRange >= 0) - p->d->m_context.setTabletAbsoluteRange(p->d->m_tabletAbsoluteRange); - } - } else { - if (p->d->m_context.tabletSupport()) - ret = p->d->m_context.disposeTablet(); - else - ret = true; - } - } - return ret; -} - #if QT_CONFIG(vulkan) QPlatformVulkanInstance *QWindowsIntegration::createPlatformVulkanInstance(QVulkanInstance *instance) const { diff --git a/src/plugins/platforms/windows/qwindowsintegration.h b/src/plugins/platforms/windows/qwindowsintegration.h index 207e018ca8..3a8c09dd43 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.h +++ b/src/plugins/platforms/windows/qwindowsintegration.h @@ -41,6 +41,8 @@ #ifndef QWINDOWSINTEGRATION_H #define QWINDOWSINTEGRATION_H +#include "qwindowsapplication.h" + #include <qpa/qplatformintegration.h> #include <QtCore/qscopedpointer.h> #include <QtGui/private/qwindowsfontdatabase_p.h> @@ -58,6 +60,7 @@ class QWindowsIntegration : public QPlatformIntegration #ifndef QT_NO_OPENGL , public QPlatformInterface::Private::QWindowsGLIntegration #endif + , public QWindowsApplication { Q_DISABLE_COPY_MOVE(QWindowsIntegration) public: @@ -119,8 +122,6 @@ public: static QWindowsIntegration *instance() { return m_instance; } - static bool setWinTabEnabled(bool enabled); - unsigned options() const; void beep() const override; diff --git a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp index fdc1268794..7d5b9b218b 100644 --- a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp +++ b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp @@ -38,7 +38,6 @@ ****************************************************************************/ #include "qwindowsnativeinterface.h" -#include "qwindowsclipboard.h" #include "qwindowswindow.h" #include "qwindowsscreen.h" #include "qwindowscontext.h" @@ -84,9 +83,6 @@ static int resourceType(const QByteArray &key) return int(result - names); } -QWindowsWindowFunctions::WindowActivationBehavior QWindowsNativeInterface::m_windowActivationBehavior = - QWindowsWindowFunctions::DefaultActivateWindow; - void *QWindowsNativeInterface::nativeResourceForWindow(const QByteArray &resource, QWindow *window) { if (!window || !window->handle()) { @@ -260,15 +256,6 @@ QFont QWindowsNativeInterface::logFontToQFont(const void *logFont, int verticalD return QWindowsFontDatabase::LOGFONT_to_QFont(*reinterpret_cast<const LOGFONT *>(logFont), verticalDpi); } -bool QWindowsNativeInterface::isTabletMode() -{ -#if QT_CONFIG(clipboard) - if (const QWindowsClipboard *clipboard = QWindowsClipboard::instance()) - return qt_windowsIsTabletMode(clipboard->clipboardViewer()); -#endif - return false; -} - QFunctionPointer QWindowsNativeInterface::platformFunction(const QByteArray &function) const { if (function == QWindowsWindowFunctions::setTouchWindowTouchTypeIdentifier()) @@ -277,12 +264,6 @@ QFunctionPointer QWindowsNativeInterface::platformFunction(const QByteArray &fun return QFunctionPointer(QWindowsWindow::setHasBorderInFullScreenStatic); if (function == QWindowsWindowFunctions::setHasBorderInFullScreenDefaultIdentifier()) return QFunctionPointer(QWindowsWindow::setHasBorderInFullScreenDefault); - if (function == QWindowsWindowFunctions::setWindowActivationBehaviorIdentifier()) - return QFunctionPointer(QWindowsNativeInterface::setWindowActivationBehavior); - if (function == QWindowsWindowFunctions::isTabletModeIdentifier()) - return QFunctionPointer(QWindowsNativeInterface::isTabletMode); - if (function == QWindowsWindowFunctions::setWinTabEnabledIdentifier()) - return QFunctionPointer(QWindowsIntegration::setWinTabEnabled); return nullptr; } diff --git a/src/plugins/platforms/windows/qwindowsnativeinterface.h b/src/plugins/platforms/windows/qwindowsnativeinterface.h index 393e1f1c99..cfb14ae794 100644 --- a/src/plugins/platforms/windows/qwindowsnativeinterface.h +++ b/src/plugins/platforms/windows/qwindowsnativeinterface.h @@ -104,20 +104,10 @@ public: QVariant windowProperty(QPlatformWindow *window, const QString &name, const QVariant &defaultValue) const override; void setWindowProperty(QPlatformWindow *window, const QString &name, const QVariant &value) override; - static QWindowsWindowFunctions::WindowActivationBehavior windowActivationBehavior() - { return QWindowsNativeInterface::m_windowActivationBehavior; } - static void setWindowActivationBehavior(QWindowsWindowFunctions::WindowActivationBehavior b) - { QWindowsNativeInterface::m_windowActivationBehavior = b; } - - static bool isTabletMode(); - QFunctionPointer platformFunction(const QByteArray &function) const override; Q_SIGNALS: void darkModeChanged(bool); - -private: - static QWindowsWindowFunctions::WindowActivationBehavior m_windowActivationBehavior; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowstabletsupport.cpp b/src/plugins/platforms/windows/qwindowstabletsupport.cpp index 7b8ba35065..f86dbb0c5f 100644 --- a/src/plugins/platforms/windows/qwindowstabletsupport.cpp +++ b/src/plugins/platforms/windows/qwindowstabletsupport.cpp @@ -206,6 +206,8 @@ bool QWindowsWinTab32DLL::init() \since 5.2 */ +int QWindowsTabletSupport::m_absoluteRange = 20; + QWindowsTabletSupport::QWindowsTabletSupport(HWND window, HCTX context) : m_window(window) , m_context(context) diff --git a/src/plugins/platforms/windows/qwindowstabletsupport.h b/src/plugins/platforms/windows/qwindowstabletsupport.h index a47d7fb2f5..229677dae4 100644 --- a/src/plugins/platforms/windows/qwindowstabletsupport.h +++ b/src/plugins/platforms/windows/qwindowstabletsupport.h @@ -140,8 +140,8 @@ public: bool translateTabletProximityEvent(WPARAM wParam, LPARAM lParam); bool translateTabletPacketEvent(); - int absoluteRange() const { return m_absoluteRange; } - void setAbsoluteRange(int a) { m_absoluteRange = a; } + static int absoluteRange() { return m_absoluteRange; } + static void setAbsoluteRange(int a) { m_absoluteRange = a; } private: unsigned options() const; @@ -150,7 +150,7 @@ private: static QWindowsWinTab32DLL m_winTab32DLL; const HWND m_window; const HCTX m_context; - int m_absoluteRange = 20; + static int m_absoluteRange; bool m_tiltSupport = false; QList<QWindowsTabletDeviceData> m_devices; int m_currentDevice = -1; diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index ca278a4773..8df4bb3428 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2547,8 +2547,9 @@ void QWindowsWindow::requestActivateWindow() // when activating windows of inactive applications. Attach to the input of the // currently active window while setting the foreground window to always activate // the window when desired. + const auto activationBehavior = QWindowsIntegration::instance()->windowActivationBehavior(); if (QGuiApplication::applicationState() != Qt::ApplicationActive - && QWindowsNativeInterface::windowActivationBehavior() == QWindowsWindowFunctions::AlwaysActivateWindow) { + && activationBehavior == QWindowsApplication::AlwaysActivateWindow) { if (const HWND foregroundWindow = GetForegroundWindow()) { foregroundThread = GetWindowThreadProcessId(foregroundWindow, nullptr); if (foregroundThread && foregroundThread != currentThread) diff --git a/src/plugins/platforms/windows/windows.pri b/src/plugins/platforms/windows/windows.pri index b71c24068c..1cfcf314f3 100644 --- a/src/plugins/platforms/windows/windows.pri +++ b/src/plugins/platforms/windows/windows.pri @@ -19,6 +19,7 @@ QMAKE_USE_PRIVATE += \ DEFINES *= QT_NO_CAST_FROM_ASCII QT_NO_FOREACH SOURCES += \ + $$PWD/qwindowsapplication.cpp \ $$PWD/qwindowswindow.cpp \ $$PWD/qwindowsintegration.cpp \ $$PWD/qwindowscontext.cpp \ @@ -41,6 +42,7 @@ SOURCES += \ $$PWD/qwin10helpers.cpp HEADERS += \ + $$PWD/qwindowsapplication.h \ $$PWD/qwindowscombase.h \ $$PWD/qwindowswindow.h \ $$PWD/qwindowsintegration.h \ |