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 { 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'; import EventBox from '../misc/cursorbox.js';
export default () => EventBox({ export default () => EventBox({
className: 'toggle-off', className: 'toggle-off',
setup: self => { onPrimaryClickRelease: () => Tablet.toggleOsk(),
subprocess(
['bash', '-c', '$AGS_PATH/osk-toggle.sh getState'],
output => self.toggleClassName('toggle-on', output === 'Running'),
);
},
onPrimaryClickRelease: self => { connections: [[Tablet, self => {
subprocess( self.toggleClassName('toggle-on', Tablet.oskState);
['bash', '-c', '$AGS_PATH/osk-toggle.sh toggle'], }, 'osk-toggled']],
output => self.toggleClassName('toggle-on', output !== 'Running'),
);
},
child: Box({ child: Box({
className: 'osk-toggle', className: 'osk-toggle',
vertical: false, vertical: false,
children: [Label({
children: [
Label({
label: ' 󰌌 ', label: ' 󰌌 ',
}), })],
],
}), }),
}); });

View file

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

View file

@ -11,6 +11,7 @@ const ROTATION_MAPPING = {
const SCREEN = 'desc:BOE 0x0964'; const SCREEN = 'desc:BOE 0x0964';
// TODO: Make autorotate reset lisgd
class Tablet extends Service { class Tablet extends Service {
static { static {
Service.register(this, { Service.register(this, {
@ -22,11 +23,13 @@ class Tablet extends Service {
'laptop-mode': ['boolean'], 'laptop-mode': ['boolean'],
'tablet-mode': ['boolean'], 'tablet-mode': ['boolean'],
'mode-toggled': ['boolean'], 'mode-toggled': ['boolean'],
'osk-toggled': ['boolean'],
}); });
} }
tabletMode = false; tabletMode = false;
autorotate = undefined; autorotate = undefined;
oskState = false;
blockedInputs = undefined; blockedInputs = undefined;
udevClient = GUdev.Client.new(['input']); udevClient = GUdev.Client.new(['input']);
@ -36,6 +39,7 @@ class Tablet extends Service {
constructor() { constructor() {
super(); super();
this.initUdevConnection(); this.initUdevConnection();
this.listenOskState();
} }
blockInputs() { blockInputs() {
@ -156,6 +160,40 @@ class Tablet extends Service {
this.emit('autorotate-destroyed', true); 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(); const tabletService = new Tablet();