[regression] XGrabKeyboard() noop focus events break TigerVNC
@CendioOssman
Submitted by Pierre Ossman (Work account) Assigned to Xorg Project Team
Link to original bug (#106895)
Description
So xserver 1.20 started sending out a few more events for XGrabKeyboard():
https://cgit.freedesktop.org/xorg/xserver/commit/?id=c67f2eac56518163981af59f5accb7c79bc00f6a
Unfortunately this breaks TigerVNC's vncviewer, and it isn't obvious how it should be fixed.
The issue is that TigerVNC tries to be a good citizen and release the grab when it loses focus (e.g. the user clicks another window with the ouse). However with the new commit we end up with:
- TigerVNC grabs keyboard
- TigerVNC recieves FocusOut
- TigerVNC ungrabs keyboard
- TigerVNC recieves FocusIn
- goto 1
The obvious fix is to ignore these no-op focus events, but I cannot see a clear way to detect them.
FocusOut could be handled by calling XGetInputFocus(), even though that probably introduces a small race.
FocusIn is more difficult. It's too late to check things with XGetInputFocus(), and there is no call to see if TigerVNC already has the grab. Perhaps manually track the focus state, but that's a bit annoying and I'm concerned there might be corner cases.
I was thinking that something might be possible to do by tracking request serial numbers, but that's a bit hacky.
Some input on this would be nice. It will start breaking things for a lot of users once 1.20 becomes common.