From b6450b167b089201381f02e1919f18df8881e082 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Wed, 1 Apr 2009 18:21:42 +0000 Subject: [PATCH] Basic horizontal splitting and layout management. Still some redraw and other issues - particularly, don't mix with manual pane resizing and be careful when viewing from multiple clients; generally cycling the layout a few times will fix most problems. Getting this in for testing while I think about how to deal with manual mode. Split window as normal and cycle the layouts with C-b space. Some of the layouts will work better when swap-pane comes along. --- CHANGES | 13 ++- GNUmakefile | 6 +- Makefile | 6 +- cmd-down-pane.c | 4 +- cmd-kill-pane.c | 3 +- cmd-new-session.c | 3 +- cmd-next-layout.c | 54 +++++++++++ cmd-select-pane.c | 3 +- cmd-server-info.c | 6 +- cmd-split-window.c | 3 +- cmd-up-pane.c | 4 +- cmd.c | 3 +- key-bindings.c | 3 +- layout.c | 219 +++++++++++++++++++++++++++++++++++++++++++++ resize.c | 14 +-- screen-redraw.c | 178 ++++++++++++++++++------------------ server.c | 19 ++-- tmux.c | 4 +- tmux.h | 21 +++-- tty.c | 142 +++++++++++++++-------------- window.c | 9 +- 21 files changed, 518 insertions(+), 199 deletions(-) create mode 100644 cmd-next-layout.c create mode 100644 layout.c diff --git a/CHANGES b/CHANGES index 939b1cc2..fef5a8ee 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,14 @@ +01 April 2009 + +* Basic horizontal splitting and layout management. Still some redraw and other + issues - particularly, don't mix with manual pane resizing and be careful + when viewing from multiple clients; generally cycling the layout a few times + will fix most problems. Getting this in for testing while I think about how + to deal with manual mode. + + Split window as normal and cycle the layouts with C-b space. Some of the + layouts will work better when swap-pane comes along. + 31 March 2009 * AIX port, thanks to cmihai for access to a box. Only tested on 6.1 with xlc @@ -1173,7 +1184,7 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.266 2009-03-31 23:14:22 nicm Exp $ +$Id: CHANGES,v 1.267 2009-04-01 18:21:12 nicm Exp $ LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms diff --git a/GNUmakefile b/GNUmakefile index d40aeaff..687817f4 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,4 @@ -# $Id: GNUmakefile,v 1.78 2009-03-31 22:08:45 nicm Exp $ +# $Id: GNUmakefile,v 1.79 2009-04-01 18:21:22 nicm Exp $ .PHONY: clean @@ -17,7 +17,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ grid.c grid-view.c \ window.c session.c log.c client.c client-msg.c client-fn.c cfg.c \ key-string.c key-bindings.c resize.c arg.c mode-key.c \ - cmd.c cmd-generic.c cmd-string.c cmd-list.c \ + layout.c cmd.c cmd-generic.c cmd-string.c cmd-list.c \ cmd-detach-client.c cmd-list-sessions.c cmd-new-window.c cmd-bind-key.c \ cmd-unbind-key.c cmd-previous-window.c cmd-last-window.c cmd-list-keys.c \ cmd-set-option.c cmd-rename-window.c cmd-select-window.c \ @@ -37,7 +37,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ cmd-resize-pane-up.c cmd-resize-pane-down.c cmd-kill-pane.c \ cmd-up-pane.c cmd-down-pane.c cmd-choose-window.c cmd-choose-session.c \ cmd-suspend-client.c cmd-find-window.c cmd-load-buffer.c \ - cmd-copy-buffer.c cmd-break-pane.c \ + cmd-copy-buffer.c cmd-break-pane.c cmd-next-layout.c \ window-clock.c window-scroll.c window-more.c window-copy.c \ window-choose.c \ options.c options-cmd.c paste.c colour.c utf8.c clock.c \ diff --git a/Makefile b/Makefile index 30a3d697..f2c52d2e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.116 2009-03-07 09:29:54 nicm Exp $ +# $Id: Makefile,v 1.117 2009-04-01 18:21:23 nicm Exp $ .SUFFIXES: .c .o .y .h .PHONY: clean update-index.html upload-index.html @@ -19,7 +19,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ screen.c screen-write.c screen-redraw.c \ grid.c grid-view.c \ window.c session.c log.c client.c client-msg.c client-fn.c cfg.c \ - key-string.c key-bindings.c resize.c arg.c mode-key.c \ + layout.c key-string.c key-bindings.c resize.c arg.c mode-key.c \ cmd.c cmd-generic.c cmd-string.c cmd-list.c \ cmd-detach-client.c cmd-list-sessions.c cmd-new-window.c cmd-bind-key.c \ cmd-unbind-key.c cmd-previous-window.c cmd-last-window.c cmd-list-keys.c \ @@ -40,7 +40,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ cmd-resize-pane-up.c cmd-resize-pane-down.c cmd-kill-pane.c \ cmd-up-pane.c cmd-down-pane.c cmd-choose-window.c cmd-choose-session.c \ cmd-suspend-client.c cmd-find-window.c cmd-load-buffer.c \ - cmd-copy-buffer.c cmd-break-pane.c \ + cmd-copy-buffer.c cmd-break-pane.c cmd-next-layout.c \ window-clock.c window-scroll.c window-more.c window-copy.c \ window-choose.c \ options.c options-cmd.c paste.c colour.c utf8.c clock.c \ diff --git a/cmd-down-pane.c b/cmd-down-pane.c index 842db127..cca5303a 100644 --- a/cmd-down-pane.c +++ b/cmd-down-pane.c @@ -1,4 +1,4 @@ -/* $Id: cmd-down-pane.c,v 1.4 2009-03-28 14:08:09 nicm Exp $ */ +/* $Id: cmd-down-pane.c,v 1.5 2009-04-01 18:21:24 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -56,5 +56,7 @@ cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx) w->active = TAILQ_FIRST(&w->panes); } while (w->active->flags & PANE_HIDDEN); + layout_refresh(wl->window); + return (0); } diff --git a/cmd-kill-pane.c b/cmd-kill-pane.c index 73e36cb9..a91d7c07 100644 --- a/cmd-kill-pane.c +++ b/cmd-kill-pane.c @@ -1,4 +1,4 @@ -/* $Id: cmd-kill-pane.c,v 1.4 2009-03-07 09:29:54 nicm Exp $ */ +/* $Id: cmd-kill-pane.c,v 1.5 2009-04-01 18:21:24 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -67,5 +67,6 @@ cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx) window_remove_pane(wl->window, wp); server_redraw_window(wl->window); + layout_refresh(wl->window); return (0); } diff --git a/cmd-new-session.c b/cmd-new-session.c index 537b3fe5..e5756d0d 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-new-session.c,v 1.39 2009-02-11 17:50:33 nicm Exp $ */ +/* $Id: cmd-new-session.c,v 1.40 2009-04-01 18:21:24 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -185,6 +185,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) server_write_client(c, MSG_READY, NULL, 0); server_redraw_client(c); } + recalculate_sizes(); return (1); } diff --git a/cmd-next-layout.c b/cmd-next-layout.c new file mode 100644 index 00000000..f5f611f6 --- /dev/null +++ b/cmd-next-layout.c @@ -0,0 +1,54 @@ +/* $Id: cmd-next-layout.c,v 1.1 2009-04-01 18:21:26 nicm Exp $ */ + +/* + * Copyright (c) 2009 Nicholas Marriott + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include "tmux.h" + +/* + * Switch window to next layout. + */ + +int cmd_next_layout_exec(struct cmd *, struct cmd_ctx *); + +const struct cmd_entry cmd_next_layout_entry = { + "next-layout", "nextl", + CMD_TARGET_WINDOW_USAGE, + 0, + cmd_target_init, + cmd_target_parse, + cmd_next_layout_exec, + cmd_target_send, + cmd_target_recv, + cmd_target_free, + cmd_target_print +}; + +int +cmd_next_layout_exec(struct cmd *self, struct cmd_ctx *ctx) +{ + struct cmd_target_data *data = self->data; + struct winlink *wl; + + if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL) + return (-1); + + layout_next(wl->window); + + return (0); +} diff --git a/cmd-select-pane.c b/cmd-select-pane.c index b7f4e65a..16cdc95b 100644 --- a/cmd-select-pane.c +++ b/cmd-select-pane.c @@ -1,4 +1,4 @@ -/* $Id: cmd-select-pane.c,v 1.2 2009-01-19 18:23:40 nicm Exp $ */ +/* $Id: cmd-select-pane.c,v 1.3 2009-04-01 18:21:26 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -63,6 +63,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx) return (-1); } window_set_active_pane(wl->window, wp); + layout_refresh(wl->window); return (0); } diff --git a/cmd-server-info.c b/cmd-server-info.c index 89d3d7da..ce680485 100644 --- a/cmd-server-info.c +++ b/cmd-server-info.c @@ -1,4 +1,4 @@ -/* $Id: cmd-server-info.c,v 1.12 2009-03-29 19:09:57 nicm Exp $ */ +/* $Id: cmd-server-info.c,v 1.13 2009-04-01 18:21:28 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -115,8 +115,8 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx) RB_FOREACH(wl, winlinks, &s->windows) { w = wl->window; ctx->print(ctx, "%4u: %p/%p %s [%ux%u] [flags=0x%x, " - "references=%u]", wl->idx, wl, w, w->name, - w->sx, w->sy, w->flags, w->references); + "references=%u, layout=%u]", wl->idx, wl, w, w->name, + w->sx, w->sy, w->flags, w->references, w->layout); j = 0; TAILQ_FOREACH(wp, &w->panes, entry) { lines = ulines = size = usize = 0; diff --git a/cmd-split-window.c b/cmd-split-window.c index 53bae77f..b79bcc82 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-split-window.c,v 1.9 2009-03-04 17:24:07 nicm Exp $ */ +/* $Id: cmd-split-window.c,v 1.10 2009-04-01 18:21:28 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -178,6 +178,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx) server_redraw_session(s); } else server_status_session(s); + layout_refresh(w); return (0); } diff --git a/cmd-up-pane.c b/cmd-up-pane.c index a78e140d..d70a2a24 100644 --- a/cmd-up-pane.c +++ b/cmd-up-pane.c @@ -1,4 +1,4 @@ -/* $Id: cmd-up-pane.c,v 1.4 2009-03-28 14:08:09 nicm Exp $ */ +/* $Id: cmd-up-pane.c,v 1.5 2009-04-01 18:21:29 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -56,5 +56,7 @@ cmd_up_pane_exec(struct cmd *self, struct cmd_ctx *ctx) w->active = TAILQ_LAST(&w->panes, window_panes); } while (w->active->flags & PANE_HIDDEN); + layout_refresh(wl->window); + return (0); } diff --git a/cmd.c b/cmd.c index c4e3267d..eade9e1b 100644 --- a/cmd.c +++ b/cmd.c @@ -1,4 +1,4 @@ -/* $Id: cmd.c,v 1.86 2009-03-07 09:29:34 nicm Exp $ */ +/* $Id: cmd.c,v 1.87 2009-04-01 18:21:29 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -57,6 +57,7 @@ const struct cmd_entry *cmd_table[] = { &cmd_move_window_entry, &cmd_new_session_entry, &cmd_new_window_entry, + &cmd_next_layout_entry, &cmd_next_window_entry, &cmd_paste_buffer_entry, &cmd_previous_window_entry, diff --git a/key-bindings.c b/key-bindings.c index 76940123..02afc1c6 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -1,4 +1,4 @@ -/* $Id: key-bindings.c,v 1.63 2009-03-28 14:08:09 nicm Exp $ */ +/* $Id: key-bindings.c,v 1.64 2009-04-01 18:21:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -79,6 +79,7 @@ key_bindings_init(void) int can_repeat; const struct cmd_entry *entry; } table[] = { + { ' ', 0, &cmd_next_layout_entry }, { '!', 0, &cmd_break_pane_entry }, { '"', 0, &cmd_split_window_entry }, { '#', 0, &cmd_list_buffers_entry }, diff --git a/layout.c b/layout.c new file mode 100644 index 00000000..032be3b0 --- /dev/null +++ b/layout.c @@ -0,0 +1,219 @@ +/* $Id: layout.c,v 1.1 2009-04-01 18:21:32 nicm Exp $ */ + +/* + * Copyright (c) 2009 Nicholas Marriott + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include "tmux.h" + +void layout_manual(struct window *); +void layout_active_only(struct window *); +void layout_even_horizontal(struct window *); +void layout_even_vertical(struct window *); +void layout_left_vertical(struct window *); + +const struct { + const char *name; + void (*fn)(struct window *); +} layouts[] = { + { "manual", layout_manual }, + { "active-only", layout_active_only }, + { "even-horizontal", layout_even_horizontal }, + { "even-vertical", layout_even_vertical }, + { "left-vertical", layout_left_vertical }, +}; + +void +layout_next(struct window *w) +{ + w->layout++; + if (w->layout > nitems(layouts) - 1) { + w->layout = 0; + /* XXX Special-case manual. */ + window_fit_panes(w); + window_update_panes(w); + } + layout_refresh(w); +} + +void +layout_refresh(struct window *w) +{ + layouts[w->layout].fn(w); + server_redraw_window(w); +} + +void +layout_manual(unused struct window *w) +{ +} + +void +layout_active_only(struct window *w) +{ + struct window_pane *wp; + + TAILQ_FOREACH(wp, &w->panes, entry) { + if (wp == w->active) { + wp->flags &= ~PANE_HIDDEN; + wp->xoff = wp->yoff = 0; + window_pane_resize(wp, w->sx, w->sy); + } else + wp->flags |= PANE_HIDDEN; + } +} + +void +layout_even_horizontal(struct window *w) +{ + struct window_pane *wp; + u_int i, n, width, xoff; + + /* How many can we fit? */ + n = window_count_panes(w); + if (w->sx / n < PANE_MINIMUM) { + width = PANE_MINIMUM; + n = w->sx / PANE_MINIMUM; + } else + width = w->sx / n; + + /* Fit the panes. */ + i = xoff = 0; + TAILQ_FOREACH(wp, &w->panes, entry) { + if (i > n) { + wp->flags |= PANE_HIDDEN; + continue; + } + wp->flags &= ~PANE_HIDDEN; + + wp->xoff = xoff; + wp->yoff = 0; + if (i != n - 1) + window_pane_resize(wp, width - 1, w->sy); + else + window_pane_resize(wp, width, w->sy); + + i++; + xoff += width; + } + + /* Any space left? */ + while (xoff++ < w->sx) { + wp = TAILQ_LAST(&w->panes, window_panes); + window_pane_resize(wp, wp->sx + 1, wp->sy); + } +} + +void +layout_even_vertical(struct window *w) +{ + struct window_pane *wp; + u_int i, n, height, yoff; + + /* How many can we fit? */ + n = window_count_panes(w); + if (w->sy / n < PANE_MINIMUM) { + height = PANE_MINIMUM; + n = w->sy / PANE_MINIMUM; + } else + height = w->sy / n; + + /* Fit the panes. */ + i = yoff = 0; + TAILQ_FOREACH(wp, &w->panes, entry) { + if (i > n) { + wp->flags |= PANE_HIDDEN; + continue; + } + wp->flags &= ~PANE_HIDDEN; + + wp->xoff = 0; + wp->yoff = yoff; + if (i != n - 1) + window_pane_resize(wp, w->sx, height - 1); + else + window_pane_resize(wp, w->sx, height); + + i++; + yoff += height; + } + + /* Any space left? */ + while (yoff++ < w->sy) { + wp = TAILQ_LAST(&w->panes, window_panes); + window_pane_resize(wp, wp->sx, wp->sy + 1); + } +} + +void +layout_left_vertical(struct window *w) +{ + struct window_pane *wp; + u_int i, n, height, yoff; + + /* Need >1 pane and minimum columns; if fewer, display active only. */ + n = window_count_panes(w) - 1; + if (n == 0 || w->sx < 82 + PANE_MINIMUM) { + layout_active_only(w); + return; + } + + /* How many can we fit, not including first? */ + if (w->sy / n < PANE_MINIMUM) { + height = PANE_MINIMUM; + n = w->sy / PANE_MINIMUM; + } else + height = w->sy / n; + + /* Fit the panes. */ + i = yoff = 0; + TAILQ_FOREACH(wp, &w->panes, entry) { + if (wp == TAILQ_FIRST(&w->panes)) { + wp->xoff = 0; + wp->yoff = 0; + window_pane_resize(wp, 81, w->sy); + wp->flags &= ~PANE_HIDDEN; + continue; + } + + if (i > n) { + wp->flags |= PANE_HIDDEN; + continue; + } + wp->flags &= ~PANE_HIDDEN; + + wp->xoff = 82; + wp->yoff = yoff; + if (i != n - 1) + window_pane_resize(wp, w->sx - 82, height - 1); + else + window_pane_resize(wp, w->sx - 82, height); + + i++; + yoff += height; + } + + /* Any space left? */ + while (yoff++ < w->sy) { + wp = TAILQ_LAST(&w->panes, window_panes); + while (wp != NULL && wp == TAILQ_FIRST(&w->panes)) + wp = TAILQ_PREV(wp, window_panes, entry); + if (wp == NULL) + break; + window_pane_resize(wp, wp->sx, wp->sy + 1); + } +} diff --git a/resize.c b/resize.c index 6ed0eb71..26aabbb0 100644 --- a/resize.c +++ b/resize.c @@ -1,4 +1,4 @@ -/* $Id: resize.c,v 1.19 2009-02-11 17:50:33 nicm Exp $ */ +/* $Id: resize.c,v 1.20 2009-04-01 18:21:32 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -45,11 +45,12 @@ void recalculate_sizes(void) { - struct session *s; - struct client *c; - struct window *w; - u_int i, j, ssx, ssy, has, limit; - int flag; + struct session *s; + struct client *c; + struct window *w; + struct window_pane *wp; + u_int i, j, ssx, ssy, has, limit; + int flag; for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { s = ARRAY_ITEM(&sessions, i); @@ -133,5 +134,6 @@ recalculate_sizes(void) window_resize(w, ssx, ssy); server_redraw_window(w); + layout_refresh(w); } } diff --git a/screen-redraw.c b/screen-redraw.c index fc90c3a2..7c989cca 100644 --- a/screen-redraw.c +++ b/screen-redraw.c @@ -1,4 +1,4 @@ -/* $Id: screen-redraw.c,v 1.30 2009-03-31 18:39:45 nicm Exp $ */ +/* $Id: screen-redraw.c,v 1.31 2009-04-01 18:21:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -22,65 +22,108 @@ #include "tmux.h" -void screen_redraw_blankx(struct client *, u_int, u_int); -void screen_redraw_blanky(struct client *, u_int, u_int, char); -void screen_redraw_line(struct client *, struct screen *, u_int, u_int); +int screen_redraw_check_cell(struct client *, u_int, u_int); -/* Redraw entire screen.. */ -void -screen_redraw_screen(struct client *c, struct screen *s) +/* Check if cell inside a pane. */ +int +screen_redraw_check_cell(struct client *c, u_int px, u_int py) { struct window *w = c->session->curw->window; struct window_pane *wp; - u_int i, cx, cy, sy; - int status; - /* Override the normal screen if one is given. */ - if (s != NULL) { - for (i = 0; i < screen_size_y(s); i++) - screen_redraw_line(c, s, 0, i); - screen_redraw_status(c); - return; + if (px > w->sx || py > w->sy) + return (0); + + TAILQ_FOREACH(wp, &w->panes, entry) { + /* Inside pane. */ + if (px >= wp->xoff && px < wp->xoff + wp->sx && + py >= wp->yoff && py < wp->yoff + wp->sy) + return (1); + + /* Left/right borders. */ + if (py >= wp->yoff && py < wp->yoff + wp->sy) { + if (wp->xoff != 0 && px == wp->xoff - 1) + return (1); + if (px == wp->xoff + wp->sx) + return (1); + } + + /* Top/bottom borders. */ + if (px >= wp->xoff && px < wp->xoff + wp->sx) { + if (wp->yoff != 0 && py == wp->yoff - 1) + return (1); + if (py == wp->yoff + wp->sy) + return (1); + } } + return (0); +} + +/* Redraw entire screen.. */ +void +screen_redraw_screen(struct client *c) +{ + struct window *w = c->session->curw->window; + struct tty *tty = &c->tty; + struct window_pane *wp; + struct screen *s; + u_int i, j, sx, sy; + int status; + + /* Get status line, er, status. */ status = options_get_number(&c->session->options, "status"); - /* Fill in empty space on the right. */ - if (w->sx < c->tty.sx) - screen_redraw_blankx(c, w->sx, c->tty.sx - w->sx); + /* Clear the screen. */ + tty_reset(tty); + for (j = 0; j < tty->sy - status; j++) { + for (i = 0; i < tty->sx; i++) { + if (!screen_redraw_check_cell(c, i, j)) { + tty_cursor(tty, i, j, 0, 0); + tty_putc(tty, '.'); + } + } + } /* Draw the panes. */ TAILQ_FOREACH(wp, &w->panes, entry) { + tty_reset(tty); + s = wp->screen; - - sy = screen_size_y(s); - - cx = s->cx; - cy = s->cy; - if (wp->yoff + sy <= w->sy) { - for (i = 0; i < sy; i++) { - if (wp->yoff + i != c->tty.sy - 1) - screen_redraw_line(c, s, wp->yoff, i); + sx = wp->sx; + sy = wp->sy; + + /* Draw left and right borders. */ + if (wp->xoff > 0) { + for (i = wp->yoff; i < wp->yoff + sy; i++) { + tty_cursor(tty, wp->xoff - 1, i, 0, 0); + tty_putc(tty, '|'); } - if (TAILQ_NEXT(wp, entry) != NULL) - screen_redraw_blanky(c, wp->yoff + sy, 1, '-'); } - s->cx = cx; - s->cy = cy; - } - - /* Fill in empty space below. */ - if (w->sy < c->tty.sy - status) - screen_redraw_blanky(c, w->sy, c->tty.sy - status - w->sy, '='); - - /* Draw right border line. */ - if (w->sx < c->tty.sx) { - for (i = 0; i < c->tty.sy; i++) { - tty_putcode2(&c->tty, TTYC_CUP, i, w->sx); - tty_putc(&c->tty, '|'); + if (wp->xoff + sx < tty->sx) { + for (i = wp->yoff; i < wp->yoff + sy; i++) { + tty_cursor(tty, wp->xoff + sx, i, 0, 0); + tty_putc(&c->tty, '|'); + } } - } + /* Draw top and bottom borders. */ + if (wp->yoff > 0) { + tty_cursor(tty, wp->xoff, wp->yoff - 1, 0, 0); + for (i = 0; i < sx; i++) + tty_putc(tty, '-'); + } + if (wp->yoff + sy < tty->sy) { + tty_cursor(tty, wp->xoff, wp->yoff + sy, 0, 0); + for (i = 0; i < sx; i++) + tty_putc(tty, '-'); + } + + /* Draw the pane. */ + for (i = 0; i < sy; i++) + tty_draw_line(tty, s, i, wp->xoff, wp->yoff); + } + /* Draw the status line. */ screen_redraw_status(c); } @@ -89,52 +132,5 @@ screen_redraw_screen(struct client *c, struct screen *s) void screen_redraw_status(struct client *c) { - screen_redraw_line(c, &c->status, c->tty.sy - 1, 0); -} - -/* Draw blank columns. */ -void -screen_redraw_blankx(struct client *c, u_int ox, u_int nx) -{ - u_int i, j; - - tty_putcode(&c->tty, TTYC_SGR0); - for (j = 0; j < c->tty.sy; j++) { - tty_putcode2(&c->tty, TTYC_CUP, j, ox); - for (i = 0; i < nx; i++) - tty_putc(&c->tty, ' '); - } - - c->tty.cx = UINT_MAX; - c->tty.cy = UINT_MAX; - memcpy(&c->tty.cell, &grid_default_cell, sizeof c->tty.cell); -} - -/* Draw blank lines. */ -void -screen_redraw_blanky(struct client *c, u_int oy, u_int ny, char ch) -{ - u_int i, j; - - tty_putcode(&c->tty, TTYC_SGR0); - for (j = 0; j < ny; j++) { - tty_putcode2(&c->tty, TTYC_CUP, oy + j, 0); - for (i = 0; i < c->tty.sx; i++) { - if (j == 0) - tty_putc(&c->tty, ch); - else - tty_putc(&c->tty, ' '); - } - } - - c->tty.cx = UINT_MAX; - c->tty.cy = UINT_MAX; - memcpy(&c->tty.cell, &grid_default_cell, sizeof c->tty.cell); -} - -/* Draw a line. */ -void -screen_redraw_line(struct client *c, struct screen *s, u_int oy, u_int py) -{ - tty_draw_line(&c->tty, s, py, oy); + tty_draw_line(&c->tty, &c->status, 0, 0, c->tty.sy - 1); } diff --git a/server.c b/server.c index 7d5eb34f..173b1cda 100644 --- a/server.c +++ b/server.c @@ -1,4 +1,4 @@ -/* $Id: server.c,v 1.132 2009-03-31 22:20:42 nicm Exp $ */ +/* $Id: server.c,v 1.133 2009-04-01 18:21:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -518,7 +518,7 @@ server_check_redraw(struct client *c) if (server_locked) server_redraw_locked(c); else - screen_redraw_screen(c, NULL); + screen_redraw_screen(c); c->flags &= ~CLIENT_STATUS; } @@ -536,7 +536,7 @@ server_redraw_locked(struct client *c) { struct screen_write_ctx ctx; struct screen screen; - u_int colour, xx, yy; + u_int colour, xx, yy, i; int style; xx = c->tty.sx; @@ -554,7 +554,9 @@ server_redraw_locked(struct client *c) clock_draw(&ctx, colour, style); screen_write_stop(&ctx); - screen_redraw_screen(c, &screen); + for (i = 0; i < screen_size_y(&screen); i++) + tty_draw_line(&c->tty, &screen, i, 0, 0); + screen_redraw_status(c); screen_free(&screen); } @@ -689,6 +691,7 @@ void server_handle_client(struct client *c) { struct window_pane *wp; + struct screen *s; struct timeval tv; struct key_binding *bd; int key, prefix, status, xtimeout; @@ -776,13 +779,14 @@ server_handle_client(struct client *c) if (c->session == NULL) return; wp = c->session->curw->window->active; /* could die - do each loop */ + s = wp->screen; /* Ensure cursor position and mode settings. */ status = options_get_number(&c->session->options, "status"); - if (wp->yoff + wp->screen->cy < c->tty.sy - status) - tty_cursor(&c->tty, wp->screen->cx, wp->screen->cy, wp->yoff); + if (wp->yoff + s->cy < c->tty.sy - status) + tty_cursor(&c->tty, s->cx, s->cy, wp->xoff, wp->yoff); - mode = wp->screen->mode; + mode = s->mode; if (server_locked) mode &= ~TTY_NOCURSOR; tty_update_mode(&c->tty, mode); @@ -912,6 +916,7 @@ server_check_window(struct window *w) else if (!flag) { window_remove_pane(w, wp); server_redraw_window(w); + layout_refresh(w); } wp = wq; } diff --git a/tmux.c b/tmux.c index 1dce5723..b9639812 100644 --- a/tmux.c +++ b/tmux.c @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.110 2009-03-27 15:57:10 nicm Exp $ */ +/* $Id: tmux.c,v 1.111 2009-04-01 18:21:40 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -216,7 +216,7 @@ main(int argc, char **argv) const char *shell; struct passwd *pw; char *path, *label, *cause, *home, *pass = NULL; - char cwd[MAXPATHLEN]; + char cwd[MAXPATHLEN]; int retcode, opt, flags, unlock, start_server; unlock = flags = 0; diff --git a/tmux.h b/tmux.h index 2a0745c1..e9c35367 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.293 2009-03-31 22:08:45 nicm Exp $ */ +/* $Id: tmux.h,v 1.294 2009-04-01 18:21:42 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -650,6 +650,7 @@ struct window_pane { u_int sx; u_int sy; + u_int xoff; u_int yoff; int flags; @@ -684,10 +685,11 @@ struct window { struct window_pane *active; struct window_panes panes; + u_int layout; u_int sx; u_int sy; - + int flags; #define WINDOW_BELL 0x1 #define WINDOW_HIDDEN 0x2 @@ -1064,9 +1066,11 @@ void options_set_number(struct options *, const char *, long long); long long options_get_number(struct options *, const char *); /* tty.c */ +void tty_emulate_repeat(struct tty *, + enum tty_code_code, enum tty_code_code, u_int); void tty_reset(struct tty *); void tty_region(struct tty *, u_int, u_int, u_int); -void tty_cursor(struct tty *, u_int, u_int, u_int); +void tty_cursor(struct tty *, u_int, u_int, u_int, u_int); void tty_cell(struct tty *, const struct grid_cell *, const struct grid_utf8 *); void tty_putcode(struct tty *, enum tty_code_code); @@ -1079,7 +1083,9 @@ void tty_start_tty(struct tty *); void tty_stop_tty(struct tty *); void tty_set_title(struct tty *, const char *); void tty_update_mode(struct tty *, int); -void tty_draw_line(struct tty *, struct screen *, u_int, u_int); +void tty_draw_line( + struct tty *, struct screen *, u_int, u_int, u_int); +void tty_draw_region(struct tty *, struct screen *, u_int, u_int); int tty_open(struct tty *, char **); void tty_close(struct tty *, int); void tty_free(struct tty *, int); @@ -1193,6 +1199,7 @@ extern const struct cmd_entry cmd_lock_server_entry; extern const struct cmd_entry cmd_move_window_entry; extern const struct cmd_entry cmd_new_session_entry; extern const struct cmd_entry cmd_new_window_entry; +extern const struct cmd_entry cmd_next_layout_entry; extern const struct cmd_entry cmd_next_window_entry; extern const struct cmd_entry cmd_paste_buffer_entry; extern const struct cmd_entry cmd_previous_window_entry; @@ -1457,7 +1464,7 @@ void screen_write_cell( struct screen_write_ctx *, const struct grid_cell *, u_char *); /* screen-redraw.c */ -void screen_redraw_screen(struct client *, struct screen *); +void screen_redraw_screen(struct client *); void screen_redraw_status(struct client *); /* screen.c */ @@ -1519,6 +1526,10 @@ void window_pane_key(struct window_pane *, struct client *, int); void window_pane_mouse(struct window_pane *, struct client *, u_char, u_char, u_char); +/* layout.c */ +void layout_refresh(struct window *); +void layout_next(struct window *); + /* window-clock.c */ extern const struct window_mode window_clock_mode; diff --git a/tty.c b/tty.c index 09db0516..7aa98552 100644 --- a/tty.c +++ b/tty.c @@ -1,4 +1,4 @@ -/* $Id: tty.c,v 1.89 2009-03-31 22:20:42 nicm Exp $ */ +/* $Id: tty.c,v 1.90 2009-04-01 18:21:42 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -30,9 +30,6 @@ void tty_fill_acs(struct tty *); u_char tty_get_acs(struct tty *, u_char); -void tty_emulate_repeat( - struct tty *, enum tty_code_code, enum tty_code_code, u_int); - void tty_raw(struct tty *, const char *); int tty_try_256(struct tty *, u_char, const char *); @@ -383,7 +380,21 @@ tty_emulate_repeat( } void -tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int oy) +tty_draw_region(struct tty *tty, struct screen *s, u_int ox, u_int oy) +{ + u_int i; + + if (s->old_cy < s->old_rupper || s->old_cy > s->old_rlower) { + for (i = s->old_cy; i < screen_size_y(s); i++) + tty_draw_line(tty, s, i, ox, oy); + } else { + for (i = s->old_rupper; i <= s->old_rlower; i++) + tty_draw_line(tty, s, i, ox, oy); + } +} + +void +tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy) { const struct grid_cell *gc; const struct grid_utf8 *gu; @@ -395,6 +406,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int oy) if (sx > tty->sx) sx = tty->sx; + tty_cursor(tty, 0, py, ox, oy); for (i = 0; i < sx; i++) { gc = grid_view_peek_cell(s->grid, i, py); @@ -402,7 +414,6 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int oy) if (gc->flags & GRID_FLAG_UTF8) gu = grid_view_peek_utf8(s->grid, i, py); - tty_cursor(tty, i, py, oy); if (screen_check_selection(s, i, py)) { s->sel.cell.data = gc->data; tty_cell(tty, &s->sel.cell, gu); @@ -414,7 +425,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int oy) return; tty_reset(tty); - tty_cursor(tty, sx, py, oy); + tty_cursor(tty, sx, py, ox, oy); if (screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) tty_putcode(tty, TTYC_EL); else { @@ -449,8 +460,8 @@ tty_cmd_insertcharacter(struct tty *tty, struct window_pane *wp, va_list ap) struct screen *s = wp->screen; u_int ua; - if (screen_size_x(s) < tty->sx) { - tty_draw_line(tty, wp->screen, s->old_cy, wp->yoff); + if (wp->xoff != 0 || screen_size_x(s) < tty->sx) { + tty_draw_line(tty, wp->screen, s->old_cy, wp->xoff, wp->yoff); return; } @@ -458,7 +469,7 @@ tty_cmd_insertcharacter(struct tty *tty, struct window_pane *wp, va_list ap) tty_reset(tty); - tty_cursor(tty, s->old_cx, s->old_cy, wp->yoff); + tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); if (tty_term_has(tty->term, TTYC_ICH) || tty_term_has(tty->term, TTYC_ICH1)) tty_emulate_repeat(tty, TTYC_ICH, TTYC_ICH1, ua); @@ -476,8 +487,8 @@ tty_cmd_deletecharacter(struct tty *tty, struct window_pane *wp, va_list ap) struct screen *s = wp->screen; u_int ua; - if (screen_size_x(s) < tty->sx) { - tty_draw_line(tty, wp->screen, s->old_cy, wp->yoff); + if (wp->xoff != 0 || screen_size_x(s) < tty->sx) { + tty_draw_line(tty, wp->screen, s->old_cy, wp->xoff, wp->yoff); return; } @@ -485,7 +496,7 @@ tty_cmd_deletecharacter(struct tty *tty, struct window_pane *wp, va_list ap) tty_reset(tty); - tty_cursor(tty, s->old_cx, s->old_cy, wp->yoff); + tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_emulate_repeat(tty, TTYC_DCH, TTYC_DCH1, ua); } @@ -493,20 +504,15 @@ void tty_cmd_insertline(struct tty *tty, struct window_pane *wp, va_list ap) { struct screen *s = wp->screen; - u_int ua, i; + u_int ua; - if (screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR)) { + if (wp->xoff != 0 || screen_size_x(s) < tty->sx || + !tty_term_has(tty->term, TTYC_CSR)) { /* * Scroll region unsupported. Redraw using data from screen * (already updated). */ - if (s->old_cy < s->old_rupper || s->old_cy > s->old_rlower) { - for (i = s->old_cy; i < screen_size_y(s); i++) - tty_draw_line(tty, wp->screen, i, wp->yoff); - } else { - for (i = s->old_rupper; i <= s->old_rlower; i++) - tty_draw_line(tty, wp->screen, i, wp->yoff); - } + tty_draw_region(tty, s, wp->xoff, wp->yoff); return; } @@ -516,7 +522,7 @@ tty_cmd_insertline(struct tty *tty, struct window_pane *wp, va_list ap) tty_region(tty, s->old_rupper, s->old_rlower, wp->yoff); - tty_cursor(tty, s->old_cx, s->old_cy, wp->yoff); + tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_emulate_repeat(tty, TTYC_IL, TTYC_IL1, ua); } @@ -524,20 +530,15 @@ void tty_cmd_deleteline(struct tty *tty, struct window_pane *wp, va_list ap) { struct screen *s = wp->screen; - u_int ua, i; + u_int ua; - if (screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR)) { + if (wp->xoff != 0 || screen_size_x(s) < tty->sx || + !tty_term_has(tty->term, TTYC_CSR)) { /* * Scroll region unsupported. Redraw using data from screen * (already updated). */ - if (s->old_cy < s->old_rupper || s->old_cy > s->old_rlower) { - for (i = s->old_cy; i < screen_size_y(s); i++) - tty_draw_line(tty, wp->screen, i, wp->yoff); - } else { - for (i = s->old_rupper; i <= s->old_rlower; i++) - tty_draw_line(tty, wp->screen, i, wp->yoff); - } + tty_draw_region(tty, s, wp->xoff, wp->yoff); return; } @@ -547,7 +548,7 @@ tty_cmd_deleteline(struct tty *tty, struct window_pane *wp, va_list ap) tty_region(tty, s->old_rupper, s->old_rlower, wp->yoff); - tty_cursor(tty, s->old_cx, s->old_cy, wp->yoff); + tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_emulate_repeat(tty, TTYC_DL, TTYC_DL1, ua); } @@ -559,8 +560,9 @@ tty_cmd_clearline(struct tty *tty, struct window_pane *wp, unused va_list ap) tty_reset(tty); - tty_cursor(tty, 0, s->old_cy, wp->yoff); - if (screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) { + tty_cursor(tty, 0, s->old_cy, wp->xoff, wp->yoff); + if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && + tty_term_has(tty->term, TTYC_EL)) { tty_putcode(tty, TTYC_EL); } else { for (i = 0; i < screen_size_x(s); i++) @@ -577,8 +579,9 @@ tty_cmd_clearendofline( tty_reset(tty); - tty_cursor(tty, s->old_cx, s->old_cy, wp->yoff); - if (screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) + tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); + if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && + tty_term_has(tty->term, TTYC_EL)) tty_putcode(tty, TTYC_EL); else { for (i = s->old_cx; i < screen_size_x(s); i++) @@ -595,11 +598,11 @@ tty_cmd_clearstartofline( tty_reset(tty); - if (tty_term_has(tty->term, TTYC_EL1)) { - tty_cursor(tty, s->old_cx, s->old_cy, wp->yoff); + if (wp->xoff == 0 && tty_term_has(tty->term, TTYC_EL1)) { + tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_putcode(tty, TTYC_EL1); } else { - tty_cursor(tty, 0, s->old_cy, wp->yoff); + tty_cursor(tty, 0, s->old_cy, wp->xoff, wp->yoff); for (i = 0; i < s->old_cx + 1; i++) tty_putc(tty, ' '); } @@ -611,15 +614,16 @@ tty_cmd_reverseindex(struct tty *tty, struct window_pane *wp, unused va_list ap) struct screen *s = wp->screen; u_int i; - if (screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR)) { + if (wp->xoff != 0 || screen_size_x(s) < tty->sx || + !tty_term_has(tty->term, TTYC_CSR)) { /* * Scroll region unsupported. If would have scrolled, redraw * scroll region from already updated window screen. */ - if (s->old_cy == s->old_rupper) { - for (i = s->old_rupper; i <= s->old_rlower; i++) - tty_draw_line(tty, wp->screen, i, wp->yoff); - } + if (s->old_cy != s->old_rupper) + return; + for (i = s->old_rupper; i <= s->old_rlower; i++) + tty_draw_line(tty, wp->screen, i, wp->xoff, wp->yoff); return; } @@ -628,7 +632,7 @@ tty_cmd_reverseindex(struct tty *tty, struct window_pane *wp, unused va_list ap) tty_region(tty, s->old_rupper, s->old_rlower, wp->yoff); if (s->old_cy == s->old_rupper) { - tty_cursor(tty, s->old_cx, s->old_rupper, wp->yoff); + tty_cursor(tty, s->old_cx, s->old_rupper, wp->xoff, wp->yoff); tty_putcode(tty, TTYC_RI); } } @@ -639,23 +643,24 @@ tty_cmd_linefeed(struct tty *tty, struct window_pane *wp, unused va_list ap) struct screen *s = wp->screen; u_int i; - if (screen_size_x(s) < tty->sx || !tty_term_has(tty->term, TTYC_CSR)) { + if (wp->xoff != 0 || screen_size_x(s) < tty->sx || + !tty_term_has(tty->term, TTYC_CSR)) { /* * Scroll region unsupported. If would have scrolled, redraw * scroll region from already updated window screen. */ - if (s->old_cy == s->old_rlower) { - for (i = s->old_rupper; i <= s->old_rlower; i++) - tty_draw_line(tty, wp->screen, i, wp->yoff); + if (s->old_cy != s->old_rlower) return; - } + for (i = s->old_rupper; i <= s->old_rlower; i++) + tty_draw_line(tty, wp->screen, i, wp->xoff, wp->yoff); + return; } tty_reset(tty); tty_region(tty, s->old_rupper, s->old_rlower, wp->yoff); - tty_cursor(tty, s->old_cx, s->old_cy, wp->yoff); + tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_putc(tty, '\n'); tty->cy++; @@ -672,12 +677,13 @@ tty_cmd_clearendofscreen( tty_reset(tty); - tty_cursor(tty, s->old_cx, s->old_cy, wp->yoff); + tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_region(tty, 0, screen_size_y(s) - 1, wp->yoff); - if (screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) { + if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && + tty_term_has(tty->term, TTYC_EL)) { tty_putcode(tty, TTYC_EL); if (s->old_cy != screen_size_y(s) - 1) { - tty_cursor(tty, 0, s->old_cy + 1, wp->yoff); + tty_cursor(tty, 0, s->old_cy + 1, wp->xoff, wp->yoff); for (i = s->old_cy + 1; i < screen_size_y(s); i++) { tty_putcode(tty, TTYC_EL); if (i == screen_size_y(s) - 1) @@ -690,7 +696,7 @@ tty_cmd_clearendofscreen( for (i = s->old_cx; i < screen_size_x(s); i++) tty_putc(tty, ' '); for (j = s->old_cy; j < screen_size_y(s); j++) { - tty_cursor(tty, 0, j, wp->yoff); + tty_cursor(tty, 0, j, wp->xoff, wp->yoff); for (i = 0; i < screen_size_x(s); i++) tty_putc(tty, ' '); } @@ -706,9 +712,10 @@ tty_cmd_clearstartofscreen( tty_reset(tty); - tty_cursor(tty, 0, 0, wp->yoff); + tty_cursor(tty, 0, 0, wp->xoff, wp->yoff); tty_region(tty, 0, screen_size_y(s) - 1, wp->yoff); - if (screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) { + if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && + tty_term_has(tty->term, TTYC_EL)) { for (i = 0; i < s->old_cy; i++) { tty_putcode(tty, TTYC_EL); tty_emulate_repeat(tty, TTYC_CUD, TTYC_CUD1, 1); @@ -716,7 +723,7 @@ tty_cmd_clearstartofscreen( } } else { for (j = 0; j < s->old_cy; j++) { - tty_cursor(tty, 0, j, wp->yoff); + tty_cursor(tty, 0, j, wp->xoff, wp->yoff); for (i = 0; i < screen_size_x(s); i++) tty_putc(tty, ' '); } @@ -734,9 +741,10 @@ tty_cmd_clearscreen( tty_reset(tty); - tty_cursor(tty, 0, 0, wp->yoff); + tty_cursor(tty, 0, 0, wp->xoff, wp->yoff); tty_region(tty, 0, screen_size_y(s) - 1, wp->yoff); - if (screen_size_x(s) >= tty->sx && tty_term_has(tty->term, TTYC_EL)) { + if (wp->xoff == 0 && screen_size_x(s) >= tty->sx && + tty_term_has(tty->term, TTYC_EL)) { for (i = 0; i < screen_size_y(s); i++) { tty_putcode(tty, TTYC_EL); if (i != screen_size_y(s) - 1) { @@ -746,7 +754,7 @@ tty_cmd_clearscreen( } } else { for (j = 0; j < screen_size_y(s); j++) { - tty_cursor(tty, 0, j, wp->yoff); + tty_cursor(tty, 0, j, wp->xoff, wp->yoff); for (i = 0; i < screen_size_x(s); i++) tty_putc(tty, ' '); } @@ -763,7 +771,7 @@ tty_cmd_cell(struct tty *tty, struct window_pane *wp, va_list ap) gc = va_arg(ap, struct grid_cell *); gu = va_arg(ap, struct grid_utf8 *); - tty_cursor(tty, s->old_cx, s->old_cy, wp->yoff); + tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff); tty_cell(tty, gc, gu); } @@ -851,13 +859,13 @@ tty_region(struct tty *tty, u_int rupper, u_int rlower, u_int oy) } void -tty_cursor(struct tty *tty, u_int cx, u_int cy, u_int oy) +tty_cursor(struct tty *tty, u_int cx, u_int cy, u_int ox, u_int oy) { - if (cx == 0 && tty->cx != 0 && tty->cy == oy + cy) { + if (ox + cx == 0 && tty->cx != 0 && tty->cy == oy + cy) { tty->cx = 0; tty_putc(tty, '\r'); - } else if (tty->cx != cx || tty->cy != oy + cy) { - tty->cx = cx; + } else if (tty->cx != ox + cx || tty->cy != oy + cy) { + tty->cx = ox + cx; tty->cy = oy + cy; tty_putcode2(tty, TTYC_CUP, tty->cy, tty->cx); } diff --git a/window.c b/window.c index 10637767..55019e13 100644 --- a/window.c +++ b/window.c @@ -1,4 +1,4 @@ -/* $Id: window.c,v 1.70 2009-03-07 09:29:54 nicm Exp $ */ +/* $Id: window.c,v 1.71 2009-04-01 18:21:42 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -212,6 +212,7 @@ window_create1(u_int sx, u_int sy) TAILQ_INIT(&w->panes); w->active = NULL; + w->layout = 0; w->sx = sx; w->sy = sy; @@ -375,6 +376,7 @@ window_update_panes(struct window *w) TAILQ_FOREACH(wp, &w->panes, entry) { if (wp->flags & PANE_HIDDEN) continue; + wp->xoff = 0; wp->yoff = yoff; yoff += wp->sy + 1; } @@ -512,11 +514,12 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) wp->mode = NULL; + wp->xoff = 0; + wp->yoff = 0; + wp->sx = sx; wp->sy = sy; - wp->yoff = 0; - screen_init(&wp->base, sx, sy, hlimit); wp->screen = &wp->base;