Skip to content

Commit

Permalink
Keyboard protocol: Clarify the behavior of the modifier bits during m…
Browse files Browse the repository at this point in the history
…odifier key events

I cant find any relevant standards for this, so am just picking the
macOS behavior as it seems more sensible to me.

Fixes #6913
  • Loading branch information
kovidgoyal committed Dec 14, 2023
1 parent d9ccbcd commit a9b424e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/keyboard-protocol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ In the escape code, the modifier value is encoded as a decimal number which is
and so on. If the modifier field is not present in the escape code, its default
value is ``1`` which means no modifiers.

When the key event is related to an actual modifier key, the corresponding modifier's bit
must be set for the press event and reset for the release event. For example
when pressing the :kbd:`LEFT_CONTROL` key, the ``ctrl`` bit must be set and
when releasing it, it must be reset. When both left and right control keys are
pressed and one is released, the release event must again have the ``ctrl`` bit
reset.

.. note:: Not all platforms will provide independent events for left and right
modifier keys. For example on macOS, the system does not send an event to
the application when the holding left control and also pressing right
control. Therefore applications are adviced to not rely on these.

.. _event_types:

Expand Down
2 changes: 2 additions & 0 deletions kitty/glfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ key_callback(GLFWwindow *w, GLFWkeyevent *ev) {
} else {
mods_at_last_key_or_button_event |= key_modifier;
}
// Normalize mods state to be what the kitty keyboard protocol requires
ev->mods = mods_at_last_key_or_button_event;
}
global_state.callback_os_window->cursor_blink_zero_time = monotonic();
if (is_window_ready_for_callbacks()) on_key_input(ev);
Expand Down

0 comments on commit a9b424e

Please sign in to comment.