xwayland: avoid focus hijack by override-redirect windows acros… #8699
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prevent focus hijack by XWayland override-redirect tooltips when a Wayland-native window is focused
🐛 Bug Description
This PR fixes an issue in Sway's XWayland focus handling where override-redirect windows (e.g. tooltips from JetBrains IDEs) can steal keyboard focus even when:
When this happens, the tooltip grabs focus, but cannot process keyboard input, leading to complete keyboard input loss until the user manually re-focuses another window.
🎯 Root Cause
Sway calls
seat_set_focus_surface()
unconditionally for unmanaged override-redirect windows that "want focus" (tooltip, dropdown etc..), regardless of whether the current client is related.This violates ICCCM expectations and breaks focus isolation across clients.
🛠 Fix Summary
This PR introduces a helper:
try_focus_unmanaged_local()
It only allows focusing an unmanaged override-redirect surface if the currently focused view has the same PID.
This effectively emulates the ICCCM "LOCAL" input model, where popups/tooltips are only focusable when their parent is active.
✅ Result
🧪 Demo and Reproduction
To demonstrate and test this bug, see:
🔗 https://github.com/user-attachments/assets/72fb3929-1ffc-45e1-b3d9-cea58904eae0
🔗 https://github.com/IvanDovgal/override-redirect-bug-demo
This repo includes:
python-xlib
🔒 Safe Change
This change only affects override-redirect windows, and only in unmanaged XWayland handling. Managed windows and compliant input models are untouched.
Please let me know if anything should be adjusted or clarified!