From: Akihiko Odaki <akihiko.odaki@gmail.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
Konstantin Nazarov <mail@knazarov.com>,
qemu-devel@nongnu.org, Akihiko Odaki <akihiko.odaki@gmail.com>,
Gerd Hoffmann <kraxel@redhat.com>
Subject: [PATCH v2] ui/cocoa: Comment about modifier key input quirks
Date: Fri, 12 Mar 2021 22:32:12 +0900 [thread overview]
Message-ID: <20210312133212.3131-1-akihiko.odaki@gmail.com> (raw)
Based-on: <20210310042348.21931-1-akihiko.odaki@gmail.com>
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
ui/cocoa.m | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 035f96aab04..35fdc92a51f 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -700,7 +700,43 @@ - (bool) handleEventLocked:(NSEvent *)event
NSPoint p = [self screenLocationOfEvent:event];
NSUInteger modifiers = [event modifierFlags];
- // emulate caps lock keydown and keyup
+ /*
+ * Check -[NSEvent modifierFlags] here.
+ *
+ * There is a NSEventType for an event notifying the change of
+ * -[NSEvent modifierFlags], NSEventTypeFlagsChanged but these operations
+ * are performed for any events because a modifier state may change while
+ * the application is inactive (i.e. no events fire) and we don't want to
+ * wait for another modifier state change to detect such a change.
+ *
+ * NSEventModifierFlagCapsLock requires a special treatment. The other flags
+ * are handled in similar manners.
+ *
+ * NSEventModifierFlagCapsLock
+ * ---------------------------
+ *
+ * If CapsLock state is changed, "up" and "down" events will be fired in
+ * sequence, effectively updates CapsLock state on the guest.
+ *
+ * The other flags
+ * ---------------
+ *
+ * If a flag is not set, fire "up" events for all keys which correspond to
+ * the flag. Note that "down" events are not fired here because the flags
+ * checked here do not tell what exact keys are down.
+ *
+ * If one of the keys corresponding to a flag is down, we rely on
+ * -[NSEvent keyCode] of an event whose -[NSEvent type] is
+ * NSEventTypeFlagsChanged to know the exact key which is down, which has
+ * the following two downsides:
+ * - It does not work when the application is inactive as described above.
+ * - It malfactions *after* the modifier state is changed while the
+ * application is inactive. It is because -[NSEvent keyCode] does not tell
+ * if the key is up or down, and requires to infer the current state from
+ * the previous state. It is still possible to fix such a malfanction by
+ * completely leaving your hands from the keyboard, which hopefully makes
+ * this implementation usable enough.
+ */
if (!!(modifiers & NSEventModifierFlagCapsLock) !=
qkbd_state_modifier_get(kbd, QKBD_MOD_CAPSLOCK)) {
qkbd_state_key_event(kbd, Q_KEY_CODE_CAPS_LOCK, true);
--
2.24.3 (Apple Git-128)
next reply other threads:[~2021-03-12 13:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-12 13:32 Akihiko Odaki [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-03-11 15:12 [PATCH v2] ui/cocoa: Comment about modifier key input quirks Akihiko Odaki
2021-03-12 10:19 ` Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210312133212.3131-1-akihiko.odaki@gmail.com \
--to=akihiko.odaki@gmail.com \
--cc=kraxel@redhat.com \
--cc=mail@knazarov.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).