mirror of
https://github.com/neovim/neovim.git
synced 2025-10-09 19:36:40 +00:00
loop: Simplify loop.c and move some code to input.c
- Declare poll timer in Loop structure instead of a loop_poll_events local variable. - Move deferred event management to input.c
This commit is contained in:
@@ -33,6 +33,7 @@ static Stream read_stream = {.closed = true};
|
||||
static RBuffer *input_buffer = NULL;
|
||||
static bool input_eof = false;
|
||||
static int global_fd = 0;
|
||||
static int events_enabled = 0;
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "os/input.c.generated.h"
|
||||
@@ -110,8 +111,8 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt)
|
||||
return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen);
|
||||
}
|
||||
|
||||
// If there are deferred events, return the keys directly
|
||||
if (loop_has_deferred_events(&loop)) {
|
||||
// If there are events, return the keys directly
|
||||
if (pending_events()) {
|
||||
return push_event_key(buf, maxlen);
|
||||
}
|
||||
|
||||
@@ -136,6 +137,16 @@ void os_breakcheck(void)
|
||||
}
|
||||
}
|
||||
|
||||
void input_enable_events(void)
|
||||
{
|
||||
events_enabled++;
|
||||
}
|
||||
|
||||
void input_disable_events(void)
|
||||
{
|
||||
events_enabled--;
|
||||
}
|
||||
|
||||
/// Test whether a file descriptor refers to a terminal.
|
||||
///
|
||||
/// @param fd File descriptor.
|
||||
@@ -358,7 +369,7 @@ static bool input_ready(void)
|
||||
{
|
||||
return typebuf_was_filled || // API call filled typeahead
|
||||
rbuffer_size(input_buffer) || // Input buffer filled
|
||||
loop_has_deferred_events(&loop); // Events must be processed
|
||||
pending_events(); // Events must be processed
|
||||
}
|
||||
|
||||
// Exit because of an input read error.
|
||||
@@ -369,3 +380,8 @@ static void read_error_exit(void)
|
||||
STRCPY(IObuff, _("Vim: Error reading input, exiting...\n"));
|
||||
preserve_exit();
|
||||
}
|
||||
|
||||
static bool pending_events(void)
|
||||
{
|
||||
return events_enabled && !kl_empty(loop.deferred_events);
|
||||
}
|
||||
|
Reference in New Issue
Block a user