summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/input.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2024-06-24 08:30:51 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2024-06-24 08:30:51 +0000
commit132f85ccf7097bf15f5ce65ae98945cfac3bddbd (patch)
treeeed845ac5b9d5a83f60fda2bb105907a97b47cd5 /usr.bin/tmux/input.c
parent2a7a8adb5207815aa587adf240e8ea8a74d5aca3 (diff)
Add a way (refresh-client -r) for control mode clients to provide OSC 10
and 11 responses to tmux so they can set the default foreground and background colours, from George Nachman in GitHub issue 4014.
Diffstat (limited to 'usr.bin/tmux/input.c')
-rw-r--r--usr.bin/tmux/input.c66
1 files changed, 55 insertions, 11 deletions
diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c
index 6d67917f47d..7ee811379d8 100644
--- a/usr.bin/tmux/input.c
+++ b/usr.bin/tmux/input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: input.c,v 1.224 2024/04/10 07:36:25 nicm Exp $ */
+/* $OpenBSD: input.c,v 1.225 2024/06/24 08:30:50 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2652,6 +2652,44 @@ input_get_bg_client(struct window_pane *wp)
return (-1);
}
+/*
+ * If any control mode client exists that has provided a bg color, return it.
+ * Otherwise, return -1.
+ */
+static int
+input_get_bg_control_client(struct window_pane *wp)
+{
+ struct client *c;
+
+ if (wp->control_bg == -1)
+ return (-1);
+
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->flags & CLIENT_CONTROL)
+ return (wp->control_bg);
+ }
+ return (-1);
+}
+
+/*
+ * If any control mode client exists that has provided a fg color, return it.
+ * Otherwise, return -1.
+ */
+static int
+input_get_fg_control_client(struct window_pane *wp)
+{
+ struct client *c;
+
+ if (wp->control_fg == -1)
+ return (-1);
+
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->flags & CLIENT_CONTROL)
+ return (wp->control_fg);
+ }
+ return (-1);
+}
+
/* Handle the OSC 10 sequence for setting and querying foreground colour. */
static void
input_osc_10(struct input_ctx *ictx, const char *p)
@@ -2663,11 +2701,14 @@ input_osc_10(struct input_ctx *ictx, const char *p)
if (strcmp(p, "?") == 0) {
if (wp == NULL)
return;
- tty_default_colours(&defaults, wp);
- if (COLOUR_DEFAULT(defaults.fg))
- c = input_get_fg_client(wp);
- else
- c = defaults.fg;
+ c = input_get_fg_control_client(wp);
+ if (c == -1) {
+ tty_default_colours(&defaults, wp);
+ if (COLOUR_DEFAULT(defaults.fg))
+ c = input_get_fg_client(wp);
+ else
+ c = defaults.fg;
+ }
input_osc_colour_reply(ictx, 10, c);
return;
}
@@ -2711,11 +2752,14 @@ input_osc_11(struct input_ctx *ictx, const char *p)
if (strcmp(p, "?") == 0) {
if (wp == NULL)
return;
- tty_default_colours(&defaults, wp);
- if (COLOUR_DEFAULT(defaults.bg))
- c = input_get_bg_client(wp);
- else
- c = defaults.bg;
+ c = input_get_bg_control_client(wp);
+ if (c == -1) {
+ tty_default_colours(&defaults, wp);
+ if (COLOUR_DEFAULT(defaults.bg))
+ c = input_get_bg_client(wp);
+ else
+ c = defaults.bg;
+ }
input_osc_colour_reply(ictx, 11, c);
return;
}