diff options
author | Thomas Adam <thomas@xteddy.org> | 2020-04-16 18:01:32 +0100 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2020-04-16 18:01:32 +0100 |
commit | 21eb2ba4191b797b9f980e207756b21eb09da948 (patch) | |
tree | c2944d48b8af08e0ecf92d2891175a7c111e0727 | |
parent | 5e38d262579662f33570c520b6661e15c215f702 (diff) | |
parent | 2e347d6a384a5cfa9e18058393043e623a10c584 (diff) | |
download | rtmux-21eb2ba4191b797b9f980e207756b21eb09da948.tar.gz rtmux-21eb2ba4191b797b9f980e207756b21eb09da948.tar.bz2 rtmux-21eb2ba4191b797b9f980e207756b21eb09da948.zip |
Merge branch 'obsd-master'
-rw-r--r-- | screen-write.c | 100 | ||||
-rw-r--r-- | tmux.h | 2 | ||||
-rw-r--r-- | tty-keys.c | 32 | ||||
-rw-r--r-- | tty.c | 5 |
4 files changed, 76 insertions, 63 deletions
diff --git a/screen-write.c b/screen-write.c index 3e7fa66b..7a06b67c 100644 --- a/screen-write.c +++ b/screen-write.c @@ -23,8 +23,6 @@ #include "tmux.h" -static void screen_write_initctx(struct screen_write_ctx *, - struct tty_ctx *); static void screen_write_collect_clear(struct screen_write_ctx *, u_int, u_int); static void screen_write_collect_scroll(struct screen_write_ctx *); @@ -95,13 +93,36 @@ screen_write_set_cursor(struct screen_write_ctx *ctx, int cx, int cy) evtimer_add(&w->offset_timer, &tv); } +/* Set up context for TTY command. */ +static void +screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx, + int sync) +{ + struct screen *s = ctx->s; + + memset(ttyctx, 0, sizeof *ttyctx); + + ttyctx->wp = ctx->wp; + + ttyctx->ocx = s->cx; + ttyctx->ocy = s->cy; + + ttyctx->orlower = s->rlower; + 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; + } +} + /* Initialize writing with a window. */ void screen_write_start(struct screen_write_ctx *ctx, struct window_pane *wp, struct screen *s) { - struct tty_ctx ttyctx; - u_int y; + u_int y; memset(ctx, 0, sizeof *ctx); @@ -130,9 +151,6 @@ screen_write_start(struct screen_write_ctx *ctx, struct window_pane *wp, screen_size_y(ctx->s)); } } - - screen_write_initctx(ctx, &ttyctx); - tty_write(tty_cmd_syncstart, &ttyctx); } /* Finish writing. */ @@ -147,8 +165,11 @@ screen_write_stop(struct screen_write_ctx *ctx) log_debug("%s: %u cells (%u written, %u skipped)", __func__, ctx->cells, ctx->written, ctx->skipped); - screen_write_initctx(ctx, &ttyctx); - tty_write(tty_cmd_syncend, &ttyctx); + if (ctx->sync) { + screen_write_initctx(ctx, &ttyctx, 0); + tty_write(tty_cmd_syncend, &ttyctx); + log_debug("%s: ending sync", __func__); + } free(ctx->item); free(ctx->list); /* flush will have emptied */ @@ -557,23 +578,6 @@ screen_write_preview(struct screen_write_ctx *ctx, struct screen *src, u_int nx, } } -/* Set up context for TTY command. */ -static void -screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx) -{ - struct screen *s = ctx->s; - - memset(ttyctx, 0, sizeof *ttyctx); - - ttyctx->wp = ctx->wp; - - ttyctx->ocx = s->cx; - ttyctx->ocy = s->cy; - - ttyctx->orlower = s->rlower; - ttyctx->orupper = s->rupper; -} - /* Set a mode. */ void screen_write_mode_set(struct screen_write_ctx *ctx, int mode) @@ -732,7 +736,7 @@ screen_write_alignmenttest(struct screen_write_ctx *ctx) s->rupper = 0; s->rlower = screen_size_y(s) - 1; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); screen_write_collect_clear(ctx, 0, screen_size_y(s) - 1); tty_write(tty_cmd_alignmenttest, &ttyctx); @@ -756,7 +760,7 @@ screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg) if (s->cx > screen_size_x(s) - 1) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); ttyctx.bg = bg; grid_view_insert_cells(s->grid, s->cx, s->cy, nx, bg); @@ -784,7 +788,7 @@ screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg) if (s->cx > screen_size_x(s) - 1) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); ttyctx.bg = bg; grid_view_delete_cells(s->grid, s->cx, s->cy, nx, bg); @@ -812,7 +816,7 @@ screen_write_clearcharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg) if (s->cx > screen_size_x(s) - 1) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); ttyctx.bg = bg; grid_view_clear(s->grid, s->cx, s->cy, nx, 1, bg); @@ -839,7 +843,7 @@ screen_write_insertline(struct screen_write_ctx *ctx, u_int ny, u_int bg) if (ny == 0) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.bg = bg; grid_view_insert_lines(gd, s->cy, ny, bg); @@ -855,7 +859,7 @@ screen_write_insertline(struct screen_write_ctx *ctx, u_int ny, u_int bg) if (ny == 0) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.bg = bg; if (s->cy < s->rupper || s->cy > s->rlower) @@ -885,7 +889,7 @@ screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny, u_int bg) if (ny == 0) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.bg = bg; grid_view_delete_lines(gd, s->cy, ny, bg); @@ -901,7 +905,7 @@ screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny, u_int bg) if (ny == 0) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.bg = bg; if (s->cy < s->rupper || s->cy > s->rlower) @@ -927,7 +931,7 @@ screen_write_clearline(struct screen_write_ctx *ctx, u_int bg) if (gl->cellsize == 0 && COLOUR_DEFAULT(bg)) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.bg = bg; grid_view_clear(s->grid, 0, s->cy, sx, 1, bg); @@ -950,7 +954,7 @@ screen_write_clearendofline(struct screen_write_ctx *ctx, u_int bg) if (s->cx > sx - 1 || (s->cx >= gl->cellsize && COLOUR_DEFAULT(bg))) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.bg = bg; grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1, bg); @@ -969,7 +973,7 @@ screen_write_clearstartofline(struct screen_write_ctx *ctx, u_int bg) struct tty_ctx ttyctx; u_int sx = screen_size_x(s); - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.bg = bg; if (s->cx > sx - 1) @@ -1012,7 +1016,7 @@ screen_write_reverseindex(struct screen_write_ctx *ctx, u_int bg) struct screen *s = ctx->s; struct tty_ctx ttyctx; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.bg = bg; if (s->cy == s->rupper) @@ -1111,7 +1115,7 @@ screen_write_scrolldown(struct screen_write_ctx *ctx, u_int lines, u_int bg) struct tty_ctx ttyctx; u_int i; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.bg = bg; if (lines == 0) @@ -1143,7 +1147,7 @@ screen_write_clearendofscreen(struct screen_write_ctx *ctx, u_int bg) struct tty_ctx ttyctx; u_int sx = screen_size_x(s), sy = screen_size_y(s); - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.bg = bg; /* Scroll into history if it is enabled and clearing entire screen. */ @@ -1168,7 +1172,7 @@ screen_write_clearstartofscreen(struct screen_write_ctx *ctx, u_int bg) struct tty_ctx ttyctx; u_int sx = screen_size_x(s); - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.bg = bg; if (s->cy > 0) @@ -1191,7 +1195,7 @@ screen_write_clearscreen(struct screen_write_ctx *ctx, u_int bg) struct tty_ctx ttyctx; u_int sx = screen_size_x(s), sy = screen_size_y(s); - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.bg = bg; /* Scroll into history if it is enabled. */ @@ -1267,7 +1271,7 @@ screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only) if (ctx->scrolled > s->rlower - s->rupper + 1) ctx->scrolled = s->rlower - s->rupper + 1; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 1); ttyctx.num = ctx->scrolled; ttyctx.bg = ctx->bg; tty_write(tty_cmd_scrollup, &ttyctx); @@ -1282,7 +1286,7 @@ screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only) for (y = 0; y < screen_size_y(s); y++) { TAILQ_FOREACH_SAFE(ci, &ctx->list[y].items, entry, tmp) { screen_write_set_cursor(ctx, ci->x, y); - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); ttyctx.cell = &ci->gc; ttyctx.wrapped = ci->wrapped; ttyctx.ptr = ci->data; @@ -1425,7 +1429,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc) if ((gc = screen_write_combine(ctx, &gc->data, &xx)) != 0) { cx = s->cx; cy = s->cy; screen_write_set_cursor(ctx, xx, s->cy); - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); ttyctx.cell = gc; tty_write(tty_cmd_cell, &ttyctx); s->cx = cx; s->cy = cy; @@ -1459,7 +1463,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc) /* Sanity check cursor position. */ if (s->cx > sx - width || s->cy > sy - 1) return; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); /* Handle overwriting of UTF-8 characters. */ gl = grid_get_line(s->grid, s->grid->hsize + s->cy); @@ -1662,7 +1666,7 @@ screen_write_setselection(struct screen_write_ctx *ctx, u_char *str, u_int len) { struct tty_ctx ttyctx; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); ttyctx.ptr = str; ttyctx.num = len; @@ -1675,7 +1679,7 @@ screen_write_rawstring(struct screen_write_ctx *ctx, u_char *str, u_int len) { struct tty_ctx ttyctx; - screen_write_initctx(ctx, &ttyctx); + screen_write_initctx(ctx, &ttyctx, 0); ttyctx.ptr = str; ttyctx.num = len; @@ -779,6 +779,7 @@ struct screen_write_collect_line; struct screen_write_ctx { struct window_pane *wp; struct screen *s; + int sync; struct screen_write_collect_item *item; struct screen_write_collect_line *list; @@ -1263,6 +1264,7 @@ struct tty { struct event key_timer; struct tty_key *key_tree; }; +#define tty_term_flags(tty) (tty->term->flags|tty->term_flags) /* TTY command context. */ struct tty_ctx { @@ -1007,8 +1007,8 @@ tty_keys_clipboard(__unused struct tty *tty, const char *buf, size_t len, } /* - * Handle device attributes input. Returns 0 for success, -1 for failure, 1 for - * partial. + * Handle secondary device attributes input. Returns 0 for success, -1 for + * failure, 1 for partial. */ static int tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, @@ -1032,7 +1032,7 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, return (-1); if (len == 2) return (1); - if (buf[2] != '?') + if (buf[2] != '>') return (-1); if (len == 3) return (1); @@ -1048,7 +1048,7 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, tmp[i] = '\0'; *size = 4 + i; - /* Convert version numbers. */ + /* Convert all arguments to numbers. */ cp = tmp; while ((next = strsep(&cp, ";")) != NULL) { p[n] = strtoul(next, &endptr, 10); @@ -1059,13 +1059,20 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, /* Set terminal flags. */ switch (p[0]) { - case 64: /* VT420 */ + case 41: /* VT420 */ flags |= (TERM_DECFRA|TERM_DECSLRM); break; + case 'M': /* mintty */ + flags |= (TERM_256COLOURS|TERM_RGBCOLOURS); + break; + case 'T': /* tmux - if newer will have the DSR as well */ + flags |= (TERM_UTF8|TERM_256COLOURS); + break; + case 'U': /* rxvt-unicode */ + flags |= (TERM_UTF8); + break; } - for (i = 1; i < n; i++) - log_debug("%s: DA feature: %d", c->name, p[i]); - log_debug("%s: received DA %.*s", c->name, (int)*size, buf); + log_debug("%s: received secondary DA %.*s", c->name, (int)*size, buf); tty_set_flags(tty, flags); tty->flags |= TTY_HAVEDA; @@ -1116,10 +1123,11 @@ tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len, *size = 3 + i; /* Set terminal flags. */ - if (strncmp(tmp, "ITERM2 ", 7) == 0) - flags |= (TERM_DECSLRM|TERM_256COLOURS|TERM_RGBCOLOURS|TERM_SYNC); - if (strncmp(tmp, "TMUX ", 5) == 0) - flags |= (TERM_256COLOURS|TERM_RGBCOLOURS); + if (strncmp(tmp, "ITERM2 ", 7) == 0) { + flags |= (TERM_UTF8|TERM_DECSLRM|TERM_SYNC|TERM_256COLOURS| + TERM_RGBCOLOURS); + } else if (strncmp(tmp, "TMUX ", 5) == 0) + flags |= (TERM_UTF8|TERM_256COLOURS|TERM_RGBCOLOURS); log_debug("%s: received DSR %.*s", c->name, (int)*size, buf); tty_set_flags(tty, flags); @@ -364,7 +364,7 @@ tty_send_requests(struct tty *tty) if (tty_term_flag(tty->term, TTYC_XT)) { if (~tty->flags & TTY_HAVEDA) - tty_puts(tty, "\033[c"); + tty_puts(tty, "\033[>c"); if (~tty->flags & TTY_HAVEDSR) tty_puts(tty, "\033[1337n"); } else @@ -1175,8 +1175,7 @@ tty_clear_area(struct tty *tty, struct window_pane *wp, u_int py, u_int ny, * background colour isn't default (because it doesn't work * after SGR 0). */ - if ((tty_get_flags(tty) & TERM_DECFRA) && - !COLOUR_DEFAULT(bg)) { + if ((tty_get_flags(tty) & TERM_DECFRA) && !COLOUR_DEFAULT(bg)) { xsnprintf(tmp, sizeof tmp, "\033[32;%u;%u;%u;%u$x", py + 1, px + 1, py + ny, px + nx); tty_puts(tty, tmp); |