mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-20 05:33:47 -04:00
config: add initial-color-theme=1|2
This option selects which color theme to use by default. I.e. at startup, and after a reset. This is useful with combined theme files, where a single file defines e.g. both a dark and light version of the theme.
This commit is contained in:
parent
10e7f29149
commit
bc5b716668
7 changed files with 58 additions and 15 deletions
|
|
@ -74,6 +74,8 @@
|
||||||
* Support for private mode 2031 - [_Dark and Light Mode
|
* Support for private mode 2031 - [_Dark and Light Mode
|
||||||
Detection_](https://contour-terminal.org/vt-extensions/color-palette-update-notifications/)
|
Detection_](https://contour-terminal.org/vt-extensions/color-palette-update-notifications/)
|
||||||
([#2025][2025])
|
([#2025][2025])
|
||||||
|
* Added `initial-color-theme=1|2` config option. `1` uses colors from
|
||||||
|
the `[colors]` section, `2` uses `[colors2]`.
|
||||||
|
|
||||||
[2025]: https://codeberg.org/dnkl/foot/issues/2025
|
[2025]: https://codeberg.org/dnkl/foot/issues/2025
|
||||||
|
|
||||||
|
|
|
||||||
11
config.c
11
config.c
|
|
@ -1098,6 +1098,15 @@ parse_section_main(struct context *ctx)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (streq(key, "initial-color-theme")) {
|
||||||
|
_Static_assert(
|
||||||
|
sizeof(conf->initial_color_theme) == sizeof(int),
|
||||||
|
"enum is not 32-bit");
|
||||||
|
|
||||||
|
return value_to_enum(ctx, (const char*[]){"1", "2", NULL},
|
||||||
|
(int *)&conf->initial_color_theme);
|
||||||
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
LOG_CONTEXTUAL_ERR("not a valid option: %s", key);
|
LOG_CONTEXTUAL_ERR("not a valid option: %s", key);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -3402,7 +3411,7 @@ config_load(struct config *conf, const char *conf_path,
|
||||||
.url = false,
|
.url = false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
.initial_color_theme = COLOR_THEME1,
|
||||||
.cursor = {
|
.cursor = {
|
||||||
.style = CURSOR_BLOCK,
|
.style = CURSOR_BLOCK,
|
||||||
.unfocused_style = CURSOR_UNFOCUSED_HOLLOW,
|
.unfocused_style = CURSOR_UNFOCUSED_HOLLOW,
|
||||||
|
|
|
||||||
6
config.h
6
config.h
|
|
@ -190,6 +190,11 @@ struct color_theme {
|
||||||
} use_custom;
|
} use_custom;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum which_color_theme {
|
||||||
|
COLOR_THEME1,
|
||||||
|
COLOR_THEME2,
|
||||||
|
};
|
||||||
|
|
||||||
struct config {
|
struct config {
|
||||||
char *term;
|
char *term;
|
||||||
char *shell;
|
char *shell;
|
||||||
|
|
@ -305,6 +310,7 @@ struct config {
|
||||||
|
|
||||||
struct color_theme colors;
|
struct color_theme colors;
|
||||||
struct color_theme colors2;
|
struct color_theme colors2;
|
||||||
|
enum which_color_theme initial_color_theme;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
enum cursor_style style;
|
enum cursor_style style;
|
||||||
|
|
|
||||||
|
|
@ -349,6 +349,18 @@ empty string to be set, but it must be quoted: *KEY=""*)
|
||||||
|
|
||||||
Default: _yes_
|
Default: _yes_
|
||||||
|
|
||||||
|
*initial-color-theme*
|
||||||
|
Selects which color theme to use, *1*, or *2*.
|
||||||
|
|
||||||
|
*1* uses the colors defined in the *colors* section, while *2*
|
||||||
|
uses the colors from the *colors2* section.
|
||||||
|
|
||||||
|
Use the *color-theme-switch-1*, *color-theme-switch-2* and
|
||||||
|
*color-theme-toggle* key bindings to switch between the two themes
|
||||||
|
at runtime.
|
||||||
|
|
||||||
|
Default: _1_
|
||||||
|
|
||||||
*initial-window-size-pixels*
|
*initial-window-size-pixels*
|
||||||
Initial window width and height in _pixels_ (subject to output
|
Initial window width and height in _pixels_ (subject to output
|
||||||
scaling), in the form _WIDTHxHEIGHT_. The height _includes_ the
|
scaling), in the form _WIDTHxHEIGHT_. The height _includes_ the
|
||||||
|
|
|
||||||
1
foot.ini
1
foot.ini
|
|
@ -23,6 +23,7 @@
|
||||||
# box-drawings-uses-font-glyphs=no
|
# box-drawings-uses-font-glyphs=no
|
||||||
# dpi-aware=no
|
# dpi-aware=no
|
||||||
|
|
||||||
|
# initial-color-theme=1
|
||||||
# initial-window-size-pixels=700x500 # Or,
|
# initial-window-size-pixels=700x500 # Or,
|
||||||
# initial-window-size-chars=<COLSxROWS>
|
# initial-window-size-chars=<COLSxROWS>
|
||||||
# initial-window-mode=windowed
|
# initial-window-mode=windowed
|
||||||
|
|
|
||||||
39
terminal.c
39
terminal.c
|
|
@ -1262,6 +1262,12 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
||||||
|
|
||||||
const bool ten_bit_surfaces = conf->tweak.surface_bit_depth == SHM_10_BIT;
|
const bool ten_bit_surfaces = conf->tweak.surface_bit_depth == SHM_10_BIT;
|
||||||
|
|
||||||
|
const struct color_theme *theme = NULL;
|
||||||
|
switch (conf->initial_color_theme) {
|
||||||
|
case COLOR_THEME1: theme = &conf->colors; break;
|
||||||
|
case COLOR_THEME2: theme = &conf->colors2; break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize configure-based terminal attributes */
|
/* Initialize configure-based terminal attributes */
|
||||||
*term = (struct terminal) {
|
*term = (struct terminal) {
|
||||||
.fdm = fdm,
|
.fdm = fdm,
|
||||||
|
|
@ -1279,7 +1285,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
||||||
},
|
},
|
||||||
.font_dpi = 0.,
|
.font_dpi = 0.,
|
||||||
.font_dpi_before_unmap = -1.,
|
.font_dpi_before_unmap = -1.,
|
||||||
.font_subpixel = (conf->colors.alpha == 0xffff /* Can't do subpixel rendering on transparent background */
|
.font_subpixel = (theme->alpha == 0xffff /* Can't do subpixel rendering on transparent background */
|
||||||
? FCFT_SUBPIXEL_DEFAULT
|
? FCFT_SUBPIXEL_DEFAULT
|
||||||
: FCFT_SUBPIXEL_NONE),
|
: FCFT_SUBPIXEL_NONE),
|
||||||
.cursor_keys_mode = CURSOR_KEYS_NORMAL,
|
.cursor_keys_mode = CURSOR_KEYS_NORMAL,
|
||||||
|
|
@ -1295,15 +1301,15 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
||||||
.state = 0, /* STATE_GROUND */
|
.state = 0, /* STATE_GROUND */
|
||||||
},
|
},
|
||||||
.colors = {
|
.colors = {
|
||||||
.fg = conf->colors.fg,
|
.fg = theme->fg,
|
||||||
.bg = conf->colors.bg,
|
.bg = theme->bg,
|
||||||
.alpha = conf->colors.alpha,
|
.alpha = theme->alpha,
|
||||||
.cursor_fg = (conf->colors.use_custom.cursor ? 1u << 31 : 0) | conf->colors.cursor.text,
|
.cursor_fg = (theme->use_custom.cursor ? 1u << 31 : 0) | theme->cursor.text,
|
||||||
.cursor_bg = (conf->colors.use_custom.cursor ? 1u << 31 : 0) | conf->colors.cursor.cursor,
|
.cursor_bg = (theme->use_custom.cursor ? 1u << 31 : 0) | theme->cursor.cursor,
|
||||||
.selection_fg = conf->colors.selection_fg,
|
.selection_fg = theme->selection_fg,
|
||||||
.selection_bg = conf->colors.selection_bg,
|
.selection_bg = theme->selection_bg,
|
||||||
.use_custom_selection = conf->colors.use_custom.selection,
|
.use_custom_selection = theme->use_custom.selection,
|
||||||
.active_theme = COLOR_THEME1,
|
.active_theme = conf->initial_color_theme,
|
||||||
},
|
},
|
||||||
.color_stack = {
|
.color_stack = {
|
||||||
.stack = NULL,
|
.stack = NULL,
|
||||||
|
|
@ -1434,7 +1440,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
||||||
xassert(tll_length(term->wl->monitors) > 0);
|
xassert(tll_length(term->wl->monitors) > 0);
|
||||||
term->scale = tll_front(term->wl->monitors).scale;
|
term->scale = tll_front(term->wl->monitors).scale;
|
||||||
|
|
||||||
memcpy(term->colors.table, term->conf->colors.table, sizeof(term->colors.table));
|
memcpy(term->colors.table, theme->table, sizeof(term->colors.table));
|
||||||
|
|
||||||
/* Initialize the Wayland window backend */
|
/* Initialize the Wayland window backend */
|
||||||
if ((term->window = wayl_win_init(term, token)) == NULL)
|
if ((term->window = wayl_win_init(term, token)) == NULL)
|
||||||
|
|
@ -2148,11 +2154,18 @@ term_reset(struct terminal *term, bool hard)
|
||||||
if (!hard)
|
if (!hard)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const struct color_theme *theme = NULL;
|
||||||
|
|
||||||
|
switch (term->conf->initial_color_theme) {
|
||||||
|
case COLOR_THEME1: theme = &term->conf->colors; break;
|
||||||
|
case COLOR_THEME2: theme = &term->conf->colors2; break;
|
||||||
|
}
|
||||||
|
|
||||||
term->flash.active = false;
|
term->flash.active = false;
|
||||||
term->blink.state = BLINK_ON;
|
term->blink.state = BLINK_ON;
|
||||||
fdm_del(term->fdm, term->blink.fd); term->blink.fd = -1;
|
fdm_del(term->fdm, term->blink.fd); term->blink.fd = -1;
|
||||||
term_theme_apply(term, &term->conf->colors);
|
term_theme_apply(term, theme);
|
||||||
term->colors.active_theme = COLOR_THEME1;
|
term->colors.active_theme = term->conf->initial_color_theme;
|
||||||
free(term->color_stack.stack);
|
free(term->color_stack.stack);
|
||||||
term->color_stack.stack = NULL;
|
term->color_stack.stack = NULL;
|
||||||
term->color_stack.size = 0;
|
term->color_stack.size = 0;
|
||||||
|
|
|
||||||
|
|
@ -405,7 +405,7 @@ struct colors {
|
||||||
uint32_t selection_fg;
|
uint32_t selection_fg;
|
||||||
uint32_t selection_bg;
|
uint32_t selection_bg;
|
||||||
bool use_custom_selection;
|
bool use_custom_selection;
|
||||||
enum { COLOR_THEME1, COLOR_THEME2 } active_theme;
|
enum which_color_theme active_theme;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct terminal {
|
struct terminal {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue