aboutsummaryrefslogtreecommitdiff
path: root/csi.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2025-04-20 10:48:37 +0000
committerDaniel Eklöf <daniel@ekloef.se>2025-04-26 12:23:34 +0000
commit10e7f291498a6600cfecc3cde604ea51de5f0f5a (patch)
treec700cabf0239306ff5d8a6e3fe8c4e1b4d385684 /csi.c
parentkey-bindings: add bindings to switch between color themes (diff)
csi: implement private mode 2031 (dark/light mode detection)
* Recognize 'CSI ? 996 n', and respond with - 'CSI ? 997 ; 1 n' if the primary theme is active - 'CSI ? 997 ; 2 n' if the alternative theme is actice * Implement private mode 2031, where changing the color theme (currently only possible via key bindings) causes the terminal to send the same CSI sequences as above. In this context, foot's primary theme is considered dark, and the alternative theme light (since the default theme is dark). Closes #2025
Diffstat (limited to 'csi.c')
-rw-r--r--csi.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/csi.c b/csi.c
index b66fda21..e8b2c492 100644
--- a/csi.c
+++ b/csi.c
@@ -563,6 +563,10 @@ decset_decrst(struct terminal *term, unsigned param, bool enable)
#endif
break;
+ case 2031:
+ term->report_theme_changes = enable;
+ break;
+
case 2048:
if (enable)
term_enable_size_notifications(term);
@@ -657,6 +661,7 @@ decrqm(const struct terminal *term, unsigned param)
case 2027: return term->conf->tweak.grapheme_width_method != GRAPHEME_WIDTH_DOUBLE
? DECRPM_PERMANENTLY_RESET
: decrpm(term->grapheme_shaping);
+ case 2031: return decrpm(term->report_theme_changes);
case 2048: return decrpm(term->size_notifications);
case 8452: return decrpm(term->sixel.cursor_right_of_graphics);
case 737769: return decrpm(term_ime_is_enabled(term));
@@ -702,6 +707,7 @@ xtsave(struct terminal *term, unsigned param)
case 2004: term->xtsave.bracketed_paste = term->bracketed_paste; break;
case 2026: term->xtsave.app_sync_updates = term->render.app_sync_updates.enabled; break;
case 2027: term->xtsave.grapheme_shaping = term->grapheme_shaping; break;
+ case 2031: term->xtsave.report_theme_changes = term->report_theme_changes; break;
case 2048: term->xtsave.size_notifications = term->size_notifications; break;
case 8452: term->xtsave.sixel_cursor_right_of_graphics = term->sixel.cursor_right_of_graphics; break;
case 737769: term->xtsave.ime = term_ime_is_enabled(term); break;
@@ -746,6 +752,7 @@ xtrestore(struct terminal *term, unsigned param)
case 2004: enable = term->xtsave.bracketed_paste; break;
case 2026: enable = term->xtsave.app_sync_updates; break;
case 2027: enable = term->xtsave.grapheme_shaping; break;
+ case 2031: enable = term->xtsave.report_theme_changes; break;
case 2048: enable = term->xtsave.size_notifications; break;
case 8452: enable = term->xtsave.sixel_cursor_right_of_graphics; break;
case 737769: enable = term->xtsave.ime; break;
@@ -1539,6 +1546,32 @@ csi_dispatch(struct terminal *term, uint8_t final)
break;
}
+ case 'n': {
+ const int param = vt_param_get(term, 0, 0);
+
+ 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);
+ break;
+ }
+ }
+ break;
+ }
+
case 'p': {
/*
* Request status of ECMA-48/"ANSI" private mode (DECRQM