Dont send events for modifier keys unless in all key mode

This commit is contained in:
Kovid Goyal 2021-01-14 04:31:55 +05:30
parent 6b2ffc774f
commit 39f41faf9f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 10 additions and 1 deletions

View File

@ -315,10 +315,12 @@ be notified of key repeat/release events. These types of events are needed for
some applications, such as games (think of movement using the ``WASD`` keys).
This progressive enhancement (``0b1000``) turns on key reporting even for key
events that generate next. When it is enabled, text will not be sent, instead
events that generate text. When it is enabled, text will not be sent, instead
only key events are sent. If the text is needed as well, combine with the
Report associated text enhancement below.
Additionally, with this mode, events for pressing modifier keys are reported.
.. _report_text:
Report associated text

View File

@ -31,6 +31,10 @@ typedef struct {
KeyAction action;
} EncodingData;
static inline bool
is_modifier_key(uint32_t key) {
return GLFW_FKEY_LEFT_SHIFT <= key && key <= GLFW_FKEY_RIGHT_SUPER;
}
static inline void
convert_glfw_mods(int mods, KeyEvent *ev) {
@ -344,6 +348,7 @@ encode_glfw_key_event(const GLFWkeyevent *e, const bool cursor_key_mode, const u
.report_text = key_encoding_flags & 8,
.embed_text = key_encoding_flags & 16
};
if (!ev.report_text && is_modifier_key(e->key)) return 0;
ev.has_text = e->text && !is_ascii_control_char(e->text[0]);
bool send_text_standalone = !ev.report_text;
if (!ev.disambiguate && GLFW_FKEY_KP_0 <= ev.key && ev.key <= GLFW_FKEY_KP_DELETE) {

View File

@ -389,6 +389,7 @@ class TestKeys(BaseTest):
ae(enc(key=ord(' ')), ' ')
ae(enc(key=ord(' '), mods=ctrl), '\0')
ae(enc(key=ord('i'), mods=ctrl | shift), csi(ctrl | shift, ord('i')))
ae(enc(key=defines.GLFW_FKEY_LEFT_SHIFT), '')
q = partial(enc, key=ord('a'))
ae(q(), 'a')
@ -434,6 +435,7 @@ class TestKeys(BaseTest):
ae(kq(ord('a'), action=defines.GLFW_REPEAT), csi(num='a'))
ae(kq(ord('a'), mods=ctrl), csi(ctrl, num='a'))
ae(kq(defines.GLFW_FKEY_UP), '\x1b[A')
ae(kq(defines.GLFW_FKEY_LEFT_SHIFT), csi(num=defines.GLFW_FKEY_LEFT_SHIFT))
# test embed text
eq = partial(enc, key_encoding_flags=0b11000)