diff --git a/changelog/next.md b/changelog/next.md index aaeaf1cc..e01844c0 100644 --- a/changelog/next.md +++ b/changelog/next.md @@ -2,3 +2,4 @@ - Fixed ScreencopyView not displaying when only lock surfaces are shown. - Fixed WlSessionLockSurface.visible crashing if accessed before backing surface creation. +- Fixed Hyprland.activeToplevel being null until the user changes focus, by seeding it from j/clients during init. diff --git a/src/wayland/hyprland/ipc/connection.cpp b/src/wayland/hyprland/ipc/connection.cpp index 0c98e350..a4c54bf4 100644 --- a/src/wayland/hyprland/ipc/connection.cpp +++ b/src/wayland/hyprland/ipc/connection.cpp @@ -715,6 +715,7 @@ void HyprlandIpc::refreshToplevels() { auto json = QJsonDocument::fromJson(resp).array(); const auto& mList = this->mToplevels.valueList(); + HyprlandToplevel* focusedToplevel = nullptr; for (auto entry: json) { auto object = entry.toObject().toVariantMap(); @@ -743,6 +744,17 @@ void HyprlandIpc::refreshToplevels() { auto* workspace = toplevel->bindableWorkspace().value(); if (workspace) workspace->insertToplevel(toplevel); + + // focusHistoryID == 0 marks the currently focused window. Hyprland's + // event socket only emits activewindowv2 on focus changes, so without + // this seed activeToplevel stays null until the user switches focus. + if (object.value("focusHistoryID").toInt() == 0) { + focusedToplevel = toplevel; + } + } + + if (focusedToplevel && this->bActiveToplevel.value() == nullptr) { + this->bActiveToplevel = focusedToplevel; } }); }