Added Power menu and show only the workspaces allocated to monitor

This commit is contained in:
Jas Singh
2024-06-09 18:40:51 -07:00
parent 3579e563b8
commit d695d9aa67
25 changed files with 784 additions and 383 deletions

View File

@@ -4,28 +4,52 @@ function range(length, start = 1) {
return Array.from({ length }, (_, i) => i + start);
}
const Workspaces = (ws) => {
const Workspaces = (monitor = -1, wsMap = {}, ws = 8) => {
const getWorkspacesForMonitor = (curWs) => {
if (
Object.keys(wsMap)
.map((mn) => Number(mn))
.includes(monitor)
) {
return wsMap[monitor].includes(curWs);
}
return true;
};
return {
component: Widget.Box({
class_name: "workspaces",
children: range(ws || 8).map((i) =>
Widget.Label({
attribute: i,
vpack: "center",
label: `${i}`,
setup: (self) =>
self.hook(hyprland, () => {
self.toggleClassName(
"active",
hyprland.active.workspace.id === i,
);
self.toggleClassName(
"occupied",
(hyprland.getWorkspace(i)?.windows || 0) > 0,
);
}),
children: range(ws || 8)
.filter((i) => getWorkspacesForMonitor(i))
.map((i) => {
return Widget.Label({
attribute: i,
vpack: "center",
label: `${i}`,
setup: (self) =>
self.hook(hyprland, () => {
// console.log(`currentMonitor: ${monitor}`);
console.log(i);
console.log(JSON.stringify(hyprland.getWorkspace(i), null, 2));
if (hyprland.getWorkspace(i)) {
// console.log(`currentMonitor: ${monitor}`);
}
self.toggleClassName(
"active",
hyprland.active.workspace.id === i,
);
self.toggleClassName(
"occupied",
(hyprland.getWorkspace(i)?.windows || 0) > 0,
);
const isCurrentMonitor =
monitor !== -1 &&
hyprland.getWorkspace(i)?.monitorID !== monitor;
self.toggleClassName("hidden", isCurrentMonitor);
}),
});
}),
),
setup: (box) => {
if (ws === 0) {
box.hook(hyprland.active.workspace, () =>