Store updated tab bar edge colors on every tab bar redraw

This commit is contained in:
Kovid Goyal 2022-12-04 14:38:56 +05:30
parent cf8f904720
commit 7a348d6ef1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 32 additions and 7 deletions

View File

@ -1497,3 +1497,4 @@ def make_x11_window_a_dock_window(x11_window_id: int, strut: Tuple[int, int, int
def unicode_database_version() -> Tuple[int, int, int]: ...
def wrapped_kitten_names() -> List[str]: ...
def expand_ansi_c_escapes(test: str) -> str: ...
def update_tab_bar_edge_colors(os_window_id: int) -> bool: ...

View File

@ -3972,11 +3972,11 @@ effective_cell_edge_color(char_type ch, color_type fg, color_type bg, bool is_le
END_ALLOW_CASE_RANGE
}
static PyObject*
line_edge_colors(Screen *self, PyObject *a UNUSED) {
bool
get_line_edge_colors(Screen *self, color_type *left, color_type *right) {
// Return the color at the left and right edges of the line with the cursor on it
Line *line = range_line_(self, self->cursor->y);
if (!line) { PyErr_SetString(PyExc_IndexError, "Line number out of range"); return NULL; }
if (!line) return false;
color_type left_cell_fg = 0, left_cell_bg = 0, right_cell_bg = 0, right_cell_fg = 0;
index_type cell_color_x = 0;
char_type left_char = line_get_char(line, cell_color_x);
@ -3984,9 +3984,16 @@ line_edge_colors(Screen *self, PyObject *a UNUSED) {
if (line->xnum > 0) cell_color_x = line->xnum - 1;
char_type right_char = line_get_char(line, cell_color_x);
colors_for_cell(line, self->color_profile, &cell_color_x, &right_cell_fg, &right_cell_bg);
unsigned long left = effective_cell_edge_color(left_char, left_cell_fg, left_cell_bg, true);
unsigned long right = effective_cell_edge_color(right_char, right_cell_fg, right_cell_bg, false);
return Py_BuildValue("kk", left, right);
*left = effective_cell_edge_color(left_char, left_cell_fg, left_cell_bg, true);
*right = effective_cell_edge_color(right_char, right_cell_fg, right_cell_bg, false);
return true;
}
static PyObject*
line_edge_colors(Screen *self, PyObject *a UNUSED) {
color_type left, right;
if (!get_line_edge_colors(self, &left, &right)) { PyErr_SetString(PyExc_IndexError, "Line number out of range"); return NULL; }
return Py_BuildValue("kk", (unsigned long)left, (unsigned long)right);
}

View File

@ -265,6 +265,7 @@ bool screen_detect_url(Screen *screen, unsigned int x, unsigned int y);
int screen_cursor_at_a_shell_prompt(const Screen *);
bool screen_fake_move_cursor_to_position(Screen *, index_type x, index_type y);
bool screen_send_signal_for_key(Screen *, char key);
bool get_line_edge_colors(Screen *self, color_type *left, color_type *right);
#define DECLARE_CH_SCREEN_HANDLER(name) void screen_##name(Screen *screen);
DECLARE_CH_SCREEN_HANDLER(bell)
DECLARE_CH_SCREEN_HANDLER(backspace)

View File

@ -1124,6 +1124,17 @@ PYWRAP1(patch_global_colors) {
Py_RETURN_NONE;
}
PYWRAP1(update_tab_bar_edge_colors) {
id_type os_window_id;
PA("K", &os_window_id);
WITH_OS_WINDOW(os_window_id)
if (os_window->tab_bar_render_data.screen) {
if (get_line_edge_colors(os_window->tab_bar_render_data.screen, &os_window->tab_bar_edge_color.left, &os_window->tab_bar_edge_color.right)) { Py_RETURN_TRUE; }
}
END_WITH_OS_WINDOW
Py_RETURN_FALSE;
}
static PyObject*
pyset_background_image(PyObject *self UNUSED, PyObject *args) {
const char *path;
@ -1348,6 +1359,7 @@ static PyMethodDef module_methods[] = {
MW(os_window_font_size, METH_VARARGS),
MW(set_os_window_size, METH_VARARGS),
MW(get_os_window_size, METH_VARARGS),
MW(update_tab_bar_edge_colors, METH_VARARGS),
MW(set_boss, METH_O),
MW(get_boss, METH_NOARGS),
MW(apply_options_update, METH_NOARGS),

View File

@ -195,6 +195,9 @@ typedef struct {
unsigned int active_tab, num_tabs, capacity, last_active_tab, last_num_tabs, last_active_window_id;
bool focused_at_last_render, needs_render;
ScreenRenderData tab_bar_render_data;
struct {
color_type left, right;
} tab_bar_edge_color;
bool tab_bar_data_updated;
bool is_focused;
monotonic_t cursor_blink_zero_time, last_mouse_activity_at;

View File

@ -14,7 +14,7 @@ from .config import build_ansi_color_table
from .constants import config_dir
from .fast_data_types import (
DECAWM, Color, Region, Screen, cell_size_for_window, get_boss, get_options,
pt_to_px, set_tab_bar_render_data, viewport_for_window,
pt_to_px, set_tab_bar_render_data, update_tab_bar_edge_colors, viewport_for_window,
)
from .rgb import alpha_blend, color_as_sgr, color_from_int, to_color
from .types import WindowGeometry, run_once
@ -664,6 +664,7 @@ class TabBar:
self.cell_ranges = cr
s.erase_in_line(0, False) # Ensure no long titles bleed after the last tab
self.align()
update_tab_bar_edge_colors(self.os_window_id)
def align_with_factor(self, factor: int = 1) -> None:
if not self.cell_ranges: