Aylur / astal

Building blocks for creating custom desktop shells
https://aylur.github.io/astal/
GNU Lesser General Public License v2.1
287 stars 37 forks source link

Hyprland focusedClient not updating upon opening a new client #131

Closed ojaskavathe closed 4 days ago

ojaskavathe commented 5 days ago

Describe the bug Upon opening a new client, the focused client retrieved from bind(hypr, "focusedClient") returns null. After switching to another client it returns just fine.

To Reproduce

const hypr = Hyprland.get_default();
const focusedClient = bind(hyprland, "focusedClient");

const setup = (self: Widget.Window) => {
  self.hook(focusedClient, () => {
    print(focusedClient.get().get_title());
  });
};

return <window setup={setup} />

Run and open a new client.

Output:

(gjs:57196): Gjs-CRITICAL **: 18:51:50.599: JS ERROR: TypeError: focusedClient.get() is null
# ...

Expected behavior The new client should be returned.

Additional context Seems like activewindowv2 is setting the focused client before windowtitlev2 updates Hyprland._clients? Feels like a sync issue.

const setup = (self: Widget.Window) => {
  self.hook(focusedClient, () => {
    hyprland.get_clients().forEach(c => print(c.title));
  });
};

The list returned by the above upon opening a new client doesn't include the newly open client.

FWIW the expected behavior can be obtained by directly connecting to hyprland's events, but I wasn't sure if this is intended behavior for focusedClient.