commit 000c1a3b19a8d3f8bbaefba84131995cb62c889f from: Gabriel Díaz via: Russ Cox date: Wed Nov 14 05:19:29 2018 UTC devdraw: set displaydpi on devdraw x11 attach (#178) 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. commit - a791787a384745b90fa0eb704cd9cbbe8c758684 commit + 000c1a3b19a8d3f8bbaefba84131995cb62c889f blob - 5363fb74f38d75f20501997369da915ff8536910 blob + f09963dceb445638db517227eb2d7223b86df759 --- src/cmd/devdraw/x11-init.c +++ 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);