2021-10-09 21:20:41 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
import sys
|
2023-03-10 17:06:03 +00:00
|
|
|
import numpy as np
|
|
|
|
import os
|
2021-10-09 21:20:41 +00:00
|
|
|
|
2022-07-31 21:09:31 +00:00
|
|
|
if len(sys.argv) < 3:
|
|
|
|
print("Usage: tablet [dev number] [property number] [scale factor] [aspect ratio]")
|
|
|
|
|
2021-10-09 21:20:41 +00:00
|
|
|
#Arguments
|
|
|
|
dev = sys.argv[1]
|
|
|
|
prop = sys.argv[2]
|
|
|
|
scale = float(sys.argv[3])
|
|
|
|
tablet_ratio = (lambda s: float(s[0]) / float(s[1]))(sys.argv[4].split(":")) if len(sys.argv) > 4 else 16/9
|
|
|
|
|
|
|
|
#Layout of screens: (x, y, w, h)
|
2022-07-31 21:09:31 +00:00
|
|
|
#screens = [
|
|
|
|
# (0, 0, 1280, 1024),
|
|
|
|
# (1280, 0, 2560, 1440),
|
|
|
|
# (3840, 0, 1080, 1920),
|
|
|
|
# (4920, 0, 1080, 1920),
|
|
|
|
#]
|
|
|
|
|
2021-10-09 21:20:41 +00:00
|
|
|
screens = [
|
2023-02-06 12:07:49 +00:00
|
|
|
(0, 0, 1920, 1080),
|
2021-10-09 21:20:41 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
#TODO find this with xrandr
|
|
|
|
|
2023-03-01 00:15:29 +00:00
|
|
|
target = screens[0]
|
2021-10-09 21:20:41 +00:00
|
|
|
|
|
|
|
#Physical offset of the selected screen
|
|
|
|
offsetx = target[0]
|
|
|
|
offsety = target[1]
|
|
|
|
|
|
|
|
#Size of the full screen areas
|
2023-03-01 00:15:29 +00:00
|
|
|
sh = 1080
|
|
|
|
sw = 1920
|
2021-10-09 21:20:41 +00:00
|
|
|
#TODO calculate using list of screens
|
|
|
|
|
|
|
|
#Aspect ratio of the tablet, to avoid weird scaling problems
|
|
|
|
|
|
|
|
#Size of the tablet
|
|
|
|
#Prioritize the with when scaling between aspect ratios
|
|
|
|
tw = target[2]
|
|
|
|
th = tw / tablet_ratio
|
|
|
|
print(tw, "x", th)
|
|
|
|
|
2023-03-10 17:06:03 +00:00
|
|
|
if "-r" in sys.argv or "-l" in sys.argv:
|
|
|
|
th = target[2]
|
|
|
|
tw = th / tablet_ratio
|
|
|
|
|
2021-10-09 21:20:41 +00:00
|
|
|
#make a variable that will try to make the scale the same over diferent resoultions
|
|
|
|
f = target[3] / target[3]
|
|
|
|
print ("f value =", f)
|
|
|
|
|
|
|
|
#calculate the new area size
|
|
|
|
aw = tw * scale * f
|
|
|
|
ah = th * scale * f
|
|
|
|
|
|
|
|
ox = (target[2] - aw) / 2 + offsetx
|
|
|
|
oy = (target[3] - ah) / 2 + offsety
|
|
|
|
#ox = offsetx
|
|
|
|
#oy = offsety
|
|
|
|
|
|
|
|
|
|
|
|
c0 = aw / sw
|
|
|
|
c2 = ah / sh
|
|
|
|
c1 = ox / sw
|
|
|
|
c3 = oy / sh
|
|
|
|
|
|
|
|
print(str(c0), "0", str(c1), "0", str(c2), str(c3), "0 0 1")
|
|
|
|
|
2023-03-10 17:06:03 +00:00
|
|
|
transform = np.matrix([[c0, 0, c1], [0, c2, c3], [0, 0, 1]])
|
|
|
|
|
|
|
|
leftrotate = np.matrix([[0, -1, 1], [1, 0, 0], [0, 0, 1]])
|
|
|
|
rightrotate = np.matrix([[0, 1, 0], [-1, 0, 1], [0, 0, 1]])
|
|
|
|
|
|
|
|
if "-r" in sys.argv:
|
|
|
|
transform *= rightrotate
|
|
|
|
if "-l" in sys.argv:
|
|
|
|
transform *= leftrotate
|
|
|
|
|
|
|
|
arr = np.squeeze(np.asarray(transform))
|
|
|
|
|
|
|
|
|
|
|
|
os.system(" ".join(["xinput set-prop", dev, prop, " ".join([str(x) for x in [arr[0, 0], arr[0, 1], arr[0, 2], arr[1, 0], arr[1, 1], arr[1, 2], arr[2, 0], arr[2, 1], arr[2, 2]]])]))
|
2021-10-09 21:20:41 +00:00
|
|
|
#alias tablet2="xinput set-prop 18 156 2.45 0 -0.725 0 2.45 -0.725 0 0 1"
|