Skip to content

Instantly share code, notes, and snippets.

@max-te
Created October 8, 2017 13:13
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 max-te/c914843bed23a31d29194d4ef9358b43 to your computer and use it in GitHub Desktop.
Save max-te/c914843bed23a31d29194d4ef9358b43 to your computer and use it in GitHub Desktop.
Automatic xinput transformation matrix
function matrix(name, a,b,c, d,e,f, g,h,i){
name[1,1] = a
name[1,2] = b
name[1,3] = c
name[2,1] = d
name[2,2] = e
name[2,3] = f
name[3,1] = g
name[3,2] = h
name[3,3] = i
}
function matrix_mult(prod, left, right) {
for(i=1; i<=3; i++){
for(j=1; j<=3; j++){
prod[i,j] = 0
for(k=1; k<=3; k++){
prod[i,j] += left[i,k] * right[k,j]
}
}
}
}
function matrix_print(name){
print name[1,1], name[1,2], name[1,3], name[2,1], name[2,2], name[2,3], name[3,1], name[3,2], name[3,3]
}
$1 == "Screen" {
sw = int( $8)
sh = int($10)
}
$1 == inp {
n = split($4, geom, /[x\+]/)
w = int(geom[1])
h = int(geom[2])
x = int(geom[3])
y = int(geom[4])
rot = $5
}
END {
switch(rot){
case "(normal":
matrix(rotrix, 1,0,0, 0,1,0, 0,0,1)
break
case "left":
matrix(rotrix, 0,-1,1, 1,0,0, 0,0,1)
break
case "right":
matrix(rotrix, 0,1,0, -1,0,1, 0,0,1)
break
case "inverted":
matrix(rotrix, -1,0,1, 0,-1,1, 0,0,1)
break
}
#matrix_print(rotrix)
matrix(geotrix, w/sw,0,x/sw, 0,h/sh,y/sh, 0,0,1)
#matrix_print(geotrix)
matrix_mult(transform, geotrix, rotrix)
matrix_print(transform)
#print sw, sh
#print w,h,x,y, rot
}
#!/bin/bash
transform=$(xrandr -q | awk -v inp="eDP-1" -f rot.awk)
xinput set-prop "Wacom Co.,Ltd. Pen and multitouch sensor Pen stylus" --type=float "Coordinate Transformation Matrix" $transform
xinput set-prop "Wacom Co.,Ltd. Pen and multitouch sensor Pen eraser" --type=float "Coordinate Transformation Matrix" $transform
xinput set-prop "Wacom Co.,Ltd. Pen and multitouch sensor Finger touch" --type=float "Coordinate Transformation Matrix" $transform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment