2023-11-05 01:34:13 -05:00
|
|
|
import Service from 'resource:///com/github/Aylur/ags/service.js';
|
|
|
|
import { subprocess } from 'resource:///com/github/Aylur/ags/utils.js';
|
|
|
|
|
|
|
|
const SCREEN = '/dev/input/by-path/platform-AMDI0010\:00-event';
|
|
|
|
|
|
|
|
const GESTURE_VERIF = [
|
|
|
|
'LR', // Left to Right
|
|
|
|
'RL', // Right to Left
|
|
|
|
'DU', // Down to Up
|
|
|
|
'UD', // Up to Down
|
|
|
|
'DLUR', // Down to Left to Up to Right (clockwise motion from Down)
|
|
|
|
'DRUL', // Down to Right to Up to Left (counter-clockwise from Down)
|
|
|
|
'URDL', // Up to Right to Down to Left (clockwise motion from Up)
|
|
|
|
'ULDR', // Up to Left to Down to Right (counter-clockwise from Up)
|
|
|
|
];
|
|
|
|
const EDGE_VERIF = [
|
2023-11-21 01:29:46 -05:00
|
|
|
'*', // Any
|
|
|
|
'N', // None
|
|
|
|
'L', // Left
|
|
|
|
'R', // Right
|
|
|
|
'T', // Top
|
|
|
|
'B', // Bottom
|
|
|
|
'TL', // Top left
|
|
|
|
'TR', // Top right
|
|
|
|
'BL', // Bottom left
|
|
|
|
'BR', // Bottom right
|
2023-11-05 01:34:13 -05:00
|
|
|
];
|
|
|
|
const DISTANCE_VERIF = [
|
2023-11-21 01:29:46 -05:00
|
|
|
'*', // Any
|
|
|
|
'S', // Short
|
|
|
|
'M', // Medium
|
|
|
|
'L', // Large
|
2023-11-05 01:34:13 -05:00
|
|
|
];
|
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
// Types
|
2024-01-22 10:23:32 -05:00
|
|
|
import { Subprocess } from 'types/@girs/gio-2.0/gio-2.0.cjs';
|
2024-01-13 11:15:08 -05:00
|
|
|
|
2023-11-05 01:34:13 -05:00
|
|
|
|
2023-11-05 13:35:12 -05:00
|
|
|
// TODO: add actmode param
|
|
|
|
// TODO: support multiple daemons for different thresholds
|
2023-11-05 01:34:13 -05:00
|
|
|
class TouchGestures extends Service {
|
|
|
|
static {
|
|
|
|
Service.register(this, {
|
|
|
|
'daemon-started': ['boolean'],
|
|
|
|
'daemon-destroyed': ['boolean'],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
#gestures = new Map();
|
2024-01-22 10:23:32 -05:00
|
|
|
#gestureDaemon = null as Subprocess | null;
|
2023-11-05 01:34:13 -05:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
get gestures() {
|
|
|
|
return this.#gestures;
|
2023-11-05 01:34:13 -05:00
|
|
|
}
|
|
|
|
|
2023-12-24 00:16:18 -05:00
|
|
|
get gestureDaemon() {
|
|
|
|
return this.#gestureDaemon;
|
|
|
|
}
|
|
|
|
|
2023-11-05 01:34:13 -05:00
|
|
|
addGesture({
|
|
|
|
name,
|
|
|
|
nFingers = '1',
|
|
|
|
gesture,
|
|
|
|
edge = '*',
|
|
|
|
distance = '*',
|
|
|
|
command,
|
2023-12-24 00:16:18 -05:00
|
|
|
}) {
|
2023-11-05 01:34:13 -05:00
|
|
|
gesture = String(gesture).toUpperCase();
|
|
|
|
if (!GESTURE_VERIF.includes(gesture)) {
|
|
|
|
logError('Wrong gesture id');
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-05 01:34:13 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
edge = String(edge).toUpperCase();
|
|
|
|
if (!EDGE_VERIF.includes(edge)) {
|
|
|
|
logError('Wrong edge id');
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-05 01:34:13 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
distance = String(distance).toUpperCase();
|
|
|
|
if (!DISTANCE_VERIF.includes(distance)) {
|
|
|
|
logError('Wrong distance id');
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-05 01:34:13 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-06 20:38:16 -05:00
|
|
|
if (typeof command !== 'string') {
|
|
|
|
globalThis[name] = command;
|
|
|
|
command = `ags -r "${name}()"`;
|
|
|
|
}
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
this.#gestures.set(name, [
|
2023-11-05 01:34:13 -05:00
|
|
|
'-g',
|
|
|
|
`${nFingers},${gesture},${edge},${distance},${command}`,
|
|
|
|
]);
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
if (this.#gestureDaemon) {
|
2023-11-05 01:34:13 -05:00
|
|
|
this.killDaemon();
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-05 01:34:13 -05:00
|
|
|
this.startDaemon();
|
|
|
|
}
|
|
|
|
|
|
|
|
startDaemon() {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (this.#gestureDaemon) {
|
2023-11-05 01:34:13 -05:00
|
|
|
return;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-05 01:34:13 -05:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
let command = [
|
2023-11-05 01:34:13 -05:00
|
|
|
'lisgd', '-d', SCREEN,
|
2023-11-21 01:29:46 -05:00
|
|
|
// Orientation
|
2023-11-05 01:34:13 -05:00
|
|
|
'-o', '0',
|
|
|
|
// Threshold of gesture recognized
|
|
|
|
'-t', '125',
|
|
|
|
// Leniency of gesture angle
|
|
|
|
'-r', '25',
|
|
|
|
// Timeout time
|
|
|
|
'-m', '3200',
|
|
|
|
];
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
this.#gestures.forEach((gesture) => {
|
2023-11-05 01:34:13 -05:00
|
|
|
command = command.concat(gesture);
|
|
|
|
});
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
this.#gestureDaemon = subprocess(
|
2023-11-05 01:34:13 -05:00
|
|
|
command,
|
2023-11-21 01:29:46 -05:00
|
|
|
() => { /**/ },
|
2023-11-05 01:34:13 -05:00
|
|
|
);
|
|
|
|
this.emit('daemon-started', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
killDaemon() {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (this.#gestureDaemon) {
|
|
|
|
this.#gestureDaemon.force_exit();
|
|
|
|
this.#gestureDaemon = null;
|
2023-11-05 01:34:13 -05:00
|
|
|
this.emit('daemon-destroyed', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const touchGesturesService = new TouchGestures();
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-05 01:34:13 -05:00
|
|
|
export default touchGesturesService;
|