summaryrefslogtreecommitdiffstats
path: root/window.c
diff options
context:
space:
mode:
authornicm <nicm>2021-08-11 20:49:55 +0000
committernicm <nicm>2021-08-11 20:49:55 +0000
commit7eea3d7ab850bb8fbeeccbb4b0fe84b9274965af (patch)
tree7967e985cb56c93a0fd80dfebe01079c4dbdd43e /window.c
parent01fd4b997e3a0a74ea57d6830cf97f98ea2c2a7c (diff)
Break the colour palette into a struct rather than just a single array
and use that to support the OSC palette-setting sequences in popups. Also add a pane-colours array option to specify the defaults. GitHub issue 2815.
Diffstat (limited to 'window.c')
-rw-r--r--window.c70
1 files changed, 11 insertions, 59 deletions
diff --git a/window.c b/window.c
index aa448e1f..f94acfcb 100644
--- a/window.c
+++ b/window.c
@@ -478,6 +478,14 @@ window_set_active_pane(struct window *w, struct window_pane *wp, int notify)
return (1);
}
+static int
+window_pane_get_palette(struct window_pane *wp, int c)
+{
+ if (wp == NULL)
+ return (-1);
+ return (colour_palette_get(&wp->palette, c));
+}
+
void
window_redraw_active_switch(struct window *w, struct window_pane *wp)
{
@@ -855,9 +863,6 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->fd = -1;
- wp->fg = 8;
- wp->bg = 8;
-
TAILQ_INIT(&wp->modes);
TAILQ_INIT (&wp->resize_queue);
@@ -867,6 +872,7 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->pipe_fd = -1;
+ colour_palette_init(&wp->palette);
screen_init(&wp->base, sx, sy, hlimit);
wp->screen = &wp->base;
@@ -916,7 +922,7 @@ window_pane_destroy(struct window_pane *wp)
free((void *)wp->cwd);
free(wp->shell);
cmd_free_argv(wp->argc, wp->argv);
- free(wp->palette);
+ colour_palette_free(&wp->palette);
free(wp);
}
@@ -968,7 +974,7 @@ window_pane_set_event(struct window_pane *wp)
wp->event = bufferevent_new(wp->fd, window_pane_read_callback,
NULL, window_pane_error_callback, wp);
- wp->ictx = input_init(wp, wp->event);
+ wp->ictx = input_init(wp, wp->event, &wp->palette);
bufferevent_enable(wp->event, EV_READ|EV_WRITE);
}
@@ -1000,60 +1006,6 @@ window_pane_resize(struct window_pane *wp, u_int sx, u_int sy)
wme->mode->resize(wme, sx, sy);
}
-void
-window_pane_set_palette(struct window_pane *wp, u_int n, int colour)
-{
- if (n > 0xff)
- return;
-
- if (wp->palette == NULL)
- wp->palette = xcalloc(0x100, sizeof *wp->palette);
-
- wp->palette[n] = colour;
- wp->flags |= PANE_REDRAW;
-}
-
-void
-window_pane_unset_palette(struct window_pane *wp, u_int n)
-{
- if (n > 0xff || wp->palette == NULL)
- return;
-
- wp->palette[n] = 0;
- wp->flags |= PANE_REDRAW;
-}
-
-void
-window_pane_reset_palette(struct window_pane *wp)
-{
- if (wp->palette == NULL)
- return;
-
- free(wp->palette);
- wp->palette = NULL;
- wp->flags |= PANE_REDRAW;
-}
-
-int
-window_pane_get_palette(struct window_pane *wp, int c)
-{
- int new;
-
- if (wp == NULL || wp->palette == NULL)
- return (-1);
-
- new = -1;
- if (c < 8)
- new = wp->palette[c];
- else if (c >= 90 && c <= 97)
- new = wp->palette[8 + c - 90];
- else if (c & COLOUR_FLAG_256)
- new = wp->palette[c & ~COLOUR_FLAG_256];
- if (new == 0)
- return (-1);
- return (new);
-}
-
int
window_pane_set_mode(struct window_pane *wp, struct window_pane *swp,
const struct window_mode *mode, struct cmd_find_state *fs,