Skip to content

Commit

Permalink
ags: make sortedClients a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
brckd committed Jul 6, 2024
1 parent 5d53342 commit 4bb753a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions modules/home/ags/widget/TaskBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function iconExists(name: string) {

const recentClients = Variable([...hyprland.clients.map((c) => c.address)]);
const recentWorkspaces = Variable([...hyprland.workspaces.map((w) => w.id)]);
const sortedClients = Utils.derive([recentClients, recentWorkspaces], () => sortClients(hyprland.clients))

hyprland.active.connect("changed", (active) => {
recentClients.setValue([active.client.address, ...recentClients.getValue()]);
Expand All @@ -59,12 +60,13 @@ export function getIcon(client: (typeof hyprland.clients)[number]) {
export const TaskBarItem = (client: (typeof hyprland.clients)[number]) =>
Widget.Button({
className: `tasks button ${client.address === hyprland.active.client.address ? "active" : ""}`,
attribute: {address: client.address},
child: Widget.Icon(getIcon(client)),
onClicked: () =>
hyprland.messageAsync(`dispatch focuswindow address:${client.address}`),
});

export function sortedClients(clients: typeof hyprland.clients) {
export function sortClients(clients: typeof hyprland.clients) {
const c = recentClients.getValue();
const w = recentWorkspaces.getValue();
return clients
Expand All @@ -74,14 +76,12 @@ export function sortedClients(clients: typeof hyprland.clients) {
.toSorted((a, b) => w.indexOf(a.workspace.id) - w.indexOf(b.workspace.id));
}


export const TaskBar = () =>
Widget.Box({
className: "tasks menu-bar",
spacing: 5,
children: Utils.merge(
[hyprland.bind("clients"), recentClients.bind(), recentWorkspaces.bind()],
(c) => sortedClients(c).map(TaskBarItem),
),
children: sortedClients.bind().as(c => c.map(TaskBarItem)),
});

export default TaskBar;

0 comments on commit 4bb753a

Please sign in to comment.