nixos-configs/devices/wim/config/ags/ts/overview/main.ts

153 lines
4.3 KiB
TypeScript
Raw Normal View History

import App from 'resource:///com/github/Aylur/ags/app.js';
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import { Box, Overlay, Window } from 'resource:///com/github/Aylur/ags/widget.js';
import { WorkspaceRow, getWorkspaces, updateWorkspaces } from './workspaces.ts';
import { Highlighter, updateCurrentWorkspace } from './current-workspace.ts';
import { updateClients } from './clients.ts';
2024-01-13 11:15:08 -05:00
// Types
import AgsBox from 'types/widgets/box.ts';
import AgsOverlay from 'types/widgets/overlay.ts';
2024-01-13 11:15:08 -05:00
2023-11-07 10:56:12 -05:00
// TODO: have a 'page' for each monitor, arrows on both sides to loop through
export const Overview = () => {
const highlighter = Highlighter();
const mainBox = Box({
// Do this for scss hierarchy
2023-12-23 01:14:21 -05:00
class_name: 'overview',
css: 'all: unset',
vertical: true,
vpack: 'center',
hpack: 'center',
2023-12-23 01:14:21 -05:00
attribute: {
workspaces: [],
update: () => {
getWorkspaces(mainBox);
updateWorkspaces(mainBox);
updateClients(mainBox);
updateCurrentWorkspace(mainBox, highlighter);
},
},
children: [
Box({
vertical: true,
children: [
WorkspaceRow('normal', 0),
],
}),
Box({
vertical: true,
children: [
WorkspaceRow('special', 0),
],
}),
],
setup: (self) => {
self.hook(Hyprland, () => {
2023-12-23 01:14:21 -05:00
if (!App.getWindow('overview')?.visible) {
return;
}
self.attribute.update();
});
},
});
const widget = Overlay({
overlays: [highlighter, mainBox],
2023-12-23 01:14:21 -05:00
attribute: {
get_child: () => mainBox,
closing: false,
2023-12-23 01:14:21 -05:00
},
// Make size of overlay big enough for content
child: Box({
2023-12-23 01:14:21 -05:00
class_name: 'overview',
css: `
min-height: ${mainBox.get_allocated_height()}px;
min-width: ${mainBox.get_allocated_width()}px;
`,
}),
// TODO: throttle this?
setup: (self) => {
self.on('get-child-position', (_, ch) => {
if (ch === mainBox && !self.attribute.closing) {
2024-01-13 11:15:08 -05:00
(self.child as AgsBox).setCss(`
transition: min-height 0.2s ease, min-width 0.2s ease;
min-height: ${mainBox.get_allocated_height()}px;
min-width: ${mainBox.get_allocated_width()}px;
`);
}
});
},
});
return widget;
};
// FIXME: can't use PopupWindow because this is an overlay already
export default () => {
const transition_duration = 800;
const win = Window({
name: 'overview',
visible: false,
// Needs this to have space
// allocated at the start
child: Box({
css: `
min-height: 1px;
min-width: 1px;
padding: 1px;
`,
}),
attribute: { close_on_unfocus: 'none' },
setup: (self) => {
const name = 'overview';
Hyprland.sendMessage('[[BATCH]] ' +
`keyword layerrule ignorealpha[0.97],${name}; ` +
`keyword layerrule blur,${name}`);
self.hook(App, (_, currentName, isOpen) => {
if (currentName === self.name) {
if (isOpen) {
self.child = Overview();
self.show_all();
2024-01-13 11:15:08 -05:00
(self.child as AgsOverlay)
.attribute.get_child().attribute.update();
}
else {
2024-01-13 11:15:08 -05:00
(self.child as AgsOverlay).attribute.closing = true;
((self.child as AgsOverlay)
.child as AgsBox).css = `
min-height: 1px;
min-width: 1px;
transition: all
${transition_duration - 10}ms ease;
`;
}
}
});
},
});
return win;
};