From 27f513920f90d1181883aaf5fd3fd546cdbf64df Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Thu, 2 Jun 2022 09:09:14 +0530 Subject: [PATCH] Refresh terminal after updating alpha --- box-drawing.c | 16 +++++++--------- config.c | 2 +- terminal.c | 9 +++++++-- util.h | 1 + 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 3962e341..8c12c688 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -15,8 +15,6 @@ #include "util.h" #include "xmalloc.h" -#define clamp(x, lower, upper) (min(upper, max(x, lower))) - enum thickness { LIGHT, HEAVY, @@ -1281,17 +1279,17 @@ draw_box_drawings_light_arc(struct buf *buf, char32_t wc) * The general idea here is to connect the two incoming lines using a * circle, which is extended to the box-edges with vertical/horizontal * lines. - * + * * The radius of the quartercircle should be as big as possible, with some * restrictions: The radius should be the same for all of ╭ ╮ ╯ ╰ at a * given box-size (which won't be the case if we choose the biggest * possible radius for a given box, consider the following:) - * - * + * + * * ▕ ███ ▏ - * ▕a │ d▔▔ - * ▕ │ x - * ▕ │ + * ▕a │ d▔▔ + * ▕ │ x + * ▕ │ * ▕ │ ██ * ▕ ╰────██ * ▕ ██ @@ -1302,7 +1300,7 @@ draw_box_drawings_light_arc(struct buf *buf, char32_t wc) * for ╰ it would be possible to center the circle on the upper right * corner of d, but we have set it on x instead because ╯ can only use a * 2px inner radius: - * + * * ▕ ███ ▏ * ▔▔a │ d▏ * x │ ▏ diff --git a/config.c b/config.c index e8fd9325..26f3b988 100644 --- a/config.c +++ b/config.c @@ -1190,7 +1190,7 @@ parse_section_colors(struct context *ctx) return false; } - conf->colors.alpha = alpha * 65535.; + conf->colors.alpha = alpha * UINT16_MAX; return true; } diff --git a/terminal.c b/terminal.c index 665ff118..f35d38d3 100644 --- a/terminal.c +++ b/terminal.c @@ -2005,17 +2005,22 @@ term_font_size_reset(struct terminal *term) return load_fonts_from_conf(term); } +#define ALPHA_STEP (0.05 * UINT16_MAX) bool term_alpha_increase(struct terminal *term) { - term->colors.alpha += 0.05; + term->colors.alpha = clamp(term->colors.alpha + ALPHA_STEP, 0, UINT16_MAX); + term->render.last_buf = NULL; + render_refresh(term); return true; } bool term_alpha_decrease(struct terminal *term) { - term->colors.alpha -= 0.05; + term->colors.alpha = clamp(term->colors.alpha - ALPHA_STEP, 0, UINT16_MAX); + term->render.last_buf = NULL; + render_refresh(term); return true; } diff --git a/util.h b/util.h index 683dbd4a..e98b013e 100644 --- a/util.h +++ b/util.h @@ -6,6 +6,7 @@ #define ALEN(v) (sizeof(v) / sizeof((v)[0])) #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) +#define clamp(x, lower, upper) (min(upper, max(x, lower))) static inline const char * thrd_err_as_string(int thrd_err)