2023-10-31 08:32:40 -04:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-13 13:19:14 -05:00
|
|
|
import { 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-11-16 00:48:50 -05:00
|
|
|
import EventBox from '../../misc/cursorbox.js';
|
2023-09-05 13:27:29 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const URGENT_DURATION = 1000;
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const Workspace = ({ i } = {}) => {
|
|
|
|
return Revealer({
|
2023-10-20 23:11:21 -04:00
|
|
|
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}`,
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
onPrimaryClickRelease: () => {
|
|
|
|
Hyprland.sendMessage(`dispatch workspace ${i}`);
|
|
|
|
},
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
child: Box({
|
2023-11-06 18:37:23 -05:00
|
|
|
vpack: 'center',
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'button',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
setup: (self) => {
|
|
|
|
self.update = (addr) => {
|
2023-11-04 17:37:46 -04:00
|
|
|
const occupied = Hyprland.getWorkspace(i)?.windows > 0;
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-04 17:37:46 -04:00
|
|
|
self.toggleClassName('occupied', occupied);
|
|
|
|
self.toggleClassName('empty', !occupied);
|
|
|
|
|
|
|
|
// Deal with urgent windows
|
2023-11-07 12:00:53 -05:00
|
|
|
if (Hyprland.getClient(addr)?.workspace.id === i) {
|
2023-11-04 17:37:46 -04:00
|
|
|
self.toggleClassName('urgent', true);
|
2023-11-07 12:00:53 -05:00
|
|
|
|
|
|
|
// Only show for a sec when urgent is current workspace
|
2023-11-21 01:29:46 -05:00
|
|
|
if (Hyprland.active.workspace.id === i) {
|
|
|
|
timeout(URGENT_DURATION, () => {
|
|
|
|
self.toggleClassName('urgent', false);
|
|
|
|
});
|
|
|
|
}
|
2023-11-07 12:00:53 -05:00
|
|
|
}
|
2023-11-04 17:37:46 -04:00
|
|
|
};
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-04 17:37:46 -04:00
|
|
|
connections: [
|
2023-11-21 01:29:46 -05:00
|
|
|
[Hyprland, (self) => self.update()],
|
2023-11-04 17:37:46 -04:00
|
|
|
|
|
|
|
// Deal with urgent windows
|
2023-11-21 01:29:46 -05:00
|
|
|
[Hyprland, (self, a) => self.update(a), 'urgent-window'],
|
|
|
|
[Hyprland.active.workspace, (self) => {
|
|
|
|
if (Hyprland.active.workspace.id === i) {
|
2023-11-04 17:37:46 -04:00
|
|
|
self.toggleClassName('urgent', false);
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-04 17:37:46 -04:00
|
|
|
}],
|
|
|
|
],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
});
|
2023-11-21 01:29:46 -05:00
|
|
|
};
|
2023-09-04 00:41:14 -04:00
|
|
|
|
2023-10-31 10:18:58 -04:00
|
|
|
export default () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
const L_PADDING = 16;
|
|
|
|
const WS_WIDTH = 30;
|
|
|
|
|
|
|
|
const updateHighlight = (self) => {
|
2023-10-31 10:18:58 -04:00
|
|
|
const currentId = Hyprland.active.workspace.id;
|
2023-11-21 01:29:46 -05:00
|
|
|
const indicators = self.get_parent().get_children()[0].child.children;
|
|
|
|
const currentIndex = indicators.findIndex((w) => w._id === currentId);
|
2023-10-31 10:18:58 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
if (currentIndex < 0) {
|
2023-10-31 10:18:58 -04:00
|
|
|
return;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-10-31 10:18:58 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
self.setCss(`margin-left: ${L_PADDING + (currentIndex * WS_WIDTH)}px`);
|
2023-10-31 10:18:58 -04:00
|
|
|
};
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-31 10:18:58 -04:00
|
|
|
const highlight = Box({
|
2023-11-06 18:37:23 -05:00
|
|
|
vpack: 'center',
|
|
|
|
hpack: 'start',
|
2023-10-29 13:40:37 -04:00
|
|
|
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({
|
2023-11-15 16:24:42 -05:00
|
|
|
pass_through: true,
|
2023-10-31 10:18:58 -04:00
|
|
|
overlays: [highlight],
|
|
|
|
child: EventBox({
|
|
|
|
child: Box({
|
|
|
|
className: 'workspaces',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-31 10:18:58 -04:00
|
|
|
properties: [
|
|
|
|
['workspaces'],
|
2023-09-20 20:25:52 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
['refresh', (self) => {
|
|
|
|
self.children.forEach((rev) => {
|
|
|
|
rev.reveal_child = false;
|
|
|
|
});
|
|
|
|
self._workspaces.forEach((ws) => {
|
2023-10-31 10:18:58 -04:00
|
|
|
ws.revealChild = true;
|
|
|
|
});
|
|
|
|
}],
|
2023-09-20 20:25:52 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
['updateWorkspaces', (self) => {
|
|
|
|
Hyprland.workspaces.forEach((ws) => {
|
|
|
|
const currentWs = self.children.find((ch) => {
|
|
|
|
return ch._id === ws.id;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!currentWs && ws.id > 0) {
|
2023-10-31 10:18:58 -04:00
|
|
|
self.add(Workspace({ i: ws.id }));
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-10-31 10:18:58 -04:00
|
|
|
});
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}],
|
|
|
|
],
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
connections: [[Hyprland, (self) => {
|
|
|
|
self._workspaces = self.children.filter((ch) => {
|
|
|
|
return Hyprland.workspaces.find((ws) => {
|
|
|
|
return ws.id === ch._id;
|
|
|
|
});
|
2023-10-31 10:18:58 -04:00
|
|
|
}).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
|
2023-11-21 01:29:46 -05:00
|
|
|
const TEMP_TIMEOUT = 10;
|
|
|
|
|
|
|
|
timeout(TEMP_TIMEOUT, () => updateHighlight(highlight));
|
2023-10-31 10:18:58 -04:00
|
|
|
}]],
|
|
|
|
}),
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-10-31 10:18:58 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
};
|