summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-04-14 16:27:33 +0200
committerPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-04-14 16:27:33 +0200
commit56b72d7809a6016149668b7df0dfd35022ff01c6 (patch)
tree06aaf93c55ce6f3185f70e1d5f9aa68372d2d807 /src
parent04e4feae6c2fc0074839c490c81977ade20011c9 (diff)
Per-screen scaleFactor
To enable, set QT_SCALE_FACTOR=auto Tons of bugs, since this does not port all the QT_DEVICE_PIXEL_RATIO fixes from xcb.
Diffstat (limited to 'src')
-rw-r--r--src/gui/kernel/qhighdpiscaling.cpp16
-rw-r--r--src/gui/kernel/qhighdpiscaling_p.h4
-rw-r--r--src/gui/kernel/qplatformscreen.cpp16
-rw-r--r--src/gui/kernel/qplatformscreen.h1
-rw-r--r--src/gui/kernel/qscreen.cpp2
-rw-r--r--src/plugins/platforms/xcb/qxcbscreen.cpp13
-rw-r--r--src/plugins/platforms/xcb/qxcbscreen.h3
7 files changed, 43 insertions, 12 deletions
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp
index eeeb995d43..0d847a243f 100644
--- a/src/gui/kernel/qhighdpiscaling.cpp
+++ b/src/gui/kernel/qhighdpiscaling.cpp
@@ -77,6 +77,7 @@ static inline qreal initialScaleFactor()
*/
qreal QHighDpiScaling::m_factor = initialScaleFactor();
+bool QHighDpiScaling::m_autoFactor = qgetenv("QT_SCALE_FACTOR").toLower() == "auto";
bool QHighDpiScaling::m_active = !qFuzzyCompare(QHighDpiScaling::m_factor, qreal(1));
bool QHighDpiScaling::m_perWindowActive = false;
@@ -103,13 +104,24 @@ void QHighDpiScaling::setWindowFactor(QWindow *window, qreal factor)
window->setProperty(scaleFactorProperty, QVariant(factor));
}
+qreal QHighDpiScaling::factor(const QScreen *screen)
+{
+ if (m_autoFactor && screen && screen->handle())
+ return screen->handle()->pixelDensity();
+ return m_factor;
+}
+
+
qreal QHighDpiScaling::factor(const QWindow *window)
{
+ qreal f = m_factor;
+ if (m_autoFactor && window && window->screen() && window->screen()->handle())
+ f = window->screen()->handle()->pixelDensity();
if (!m_perWindowActive || window == 0)
- return m_factor;
+ return f;
QVariant windowFactor = window->property(scaleFactorProperty);
- return m_factor * (windowFactor.isValid() ? windowFactor.toReal() : 1);
+ return f * (windowFactor.isValid() ? windowFactor.toReal() : 1);
}
Q_GUI_EXPORT QSize QHighDpi::toDevicePixelsConstrained(const QSize &size, const QWindow *window)
diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h
index 6929b3ac83..5827bc1565 100644
--- a/src/gui/kernel/qhighdpiscaling_p.h
+++ b/src/gui/kernel/qhighdpiscaling_p.h
@@ -79,11 +79,13 @@ Q_DECLARE_LOGGING_CATEGORY(lcScaling);
class Q_GUI_EXPORT QHighDpiScaling {
public:
static bool isActive() { return m_active; }
- static qreal factor(const QWindow *window = 0);
+ static qreal factor(const QWindow *window);
+ static qreal factor(const QScreen *screen);
static void setFactor(qreal factor);
static void setWindowFactor(QWindow *window, qreal factor);
private:
static qreal m_factor;
+ static bool m_autoFactor;
static bool m_active;
static bool m_perWindowActive;
};
diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp
index e2c84fbc2c..6088e6495e 100644
--- a/src/gui/kernel/qplatformscreen.cpp
+++ b/src/gui/kernel/qplatformscreen.cpp
@@ -157,9 +157,9 @@ QDpi QPlatformScreen::logicalDpi() const
}
/*!
- Reimplement this function in subclass to return the device pixel
- ratio for the screen. This is the ratio between physical pixels
- and device-independent pixels.
+ Reimplement this function in subclass to return the device pixel ratio
+ for the screen. This is the ratio between physical pixels and the
+ device-independent pixels of the windowing system.
\sa QPlatformWindow::devicePixelRatio();
*/
@@ -169,6 +169,16 @@ qreal QPlatformScreen::devicePixelRatio() const
}
/*!
+ Reimplement this function in subclass to return the pixel density of the
+ screen. This is the scale factor needed to make a low-dpi application
+ usable on this screen. The default implementation returns 1.0.
+*/
+qreal QPlatformScreen::pixelDensity() const
+{
+ return 1.0;
+}
+
+/*!
Reimplement this function in subclass to return the vertical refresh rate
of the screen, in Hz.
diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h
index ad1cb6f9b3..8dceef26eb 100644
--- a/src/gui/kernel/qplatformscreen.h
+++ b/src/gui/kernel/qplatformscreen.h
@@ -96,6 +96,7 @@ public:
virtual QSizeF physicalSize() const;
virtual QDpi logicalDpi() const;
virtual qreal devicePixelRatio() const;
+ virtual qreal pixelDensity() const;
virtual qreal refreshRate() const;
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp
index 684b298631..91cef9640b 100644
--- a/src/gui/kernel/qscreen.cpp
+++ b/src/gui/kernel/qscreen.cpp
@@ -259,7 +259,7 @@ qreal QScreen::logicalDotsPerInch() const
qreal QScreen::devicePixelRatio() const
{
Q_D(const QScreen);
- return d->platformScreen->devicePixelRatio() * QHighDpiScaling::factor();
+ return d->platformScreen->devicePixelRatio() * QHighDpiScaling::factor(this);
}
/*!
diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp
index baa4eb06fd..1e42359fd9 100644
--- a/src/plugins/platforms/xcb/qxcbscreen.cpp
+++ b/src/plugins/platforms/xcb/qxcbscreen.cpp
@@ -66,7 +66,7 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *scr,
, m_number(number)
, m_refreshRate(60)
, m_forcedDpi(-1)
- , m_devicePixelRatio(1)
+ , m_pixelDensity(1)
, m_hintStyle(QFontEngine::HintStyle(-1))
, m_noFontHinting(false)
, m_subpixelType(QFontEngine::SubpixelAntialiasingType(-1))
@@ -331,10 +331,15 @@ qreal QXcbScreen::devicePixelRatio() const
if (override_dpr > 0)
return override_dpr;
if (auto_dpr)
- return m_devicePixelRatio;
+ return m_pixelDensity;
return 1.0;
}
+qreal QXcbScreen::pixelDensity() const
+{
+ return m_pixelDensity;
+}
+
QPlatformCursor *QXcbScreen::cursor() const
{
return m_cursor;
@@ -478,8 +483,8 @@ void QXcbScreen::updateGeometry(const QRect &geom, uint8_t rotation)
free(workArea);
qreal dpi = xGeometry.width() / physicalSize().width() * qreal(25.4);
- m_devicePixelRatio = qRound(dpi/96);
- const int dpr = int(devicePixelRatio()); // we may override m_devicePixelRatio
+ m_pixelDensity = qRound(dpi/96);
+ const int dpr = int(devicePixelRatio());
m_geometry = QRect(xGeometry.topLeft()/dpr, xGeometry.size()/dpr);
m_nativeGeometry = QRect(xGeometry.topLeft(), xGeometry.size());
m_availableGeometry = QRect(xAvailableGeometry.topLeft()/dpr, xAvailableGeometry.size()/dpr);
diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h
index 3f228465f2..b67816ab79 100644
--- a/src/plugins/platforms/xcb/qxcbscreen.h
+++ b/src/plugins/platforms/xcb/qxcbscreen.h
@@ -76,6 +76,7 @@ public:
QSizeF physicalVirtualSize() const { return m_virtualSizeMillimeters; }
QDpi logicalDpi() const Q_DECL_OVERRIDE;
qreal devicePixelRatio() const Q_DECL_OVERRIDE;
+ qreal pixelDensity() const Q_DECL_OVERRIDE;
QPlatformCursor *cursor() const Q_DECL_OVERRIDE;
qreal refreshRate() const Q_DECL_OVERRIDE { return m_refreshRate; }
Qt::ScreenOrientation orientation() const Q_DECL_OVERRIDE { return m_orientation; }
@@ -152,7 +153,7 @@ private:
QXcbCursor *m_cursor;
int m_refreshRate;
int m_forcedDpi;
- int m_devicePixelRatio;
+ int m_pixelDensity;
QFontEngine::HintStyle m_hintStyle;
bool m_noFontHinting;
QFontEngine::SubpixelAntialiasingType m_subpixelType;