feat(ags tablet): add OSK to tablet service

This commit is contained in:
matt1432 2023-11-04 18:51:59 -04:00
parent ad27c6d6fc
commit cf7390090e
4 changed files with 47 additions and 51 deletions

View file

@ -1,30 +0,0 @@
#!/usr/bin/env bash
state () {
if [[ $(busctl get-property --user sm.puri.OSK0 /sm/puri/OSK0 sm.puri.OSK0 Visible) == "b true" ]]; then
echo "Running"
else
echo "Stopped"
fi
}
toggle () {
if [[ $(busctl get-property --user sm.puri.OSK0 /sm/puri/OSK0 sm.puri.OSK0 Visible) == "b true" ]]; then
echo "Running"
busctl call --user sm.puri.OSK0 /sm/puri/OSK0 sm.puri.OSK0 SetVisible b false
else
echo "Stopped"
busctl call --user sm.puri.OSK0 /sm/puri/OSK0 sm.puri.OSK0 SetVisible b true
fi
}
if [[ $1 == "getState" ]]; then
while true; do
sleep 0.2
state
done
fi
if [[ $1 == "toggle" ]];then
toggle
fi

View file

@ -1,33 +1,21 @@
import { Box, Label } from 'resource:///com/github/Aylur/ags/widget.js';
import { subprocess } from 'resource:///com/github/Aylur/ags/utils.js';
import EventBox from '../misc/cursorbox.js';
export default () => EventBox({
className: 'toggle-off',
setup: self => {
subprocess(
['bash', '-c', '$AGS_PATH/osk-toggle.sh getState'],
output => self.toggleClassName('toggle-on', output === 'Running'),
);
},
onPrimaryClickRelease: () => Tablet.toggleOsk(),
onPrimaryClickRelease: self => {
subprocess(
['bash', '-c', '$AGS_PATH/osk-toggle.sh toggle'],
output => self.toggleClassName('toggle-on', output !== 'Running'),
);
},
connections: [[Tablet, self => {
self.toggleClassName('toggle-on', Tablet.oskState);
}, 'osk-toggled']],
child: Box({
className: 'osk-toggle',
vertical: false,
children: [
Label({
label: ' 󰌌 ',
}),
],
children: [Label({
label: ' 󰌌 ',
})],
}),
});

View file

@ -14,8 +14,8 @@ export default () => EventBox({
child: Box({
className: 'tablet-toggle',
vertical: false,
child: Label({
children: [Label({
label: ' 󰦧 ',
}),
})],
}),
});

View file

@ -11,6 +11,7 @@ const ROTATION_MAPPING = {
const SCREEN = 'desc:BOE 0x0964';
// TODO: Make autorotate reset lisgd
class Tablet extends Service {
static {
Service.register(this, {
@ -22,11 +23,13 @@ class Tablet extends Service {
'laptop-mode': ['boolean'],
'tablet-mode': ['boolean'],
'mode-toggled': ['boolean'],
'osk-toggled': ['boolean'],
});
}
tabletMode = false;
autorotate = undefined;
oskState = false;
blockedInputs = undefined;
udevClient = GUdev.Client.new(['input']);
@ -36,6 +39,7 @@ class Tablet extends Service {
constructor() {
super();
this.initUdevConnection();
this.listenOskState();
}
blockInputs() {
@ -156,6 +160,40 @@ class Tablet extends Service {
this.emit('autorotate-destroyed', true);
}
}
listenOskState() {
subprocess(
['bash', '-c', 'busctl monitor --user sm.puri.OSK0'],
output => {
if (output.includes('BOOLEAN')) {
this.oskState = output.match('true|false')[0] === 'true';
this.emit('osk-toggled', this.oskState);
}
},
err => logError(err),
);
}
openOsk() {
execAsync(['busctl', 'call', '--user',
'sm.puri.OSK0', '/sm/puri/OSK0', 'sm.puri.OSK0',
'SetVisible', 'b', 'true'])
.catch(print);
}
closeOsk() {
execAsync(['busctl', 'call', '--user',
'sm.puri.OSK0', '/sm/puri/OSK0', 'sm.puri.OSK0',
'SetVisible', 'b', 'false'])
.catch(print);
}
toggleOsk() {
if (this.oskState)
this.closeOsk();
else
this.openOsk();
}
}
const tabletService = new Tablet();