2023-10-16 17:06:19 -04:00
|
|
|
import { App, Utils, Widget } from '../../imports.js';
|
|
|
|
const { Window, Revealer } = Widget;
|
|
|
|
|
|
|
|
import Pointers from '../../services/pointers.js';
|
2023-09-12 14:42:53 -04:00
|
|
|
|
2023-09-25 12:43:36 -04:00
|
|
|
const ALWAYS_OPEN = [
|
|
|
|
'closer',
|
|
|
|
'bar',
|
|
|
|
'notifications',
|
2023-10-16 13:55:31 -04:00
|
|
|
'cornertl',
|
|
|
|
'cornertr',
|
|
|
|
'cornerbl',
|
|
|
|
'cornerbr'
|
2023-09-25 12:43:36 -04:00
|
|
|
];
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-10-16 18:11:19 -04:00
|
|
|
const closeAll = () => {
|
2023-10-02 12:06:35 -04:00
|
|
|
App.windows.forEach(w => {
|
2023-09-25 12:43:36 -04:00
|
|
|
if (!ALWAYS_OPEN.some(window => window === w.name))
|
2023-10-14 13:54:45 -04:00
|
|
|
App.closeWindow(w.name)
|
2023-09-13 19:04:23 -04:00
|
|
|
});
|
2023-10-14 13:54:45 -04:00
|
|
|
App.closeWindow('closer');
|
2023-09-13 19:04:23 -04:00
|
|
|
};
|
2023-10-17 13:47:02 -04:00
|
|
|
globalThis.closeAll = closeAll;
|
2023-09-12 09:37:48 -04:00
|
|
|
|
2023-10-16 17:06:19 -04:00
|
|
|
Pointers.connect('new-line', (_, out) => {
|
|
|
|
if (out) {
|
|
|
|
Utils.execAsync('hyprctl layers -j').then(layers => {
|
|
|
|
layers = JSON.parse(layers);
|
|
|
|
|
|
|
|
Utils.execAsync('hyprctl cursorpos -j').then(pos => {
|
|
|
|
pos = JSON.parse(pos);
|
|
|
|
|
|
|
|
Object.values(layers).forEach(key => {
|
|
|
|
let bar = key['levels']['3']
|
|
|
|
.find(n => n.namespace === "bar");
|
|
|
|
|
|
|
|
let widgets = key['levels']['3']
|
|
|
|
.filter(n => !ALWAYS_OPEN.includes(n.namespace));
|
|
|
|
|
|
|
|
if (pos.x > bar.x && pos.x < bar.x + bar.w &&
|
|
|
|
pos.y > bar.y && pos.y < bar.y + bar.h) {
|
|
|
|
|
|
|
|
// don't handle clicks when on bar
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
widgets.forEach(l => {
|
|
|
|
if (!(pos.x > l.x && pos.x < l.x + l.w &&
|
|
|
|
pos.y > l.y && pos.y < l.y + l.h)) {
|
|
|
|
closeAll();
|
|
|
|
return
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}).catch(print);
|
|
|
|
}).catch(print);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-10-16 18:11:19 -04:00
|
|
|
export default () => Window({
|
2023-09-11 19:57:21 -04:00
|
|
|
name: 'closer',
|
|
|
|
popup: true,
|
|
|
|
layer: 'top',
|
|
|
|
|
2023-10-16 17:06:19 -04:00
|
|
|
child: Revealer({
|
|
|
|
connections: [[App, (_, windowName, visible) => {
|
2023-10-02 12:06:35 -04:00
|
|
|
if (!Array.from(App.windows).some(w => w[1].visible &&
|
2023-09-25 12:43:36 -04:00
|
|
|
!ALWAYS_OPEN.some(window => window === w[0]))) {
|
2023-10-14 13:54:45 -04:00
|
|
|
App.closeWindow('closer');
|
2023-09-18 17:39:10 -04:00
|
|
|
}
|
2023-10-16 17:06:19 -04:00
|
|
|
|
|
|
|
if (windowName === 'closer') {
|
|
|
|
if (visible)
|
|
|
|
Pointers.startProc();
|
|
|
|
else
|
|
|
|
Pointers.killProc();
|
|
|
|
}
|
2023-09-18 17:39:10 -04:00
|
|
|
}]],
|
2023-09-11 19:57:21 -04:00
|
|
|
}),
|
|
|
|
});
|