aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/tui/input.c
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-12-03 16:49:30 +0300
committerZyX <kp-pav@yandex.ru>2017-12-03 16:49:30 +0300
commitc49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57 (patch)
treeb7e59c416d1435725c65f8952b6e55c70544d97e /src/nvim/tui/input.c
parent62108c3b0be46936c83f6d4c98b44ceb5e6f77fd (diff)
parent27a577586eace687c47e7398845178208cae524a (diff)
downloadrneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.gz
rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.bz2
rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.zip
Merge branch 'master' into s-dash-stdin
Diffstat (limited to 'src/nvim/tui/input.c')
-rw-r--r--src/nvim/tui/input.c67
1 files changed, 40 insertions, 27 deletions
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c
index 8e5adb14f9..96bb692db9 100644
--- a/src/nvim/tui/input.c
+++ b/src/nvim/tui/input.c
@@ -1,3 +1,6 @@
+// This is an open source non-commercial project. Dear PVS-Studio, please check
+// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
+
#include "nvim/tui/input.h"
#include "nvim/vim.h"
@@ -5,13 +8,12 @@
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/main.h"
+#include "nvim/aucmd.h"
#include "nvim/os/os.h"
#include "nvim/os/input.h"
#include "nvim/event/rstream.h"
#define PASTETOGGLE_KEY "<Paste>"
-#define FOCUSGAINED_KEY "<FocusGained>"
-#define FOCUSLOST_KEY "<FocusLost>"
#define KEY_BUFFER_SIZE 0xfff
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -44,7 +46,13 @@ void term_input_init(TermInput *input, Loop *loop)
int curflags = termkey_get_canonflags(input->tk);
termkey_set_canonflags(input->tk, curflags | TERMKEY_CANON_DELBS);
// setup input handle
+#ifdef WIN32
+ uv_tty_init(loop, &input->tty_in, 0, 1);
+ uv_tty_set_mode(&input->tty_in, UV_TTY_MODE_RAW);
+ rstream_init_stream(&input->read_stream, &input->tty_in, 0xfff);
+#else
rstream_init_fd(loop, &input->read_stream, input->in_fd, 0xfff);
+#endif
// initialize a timer handle for handling ESC with libtermkey
time_watcher_init(loop, &input->timer_handle, input);
}
@@ -99,7 +107,7 @@ static void flush_input(TermInput *input, bool wait_until_empty)
size_t drain_boundary = wait_until_empty ? 0 : 0xff;
do {
uv_mutex_lock(&input->key_buffer_mutex);
- loop_schedule(&main_loop, event_create(1, wait_input_enqueue, 1, input));
+ loop_schedule(&main_loop, event_create(wait_input_enqueue, 1, input));
input->waiting = true;
while (input->waiting) {
uv_cond_wait(&input->key_buffer_cond, &input->key_buffer_mutex);
@@ -191,18 +199,25 @@ static void forward_mouse_event(TermInput *input, TermKeyKey *key)
len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Right");
}
- if (ev == TERMKEY_MOUSE_PRESS) {
- if (button == 4) {
- len += (size_t)snprintf(buf + len, sizeof(buf) - len, "ScrollWheelUp");
- } else if (button == 5) {
- len += (size_t)snprintf(buf + len, sizeof(buf) - len, "ScrollWheelDown");
- } else {
- len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Mouse");
- }
- } else if (ev == TERMKEY_MOUSE_DRAG) {
- len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Drag");
- } else if (ev == TERMKEY_MOUSE_RELEASE) {
- len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Release");
+ switch (ev) {
+ case TERMKEY_MOUSE_PRESS:
+ if (button == 4) {
+ len += (size_t)snprintf(buf + len, sizeof(buf) - len, "ScrollWheelUp");
+ } else if (button == 5) {
+ len += (size_t)snprintf(buf + len, sizeof(buf) - len,
+ "ScrollWheelDown");
+ } else {
+ len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Mouse");
+ }
+ break;
+ case TERMKEY_MOUSE_DRAG:
+ len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Drag");
+ break;
+ case TERMKEY_MOUSE_RELEASE:
+ len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Release");
+ break;
+ case TERMKEY_MOUSE_UNKNOWN:
+ assert(false);
}
len += (size_t)snprintf(buf + len, sizeof(buf) - len, "><%d,%d>", col, row);
@@ -220,12 +235,14 @@ static int get_key_code_timeout(void)
{
Integer ms = -1;
// Check 'ttimeout' to determine if we should send ESC after 'ttimeoutlen'.
- // See :help 'ttimeout' for more information
Error err = ERROR_INIT;
if (nvim_get_option(cstr_as_string("ttimeout"), &err).data.boolean) {
- ms = nvim_get_option(cstr_as_string("ttimeoutlen"), &err).data.integer;
+ Object rv = nvim_get_option(cstr_as_string("ttimeoutlen"), &err);
+ if (!ERROR_SET(&err)) {
+ ms = rv.data.integer;
+ }
}
-
+ api_clear_error(&err);
return (int)ms;
}
@@ -269,9 +286,9 @@ static void timer_cb(TimeWatcher *watcher, void *data)
/// Handle focus events.
///
-/// If the upcoming sequence of bytes in the input stream matches either the
-/// escape code for focus gained `<ESC>[I` or focus lost `<ESC>[O` then consume
-/// that sequence and push the appropriate event into the input queue
+/// If the upcoming sequence of bytes in the input stream matches the termcode
+/// for "focus gained" or "focus lost", consume that sequence and schedule an
+/// event on the main loop.
///
/// @param input the input stream
/// @return true iff handle_focus_event consumed some input
@@ -283,11 +300,7 @@ static bool handle_focus_event(TermInput *input)
// Advance past the sequence
bool focus_gained = *rbuffer_get(input->read_stream.buffer, 2) == 'I';
rbuffer_consumed(input->read_stream.buffer, 3);
- if (focus_gained) {
- enqueue_input(input, FOCUSGAINED_KEY, sizeof(FOCUSGAINED_KEY) - 1);
- } else {
- enqueue_input(input, FOCUSLOST_KEY, sizeof(FOCUSLOST_KEY) - 1);
- }
+ aucmd_schedule_focusgained(focus_gained);
return true;
}
return false;
@@ -347,7 +360,7 @@ static void read_cb(Stream *stream, RBuffer *buf, size_t c, void *data,
stream_close(&input->read_stream, NULL, NULL);
multiqueue_put(input->loop->fast_events, restart_reading, 1, input);
} else {
- loop_schedule(&main_loop, event_create(1, input_done_event, 0));
+ loop_schedule(&main_loop, event_create(input_done_event, 0));
}
return;
}