2023-10-02 12:06:35 -04:00
|
|
|
import { Hyprland, Utils, Widget } from '../../imports.js';
|
|
|
|
const { Box, Label, Revealer } = Widget;
|
|
|
|
const { execAsync } = Utils;
|
2023-09-04 00:41:14 -04:00
|
|
|
|
2023-09-11 19:57:21 -04:00
|
|
|
import { EventBox } from '../misc/cursorbox.js';
|
2023-09-05 13:27:29 -04:00
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-09-10 23:15:11 -04:00
|
|
|
const Workspace = ({ i } = {}) =>
|
2023-09-05 13:27:29 -04:00
|
|
|
Revealer({
|
2023-09-04 12:44:14 -04:00
|
|
|
transition: "slide_right",
|
2023-09-20 20:25:52 -04:00
|
|
|
properties: [
|
|
|
|
['id', i],
|
|
|
|
],
|
2023-09-04 12:44:14 -04:00
|
|
|
child: EventBox({
|
2023-09-20 16:07:17 -04:00
|
|
|
tooltipText: `${i}`,
|
2023-09-04 12:44:14 -04:00
|
|
|
onPrimaryClickRelease: () => execAsync(`hyprctl dispatch workspace ${i}`).catch(print),
|
|
|
|
child: Box({
|
|
|
|
className: 'button',
|
|
|
|
connections: [
|
|
|
|
[Hyprland, btn => {
|
2023-09-10 15:49:37 -04:00
|
|
|
const occupied = Hyprland.getWorkspace(i)?.windows > 0;
|
|
|
|
btn.toggleClassName('active', Hyprland.active.workspace.id === i);
|
2023-09-04 12:44:14 -04:00
|
|
|
btn.toggleClassName('occupied', occupied);
|
|
|
|
btn.toggleClassName('empty', !occupied);
|
|
|
|
}]
|
|
|
|
],
|
|
|
|
}),
|
2023-09-04 00:41:14 -04:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
2023-09-10 23:15:11 -04:00
|
|
|
export const Workspaces = Box({
|
2023-09-05 13:27:29 -04:00
|
|
|
className: 'workspaces',
|
2023-09-04 00:41:14 -04:00
|
|
|
children: [EventBox({
|
|
|
|
child: Box({
|
2023-09-20 20:25:52 -04:00
|
|
|
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 => {
|
2023-09-20 20:25:52 -04:00
|
|
|
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
|
|
|
|
2023-09-20 20:25:52 -04:00
|
|
|
box._updateWs(box);
|
|
|
|
box._refresh(box);
|
2023-09-04 00:41:14 -04:00
|
|
|
}]],
|
|
|
|
}),
|
|
|
|
})],
|
|
|
|
});
|