Add mode 2031 support (automatic dark/light mode).

Co-Author: Nicholas Marriott <nicholas.marriott@gmail.com>
This commit is contained in:
Jonathan Slenders
2024-12-11 21:56:28 +00:00
parent ef68debc8d
commit e536f48d0e
11 changed files with 338 additions and 93 deletions

View File

@@ -56,11 +56,11 @@ static void server_client_set_title(struct client *);
static void server_client_set_path(struct client *);
static void server_client_reset_state(struct client *);
static void server_client_update_latest(struct client *);
static void server_client_dispatch(struct imsg *, void *);
static void server_client_dispatch_command(struct client *, struct imsg *);
static void server_client_dispatch_identify(struct client *, struct imsg *);
static void server_client_dispatch_shell(struct client *);
static void server_client_report_theme(struct client *, enum client_theme);
/* Compare client windows. */
static int
@@ -299,6 +299,7 @@ server_client_create(int fd)
c->tty.sx = 80;
c->tty.sy = 24;
c->theme = THEME_UNKNOWN;
status_init(c);
c->flags |= CLIENT_FOCUSED;
@@ -2383,6 +2384,16 @@ server_client_key_callback(struct cmdq_item *item, void *data)
event->key = key;
}
/* Handle theme reporting keys. */
if (key == KEYC_REPORT_LIGHT_THEME) {
server_client_report_theme(c, THEME_LIGHT);
goto out;
}
if (key == KEYC_REPORT_DARK_THEME) {
server_client_report_theme(c, THEME_DARK);
goto out;
}
/* Find affected pane. */
if (!KEYC_IS_MOUSE(key) || cmd_find_from_mouse(&fs, m, 0) != 0)
cmd_find_from_client(&fs, c, 0);
@@ -3909,3 +3920,21 @@ out:
if (!parse)
free(msg);
}
static void
server_client_report_theme(struct client *c, enum client_theme theme)
{
if (theme == THEME_LIGHT) {
c->theme = THEME_LIGHT;
notify_client("client-light-theme", c);
} else {
c->theme = THEME_DARK;
notify_client("client-dark-theme", c);
}
/*
* Request foregroundand background colour again. Don't forward 2031 to
* panes until a response is received.
*/
tty_puts(&c->tty, "\033]10;?\033\\\033]11;?\033\\");
}