Skip to content

Instantly share code, notes, and snippets.

@phillipberndt
Created May 18, 2015 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipberndt/32cf4e75a8214f90a8ab to your computer and use it in GitHub Desktop.
Save phillipberndt/32cf4e75a8214f90a8ab to your computer and use it in GitHub Desktop.
autorandr patch to show DPI
diff --git a/autorandr.py b/autorandr.py
index 19722c9..6df9d9b 100755
--- a/autorandr.py
+++ b/autorandr.py
@@ -129,7 +129,8 @@ class XrandrOutput(object):
(?P<rotate>(?:normal|left|right|inverted))\s+ # Rotation
(?:(?P<reflect>X\ and\ Y|X|Y)\ axis)? # Reflection
)? # .. but everything of the above only if the screen is in use.
- (?:[\ \t]*\([^\)]+\))(?:\s*[0-9]+mm\sx\s[0-9]+mm)?
+ (?:[\ \t]*\([^\)]+\))\s*
+ (?:(?P<physical_width>[0-9]+)mm\sx\s(?P<physical_height>[0-9]+)mm)? # Physical size
(?:[\ \t]*panning\ (?P<panning>[0-9]+x[0-9]+\+[0-9]+\+[0-9]+))? # Panning information
(?:[\ \t]*tracking\ (?P<tracking>[0-9]+x[0-9]+\+[0-9]+\+[0-9]+))? # Tracking information
(?:[\ \t]*border\ (?P<border>(?:[0-9]+/){3}[0-9]+))? # Border information
@@ -167,6 +168,7 @@ class XrandrOutput(object):
XRANDR_DEFAULTS = dict(list(XRANDR_13_DEFAULTS.items()) + list(XRANDR_12_DEFAULTS.items()))
+ METRE_TO_INCH = 39.3700787402
EDID_UNAVAILABLE = "--CONNECTED-BUT-EDID-UNAVAILABLE-"
def __repr__(self):
@@ -313,6 +315,10 @@ class XrandrOutput(object):
options["gamma"] = gamma
if match["rate"]:
options["rate"] = match["rate"]
+ if match["physical_width"]:
+ width_inches = int(match["physical_width"]) * 1e-3 * XrandrOutput.METRE_TO_INCH
+ height_inches = int(match["physical_height"]) * 1e-3 * XrandrOutput.METRE_TO_INCH
+ print("\033[1mDebug\033[0m: Output %s reports %3.2f x %3.2f DPI" % (match["output"], int(match["width"]) / width_inches, int(match["height"]) / height_inches))
return XrandrOutput(match["output"], edid, options), modes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment