mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
Extract function for reporting color theme mode
This commit is contained in:
parent
6ab7190d74
commit
7e2ea901d6
3 changed files with 24 additions and 23 deletions
16
csi.c
16
csi.c
|
|
@ -1566,21 +1566,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
|||
|
||||
switch (param) {
|
||||
case 996: { /* Query current theme mode (see private mode 2031) */
|
||||
/*
|
||||
* 1 - dark mode
|
||||
* 2 - light mode
|
||||
*
|
||||
* In foot, the themes aren't necessarily light/dark,
|
||||
* but by convention, the primary theme is dark, and
|
||||
* the alternative theme is light.
|
||||
*/
|
||||
char reply[16] = {0};
|
||||
int chars = snprintf(
|
||||
reply, sizeof(reply),
|
||||
"\033[?997;%dn",
|
||||
term->colors.active_theme == COLOR_THEME1 ? 1 : 2);
|
||||
|
||||
term_to_slave(term, reply, chars);
|
||||
term_send_color_theme_mode(term);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
terminal.c
30
terminal.c
|
|
@ -4734,7 +4734,7 @@ term_theme_switch_to_1(struct terminal *term)
|
|||
term_font_subpixel_changed(term);
|
||||
|
||||
if (term->report_theme_changes)
|
||||
term_to_slave(term, "\033[?997;1n", 9);
|
||||
term_send_color_theme_mode(term);
|
||||
|
||||
term_damage_view(term);
|
||||
term_damage_margins(term);
|
||||
|
|
@ -4754,7 +4754,7 @@ term_theme_switch_to_2(struct terminal *term)
|
|||
term_font_subpixel_changed(term);
|
||||
|
||||
if (term->report_theme_changes)
|
||||
term_to_slave(term, "\033[?997;2n", 9);
|
||||
term_send_color_theme_mode(term);
|
||||
|
||||
term_damage_view(term);
|
||||
term_damage_margins(term);
|
||||
|
|
@ -4767,16 +4767,12 @@ term_theme_toggle(struct terminal *term)
|
|||
if (term->colors.active_theme == COLOR_THEME1) {
|
||||
term_theme_apply(term, &term->conf->colors2);
|
||||
term->colors.active_theme = COLOR_THEME2;
|
||||
|
||||
if (term->report_theme_changes)
|
||||
term_to_slave(term, "\033[?997;2n", 9);
|
||||
} else {
|
||||
term_theme_apply(term, &term->conf->colors);
|
||||
term->colors.active_theme = COLOR_THEME1;
|
||||
|
||||
if (term->report_theme_changes)
|
||||
term_to_slave(term, "\033[?997;1n", 9);
|
||||
}
|
||||
if (term->report_theme_changes)
|
||||
term_send_color_theme_mode(term);
|
||||
|
||||
wayl_win_alpha_changed(term->window);
|
||||
term_font_subpixel_changed(term);
|
||||
|
|
@ -4785,3 +4781,21 @@ term_theme_toggle(struct terminal *term)
|
|||
term_damage_margins(term);
|
||||
render_refresh(term);
|
||||
}
|
||||
|
||||
/*
|
||||
* 1 - dark mode
|
||||
* 2 - light mode
|
||||
*
|
||||
* In foot, the themes aren't necessarily light/dark,
|
||||
* but by convention, the primary theme is dark, and
|
||||
* the alternative theme is light.
|
||||
*/
|
||||
void term_send_color_theme_mode(struct terminal* term)
|
||||
{
|
||||
static const char reply[2][9] = {
|
||||
"\033[?997;2n",
|
||||
"\033[?997;1n",
|
||||
};
|
||||
const bool is_dark = term->colors.active_theme == COLOR_THEME1;
|
||||
term_to_slave(term, reply[is_dark], 9);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -997,6 +997,7 @@ void term_send_size_notification(struct terminal *term);
|
|||
void term_theme_switch_to_1(struct terminal *term);
|
||||
void term_theme_switch_to_2(struct terminal *term);
|
||||
void term_theme_toggle(struct terminal *term);
|
||||
void term_send_color_theme_mode(struct terminal* term);
|
||||
|
||||
static inline void term_reset_grapheme_state(struct terminal *term)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue