Skip to content

Instantly share code, notes, and snippets.

@gicmo
Created May 17, 2017 15:59
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 gicmo/88a640107ab8c14fbe9338a43f79bbb4 to your computer and use it in GitHub Desktop.
Save gicmo/88a640107ab8c14fbe9338a43f79bbb4 to your computer and use it in GitHub Desktop.
Estimation for mutter HiDPI thresholds
#!/usr/bin/env python3
import sys
import numpy as np
def area(d, a, b):
return (a*b)/(a**2+b**2) * d**2
def dpi(d, res, ratio):
a, b = ratio
x, y = res
A = area(d, a, b)
px = x*y
return np.sqrt(px/A), d, res, ratio
res = [(3840, 2048)]
sizes = [22, 23, 23.4, 24, 25]
ratio = [(4,3), (16, 9), (16,10), (21,9)]
def main():
ts = 192 if len(sys.argv) < 2 else int(sys.argv[1])
dpis = [dpi(s, r, q) for s in sizes for r in res for q in ratio]
print('Using threashold %d' % ts)
for d, s, r, q in dpis:
scale = 2 if d > ts else 1
scale_5p = 2 if d > ts-(ts*0.05) else 1
change = '!' if scale != scale_5p else ''
print('%2.1f", %dx%d, %2d:%2d => %3.1f -> %d, %d %s' %
(s, r[0], r[1], q[0], q[1], d, scale, scale_5p, change))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment