Skip to content

fix: guard raise/focus/activate against unmanaged windows#520

Open
mayconrcmello wants to merge 1 commit intoforge-ext:mainfrom
mayconrcmello:fix/guard-stack-ops-on-unmanaged-windows
Open

fix: guard raise/focus/activate against unmanaged windows#520
mayconrcmello wants to merge 1 commit intoforge-ext:mainfrom
mayconrcmello:fix/guard-stack-ops-on-unmanaged-windows

Conversation

@mayconrcmello
Copy link
Copy Markdown

Summary

meta_window_set_stack_position_no_sync: assertion 'window->stack_position >= 0' failed floods the journal on window churn (alt-tab, app close, tile swap) on GNOME 49. Mutter sets stack_position = -1 and clears compositor_private the moment a window is unmanaged, so any subsequent call into the stack-manipulation API (raise, focus, activate) fails its assertion and gnome-shell pays the cost on every event.

8716a05 already guards the render path (move, border draw). The focus path was still unguarded — metaWindow.raise() / .focus() / .activate() calls throughout tree.js and window.js.

What this PR does

  • Adds lib/extension/mutter-safe.js with isWindowAlive(metaWindow) (a single get_compositor_private() check) plus safeRaise / safeFocus / safeActivate wrappers.
  • Routes the 8 unguarded call sites in tree.js (3) and window.js (5) through these helpers.

Behaviour for live windows is unchanged. Dead-window operations now short-circuit silently instead of firing the assertion.

Test plan

  • Syntax check (node --check) on all touched files.
  • Churn test: 20 cycles of nautilus &; sleep 0.3; kill <pid> over ~6s.
    • Before: assertion fires 1–2× per minute during normal use.
    • After: 0 assertions during/after churn; idle CPU normal.
  • No JS errors in the journal under the patched extension.
  • Smoke test by other users on different GNOME versions appreciated.

Notes

  • Helpers are intentionally tiny — could be inlined, but a named module keeps the rationale findable when grepping for stack_position.
  • The check is get_compositor_private() !== null; this matches the same idiom Forge already uses in places like tree.js:89 (this._actor = this._data.get_compositor_private()), so no new dependency on Mutter internals.

Forge calls metaWindow.raise()/.focus()/.activate() on windows held
by its tree after Mutter has unmanaged them, which fires assertion
warnings on every churn (alt-tab, app close, swap):

  meta_window_set_stack_position_no_sync:
    assertion 'window->stack_position >= 0' failed

The compositor private of an unmanaged window is null, so a single
get_compositor_private() check is enough to short-circuit before the
call hits Mutter. Add lib/extension/mutter-safe.js with isWindowAlive()
+ safeRaise/safeFocus/safeActivate wrappers, and route the call sites
in tree.js and window.js through them.

Behaviour for live windows is unchanged. For dead windows, the
operation is silently skipped instead of warning. Complementary to
8716a05 ("guard tree rendering against destroyed window actors"),
which already guards the *render* path (move + border draw); the
focus path remained unguarded.

Verified by churn test: 20 cycles of nautilus open/close (~5s),
journal stays silent on stack_position warnings (was 1-2/min during
normal use before the patch).
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.

1 participant