nixos-configs/devices/wim/config/ags/js/misc/popup.js

86 lines
2.3 KiB
JavaScript
Raw Normal View History

import App from 'resource:///com/github/Aylur/ags/app.js';
import { Revealer, Box, Window } from 'resource:///com/github/Aylur/ags/widget.js';
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
export default ({
2023-10-30 19:53:50 -04:00
// Revealer props
transition = 'slide_down',
transitionDuration = 500,
// Optional: execute a function whenever
// the window pops up or goes away
onOpen = () => { /**/ },
onClose = () => { /**/ },
2023-10-30 19:53:50 -04:00
// Window props
name,
child,
closeOnUnfocus = 'released',
2023-10-30 19:53:50 -04:00
visible = false,
layer = 'overlay',
...props
}) => {
const window = Window({
name,
2023-10-30 19:53:50 -04:00
layer,
visible: false,
...props,
2023-10-30 19:53:50 -04:00
// Add way to make window open on startup
setup: () => {
const id = App.connect('config-parsed', () => {
if (visible) {
2023-10-30 19:53:50 -04:00
App.openWindow(name);
}
2023-10-30 19:53:50 -04:00
App.disconnect(id);
});
},
// Wrapping the revealer inside a box is needed
// to allocate some space for it even when not revealed
child: Box({
css: `
min-height:1px;
min-width:1px;
padding: 1px;
`,
child: Revealer({
transition,
2023-10-30 19:53:50 -04:00
transitionDuration,
connections: [[App, (rev, currentName, isOpen) => {
if (currentName === name) {
rev.revealChild = isOpen;
if (isOpen) {
onOpen(child);
}
else {
timeout(transitionDuration, () => {
onClose(child);
});
}
}
}]],
child: child || Box(),
}),
}),
});
2023-10-30 19:53:50 -04:00
// Make getting the original child passed in this
// function easier when making more code for the widget
window.getChild = () => window.child.children[0].child;
window.setChild = (newChild) => {
window.child.children[0].child = newChild;
window.child.children[0].show_all();
};
2023-10-30 19:53:50 -04:00
// This is for my custom pointers.js
window.closeOnUnfocus = closeOnUnfocus;
2023-10-30 19:53:50 -04:00
return window;
};