feat(ags): hide systray when no items

This commit is contained in:
matt1432 2023-09-26 08:57:32 -04:00
parent c431df1215
commit 931376fb67
2 changed files with 38 additions and 29 deletions

View file

@ -41,8 +41,6 @@ export const Bar = Window({
SysTray,
Separator(12),
AudioIndicator,
Separator(12),

View file

@ -1,8 +1,8 @@
const { SystemTray } = ags.Service;
const { Box, Button, Icon, MenuItem } = ags.Widget;
const { Box, Revealer, Icon, MenuItem } = ags.Widget;
const { Gtk } = imports.gi;
import { EventBox } from '../misc/cursorbox.js';
import { Separator } from '../misc/separator.js';
const SysTrayItem = item => MenuItem({
className: 'tray-item',
@ -16,31 +16,42 @@ const SysTrayItem = item => MenuItem({
}]]
});
export const SysTray = ags.Widget({
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;
export const SysTray = Revealer({
transition: 'slide_right',
connections: [[SystemTray, rev => {
rev.revealChild = rev.child.children[0].get_children().length > 0;
}]],
child: Box({
children: [
ags.Widget({
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;
const widget = SysTrayItem(item);
box._items.set(id, widget);
box.add(widget);
box.show_all();
}],
['onRemoved', (box, id) => {
if (!box._items.has(id))
return;
const widget = SysTrayItem(item);
box._items.set(id, widget);
box.add(widget);
box.show_all();
}],
['onRemoved', (box, id) => {
if (!box._items.has(id))
return;
box._items.get(id).destroy();
box._items.delete(id);
}],
],
connections: [
[SystemTray, (box, id) => box._onAdded(box, id), 'added'],
[SystemTray, (box, id) => box._onRemoved(box, id), 'removed'],
],
box._items.get(id).destroy();
box._items.delete(id);
}],
],
connections: [
[SystemTray, (box, id) => box._onAdded(box, id), 'added'],
[SystemTray, (box, id) => box._onRemoved(box, id), 'removed'],
],
}),
Separator(12),
],
}),
});