Aylur / ags

A customizable and extensible shell
GNU General Public License v3.0
1.74k stars 95 forks source link

Issues with trying to detect a urgent workspace #420

Closed TheKamboy closed 1 month ago

TheKamboy commented 1 month ago

I'm not good with typescript so I can't explain much.

Here's the code for the workspaces thing on my bar:

const Workspaces = (ws: number) => Widget.Box({
    children: range(ws || 20).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)
            self.toggleClassName("urgent", hyprland.getWorkspace(i)?.lastwindow === hyprland.urgent_window)
        }),
    })),
    setup: box => {
        if (ws === 0) {
            box.hook(hyprland.active.workspace, () => box.children.map(btn => {
                btn.visible = hyprland.workspaces.some(ws => ws.id === btn.attribute)
            }))
        }
    },
})

With this code, this is the result: image

What do I do so that it only makes it red when the workspace is urgent?

kotontrion commented 1 month ago

urgent_windowis a signal and not a property. neither Hyprland nor ags keeps track of which windows/worksapces are urgent. You have to do that yourself. I modified your code to do that. I didn't test this but it might give you the right idea.

const Workspaces = (ws: number) => Widget.Box({
    children: range(ws || 20).map(i => Widget.Label({
        attribute: {
            id: i,
            isUrgent: false,
        },
        vpack: "center",
        label: `${i}`,
        setup: self => {
            self.hook(hyprland, () => {
                //unset urgent if ws gets focus
                if(hyprland.active.workspace.id === i) self.attribute.isUrgent = false
                self.toggleClassName("active", hyprland.active.workspace.id === i)
                self.toggleClassName("occupied", (hyprland.getWorkspace(i)?.windows || 0) > 0)
                self.toggleClassName("urgent", self.attribute.isUrgent)
            })
            self.hook(hyprland, (_, address) => {
                //set urgent on ws containing the urgent window
                if(hyprland.getClient(address).workspace.id == self.attribute.id) {
                    self.attribute.isUrgent = true
                    self.toggleClassName("urgent", self.attribute.isUrgent)
                }
            }, "urgent-window")
        },
    })),
    setup: box => {
        if (ws === 0) {
            box.hook(hyprland.active.workspace, () => box.children.map(btn => {
                btn.visible = hyprland.workspaces.some(ws => ws.id === btn.attribute.id)
            }))
        }
    },
})
TheKamboy commented 1 month ago

It worked! Thanks!