diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/globals.h | 8 | ||||
-rw-r--r-- | src/nvim/option.c | 2 | ||||
-rw-r--r-- | src/nvim/tui/input.c | 25 |
3 files changed, 27 insertions, 8 deletions
diff --git a/src/nvim/globals.h b/src/nvim/globals.h index f47697b190..a988af79b2 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -83,10 +83,10 @@ EXTERN struct nvim_stats_s { int64_t redraw; } g_stats INIT(= { 0, 0 }); -/* Values for "starting" */ -#define NO_SCREEN 2 /* no screen updating yet */ -#define NO_BUFFERS 1 /* not all buffers loaded yet */ -/* 0 not starting anymore */ +// Values for "starting". +#define NO_SCREEN 2 // no screen updating yet +#define NO_BUFFERS 1 // not all buffers loaded yet +// 0 not starting anymore /* * Number of Rows and Columns in the screen. diff --git a/src/nvim/option.c b/src/nvim/option.c index b85ec6dbcc..fc1fab834e 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -883,7 +883,7 @@ set_options_default ( /// @param name The name of the option /// @param val The value of the option /// @param allocated If true, do not copy default as it was already allocated. -void set_string_default(const char *name, char *val, bool allocated) +static void set_string_default(const char *name, char *val, bool allocated) FUNC_ATTR_NONNULL_ALL { int opt_idx = findoption(name); diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index e0dd4022ed..3eb88366d6 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -357,12 +357,28 @@ static bool handle_forced_escape(TermInput *input) static void set_bg_deferred(void **argv) { char *bgvalue = argv[0]; - set_string_default("bg", bgvalue, false); - if (!option_was_set("bg")) { - set_option_value("bg", 0, bgvalue, 0); + if (starting) { + // Wait until after startup, so OptionSet is triggered. + loop_schedule(&main_loop, event_create(set_bg_deferred, 1, bgvalue)); + return; + } + if (!option_was_set("bg") && !strequal((char *)p_bg, bgvalue)) { + // Value differs, apply it. + set_option_value("bg", 0L, bgvalue, 0); + reset_option_was_set("bg"); } } +// During startup, tui.c requests the background color (see `ext.get_bg`). +// +// Here in input.c, we watch for the terminal response `\e]11;COLOR\a`. If +// COLOR matches `rgb:RRRR/GGGG/BBBB` where R, G, and B are hex digits, then +// compute the luminance[1] of the RGB color and classify it as light/dark +// accordingly. Note that the color components may have anywhere from one to +// four hex digits, and require scaling accordingly as values out of 4, 8, 12, +// or 16 bits. +// +// [1] https://en.wikipedia.org/wiki/Luma_%28video%29 static bool handle_background_color(TermInput *input) { size_t count = 0; @@ -407,7 +423,10 @@ static bool handle_background_color(TermInput *input) double b = (double)rgb[2] / (double)rgb_max[2]; double luminance = (0.299 * r) + (0.587 * g) + (0.114 * b); // CCIR 601 char *bgvalue = luminance < 0.5 ? "dark" : "light"; + DLOG("bg response: %s", bgvalue); loop_schedule(&main_loop, event_create(set_bg_deferred, 1, bgvalue)); + } else { + DLOG("failed to parse bg response"); } return true; } |