nixos-configs/modules/ags/config/ts/osd/main.ts

79 lines
1.6 KiB
TypeScript
Raw Normal View History

const { timeout } = Utils;
const { Stack } = Widget;
2023-11-10 23:51:50 -05:00
import PopupWindow from '../misc/popup.ts';
2024-01-29 20:56:56 -05:00
// Types
2024-02-27 18:27:47 -05:00
import { BoxGeneric } from 'global-types';
2023-11-10 23:51:50 -05:00
// Import all the OSDs as an array
2024-02-27 18:27:47 -05:00
const OSDList = [] as Array<() => BoxGeneric>;
import * as Modules from './osds.ts';
for (const osd in Modules) {
OSDList.push(Modules[osd]);
} // Array
2023-11-10 23:51:50 -05:00
const HIDE_DELAY = 2000;
const transition_duration = 300;
2023-11-10 23:51:50 -05:00
const OSDs = () => {
2023-11-10 23:51:50 -05:00
const stack = Stack({
transition: 'over_up_down',
transition_duration,
2023-12-21 01:25:59 -05:00
attribute: {
popup: (osd: string) => {
if (!osd) {
//
}
},
},
2023-11-10 23:51:50 -05:00
});
2024-02-03 14:25:47 -05:00
// Send reference of stack to all children
stack.children = Object.fromEntries(
OSDList.map((osd) => {
2024-02-27 18:27:47 -05:00
const widget = osd();
return [widget.name, widget];
}),
2024-02-03 14:25:47 -05:00
);
stack.show_all();
// Delay popup method so it
// doesn't show any OSDs at launch
timeout(1000, () => {
let count = 0;
2023-11-10 23:51:50 -05:00
stack.attribute.popup = (osd: string) => {
++count;
stack.shown = osd;
App.openWindow('win-osd');
2023-11-10 23:51:50 -05:00
timeout(HIDE_DELAY, () => {
--count;
2023-11-10 23:51:50 -05:00
if (count === 0) {
App.closeWindow('win-osd');
}
});
};
globalThis['popup_osd'] = stack.attribute.popup;
});
return stack;
2023-11-10 23:51:50 -05:00
};
export default () => PopupWindow({
name: 'osd',
anchor: ['bottom'],
exclusivity: 'ignore',
close_on_unfocus: 'stay',
transition: 'slide bottom',
child: OSDs(),
});