From 2083a6ea2050fb211eab3da0df0ff5a40b4973b4 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 20 Apr 2020 14:59:31 +0000 Subject: [PATCH 1/3] Change how sync works to always send the end sequence after all output is done when we are returning to the event loop (since we always move the cursor at that point). Also a man fix from jmc. --- screen-redraw.c | 2 -- screen-write.c | 9 --------- server-client.c | 12 +++++++++++- tmux.1 | 2 +- tmux.h | 1 - tty-keys.c | 2 +- tty.c | 26 ++++++++++++++++---------- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/screen-redraw.c b/screen-redraw.c index c9e70590..8e74fe97 100644 --- a/screen-redraw.c +++ b/screen-redraw.c @@ -458,7 +458,6 @@ screen_redraw_screen(struct client *c) } tty_reset(&c->tty); - tty_sync_end(&c->tty); } /* Redraw a single pane. */ @@ -476,7 +475,6 @@ screen_redraw_pane(struct client *c, struct window_pane *wp) screen_redraw_draw_pane(&ctx, wp); tty_reset(&c->tty); - tty_sync_end(&c->tty); } /* Draw a border cell. */ diff --git a/screen-write.c b/screen-write.c index 55d399a7..042f2fa8 100644 --- a/screen-write.c +++ b/screen-write.c @@ -119,7 +119,6 @@ screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx, ttyctx->orupper = s->rupper; if (sync && !ctx->sync && ttyctx->wp != NULL) { - log_debug("%s: starting sync", __func__); tty_write(tty_cmd_syncstart, ttyctx); ctx->sync = 1; } @@ -184,8 +183,6 @@ screen_write_start(struct screen_write_ctx *ctx, struct window_pane *wp, void screen_write_stop(struct screen_write_ctx *ctx) { - struct tty_ctx ttyctx; - screen_write_collect_end(ctx); screen_write_collect_flush(ctx, 0, __func__); @@ -196,12 +193,6 @@ screen_write_stop(struct screen_write_ctx *ctx) ctx->wp->skipped += ctx->skipped; } - if (ctx->sync) { - screen_write_initctx(ctx, &ttyctx, 0); - tty_write(tty_cmd_syncend, &ttyctx); - log_debug("%s: ending sync", __func__); - } - free(ctx->item); } diff --git a/server-client.c b/server-client.c index cd850593..8da55ac0 100644 --- a/server-client.c +++ b/server-client.c @@ -1541,7 +1541,7 @@ server_client_reset_state(struct client *c) struct window_pane *wp = w->active, *loop; struct screen *s; struct options *oo = c->session->options; - int mode, cursor; + int mode, cursor, flags; u_int cx = 0, cy = 0, ox, oy, sx, sy; if (c->flags & (CLIENT_CONTROL|CLIENT_SUSPENDED)) @@ -1606,6 +1606,16 @@ server_client_reset_state(struct client *c) /* Set the terminal mode and reset attributes. */ tty_update_mode(&c->tty, mode, s); tty_reset(&c->tty); + + /* + * All writing must be done, send a sync end (if it was started). It + * may have been started by redrawing so needs to go out even if the + * block flag is set. + */ + flags = (c->tty.flags & TTY_BLOCK); + c->tty.flags &= ~TTY_BLOCK; + tty_sync_end(&c->tty); + c->tty.flags |= flags; } /* Repeat time callback. */ diff --git a/tmux.1 b/tmux.1 index 648aed4d..e54817d5 100644 --- a/tmux.1 +++ b/tmux.1 @@ -5534,7 +5534,7 @@ The server crashed or otherwise exited without telling the client the reason. .Sh TERMINFO EXTENSIONS .Nm understands some unofficial extensions to -.Xr terminfo 5. +.Xr terminfo 5 . It is not normally necessary to set these manually, instead the .Ic terminal-features option should be used. diff --git a/tmux.h b/tmux.h index 3853b09f..5d7dbba7 100644 --- a/tmux.h +++ b/tmux.h @@ -1992,7 +1992,6 @@ void tty_cmd_reverseindex(struct tty *, const struct tty_ctx *); void tty_cmd_setselection(struct tty *, const struct tty_ctx *); void tty_cmd_rawstring(struct tty *, const struct tty_ctx *); void tty_cmd_syncstart(struct tty *, const struct tty_ctx *); -void tty_cmd_syncend(struct tty *, const struct tty_ctx *); /* tty-term.c */ extern struct tty_terms tty_terms; diff --git a/tty-keys.c b/tty-keys.c index 14952c05..aa775d69 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -1150,7 +1150,7 @@ tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len, "cstyle," "margins," "sync," - "title,", + "title", ","); } else if (strncmp(tmp, "TMUX ", 5) == 0) { tty_add_features(&c->term_features, diff --git a/tty.c b/tty.c index e1c629ec..0214524c 100644 --- a/tty.c +++ b/tty.c @@ -1427,18 +1427,30 @@ tty_draw_line(struct tty *tty, struct window_pane *wp, struct screen *s, void tty_sync_start(struct tty *tty) { - if ((~tty->flags & TTY_SYNCING) && tty_term_has(tty->term, TTYC_SYNC)) { + if (tty->flags & TTY_BLOCK) + return; + if (tty->flags & TTY_SYNCING) + return; + tty->flags |= TTY_SYNCING; + + if (tty_term_has(tty->term, TTYC_SYNC)) { + log_debug("%s sync start", tty->client->name); tty_putcode1(tty, TTYC_SYNC, 1); - tty->flags |= TTY_SYNCING; } } void tty_sync_end(struct tty *tty) { - if ((tty->flags & TTY_SYNCING) && tty_term_has(tty->term, TTYC_SYNC)) { + if (tty->flags & TTY_BLOCK) + return; + if (~tty->flags & TTY_SYNCING) + return; + tty->flags &= ~TTY_SYNCING; + + if (tty_term_has(tty->term, TTYC_SYNC)) { + log_debug("%s sync end", tty->client->name); tty_putcode1(tty, TTYC_SYNC, 2); - tty->flags &= ~TTY_SYNCING; } } @@ -1952,12 +1964,6 @@ tty_cmd_syncstart(struct tty *tty, __unused const struct tty_ctx *ctx) tty_sync_start(tty); } -void -tty_cmd_syncend(struct tty *tty, __unused const struct tty_ctx *ctx) -{ - tty_sync_end(tty); -} - static void tty_cell(struct tty *tty, const struct grid_cell *gc, struct window_pane *wp) { From 117ec1b2e603c2692ab564947b099ec79a20150f Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 20 Apr 2020 15:37:32 +0000 Subject: [PATCH 2/3] Apply terminal-overrides after terminal detection, it always takes precedence. --- tmux.h | 3 ++- tty-features.c | 7 +++++-- tty-term.c | 41 ++++++++++++++++++++++++++--------------- tty.c | 3 ++- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/tmux.h b/tmux.h index 5d7dbba7..3fe32b50 100644 --- a/tmux.h +++ b/tmux.h @@ -1997,6 +1997,7 @@ void tty_cmd_syncstart(struct tty *, const struct tty_ctx *); extern struct tty_terms tty_terms; u_int tty_term_ncodes(void); void tty_term_apply(struct tty_term *, const char *, int); +void tty_term_apply_overrides(struct tty_term *); struct tty_term *tty_term_create(struct tty *, char *, int *, int, char **); void tty_term_free(struct tty_term *); int tty_term_has(struct tty_term *, enum tty_code_code); @@ -2017,7 +2018,7 @@ const char *tty_term_describe(struct tty_term *, enum tty_code_code); /* tty-features.c */ void tty_add_features(int *, const char *, const char *); const char *tty_get_features(int); -void tty_apply_features(struct tty_term *, int); +int tty_apply_features(struct tty_term *, int); /* tty-acs.c */ int tty_acs_needed(struct tty *); diff --git a/tty-features.c b/tty-features.c index b6934673..3b12b068 100644 --- a/tty-features.c +++ b/tty-features.c @@ -232,7 +232,7 @@ tty_get_features(int feat) return (s); } -void +int tty_apply_features(struct tty_term *term, int feat) { const struct tty_feature *tf; @@ -240,7 +240,7 @@ tty_apply_features(struct tty_term *term, int feat) u_int i; if (feat == 0) - return; + return (0); log_debug("applying terminal features: %s", tty_get_features(feat)); for (i = 0; i < nitems(tty_features); i++) { @@ -259,5 +259,8 @@ tty_apply_features(struct tty_term *term, int feat) } term->flags |= tf->flags; } + if ((term->features | feat) == term->features) + return (0); term->features |= feat; + return (1); } diff --git a/tty-term.c b/tty-term.c index e1b026ea..f4a18b63 100644 --- a/tty-term.c +++ b/tty-term.c @@ -410,6 +410,30 @@ tty_term_apply(struct tty_term *term, const char *capabilities, int quiet) } } +void +tty_term_apply_overrides(struct tty_term *term) +{ + struct options_entry *o; + struct options_array_item *a; + union options_value *ov; + const char *s; + size_t offset; + char *first; + + o = options_get_only(global_options, "terminal-overrides"); + a = options_array_first(o); + while (a != NULL) { + ov = options_array_item_value(a); + s = ov->string; + + offset = 0; + first = tty_term_override_next(s, &offset); + if (first != NULL && fnmatch(first, term->name, 0) == 0) + tty_term_apply(term, s + offset, 0); + a = options_array_next(a); + } +} + struct tty_term * tty_term_create(struct tty *tty, char *name, int *feat, int fd, char **cause) { @@ -501,20 +525,6 @@ tty_term_create(struct tty *tty, char *name, int *feat, int fd, char **cause) a = options_array_next(a); } - /* Apply terminal overrides. */ - o = options_get_only(global_options, "terminal-overrides"); - a = options_array_first(o); - while (a != NULL) { - ov = options_array_item_value(a); - s = ov->string; - - offset = 0; - first = tty_term_override_next(s, &offset); - if (first != NULL && fnmatch(first, term->name, 0) == 0) - tty_term_apply(term, s + offset, 0); - a = options_array_next(a); - } - /* Delete curses data. */ del_curterm(cur_term); @@ -544,8 +554,9 @@ tty_term_create(struct tty *tty, char *name, int *feat, int fd, char **cause) if (tty_term_flag(term, TTYC_XT)) tty_add_features(feat, "title", ":,"); - /* Apply the features. */ + /* Apply the features and overrides. */ tty_apply_features(term, *feat); + tty_term_apply_overrides(term); /* * Terminals without xenl (eat newline glitch) wrap at at $COLUMNS - 1 diff --git a/tty.c b/tty.c index 0214524c..556931da 100644 --- a/tty.c +++ b/tty.c @@ -469,7 +469,8 @@ tty_update_features(struct tty *tty) { struct client *c = tty->client; - tty_apply_features(tty->term, c->term_features); + if (tty_apply_features(tty->term, c->term_features)) + tty_term_apply_overrides(tty->term); if (tty_use_margin(tty)) tty_puts(tty, "\033[?69h"); /* DECLRMM */ From 4a5182e6658907f876581fbcf4c774bf86d0d953 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 20 Apr 2020 15:49:05 +0000 Subject: [PATCH 3/3] Always start sync for output in panes that are not the active pane. --- screen-write.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/screen-write.c b/screen-write.c index 042f2fa8..98a4a701 100644 --- a/screen-write.c +++ b/screen-write.c @@ -118,7 +118,9 @@ screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx, ttyctx->orlower = s->rlower; ttyctx->orupper = s->rupper; - if (sync && !ctx->sync && ttyctx->wp != NULL) { + if (ctx->wp != NULL && + !ctx->sync && + (sync || ctx->wp != ctx->wp->window->active)) { tty_write(tty_cmd_syncstart, ttyctx); ctx->sync = 1; }