feat(ags): use revealers to make workspace widget cleaner

This commit is contained in:
matt1432 2023-09-04 12:44:14 -04:00
parent a4fd6091b4
commit b74db6f1fa
2 changed files with 33 additions and 36 deletions

View file

@ -7,7 +7,9 @@ const { execAsync, lookUpIcon } = ags.Utils;
const { Box, Button, EventBox, Label, Icon } = ags.Widget; const { Box, Button, EventBox, Label, Icon } = ags.Widget;
export const Workspace = ({ i, } = {}) => export const Workspace = ({ i, } = {}) =>
EventBox({ ags.Widget.Revealer({
transition: "slide_right",
child: EventBox({
onPrimaryClickRelease: () => execAsync(`hyprctl dispatch workspace ${i}`).catch(print), onPrimaryClickRelease: () => execAsync(`hyprctl dispatch workspace ${i}`).catch(print),
onHover: box => { onHover: box => {
box.window.set_cursor(Gdk.Cursor.new_from_name(display, 'pointer')); box.window.set_cursor(Gdk.Cursor.new_from_name(display, 'pointer'));
@ -28,6 +30,7 @@ EventBox({
}] }]
], ],
}), }),
}),
}); });
var prev = Hyprland.active.workspace.id; var prev = Hyprland.active.workspace.id;
@ -42,29 +45,20 @@ export const Workspaces = props => Box({
new Promise(resolve => { new Promise(resolve => {
Hyprland.workspaces.forEach(ws => { Hyprland.workspaces.forEach(ws => {
if (ws.id > 0) { if (ws.id > 0) workspaces.push(ws);
workspaces.push(ws);
}
}); });
resolve(); resolve();
}).then(value => { }).then(value => {
if (workspaces.length > 0) { box.children.forEach(rev => rev.reveal_child = false);
let currentId = Hyprland.active.workspace.id; workspaces.forEach(ws => {
let qtyChange = Number(currentId - box.children.length); box.children[ws.id - 1].reveal_child = true;
});
if (qtyChange != 0 && currentId != prev) {
box.get_children().forEach(ch => ch.destroy());
box.children = Array.from(
{ length: Math.max(...workspaces.map(ws => ws.id)) },
(_, i) => i + 1).map(i => Workspace({ i: i}));
}
prev = currentId;
}
}); });
}]], }]],
children: Array.from({ length: 10 }, (_, i) => i + 1).map(i => Workspace({ i: i})),
}), }),
})], })],
}); });

View file

@ -16,12 +16,15 @@
.empty { .empty {
border: none; border: none;
transition: border-color 0.3s ease-in-out;
} }
.occupied { .occupied {
border: 2px solid $bg; border: 2px solid $bg;
background: $contrastbg; background: $contrastbg;
transition: border-color 0.3s ease-in-out;
} }
.active { .active {
border: 2px solid #50fa7b; border: 2px solid #50fa7b;
transition: border-color 0.3s ease-in-out;
} }
} }