diff options
-rw-r--r-- | src/nvim/tui/input.c | 12 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 22 | ||||
-rw-r--r-- | src/nvim/tui/tui.h | 16 |
3 files changed, 26 insertions, 24 deletions
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 03f22745bf..6b9361848a 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -586,11 +586,13 @@ static void handle_term_response(TermInput *input, const TermKeyKey *key) static void handle_modereport(TermInput *input, const TermKeyKey *key) FUNC_ATTR_NONNULL_ALL { - // termkey_interpret_modereport incorrectly sign extends the mode so we parse the response - // ourselves - int mode = (uint8_t)key->code.mouse[1] << 8 | (uint8_t)key->code.mouse[2]; - TerminalModeState value = (uint8_t)key->code.mouse[3]; - tui_dec_report_mode(input->tui_data, (TerminalDecMode)mode, value); + int initial; + int mode; + int value; + if (termkey_interpret_modereport(input->tk, key, &initial, &mode, &value) == TERMKEY_RES_KEY) { + (void)initial; // Unused + tui_handle_term_mode(input->tui_data, (TermMode)mode, (TermModeState)value); + } } /// Handle a CSI sequence from the terminal that is unrecognized by libtermkey. diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index cdc8f769a1..93b891afff 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -211,10 +211,10 @@ static void tui_reset_key_encoding(TUIData *tui) } } -/// Request the terminal's DEC mode (DECRQM). +/// Request the terminal's mode (DECRQM). /// /// @see handle_modereport -static void tui_dec_request_mode(TUIData *tui, TerminalDecMode mode) +static void tui_request_term_mode(TUIData *tui, TermMode mode) FUNC_ATTR_NONNULL_ALL { // 5 bytes for \x1b[?$p, 1 byte for null terminator, 6 bytes for mode digits (more than enough) @@ -224,22 +224,22 @@ static void tui_dec_request_mode(TUIData *tui, TerminalDecMode mode) out(tui, buf, (size_t)len); } -/// Handle a DECRPM response from the terminal. -void tui_dec_report_mode(TUIData *tui, TerminalDecMode mode, TerminalModeState state) +/// Handle a mode report (DECRPM) from the terminal. +void tui_handle_term_mode(TUIData *tui, TermMode mode, TermModeState state) FUNC_ATTR_NONNULL_ALL { switch (state) { - case kTerminalModeNotRecognized: - case kTerminalModePermanentlySet: - case kTerminalModePermanentlyReset: + case kTermModeNotRecognized: + case kTermModePermanentlySet: + case kTermModePermanentlyReset: // If the mode is not recognized, or if the terminal emulator does not allow it to be changed, // then there is nothing to do break; - case kTerminalModeSet: - case kTerminalModeReset: + case kTermModeSet: + case kTermModeReset: // The terminal supports changing the given mode switch (mode) { - case kDecModeSynchronizedOutput: + case kTermModeSynchronizedOutput: // Ref: https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036 tui->unibi_ext.sync = (int)unibi_add_ext_str(tui->ut, "Sync", "\x1b[?2026%?%p1%{1}%-%tl%eh%;"); @@ -371,7 +371,7 @@ static void terminfo_start(TUIData *tui) // Query support for mode 2026 (Synchronized Output). Some terminals also // support an older DCS sequence for synchronized output, but we will only use // mode 2026 - tui_dec_request_mode(tui, kDecModeSynchronizedOutput); + tui_request_term_mode(tui, kTermModeSynchronizedOutput); // Query the terminal to see if it supports Kitty's keyboard protocol tui_query_kitty_keyboard(tui); diff --git a/src/nvim/tui/tui.h b/src/nvim/tui/tui.h index 29afdef4de..1cd283cf49 100644 --- a/src/nvim/tui/tui.h +++ b/src/nvim/tui/tui.h @@ -6,16 +6,16 @@ typedef struct TUIData TUIData; typedef enum { - kDecModeSynchronizedOutput = 2026, -} TerminalDecMode; + kTermModeSynchronizedOutput = 2026, +} TermMode; typedef enum { - kTerminalModeNotRecognized = 0, - kTerminalModeSet = 1, - kTerminalModeReset = 2, - kTerminalModePermanentlySet = 3, - kTerminalModePermanentlyReset = 4, -} TerminalModeState; + kTermModeNotRecognized = 0, + kTermModeSet = 1, + kTermModeReset = 2, + kTermModePermanentlySet = 3, + kTermModePermanentlyReset = 4, +} TermModeState; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "tui/tui.h.generated.h" |