From 77e04acb4e0266d7da2f9e7100ec22836d9889d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 8 Jun 2020 22:38:15 +0200 Subject: [PATCH] X11: restrict fallback logical DPI to 96 and higher MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QXcbScreen determines logical DPI using the following priority: 1) use Xft.dpi if set 2) virtual desktop size / virtual desktop physical size (This change does not restrict or alter the value obtained from Xft.dpi in any way) The fallback option 2) has several problems: - It is a physical DPI, which does not account for viewing distance or user preference - It is a global value for the entire virtual desktop (not per-screen) - X servers usually fake the virtual desktop physical size such that the computed DPI ends up at 96; in cases where this does not happen we can end up with a surprising DPI value. We might be better off just hardcoding 96 here, to avoid picking up an incorrect physical DPI when for example connecting to a TV (as reported in QTBUG-67928). This change does not go as far as hardcoding 96, but instead restricts the (fallback) DPI value to be 96 or higher. Pick-to: 5.15 Task-number: QTBUG-67928 Change-Id: Ieea6c7a137261282b40302fb4c19273c5def10af Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/xcb/qxcbscreen.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index 4d3f269cf4f..6ce8a91f36a 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -698,7 +698,12 @@ QDpi QXcbScreen::logicalDpi() const if (forcedDpi > 0) return QDpi(forcedDpi, forcedDpi); - return m_virtualDesktop->dpi(); + // Fall back to physical virtual desktop DPI, but prevent + // using DPI values lower than 96. This ensuers that connecting + // to e.g. a TV works somewhat predictabilly. + QDpi virtualDesktopPhysicalDPi = m_virtualDesktop->dpi(); + return QDpi(std::max(virtualDesktopPhysicalDPi.first, 96.0), + std::max(virtualDesktopPhysicalDPi.second, 96.0)); } QPlatformCursor *QXcbScreen::cursor() const