ags(apps-window, osd): drop astal variables on ::destroy

This commit is contained in:
retrozinndev
2025-05-11 22:24:18 -03:00
parent b1eef4285f
commit 89fe8c36b3
2 changed files with 79 additions and 65 deletions
+1
View File
@@ -117,6 +117,7 @@ export const AppsWindow = (mon: number): (Widget.Window) => {
marginTop: 64,
onDestroy: () => {
searchSubscription?.();
searchString.drop();
flowboxConnections.map(id => flowbox.disconnect(id));
},
onKeyPressEvent: (_, event: Gdk.Event) => {
+78 -65
View File
@@ -7,73 +7,86 @@ export enum OSDModes {
BRIGHTNESS
}
let osdMode: Variable<OSDModes> = new Variable<OSDModes>(OSDModes.SINK);
let osdIcon: Binding<string | undefined> = osdMode().as((mode: OSDModes) => {
switch(mode) {
case OSDModes.SINK: return "󰕾";
case OSDModes.BRIGHTNESS: return "󰃠";
default: return "󱧣";
}
});
let osdMode: (Variable<OSDModes>|null);
let osdIcon: (Binding<string | undefined>|null);
export function setOSDMode(newMode: OSDModes): void {
if(!osdMode) return;
osdMode.set(newMode);
}
export const OSD = (mon: number) => new Widget.Window({
namespace: "osd",
layer: Astal.Layer.OVERLAY,
anchor: Astal.WindowAnchor.BOTTOM,
canFocus: false,
marginBottom: 80,
focusOnClick: false,
clickThrough: true,
monitor: mon,
child: new Widget.Box({
className: "osd",
children: [
new Widget.Label({
className: "icon",
label: osdIcon
} as Widget.LabelProps),
new Widget.Box({
className: "volume",
orientation: Gtk.Orientation.VERTICAL,
valign: Gtk.Align.CENTER,
children: [
new Widget.Label({
className: "device",
label: bind(Wireplumber.getDefault().getDefaultSink(), "name").as((name: string) =>
name || "Speaker"),
halign: Gtk.Align.CENTER
} as Widget.LabelProps),
new Widget.Box({
vexpand: false,
expand: false,
children: [
new Widget.LevelBar({
className: "levelbar",
width_request: 120,
value: bind(Wireplumber.getDefault().getDefaultSink(), "volume").as((volume: number) =>
Math.floor(volume * 100)),
maxValue: bind(Wireplumber.getWireplumber(), "defaultSpeaker").as(() =>
Wireplumber.getDefault().getMaxSinkVolume()),
vexpand: false,
expand: false,
halign: Gtk.Align.CENTER
} as Widget.LevelBarProps),
/*new Widget.Label({
className: "value",
label: bind(Wireplumber.getDefault().getDefaultSink(), "volume").as((volume: number) =>
`${Math.floor(volume * 100)}%`),
vexpand: false,
expand: false,
halign: Gtk.Align.CENTER
} as Widget.LabelProps)*/
]
} as Widget.BoxProps)
]
} as Widget.BoxProps)
]
} as Widget.BoxProps)
} as Widget.WindowProps);
export const OSD = (mon: number) => {
osdMode = new Variable<OSDModes>(OSDModes.SINK);
osdIcon = osdMode().as((mode: OSDModes) => {
switch(mode) {
case OSDModes.SINK: return "󰕾";
case OSDModes.BRIGHTNESS: return "󰃠";
default: return "󱧣";
}
});
return new Widget.Window({
namespace: "osd",
layer: Astal.Layer.OVERLAY,
anchor: Astal.WindowAnchor.BOTTOM,
canFocus: false,
marginBottom: 80,
focusOnClick: false,
clickThrough: true,
monitor: mon,
onDestroy: () => {
osdMode?.drop();
osdMode = null;
osdIcon = null;
},
child: new Widget.Box({
className: "osd",
children: [
new Widget.Label({
className: "icon",
label: osdIcon
} as Widget.LabelProps),
new Widget.Box({
className: "volume",
orientation: Gtk.Orientation.VERTICAL,
valign: Gtk.Align.CENTER,
children: [
new Widget.Label({
className: "device",
label: bind(Wireplumber.getDefault().getDefaultSink(), "name").as((name: string) =>
name || "Speaker"),
halign: Gtk.Align.CENTER
} as Widget.LabelProps),
new Widget.Box({
vexpand: false,
expand: false,
children: [
new Widget.LevelBar({
className: "levelbar",
width_request: 120,
value: bind(Wireplumber.getDefault().getDefaultSink(), "volume").as((volume: number) =>
Math.floor(volume * 100)),
maxValue: bind(Wireplumber.getWireplumber(), "defaultSpeaker").as(() =>
Wireplumber.getDefault().getMaxSinkVolume()),
vexpand: false,
expand: false,
halign: Gtk.Align.CENTER
} as Widget.LevelBarProps),
/*new Widget.Label({
className: "value",
label: bind(Wireplumber.getDefault().getDefaultSink(), "volume").as((volume: number) =>
`${Math.floor(volume * 100)}%`),
vexpand: false,
expand: false,
halign: Gtk.Align.CENTER
} as Widget.LabelProps)*/
]
} as Widget.BoxProps)
]
} as Widget.BoxProps)
]
} as Widget.BoxProps)
} as Widget.WindowProps);
}