Quickly (but not too quick) changing window decorations make it lose focus
When changing decorations on and off, a window could lose its focus, even with the fix for #273 (closed). I'm attaching a simple source program that can reproduce this issue by quickly sending decoration change requests on key press. Note that the two calls to set_decoration(1) before the XFlush, and the usleep help to reproduce the issue but aren't required.
I believe that (at least) two XReparentWindow calls are being queued before any UnmapNotify/MapNotify is received, and mutter does not handle it properly. The problem is that mutter tries to restore the focus on the first MapNotify event being received, although it should probably wait for the last one. Also, the unmaps_pending counter was not incremented again for a second XReparentWindow request in a row, so I believe it is losing count.
I'm also attaching a patch for mutter 3.32.2, that seems to fix the problem by correcting the issues mentioned above, but I don't really know mutter so it's maybe completely wrong.
bug-16979-xlib-repro.c 0001-Wait-for-all-pending-unmaps-before-restoring-focus.patch