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-12-18 23:20:32 -05:00
|
|
|
/**
|
|
|
|
* @typedef {import('types/widgets/revealer').RevealerProps} RevProp
|
|
|
|
* @typedef {import('types/widgets/window').WindowProps} WinProp
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {WinProp & {
|
|
|
|
* transition?: RevProp['transition']
|
|
|
|
* transition_duration?: RevProp['transition_duration']
|
|
|
|
* onOpen?: function
|
|
|
|
* onClose?: function
|
|
|
|
* blur?: boolean
|
|
|
|
* close_on_unfocus?: 'none'|'stay'|'released'|'clicked'
|
|
|
|
* }} o
|
|
|
|
*/
|
2023-10-17 13:47:02 -04:00
|
|
|
export default ({
|
2023-10-30 19:53:50 -04:00
|
|
|
transition = 'slide_down',
|
2023-12-18 23:20:32 -05:00
|
|
|
transition_duration = 500,
|
2023-12-20 17:14:07 -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-10-30 19:53:50 -04:00
|
|
|
visible = false,
|
|
|
|
layer = 'overlay',
|
2023-12-18 23:20:32 -05:00
|
|
|
blur = false,
|
|
|
|
close_on_unfocus = 'released',
|
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-12-18 23:20:32 -05:00
|
|
|
attribute: {
|
2023-12-20 17:14:07 -05:00
|
|
|
/**
|
|
|
|
* @param {typeof imports.gi.Gtk.Allocation} alloc
|
|
|
|
* @param {'left'|'right'} side
|
|
|
|
*/
|
2023-12-18 23:20:32 -05:00
|
|
|
set_x_pos: (
|
2023-12-20 17:14:07 -05:00
|
|
|
alloc,
|
2023-12-18 23:20:32 -05:00
|
|
|
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),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
|
|
|
|
// @ts-expect-error
|
|
|
|
get_child: () => window.child.children[0].child,
|
|
|
|
|
2023-12-19 13:44:12 -05:00
|
|
|
/** @param {import('types/widget').Widget} new_child */
|
|
|
|
set_child: (new_child) => {
|
2023-12-18 23:20:32 -05:00
|
|
|
// @ts-expect-error
|
2023-12-19 13:44:12 -05:00
|
|
|
window.child.children[0].child = new_child;
|
2023-12-18 23:20:32 -05:00
|
|
|
// @ts-expect-error
|
|
|
|
window.child.children[0].show_all();
|
|
|
|
},
|
|
|
|
|
|
|
|
// This is for my custom pointers.js
|
|
|
|
close_on_unfocus,
|
|
|
|
},
|
|
|
|
|
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-12-18 23:20:32 -05:00
|
|
|
App.openWindow(String(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-12-18 23:20:32 -05:00
|
|
|
transition_duration,
|
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) {
|
2023-12-18 23:20:32 -05:00
|
|
|
self.reveal_child = isOpen;
|
2023-11-14 09:36:39 -05:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
if (isOpen) {
|
|
|
|
onOpen(window);
|
|
|
|
}
|
|
|
|
else {
|
2023-12-18 23:20:32 -05:00
|
|
|
timeout(Number(transition_duration), () => {
|
2023-12-17 00:01:58 -05:00
|
|
|
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-10-20 23:11:21 -04:00
|
|
|
return window;
|
|
|
|
};
|