From b26523c26dc7cf0a24a1adb787aa1816deb40693 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 30 May 2019 20:54:03 +0000 Subject: Remove a leftover abort and some fixes from cppcheck. --- window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'window.c') diff --git a/window.c b/window.c index b08a5d35..1d83c247 100644 --- a/window.c +++ b/window.c @@ -1136,7 +1136,7 @@ window_pane_reset_mode(struct window_pane *wp) } else { log_debug("%s: next mode is %s", __func__, next->mode->name); wp->screen = next->screen; - if (next != NULL && next->mode->resize != NULL) + if (next->mode->resize != NULL) next->mode->resize(next, wp->sx, wp->sy); } wp->flags |= (PANE_REDRAW|PANE_CHANGED); -- cgit From 915097d312319a463fa4333c9bdf728b8dd6d39d Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 9 Jun 2019 06:50:24 +0000 Subject: Exiting alternate screen mode should restore cursor position and attributes even if already outside alternate screen mode. GitHub issue 1789. --- window.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index 1d83c247..781ff30c 100644 --- a/window.c +++ b/window.c @@ -804,6 +804,8 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) wp->pipe_event = NULL; wp->saved_grid = NULL; + wp->saved_cx = UINT_MAX; + wp->saved_cy = UINT_MAX; style_set(&wp->style, &grid_default_cell); @@ -962,10 +964,25 @@ window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc, struct screen *s = &wp->base; u_int sx, sy; - if (wp->saved_grid == NULL) - return; if (!options_get_number(wp->window->options, "alternate-screen")) return; + + /* + * Restore the cursor position and cell. This happens even if not + * currently in the alternate screen. + */ + if (cursor && wp->saved_cx != UINT_MAX && wp->saved_cy != UINT_MAX) { + s->cx = wp->saved_cx; + if (s->cx > screen_size_x(s) - 1) + s->cx = screen_size_x(s) - 1; + s->cy = wp->saved_cy; + if (s->cy > screen_size_y(s) - 1) + s->cy = screen_size_y(s) - 1; + memcpy(gc, &wp->saved_cell, sizeof *gc); + } + + if (wp->saved_grid == NULL) + return; sx = screen_size_x(s); sy = screen_size_y(s); @@ -976,17 +993,8 @@ window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc, if (sy > wp->saved_grid->sy) screen_resize(s, sx, wp->saved_grid->sy, 1); - /* Restore the grid, cursor position and cell. */ + /* Restore the saved grid. */ grid_duplicate_lines(s->grid, screen_hsize(s), wp->saved_grid, 0, sy); - if (cursor) - s->cx = wp->saved_cx; - if (s->cx > screen_size_x(s) - 1) - s->cx = screen_size_x(s) - 1; - if (cursor) - s->cy = wp->saved_cy; - if (s->cy > screen_size_y(s) - 1) - s->cy = screen_size_y(s) - 1; - memcpy(gc, &wp->saved_cell, sizeof *gc); /* * Turn history back on (so resize can use it) and then resize back to -- cgit From 3e72e98e3bdf3e814d6d20060247bb5f5dc859bb Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 13 Jun 2019 19:46:00 +0000 Subject: Add regular expression support for the format search, match and substitute modifiers. --- window.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index 781ff30c..e89cf96c 100644 --- a/window.c +++ b/window.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -1206,24 +1207,41 @@ window_pane_visible(struct window_pane *wp) } u_int -window_pane_search(struct window_pane *wp, const char *searchstr) +window_pane_search(struct window_pane *wp, const char *term, int regex, + int ignore) { struct screen *s = &wp->base; - char *newsearchstr, *line; + regex_t r; + char *new = NULL, *line; u_int i; + int flags = 0, found; - xasprintf(&newsearchstr, "*%s*", searchstr); + if (!regex) { + if (ignore) + flags |= FNM_CASEFOLD; + xasprintf(&new, "*%s*", term); + } else { + if (ignore) + flags |= REG_ICASE; + if (regcomp(&r, term, flags|REG_EXTENDED) != 0) + return (0); + } for (i = 0; i < screen_size_y(s); i++) { line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s)); - if (fnmatch(newsearchstr, line, 0) == 0) { - free(line); - break; - } + if (!regex) + found = (fnmatch(new, line, 0) == 0); + else + found = (regexec(&r, line, 0, NULL, 0) == 0); free(line); + if (found) + break; } + if (!regex) + free(new); + else + regfree(&r); - free(newsearchstr); if (i == screen_size_y(s)) return (0); return (i + 1); -- cgit From 9272fe36e2e36789342337d81914008826499941 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 18 Jun 2019 11:08:42 +0000 Subject: Add a cmdq_continue function rather than twiddling the flag directly. --- window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'window.c') diff --git a/window.c b/window.c index e89cf96c..e7941c70 100644 --- a/window.c +++ b/window.c @@ -1512,7 +1512,7 @@ window_pane_input_callback(struct client *c, int closed, void *data) c->stdin_callback = NULL; server_client_unref(c); - cdata->item->flags &= ~CMDQ_WAITING; + cmdq_continue(cdata->item); free(cdata); return; -- cgit From 5f92f92908b81b4ec66682adb84b9ffc8d83c2f7 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 20 Jun 2019 11:59:59 +0000 Subject: Add a per-pane option set. Pane options inherit from window options (so there should be no change to existing behaviour) and are set and shown with set-option -p and show-options -p. Change remain-on-exit and window-style/window-active-style to be pane options (some others will be changed later). This makes select-pane -P and -g unnecessary so no longer document them (they still work) and no longer document set-window-option and show-window-options in favour of set-option -w and show-options -w. --- window.c | 55 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 24 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index e7941c70..25784454 100644 --- a/window.c +++ b/window.c @@ -313,7 +313,7 @@ window_create(u_int sx, u_int sy) w = xcalloc(1, sizeof *w); w->name = NULL; - w->flags = WINDOW_STYLECHANGED; + w->flags = 0; TAILQ_INIT(&w->panes); w->active = NULL; @@ -450,31 +450,37 @@ window_set_active_pane(struct window *w, struct window_pane *wp, int notify) void window_redraw_active_switch(struct window *w, struct window_pane *wp) { - struct style *sy; + struct style *sy1, *sy2; + int c1, c2; if (wp == w->active) return; - /* - * If window-style and window-active-style are the same, we don't need - * to redraw panes when switching active panes. - */ - sy = options_get_style(w->options, "window-active-style"); - if (style_equal(sy, options_get_style(w->options, "window-style"))) - return; - - /* - * If the now active or inactive pane do not have a custom style or if - * the palette is different, they need to be redrawn. - */ - if (window_pane_get_palette(w->active, w->active->style.gc.fg) != -1 || - window_pane_get_palette(w->active, w->active->style.gc.bg) != -1 || - style_is_default(&w->active->style)) - w->active->flags |= PANE_REDRAW; - if (window_pane_get_palette(wp, wp->style.gc.fg) != -1 || - window_pane_get_palette(wp, wp->style.gc.bg) != -1 || - style_is_default(&wp->style)) - wp->flags |= PANE_REDRAW; + for (;;) { + /* + * If the active and inactive styles or palettes are different, + * need to redraw the panes. + */ + sy1 = &wp->cached_style; + sy2 = &wp->cached_active_style; + if (!style_equal(sy1, sy2)) + wp->flags |= PANE_REDRAW; + else { + c1 = window_pane_get_palette(wp, sy1->gc.fg); + c2 = window_pane_get_palette(wp, sy2->gc.fg); + if (c1 != c2) + wp->flags |= PANE_REDRAW; + else { + c1 = window_pane_get_palette(wp, sy1->gc.bg); + c2 = window_pane_get_palette(wp, sy2->gc.bg); + if (c1 != c2) + wp->flags |= PANE_REDRAW; + } + } + if (wp == w->active) + break; + wp = w->active; + } } struct window_pane * @@ -778,6 +784,8 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) wp = xcalloc(1, sizeof *wp); wp->window = w; + wp->options = options_create(w->options); + wp->flags = PANE_STYLECHANGED; wp->id = next_window_pane_id++; RB_INSERT(window_pane_tree, &all_window_panes, wp); @@ -808,8 +816,6 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) wp->saved_cx = UINT_MAX; wp->saved_cy = UINT_MAX; - style_set(&wp->style, &grid_default_cell); - screen_init(&wp->base, sx, sy, hlimit); wp->screen = &wp->base; @@ -852,6 +858,7 @@ window_pane_destroy(struct window_pane *wp) RB_REMOVE(window_pane_tree, &all_window_panes, wp); + options_free(wp->options); free((void *)wp->cwd); free(wp->shell); cmd_free_argv(wp->argc, wp->argv); -- cgit From fc1df91e034627f674ed905be6a1159da883545e Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 20 Jun 2019 13:40:22 +0000 Subject: allow-rename and alternate-screen can be pane options. --- window.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index 25784454..77ca2ce2 100644 --- a/window.c +++ b/window.c @@ -944,7 +944,7 @@ window_pane_alternate_on(struct window_pane *wp, struct grid_cell *gc, if (wp->saved_grid != NULL) return; - if (!options_get_number(wp->window->options, "alternate-screen")) + if (!options_get_number(wp->options, "alternate-screen")) return; sx = screen_size_x(s); sy = screen_size_y(s); @@ -972,7 +972,7 @@ window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc, struct screen *s = &wp->base; u_int sx, sy; - if (!options_get_number(wp->window->options, "alternate-screen")) + if (!options_get_number(wp->options, "alternate-screen")) return; /* -- cgit From bdab5950955539ea4ffab0816faf182607db4c2b Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 24 Jun 2019 08:20:02 +0000 Subject: Trim trailing spaces when matching. --- window.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'window.c') diff --git a/window.c b/window.c index 77ca2ce2..f900a1b2 100644 --- a/window.c +++ b/window.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -1222,6 +1223,7 @@ window_pane_search(struct window_pane *wp, const char *term, int regex, char *new = NULL, *line; u_int i; int flags = 0, found; + size_t n; if (!regex) { if (ignore) @@ -1236,6 +1238,12 @@ window_pane_search(struct window_pane *wp, const char *term, int regex, for (i = 0; i < screen_size_y(s); i++) { line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s)); + for (n = strlen(line); n > 0; n--) { + if (!isspace((u_char)line[n - 1])) + break; + line[n - 1] = '\0'; + } + log_debug("%s: %s", __func__, line); if (!regex) found = (fnmatch(new, line, 0) == 0); else -- cgit From d83f356218fc9144735667e39c9553bcf905d10b Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 26 Jun 2019 13:03:47 +0000 Subject: Add #define for the pane status line option position numbers. --- window.c | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index f900a1b2..c8b9b710 100644 --- a/window.c +++ b/window.c @@ -1288,25 +1288,35 @@ window_pane_choose_best(struct window_pane **list, u_int size) struct window_pane * window_pane_find_up(struct window_pane *wp) { + struct window *w; struct window_pane *next, *best, **list; u_int edge, left, right, end, size; int status, found; if (wp == NULL) return (NULL); - status = options_get_number(wp->window->options, "pane-border-status"); + w = wp->window; + status = options_get_number(w->options, "pane-border-status"); list = NULL; size = 0; edge = wp->yoff; - if (edge == (status == 1 ? 1 : 0)) - edge = wp->window->sy + 1 - (status == 2 ? 1 : 0); + if (status == PANE_STATUS_TOP) { + if (edge == 1) + edge = w->sy + 1; + } else if (status == PANE_STATUS_BOTTOM) { + if (edge == 0) + edge = w->sy; + } else { + if (edge == 0) + edge = w->sy + 1; + } left = wp->xoff; right = wp->xoff + wp->sx; - TAILQ_FOREACH(next, &wp->window->panes, entry) { + TAILQ_FOREACH(next, &w->panes, entry) { if (next == wp) continue; if (next->yoff + next->sy + 1 != edge) @@ -1335,25 +1345,35 @@ window_pane_find_up(struct window_pane *wp) struct window_pane * window_pane_find_down(struct window_pane *wp) { + struct window *w; struct window_pane *next, *best, **list; u_int edge, left, right, end, size; int status, found; if (wp == NULL) return (NULL); - status = options_get_number(wp->window->options, "pane-border-status"); + w = wp->window; + status = options_get_number(w->options, "pane-border-status"); list = NULL; size = 0; edge = wp->yoff + wp->sy + 1; - if (edge >= wp->window->sy - (status == 2 ? 1 : 0)) - edge = (status == 1 ? 1 : 0); + if (status == PANE_STATUS_TOP) { + if (edge >= w->sy) + edge = 1; + } else if (status == PANE_STATUS_BOTTOM) { + if (edge >= w->sy - 1) + edge = 0; + } else { + if (edge >= wp->sy) + edge = 0; + } left = wp->xoff; right = wp->xoff + wp->sx; - TAILQ_FOREACH(next, &wp->window->panes, entry) { + TAILQ_FOREACH(next, &w->panes, entry) { if (next == wp) continue; if (next->yoff != edge) @@ -1382,24 +1402,26 @@ window_pane_find_down(struct window_pane *wp) struct window_pane * window_pane_find_left(struct window_pane *wp) { + struct window *w; struct window_pane *next, *best, **list; u_int edge, top, bottom, end, size; int found; if (wp == NULL) return (NULL); + w = wp->window; list = NULL; size = 0; edge = wp->xoff; if (edge == 0) - edge = wp->window->sx + 1; + edge = w->sx + 1; top = wp->yoff; bottom = wp->yoff + wp->sy; - TAILQ_FOREACH(next, &wp->window->panes, entry) { + TAILQ_FOREACH(next, &w->panes, entry) { if (next == wp) continue; if (next->xoff + next->sx + 1 != edge) @@ -1428,24 +1450,26 @@ window_pane_find_left(struct window_pane *wp) struct window_pane * window_pane_find_right(struct window_pane *wp) { + struct window *w; struct window_pane *next, *best, **list; u_int edge, top, bottom, end, size; int found; if (wp == NULL) return (NULL); + w = wp->window; list = NULL; size = 0; edge = wp->xoff + wp->sx + 1; - if (edge >= wp->window->sx) + if (edge >= w->sx) edge = 0; top = wp->yoff; bottom = wp->yoff + wp->sy; - TAILQ_FOREACH(next, &wp->window->panes, entry) { + TAILQ_FOREACH(next, &w->panes, entry) { if (next == wp) continue; if (next->xoff != edge) -- cgit From c599ad63f8857bd74e85150e60339fd2efbb9650 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 26 Jun 2019 13:05:24 +0000 Subject: Log window and pane resizes. --- window.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'window.c') diff --git a/window.c b/window.c index c8b9b710..8108600d 100644 --- a/window.c +++ b/window.c @@ -412,6 +412,7 @@ window_set_name(struct window *w, const char *new_name) void window_resize(struct window *w, u_int sx, u_int sy) { + log_debug("%s: @%u resize %ux%u", __func__, w->id, sx, sy); w->sx = sx; w->sy = sy; } @@ -923,6 +924,7 @@ window_pane_resize(struct window_pane *wp, u_int sx, u_int sy) wp->sx = sx; wp->sy = sy; + log_debug("%s: %%%u resize %ux%u", __func__, wp->id, sx, sy); screen_resize(&wp->base, sx, sy, wp->saved_grid == NULL); wme = TAILQ_FIRST(&wp->modes); -- cgit From 3a6d90adadfcd4aa6b513df7f8ae5c4dcc05a6dc Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 26 Jun 2019 18:44:22 +0000 Subject: Fix a typo in window_pane_find_down (w not wp) and a missing PANE_STATUS_TOP. --- window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'window.c') diff --git a/window.c b/window.c index 8108600d..65097e1c 100644 --- a/window.c +++ b/window.c @@ -1368,7 +1368,7 @@ window_pane_find_down(struct window_pane *wp) if (edge >= w->sy - 1) edge = 0; } else { - if (edge >= wp->sy) + if (edge >= w->sy) edge = 0; } -- cgit From cf30e0f9357b7e42491645a87eeae06ffb8e8066 Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 30 Jun 2019 19:21:53 +0000 Subject: Do not double free window if pane fails to start. --- window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'window.c') diff --git a/window.c b/window.c index 65097e1c..06145221 100644 --- a/window.c +++ b/window.c @@ -338,7 +338,7 @@ window_create(u_int sx, u_int sy) return (w); } -void +static void window_destroy(struct window *w) { log_debug("window @%u destroyed (%d references)", w->id, w->references); -- cgit