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-18 18:00:30 -05:00
|
|
|
/**
|
|
|
|
* @param {Label} self
|
|
|
|
* @param {string} layout
|
|
|
|
* @param {void} _
|
|
|
|
*/
|
|
|
|
const getKbdLayout = (self, _, layout) => {
|
|
|
|
if (layout) {
|
|
|
|
if (layout === 'error') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const shortName = layout.match(/\(([A-Za-z]+)\)/);
|
|
|
|
|
|
|
|
// @ts-expect-error
|
|
|
|
self.label = shortName ? shortName[1] : layout;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// At launch, kb layout is undefined
|
|
|
|
Hyprland.sendMessage('j/devices').then((obj) => {
|
|
|
|
const kb = Array.from(JSON.parse(obj).keyboards)
|
|
|
|
.find((v) => v.name === DEFAULT_KB);
|
|
|
|
|
|
|
|
layout = kb['active_keymap'];
|
|
|
|
|
|
|
|
const shortName = layout
|
|
|
|
.match(/\(([A-Za-z]+)\)/);
|
|
|
|
|
|
|
|
// @ts-expect-error
|
|
|
|
self.label = shortName ? shortName[1] : layout;
|
|
|
|
}).catch(print);
|
|
|
|
}
|
|
|
|
};
|
2023-12-17 00:01:58 -05:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
export default () => {
|
2023-12-18 18:00:30 -05:00
|
|
|
const hoverRevLabel = Revealer({
|
2023-12-05 09:42:06 -05:00
|
|
|
transition: 'slide_right',
|
2023-12-18 18:00:30 -05:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
child: Box({
|
2023-12-18 18:00:30 -05:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
children: [
|
2023-12-08 02:22:38 -05:00
|
|
|
Separator(SPACING),
|
2023-12-18 18:00:30 -05:00
|
|
|
|
|
|
|
Label({ css: 'font-size: 20px;' })
|
|
|
|
.hook(Hyprland, getKbdLayout, 'keyboard-layout'),
|
2023-12-05 09:42:06 -05:00
|
|
|
],
|
|
|
|
}),
|
|
|
|
});
|
2023-10-13 17:01:02 -04:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
const widget = EventBox({
|
2023-12-18 18:00:30 -05:00
|
|
|
on_hover: () => {
|
|
|
|
hoverRevLabel.reveal_child = true;
|
2023-12-05 09:42:06 -05:00
|
|
|
},
|
2023-12-18 18:00:30 -05:00
|
|
|
on_hover_lost: () => {
|
|
|
|
hoverRevLabel.reveal_child = false;
|
2023-12-05 09:42:06 -05:00
|
|
|
},
|
2023-12-18 18:00:30 -05:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
child: Box({
|
|
|
|
css: 'padding: 0 10px; margin-right: -10px;',
|
2023-12-18 18:00:30 -05:00
|
|
|
|
2023-12-05 09:42:06 -05:00
|
|
|
children: [
|
|
|
|
Icon({
|
|
|
|
icon: 'input-keyboard-symbolic',
|
|
|
|
size: 20,
|
|
|
|
}),
|
2023-11-13 13:19:14 -05:00
|
|
|
|
2023-12-18 18:00:30 -05:00
|
|
|
hoverRevLabel,
|
2023-12-05 09:42:06 -05:00
|
|
|
],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-12-05 09:42:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
};
|