diff options
Diffstat (limited to 'window.c')
-rw-r--r-- | window.c | 174 |
1 files changed, 30 insertions, 144 deletions
@@ -423,8 +423,8 @@ window_resize(struct window *w, u_int sx, u_int sy, int xpixel, int ypixel) ypixel = DEFAULT_YPIXEL; log_debug("%s: @%u resize %ux%u (%ux%u)", __func__, w->id, sx, sy, - xpixel == -1 ? w->xpixel : xpixel, - ypixel == -1 ? w->ypixel : ypixel); + xpixel == -1 ? w->xpixel : (u_int)xpixel, + ypixel == -1 ? w->ypixel : (u_int)ypixel); w->sx = sx; w->sy = sy; if (xpixel != -1) @@ -495,8 +495,8 @@ 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 *sy1, *sy2; - int c1, c2; + struct grid_cell *gc1, *gc2; + int c1, c2; if (wp == w->active) return; @@ -506,18 +506,18 @@ window_redraw_active_switch(struct window *w, struct window_pane *wp) * 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)) + gc1 = &wp->cached_gc; + gc2 = &wp->cached_active_gc; + if (!grid_cells_look_equal(gc1, gc2)) wp->flags |= PANE_REDRAW; else { - c1 = window_pane_get_palette(wp, sy1->gc.fg); - c2 = window_pane_get_palette(wp, sy2->gc.fg); + c1 = window_pane_get_palette(wp, gc1->fg); + c2 = window_pane_get_palette(wp, gc2->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); + c1 = window_pane_get_palette(wp, gc1->bg); + c2 = window_pane_get_palette(wp, gc2->bg); if (c1 != c2) wp->flags |= PANE_REDRAW; } @@ -872,6 +872,9 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) wp->fd = -1; wp->event = NULL; + wp->fg = 8; + wp->bg = 8; + TAILQ_INIT(&wp->modes); wp->layout_cell = NULL; @@ -886,10 +889,6 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) wp->pipe_off = 0; wp->pipe_event = NULL; - wp->saved_grid = NULL; - wp->saved_cx = UINT_MAX; - wp->saved_cy = UINT_MAX; - screen_init(&wp->base, sx, sy, hlimit); wp->screen = &wp->base; @@ -898,8 +897,6 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) if (gethostname(host, sizeof host) == 0) screen_set_title(&wp->base, host); - input_init(wp); - return (wp); } @@ -916,14 +913,12 @@ window_pane_destroy(struct window_pane *wp) bufferevent_free(wp->event); close(wp->fd); } - - input_free(wp); + if (wp->ictx != NULL) + input_free(wp->ictx); screen_free(&wp->status_screen); screen_free(&wp->base); - if (wp->saved_grid != NULL) - grid_destroy(wp->saved_grid); if (wp->pipe_fd != -1) { bufferevent_free(wp->pipe_event); @@ -959,7 +954,7 @@ window_pane_read_callback(__unused struct bufferevent *bufev, void *data) } log_debug("%%%u has %zu bytes", wp->id, size); - input_parse(wp); + input_parse_pane(wp); wp->pipe_off = EVBUFFER_LENGTH(evb); } @@ -984,6 +979,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); bufferevent_setwatermark(wp->event, EV_READ, 0, READ_SIZE); bufferevent_enable(wp->event, EV_READ|EV_WRITE); @@ -1000,7 +996,7 @@ window_pane_resize(struct window_pane *wp, u_int sx, u_int sy) 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); + screen_resize(&wp->base, sx, sy, wp->base.saved_grid == NULL); wme = TAILQ_FIRST(&wp->modes); if (wme != NULL && wme->mode->resize != NULL) @@ -1009,93 +1005,6 @@ window_pane_resize(struct window_pane *wp, u_int sx, u_int sy) wp->flags |= (PANE_RESIZE|PANE_RESIZED); } -/* - * Enter alternative screen mode. A copy of the visible screen is saved and the - * history is not updated - */ -void -window_pane_alternate_on(struct window_pane *wp, struct grid_cell *gc, - int cursor) -{ - struct screen *s = &wp->base; - u_int sx, sy; - - if (wp->saved_grid != NULL) - return; - if (!options_get_number(wp->options, "alternate-screen")) - return; - sx = screen_size_x(s); - sy = screen_size_y(s); - - wp->saved_grid = grid_create(sx, sy, 0); - grid_duplicate_lines(wp->saved_grid, 0, s->grid, screen_hsize(s), sy); - if (cursor) { - wp->saved_cx = s->cx; - wp->saved_cy = s->cy; - } - memcpy(&wp->saved_cell, gc, sizeof wp->saved_cell); - - grid_view_clear(s->grid, 0, 0, sx, sy, 8); - - wp->base.grid->flags &= ~GRID_HISTORY; - - wp->flags |= PANE_REDRAW; -} - -/* Exit alternate screen mode and restore the copied grid. */ -void -window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc, - int cursor) -{ - struct screen *s = &wp->base; - u_int sx, sy; - - if (!options_get_number(wp->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); - - /* - * If the current size is bigger, temporarily resize to the old size - * before copying back. - */ - if (sy > wp->saved_grid->sy) - screen_resize(s, sx, wp->saved_grid->sy, 1); - - /* Restore the saved grid. */ - grid_duplicate_lines(s->grid, screen_hsize(s), wp->saved_grid, 0, sy); - - /* - * Turn history back on (so resize can use it) and then resize back to - * the current size. - */ - wp->base.grid->flags |= GRID_HISTORY; - if (sy > wp->saved_grid->sy || sx != wp->saved_grid->sx) - screen_resize(s, sx, sy, 1); - - grid_destroy(wp->saved_grid); - wp->saved_grid = NULL; - - wp->flags |= PANE_REDRAW; -} - void window_pane_set_palette(struct window_pane *wp, u_int n, int colour) { @@ -1150,40 +1059,16 @@ window_pane_get_palette(struct window_pane *wp, int c) return (new); } -static void -window_pane_mode_timer(__unused int fd, __unused short events, void *arg) -{ - struct window_pane *wp = arg; - struct timeval tv = { .tv_sec = 10 }; - int n = 0; - - evtimer_del(&wp->modetimer); - evtimer_add(&wp->modetimer, &tv); - - log_debug("%%%u in mode: last=%ld", wp->id, (long)wp->modelast); - - if (wp->modelast < time(NULL) - WINDOW_MODE_TIMEOUT) { - if (ioctl(wp->fd, FIONREAD, &n) == -1 || n > 0) - window_pane_reset_mode_all(wp); - } -} - int -window_pane_set_mode(struct window_pane *wp, const struct window_mode *mode, - struct cmd_find_state *fs, struct args *args) +window_pane_set_mode(struct window_pane *wp, struct window_pane *swp, + const struct window_mode *mode, struct cmd_find_state *fs, + struct args *args) { - struct timeval tv = { .tv_sec = 10 }; struct window_mode_entry *wme; if (!TAILQ_EMPTY(&wp->modes) && TAILQ_FIRST(&wp->modes)->mode == mode) return (1); - wp->modelast = time(NULL); - if (TAILQ_EMPTY(&wp->modes)) { - evtimer_set(&wp->modetimer, window_pane_mode_timer, wp); - evtimer_add(&wp->modetimer, &tv); - } - TAILQ_FOREACH(wme, &wp->modes, entry) { if (wme->mode == mode) break; @@ -1194,6 +1079,7 @@ window_pane_set_mode(struct window_pane *wp, const struct window_mode *mode, } else { wme = xcalloc(1, sizeof *wme); wme->wp = wp; + wme->swp = swp; wme->mode = mode; wme->prefix = 1; TAILQ_INSERT_HEAD(&wp->modes, wme, entry); @@ -1203,6 +1089,7 @@ window_pane_set_mode(struct window_pane *wp, const struct window_mode *mode, wp->screen = wme->screen; wp->flags |= (PANE_REDRAW|PANE_CHANGED); + server_redraw_window_borders(wp->window); server_status_window(wp->window); notify_pane("pane-mode-changed", wp); @@ -1225,7 +1112,6 @@ window_pane_reset_mode(struct window_pane *wp) next = TAILQ_FIRST(&wp->modes); if (next == NULL) { log_debug("%s: no next mode", __func__); - evtimer_del(&wp->modetimer); wp->screen = &wp->base; } else { log_debug("%s: next mode is %s", __func__, next->mode->name); @@ -1235,6 +1121,7 @@ window_pane_reset_mode(struct window_pane *wp) } wp->flags |= (PANE_REDRAW|PANE_CHANGED); + server_redraw_window_borders(wp->window); server_status_window(wp->window); notify_pane("pane-mode-changed", wp); } @@ -1258,8 +1145,7 @@ window_pane_key(struct window_pane *wp, struct client *c, struct session *s, wme = TAILQ_FIRST(&wp->modes); if (wme != NULL) { - wp->modelast = time(NULL); - if (wme->mode->key != NULL) + if (wme->mode->key != NULL && c != NULL) wme->mode->key(wme, c, s, wl, (key & ~KEYC_XTERM), m); return (0); } @@ -1267,7 +1153,7 @@ window_pane_key(struct window_pane *wp, struct client *c, struct session *s, if (wp->fd == -1 || wp->flags & PANE_INPUTOFF) return (0); - if (input_key(wp, key, m) != 0) + if (input_key_pane(wp, key, m) != 0) return (-1); if (KEYC_IS_MOUSE(key)) @@ -1279,7 +1165,7 @@ window_pane_key(struct window_pane *wp, struct client *c, struct session *s, wp2->fd != -1 && (~wp2->flags & PANE_INPUTOFF) && window_pane_visible(wp2)) - input_key(wp2, key, NULL); + input_key_pane(wp2, key, NULL); } } return (0); @@ -1324,7 +1210,7 @@ window_pane_search(struct window_pane *wp, const char *term, int regex, } log_debug("%s: %s", __func__, line); if (!regex) - found = (fnmatch(new, line, 0) == 0); + found = (fnmatch(new, line, flags) == 0); else found = (regexec(&r, line, 0, NULL, 0) == 0); free(line); @@ -1645,7 +1531,7 @@ int window_pane_start_input(struct window_pane *wp, struct cmdq_item *item, char **cause) { - struct client *c = item->client; + struct client *c = cmdq_get_client(item); struct window_pane_input_data *cdata; if (~wp->flags & PANE_EMPTY) { |