mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-19 05:33:44 -04:00
term: group 'blink' state together in a struct
This commit is contained in:
parent
196f9d67c2
commit
428b31f071
3 changed files with 21 additions and 17 deletions
14
main.c
14
main.c
|
|
@ -330,7 +330,9 @@ main(int argc, char *const *argv)
|
||||||
.flash = {
|
.flash = {
|
||||||
.fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC),
|
.fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC),
|
||||||
},
|
},
|
||||||
.blink_timer_fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC),
|
.blink = {
|
||||||
|
.fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC),
|
||||||
|
},
|
||||||
.vt = {
|
.vt = {
|
||||||
.state = 1, /* STATE_GROUND */
|
.state = 1, /* STATE_GROUND */
|
||||||
.attrs = {
|
.attrs = {
|
||||||
|
|
@ -688,7 +690,7 @@ main(int argc, char *const *argv)
|
||||||
{.fd = term.ptmx, .events = POLLIN},
|
{.fd = term.ptmx, .events = POLLIN},
|
||||||
{.fd = term.kbd.repeat.pipe_read_fd, .events = POLLIN},
|
{.fd = term.kbd.repeat.pipe_read_fd, .events = POLLIN},
|
||||||
{.fd = term.flash.fd, .events = POLLIN},
|
{.fd = term.flash.fd, .events = POLLIN},
|
||||||
{.fd = term.blink_timer_fd, .events = POLLIN},
|
{.fd = term.blink.fd, .events = POLLIN},
|
||||||
};
|
};
|
||||||
|
|
||||||
wl_display_flush(term.wl.display);
|
wl_display_flush(term.wl.display);
|
||||||
|
|
@ -804,7 +806,7 @@ main(int argc, char *const *argv)
|
||||||
if (fds[4].revents & POLLIN) {
|
if (fds[4].revents & POLLIN) {
|
||||||
uint64_t expiration_count;
|
uint64_t expiration_count;
|
||||||
ssize_t ret = read(
|
ssize_t ret = read(
|
||||||
term.blink_timer_fd, &expiration_count, sizeof(expiration_count));
|
term.blink.fd, &expiration_count, sizeof(expiration_count));
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
LOG_ERRNO("failed to read blink timer");
|
LOG_ERRNO("failed to read blink timer");
|
||||||
|
|
@ -812,7 +814,7 @@ main(int argc, char *const *argv)
|
||||||
LOG_DBG("blink timer expired %llu times",
|
LOG_DBG("blink timer expired %llu times",
|
||||||
(unsigned long long)expiration_count);
|
(unsigned long long)expiration_count);
|
||||||
|
|
||||||
term.blink_mode = term.blink_mode == BLINK_ON
|
term.blink.state = term.blink.state == BLINK_ON
|
||||||
? BLINK_OFF : BLINK_ON;
|
? BLINK_OFF : BLINK_ON;
|
||||||
|
|
||||||
/* Scan all visible cells and mark rows with blinking cells dirty */
|
/* Scan all visible cells and mark rows with blinking cells dirty */
|
||||||
|
|
@ -919,8 +921,8 @@ out:
|
||||||
|
|
||||||
if (term.flash.fd != -1)
|
if (term.flash.fd != -1)
|
||||||
close(term.flash.fd);
|
close(term.flash.fd);
|
||||||
if (term.blink_timer_fd != -1)
|
if (term.blink.fd != -1)
|
||||||
close(term.blink_timer_fd);
|
close(term.blink.fd);
|
||||||
|
|
||||||
if (term.ptmx != -1)
|
if (term.ptmx != -1)
|
||||||
close(term.ptmx);
|
close(term.ptmx);
|
||||||
|
|
|
||||||
16
render.c
16
render.c
|
|
@ -118,7 +118,7 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell,
|
||||||
_bg = swap;
|
_bg = swap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell->attrs.blink && term->blink_mode == BLINK_OFF)
|
if (cell->attrs.blink && term->blink.state == BLINK_OFF)
|
||||||
_fg = _bg;
|
_fg = _bg;
|
||||||
|
|
||||||
struct rgb fg = color_hex_to_rgb(_fg);
|
struct rgb fg = color_hex_to_rgb(_fg);
|
||||||
|
|
@ -132,7 +132,7 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell,
|
||||||
cairo_rectangle(buf->cairo, x, y, width, height);
|
cairo_rectangle(buf->cairo, x, y, width, height);
|
||||||
cairo_fill(buf->cairo);
|
cairo_fill(buf->cairo);
|
||||||
|
|
||||||
if (cell->attrs.blink && !term->is_blinking) {
|
if (cell->attrs.blink && !term->blink.active) {
|
||||||
/* First cell we see that has blink set - arm blink timer */
|
/* First cell we see that has blink set - arm blink timer */
|
||||||
LOG_DBG("arming blink timer");
|
LOG_DBG("arming blink timer");
|
||||||
struct itimerspec alarm = {
|
struct itimerspec alarm = {
|
||||||
|
|
@ -140,10 +140,10 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell,
|
||||||
.it_interval = {.tv_sec = 0, .tv_nsec = 500 * 1000000},
|
.it_interval = {.tv_sec = 0, .tv_nsec = 500 * 1000000},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (timerfd_settime(term->blink_timer_fd, 0, &alarm, NULL) < 0)
|
if (timerfd_settime(term->blink.fd, 0, &alarm, NULL) < 0)
|
||||||
LOG_ERRNO("failed to arm blink timer");
|
LOG_ERRNO("failed to arm blink timer");
|
||||||
else
|
else
|
||||||
term->is_blinking = true;
|
term->blink.active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell->c[0] == '\0' || cell->attrs.conceal)
|
if (cell->c[0] == '\0' || cell->attrs.conceal)
|
||||||
|
|
@ -389,7 +389,7 @@ grid_render(struct terminal *term)
|
||||||
term->width, term->cell_height);
|
term->width, term->cell_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (term->is_blinking) {
|
if (term->blink.active) {
|
||||||
/* Check if there are still any visible blinking cells */
|
/* Check if there are still any visible blinking cells */
|
||||||
bool none_is_blinking = true;
|
bool none_is_blinking = true;
|
||||||
for (int r = 0; r < term->rows; r++) {
|
for (int r = 0; r < term->rows; r++) {
|
||||||
|
|
@ -406,11 +406,11 @@ grid_render(struct terminal *term)
|
||||||
if (none_is_blinking) {
|
if (none_is_blinking) {
|
||||||
LOG_DBG("disarming blink timer");
|
LOG_DBG("disarming blink timer");
|
||||||
|
|
||||||
term->is_blinking = false;
|
term->blink.active = false;
|
||||||
term->blink_mode = BLINK_ON;
|
term->blink.state = BLINK_ON;
|
||||||
|
|
||||||
if (timerfd_settime(
|
if (timerfd_settime(
|
||||||
term->blink_timer_fd, 0,
|
term->blink.fd, 0,
|
||||||
&(struct itimerspec){0}, NULL) < 0)
|
&(struct itimerspec){0}, NULL) < 0)
|
||||||
{
|
{
|
||||||
LOG_ERRNO("failed to disarm blink timer");
|
LOG_ERRNO("failed to disarm blink timer");
|
||||||
|
|
|
||||||
|
|
@ -248,9 +248,11 @@ struct terminal {
|
||||||
int fd;
|
int fd;
|
||||||
} flash;
|
} flash;
|
||||||
|
|
||||||
bool is_blinking;
|
struct {
|
||||||
enum { BLINK_ON, BLINK_OFF } blink_mode;
|
bool active;
|
||||||
int blink_timer_fd;
|
enum { BLINK_ON, BLINK_OFF } state;
|
||||||
|
int fd;
|
||||||
|
} blink;
|
||||||
|
|
||||||
struct vt vt;
|
struct vt vt;
|
||||||
struct kbd kbd;
|
struct kbd kbd;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue