From 567e7f1518b14ab8568377522df0396ebaa5c1e0 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 12 Apr 2021 13:14:52 +0400 Subject: Read DPI from X Settings initially as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, Xft.dpi from X Resources is read initially, while changes are monitored for Xft/DPI from X Settings. These protocols are different and can have different values. E.g. MATE sets X Resources' Xft.dpi to 96.30859375, while X Settings' Xft/DPI is set to 197240 at 2x scale. This results in a very weird bug when Qt can't determine 2x scale initially, but if scale is changed at run time, Qt changes scale to the right value. The difference could be checked via xrdb -query and dump_xsettings (the second is from xsettingsd project). [ChangeLog] Qt now reads Xft/DPI from X settings at startup, and will prefer this value over Xft.dpi from X resources. Change-Id: If6adac0c88198579332ddebc673f1524f324c0e4 Reviewed-by: Morten Johan Sørvig (cherry picked from commit 6560778616b090f8cc73700675ec2ef385953fb6) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/xcb/qxcbscreen.cpp | 23 ++++++++++++++++------- src/plugins/platforms/xcb/qxcbscreen.h | 2 ++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index e1fa4d8416..2e4fc16998 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -114,17 +114,13 @@ QXcbVirtualDesktop::QXcbVirtualDesktop(QXcbConnection *connection, xcb_screen_t } auto dpiChangedCallback = [](QXcbVirtualDesktop *desktop, const QByteArray &, const QVariant &property, void *) { - bool ok; - int dpiTimes1k = property.toInt(&ok); - if (!ok) + if (!desktop->setDpiFromXSettings(property)) return; - int dpi = dpiTimes1k / 1024; - if (desktop->m_forcedDpi == dpi) - return; - desktop->m_forcedDpi = dpi; + const auto dpi = desktop->forcedDpi(); for (QXcbScreen *screen : desktop->connection()->screens()) QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(screen->QPlatformScreen::screen(), dpi, dpi); }; + setDpiFromXSettings(xSettings()->setting("Xft/DPI")); xSettings()->registerCallbackForProperty("Xft/DPI", dpiChangedCallback, nullptr); } @@ -425,6 +421,19 @@ void QXcbVirtualDesktop::readXResources() } } +bool QXcbVirtualDesktop::setDpiFromXSettings(const QVariant &property) +{ + bool ok; + int dpiTimes1k = property.toInt(&ok); + if (!ok) + return false; + int dpi = dpiTimes1k / 1024; + if (m_forcedDpi == dpi) + return false; + m_forcedDpi = dpi; + return true; +} + QSurfaceFormat QXcbVirtualDesktop::surfaceFormatFor(const QSurfaceFormat &format) const { const xcb_visualid_t xcb_visualid = connection()->hasDefaultVisualId() ? connection()->defaultVisualId() diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h index aabf227a09..02b1868331 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.h +++ b/src/plugins/platforms/xcb/qxcbscreen.h @@ -117,6 +117,8 @@ private: QByteArray &stringValue); void readXResources(); + bool setDpiFromXSettings(const QVariant &property); + xcb_screen_t *m_screen; const int m_number; QList m_screens; -- cgit v1.2.3