From: nicm Date: Sat, 18 Aug 2018 16:14:03 +0000 (+0000) Subject: Some tidying and helper functions. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=84cde37cc2922823b0a91e9b76ddb024f71c89ae;p=openbsd Some tidying and helper functions. --- diff --git a/usr.bin/tmux/cmd-resize-pane.c b/usr.bin/tmux/cmd-resize-pane.c index 927b5bf444f..76d64c471c6 100644 --- a/usr.bin/tmux/cmd-resize-pane.c +++ b/usr.bin/tmux/cmd-resize-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-resize-pane.c,v 1.34 2018/06/24 21:24:09 nicm Exp $ */ +/* $OpenBSD: cmd-resize-pane.c,v 1.35 2018/08/18 16:14:03 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -91,9 +91,8 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item) } } - if (args_has(self->args, 'x')) { - x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX, - &cause); + if (args_has(args, 'x')) { + x = args_strtonum(args, 'x', PANE_MINIMUM, INT_MAX, &cause); if (cause != NULL) { cmdq_error(item, "width %s", cause); free(cause); @@ -101,9 +100,8 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item) } layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x); } - if (args_has(self->args, 'y')) { - y = args_strtonum(self->args, 'y', PANE_MINIMUM, INT_MAX, - &cause); + if (args_has(args, 'y')) { + y = args_strtonum(args, 'y', PANE_MINIMUM, INT_MAX, &cause); if (cause != NULL) { cmdq_error(item, "height %s", cause); free(cause); @@ -112,13 +110,13 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item) layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y); } - if (args_has(self->args, 'L')) + if (args_has(args, 'L')) layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust, 1); - else if (args_has(self->args, 'R')) + else if (args_has(args, 'R')) layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust, 1); - else if (args_has(self->args, 'U')) + else if (args_has(args, 'U')) layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust, 1); - else if (args_has(self->args, 'D')) + else if (args_has(args, 'D')) layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust, 1); server_redraw_window(wl->window); diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index 294da0e0b3a..5a86f634969 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.158 2018/07/04 09:44:07 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.159 2018/08/18 16:14:03 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -1447,12 +1447,13 @@ format_defaults_winlink(struct format_tree *ft, struct winlink *wl) void format_defaults_pane(struct format_tree *ft, struct window_pane *wp) { + struct window *w = wp->window; struct grid *gd = wp->base.grid; int status = wp->status; u_int idx; if (ft->w == NULL) - ft->w = wp->window; + ft->w = w; ft->wp = wp; format_add(ft, "history_size", "%u", gd->hsize); @@ -1467,7 +1468,7 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "pane_height", "%u", wp->sy); format_add(ft, "pane_title", "%s", wp->base.title); format_add(ft, "pane_id", "%%%u", wp->id); - format_add(ft, "pane_active", "%d", wp == wp->window->active); + format_add(ft, "pane_active", "%d", wp == w->active); format_add(ft, "pane_input_off", "%d", !!(wp->flags & PANE_INPUTOFF)); format_add(ft, "pane_pipe", "%d", wp->pipe_fd != -1); @@ -1483,9 +1484,9 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "pane_at_left", "%d", wp->xoff == 0); format_add(ft, "pane_at_top", "%d", wp->yoff == 0); format_add(ft, "pane_at_right", "%d", - wp->xoff + wp->sx == wp->window->sx); + wp->xoff + wp->sx == w->sx); format_add(ft, "pane_at_bottom", "%d", - wp->yoff + wp->sy == wp->window->sy); + wp->yoff + wp->sy == w->sy); } format_add(ft, "pane_in_mode", "%d", wp->screen != &wp->base); @@ -1493,7 +1494,7 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "pane_mode", "%s", wp->mode->name); format_add(ft, "pane_synchronized", "%d", - !!options_get_number(wp->window->options, "synchronize-panes")); + !!options_get_number(w->options, "synchronize-panes")); if (wp->searchstr != NULL) format_add(ft, "pane_search_string", "%s", wp->searchstr); diff --git a/usr.bin/tmux/screen-redraw.c b/usr.bin/tmux/screen-redraw.c index 7af3e042282..00a8492752c 100644 --- a/usr.bin/tmux/screen-redraw.c +++ b/usr.bin/tmux/screen-redraw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-redraw.c,v 1.51 2018/08/14 11:38:05 nicm Exp $ */ +/* $OpenBSD: screen-redraw.c,v 1.52 2018/08/18 16:14:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -35,17 +35,6 @@ struct screen_redraw_ctx { u_int sy; }; -static int screen_redraw_cell_border1(struct window_pane *, u_int, u_int); -static int screen_redraw_cell_border(struct client *, u_int, u_int); -static int screen_redraw_check_cell(struct client *, u_int, u_int, int, - struct window_pane **); -static int screen_redraw_check_is(u_int, u_int, int, int, struct window *, - struct window_pane *, struct window_pane *); - -static int screen_redraw_make_pane_status(struct client *, struct window *, - struct window_pane *); -static void screen_redraw_draw_pane_status(struct client *, int); - static void screen_redraw_draw_borders(struct screen_redraw_ctx *); static void screen_redraw_draw_panes(struct screen_redraw_ctx *); static void screen_redraw_draw_status(struct screen_redraw_ctx *); @@ -327,8 +316,9 @@ screen_redraw_make_pane_status(struct client *c, struct window *w, /* Draw pane status. */ static void -screen_redraw_draw_pane_status(struct client *c, int pane_status) +screen_redraw_draw_pane_status(struct screen_redraw_ctx *ctx) { + struct client *c = ctx->c; struct window *w = c->session->curw->window; struct options *oo = c->session->options; struct tty *tty = &c->tty; @@ -340,7 +330,7 @@ screen_redraw_draw_pane_status(struct client *c, int pane_status) TAILQ_FOREACH(wp, &w->panes, entry) { if (!window_pane_visible(wp)) continue; - if (pane_status == CELL_STATUS_TOP) + if (ctx->pane_status == CELL_STATUS_TOP) yoff = wp->yoff - 1; else yoff = wp->yoff + wp->sy; @@ -382,50 +372,51 @@ screen_redraw_update(struct client *c) } } +/* Set up redraw context. */ +static void +screen_redraw_set_context(struct client *c, struct screen_redraw_ctx *ctx) +{ + struct session *s = c->session; + struct options *oo = s->options; + struct window *w = s->curw->window; + struct options *wo = w->options; + + memset(ctx, 0, sizeof *ctx); + ctx->c = c; + + ctx->lines = tty_status_lines(c); + if (ctx->lines != 0 && options_get_number(oo, "status-position") == 0) + ctx->top = 1; + ctx->pane_status = options_get_number(wo, "pane-border-status"); + + ctx->sx = c->tty.sx; + ctx->sy = c->tty.sy - ctx->lines; +} + /* Redraw entire screen. */ void screen_redraw_screen(struct client *c, int draw_panes, int draw_status, int draw_borders) { - struct options *oo = c->session->options; - struct tty *tty = &c->tty; - struct window *w = c->session->curw->window; - struct options *wo = w->options; struct screen_redraw_ctx ctx; if (c->flags & CLIENT_SUSPENDED) return; - memset(&ctx, 0, sizeof ctx); - ctx.c = c; - - if (c->flags & CLIENT_STATUSOFF) - ctx.lines = 0; - else - ctx.lines = status_line_size(c->session); - if (c->message_string != NULL || c->prompt_string != NULL) - ctx.lines = (ctx.lines == 0) ? 1 : ctx.lines; - - if (ctx.lines != 0 && options_get_number(oo, "status-position") == 0) - ctx.top = 1; - ctx.pane_status = options_get_number(wo, "pane-border-status"); - - ctx.sx = tty->sx; - ctx.sy = tty->sy - ctx.lines; + screen_redraw_set_context(c, &ctx); if (ctx.lines == 0) draw_status = 0; - if (draw_borders) { - if (ctx.pane_status != CELL_STATUS_OFF) - screen_redraw_draw_pane_status(c, ctx.pane_status); + if (draw_borders) screen_redraw_draw_borders(&ctx); - } + if (draw_borders && ctx.pane_status != CELL_STATUS_OFF) + screen_redraw_draw_pane_status(&ctx); if (draw_panes) screen_redraw_draw_panes(&ctx); if (draw_status) screen_redraw_draw_status(&ctx); - tty_reset(tty); + tty_reset(&c->tty); } /* Draw a single pane. */ diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 8f297a492dc..08da07b44d5 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.837 2018/08/09 09:53:44 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.838 2018/08/18 16:14:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1638,6 +1638,7 @@ struct environ *environ_for_session(struct session *, int); /* tty.c */ void tty_create_log(void); +u_int tty_status_lines(struct client *); void tty_raw(struct tty *, const char *); void tty_attributes(struct tty *, const struct grid_cell *, const struct window_pane *); diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index 7ac95627005..7e225aa9e5d 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.303 2018/07/04 09:44:07 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.304 2018/08/18 16:14:03 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -698,6 +698,21 @@ tty_repeat_space(struct tty *tty, u_int n) tty_putn(tty, s, n, n); } +/* How many lines are taken up by the status line on this client? */ +u_int +tty_status_lines(struct client *c) +{ + u_int lines; + + if (c->flags & CLIENT_STATUSOFF) + lines = 0; + else + lines = status_line_size(c->session); + if (c->message_string != NULL || c->prompt_string != NULL) + lines = (lines == 0) ? 1 : lines; + return (lines); +} + /* * Is the region large enough to be worth redrawing once later rather than * probably several times now? Currently yes if it is more than 50% of the