window focus lost when closing two windows at the same time
I noticed a keyboard focus issue with one of my own X applications. The problem happens with three windows involved. Window A is the main window. Window B is opened as a regular window and window C is opened as a dialog window for window B (transient_for hint set to B). When the dialog C is closed and due to program logic the window B is closed immediately afterwards, the keyboard focus is not returned to window A but instead no (user visible) window gets the focus at all, probably the root window instead.
If there is a XSync between closing C and B, or B is transient for A as well, it works as expected.
I have created a small program to demonstrate the issue (quick'n'dirty with no error handling).
The program opens 3 windows and has a simple button press event loop:
How to reproduce:
- compile with make
- run without arguments: ./xprog
- click into the dialog window
- the dialog window and secondary window closes
- Expected behavior: the primary window gets the focus again
- Actual behavior: no window has the focus
- Click in the primary window to end the application.
If the program is started with the number "1" as argument, it uses a XSync call between closing the dialog and the secondary window. In this case the behavior is as expected. With argument "2", the secondary window B is set transient for A, and that case it also behaves as expected.
If there is a large enough delay between closing window C and B, it also works so I think it might be some race when processing the unmap events within xfwm. Maybe, when the unmap event for window C is processed in xfwm, it tries to give focus to window B which is already destroyed.
It may not have anything to do with the transient status. If none of the windows is transient, the bug occurs as well, but if the secondary and dialog is transient, the behavior is as expected.
Affected version: xfwm4 version 4.16.1 (revision 5f61a84a) on openSUSE Tumbleweed xfwm4 version 4.14.1 (revision 44809c49) on ubuntu 20.04.2 lts I can't tell for sure but I did not experienced that problem with older versions, probably <=4.12.
The focus related window manager options are as follows:
- Focus model: Click to focus
- New window focus: automatically
- Raise on focus: no
- Raise on click yes