Skip to content

hyprland/ipc: prune toplevels missing from the clients reply - #1501

Open
sadsfae wants to merge 1 commit into
quickshell-mirror:masterfrom
sadsfae:fix/stale-toplevels
Open

sadsfae wants to merge 1 commit into
quickshell-mirror:masterfrom
sadsfae:fix/stale-toplevels

Conversation

@sadsfae

@sadsfae sadsfae commented Nov 16, 2026

Copy link
Copy Markdown

Describe your changes

refreshToplevels() now deletes toplevels that are not in the j/clients reply.
Entries can exist without a matching client because title and urgent events
create them before openwindow does, and Hyprland sends no closewindow for X11
helper windows it never mapped. The old code only added and updated, so those
entries stayed in Hyprland.toplevels until the shell restarted. This also
cleans up entries that a running session can still have after #1465.

Windows opened while the request was in flight can be missing from the reply,
so they are exempt from the prune.

Details and descisions

Same teardown as the closewindow handler, in two passes like refreshWorkspaces.
The in-flight guard covers windows that open during the request, so they are
not pruned just because an older reply omits them. #1490 does the opposite
side of the same race (a window that closes during the request is not re-added
from the stale reply); there is a small overlap in this function that needs a
rebase once one lands. #1465 stops title events from creating entries at all;
this PR prunes whatever already exists and keeps refreshes authoritative.
References #1450, #1268, #1465, #1490.

AI context The repro (socket2 event capture) and the patch were prepared with AI assistance. The submitter reviewed the code and wrote this description.

Open concerns

refreshToplevels only runs on shell start, config reload, and explicit calls
from shell QML, so state is reconciled at those points, not continuously.
With #1465 merged, the never-mapped class is prevented at creation; this PR
removes whatever is already there and keeps refreshes authoritative.

Participation

Happy to iterate on this and help test; the ghost windows showed up in the
window switcher I use daily.

@sadsfae

sadsfae commented Nov 21, 2026 •

Copy link
Copy Markdown
Author

Reopened; closed by accident.

@bmaltais

bmaltais commented Dec 2, 2026

Copy link
Copy Markdown

Hit this with mapped windows, not only the never-mapped windowtitlev2 helpers in #1450.

Two cmd.exe consoles from an LSW VM stayed in Hyprland.toplevels after hyprctl clients no longer listed them. A taskbar that only mirrors that model kept two window marks until the shell process was restarted. Quickshell 0.3.2 (revision 2b4501a, Omarchy package), Hyprland 0.57.2.

I did not see a closewindow in what I had logged, so I cannot say the event was lost rather than never sent. Either way the clients reply and the toplevel list disagreed, and the running shell never reconciled them. The prune here is what would drop those entries on the next refreshToplevels().

@sadsfae

sadsfae commented Dec 2, 2026

Copy link
Copy Markdown
Author

Confirmed, that case is covered. The prune is mapping-agnostic: refreshToplevels() now drops any toplevel whose address is missing from the j/clients reply (src/wayland/hyprland/ipc/connection.cpp), so the two cmd.exe entries vanish on the next refresh whether or not closewindow ever arrived. No need to know if the event was lost or never sent, the clients reply is the source of truth.

One timing note: refreshToplevels() currently runs on connect and configreloaded, so mid-session the stale marks clear on the next config reload rather than instantly. If your setup shows them persisting past that after this head (b125150), reopen the thread with a log and we can trigger reconciliation earlier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants