2023-10-31 08:32:40 -04:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
|
|
|
import { Box, Icon, Label } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-10-13 17:01:02 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
const DEFAULT_KB = 'at-translated-set-2-keyboard';
|
2023-10-13 17:01:02 -04:00
|
|
|
|
2023-11-16 14:37:09 -05:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
export default () => Box({
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'toggle-off',
|
2023-11-13 13:19:14 -05:00
|
|
|
css: 'padding: 0 10px;',
|
2023-10-20 23:11:21 -04:00
|
|
|
children: [
|
|
|
|
Icon({
|
|
|
|
icon: 'input-keyboard-symbolic',
|
2023-11-06 18:37:23 -05:00
|
|
|
css: 'margin-right: 4px;',
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
Label({
|
|
|
|
connections: [[Hyprland, (self, _n, layout) => {
|
|
|
|
if (!layout) {
|
2023-11-13 13:19:14 -05:00
|
|
|
Hyprland.sendMessage('j/devices').then(obj => {
|
|
|
|
const kb = JSON.parse(obj)['keyboards']
|
|
|
|
.find(val => val.name === DEFAULT_KB);
|
2023-10-13 17:01:02 -04:00
|
|
|
|
2023-11-13 13:19:14 -05:00
|
|
|
layout = kb['active_keymap'];
|
2023-10-13 17:01:02 -04:00
|
|
|
|
2023-11-13 13:19:14 -05:00
|
|
|
const shortName = layout.match(/\(([A-Za-z]+)\)/);
|
|
|
|
|
|
|
|
self.label = shortName ? shortName[1] : layout;
|
|
|
|
}).catch(print);
|
2023-10-20 23:11:21 -04:00
|
|
|
}
|
|
|
|
else {
|
2023-11-13 13:19:14 -05:00
|
|
|
if (layout === 'error')
|
|
|
|
return;
|
|
|
|
|
|
|
|
const shortName = layout.match(/\(([A-Za-z]+)\)/);
|
|
|
|
|
|
|
|
self.label = shortName ? shortName[1] : layout;
|
2023-10-20 23:11:21 -04:00
|
|
|
}
|
|
|
|
}, 'keyboard-layout']],
|
|
|
|
}),
|
|
|
|
],
|
2023-10-13 17:01:02 -04:00
|
|
|
});
|