From 1ed7206222524c07fda9acebe7bd3a1164b5f230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baltaz=C3=A1r=20Radics?= Date: Tue, 16 Aug 2022 12:49:44 +0200 Subject: [PATCH] key-binding: add binds for changing alpha --- box-drawing.c | 2 -- config.c | 4 ++++ doc/foot.ini.5.scd | 12 ++++++++++++ foot.ini | 4 ++++ input.c | 19 +++++++++++++++++++ key-binding.h | 4 ++++ terminal.c | 9 +++++++++ terminal.h | 1 + util.h | 1 + 9 files changed, 54 insertions(+), 2 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 421ff54d..4ae859be 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, diff --git a/config.c b/config.c index 04a9c9d4..64b0ff01 100644 --- a/config.c +++ b/config.c @@ -124,6 +124,10 @@ static const char *const binding_action_map[] = { [BIND_ACTION_FONT_SIZE_UP] = "font-increase", [BIND_ACTION_FONT_SIZE_DOWN] = "font-decrease", [BIND_ACTION_FONT_SIZE_RESET] = "font-reset", + [BIND_ACTION_ALPHA_UP] = "alpha-increase", + [BIND_ACTION_ALPHA_DOWN] = "alpha-decrease", + [BIND_ACTION_ALPHA_RESET] = "alpha-reset", + [BIND_ACTION_ALPHA_TOGGLE] = "alpha-toggle", [BIND_ACTION_SPAWN_TERMINAL] = "spawn-terminal", [BIND_ACTION_MINIMIZE] = "minimize", [BIND_ACTION_MAXIMIZE] = "maximize", diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 215809f8..d5e741fa 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -1307,6 +1307,18 @@ e.g. *search-start=none*. *font-reset* Resets the font size to the default. Default: _Control+0 Control+KP\_0_. +*alpha-increase* + Increases alpha by 5 percentage points. Default: _not_bound_. + +*alpha-decrease* + Decreases alpha by 5 percentage points. Default: _not_bound_. + +*alpha-reset* + Resets alpha to the default. Default: _not_bound_. + +*alpha-toggle* + Toggles alpha between 100% and the default. Default: _not_bound_. + *spawn-terminal* Spawns a new terminal. If the shell has been configured to emit the OSC 7 escape sequence, the new terminal will start in the diff --git a/foot.ini b/foot.ini index 563558db..caf78b4a 100644 --- a/foot.ini +++ b/foot.ini @@ -199,6 +199,10 @@ # font-increase=Control+plus Control+equal Control+KP_Add # font-decrease=Control+minus Control+KP_Subtract # font-reset=Control+0 Control+KP_0 +# alpha-increase=none +# alpha-decrease=none +# alpha-reset=none +# alpha-toggle=none # spawn-terminal=Control+Shift+n # minimize=none # maximize=none diff --git a/input.c b/input.c index b6c56fde..711fe627 100644 --- a/input.c +++ b/input.c @@ -198,6 +198,25 @@ execute_binding(struct seat *seat, struct terminal *term, term_font_size_reset(term); return true; + case BIND_ACTION_ALPHA_UP: + term_alpha_set(term, + clamp(term->colors.alpha + 0.05 * UINT16_MAX, 0, UINT16_MAX)); + return true; + + case BIND_ACTION_ALPHA_DOWN: + term_alpha_set(term, + clamp(term->colors.alpha - 0.05 * UINT16_MAX, 0, UINT16_MAX)); + return true; + + case BIND_ACTION_ALPHA_RESET: + term_alpha_set(term, term->conf->colors.alpha); + return true; + + case BIND_ACTION_ALPHA_TOGGLE: + term_alpha_set(term, term->colors.alpha == UINT16_MAX + ? term->conf->colors.alpha : UINT16_MAX); + return true; + case BIND_ACTION_SPAWN_TERMINAL: term_spawn_new(term); return true; diff --git a/key-binding.h b/key-binding.h index 5f0c1f1e..2bcbbd82 100644 --- a/key-binding.h +++ b/key-binding.h @@ -25,6 +25,10 @@ enum bind_action_normal { BIND_ACTION_FONT_SIZE_UP, BIND_ACTION_FONT_SIZE_DOWN, BIND_ACTION_FONT_SIZE_RESET, + BIND_ACTION_ALPHA_UP, + BIND_ACTION_ALPHA_DOWN, + BIND_ACTION_ALPHA_RESET, + BIND_ACTION_ALPHA_TOGGLE, BIND_ACTION_SPAWN_TERMINAL, BIND_ACTION_MINIMIZE, BIND_ACTION_MAXIMIZE, diff --git a/terminal.c b/terminal.c index d25516cb..d4c76c3d 100644 --- a/terminal.c +++ b/terminal.c @@ -2323,6 +2323,15 @@ term_font_size_reset(struct terminal *term) return load_fonts_from_conf(term); } +void +term_alpha_set(struct terminal *term, uint16_t alpha) +{ + term->colors.alpha = alpha; + term_damage_margins(term); + wayl_win_alpha_changed(term->window); + term_font_subpixel_changed(term); +} + bool term_fractional_scaling(const struct terminal *term) { diff --git a/terminal.h b/terminal.h index 4639fa69..5bdb4d4f 100644 --- a/terminal.h +++ b/terminal.h @@ -859,6 +859,7 @@ bool term_update_scale(struct terminal *term); bool term_font_size_increase(struct terminal *term); bool term_font_size_decrease(struct terminal *term); bool term_font_size_reset(struct terminal *term); +void term_alpha_set(struct terminal *term, uint16_t alpha); bool term_font_dpi_changed(struct terminal *term, float old_scale); void term_font_subpixel_changed(struct terminal *term); int term_font_baseline(const struct terminal *term); diff --git a/util.h b/util.h index 3746e269..a691cadd 100644 --- a/util.h +++ b/util.h @@ -8,6 +8,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 bool streq(const char *a, const char *b)