From 5e7e512d8af21b52984238dc43688fbb6482d319 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 20 Oct 2024 10:20:42 +0530 Subject: [PATCH] Do not store Screen pointer on CursorTrail The lifetime of the Screen pointer is managed by Window. Also we want the cursor trail color to be the color of the active window cursor not the color of the cursor in the last rendered window. --- kitty/child-monitor.c | 4 +++- kitty/cursor_trail.c | 3 +-- kitty/shaders.c | 9 ++++----- kitty/state.h | 3 +-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index a71ca63b5..ccec2932d 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -802,17 +802,19 @@ render_prepared_os_window(OSWindow *os_window, unsigned int active_window_id, co br->is_dirty = false; if (TD.screen && os_window->num_tabs >= OPT(tab_bar_min_tabs)) draw_cells(TD.vao_idx, &TD, os_window, true, true, false, NULL); unsigned int num_of_visible_windows = 0; + Window *active_window = NULL; for (unsigned int i = 0; i < tab->num_windows; i++) { if (tab->windows[i].visible) num_of_visible_windows++; } for (unsigned int i = 0; i < tab->num_windows; i++) { Window *w = tab->windows + i; if (w->visible && WD.screen) { bool is_active_window = i == tab->active_window; + if (is_active_window) active_window = w; draw_cells(WD.vao_idx, &WD, os_window, is_active_window, false, num_of_visible_windows == 1, w); if (WD.screen->start_visual_bell_at != 0) set_maximum_wait(ANIMATION_SAMPLE_WAIT); w->cursor_opacity_at_last_render = WD.screen->cursor_render_info.opacity; w->last_cursor_shape = WD.screen->cursor_render_info.shape; } } - if (OPT(cursor_trail) && tab->cursor_trail.needs_render) draw_cursor_trail(&tab->cursor_trail); + if (OPT(cursor_trail) && tab->cursor_trail.needs_render) draw_cursor_trail(&tab->cursor_trail, active_window); if (os_window->live_resize.in_progress) draw_resizing_text(os_window); swap_window_buffers(os_window); os_window->last_active_tab = os_window->active_tab; os_window->last_num_tabs = os_window->num_tabs; os_window->last_active_window_id = active_window_id; diff --git a/kitty/cursor_trail.c b/kitty/cursor_trail.c index 1240407f3..da0e217bb 100644 --- a/kitty/cursor_trail.c +++ b/kitty/cursor_trail.c @@ -1,5 +1,5 @@ +#include #include "state.h" -#include "float.h" inline static float norm(float x, float y) { @@ -43,7 +43,6 @@ update_cursor_trail_target(CursorTrail *ct, Window *w) { EDGE(x, 1) = right; EDGE(y, 0) = top; EDGE(y, 1) = bottom; - ct->screen = WD.screen; } } diff --git a/kitty/shaders.c b/kitty/shaders.c index e64440169..f953fe71b 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -368,6 +368,8 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, c if (IS_SPECIAL_COLOR(cursor_text_color)) rd->cursor_fg = cell_bg; else rd->cursor_fg = COLOR(cursor_text_color); } + // store last rendered cursor color for trail rendering + screen->last_rendered.cursor_bg = rd->cursor_bg; } else rd->cursor_x = screen->columns, rd->cursor_y = screen->lines; rd->cursor_w = rd->cursor_x; if ((rd->cursor_fg_sprite_idx == BLOCK_IDX || rd->cursor_fg_sprite_idx == UNDERLINE_IDX) && line_for_cursor && line_for_cursor->gpu_cells[cursor->x].attrs.width > 1) { @@ -385,9 +387,6 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, c #undef COLOR rd->url_color = OPT(url_color); rd->url_style = OPT(url_style); - // store last rendered cursor color for trail rendering - screen->last_rendered.cursor_bg = rd->cursor_bg; - unmap_vao_buffer(vao_idx, uniform_buffer); rd = NULL; } @@ -1148,7 +1147,7 @@ init_trail_program(void) { } void -draw_cursor_trail(CursorTrail *trail) { +draw_cursor_trail(CursorTrail *trail, Window *active_window) { bind_program(TRAIL_PROGRAM); glUniform4fv(trail_program_layout.uniforms.x_coords, 1, trail->corner_x); @@ -1157,7 +1156,7 @@ draw_cursor_trail(CursorTrail *trail) { glUniform2fv(trail_program_layout.uniforms.cursor_edge_x, 1, trail->cursor_edge_x); glUniform2fv(trail_program_layout.uniforms.cursor_edge_y, 1, trail->cursor_edge_y); - color_vec3(trail_program_layout.uniforms.trail_color, trail->screen->last_rendered.cursor_bg); + color_vec3(trail_program_layout.uniforms.trail_color, active_window ? active_window->render_data.screen->last_rendered.cursor_bg : OPT(foreground)); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); diff --git a/kitty/state.h b/kitty/state.h index a121073c7..6e9619796 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -218,7 +218,6 @@ typedef struct { typedef struct { bool needs_render; monotonic_t updated_at; - Screen* screen; float corner_x[4]; float corner_y[4]; float cursor_edge_x[2]; @@ -366,7 +365,7 @@ ssize_t create_border_vao(void); bool send_cell_data_to_gpu(ssize_t, float, float, float, float, Screen *, OSWindow *); void draw_cells(ssize_t, const WindowRenderData*, OSWindow *, bool, bool, bool, Window*); void draw_centered_alpha_mask(OSWindow *w, size_t screen_width, size_t screen_height, size_t width, size_t height, uint8_t *canvas, float); -void draw_cursor_trail(CursorTrail *trail); +void draw_cursor_trail(CursorTrail *trail, Window *active_window); bool update_cursor_trail(CursorTrail *ct, Window *w, monotonic_t now, OSWindow *os_window); void update_surface_size(int, int, uint32_t); void free_texture(uint32_t*);