nixos-configs/config/ags/js/bar/systray.js

68 lines
1.7 KiB
JavaScript
Raw Normal View History

import { SystemTray, Widget } from '../../imports.js';
const { Box, Revealer, Icon, MenuItem } = Widget;
import Gtk from 'gi://Gtk';
2023-09-11 19:57:21 -04:00
2023-09-26 08:57:32 -04:00
import { Separator } from '../misc/separator.js';
const SysTrayItem = item => MenuItem({
className: 'tray-item',
child: Revealer({
transition: 'slide_right',
child: Icon({
size: 24,
}),
}),
submenu: item.menu,
connections: [[item, btn => {
btn.child.child.icon = item.icon;
btn.tooltipMarkup = item.tooltipMarkup;
}]]
});
2023-09-26 08:57:32 -04:00
export const SysTray = Revealer({
transition: 'slide_right',
connections: [[SystemTray, rev => {
rev.revealChild = rev.child.children[0].get_children().length > 0;
}]],
child: Box({
children: [
Widget({
2023-09-26 08:57:32 -04:00
type: Gtk.MenuBar,
className: 'sys-tray',
properties: [
['items', new Map()],
['onAdded', (box, id) => {
const item = SystemTray.getItem(id);
if (box._items.has(id) || !item)
return;
2023-09-26 08:57:32 -04:00
const widget = SysTrayItem(item);
box._items.set(id, widget);
box.add(widget);
box.show_all();
widget.child.revealChild = true;
2023-09-26 08:57:32 -04:00
}],
2023-09-26 08:57:32 -04:00
['onRemoved', (box, id) => {
if (!box._items.has(id))
return;
box._items.get(id).child.revealChild = false;
setTimeout(() => {
box._items.get(id).destroy();
box._items.delete(id);
}, 400);
2023-09-26 08:57:32 -04:00
}],
],
connections: [
[SystemTray, (box, id) => box._onAdded(box, id), 'added'],
[SystemTray, (box, id) => box._onRemoved(box, id), 'removed'],
],
}),
Separator(12),
],
}),
});