2023-10-31 08:32:40 -04:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
import { Box, EventBox, Icon, Label, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
|
|
|
|
|
|
|
|
import Separator from '../../misc/separator.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-12-08 02:22:38 -05:00
|
|
|
const SPACING = 4;
|
2023-10-13 17:01:02 -04:00
|
|
|
|
2023-11-16 14:37:09 -05:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
export default () => {
|
|
|
|
const rev = Revealer({
|
|
|
|
transition: 'slide_right',
|
|
|
|
child: Box({
|
|
|
|
children: [
|
2023-12-08 02:22:38 -05:00
|
|
|
Separator(SPACING),
|
2023-12-05 09:42:06 -05:00
|
|
|
Label({
|
|
|
|
css: 'font-size: 20px;',
|
|
|
|
connections: [[Hyprland, (self, _n, layout) => {
|
|
|
|
if (layout) {
|
|
|
|
if (layout === 'error') {
|
|
|
|
return;
|
|
|
|
}
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
const shortName = layout.match(/\(([A-Za-z]+)\)/);
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
self.label = shortName ? shortName[1] : layout;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// At launch, kb layout is undefined
|
|
|
|
Hyprland.sendMessage('j/devices').then((obj) => {
|
|
|
|
const kb = JSON.parse(obj).keyboards
|
|
|
|
.find((val) => val.name === DEFAULT_KB);
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
layout = kb['active_keymap'];
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
const shortName = layout
|
|
|
|
.match(/\(([A-Za-z]+)\)/);
|
2023-10-13 17:01:02 -04:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
self.label = shortName ? shortName[1] : layout;
|
|
|
|
}).catch(print);
|
|
|
|
}
|
|
|
|
}, 'keyboard-layout']],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
});
|
2023-10-13 17:01:02 -04:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
const widget = EventBox({
|
|
|
|
onHover: () => {
|
|
|
|
rev.revealChild = true;
|
|
|
|
},
|
|
|
|
onHoverLost: () => {
|
|
|
|
rev.revealChild = false;
|
|
|
|
},
|
|
|
|
child: Box({
|
|
|
|
css: 'padding: 0 10px; margin-right: -10px;',
|
|
|
|
children: [
|
|
|
|
Icon({
|
|
|
|
icon: 'input-keyboard-symbolic',
|
|
|
|
size: 20,
|
|
|
|
}),
|
2023-11-13 13:19:14 -05:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
rev,
|
|
|
|
],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-12-05 09:42:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
widget.rev = rev;
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
};
|