summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2012-12-18 14:05:45 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-18 14:19:38 +0100
commit3bf50a7db9a1add66fb66b7a1f9c1d3b038c5e7f (patch)
treedb8202c4c9f8905da7c5f77b8ed0b1620f381949
parente14dd5a65d1ba9cd37c8ca9924886e0b36de9911 (diff)
Fix font sizes when X11 has a forced dpi settingv5.0.0
On X11, the X resource system can override the physical DPI of the screen for resolving font sizes etc. Correctly load the setting and adjust the logicalDpi() accordingly. Change-Id: Id60d03d1d214fb99e9de17a65976abd170bb7cca Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
-rw-r--r--src/plugins/platforms/xcb/qxcbscreen.cpp44
-rw-r--r--src/plugins/platforms/xcb/qxcbscreen.h2
2 files changed, 46 insertions, 0 deletions
diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp
index 4f0c3ba6bb..fc80662c46 100644
--- a/src/plugins/platforms/xcb/qxcbscreen.cpp
+++ b/src/plugins/platforms/xcb/qxcbscreen.cpp
@@ -66,6 +66,7 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *scr,
, m_orientation(Qt::PrimaryOrientation)
, m_number(number)
, m_refreshRate(60)
+ , m_forcedDpi(-1)
{
if (connection->hasXRandr())
xcb_randr_select_input(xcb_connection(), screen()->root, true);
@@ -82,6 +83,9 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *scr,
if (m_availableGeometry.isEmpty())
m_availableGeometry = QRect(QPoint(), m_virtualSize);
+ readXResources();
+
+
#ifdef Q_XCB_DEBUG
qDebug();
qDebug("Screen output %s of xcb screen %d:", m_outputName.toUtf8().constData(), m_number);
@@ -243,6 +247,9 @@ QImage::Format QXcbScreen::format() const
QDpi QXcbScreen::logicalDpi() const
{
+ if (m_forcedDpi > 0)
+ return QDpi(m_forcedDpi, m_forcedDpi);
+
return QDpi(Q_MM_PER_INCH * m_virtualSize.width() / m_virtualSizeMillimeters.width(),
Q_MM_PER_INCH * m_virtualSize.height() / m_virtualSizeMillimeters.height());
}
@@ -474,4 +481,41 @@ QPixmap QXcbScreen::grabWindow(WId window, int x, int y, int width, int height)
return result;
}
+void QXcbScreen::readXResources()
+{
+ int offset = 0;
+ QByteArray resources;
+ while(1) {
+ xcb_get_property_reply_t *reply =
+ xcb_get_property_reply(xcb_connection(),
+ xcb_get_property_unchecked(xcb_connection(), false, screen()->root,
+ XCB_ATOM_RESOURCE_MANAGER,
+ XCB_ATOM_STRING, offset/4, 8192), NULL);
+ bool more = false;
+ if (reply && reply->format == 8 && reply->type == XCB_ATOM_STRING) {
+ resources += QByteArray((const char *)xcb_get_property_value(reply), xcb_get_property_value_length(reply));
+ offset += xcb_get_property_value_length(reply);
+ more = reply->bytes_after != 0;
+ }
+
+ if (reply)
+ free(reply);
+
+ if (!more)
+ break;
+ }
+
+ QList<QByteArray> split = resources.split('\n');
+ for (int i = 0; i < split.size(); ++i) {
+ const QByteArray &r = split.at(i);
+ if (r.startsWith("Xft.dpi:\t")) {
+ bool ok;
+ int dpi = r.mid(sizeof("Xft.dpi:")).toInt(&ok);
+ if (ok)
+ m_forcedDpi = dpi;
+ break;
+ }
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h
index d9eee464dc..96d30cde8b 100644
--- a/src/plugins/platforms/xcb/qxcbscreen.h
+++ b/src/plugins/platforms/xcb/qxcbscreen.h
@@ -96,6 +96,7 @@ public:
void updateGeometry(xcb_timestamp_t timestamp);
void updateRefreshRate();
+ void readXResources();
private:
xcb_screen_t *m_screen;
xcb_randr_crtc_t m_crtc;
@@ -114,6 +115,7 @@ private:
QMap<xcb_visualid_t, xcb_visualtype_t> m_visuals;
QXcbCursor *m_cursor;
int m_refreshRate;
+ int m_forcedDpi;
};
QT_END_NAMESPACE