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) => {
+20 -7
View File
@@ -7,8 +7,18 @@ 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);
export function setOSDMode(newMode: OSDModes): void {
if(!osdMode) return;
osdMode.set(newMode);
}
export const OSD = (mon: number) => {
osdMode = new Variable<OSDModes>(OSDModes.SINK);
osdIcon = osdMode().as((mode: OSDModes) => {
switch(mode) { switch(mode) {
case OSDModes.SINK: return "󰕾"; case OSDModes.SINK: return "󰕾";
case OSDModes.BRIGHTNESS: return "󰃠"; case OSDModes.BRIGHTNESS: return "󰃠";
@@ -16,11 +26,7 @@ let osdIcon: Binding<string | undefined> = osdMode().as((mode: OSDModes) => {
} }
}); });
export function setOSDMode(newMode: OSDModes): void { return new Widget.Window({
osdMode.set(newMode);
}
export const OSD = (mon: number) => new Widget.Window({
namespace: "osd", namespace: "osd",
layer: Astal.Layer.OVERLAY, layer: Astal.Layer.OVERLAY,
anchor: Astal.WindowAnchor.BOTTOM, anchor: Astal.WindowAnchor.BOTTOM,
@@ -29,6 +35,12 @@ export const OSD = (mon: number) => new Widget.Window({
focusOnClick: false, focusOnClick: false,
clickThrough: true, clickThrough: true,
monitor: mon, monitor: mon,
onDestroy: () => {
osdMode?.drop();
osdMode = null;
osdIcon = null;
},
child: new Widget.Box({ child: new Widget.Box({
className: "osd", className: "osd",
children: [ children: [
@@ -77,3 +89,4 @@ export const OSD = (mon: number) => new Widget.Window({
] ]
} as Widget.BoxProps) } as Widget.BoxProps)
} as Widget.WindowProps); } as Widget.WindowProps);
}