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. --- main.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 54140fd0..d7759c72 100644 --- a/main.c +++ b/main.c @@ -10,6 +10,8 @@ #include #include +#include + #include #include #include @@ -325,6 +327,7 @@ main(int argc, char *const *argv) .keypad_keys_mode = KEYPAD_NUMERICAL, .auto_margin = true, .window_title_stack = tll_init(), + .flash_timer_fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC), .vt = { .state = 1, /* STATE_GROUND */ .attrs = { @@ -681,6 +684,7 @@ main(int argc, char *const *argv) {.fd = wl_display_get_fd(term.wl.display), .events = POLLIN}, {.fd = term.ptmx, .events = POLLIN}, {.fd = term.kbd.repeat.pipe_read_fd, .events = POLLIN}, + {.fd = term.flash_timer_fd, .events = POLLIN}, }; wl_display_flush(term.wl.display); @@ -775,6 +779,23 @@ main(int argc, char *const *argv) if (fds[2].revents & POLLHUP) LOG_ERR("keyboard repeat handling thread died"); + + if (fds[3].revents & POLLIN) { + uint64_t expiration_count; + ssize_t ret = read( + term.flash_timer_fd, &expiration_count, sizeof(expiration_count)); + + if (ret < 0) + LOG_ERRNO("failed to read flash timer"); + else + LOG_DBG("flash timer expired %llu times", + (unsigned long long)expiration_count); + + term.flash_active = false; + term_damage_view(&term); + if (term.frame_callback == NULL) + grid_render(&term); + } } out: @@ -862,6 +883,9 @@ out: cairo_glyph_free(f->glyph_cache[j].glyphs); } + if (term.flash_timer_fd != -1) + close(term.flash_timer_fd); + if (term.ptmx != -1) close(term.ptmx); -- cgit v1.3