aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/tui/termkey/driver-csi.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
committerJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
commitd5f194ce780c95821a855aca3c19426576d28ae0 (patch)
treed45f461b19f9118ad2bb1f440a7a08973ad18832 /src/nvim/tui/termkey/driver-csi.c
parentc5d770d311841ea5230426cc4c868e8db27300a8 (diff)
parent44740e561fc93afe3ebecfd3618bda2d2abeafb0 (diff)
downloadrneovim-rahm.tar.gz
rneovim-rahm.tar.bz2
rneovim-rahm.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309HEADrahm
Diffstat (limited to 'src/nvim/tui/termkey/driver-csi.c')
-rw-r--r--src/nvim/tui/termkey/driver-csi.c57
1 files changed, 48 insertions, 9 deletions
diff --git a/src/nvim/tui/termkey/driver-csi.c b/src/nvim/tui/termkey/driver-csi.c
index 28c7eaccfd..d427be50ff 100644
--- a/src/nvim/tui/termkey/driver-csi.c
+++ b/src/nvim/tui/termkey/driver-csi.c
@@ -1,11 +1,10 @@
#include <assert.h>
-#include <stdio.h>
+#include <stdint.h>
#include <string.h>
#include "nvim/memory.h"
#include "nvim/tui/termkey/driver-csi.h"
#include "nvim/tui/termkey/termkey-internal.h"
-#include "nvim/tui/termkey/termkey.h"
#include "nvim/tui/termkey/termkey_defs.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -32,11 +31,20 @@ static TermKeyResult handle_csi_ss3_full(TermKey *tk, TermKeyKey *key, int cmd,
if (nparams > 1 && params[1].param != NULL) {
int arg = 0;
- result = termkey_interpret_csi_param(params[1], &arg, NULL, NULL);
+ int subparam = 0;
+ size_t nsubparams = 1;
+ result = termkey_interpret_csi_param(params[1], &arg, &subparam, &nsubparams);
if (result != TERMKEY_RES_KEY) {
return result;
}
+ if (nsubparams > 0) {
+ key->event = parse_key_event(subparam);
+ if (key->event == TERMKEY_EVENT_UNKNOWN) {
+ return TERMKEY_RES_NONE;
+ }
+ }
+
key->modifiers = arg - 1;
} else {
key->modifiers = 0;
@@ -104,11 +112,20 @@ static TermKeyResult handle_csifunc(TermKey *tk, TermKeyKey *key, int cmd, TermK
int args[3];
if (nparams > 1 && params[1].param != NULL) {
- result = termkey_interpret_csi_param(params[1], &args[1], NULL, NULL);
+ int subparam = 0;
+ size_t nsubparams = 1;
+ result = termkey_interpret_csi_param(params[1], &args[1], &subparam, &nsubparams);
if (result != TERMKEY_RES_KEY) {
return result;
}
+ if (nsubparams > 0) {
+ key->event = parse_key_event(subparam);
+ if (key->event == TERMKEY_EVENT_UNKNOWN) {
+ return TERMKEY_RES_NONE;
+ }
+ }
+
key->modifiers = args[1] - 1;
} else {
key->modifiers = 0;
@@ -178,9 +195,11 @@ static TermKeyResult handle_csi_u(TermKey *tk, TermKeyKey *key, int cmd, TermKey
return TERMKEY_RES_ERROR;
}
- if (nsubparams > 0 && subparam != 1) {
- // Not a press event. Ignore for now
- return TERMKEY_RES_NONE;
+ if (nsubparams > 0) {
+ key->event = parse_key_event(subparam);
+ if (key->event == TERMKEY_EVENT_UNKNOWN) {
+ return TERMKEY_RES_NONE;
+ }
}
key->modifiers = args[1] - 1;
@@ -308,6 +327,12 @@ TermKeyResult termkey_interpret_mouse(TermKey *tk, const TermKeyKey *key, TermKe
btn = code + 4 - 64;
break;
+ case 128:
+ case 129:
+ *event = drag ? TERMKEY_MOUSE_DRAG : TERMKEY_MOUSE_PRESS;
+ btn = code + 8 - 128;
+ break;
+
default:
*event = TERMKEY_MOUSE_UNKNOWN;
}
@@ -419,6 +444,20 @@ TermKeyResult termkey_interpret_modereport(TermKey *tk, const TermKeyKey *key, i
#define CHARAT(i) (tk->buffer[tk->buffstart + (i)])
+static TermKeyEvent parse_key_event(int n)
+{
+ switch (n) {
+ case 1:
+ return TERMKEY_EVENT_PRESS;
+ case 2:
+ return TERMKEY_EVENT_REPEAT;
+ case 3:
+ return TERMKEY_EVENT_RELEASE;
+ default:
+ return TERMKEY_EVENT_UNKNOWN;
+ }
+}
+
static TermKeyResult parse_csi(TermKey *tk, size_t introlen, size_t *csi_len,
TermKeyCsiParam params[], size_t *nargs, unsigned *commandp)
{
@@ -529,7 +568,7 @@ TermKeyResult termkey_interpret_csi_param(TermKeyCsiParam param, int *paramp, in
if (c == ':') {
if (length == 0) {
*paramp = arg;
- } else {
+ } else if (subparams != NULL) {
subparams[length - 1] = arg;
}
@@ -544,7 +583,7 @@ TermKeyResult termkey_interpret_csi_param(TermKeyCsiParam param, int *paramp, in
if (length == 0) {
*paramp = arg;
- } else {
+ } else if (subparams != NULL) {
subparams[length - 1] = arg;
}