45 Commits

Author SHA1 Message Date
Mitchell Hashimoto
0a1dfae2ef input: kitty keyboard modifier event changes from Kitty 0.32
> When the key event is related to an actual modifier key, the corresponding
> modifier's bit must be set to the modifier state including the effect for the
> current 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 have the ``ctrl`` bit set. See :iss:`6913` for discussion of this design.
2023-12-24 08:21:31 -08:00
Mitchell Hashimoto
ede7ec9c63 input: kitty encoding should only report alt key if not equal to utf8 2023-12-21 20:43:42 -08:00
Mitchell Hashimoto
9642dd3275 macos: proper event when sided mod released with other side pressed
Related to https://github.com/mitchellh/ghostty/issues/1082

This fixes two separate issues to follow along with the new spec changes
Kovid pushed to Kitty:

  1. When two modifiers are pressed and one is released, this shows up
     as a proper release event with the correct side. Previously, the
     correct side was shown but as a press event.

  2. When two modifiers are pressed and one is released, the Kitty event
     should not have that specific modifier set. For example, pressing
     left ctrl, then right ctrl, then releasing right ctrl should encode
     as "right ctrl released" but with NO modifiers still present.
2023-12-13 21:50:00 -08:00
Mitchell Hashimoto
5a372f6a06 input/kitty: do not encode event with mods if press
Fixes #1082
2023-12-13 13:39:44 -08:00
Mitchell Hashimoto
c0eded766a input/kitty: do not encode event+mods if they're both default 2023-12-13 10:57:17 -08:00
Mitchell Hashimoto
bc7643eae9 input: update preventsText comment 2023-11-29 21:36:10 -08:00
Mitchell Hashimoto
659b43de37 input: Kitty encoding suppress associated text on macOS with alt 2023-11-29 21:34:30 -08:00
Tim Culverhouse
07e6cf900f key-encode: only set associated text when there is printable text
Associated text should only be sent to the terminal when printable text
is generated from the keypress. Prevent sending associated text when any
modifier is pressed, except for Shift, NumLock, and Capslock

This brings Ghostty inline with the output of Kitty.
2023-11-24 14:27:37 -06:00
Mitchell Hashimoto
a67d90710c input: kitty encoding should ignore committed preedit state
Fixes #952
2023-11-24 07:58:31 -08:00
Mitchell Hashimoto
4cff8d972c input: do not encode enter with utf8 as pc style key
If the enter key has utf-8 attach, we assume its a dead key state being
committed so we don't process it.
2023-11-15 08:58:12 -08:00
Mitchell Hashimoto
35e78939e5 macos: ignore alt key with other modifiers set
This enables shifted alt-prefixed keys, such as `shift+alt+.` on
US standard becoming `M->`. To do this, we needed to fix a few bugs:

  (1) translation mods should strip alt even if other mods are set
  (2) AppKit translation event needs to construct new characters with
      the translation mods.
  (3) Alt-prefix handling in KeyEncoder needs to allow ASCII utf8
      translations even for macOS.
2023-11-13 19:21:51 -08:00
Mitchell Hashimoto
63e106390f input: fix failing test on Linux 2023-11-13 13:58:41 -08:00
Mitchell Hashimoto
b4d393fdcf input: process alt-prefix even if utf8 text doesn't exist 2023-11-13 13:50:00 -08:00
Mitchell Hashimoto
86fbc6a85b macos-option-as-alt works again
This regressed sometime -- I can't find the exact commit -- but in any
case I've moved this handling directly into the KeyEncoder so we can
unit test it and prevent future regressions.
2023-11-12 15:26:55 -08:00
Mitchell Hashimoto
d97e5b9dab input: legacy encoding pc style keys should ignore directional modifiers 2023-10-12 12:28:26 -07:00
Mitchell Hashimoto
7bbe669641 Merge pull request #578 from rockorager/dev
Kitty keyboard improvements
2023-09-29 11:56:34 -07:00
Mitchell Hashimoto
a2e2889f2b input: make Key ascii functions comptime-generated 2023-09-29 11:54:05 -07:00
Tim Culverhouse
11cb6824cd input: don't ESC prefix non-ascii characters
User input withe Alt modifier is typically ESC prefixed. Escape
prefixing a non-ascii character can cause bugs in some applications. For
example in bash, emitting an Alt+ф allows the user to backspace one
character into the prompt. This can be repeated multiple times.

When a character is outside the ASCII range (exclusive of 0x7F, this is
handled as a control sequence), print the character as is, with no
prefix.
2023-09-29 08:35:21 -07:00
Tim Culverhouse
fb649e689d input(kitty): fix reporting of alternate keys
Fix reporting of alternate keys when using the kitty protocol. Alternate
keyboard layouts were failing to report the "base layout" key. This
implementation now matches kitty's output 1:1, and has some added unit
tests for cyrillic characters.

