From 000c1a3b19a8d3f8bbaefba84131995cb62c889f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20D=C3=ADaz?= Date: Wed, 14 Nov 2018 06:19:29 +0100 Subject: devdraw: set displaydpi on devdraw x11 attach (#178) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://plan9port-review.googlesource.com/c/plan9/+/1470 for discussion of the approach, especially Michael Stapleberg's comment: Note that chromium, firefox and others have tried this and then switched to using the Xft.dpi X resource, see e.g. https://code.google.com/p/chromium/codesearch#chromium/src/chrome/browser/ui/libgtk2ui/gtk2_ui.cc and especially http://sources.debian.net/src/gnome-settings-daemon/3.18.2-1/plugins/xsettings/gsd-xsettings-manager.c/?hl=824#L80 for some anecdata about why this approach doesn’t work out. The Xft.dpi resource is being set accurately by desktop environments (GNOME, KDE, …) and can easily be changed by users of niche window managers by editing ~/.Xresources. I suggest we check only Xft.dpi, without considering the DPI environment variable or the monitor width/height. --- src/cmd/devdraw/x11-init.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/cmd/devdraw/x11-init.c') diff --git a/src/cmd/devdraw/x11-init.c b/src/cmd/devdraw/x11-init.c index 5363fb74..f09963dc 100644 --- a/src/cmd/devdraw/x11-init.c +++ b/src/cmd/devdraw/x11-init.c @@ -208,9 +208,9 @@ _xattach(char *label, char *winsize) * Parse the various X resources. Thanks to Peter Canning. */ char *screen_resources, *display_resources, *geom, - *geomrestype, *home, *file; + *geomrestype, *home, *file, *dpitype; XrmDatabase database; - XrmValue geomres; + XrmValue geomres, dpires; database = XrmGetDatabase(_x.display); screen_resources = XScreenResourceString(xscreen); @@ -230,6 +230,11 @@ _xattach(char *label, char *winsize) }else XrmCombineDatabase(XrmGetStringDatabase(display_resources), &database, False); + if (XrmGetResource(database, "Xft.dpi", "String", &dpitype, &dpires) == True) { + if (dpires.addr) { + displaydpi=atoi(dpires.addr); + } + } geom = smprint("%s.geometry", label); if(geom && XrmGetResource(database, geom, nil, &geomrestype, &geomres)) mask = XParseGeometry(geomres.addr, &x, &y, (uint*)&width, (uint*)&height); -- cgit v1.2.3