-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
28 lines (24 loc) · 901 Bytes
/
index.js
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
'use strict'
const exec = require('child_process').exec
module.exports = (direction, cb) => {
const coordinateMatrices = {
left: " 0 -1 1 1 0 0 0 0 1",
right: " 0 1 0 -1 0 1 0 0 1",
normal: " 1 0 0 0 1 0 0 0 1",
inverse: "-1 0 1 0 -1 1 0 0 1"
}
exec('xinput', (err, stdout) => {
if (err) cb(err)
const lines = stdout.split('\n')
const pointerLines = lines.filter(line => line.includes('slave pointer'))
const deviceNames = pointerLines.map(line => {
const nameSection = line.split('\t')[0]
const name = nameSection.slice(nameSection.indexOf('↳') + 1)
return name.trim()
})
const script = deviceNames.map(deviceName => {
return `xinput set-prop "${deviceName}" --type=float "Coordinate Transformation Matrix" ${coordinateMatrices[direction]}`
}).join('\n')
cb(null, script)
})
}