ui/cocoa: Clear modifiers whenever possible
commit6d73bb643aa725348aabe6a885ac5fb0b7f70252
authorAkihiko Odaki <akihiko.odaki@gmail.com>
Wed, 10 Mar 2021 14:46:02 +0000 (10 23:46 +0900)
committerGerd Hoffmann <kraxel@redhat.com>
Thu, 11 Mar 2021 09:06:44 +0000 (11 10:06 +0100)
treeb450eebba94917bd80712d59acad50267a806ab1
parenta0f973f931680ae8bd847054aca7f658abb9c18f
ui/cocoa: Clear modifiers whenever possible

ui/cocoa does not receive NSEventTypeFlagsChanged when it is not active,
and the modifier state can be desynchronized in such a situation.

[NSEvent -modifierFlags] tells whether a modifier is *not* pressed, so
check it whenever receiving an event and clear the modifier if it is not
pressed.

Note that [NSEvent -modifierFlags] does not tell if a certain modifier
*is* pressed because the documented mask for [NSEvent -modifierFlags]
generalizes left shift and right shift, for example. CapsLock is the
only exception. The pressed state is synchronized only with
NSEventTypeFlagsChanged.

This change also removes modifier keys from keycode map. If they
are input with NSEventTypeKeyDown or NSEventTypeKeyUp, it leads to
desynchronization. Although such a situation is not observed, they are
removed just in case.

Moreover, QKbdState is introduced for automatic key state tracking.

Thanks to Konstantin Nazarov for testing and finding a bug in this
change:
https://gist.github.com/akihikodaki/87df4149e7ca87f18dc56807ec5a1bc5#gistcomment-3659419

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Message-Id: <20210310144602.58528-1-akihiko.odaki@gmail.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
ui/cocoa.m