aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/tui/input.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/input.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/input.c')
-rw-r--r--src/nvim/tui/input.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c
index 98dd7b4b45..1f73f2d135 100644
--- a/src/nvim/tui/input.c
+++ b/src/nvim/tui/input.c
@@ -8,7 +8,6 @@
#include "nvim/api/private/helpers.h"
#include "nvim/event/loop.h"
#include "nvim/event/rstream.h"
-#include "nvim/event/stream.h"
#include "nvim/macros_defs.h"
#include "nvim/main.h"
#include "nvim/map_defs.h"
@@ -160,12 +159,16 @@ void tinput_init(TermInput *input, Loop *loop)
// initialize a timer handle for handling ESC with libtermkey
uv_timer_init(&loop->uv, &input->timer_handle);
input->timer_handle.data = input;
+
+ uv_timer_init(&loop->uv, &input->bg_query_timer);
+ input->bg_query_timer.data = input;
}
void tinput_destroy(TermInput *input)
{
map_destroy(int, &kitty_key_map);
uv_close((uv_handle_t *)&input->timer_handle, NULL);
+ uv_close((uv_handle_t *)&input->bg_query_timer, NULL);
rstream_may_close(&input->read_stream);
termkey_destroy(input->tk);
}
@@ -179,6 +182,7 @@ void tinput_stop(TermInput *input)
{
rstream_stop(&input->read_stream);
uv_timer_stop(&input->timer_handle);
+ uv_timer_stop(&input->bg_query_timer);
}
static void tinput_done_event(void **argv)
@@ -383,6 +387,10 @@ static void forward_mouse_event(TermInput *input, TermKeyKey *key)
len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Middle");
} else if (button == 3) {
len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Right");
+ } else if (button == 8) {
+ len += (size_t)snprintf(buf + len, sizeof(buf) - len, "X1");
+ } else if (button == 9) {
+ len += (size_t)snprintf(buf + len, sizeof(buf) - len, "X2");
}
switch (ev) {
@@ -427,6 +435,15 @@ static void tk_getkeys(TermInput *input, bool force)
TermKeyResult result;
while ((result = tk_getkey(input->tk, &key, force)) == TERMKEY_RES_KEY) {
+ // Only press and repeat events are handled for now
+ switch (key.event) {
+ case TERMKEY_EVENT_PRESS:
+ case TERMKEY_EVENT_REPEAT:
+ break;
+ default:
+ continue;
+ }
+
if (key.type == TERMKEY_TYPE_UNICODE && !key.modifiers) {
forward_simple_utf8(input, &key);
} else if (key.type == TERMKEY_TYPE_UNICODE
@@ -474,6 +491,13 @@ static void tinput_timer_cb(uv_timer_t *handle)
tinput_flush(input);
}
+static void bg_query_timer_cb(uv_timer_t *handle)
+ FUNC_ATTR_NONNULL_ALL
+{
+ TermInput *input = handle->data;
+ tui_query_bg_color(input->tui_data);
+}
+
/// Handle focus events.
///
/// If the upcoming sequence of bytes in the input stream matches the termcode
@@ -660,6 +684,33 @@ static void handle_unknown_csi(TermInput *input, const TermKeyKey *key)
}
}
break;
+ case 'n':
+ // Device Status Report (DSR)
+ if (nparams == 2) {
+ int args[2];
+ for (size_t i = 0; i < ARRAY_SIZE(args); i++) {
+ if (termkey_interpret_csi_param(params[i], &args[i], NULL, NULL) != TERMKEY_RES_KEY) {
+ return;
+ }
+ }
+
+ if (args[0] == 997) {
+ // Theme update notification
+ // https://github.com/contour-terminal/contour/blob/master/docs/vt-extensions/color-palette-update-notifications.md
+ // The second argument tells us whether the OS theme is set to light
+ // mode or dark mode, but all we care about is the background color of
+ // the terminal emulator. We query for that with OSC 11 and the response
+ // is handled by the autocommand created in _defaults.lua. The terminal
+ // may send us multiple notifications all at once so we use a timer to
+ // coalesce the queries.
+ if (uv_timer_get_due_in(&input->bg_query_timer) > 0) {
+ return;
+ }
+
+ uv_timer_start(&input->bg_query_timer, bg_query_timer_cb, 100, 0);
+ }
+ }
+ break;
default:
break;
}