From 067cfb7cd6e4dba009bbb746050c8149a3f712f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 8 Aug 2016 04:02:25 +0200 Subject: [PATCH] Send approximate physical screen dimensions to the VM When properly set, applications will have a chance to automatically detect HiDPI and act accordingly. This is the case for Fedora 23 template and GNOME apps (maybe even all built on top of GTK). But for privacy reasons, don't provide real values, only some approximate one. Give enough information to distinguish DPI above 150, 200 and 300. This is some compromise between privacy and HiDPI support. QubesOS/qubes-issues#1951 This commit is migrated from gui-daemon repository (dec462795d14a336bf27cc46948bbd592c307401). --- qubes/ext/gui.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/qubes/ext/gui.py b/qubes/ext/gui.py index 270cc4ee..f3dccbe9 100644 --- a/qubes/ext/gui.py +++ b/qubes/ext/gui.py @@ -45,6 +45,11 @@ REGEX_OUTPUT = re.compile(r''' (?P\d+)[+] (?P\d+) )|[\D]) # or not a digit + ([ ]\(.*\))?[ ]? # ignore options + ( # 304mm x 228mm + (?P\d+)mm[ ]x[ ] + (?P\d+)mm + )? .* # ignore rest of line ''') @@ -57,11 +62,34 @@ def get_monitor_layout(): if not line.startswith("Screen") and not line.startswith(" "): output_params = REGEX_OUTPUT.match(line).groupdict() if output_params['width']: - outputs.append("%s %s %s %s\n" % ( + phys_size = "" + if output_params['width_mm']: + # don't provide real values for privacy reasons - see + # #1951 for details + dpi = (int(output_params['width']) * 254 / + int(output_params['width_mm']) / 10) + if dpi > 300: + dpi = 300 + elif dpi > 200: + dpi = 200 + elif dpi > 150: + dpi = 150 + else: + # if lower, don't provide this info to the VM at all + dpi = 0 + if dpi: + # now calculate dimensions based on approximate DPI + phys_size = " {} {}".format( + int(output_params['width']) * 254 / dpi / 10, + int(output_params['height']) * 254 / dpi / 10, + ) + outputs.append("%s %s %s %s%s\n" % ( output_params['width'], output_params['height'], output_params['x'], - output_params['y'])) + output_params['y'], + phys_size, + )) return outputs