key-binding: add binds for changing alpha

This commit is contained in:
Baltazár Radics 2022-08-16 12:49:44 +02:00
parent d7b48d3924
commit 1ed7206222
9 changed files with 54 additions and 2 deletions

View file

@ -15,8 +15,6 @@
#include "util.h"
#include "xmalloc.h"
#define clamp(x, lower, upper) (min(upper, max(x, lower)))
enum thickness {
LIGHT,
HEAVY,

View file

@ -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",

View file

@ -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

View file

@ -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

19
input.c
View file

@ -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;

View file

@ -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,

View file

@ -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)
{

View file

@ -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);

1
util.h
View file

@ -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)