2023-10-31 08:32:40 -04:00
|
|
|
import App from 'resource:///com/github/Aylur/ags/app.js';
|
2023-12-08 00:01:43 -05:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-31 08:32:40 -04:00
|
|
|
import { Revealer, Box, Window } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-11-28 00:50:58 -05:00
|
|
|
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-09-21 20:01:14 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
export default ({
|
2023-10-30 19:53:50 -04:00
|
|
|
// Revealer props
|
|
|
|
transition = 'slide_down',
|
|
|
|
transitionDuration = 500,
|
2023-11-14 09:36:39 -05:00
|
|
|
|
|
|
|
// Optional: execute a function whenever
|
|
|
|
// the window pops up or goes away
|
2023-11-21 01:29:46 -05:00
|
|
|
onOpen = () => { /**/ },
|
|
|
|
onClose = () => { /**/ },
|
2023-10-30 19:53:50 -04:00
|
|
|
|
|
|
|
// Window props
|
2023-10-17 13:47:02 -04:00
|
|
|
name,
|
2023-10-20 23:11:21 -04:00
|
|
|
child,
|
2023-12-08 00:01:43 -05:00
|
|
|
blur = false,
|
2023-10-24 17:26:38 -04:00
|
|
|
closeOnUnfocus = 'released',
|
2023-10-30 19:53:50 -04:00
|
|
|
visible = false,
|
|
|
|
layer = 'overlay',
|
2023-10-20 23:11:21 -04:00
|
|
|
...props
|
|
|
|
}) => {
|
|
|
|
const window = Window({
|
|
|
|
name,
|
2023-10-30 19:53:50 -04:00
|
|
|
layer,
|
2023-10-20 23:11:21 -04:00
|
|
|
visible: false,
|
|
|
|
...props,
|
2023-09-22 01:34:36 -04:00
|
|
|
|
2023-10-30 19:53:50 -04:00
|
|
|
setup: () => {
|
2023-12-08 00:01:43 -05:00
|
|
|
// Add way to make window open on startup
|
2023-10-30 19:53:50 -04:00
|
|
|
const id = App.connect('config-parsed', () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (visible) {
|
2023-10-30 19:53:50 -04:00
|
|
|
App.openWindow(name);
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-10-30 19:53:50 -04:00
|
|
|
App.disconnect(id);
|
|
|
|
});
|
2023-12-08 00:01:43 -05:00
|
|
|
|
|
|
|
if (blur) {
|
|
|
|
Hyprland.sendMessage('[[BATCH]] ' +
|
|
|
|
`keyword layerrule ignorealpha[0.97],${name}; ` +
|
|
|
|
`keyword layerrule blur,${name}`);
|
|
|
|
}
|
2023-10-30 19:53:50 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// Wrapping the revealer inside a box is needed
|
|
|
|
// to allocate some space for it even when not revealed
|
2023-10-20 23:11:21 -04:00
|
|
|
child: Box({
|
2023-11-21 01:29:46 -05:00
|
|
|
css: `
|
|
|
|
min-height:1px;
|
|
|
|
min-width:1px;
|
|
|
|
padding: 1px;
|
|
|
|
`,
|
2023-10-20 23:11:21 -04:00
|
|
|
child: Revealer({
|
|
|
|
transition,
|
2023-10-30 19:53:50 -04:00
|
|
|
transitionDuration,
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
setup: (self) => {
|
|
|
|
self.hook(App, (_, currentName, isOpen) => {
|
|
|
|
if (currentName === name) {
|
|
|
|
self.revealChild = isOpen;
|
2023-11-14 09:36:39 -05:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
if (isOpen) {
|
|
|
|
onOpen(window);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
timeout(transitionDuration, () => {
|
|
|
|
onClose(window);
|
|
|
|
});
|
|
|
|
}
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-12-17 00:01:58 -05:00
|
|
|
});
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-19 16:21:25 -05:00
|
|
|
child: child || Box(),
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
});
|
2023-10-30 19:53:50 -04:00
|
|
|
|
2023-12-12 11:21:27 -05:00
|
|
|
window.setXPos = (
|
|
|
|
alloc,
|
|
|
|
side = 'right',
|
|
|
|
) => {
|
|
|
|
const width = window.get_display()
|
|
|
|
.get_monitor_at_point(alloc.x, alloc.y)
|
|
|
|
.get_geometry().width;
|
|
|
|
|
|
|
|
window.margins = [
|
|
|
|
window.margins[0],
|
|
|
|
|
|
|
|
side === 'right' ?
|
|
|
|
(width - alloc.x - alloc.width) :
|
|
|
|
window.margins[1],
|
|
|
|
|
|
|
|
window.margins[2],
|
|
|
|
|
|
|
|
side === 'right' ?
|
|
|
|
window.margins[3] :
|
|
|
|
(alloc.x - alloc.width),
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
// Make getting the original child passed in this
|
|
|
|
// function easier when making more code for the widget
|
2023-11-19 16:21:25 -05:00
|
|
|
window.getChild = () => window.child.children[0].child;
|
2023-11-21 01:29:46 -05:00
|
|
|
window.setChild = (newChild) => {
|
|
|
|
window.child.children[0].child = newChild;
|
2023-11-28 00:50:58 -05:00
|
|
|
window.child.children[0].show_all();
|
2023-11-21 01:29:46 -05:00
|
|
|
};
|
2023-10-30 19:53:50 -04:00
|
|
|
|
|
|
|
// This is for my custom pointers.js
|
2023-10-24 17:26:38 -04:00
|
|
|
window.closeOnUnfocus = closeOnUnfocus;
|
2023-10-30 19:53:50 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
return window;
|
|
|
|
};
|