forked from Shinonome/dots-hyprland
ags: update to new syntax
This commit is contained in:
@@ -1,24 +1,28 @@
|
||||
const { GLib, Gdk, Gtk } = imports.gi;
|
||||
import { Service, Widget } from '../../imports.js';
|
||||
const { Gtk } = imports.gi;
|
||||
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
||||
import SystemTray from 'resource:///com/github/Aylur/ags/service/systemtray.js';
|
||||
const { Box, Icon, Button, Revealer } = Widget;
|
||||
const { Gravity } = imports.gi.Gdk;
|
||||
|
||||
const revealerDuration = 200;
|
||||
|
||||
const SysTrayItem = item => Button({
|
||||
const SysTrayItem = (item) => Button({
|
||||
className: 'bar-systray-item',
|
||||
child: Icon({
|
||||
hpack: 'center',
|
||||
binds: [['icon', item, 'icon']],
|
||||
setup: (self) => Utils.timeout(1, () => {
|
||||
const styleContext = self.get_parent().get_style_context();
|
||||
const width = styleContext.get_property('min-width', Gtk.StateFlags.NORMAL);
|
||||
const height = styleContext.get_property('min-height', Gtk.StateFlags.NORMAL);
|
||||
self.size = Math.max(width, height, 1); // im too lazy to add another box lol
|
||||
}),
|
||||
setup: (self) => {
|
||||
self.hook(item, (self) => self.icon = item.icon);
|
||||
Utils.timeout(1, () => {
|
||||
const styleContext = self.get_parent().get_style_context();
|
||||
const width = styleContext.get_property('min-width', Gtk.StateFlags.NORMAL);
|
||||
const height = styleContext.get_property('min-height', Gtk.StateFlags.NORMAL);
|
||||
self.size = Math.max(width, height, 1); // im too lazy to add another box lol
|
||||
})
|
||||
},
|
||||
}),
|
||||
binds: [['tooltipMarkup', item, 'tooltip-markup']],
|
||||
setup: (self) => self
|
||||
.hook(item, (self) => self.tooltipMarkup = item['tooltip-markup'])
|
||||
,
|
||||
onClicked: btn => item.menu.popup_at_widget(btn, Gravity.SOUTH, Gravity.NORTH, null),
|
||||
onSecondaryClick: btn => item.menu.popup_at_widget(btn, Gravity.SOUTH, Gravity.NORTH, null),
|
||||
});
|
||||
@@ -26,34 +30,34 @@ const SysTrayItem = item => Button({
|
||||
export const Tray = (props = {}) => {
|
||||
const trayContent = Box({
|
||||
className: 'margin-right-5 spacing-h-15',
|
||||
properties: [
|
||||
['items', new Map()],
|
||||
['onAdded', (box, id) => {
|
||||
attribute: {
|
||||
items: new Map(),
|
||||
onAdded: (box, id) => {
|
||||
const item = SystemTray.getItem(id);
|
||||
if (!item) return;
|
||||
item.menu.className = 'menu';
|
||||
if (box._items.has(id) || !item)
|
||||
if (box.attribute.items.has(id) || !item)
|
||||
return;
|
||||
const widget = SysTrayItem(item);
|
||||
box._items.set(id, widget);
|
||||
box.attribute.items.set(id, widget);
|
||||
box.add(widget);
|
||||
box.show_all();
|
||||
if (box._items.size === 1)
|
||||
if (box.attribute.items.size === 1)
|
||||
trayRevealer.revealChild = true;
|
||||
}],
|
||||
['onRemoved', (box, id) => {
|
||||
if (!box._items.has(id))
|
||||
},
|
||||
onRemoved: (box, id) => {
|
||||
if (!box.attribute.items.has(id))
|
||||
return;
|
||||
|
||||
box._items.get(id).destroy();
|
||||
box._items.delete(id);
|
||||
if (box._items.size === 0)
|
||||
box.attribute.items.get(id).destroy();
|
||||
box.attribute.items.delete(id);
|
||||
if (box.attribute.items.size === 0)
|
||||
trayRevealer.revealChild = false;
|
||||
}],
|
||||
],
|
||||
},
|
||||
},
|
||||
setup: (self) => self
|
||||
.hook(SystemTray, (box, id) => box._onAdded(box, id), 'added')
|
||||
.hook(SystemTray, (box, id) => box._onRemoved(box, id), 'removed')
|
||||
.hook(SystemTray, (box, id) => box.attribute.onAdded(box, id), 'added')
|
||||
.hook(SystemTray, (box, id) => box.attribute.onRemoved(box, id), 'removed')
|
||||
,
|
||||
});
|
||||
const trayRevealer = Widget.Revealer({
|
||||
|
||||
Reference in New Issue
Block a user