From 5116e40581ad5f2a326e3022a1f148402cf26b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 29 Sep 2020 10:03:00 +0200 Subject: [PATCH 1/5] term: add term_damage_cursor() and term_damage_margins() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit term_damage_cursor() damages the cell where the cursor is currently at. This can be used to ensure the cursor is re-drawn, if there aren’t any other pending updates. term_damage_margins() requests the margins be redrawn the next time we render the grid. --- terminal.c | 13 +++++++++++++ terminal.h | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/terminal.c b/terminal.c index 5e0dc65a..0840a45c 100644 --- a/terminal.c +++ b/terminal.c @@ -1626,6 +1626,19 @@ term_damage_view(struct terminal *term) term_damage_rows_in_view(term, 0, term->rows - 1); } +void +term_damage_cursor(struct terminal *term) +{ + term->grid->cur_row->cells[term->grid->cursor.point.col].attrs.clean = 0; + term->grid->cur_row->dirty = true; +} + +void +term_damage_margins(struct terminal *term) +{ + term->render.margins = true; +} + void term_damage_scroll(struct terminal *term, enum damage_type damage_type, struct scroll_region region, int lines) diff --git a/terminal.h b/terminal.h index 12e93ce2..13339c3b 100644 --- a/terminal.h +++ b/terminal.h @@ -388,6 +388,8 @@ struct terminal { bool title; } pending; + bool margins; /* Someone explicitly requested a refresh of the margins */ + int scrollback_lines; /* Number of scrollback lines, from conf (TODO: move out from render struct?) */ struct { @@ -512,6 +514,9 @@ void term_damage_rows_in_view(struct terminal *term, int start, int end); void term_damage_all(struct terminal *term); void term_damage_view(struct terminal *term); +void term_damage_cursor(struct terminal *term); +void term_damage_margins(struct terminal *term); + void term_reset_view(struct terminal *term); void term_damage_scroll( From b19e07ad1c3e7b77a964e20b9dc2d9721a069f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 29 Sep 2020 10:04:41 +0200 Subject: [PATCH 2/5] render: term->render.margins is used to explicitly tell us to re-render margins --- render.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/render.c b/render.c index 43bcf5eb..86f028f7 100644 --- a/render.c +++ b/render.c @@ -1568,7 +1568,7 @@ static const struct wl_callback_listener frame_listener = { }; static void -grid_render(struct terminal *term, bool redraw_margins) +grid_render(struct terminal *term) { if (term->is_shutting_down) return; @@ -1588,7 +1588,7 @@ grid_render(struct terminal *term, bool redraw_margins) if (term->render.last_buf != buf || term->flash.active || term->render.was_flashing || term->is_searching != term->render.was_searching || - redraw_margins) + term->render.margins) { if (term->render.last_buf != NULL && term->render.last_buf->width == buf->width && @@ -1596,7 +1596,7 @@ grid_render(struct terminal *term, bool redraw_margins) !term->flash.active && !term->render.was_flashing && term->is_searching == term->render.was_searching && - !redraw_margins) + !term->render.margins) { static bool has_warned = false; if (!has_warned) { @@ -1972,13 +1972,11 @@ frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_da term->window->frame_callback = NULL; bool grid = term->render.pending.grid; - bool margins = term->render.pending.margins; bool csd = term->render.pending.csd; bool search = term->render.pending.search; bool title = term->render.pending.title; term->render.pending.grid = false; - term->render.pending.margins = false; term->render.pending.csd = false; term->render.pending.search = false; term->render.pending.title = false; @@ -1995,11 +1993,8 @@ frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_da if (search && term->is_searching) render_search_box(term); - if ((grid || margins) && - (!term->delayed_render_timer.is_armed || csd || search)) - { - grid_render(term, margins); - } + if (grid && (!term->delayed_render_timer.is_armed || csd || search)) + grid_render(term); } /* Move to terminal.c? */ @@ -2336,13 +2331,11 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data) assert(term->window->is_configured); bool grid = term->render.refresh.grid; - bool margins = term->render.refresh.margins; bool csd = term->render.refresh.csd; bool search = term->render.refresh.search; bool title = term->render.refresh.title; term->render.refresh.grid = false; - term->render.refresh.margins = false; term->render.refresh.csd = false; term->render.refresh.search = false; term->render.refresh.title = false; @@ -2357,12 +2350,11 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data) render_update_title(term); if (search) render_search_box(term); - if (grid || margins) - grid_render(term, margins); + if (grid) + grid_render(term); } else { /* Tells the frame callback to render again */ term->render.pending.grid |= grid; - term->render.pending.margins |= margins; term->render.pending.csd |= csd; term->render.pending.search |= search; term->render.pending.title |= title; From edb904a1877324ae4977c8a38596487518c9e1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 29 Sep 2020 10:05:52 +0200 Subject: [PATCH 3/5] =?UTF-8?q?osc:=20don=E2=80=99t=20explicitly=20call=20?= =?UTF-8?q?render=5Frefresh()=20when=20changing=20the=20color=20palette?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Doing so will schedule the renderer “as soon as possible”. I.e we’re by-passing the regular scheduler, and thus we’re by-passing the user’s setting of the delayed-render-* timers. The fact that we’re scheduling “as soon as possible” also means we’re much more likely to trigger flickering, or color flashes, if the application is changing colors which are on the screen. To handle changes to the cursor color(s), use the new term_damage_cursor() instead of render_refresh(). To handle background color changes, which affect the margins, use the new term_damage_margins() instead of render_refresh_margins(), Closes #141 --- osc.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/osc.c b/osc.c index 7e22d7c1..384cf401 100644 --- a/osc.c +++ b/osc.c @@ -589,7 +589,6 @@ osc_dispatch(struct terminal *term) } } - render_refresh(term); break; } @@ -635,8 +634,7 @@ osc_dispatch(struct terminal *term) } term_damage_view(term); - render_refresh(term); - render_refresh_margins(term); + term_damage_margins(term); break; } @@ -664,7 +662,8 @@ osc_dispatch(struct terminal *term) term->cursor_color.cursor = 0; /* Invert fg/bg */ else term->cursor_color.cursor = 1u << 31 | color; - render_refresh(term); + + term_damage_cursor(term); break; case 30: /* Set tab title */ @@ -705,7 +704,6 @@ osc_dispatch(struct terminal *term) } } - render_refresh(term); break; } @@ -716,22 +714,20 @@ osc_dispatch(struct terminal *term) LOG_DBG("resetting foreground"); term->colors.fg = term->colors.default_fg; term_damage_view(term); - render_refresh(term); break; case 111: /* Reset default text background color */ LOG_DBG("resetting background"); term->colors.bg = term->colors.default_bg; term_damage_view(term); - render_refresh(term); - render_refresh_margins(term); + term_damage_margins(term); break; case 112: LOG_DBG("resetting cursor color"); term->cursor_color.text = term->default_cursor_color.text; term->cursor_color.cursor = term->default_cursor_color.cursor; - render_refresh(term); + term_damage_cursor(term); break; case 555: From 7ffd31e13a8834938550222d8b6078c4b98616f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 29 Sep 2020 10:08:59 +0200 Subject: [PATCH 4/5] render: remove render_refresh_margins() --- render.c | 6 ------ render.h | 1 - terminal.h | 2 -- 3 files changed, 9 deletions(-) diff --git a/render.c b/render.c index 86f028f7..210eaf47 100644 --- a/render.c +++ b/render.c @@ -2385,12 +2385,6 @@ render_refresh(struct terminal *term) term->render.refresh.grid = true; } -void -render_refresh_margins(struct terminal *term) -{ - term->render.refresh.margins = true; -} - void render_refresh_csd(struct terminal *term) { diff --git a/render.h b/render.h index 3f8cf540..05c79322 100644 --- a/render.h +++ b/render.h @@ -13,7 +13,6 @@ bool render_resize(struct terminal *term, int width, int height); bool render_resize_force(struct terminal *term, int width, int height); void render_refresh(struct terminal *term); -void render_refresh_margins(struct terminal *term); void render_refresh_csd(struct terminal *term); void render_refresh_search(struct terminal *term); void render_refresh_title(struct terminal *term); diff --git a/terminal.h b/terminal.h index 13339c3b..60a4aba4 100644 --- a/terminal.h +++ b/terminal.h @@ -373,7 +373,6 @@ struct terminal { /* Scheduled for rendering, as soon-as-possible */ struct { bool grid; - bool margins; bool csd; bool search; bool title; @@ -382,7 +381,6 @@ struct terminal { /* Scheduled for rendering, in the next frame callback */ struct { bool grid; - bool margins; bool csd; bool search; bool title; From 002648d2a9112afc7651f6795b491ba1fba1b6f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 29 Sep 2020 10:11:03 +0200 Subject: [PATCH 5/5] changelog: fixed color flashes with OSC 4,10,11 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fbc2cc0..ca17ca4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ than specified in the binding. This allows you to, for example, quickly press the middle-button to paste multiple times (https://codeberg.org/dnkl/foot/issues/146). +* Color flashes when changing the color palette with OSC 4,10,11 + (https://codeberg.org/dnkl/foot/issues/141). ### Security