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

109 lines
2.9 KiB
JavaScript
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 } from 'resource:///com/github/Aylur/ags/widget.js';
import PopupWindow from '../misc/popup.js';
import { WorkspaceRow, getWorkspaces, updateWorkspaces } from './workspaces.js';
import { Highlighter, updateCurrentWorkspace } from './current-workspace.js';
import { updateClients } from './clients.js';
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;
}
2023-12-23 01:14:21 -05:00
self?.attribute.update();
});
},
});
const widget = Overlay({
overlays: [highlighter, mainBox],
2023-12-23 01:14:21 -05:00
attribute: {
get_child: () => mainBox,
},
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) {
2023-12-23 01:14:21 -05:00
// @ts-expect-error
self.child.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;
};
export default () => {
const win = PopupWindow({
name: 'overview',
2023-12-08 00:01:43 -05:00
blur: true,
close_on_unfocus: 'none',
onOpen: () => {
win.attribute.set_child(Overview());
2023-12-23 01:14:21 -05:00
win.attribute.get_child().attribute.get_child().attribute.update();
},
});
return win;
};