ags icon indicating copy to clipboard operation
ags copied to clipboard

Hyprland Workspaces Bind Triggers Twice

Open BowlBird opened this issue 1 year ago • 4 comments

Hello!

I noticed some odd behavior which, while technically not causing any issues can significantly degrade performance depending on the complexity of any given widget.

I have this test widget:

const WorkspaceTest = () => Widget.Label({
    label: Hyprland.bind('workspaces').transform(_ => {
        console.log("here")
        return ""
    })
})

that demonstrates the behavior. Essentially, on either switching to another workspace, or opening a new window (but NOT closing a window or updating a window's state, these acts normally), here will in this case be printed twice. I believe that it should only be printed once as there has only been one update in both of these scenarios.

thanks!

BowlBird avatar Jan 02 '24 04:01 BowlBird

Are you sure you are not instantiating two of these? it works as expected when I tried

let count = 0;
Hyprland.connect('notify::workspaces', () => {
    print(count++)
})

Aylur avatar Jan 06 '24 13:01 Aylur

This behavior only occurs when using the bind function. (in fact none of the workspaces services like workspace-added, or workspace-removed seem to do anything either).

const Workspaces = () => Widget.Box({
    class_name: 'workspaces',
    children: Hyprland.bind('workspaces').transform(_ => {
        console.log("Hello")
    })
})

this was the bit of code I used to test it again. You're right that the connect method works normally, however it is quite difficult to use anything other than the bind method I have found.

BowlBird avatar Jan 07 '24 02:01 BowlBird

Hyprland.bind('workspaces').transform() will result to Hyprland.connect('notify::workspaces'), so the two snippets are essentially same I tried your snippet too, and It works as expected for me, but I discovered that changing a song on the spotify client indeed fires it off twice because the windowtitle event is signaled twice from the Hyprland socket.

I think this is an issue with some clients

Hyprland.connect('event', (_, e, a) => print(a, e))

Aylur avatar Jan 07 '24 17:01 Aylur

Are you using Hyprland? Just moving between windows or switching workspaces triggers it for me

BowlBird avatar Jan 11 '24 01:01 BowlBird