mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 05:28:49 +00:00
Eliminate the "input callback queue"
This was a sort of side channel that was only used to propagate redraws after universal variable changes. We can eliminate it and handle these more directly.
This commit is contained in:
parent
56fd6f696b
commit
edab366d3a
5 changed files with 17 additions and 39 deletions
|
@ -61,7 +61,7 @@ static latch_t<env_universal_t> s_universal_variables;
|
||||||
/// Getter for universal variables.
|
/// Getter for universal variables.
|
||||||
static env_universal_t *uvars() { return s_universal_variables; }
|
static env_universal_t *uvars() { return s_universal_variables; }
|
||||||
|
|
||||||
void env_universal_barrier() { env_stack_t::principal().universal_barrier(); }
|
bool env_universal_barrier() { return env_stack_t::principal().universal_barrier(); }
|
||||||
|
|
||||||
// A typedef for a set of constant strings. Note our sets are typically on the order of 6 elements,
|
// A typedef for a set of constant strings. Note our sets are typically on the order of 6 elements,
|
||||||
// so we don't bother to sort them.
|
// so we don't bother to sort them.
|
||||||
|
@ -498,9 +498,9 @@ env_scoped_t::env_scoped_t(std::unique_ptr<var_stack_t> vars) : vars_(std::move(
|
||||||
env_scoped_t::env_scoped_t(env_scoped_t &&) = default;
|
env_scoped_t::env_scoped_t(env_scoped_t &&) = default;
|
||||||
env_scoped_t::~env_scoped_t() = default;
|
env_scoped_t::~env_scoped_t() = default;
|
||||||
|
|
||||||
void env_stack_t::universal_barrier() {
|
bool env_stack_t::universal_barrier() {
|
||||||
ASSERT_IS_MAIN_THREAD();
|
ASSERT_IS_MAIN_THREAD();
|
||||||
if (!uvars()) return;
|
if (!uvars()) return false;
|
||||||
|
|
||||||
callback_data_list_t callbacks;
|
callback_data_list_t callbacks;
|
||||||
bool changed = uvars()->sync(callbacks);
|
bool changed = uvars()->sync(callbacks);
|
||||||
|
@ -509,6 +509,7 @@ void env_stack_t::universal_barrier() {
|
||||||
}
|
}
|
||||||
|
|
||||||
env_universal_callbacks(this, callbacks);
|
env_universal_callbacks(this, callbacks);
|
||||||
|
return changed || !callbacks.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If they don't already exist initialize the `COLUMNS` and `LINES` env vars to reasonable
|
/// If they don't already exist initialize the `COLUMNS` and `LINES` env vars to reasonable
|
||||||
|
|
|
@ -271,7 +271,8 @@ class env_stack_t final : public env_scoped_t {
|
||||||
void pop();
|
void pop();
|
||||||
|
|
||||||
/// Synchronizes all universal variable changes: writes everything out, reads stuff in.
|
/// Synchronizes all universal variable changes: writes everything out, reads stuff in.
|
||||||
void universal_barrier();
|
/// \return true if something changed, false otherwise.
|
||||||
|
bool universal_barrier();
|
||||||
|
|
||||||
/// Returns an array containing all exported variables in a format suitable for execv
|
/// Returns an array containing all exported variables in a format suitable for execv
|
||||||
const char *const *export_arr();
|
const char *const *export_arr();
|
||||||
|
@ -302,7 +303,8 @@ extern bool g_use_posix_spawn;
|
||||||
extern bool term_has_xn; // does the terminal have the "eat_newline_glitch"
|
extern bool term_has_xn; // does the terminal have the "eat_newline_glitch"
|
||||||
|
|
||||||
/// Synchronizes all universal variable changes: writes everything out, reads stuff in.
|
/// Synchronizes all universal variable changes: writes everything out, reads stuff in.
|
||||||
void env_universal_barrier();
|
/// \return true if any value changed.
|
||||||
|
bool env_universal_barrier();
|
||||||
|
|
||||||
/// Returns true if we think the terminal supports setting its title.
|
/// Returns true if we think the terminal supports setting its title.
|
||||||
bool term_supports_setting_title();
|
bool term_supports_setting_title();
|
||||||
|
|
|
@ -36,11 +36,6 @@ static int wait_on_escape_ms = WAIT_ON_ESCAPE_DEFAULT;
|
||||||
/// Events which have been read and returned by the sequence matching code.
|
/// Events which have been read and returned by the sequence matching code.
|
||||||
static std::deque<char_event_t> lookahead_list;
|
static std::deque<char_event_t> lookahead_list;
|
||||||
|
|
||||||
// Queue of pairs of (function pointer, argument) to be invoked. Expected to be mostly empty.
|
|
||||||
typedef std::list<std::function<void(void)>> callback_queue_t;
|
|
||||||
static callback_queue_t callback_queue;
|
|
||||||
static void input_flush_callbacks();
|
|
||||||
|
|
||||||
static bool has_lookahead() { return !lookahead_list.empty(); }
|
static bool has_lookahead() { return !lookahead_list.empty(); }
|
||||||
|
|
||||||
static char_event_t lookahead_pop() {
|
static char_event_t lookahead_pop() {
|
||||||
|
@ -78,9 +73,6 @@ static char_event_t readb() {
|
||||||
bool do_loop;
|
bool do_loop;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// Flush callbacks.
|
|
||||||
input_flush_callbacks();
|
|
||||||
|
|
||||||
fd_set fdset;
|
fd_set fdset;
|
||||||
int fd_max = 0;
|
int fd_max = 0;
|
||||||
int ioport = iothread_port();
|
int ioport = iothread_port();
|
||||||
|
@ -139,7 +131,12 @@ static char_event_t readb() {
|
||||||
barrier_from_readability = notifier.notification_fd_became_readable(notifier_fd);
|
barrier_from_readability = notifier.notification_fd_became_readable(notifier_fd);
|
||||||
}
|
}
|
||||||
if (barrier_from_poll || barrier_from_readability) {
|
if (barrier_from_poll || barrier_from_readability) {
|
||||||
env_universal_barrier();
|
if (env_universal_barrier()) {
|
||||||
|
// A variable change may have triggered a repaint, etc.
|
||||||
|
if (auto mc = lookahead_pop_evt()) {
|
||||||
|
return *mc;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioport > 0 && FD_ISSET(ioport, &fdset)) {
|
if (ioport > 0 && FD_ISSET(ioport, &fdset)) {
|
||||||
|
@ -245,19 +242,3 @@ char_event_t input_common_readch_timed(bool dequeue_timeouts) {
|
||||||
void input_common_queue_ch(char_event_t ch) { lookahead_push_back(ch); }
|
void input_common_queue_ch(char_event_t ch) { lookahead_push_back(ch); }
|
||||||
|
|
||||||
void input_common_next_ch(char_event_t ch) { lookahead_push_front(ch); }
|
void input_common_next_ch(char_event_t ch) { lookahead_push_front(ch); }
|
||||||
|
|
||||||
void input_common_add_callback(std::function<void(void)> callback) {
|
|
||||||
ASSERT_IS_MAIN_THREAD();
|
|
||||||
callback_queue.push_back(std::move(callback));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void input_flush_callbacks() {
|
|
||||||
// We move the queue into a local variable, so that events queued up during a callback don't get
|
|
||||||
// fired until next round.
|
|
||||||
ASSERT_IS_MAIN_THREAD();
|
|
||||||
callback_queue_t local_queue;
|
|
||||||
std::swap(local_queue, callback_queue);
|
|
||||||
for (auto &f : local_queue) {
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,13 +2,11 @@
|
||||||
#ifndef INPUT_COMMON_H
|
#ifndef INPUT_COMMON_H
|
||||||
#define INPUT_COMMON_H
|
#define INPUT_COMMON_H
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "maybe.h"
|
#include "maybe.h"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
enum class readline_cmd_t {
|
enum class readline_cmd_t {
|
||||||
beginning_of_line,
|
beginning_of_line,
|
||||||
end_of_line,
|
end_of_line,
|
||||||
|
@ -172,8 +170,4 @@ void input_common_queue_ch(char_event_t ch);
|
||||||
/// once).
|
/// once).
|
||||||
void input_common_next_ch(char_event_t ch);
|
void input_common_next_ch(char_event_t ch);
|
||||||
|
|
||||||
/// Adds a callback to be invoked at the next turn of the "event loop." The callback function will
|
|
||||||
/// be invoked and passed arg.
|
|
||||||
void input_common_add_callback(std::function<void(void)>);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3436,7 +3436,7 @@ void reader_react_to_color_change() {
|
||||||
if (!data->repaint_needed || !data->screen_reset_needed) {
|
if (!data->repaint_needed || !data->screen_reset_needed) {
|
||||||
data->repaint_needed = true;
|
data->repaint_needed = true;
|
||||||
data->screen_reset_needed = true;
|
data->screen_reset_needed = true;
|
||||||
input_common_add_callback(reader_repaint_if_needed);
|
input_common_queue_ch(readline_cmd_t::repaint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue