From 45bb9c29e8b70cd15b01d8ab18d1df7f9707c215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 2 Oct 2015 15:56:04 +0200 Subject: Fix QHighDPiScaling initialization issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call QHighDpiScaling::updateHighDpiScaling() in init_plaform(), after the platform integration has been created and most platforms have populated the screen list. Keep the existing udpate call for the platforms that don't, but guard against calling it twice. Task-number: QTBUG-47947 Change-Id: Ib73bea7c4ab42e7acf6532f3a3100e1fc29acc2c Reviewed-by: Friedemann Kleint Reviewed-by: Laszlo Agocs Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qguiapplication.cpp | 16 +++++++++++++--- src/gui/kernel/qguiapplication_p.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 2e0595152b..216537e51a 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -129,6 +129,8 @@ QWindow *QGuiApplicationPrivate::currentMouseWindow = 0; Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive; +bool QGuiApplicationPrivate::highDpiScalingUpdated = false; + QPlatformIntegration *QGuiApplicationPrivate::platform_integration = 0; QPlatformTheme *QGuiApplicationPrivate::platform_theme = 0; @@ -1051,6 +1053,13 @@ static void init_platform(const QString &pluginArgument, const QString &platform return; } + // Many platforms have created QScreens at this point. Finish initializing + // QHighDpiScaling to be prepared for early calls to qt_defaultDpi(). + if (QGuiApplication::primaryScreen()) { + QGuiApplicationPrivate::highDpiScalingUpdated = true; + QHighDpiScaling::updateHighDpiScaling(); + } + // Create the platform theme: // 1) Fetch the platform name from the environment if present. @@ -1220,9 +1229,10 @@ void QGuiApplicationPrivate::eventDispatcherReady() platform_integration->initialize(); - // Do this here in order to play nice with platforms that add screens only - // in initialize(). - QHighDpiScaling::updateHighDpiScaling(); + // All platforms should have added screens at this point. Finish + // QHighDpiScaling initialization if it has not been done so already. + if (!QGuiApplicationPrivate::highDpiScalingUpdated) + QHighDpiScaling::updateHighDpiScaling(); } void QGuiApplicationPrivate::init() diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 0559442049..c3c5acf17c 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -202,6 +202,7 @@ public: static QWindow *currentMouseWindow; static QWindow *currentMousePressWindow; static Qt::ApplicationState applicationState; + static bool highDpiScalingUpdated; #ifndef QT_NO_CLIPBOARD static QClipboard *qt_clipboard; -- cgit v1.2.3 From 1bf639d5605863970b8dc5a91d5fc785cdf0ecf1 Mon Sep 17 00:00:00 2001 From: Samuel Nevala Date: Tue, 3 Nov 2015 08:15:33 +0200 Subject: Modify QPA handleExtendedKeyEvent. Allow setting tryShortcutOverride for handleExtendedKeyEvent with no timestamps. Change-Id: I469b144cfcaf063861debe86195e1f96ac94cc37 Reviewed-by: Andrew Knight Reviewed-by: Oliver Wolff --- src/gui/kernel/qwindowsysteminterface.cpp | 4 ++-- src/gui/kernel/qwindowsysteminterface.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index e7abff9ccc..8a46e7009b 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -261,11 +261,11 @@ bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *w, QEvent::Type typ quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString& text, bool autorep, - ushort count) + ushort count, bool tryShortcutOverride) { unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); return handleExtendedKeyEvent(w, time, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, - text, autorep, count); + text, autorep, count, tryShortcutOverride); } bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *tlw, ulong timestamp, QEvent::Type type, int key, diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h index 387c1e00b9..a27c68649e 100644 --- a/src/gui/kernel/qwindowsysteminterface.h +++ b/src/gui/kernel/qwindowsysteminterface.h @@ -88,7 +88,7 @@ public: quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString& text = QString(), bool autorep = false, - ushort count = 1); + ushort count = 1, bool tryShortcutOverride = true); static bool handleExtendedKeyEvent(QWindow *w, ulong timestamp, QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, -- cgit v1.2.3 From add58edcdbd986e68cdd65a2a935b76d85d5b639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 16 Oct 2015 12:24:38 +0200 Subject: Update high-DPI scaling enablers. Make it possible to enable and disable both at the environment variable level and at the source code level. This applies to scaling done by Qt using display density information provided by the operating system. Disabling is done with a 'veto' system: both the environment and source code my prevent the other for enabling scaling. This covers use cases of 'my system does not provide correct display metrics' and 'my application needs access to display pixels', respectively. On the environment, scaling is now enabled with QT_AUTO_SCREEN_SCALE_FACTOR=1 and disabled with QT_AUTO_SCREEN_SCALE_FACTOR=0. In source code the corresponding application attributes are AA_EnableHighDpiScaling and AA_DisapleHighDpiScaling. Not setting any of these indicates 'no preference'. The global scale factor set by QT_SCALE_FACTOR is not affected by any if the disablers. Task-number: QTBUG-46615 Change-Id: If18607d4b56ace1914a710e5aa60b2f0968e0010 Reviewed-by: Lars Knoll Reviewed-by: Paul Olav Tvete --- src/gui/kernel/qhighdpiscaling.cpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index daba9f94a1..a002b8c48d 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -49,7 +49,7 @@ static const char scaleFactorEnvVar[] = "QT_SCALE_FACTOR"; static const char autoScreenEnvVar[] = "QT_AUTO_SCREEN_SCALE_FACTOR"; static const char screenFactorsEnvVar[] = "QT_SCREEN_SCALE_FACTORS"; -static inline qreal initialScaleFactor() +static inline qreal initialGlobalScaleFactor() { qreal result = 1; @@ -134,19 +134,31 @@ QDpi QHighDpiScaling::m_logicalDpi = QDpi(-1,-1); // The scaled logical DPI of t Initializes the QHighDpiScaling global variables. Called before the platform plugin is created. */ -void QHighDpiScaling::initHighDpiScaling() + +static inline bool usePixelDensity() { - if (QCoreApplication::testAttribute(Qt::AA_NoHighDpiScaling)) { - m_factor = 1; - m_active = false; - return; - } - m_factor = initialScaleFactor(); - bool usePlatformPluginPixelDensity = qEnvironmentVariableIsSet(autoScreenEnvVar) - || qgetenv(legacyDevicePixelEnvVar).toLower() == "auto"; + // Determine if we should set a scale factor based on the pixel density + // reported by the platform plugin. There are several enablers and several + // disablers. A single disable may veto all other enablers. + if (QCoreApplication::testAttribute(Qt::AA_DisableHighDpiScaling)) + return false; + bool screenEnvValueOk; + const int screenEnvValue = qEnvironmentVariableIntValue(autoScreenEnvVar, &screenEnvValueOk); + if (screenEnvValueOk && screenEnvValue < 1) + return false; + return QCoreApplication::testAttribute(Qt::AA_EnableHighDpiScaling) + || (screenEnvValueOk && screenEnvValue > 0) + || (qEnvironmentVariableIsSet(legacyDevicePixelEnvVar) && qgetenv(legacyDevicePixelEnvVar).toLower() == "auto"); +} +void QHighDpiScaling::initHighDpiScaling() +{ + // Determine if there is a global scale factor set. + m_factor = initialGlobalScaleFactor(); m_globalScalingActive = !qFuzzyCompare(m_factor, qreal(1)); - m_usePixelDensity = usePlatformPluginPixelDensity; + + m_usePixelDensity = usePixelDensity(); + m_pixelDensityScalingActive = false; //set in updateHighDpiScaling below // we update m_active in updateHighDpiScaling, but while we create the @@ -156,7 +168,7 @@ void QHighDpiScaling::initHighDpiScaling() void QHighDpiScaling::updateHighDpiScaling() { - if (QCoreApplication::testAttribute(Qt::AA_NoHighDpiScaling)) + if (QCoreApplication::testAttribute(Qt::AA_DisableHighDpiScaling)) return; if (m_usePixelDensity && !m_pixelDensityScalingActive) { -- cgit v1.2.3