Skip to content

Grant on-demand focus to a layer popup root before installing its grab - #343

Open
ReDeced wants to merge 1 commit into
malbiruk:mainfrom
ReDeced:fix/layer-popup-grab-focus
Open

ReDeced wants to merge 1 commit into
malbiruk:mainfrom
ReDeced:fix/layer-popup-grab-focus

Conversation

@ReDeced

@ReDeced ReDeced commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #342.

Problem

A popup grabbed against a layer surface whose interactivity was flipped None → OnDemand in the same interaction gets dismissed by popup_done one roundtrip after the grab. The grab handler takes a keyboard grab (the layer reads as OnDemand), but the root holds no focus: at click time the layer was still None, so focus_layer_if_on_demand never registered it, and the client's flip doesn't grant focus. The next focus recompute resolves target = None, reads "focus left the grab root", tears the grab down and ungrabs — dismissing the menu. Real-world symptom: tray menus in noctalia flash for ~13 ms and close.

Fix

In the grab handler, when the popup root is a layer surface with OnDemand interactivity, grant it the on-demand focus before installing the grabs. Same state as the already-covered path where the user clicks the layer first.

Tests

  • New src/tests/tray_menu_repro.rs:
    • popup + grab on a None-interactivity layer (already worked, stays covered)
    • the exact failing sequence: click at None → flip to OnDemand → popup + grab (pre-fix: grab torn down, popup_done; post-fix: stays mapped)
    • flip to OnDemand + click grants the layer focus
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings, full cargo test pass.

A shell can flip a layer surface from None to OnDemand in the same
interaction as the popup grab — e.g. a tray menu whose bar was None at
click time and is switched to OnDemand right before the popup maps, so
the grabbed popup can carry keyboard. The grab handler then takes a
keyboard grab, but the root never holds focus: the next focus recompute
resolves target = None, reads "focus left the grab root", tears the grab
down and ungrabs, dismissing the just-opened menu.

Grant the OnDemand layer root the on-demand focus in the grab handler,
mirroring what happens when the user clicks the layer first. Repro in
src/tests/tray_menu_repro.rs.

Fixes malbiruk#342
@ReDeced
ReDeced force-pushed the fix/layer-popup-grab-focus branch from 5fd9a30 to 0ff13e1 Compare November 13, 2026 13:52

This branch has not been deployed

No deployments
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.

Layer-rooted popup grab is torn down when the shell flips the layer to OnDemand in the same interaction

1 participant