mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
term: group 'flash' state together in a struct
This commit is contained in:
parent
61409d40e2
commit
196f9d67c2
4 changed files with 18 additions and 14 deletions
14
main.c
14
main.c
|
|
@ -327,7 +327,9 @@ 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),
|
||||
.flash = {
|
||||
.fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC),
|
||||
},
|
||||
.blink_timer_fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC),
|
||||
.vt = {
|
||||
.state = 1, /* STATE_GROUND */
|
||||
|
|
@ -685,7 +687,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},
|
||||
{.fd = term.flash.fd, .events = POLLIN},
|
||||
{.fd = term.blink_timer_fd, .events = POLLIN},
|
||||
};
|
||||
|
||||
|
|
@ -785,7 +787,7 @@ main(int argc, char *const *argv)
|
|||
if (fds[3].revents & POLLIN) {
|
||||
uint64_t expiration_count;
|
||||
ssize_t ret = read(
|
||||
term.flash_timer_fd, &expiration_count, sizeof(expiration_count));
|
||||
term.flash.fd, &expiration_count, sizeof(expiration_count));
|
||||
|
||||
if (ret < 0)
|
||||
LOG_ERRNO("failed to read flash timer");
|
||||
|
|
@ -793,7 +795,7 @@ main(int argc, char *const *argv)
|
|||
LOG_DBG("flash timer expired %llu times",
|
||||
(unsigned long long)expiration_count);
|
||||
|
||||
term.flash_active = false;
|
||||
term.flash.active = false;
|
||||
term_damage_view(&term);
|
||||
if (term.frame_callback == NULL)
|
||||
grid_render(&term);
|
||||
|
|
@ -915,8 +917,8 @@ out:
|
|||
cairo_glyph_free(f->glyph_cache[j].glyphs);
|
||||
}
|
||||
|
||||
if (term.flash_timer_fd != -1)
|
||||
close(term.flash_timer_fd);
|
||||
if (term.flash.fd != -1)
|
||||
close(term.flash.fd);
|
||||
if (term.blink_timer_fd != -1)
|
||||
close(term.blink_timer_fd);
|
||||
|
||||
|
|
|
|||
4
osc.c
4
osc.c
|
|
@ -213,10 +213,10 @@ osc_flash(struct terminal *term)
|
|||
.it_value = {.tv_sec = 0, .tv_nsec = duration_ms * 1000000},
|
||||
};
|
||||
|
||||
if (timerfd_settime(term->flash_timer_fd, 0, &alarm, NULL) < 0)
|
||||
if (timerfd_settime(term->flash.fd, 0, &alarm, NULL) < 0)
|
||||
LOG_ERRNO("failed to arm flash timer");
|
||||
else {
|
||||
term->flash_active = true;
|
||||
term->flash.active = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
8
render.c
8
render.c
|
|
@ -314,14 +314,14 @@ 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)
|
||||
if (term->flash.active)
|
||||
term_damage_view(term);
|
||||
|
||||
static struct buffer *last_buf = NULL;
|
||||
static bool last_flash = false;
|
||||
|
||||
/* If we resized the window, or is flashing, or just stopped flashing */
|
||||
if (last_buf != buf || term->flash_active || last_flash) {
|
||||
if (last_buf != buf || term->flash.active || last_flash) {
|
||||
LOG_DBG("new buffer");
|
||||
|
||||
/* Fill area outside the cell grid with the default background color */
|
||||
|
|
@ -347,7 +347,7 @@ grid_render(struct terminal *term)
|
|||
term_damage_view(term);
|
||||
|
||||
last_buf = buf;
|
||||
last_flash = term->flash_active;
|
||||
last_flash = term->flash.active;
|
||||
}
|
||||
|
||||
bool all_clean = tll_length(term->grid->scroll_damage) == 0;
|
||||
|
|
@ -475,7 +475,7 @@ grid_render(struct terminal *term)
|
|||
if (gseq.count > 0)
|
||||
gseq_flush(term, buf);
|
||||
|
||||
if (term->flash_active) {
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -243,8 +243,10 @@ struct terminal {
|
|||
char *window_title;
|
||||
tll(char *) window_title_stack;
|
||||
|
||||
bool flash_active;
|
||||
int flash_timer_fd;
|
||||
struct {
|
||||
bool active;
|
||||
int fd;
|
||||
} flash;
|
||||
|
||||
bool is_blinking;
|
||||
enum { BLINK_ON, BLINK_OFF } blink_mode;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue