diff --git a/changelog/next.md b/changelog/next.md index 9827fa08..210409b0 100644 --- a/changelog/next.md +++ b/changelog/next.md @@ -7,3 +7,4 @@ - Fixed session lock crashes on sleep, wake, DPMS, and unlocking. - QsWindow.updatesEnabled makes sure windows are redrawn when set to true. - Fixed potential crashes from usage of `WindowsetProjection.screens` during monitor unplug. +- 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 627c369f..23c729df 100644 --- a/src/wayland/hyprland/ipc/connection.cpp +++ b/src/wayland/hyprland/ipc/connection.cpp @@ -714,6 +714,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(); @@ -742,6 +743,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; } }); }