feat(ags): add battery and systray modules. change default outline to tray items

This commit is contained in:
matt1432 2023-09-06 17:36:26 -04:00
parent 7ccf86d7a6
commit fe2404d439
7 changed files with 174 additions and 10 deletions
config/ags/js/bar

View file

@ -9,6 +9,8 @@ import { TabletToggle } from './tablet-toggle.js';
import { QsToggle } from './quick-settings.js';
import { NotifButton } from './notif-button.js';
import { Clock } from './clock.js';
import { SysTray } from './systray.js';
import { BatteryLabel } from './battery.js';
export const Bar = Window({
name: 'left-bar',
@ -41,6 +43,10 @@ export const Bar = Window({
Separator(12),
SysTray,
Separator(12),
Workspaces,
],
@ -53,6 +59,10 @@ export const Bar = Window({
Box({
halign: 'end',
children: [
BatteryLabel(),
Separator(12),
Clock,
Separator(12),

View file

@ -0,0 +1,47 @@
const { SystemTray } = ags.Service;
const { Box, Button, Icon, MenuItem } = ags.Widget;
const { Gtk } = imports.gi;
// this one uses a MenuBar and shouldn't throw that destroyed widget warning
const SysTrayItem = item => MenuItem({
className: 'tray-item',
child: Icon({
size: 24,
}),
submenu: item.menu,
connections: [[item, btn => {
btn.child.icon = item.icon;
btn.tooltipMarkup = item.tooltipMarkup;
}]]
});
export const SysTrayModule = () => 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;
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'],
],
});
export const SysTray = SysTrayModule();