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