-
Notifications
You must be signed in to change notification settings - Fork 8
/
grox.rb
executable file
·123 lines (96 loc) · 3.42 KB
/
grox.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/ruby
# ./grox.rb <dir>
# +left, +right, flip: relative movement
# left, right, normal, inverted: absolute movement
# devices to manipulate
# If you don't have one of the input devices listed, just leave it blank
$screen = 'eDP1'
$touchscreen = 'Wacom HID 5196 Finger'
$pen = 'Wacom HID 5196 Pen Pen (0xae4d0b0a)'
$eraser = 'Wacom HID 5196 Pen Eraser (0xae4d0b0a)'
$touchpad = 'SYNA2B31:00 06CB:CD3E Touchpad'
$keyboard = 'AT Translated Set 2 keyboard'
# disable keypad and touchpad on all but normal orientation
$controlKeys = false
# runs cmd and greps output to find orientation
$orientationCmd = 'xrandr'
$orientationRE = /\s*#{$screen}\s+\w+\s+[x+\d]+\s+(|left|right|inverted)\s*\(/
# default direction
$defaultDirection = 'right'
# CODE
def main()
direction = $defaultDirection
if ARGV.length > 0
direction = ARGV[0]
end
doOrientate(getNewOrientation(direction))
end
def orientateCmd(orientation, transform)
rotateScreen = "xrandr --output #{$screen}" +
" --rotate #{orientation}";
rotateTouchscreen = "xinput --set-prop '#{$touchscreen}'" +
" --type=float" +
" 'Coordinate Transformation Matrix'" +
" #{transform}"
rotatePen = "xinput --set-prop '#{$pen}'" +
" --type=float" +
" 'Coordinate Transformation Matrix'" +
" #{transform}"
rotateEraser = "xinput --set-prop '#{$eraser}'" +
" --type=float" +
" 'Coordinate Transformation Matrix'" +
" #{transform}"
controlKeys = ""
if $controlKeys
setCmd = orientation == 'normal' ? 'xinput --enable '
: 'xinput --disable '
controlKeys = "#{setCmd} '#{$touchpad}'; #{setCmd} '#{$keyboard}';"
end
return controlKeys +
rotateScreen + ';' +
rotateTouchscreen + ';' +
rotatePen + ';' +
rotateEraser + ';'
end
def doOrientate(orientation)
case orientation
when 'normal'
`#{orientateCmd('normal', '1 0 0 0 1 0 0 0 1')}`
when 'left'
`#{orientateCmd('left', '0 -1 1 1 0 0 0 0 1')}`
when 'right'
`#{orientateCmd('right', '0 1 0 -1 0 1 0 0 1')}`
when 'inverted'
`#{orientateCmd('inverted', '-1 0 1 0 -1 1 0 0 1')}`
else
raise "Don't know how to orientate to #{orientation}"
end
end
# returns direction of $screen: left, right, normal or invert
def getOrientation()
if `#{$orientationCmd}` =~ $orientationRE
return $1 == '' ? 'normal' : $1
else
raise "Could not determine orientation of #{$screen} from #{$orientationCmd}"
end
end
# direction should be +left, +right, flip, left, right, normal, or inverted
def getNewOrientation(direction)
clockwise = ['normal', 'right', 'inverted', 'left']
if clockwise.include?(direction)
return direction
else
curdir = clockwise.find_index(getOrientation())
shift = case direction
when '+left' then -1
when '+right' then 1
when 'flip' then 2
else
raise "Unrecognised rotate direction #{direction}"
end
newdir = (curdir + shift) % 4
return clockwise[newdir]
end
end
# DO
main()