nixos-configs/config/ags/js/bar/workspaces.js

71 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2023-09-04 00:41:14 -04:00
const { Hyprland, Applications } = ags.Service;
const { execAsync } = ags.Utils;
const { Box, Button, Label, Revealer } = ags.Widget;
2023-09-04 00:41:14 -04:00
2023-09-11 19:57:21 -04:00
import { EventBox } from '../misc/cursorbox.js';
const Workspace = ({ i } = {}) =>
Revealer({
transition: "slide_right",
properties: [
['id', i],
],
child: EventBox({
tooltipText: `${i}`,
onPrimaryClickRelease: () => execAsync(`hyprctl dispatch workspace ${i}`).catch(print),
child: Box({
className: 'button',
child: Label(`${i}`),
connections: [
[Hyprland, btn => {
const occupied = Hyprland.getWorkspace(i)?.windows > 0;
btn.toggleClassName('active', Hyprland.active.workspace.id === i);
btn.toggleClassName('occupied', occupied);
btn.toggleClassName('empty', !occupied);
}]
],
}),
2023-09-04 00:41:14 -04:00
}),
});
export const Workspaces = Box({
className: 'workspaces',
2023-09-04 00:41:14 -04:00
children: [EventBox({
child: Box({
properties: [
['workspaces'],
['refresh', box => {
box.children.forEach(rev => rev.reveal_child = false);
box._workspaces.forEach(ws => {
ws.revealChild = true;
});
}],
['updateWs', box => {
Hyprland.workspaces.forEach(ws => {
let currentWs = box.children.find(ch => ch._id == ws.id);
if (!currentWs && ws.id > 0) {
box.add(Workspace({ i: ws.id}));
}
});
box.show_all();
// Make sure the order is correct
box._workspaces.forEach((workspace, i) => {
workspace.get_parent().reorder_child(workspace, i);
});
}],
],
2023-09-04 00:41:14 -04:00
connections: [[Hyprland, box => {
box._workspaces = box.children.filter(ch => {
return Hyprland.workspaces.find(ws => ws.id == ch._id)
}).sort((a, b) => a._id - b._id);
2023-09-04 00:41:14 -04:00
box._updateWs(box);
box._refresh(box);
2023-09-04 00:41:14 -04:00
}]],
}),
})],
});