diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2025-06-09 05:37:29 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2025-06-10 05:11:45 +0000 |
| commit | 33eefa7b45c2d20750f5788dfdcc1008cf33ca47 (patch) | |
| tree | cefa7a41f60050df3cfd9687cf2ea1cc412f3762 | |
| parent | quirks: remove subsurface unmap quirk for Sway (diff) | |
term+input: refactor: move theme switching into term_theme_* functions
| -rw-r--r-- | input.c | 51 | ||||
| -rw-r--r-- | terminal.c | 83 | ||||
| -rw-r--r-- | terminal.h | 4 |
3 files changed, 80 insertions, 58 deletions
@@ -486,60 +486,15 @@ execute_binding(struct seat *seat, struct terminal *term, return true; case BIND_ACTION_THEME_SWITCH_1: - if (term->colors.active_theme != COLOR_THEME1) { - term_theme_apply(term, &term->conf->colors); - term->colors.active_theme = COLOR_THEME1; - - wayl_win_alpha_changed(term->window); - term_font_subpixel_changed(term); - - if (term->report_theme_changes) - term_to_slave(term, "\033[?997;1n", 9); - - term_damage_view(term); - term_damage_margins(term); - render_refresh(term); - } + term_theme_switch_to_1(term); return true; case BIND_ACTION_THEME_SWITCH_2: - if (term->colors.active_theme != COLOR_THEME2) { - term_theme_apply(term, &term->conf->colors2); - term->colors.active_theme = COLOR_THEME2; - - wayl_win_alpha_changed(term->window); - term_font_subpixel_changed(term); - - if (term->report_theme_changes) - term_to_slave(term, "\033[?997;2n", 9); - - term_damage_view(term); - term_damage_margins(term); - render_refresh(term); - } + term_theme_switch_to_2(term); return true; case BIND_ACTION_THEME_TOGGLE: - 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); - } - - wayl_win_alpha_changed(term->window); - term_font_subpixel_changed(term); - - term_damage_view(term); - term_damage_margins(term); - render_refresh(term); + term_theme_toggle(term); return true; case BIND_ACTION_SELECT_BEGIN: @@ -2074,6 +2074,19 @@ erase_line(struct terminal *term, struct row *row) row->shell_integration.cmd_end = -1; } +static void +term_theme_apply(struct terminal *term, const struct color_theme *theme) +{ + term->colors.fg = theme->fg; + term->colors.bg = theme->bg; + term->colors.alpha = theme->alpha; + term->colors.cursor_fg = (theme->use_custom.cursor ? 1u << 31 : 0) | theme->cursor.text; + term->colors.cursor_bg = (theme->use_custom.cursor ? 1u << 31 : 0) | theme->cursor.cursor; + term->colors.selection_fg = theme->selection_fg; + term->colors.selection_bg = theme->selection_bg; + memcpy(term->colors.table, theme->table, sizeof(term->colors.table)); +} + void term_reset(struct terminal *term, bool hard) { @@ -4704,14 +4717,66 @@ term_send_size_notification(struct terminal *term) } void -term_theme_apply(struct terminal *term, const struct color_theme *theme) +term_theme_switch_to_1(struct terminal *term) { - term->colors.fg = theme->fg; - term->colors.bg = theme->bg; - term->colors.alpha = theme->alpha; - term->colors.cursor_fg = (theme->use_custom.cursor ? 1u << 31 : 0) | theme->cursor.text; - term->colors.cursor_bg = (theme->use_custom.cursor ? 1u << 31 : 0) | theme->cursor.cursor; - term->colors.selection_fg = theme->selection_fg; - term->colors.selection_bg = theme->selection_bg; - memcpy(term->colors.table, theme->table, sizeof(term->colors.table)); + if (term->colors.active_theme == COLOR_THEME1) + return; + + term_theme_apply(term, &term->conf->colors); + term->colors.active_theme = COLOR_THEME1; + + wayl_win_alpha_changed(term->window); + term_font_subpixel_changed(term); + + if (term->report_theme_changes) + term_to_slave(term, "\033[?997;1n", 9); + + term_damage_view(term); + term_damage_margins(term); + render_refresh(term); +} + +void +term_theme_switch_to_2(struct terminal *term) +{ + if (term->colors.active_theme == COLOR_THEME2) + return; + + term_theme_apply(term, &term->conf->colors2); + term->colors.active_theme = COLOR_THEME2; + + wayl_win_alpha_changed(term->window); + term_font_subpixel_changed(term); + + if (term->report_theme_changes) + term_to_slave(term, "\033[?997;2n", 9); + + term_damage_view(term); + term_damage_margins(term); + render_refresh(term); +} + +void +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); + } + + wayl_win_alpha_changed(term->window); + term_font_subpixel_changed(term); + + term_damage_view(term); + term_damage_margins(term); + render_refresh(term); } @@ -984,7 +984,9 @@ void term_enable_size_notifications(struct terminal *term); void term_disable_size_notifications(struct terminal *term); void term_send_size_notification(struct terminal *term); -void term_theme_apply(struct terminal *term, const struct color_theme *theme); +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); static inline void term_reset_grapheme_state(struct terminal *term) { |