This also fixes a bug where a caps_lock modified key would report the
shifted key as well. The protocol explicitly requires that shifted keys
are only reported if the shift modifier is true.
2023-09-29 06:37:08 -05:00
Mitchell Hashimoto
35a4427f54 input: 0x7F is a control character, use helper
Fixes #556

One check for control chars was missing 0x7F. Since we do this three
times, extract it to a helper and call that.
2023-09-27 07:57:21 -07:00
Mitchell Hashimoto
9ad27924a6 input: correct xterm encoding for modified F1-F4
Fixes #499
2023-09-20 14:33:55 -07:00
Mitchell Hashimoto
62a35417ab input: kitty alternates and text should not include control characters 2023-09-19 15:18:00 -07:00
Mitchell Hashimoto
39c2332d35 input: keypad enter should act as normal "\r" if no other seq matches
This matches Kitty behavior on both macOS and Linux. In certain keyboard
modes and Kitty keyboard modes, the behavior changes but those already
matched (tested).
2023-08-26 07:43:22 -07:00
Mitchell Hashimoto
e7c11f7d13 input: kitty should not encode modifier-only key unless "report all" 2023-08-24 21:24:41 -07:00
Mitchell Hashimoto
3a93aaf9cf apprt/embedded: do not translate control characters
macOS translates inputs such as shift+tab into the control character tab
(ascii 0x09). Linux/GTK does not translate character inputs except to
printable characters. We don't want control character translations
because these are all handled manually by our key encoder (i.e.
translating ctrl+c to 0x03).
2023-08-24 15:01:57 -07:00
Mitchell Hashimoto
5e45dc3386 input: kitty encoding should only output unmodified utf8 if printable 2023-08-22 15:00:53 -07:00
Mitchell Hashimoto
99abff85dd input: pc style function keys should use all mods, not effective 2023-08-21 08:10:27 -07:00
Mitchell Hashimoto
b7e1122224 input: remove old TODO. This is handled now in the app runtimes 2023-08-17 12:59:22 -07:00
Mitchell Hashimoto
91456fe420 input: repeat events need to be handled for Kitty w/o report events 2023-08-17 11:23:13 -07:00
Mitchell Hashimoto
78080f0cd6 input: proper optional entry handling 2023-08-17 09:52:44 -07:00
Mitchell Hashimoto
6493da0dd3 input: Kitty encodes alternate keys 2023-08-17 09:51:16 -07:00
Mitchell Hashimoto
37daf02804 core: use Kitty encoding if enabled 2023-08-17 09:02:43 -07:00
Mitchell Hashimoto
fb9dc74b29 input: lot more Kitty encoding logic 2023-08-17 08:55:37 -07:00
Mitchell Hashimoto
91ba53b081 input: KittySequence for encoding sequences 2023-08-17 08:43:40 -07:00
Mitchell Hashimoto
c5177f6609 input: begin kitty key encoding logic (not working yet) 2023-08-16 22:08:16 -07:00
Mitchell Hashimoto
9cef09c58d input: do not send ctrl-sequences for ctrl-i,m,[ 2023-08-16 14:17:31 -07:00
Mitchell Hashimoto
2ff2e018ba input: clarify why we use all mods for unicode CSI u 2023-08-16 14:04:38 -07:00
Mitchell Hashimoto
dcf9cdd8bf input: CSI u encoding for modified unicode chars 2023-08-16 13:57:17 -07:00
Mitchell Hashimoto
c254a8b09e input: encoding should always write to the buf 2023-08-16 12:48:48 -07:00
Mitchell Hashimoto
aadb78394b input: legacy encoding never emits sequence during dead key state 2023-08-16 12:48:48 -07:00
Mitchell Hashimoto
9b90692fc7 core: start on key2Callback for the new callback that uses KeyEncoder 2023-08-16 12:48:48 -07:00
Mitchell Hashimoto
a2d4e7ce29 input: legacy key encoding handles alt-as-esc for general utf8 2023-08-16 12:48:48 -07:00
Mitchell Hashimoto
871f797758 input: KeyEncoder handles the charCallback stuff now too 2023-08-16 12:48:48 -07:00
Mitchell Hashimoto
6555bb1410 input: KeyEncoder legacy encoding handles old keyCallback logic 2023-08-16 12:48:48 -07:00
Mitchell Hashimoto
f57fd99d3e input: starting to work on KeyEncoder, got ctrl sequences 2023-08-16 12:48:48 -07:00