2023-10-31 08:32:40 -04:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
2023-10-31 10:18:58 -04:00
|
|
|
import { execAsync, timeout } from 'resource:///com/github/Aylur/ags/utils.js';
|
2023-10-31 08:32:40 -04:00
|
|
|
import { Box, Overlay, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-09-04 00:41:14 -04:00
|
|
|
|
2023-10-17 13:47:02 -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-10-20 23:11:21 -04:00
|
|
|
Revealer({
|
|
|
|
transition: 'slide_right',
|
|
|
|
properties: [['id', i]],
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
child: EventBox({
|
|
|
|
tooltipText: `${i}`,
|
|
|
|
onPrimaryClickRelease: () => {
|
|
|
|
execAsync(`hyprctl dispatch workspace ${i}`)
|
|
|
|
.catch(print);
|
|
|
|
},
|
|
|
|
child: Box({
|
2023-10-29 12:15:08 -04:00
|
|
|
valign: 'center',
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'button',
|
|
|
|
connections: [[Hyprland, self => {
|
|
|
|
const occupied = Hyprland.getWorkspace(i)?.windows > 0;
|
|
|
|
self.toggleClassName('occupied', occupied);
|
|
|
|
self.toggleClassName('empty', !occupied);
|
|
|
|
}]],
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
});
|
2023-09-04 00:41:14 -04:00
|
|
|
|
2023-10-31 10:18:58 -04:00
|
|
|
export default () => {
|
|
|
|
const updateHighlight = () => {
|
|
|
|
const currentId = Hyprland.active.workspace.id;
|
|
|
|
const indicators = highlight.get_parent().get_children()[0].child.children;
|
|
|
|
const currentIndex = indicators.findIndex(w => w._id == currentId);
|
|
|
|
|
|
|
|
if (currentIndex < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
highlight.setStyle(`margin-left: ${16 + currentIndex * 30}px`);
|
|
|
|
};
|
|
|
|
const highlight = Box({
|
2023-10-29 13:40:37 -04:00
|
|
|
valign: 'center',
|
|
|
|
halign: 'start',
|
|
|
|
className: 'button active',
|
2023-10-31 10:18:58 -04:00
|
|
|
connections: [[Hyprland.active.workspace, updateHighlight]],
|
|
|
|
});
|
2023-10-29 13:40:37 -04:00
|
|
|
|
2023-10-31 10:18:58 -04:00
|
|
|
const widget = Overlay({
|
|
|
|
setup: self => {
|
|
|
|
self.set_overlay_pass_through(
|
|
|
|
self.get_children()[1],
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
overlays: [highlight],
|
|
|
|
child: EventBox({
|
|
|
|
child: Box({
|
|
|
|
className: 'workspaces',
|
|
|
|
properties: [
|
|
|
|
['workspaces'],
|
2023-09-20 20:25:52 -04:00
|
|
|
|
2023-10-31 10:18:58 -04:00
|
|
|
['refresh', self => {
|
|
|
|
self.children.forEach(rev => rev.reveal_child = false);
|
|
|
|
self._workspaces.forEach(ws => {
|
|
|
|
ws.revealChild = true;
|
|
|
|
});
|
|
|
|
}],
|
2023-09-20 20:25:52 -04:00
|
|
|
|
2023-10-31 10:18:58 -04:00
|
|
|
['updateWorkspaces', self => {
|
|
|
|
Hyprland.workspaces.forEach(ws => {
|
|
|
|
const currentWs = self.children.find(ch => ch._id == ws.id);
|
|
|
|
if (!currentWs && ws.id > 0)
|
|
|
|
self.add(Workspace({ i: ws.id }));
|
|
|
|
});
|
|
|
|
self.show_all();
|
2023-09-20 20:25:52 -04:00
|
|
|
|
2023-10-31 10:18:58 -04:00
|
|
|
// Make sure the order is correct
|
|
|
|
self._workspaces.forEach((workspace, i) => {
|
|
|
|
workspace.get_parent().reorder_child(workspace, i);
|
|
|
|
});
|
|
|
|
}],
|
|
|
|
],
|
|
|
|
connections: [[Hyprland, self => {
|
|
|
|
self._workspaces = self.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-10-31 10:18:58 -04:00
|
|
|
self._updateWorkspaces(self);
|
|
|
|
self._refresh(self);
|
|
|
|
|
|
|
|
// Make sure the highlight doesn't go too far
|
|
|
|
timeout(10, updateHighlight);
|
|
|
|
}]],
|
|
|
|
}),
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-10-31 10:18:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
};
|