From 0dd8951cb3d3b260575162ebbd1914c61a10d876 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 21 Jul 2019 19:14:19 +0200 Subject: flash: implement 'flash' Use our own escape sequence for the 'flash' terminfo entry. Implemented by arming a timer FD and setting a boolean that indicates we're currently "flashing". The renderer draws a semi-transparent yellowish layer over the entire window when "flashing" is active. --- render.c | 58 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 21 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index db9881a3..9664cd20 100644 --- a/render.c +++ b/render.c @@ -296,34 +296,40 @@ grid_render(struct terminal *term) struct buffer *buf = shm_get_buffer(term->wl.shm, term->width, term->height); cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE); + if (term->flash_active) + term_damage_view(term); + static struct buffer *last_buf = NULL; - if (last_buf != buf || false) { - if (last_buf != NULL) { - LOG_DBG("new buffer"); + static bool last_flash = false; - /* Fill area outside the cell grid with the default background color */ - int rmargin = term->cols * term->cell_width; - int bmargin = term->rows * term->cell_height; - int rmargin_width = term->width - rmargin; - int bmargin_height = term->height - bmargin; + /* If we resized the window, or is flashing, or just stopped flashing */ + if (last_buf != buf || term->flash_active || last_flash) { + LOG_DBG("new buffer"); - uint32_t _bg = !term->reverse ? term->colors.bg : term->colors.fg; - struct rgb bg = color_hex_to_rgb(_bg); - cairo_set_source_rgb(buf->cairo, bg.r, bg.g, bg.b); + /* Fill area outside the cell grid with the default background color */ + int rmargin = term->cols * term->cell_width; + int bmargin = term->rows * term->cell_height; + int rmargin_width = term->width - rmargin; + int bmargin_height = term->height - bmargin; - cairo_rectangle(buf->cairo, rmargin, 0, rmargin_width, term->height); - cairo_rectangle(buf->cairo, 0, bmargin, term->width, bmargin_height); - cairo_fill(buf->cairo); + uint32_t _bg = !term->reverse ? term->colors.bg : term->colors.fg; + struct rgb bg = color_hex_to_rgb(_bg); + cairo_set_source_rgb(buf->cairo, bg.r, bg.g, bg.b); - wl_surface_damage_buffer( - term->wl.surface, rmargin, 0, rmargin_width, term->height); - wl_surface_damage_buffer( - term->wl.surface, 0, bmargin, term->width, bmargin_height); + cairo_rectangle(buf->cairo, rmargin, 0, rmargin_width, term->height); + cairo_rectangle(buf->cairo, 0, bmargin, term->width, bmargin_height); + cairo_fill(buf->cairo); + + wl_surface_damage_buffer( + term->wl.surface, rmargin, 0, rmargin_width, term->height); + wl_surface_damage_buffer( + term->wl.surface, 0, bmargin, term->width, bmargin_height); + + /* Force a full grid refresh */ + term_damage_view(term); - /* Force a full grid refresh */ - term_damage_all(term); - } last_buf = buf; + last_flash = term->flash_active; } bool all_clean = tll_length(term->grid->scroll_damage) == 0; @@ -419,6 +425,16 @@ grid_render(struct terminal *term) if (gseq.count > 0) gseq_flush(term, buf); + if (term->flash_active) { + cairo_set_source_rgba(buf->cairo, 1.0, 1.0, 0.0, 0.5); + cairo_set_operator(buf->cairo, CAIRO_OPERATOR_OVER); + cairo_rectangle(buf->cairo, 0, 0, term->width, term->height); + cairo_fill(buf->cairo); + + wl_surface_damage_buffer( + term->wl.surface, 0, 0, term->width, term->height); + } + assert(term->grid->offset >= 0 && term->grid->offset < term->grid->num_rows); assert(term->grid->view >= 0 && term->grid->view < term->grid->num_rows); -- cgit v1.3