1 /* $OpenBSD: window.c,v 1.279 2022/03/16 17:00:17 nicm Exp $ */ 2 3 /* 4 * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <sys/types.h> 20 #include <sys/ioctl.h> 21 22 #include <ctype.h> 23 #include <errno.h> 24 #include <fcntl.h> 25 #include <fnmatch.h> 26 #include <regex.h> 27 #include <signal.h> 28 #include <stdint.h> 29 #include <stdlib.h> 30 #include <string.h> 31 #include <time.h> 32 #include <unistd.h> 33 #include <util.h> 34 #include <vis.h> 35 36 #include "tmux.h" 37 38 /* 39 * Each window is attached to a number of panes, each of which is a pty. This 40 * file contains code to handle them. 41 * 42 * A pane has two buffers attached, these are filled and emptied by the main 43 * server poll loop. Output data is received from pty's in screen format, 44 * translated and returned as a series of escape sequences and strings via 45 * input_parse (in input.c). Input data is received as key codes and written 46 * directly via input_key. 47 * 48 * Each pane also has a "virtual" screen (screen.c) which contains the current 49 * state and is redisplayed when the window is reattached to a client. 50 * 51 * Windows are stored directly on a global array and wrapped in any number of 52 * winlink structs to be linked onto local session RB trees. A reference count 53 * is maintained and a window removed from the global list and destroyed when 54 * it reaches zero. 55 */ 56 57 /* Global window list. */ 58 struct windows windows; 59 60 /* Global panes tree. */ 61 struct window_pane_tree all_window_panes; 62 static u_int next_window_pane_id; 63 static u_int next_window_id; 64 static u_int next_active_point; 65 66 struct window_pane_input_data { 67 struct cmdq_item *item; 68 u_int wp; 69 }; 70 71 static struct window_pane *window_pane_create(struct window *, u_int, u_int, 72 u_int); 73 static void window_pane_destroy(struct window_pane *); 74 75 RB_GENERATE(windows, window, entry, window_cmp); 76 RB_GENERATE(winlinks, winlink, entry, winlink_cmp); 77 RB_GENERATE(window_pane_tree, window_pane, tree_entry, window_pane_cmp); 78 79 int 80 window_cmp(struct window *w1, struct window *w2) 81 { 82 return (w1->id - w2->id); 83 } 84 85 int 86 winlink_cmp(struct winlink *wl1, struct winlink *wl2) 87 { 88 return (wl1->idx - wl2->idx); 89 } 90 91 int 92 window_pane_cmp(struct window_pane *wp1, struct window_pane *wp2) 93 { 94 return (wp1->id - wp2->id); 95 } 96 97 struct winlink * 98 winlink_find_by_window(struct winlinks *wwl, struct window *w) 99 { 100 struct winlink *wl; 101 102 RB_FOREACH(wl, winlinks, wwl) { 103 if (wl->window == w) 104 return (wl); 105 } 106 107 return (NULL); 108 } 109 110 struct winlink * 111 winlink_find_by_index(struct winlinks *wwl, int idx) 112 { 113 struct winlink wl; 114 115 if (idx < 0) 116 fatalx("bad index"); 117 118 wl.idx = idx; 119 return (RB_FIND(winlinks, wwl, &wl)); 120 } 121 122 struct winlink * 123 winlink_find_by_window_id(struct winlinks *wwl, u_int id) 124 { 125 struct winlink *wl; 126 127 RB_FOREACH(wl, winlinks, wwl) { 128 if (wl->window->id == id) 129 return (wl); 130 } 131 return (NULL); 132 } 133 134 static int 135 winlink_next_index(struct winlinks *wwl, int idx) 136 { 137 int i; 138 139 i = idx; 140 do { 141 if (winlink_find_by_index(wwl, i) == NULL) 142 return (i); 143 if (i == INT_MAX) 144 i = 0; 145 else 146 i++; 147 } while (i != idx); 148 return (-1); 149 } 150 151 u_int 152 winlink_count(struct winlinks *wwl) 153 { 154 struct winlink *wl; 155 u_int n; 156 157 n = 0; 158 RB_FOREACH(wl, winlinks, wwl) 159 n++; 160 161 return (n); 162 } 163 164 struct winlink * 165 winlink_add(struct winlinks *wwl, int idx) 166 { 167 struct winlink *wl; 168 169 if (idx < 0) { 170 if ((idx = winlink_next_index(wwl, -idx - 1)) == -1) 171 return (NULL); 172 } else if (winlink_find_by_index(wwl, idx) != NULL) 173 return (NULL); 174 175 wl = xcalloc(1, sizeof *wl); 176 wl->idx = idx; 177 RB_INSERT(winlinks, wwl, wl); 178 179 return (wl); 180 } 181 182 void 183 winlink_set_window(struct winlink *wl, struct window *w) 184 { 185 if (wl->window != NULL) { 186 TAILQ_REMOVE(&wl->window->winlinks, wl, wentry); 187 window_remove_ref(wl->window, __func__); 188 } 189 TAILQ_INSERT_TAIL(&w->winlinks, wl, wentry); 190 wl->window = w; 191 window_add_ref(w, __func__); 192 } 193 194 void 195 winlink_remove(struct winlinks *wwl, struct winlink *wl) 196 { 197 struct window *w = wl->window; 198 199 if (w != NULL) { 200 TAILQ_REMOVE(&w->winlinks, wl, wentry); 201 window_remove_ref(w, __func__); 202 } 203 204 RB_REMOVE(winlinks, wwl, wl); 205 free(wl); 206 } 207 208 struct winlink * 209 winlink_next(struct winlink *wl) 210 { 211 return (RB_NEXT(winlinks, wwl, wl)); 212 } 213 214 struct winlink * 215 winlink_previous(struct winlink *wl) 216 { 217 return (RB_PREV(winlinks, wwl, wl)); 218 } 219 220 struct winlink * 221 winlink_next_by_number(struct winlink *wl, struct session *s, int n) 222 { 223 for (; n > 0; n--) { 224 if ((wl = RB_NEXT(winlinks, wwl, wl)) == NULL) 225 wl = RB_MIN(winlinks, &s->windows); 226 } 227 228 return (wl); 229 } 230 231 struct winlink * 232 winlink_previous_by_number(struct winlink *wl, struct session *s, int n) 233 { 234 for (; n > 0; n--) { 235 if ((wl = RB_PREV(winlinks, wwl, wl)) == NULL) 236 wl = RB_MAX(winlinks, &s->windows); 237 } 238 239 return (wl); 240 } 241 242 void 243 winlink_stack_push(struct winlink_stack *stack, struct winlink *wl) 244 { 245 if (wl == NULL) 246 return; 247 248 winlink_stack_remove(stack, wl); 249 TAILQ_INSERT_HEAD(stack, wl, sentry); 250 } 251 252 void 253 winlink_stack_remove(struct winlink_stack *stack, struct winlink *wl) 254 { 255 struct winlink *wl2; 256 257 if (wl == NULL) 258 return; 259 260 TAILQ_FOREACH(wl2, stack, sentry) { 261 if (wl2 == wl) { 262 TAILQ_REMOVE(stack, wl, sentry); 263 return; 264 } 265 } 266 } 267 268 struct window * 269 window_find_by_id_str(const char *s) 270 { 271 const char *errstr; 272 u_int id; 273 274 if (*s != '@') 275 return (NULL); 276 277 id = strtonum(s + 1, 0, UINT_MAX, &errstr); 278 if (errstr != NULL) 279 return (NULL); 280 return (window_find_by_id(id)); 281 } 282 283 struct window * 284 window_find_by_id(u_int id) 285 { 286 struct window w; 287 288 w.id = id; 289 return (RB_FIND(windows, &windows, &w)); 290 } 291 292 void 293 window_update_activity(struct window *w) 294 { 295 gettimeofday(&w->activity_time, NULL); 296 alerts_queue(w, WINDOW_ACTIVITY); 297 } 298 299 struct window * 300 window_create(u_int sx, u_int sy, u_int xpixel, u_int ypixel) 301 { 302 struct window *w; 303 304 if (xpixel == 0) 305 xpixel = DEFAULT_XPIXEL; 306 if (ypixel == 0) 307 ypixel = DEFAULT_YPIXEL; 308 309 w = xcalloc(1, sizeof *w); 310 w->name = xstrdup(""); 311 w->flags = 0; 312 313 TAILQ_INIT(&w->panes); 314 w->active = NULL; 315 316 w->lastlayout = -1; 317 w->layout_root = NULL; 318 319 w->sx = sx; 320 w->sy = sy; 321 w->manual_sx = sx; 322 w->manual_sy = sy; 323 w->xpixel = xpixel; 324 w->ypixel = ypixel; 325 326 w->options = options_create(global_w_options); 327 328 w->references = 0; 329 TAILQ_INIT(&w->winlinks); 330 331 w->id = next_window_id++; 332 RB_INSERT(windows, &windows, w); 333 334 window_set_fill_character(w); 335 window_update_activity(w); 336 337 log_debug("%s: @%u create %ux%u (%ux%u)", __func__, w->id, sx, sy, 338 w->xpixel, w->ypixel); 339 return (w); 340 } 341 342 static void 343 window_destroy(struct window *w) 344 { 345 log_debug("window @%u destroyed (%d references)", w->id, w->references); 346 347 RB_REMOVE(windows, &windows, w); 348 349 if (w->layout_root != NULL) 350 layout_free_cell(w->layout_root); 351 if (w->saved_layout_root != NULL) 352 layout_free_cell(w->saved_layout_root); 353 free(w->old_layout); 354 355 window_destroy_panes(w); 356 357 if (event_initialized(&w->name_event)) 358 evtimer_del(&w->name_event); 359 360 if (event_initialized(&w->alerts_timer)) 361 evtimer_del(&w->alerts_timer); 362 if (event_initialized(&w->offset_timer)) 363 event_del(&w->offset_timer); 364 365 options_free(w->options); 366 free(w->fill_character); 367 368 free(w->name); 369 free(w); 370 } 371 372 int 373 window_pane_destroy_ready(struct window_pane *wp) 374 { 375 int n; 376 377 if (wp->pipe_fd != -1) { 378 if (EVBUFFER_LENGTH(wp->pipe_event->output) != 0) 379 return (0); 380 if (ioctl(wp->fd, FIONREAD, &n) != -1 && n > 0) 381 return (0); 382 } 383 384 if (~wp->flags & PANE_EXITED) 385 return (0); 386 return (1); 387 } 388 389 void 390 window_add_ref(struct window *w, const char *from) 391 { 392 w->references++; 393 log_debug("%s: @%u %s, now %d", __func__, w->id, from, w->references); 394 } 395 396 void 397 window_remove_ref(struct window *w, const char *from) 398 { 399 w->references--; 400 log_debug("%s: @%u %s, now %d", __func__, w->id, from, w->references); 401 402 if (w->references == 0) 403 window_destroy(w); 404 } 405 406 void 407 window_set_name(struct window *w, const char *new_name) 408 { 409 free(w->name); 410 utf8_stravis(&w->name, new_name, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL); 411 notify_window("window-renamed", w); 412 } 413 414 void 415 window_resize(struct window *w, u_int sx, u_int sy, int xpixel, int ypixel) 416 { 417 if (xpixel == 0) 418 xpixel = DEFAULT_XPIXEL; 419 if (ypixel == 0) 420 ypixel = DEFAULT_YPIXEL; 421 422 log_debug("%s: @%u resize %ux%u (%ux%u)", __func__, w->id, sx, sy, 423 xpixel == -1 ? w->xpixel : (u_int)xpixel, 424 ypixel == -1 ? w->ypixel : (u_int)ypixel); 425 w->sx = sx; 426 w->sy = sy; 427 if (xpixel != -1) 428 w->xpixel = xpixel; 429 if (ypixel != -1) 430 w->ypixel = ypixel; 431 } 432 433 void 434 window_pane_send_resize(struct window_pane *wp, u_int sx, u_int sy) 435 { 436 struct window *w = wp->window; 437 struct winsize ws; 438 439 if (wp->fd == -1) 440 return; 441 442 log_debug("%s: %%%u resize to %u,%u", __func__, wp->id, sx, sy); 443 444 memset(&ws, 0, sizeof ws); 445 ws.ws_col = sx; 446 ws.ws_row = sy; 447 ws.ws_xpixel = w->xpixel * ws.ws_col; 448 ws.ws_ypixel = w->ypixel * ws.ws_row; 449 if (ioctl(wp->fd, TIOCSWINSZ, &ws) == -1) 450 fatal("ioctl failed"); 451 } 452 453 int 454 window_has_pane(struct window *w, struct window_pane *wp) 455 { 456 struct window_pane *wp1; 457 458 TAILQ_FOREACH(wp1, &w->panes, entry) { 459 if (wp1 == wp) 460 return (1); 461 } 462 return (0); 463 } 464 465 void 466 window_update_focus(struct window *w) 467 { 468 if (w != NULL) { 469 log_debug("%s: @%u", __func__, w->id); 470 window_pane_update_focus(w->active); 471 } 472 } 473 474 void 475 window_pane_update_focus(struct window_pane *wp) 476 { 477 struct client *c; 478 int focused = 0; 479 480 if (wp != NULL) { 481 if (wp != wp->window->active) 482 focused = 0; 483 else { 484 TAILQ_FOREACH(c, &clients, entry) { 485 if (c->session != NULL && 486 c->session->attached != 0 && 487 (c->flags & CLIENT_FOCUSED) && 488 c->session->curw->window == wp->window) { 489 focused = 1; 490 break; 491 } 492 } 493 } 494 if (!focused && (wp->flags & PANE_FOCUSED)) { 495 log_debug("%s: %%%u focus out", __func__, wp->id); 496 if (wp->base.mode & MODE_FOCUSON) 497 bufferevent_write(wp->event, "\033[O", 3); 498 notify_pane("pane-focus-out", wp); 499 wp->flags &= ~PANE_FOCUSED; 500 } else if (focused && (~wp->flags & PANE_FOCUSED)) { 501 log_debug("%s: %%%u focus in", __func__, wp->id); 502 if (wp->base.mode & MODE_FOCUSON) 503 bufferevent_write(wp->event, "\033[I", 3); 504 notify_pane("pane-focus-in", wp); 505 wp->flags |= PANE_FOCUSED; 506 } else 507 log_debug("%s: %%%u focus unchanged", __func__, wp->id); 508 } 509 } 510 511 int 512 window_set_active_pane(struct window *w, struct window_pane *wp, int notify) 513 { 514 log_debug("%s: pane %%%u", __func__, wp->id); 515 516 if (wp == w->active) 517 return (0); 518 w->last = w->active; 519 520 w->active = wp; 521 w->active->active_point = next_active_point++; 522 w->active->flags |= PANE_CHANGED; 523 524 if (options_get_number(global_options, "focus-events")) { 525 window_pane_update_focus(w->last); 526 window_pane_update_focus(w->active); 527 } 528 529 tty_update_window_offset(w); 530 531 if (notify) 532 notify_window("window-pane-changed", w); 533 return (1); 534 } 535 536 static int 537 window_pane_get_palette(struct window_pane *wp, int c) 538 { 539 if (wp == NULL) 540 return (-1); 541 return (colour_palette_get(&wp->palette, c)); 542 } 543 544 void 545 window_redraw_active_switch(struct window *w, struct window_pane *wp) 546 { 547 struct grid_cell *gc1, *gc2; 548 int c1, c2; 549 550 if (wp == w->active) 551 return; 552 553 for (;;) { 554 /* 555 * If the active and inactive styles or palettes are different, 556 * need to redraw the panes. 557 */ 558 gc1 = &wp->cached_gc; 559 gc2 = &wp->cached_active_gc; 560 if (!grid_cells_look_equal(gc1, gc2)) 561 wp->flags |= PANE_REDRAW; 562 else { 563 c1 = window_pane_get_palette(wp, gc1->fg); 564 c2 = window_pane_get_palette(wp, gc2->fg); 565 if (c1 != c2) 566 wp->flags |= PANE_REDRAW; 567 else { 568 c1 = window_pane_get_palette(wp, gc1->bg); 569 c2 = window_pane_get_palette(wp, gc2->bg); 570 if (c1 != c2) 571 wp->flags |= PANE_REDRAW; 572 } 573 } 574 if (wp == w->active) 575 break; 576 wp = w->active; 577 } 578 } 579 580 struct window_pane * 581 window_get_active_at(struct window *w, u_int x, u_int y) 582 { 583 struct window_pane *wp; 584 585 TAILQ_FOREACH(wp, &w->panes, entry) { 586 if (!window_pane_visible(wp)) 587 continue; 588 if (x < wp->xoff || x > wp->xoff + wp->sx) 589 continue; 590 if (y < wp->yoff || y > wp->yoff + wp->sy) 591 continue; 592 return (wp); 593 } 594 return (NULL); 595 } 596 597 struct window_pane * 598 window_find_string(struct window *w, const char *s) 599 { 600 u_int x, y, top = 0, bottom = w->sy - 1; 601 int status; 602 603 x = w->sx / 2; 604 y = w->sy / 2; 605 606 status = options_get_number(w->options, "pane-border-status"); 607 if (status == PANE_STATUS_TOP) 608 top++; 609 else if (status == PANE_STATUS_BOTTOM) 610 bottom--; 611 612 if (strcasecmp(s, "top") == 0) 613 y = top; 614 else if (strcasecmp(s, "bottom") == 0) 615 y = bottom; 616 else if (strcasecmp(s, "left") == 0) 617 x = 0; 618 else if (strcasecmp(s, "right") == 0) 619 x = w->sx - 1; 620 else if (strcasecmp(s, "top-left") == 0) { 621 x = 0; 622 y = top; 623 } else if (strcasecmp(s, "top-right") == 0) { 624 x = w->sx - 1; 625 y = top; 626 } else if (strcasecmp(s, "bottom-left") == 0) { 627 x = 0; 628 y = bottom; 629 } else if (strcasecmp(s, "bottom-right") == 0) { 630 x = w->sx - 1; 631 y = bottom; 632 } else 633 return (NULL); 634 635 return (window_get_active_at(w, x, y)); 636 } 637 638 int 639 window_zoom(struct window_pane *wp) 640 { 641 struct window *w = wp->window; 642 struct window_pane *wp1; 643 644 if (w->flags & WINDOW_ZOOMED) 645 return (-1); 646 647 if (window_count_panes(w) == 1) 648 return (-1); 649 650 if (w->active != wp) 651 window_set_active_pane(w, wp, 1); 652 653 TAILQ_FOREACH(wp1, &w->panes, entry) { 654 wp1->saved_layout_cell = wp1->layout_cell; 655 wp1->layout_cell = NULL; 656 } 657 658 w->saved_layout_root = w->layout_root; 659 layout_init(w, wp); 660 w->flags |= WINDOW_ZOOMED; 661 notify_window("window-layout-changed", w); 662 663 return (0); 664 } 665 666 int 667 window_unzoom(struct window *w) 668 { 669 struct window_pane *wp; 670 671 if (!(w->flags & WINDOW_ZOOMED)) 672 return (-1); 673 674 w->flags &= ~WINDOW_ZOOMED; 675 layout_free(w); 676 w->layout_root = w->saved_layout_root; 677 w->saved_layout_root = NULL; 678 679 TAILQ_FOREACH(wp, &w->panes, entry) { 680 wp->layout_cell = wp->saved_layout_cell; 681 wp->saved_layout_cell = NULL; 682 } 683 layout_fix_panes(w, NULL); 684 notify_window("window-layout-changed", w); 685 686 return (0); 687 } 688 689 int 690 window_push_zoom(struct window *w, int always, int flag) 691 { 692 log_debug("%s: @%u %d", __func__, w->id, 693 flag && (w->flags & WINDOW_ZOOMED)); 694 if (flag && (always || (w->flags & WINDOW_ZOOMED))) 695 w->flags |= WINDOW_WASZOOMED; 696 else 697 w->flags &= ~WINDOW_WASZOOMED; 698 return (window_unzoom(w) == 0); 699 } 700 701 int 702 window_pop_zoom(struct window *w) 703 { 704 log_debug("%s: @%u %d", __func__, w->id, 705 !!(w->flags & WINDOW_WASZOOMED)); 706 if (w->flags & WINDOW_WASZOOMED) 707 return (window_zoom(w->active) == 0); 708 return (0); 709 } 710 711 struct window_pane * 712 window_add_pane(struct window *w, struct window_pane *other, u_int hlimit, 713 int flags) 714 { 715 struct window_pane *wp; 716 717 if (other == NULL) 718 other = w->active; 719 720 wp = window_pane_create(w, w->sx, w->sy, hlimit); 721 if (TAILQ_EMPTY(&w->panes)) { 722 log_debug("%s: @%u at start", __func__, w->id); 723 TAILQ_INSERT_HEAD(&w->panes, wp, entry); 724 } else if (flags & SPAWN_BEFORE) { 725 log_debug("%s: @%u before %%%u", __func__, w->id, wp->id); 726 if (flags & SPAWN_FULLSIZE) 727 TAILQ_INSERT_HEAD(&w->panes, wp, entry); 728 else 729 TAILQ_INSERT_BEFORE(other, wp, entry); 730 } else { 731 log_debug("%s: @%u after %%%u", __func__, w->id, wp->id); 732 if (flags & SPAWN_FULLSIZE) 733 TAILQ_INSERT_TAIL(&w->panes, wp, entry); 734 else 735 TAILQ_INSERT_AFTER(&w->panes, other, wp, entry); 736 } 737 return (wp); 738 } 739 740 void 741 window_lost_pane(struct window *w, struct window_pane *wp) 742 { 743 log_debug("%s: @%u pane %%%u", __func__, w->id, wp->id); 744 745 if (wp == marked_pane.wp) 746 server_clear_marked(); 747 748 if (wp == w->active) { 749 w->active = w->last; 750 w->last = NULL; 751 if (w->active == NULL) { 752 w->active = TAILQ_PREV(wp, window_panes, entry); 753 if (w->active == NULL) 754 w->active = TAILQ_NEXT(wp, entry); 755 } 756 if (w->active != NULL) { 757 w->active->flags |= PANE_CHANGED; 758 notify_window("window-pane-changed", w); 759 window_update_focus(w); 760 } 761 } else if (wp == w->last) 762 w->last = NULL; 763 } 764 765 void 766 window_remove_pane(struct window *w, struct window_pane *wp) 767 { 768 window_lost_pane(w, wp); 769 770 TAILQ_REMOVE(&w->panes, wp, entry); 771 window_pane_destroy(wp); 772 } 773 774 struct window_pane * 775 window_pane_at_index(struct window *w, u_int idx) 776 { 777 struct window_pane *wp; 778 u_int n; 779 780 n = options_get_number(w->options, "pane-base-index"); 781 TAILQ_FOREACH(wp, &w->panes, entry) { 782 if (n == idx) 783 return (wp); 784 n++; 785 } 786 return (NULL); 787 } 788 789 struct window_pane * 790 window_pane_next_by_number(struct window *w, struct window_pane *wp, u_int n) 791 { 792 for (; n > 0; n--) { 793 if ((wp = TAILQ_NEXT(wp, entry)) == NULL) 794 wp = TAILQ_FIRST(&w->panes); 795 } 796 797 return (wp); 798 } 799 800 struct window_pane * 801 window_pane_previous_by_number(struct window *w, struct window_pane *wp, 802 u_int n) 803 { 804 for (; n > 0; n--) { 805 if ((wp = TAILQ_PREV(wp, window_panes, entry)) == NULL) 806 wp = TAILQ_LAST(&w->panes, window_panes); 807 } 808 809 return (wp); 810 } 811 812 int 813 window_pane_index(struct window_pane *wp, u_int *i) 814 { 815 struct window_pane *wq; 816 struct window *w = wp->window; 817 818 *i = options_get_number(w->options, "pane-base-index"); 819 TAILQ_FOREACH(wq, &w->panes, entry) { 820 if (wp == wq) { 821 return (0); 822 } 823 (*i)++; 824 } 825 826 return (-1); 827 } 828 829 u_int 830 window_count_panes(struct window *w) 831 { 832 struct window_pane *wp; 833 u_int n; 834 835 n = 0; 836 TAILQ_FOREACH(wp, &w->panes, entry) 837 n++; 838 return (n); 839 } 840 841 void 842 window_destroy_panes(struct window *w) 843 { 844 struct window_pane *wp; 845 846 while (!TAILQ_EMPTY(&w->panes)) { 847 wp = TAILQ_FIRST(&w->panes); 848 TAILQ_REMOVE(&w->panes, wp, entry); 849 window_pane_destroy(wp); 850 } 851 } 852 853 const char * 854 window_printable_flags(struct winlink *wl, int escape) 855 { 856 struct session *s = wl->session; 857 static char flags[32]; 858 int pos; 859 860 pos = 0; 861 if (wl->flags & WINLINK_ACTIVITY) { 862 flags[pos++] = '#'; 863 if (escape) 864 flags[pos++] = '#'; 865 } 866 if (wl->flags & WINLINK_BELL) 867 flags[pos++] = '!'; 868 if (wl->flags & WINLINK_SILENCE) 869 flags[pos++] = '~'; 870 if (wl == s->curw) 871 flags[pos++] = '*'; 872 if (wl == TAILQ_FIRST(&s->lastw)) 873 flags[pos++] = '-'; 874 if (server_check_marked() && wl == marked_pane.wl) 875 flags[pos++] = 'M'; 876 if (wl->window->flags & WINDOW_ZOOMED) 877 flags[pos++] = 'Z'; 878 flags[pos] = '\0'; 879 return (flags); 880 } 881 882 struct window_pane * 883 window_pane_find_by_id_str(const char *s) 884 { 885 const char *errstr; 886 u_int id; 887 888 if (*s != '%') 889 return (NULL); 890 891 id = strtonum(s + 1, 0, UINT_MAX, &errstr); 892 if (errstr != NULL) 893 return (NULL); 894 return (window_pane_find_by_id(id)); 895 } 896 897 struct window_pane * 898 window_pane_find_by_id(u_int id) 899 { 900 struct window_pane wp; 901 902 wp.id = id; 903 return (RB_FIND(window_pane_tree, &all_window_panes, &wp)); 904 } 905 906 static struct window_pane * 907 window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) 908 { 909 struct window_pane *wp; 910 char host[HOST_NAME_MAX + 1]; 911 912 wp = xcalloc(1, sizeof *wp); 913 wp->window = w; 914 wp->options = options_create(w->options); 915 wp->flags = PANE_STYLECHANGED; 916 917 wp->id = next_window_pane_id++; 918 RB_INSERT(window_pane_tree, &all_window_panes, wp); 919 920 wp->fd = -1; 921 922 TAILQ_INIT(&wp->modes); 923 924 TAILQ_INIT (&wp->resize_queue); 925 926 wp->sx = sx; 927 wp->sy = sy; 928 929 wp->pipe_fd = -1; 930 931 colour_palette_init(&wp->palette); 932 colour_palette_from_option(&wp->palette, wp->options); 933 934 screen_init(&wp->base, sx, sy, hlimit); 935 wp->screen = &wp->base; 936 937 screen_init(&wp->status_screen, 1, 1, 0); 938 939 if (gethostname(host, sizeof host) == 0) 940 screen_set_title(&wp->base, host); 941 942 return (wp); 943 } 944 945 static void 946 window_pane_destroy(struct window_pane *wp) 947 { 948 struct window_pane_resize *r; 949 struct window_pane_resize *r1; 950 951 window_pane_reset_mode_all(wp); 952 free(wp->searchstr); 953 954 if (wp->fd != -1) { 955 bufferevent_free(wp->event); 956 close(wp->fd); 957 } 958 if (wp->ictx != NULL) 959 input_free(wp->ictx); 960 961 screen_free(&wp->status_screen); 962 963 screen_free(&wp->base); 964 965 if (wp->pipe_fd != -1) { 966 bufferevent_free(wp->pipe_event); 967 close(wp->pipe_fd); 968 } 969 970 if (event_initialized(&wp->resize_timer)) 971 event_del(&wp->resize_timer); 972 TAILQ_FOREACH_SAFE(r, &wp->resize_queue, entry, r1) { 973 TAILQ_REMOVE(&wp->resize_queue, r, entry); 974 free(r); 975 } 976 977 RB_REMOVE(window_pane_tree, &all_window_panes, wp); 978 979 options_free(wp->options); 980 free((void *)wp->cwd); 981 free(wp->shell); 982 cmd_free_argv(wp->argc, wp->argv); 983 colour_palette_free(&wp->palette); 984 free(wp); 985 } 986 987 static void 988 window_pane_read_callback(__unused struct bufferevent *bufev, void *data) 989 { 990 struct window_pane *wp = data; 991 struct evbuffer *evb = wp->event->input; 992 struct window_pane_offset *wpo = &wp->pipe_offset; 993 size_t size = EVBUFFER_LENGTH(evb); 994 char *new_data; 995 size_t new_size; 996 struct client *c; 997 998 if (wp->pipe_fd != -1) { 999 new_data = window_pane_get_new_data(wp, wpo, &new_size); 1000 if (new_size > 0) { 1001 bufferevent_write(wp->pipe_event, new_data, new_size); 1002 window_pane_update_used_data(wp, wpo, new_size); 1003 } 1004 } 1005 1006 log_debug("%%%u has %zu bytes", wp->id, size); 1007 TAILQ_FOREACH(c, &clients, entry) { 1008 if (c->session != NULL && (c->flags & CLIENT_CONTROL)) 1009 control_write_output(c, wp); 1010 } 1011 input_parse_pane(wp); 1012 bufferevent_disable(wp->event, EV_READ); 1013 } 1014 1015 static void 1016 window_pane_error_callback(__unused struct bufferevent *bufev, 1017 __unused short what, void *data) 1018 { 1019 struct window_pane *wp = data; 1020 1021 log_debug("%%%u error", wp->id); 1022 wp->flags |= PANE_EXITED; 1023 1024 if (window_pane_destroy_ready(wp)) 1025 server_destroy_pane(wp, 1); 1026 } 1027 1028 void 1029 window_pane_set_event(struct window_pane *wp) 1030 { 1031 setblocking(wp->fd, 0); 1032 1033 wp->event = bufferevent_new(wp->fd, window_pane_read_callback, 1034 NULL, window_pane_error_callback, wp); 1035 wp->ictx = input_init(wp, wp->event, &wp->palette); 1036 1037 bufferevent_enable(wp->event, EV_READ|EV_WRITE); 1038 } 1039 1040 void 1041 window_pane_resize(struct window_pane *wp, u_int sx, u_int sy) 1042 { 1043 struct window_mode_entry *wme; 1044 struct window_pane_resize *r; 1045 1046 if (sx == wp->sx && sy == wp->sy) 1047 return; 1048 1049 r = xmalloc (sizeof *r); 1050 r->sx = sx; 1051 r->sy = sy; 1052 r->osx = wp->sx; 1053 r->osy = wp->sy; 1054 TAILQ_INSERT_TAIL (&wp->resize_queue, r, entry); 1055 1056 wp->sx = sx; 1057 wp->sy = sy; 1058 1059 log_debug("%s: %%%u resize %ux%u", __func__, wp->id, sx, sy); 1060 screen_resize(&wp->base, sx, sy, wp->base.saved_grid == NULL); 1061 1062 wme = TAILQ_FIRST(&wp->modes); 1063 if (wme != NULL && wme->mode->resize != NULL) 1064 wme->mode->resize(wme, sx, sy); 1065 } 1066 1067 int 1068 window_pane_set_mode(struct window_pane *wp, struct window_pane *swp, 1069 const struct window_mode *mode, struct cmd_find_state *fs, 1070 struct args *args) 1071 { 1072 struct window_mode_entry *wme; 1073 1074 if (!TAILQ_EMPTY(&wp->modes) && TAILQ_FIRST(&wp->modes)->mode == mode) 1075 return (1); 1076 1077 TAILQ_FOREACH(wme, &wp->modes, entry) { 1078 if (wme->mode == mode) 1079 break; 1080 } 1081 if (wme != NULL) { 1082 TAILQ_REMOVE(&wp->modes, wme, entry); 1083 TAILQ_INSERT_HEAD(&wp->modes, wme, entry); 1084 } else { 1085 wme = xcalloc(1, sizeof *wme); 1086 wme->wp = wp; 1087 wme->swp = swp; 1088 wme->mode = mode; 1089 wme->prefix = 1; 1090 TAILQ_INSERT_HEAD(&wp->modes, wme, entry); 1091 wme->screen = wme->mode->init(wme, fs, args); 1092 } 1093 1094 wp->screen = wme->screen; 1095 wp->flags |= (PANE_REDRAW|PANE_CHANGED); 1096 1097 server_redraw_window_borders(wp->window); 1098 server_status_window(wp->window); 1099 notify_pane("pane-mode-changed", wp); 1100 1101 return (0); 1102 } 1103 1104 void 1105 window_pane_reset_mode(struct window_pane *wp) 1106 { 1107 struct window_mode_entry *wme, *next; 1108 1109 if (TAILQ_EMPTY(&wp->modes)) 1110 return; 1111 1112 wme = TAILQ_FIRST(&wp->modes); 1113 TAILQ_REMOVE(&wp->modes, wme, entry); 1114 wme->mode->free(wme); 1115 free(wme); 1116 1117 next = TAILQ_FIRST(&wp->modes); 1118 if (next == NULL) { 1119 log_debug("%s: no next mode", __func__); 1120 wp->screen = &wp->base; 1121 } else { 1122 log_debug("%s: next mode is %s", __func__, next->mode->name); 1123 wp->screen = next->screen; 1124 if (next->mode->resize != NULL) 1125 next->mode->resize(next, wp->sx, wp->sy); 1126 } 1127 wp->flags |= (PANE_REDRAW|PANE_CHANGED); 1128 1129 server_redraw_window_borders(wp->window); 1130 server_status_window(wp->window); 1131 notify_pane("pane-mode-changed", wp); 1132 } 1133 1134 void 1135 window_pane_reset_mode_all(struct window_pane *wp) 1136 { 1137 while (!TAILQ_EMPTY(&wp->modes)) 1138 window_pane_reset_mode(wp); 1139 } 1140 1141 static void 1142 window_pane_copy_key(struct window_pane *wp, key_code key) 1143 { 1144 struct window_pane *loop; 1145 1146 TAILQ_FOREACH(loop, &wp->window->panes, entry) { 1147 if (loop != wp && 1148 TAILQ_EMPTY(&loop->modes) && 1149 loop->fd != -1 && 1150 (~loop->flags & PANE_INPUTOFF) && 1151 window_pane_visible(loop) && 1152 options_get_number(loop->options, "synchronize-panes")) 1153 input_key_pane(loop, key, NULL); 1154 } 1155 } 1156 1157 int 1158 window_pane_key(struct window_pane *wp, struct client *c, struct session *s, 1159 struct winlink *wl, key_code key, struct mouse_event *m) 1160 { 1161 struct window_mode_entry *wme; 1162 1163 if (KEYC_IS_MOUSE(key) && m == NULL) 1164 return (-1); 1165 1166 wme = TAILQ_FIRST(&wp->modes); 1167 if (wme != NULL) { 1168 if (wme->mode->key != NULL && c != NULL) { 1169 key &= ~KEYC_MASK_FLAGS; 1170 wme->mode->key(wme, c, s, wl, key, m); 1171 } 1172 return (0); 1173 } 1174 1175 if (wp->fd == -1 || wp->flags & PANE_INPUTOFF) 1176 return (0); 1177 1178 if (input_key_pane(wp, key, m) != 0) 1179 return (-1); 1180 1181 if (KEYC_IS_MOUSE(key)) 1182 return (0); 1183 if (options_get_number(wp->options, "synchronize-panes")) 1184 window_pane_copy_key(wp, key); 1185 return (0); 1186 } 1187 1188 int 1189 window_pane_visible(struct window_pane *wp) 1190 { 1191 if (~wp->window->flags & WINDOW_ZOOMED) 1192 return (1); 1193 return (wp == wp->window->active); 1194 } 1195 1196 u_int 1197 window_pane_search(struct window_pane *wp, const char *term, int regex, 1198 int ignore) 1199 { 1200 struct screen *s = &wp->base; 1201 regex_t r; 1202 char *new = NULL, *line; 1203 u_int i; 1204 int flags = 0, found; 1205 size_t n; 1206 1207 if (!regex) { 1208 if (ignore) 1209 flags |= FNM_CASEFOLD; 1210 xasprintf(&new, "*%s*", term); 1211 } else { 1212 if (ignore) 1213 flags |= REG_ICASE; 1214 if (regcomp(&r, term, flags|REG_EXTENDED) != 0) 1215 return (0); 1216 } 1217 1218 for (i = 0; i < screen_size_y(s); i++) { 1219 line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s)); 1220 for (n = strlen(line); n > 0; n--) { 1221 if (!isspace((u_char)line[n - 1])) 1222 break; 1223 line[n - 1] = '\0'; 1224 } 1225 log_debug("%s: %s", __func__, line); 1226 if (!regex) 1227 found = (fnmatch(new, line, flags) == 0); 1228 else 1229 found = (regexec(&r, line, 0, NULL, 0) == 0); 1230 free(line); 1231 if (found) 1232 break; 1233 } 1234 if (!regex) 1235 free(new); 1236 else 1237 regfree(&r); 1238 1239 if (i == screen_size_y(s)) 1240 return (0); 1241 return (i + 1); 1242 } 1243 1244 /* Get MRU pane from a list. */ 1245 static struct window_pane * 1246 window_pane_choose_best(struct window_pane **list, u_int size) 1247 { 1248 struct window_pane *next, *best; 1249 u_int i; 1250 1251 if (size == 0) 1252 return (NULL); 1253 1254 best = list[0]; 1255 for (i = 1; i < size; i++) { 1256 next = list[i]; 1257 if (next->active_point > best->active_point) 1258 best = next; 1259 } 1260 return (best); 1261 } 1262 1263 /* 1264 * Find the pane directly above another. We build a list of those adjacent to 1265 * top edge and then choose the best. 1266 */ 1267 struct window_pane * 1268 window_pane_find_up(struct window_pane *wp) 1269 { 1270 struct window *w; 1271 struct window_pane *next, *best, **list; 1272 u_int edge, left, right, end, size; 1273 int status, found; 1274 1275 if (wp == NULL) 1276 return (NULL); 1277 w = wp->window; 1278 status = options_get_number(w->options, "pane-border-status"); 1279 1280 list = NULL; 1281 size = 0; 1282 1283 edge = wp->yoff; 1284 if (status == PANE_STATUS_TOP) { 1285 if (edge == 1) 1286 edge = w->sy + 1; 1287 } else if (status == PANE_STATUS_BOTTOM) { 1288 if (edge == 0) 1289 edge = w->sy; 1290 } else { 1291 if (edge == 0) 1292 edge = w->sy + 1; 1293 } 1294 1295 left = wp->xoff; 1296 right = wp->xoff + wp->sx; 1297 1298 TAILQ_FOREACH(next, &w->panes, entry) { 1299 if (next == wp) 1300 continue; 1301 if (next->yoff + next->sy + 1 != edge) 1302 continue; 1303 end = next->xoff + next->sx - 1; 1304 1305 found = 0; 1306 if (next->xoff < left && end > right) 1307 found = 1; 1308 else if (next->xoff >= left && next->xoff <= right) 1309 found = 1; 1310 else if (end >= left && end <= right) 1311 found = 1; 1312 if (!found) 1313 continue; 1314 list = xreallocarray(list, size + 1, sizeof *list); 1315 list[size++] = next; 1316 } 1317 1318 best = window_pane_choose_best(list, size); 1319 free(list); 1320 return (best); 1321 } 1322 1323 /* Find the pane directly below another. */ 1324 struct window_pane * 1325 window_pane_find_down(struct window_pane *wp) 1326 { 1327 struct window *w; 1328 struct window_pane *next, *best, **list; 1329 u_int edge, left, right, end, size; 1330 int status, found; 1331 1332 if (wp == NULL) 1333 return (NULL); 1334 w = wp->window; 1335 status = options_get_number(w->options, "pane-border-status"); 1336 1337 list = NULL; 1338 size = 0; 1339 1340 edge = wp->yoff + wp->sy + 1; 1341 if (status == PANE_STATUS_TOP) { 1342 if (edge >= w->sy) 1343 edge = 1; 1344 } else if (status == PANE_STATUS_BOTTOM) { 1345 if (edge >= w->sy - 1) 1346 edge = 0; 1347 } else { 1348 if (edge >= w->sy) 1349 edge = 0; 1350 } 1351 1352 left = wp->xoff; 1353 right = wp->xoff + wp->sx; 1354 1355 TAILQ_FOREACH(next, &w->panes, entry) { 1356 if (next == wp) 1357 continue; 1358 if (next->yoff != edge) 1359 continue; 1360 end = next->xoff + next->sx - 1; 1361 1362 found = 0; 1363 if (next->xoff < left && end > right) 1364 found = 1; 1365 else if (next->xoff >= left && next->xoff <= right) 1366 found = 1; 1367 else if (end >= left && end <= right) 1368 found = 1; 1369 if (!found) 1370 continue; 1371 list = xreallocarray(list, size + 1, sizeof *list); 1372 list[size++] = next; 1373 } 1374 1375 best = window_pane_choose_best(list, size); 1376 free(list); 1377 return (best); 1378 } 1379 1380 /* Find the pane directly to the left of another. */ 1381 struct window_pane * 1382 window_pane_find_left(struct window_pane *wp) 1383 { 1384 struct window *w; 1385 struct window_pane *next, *best, **list; 1386 u_int edge, top, bottom, end, size; 1387 int found; 1388 1389 if (wp == NULL) 1390 return (NULL); 1391 w = wp->window; 1392 1393 list = NULL; 1394 size = 0; 1395 1396 edge = wp->xoff; 1397 if (edge == 0) 1398 edge = w->sx + 1; 1399 1400 top = wp->yoff; 1401 bottom = wp->yoff + wp->sy; 1402 1403 TAILQ_FOREACH(next, &w->panes, entry) { 1404 if (next == wp) 1405 continue; 1406 if (next->xoff + next->sx + 1 != edge) 1407 continue; 1408 end = next->yoff + next->sy - 1; 1409 1410 found = 0; 1411 if (next->yoff < top && end > bottom) 1412 found = 1; 1413 else if (next->yoff >= top && next->yoff <= bottom) 1414 found = 1; 1415 else if (end >= top && end <= bottom) 1416 found = 1; 1417 if (!found) 1418 continue; 1419 list = xreallocarray(list, size + 1, sizeof *list); 1420 list[size++] = next; 1421 } 1422 1423 best = window_pane_choose_best(list, size); 1424 free(list); 1425 return (best); 1426 } 1427 1428 /* Find the pane directly to the right of another. */ 1429 struct window_pane * 1430 window_pane_find_right(struct window_pane *wp) 1431 { 1432 struct window *w; 1433 struct window_pane *next, *best, **list; 1434 u_int edge, top, bottom, end, size; 1435 int found; 1436 1437 if (wp == NULL) 1438 return (NULL); 1439 w = wp->window; 1440 1441 list = NULL; 1442 size = 0; 1443 1444 edge = wp->xoff + wp->sx + 1; 1445 if (edge >= w->sx) 1446 edge = 0; 1447 1448 top = wp->yoff; 1449 bottom = wp->yoff + wp->sy; 1450 1451 TAILQ_FOREACH(next, &w->panes, entry) { 1452 if (next == wp) 1453 continue; 1454 if (next->xoff != edge) 1455 continue; 1456 end = next->yoff + next->sy - 1; 1457 1458 found = 0; 1459 if (next->yoff < top && end > bottom) 1460 found = 1; 1461 else if (next->yoff >= top && next->yoff <= bottom) 1462 found = 1; 1463 else if (end >= top && end <= bottom) 1464 found = 1; 1465 if (!found) 1466 continue; 1467 list = xreallocarray(list, size + 1, sizeof *list); 1468 list[size++] = next; 1469 } 1470 1471 best = window_pane_choose_best(list, size); 1472 free(list); 1473 return (best); 1474 } 1475 1476 /* Clear alert flags for a winlink */ 1477 void 1478 winlink_clear_flags(struct winlink *wl) 1479 { 1480 struct winlink *loop; 1481 1482 wl->window->flags &= ~WINDOW_ALERTFLAGS; 1483 TAILQ_FOREACH(loop, &wl->window->winlinks, wentry) { 1484 if ((loop->flags & WINLINK_ALERTFLAGS) != 0) { 1485 loop->flags &= ~WINLINK_ALERTFLAGS; 1486 server_status_session(loop->session); 1487 } 1488 } 1489 } 1490 1491 /* Shuffle window indexes up. */ 1492 int 1493 winlink_shuffle_up(struct session *s, struct winlink *wl, int before) 1494 { 1495 int idx, last; 1496 1497 if (wl == NULL) 1498 return (-1); 1499 if (before) 1500 idx = wl->idx; 1501 else 1502 idx = wl->idx + 1; 1503 1504 /* Find the next free index. */ 1505 for (last = idx; last < INT_MAX; last++) { 1506 if (winlink_find_by_index(&s->windows, last) == NULL) 1507 break; 1508 } 1509 if (last == INT_MAX) 1510 return (-1); 1511 1512 /* Move everything from last - 1 to idx up a bit. */ 1513 for (; last > idx; last--) { 1514 wl = winlink_find_by_index(&s->windows, last - 1); 1515 RB_REMOVE(winlinks, &s->windows, wl); 1516 wl->idx++; 1517 RB_INSERT(winlinks, &s->windows, wl); 1518 } 1519 1520 return (idx); 1521 } 1522 1523 static void 1524 window_pane_input_callback(struct client *c, __unused const char *path, 1525 int error, int closed, struct evbuffer *buffer, void *data) 1526 { 1527 struct window_pane_input_data *cdata = data; 1528 struct window_pane *wp; 1529 u_char *buf = EVBUFFER_DATA(buffer); 1530 size_t len = EVBUFFER_LENGTH(buffer); 1531 1532 wp = window_pane_find_by_id(cdata->wp); 1533 if (wp == NULL || closed || error != 0 || (c->flags & CLIENT_DEAD)) { 1534 if (wp == NULL) 1535 c->flags |= CLIENT_EXIT; 1536 1537 evbuffer_drain(buffer, len); 1538 cmdq_continue(cdata->item); 1539 1540 server_client_unref(c); 1541 free(cdata); 1542 return; 1543 } 1544 input_parse_buffer(wp, buf, len); 1545 evbuffer_drain(buffer, len); 1546 } 1547 1548 int 1549 window_pane_start_input(struct window_pane *wp, struct cmdq_item *item, 1550 char **cause) 1551 { 1552 struct client *c = cmdq_get_client(item); 1553 struct window_pane_input_data *cdata; 1554 1555 if (~wp->flags & PANE_EMPTY) { 1556 *cause = xstrdup("pane is not empty"); 1557 return (-1); 1558 } 1559 if (c->flags & (CLIENT_DEAD|CLIENT_EXITED)) 1560 return (1); 1561 if (c->session != NULL) 1562 return (1); 1563 1564 cdata = xmalloc(sizeof *cdata); 1565 cdata->item = item; 1566 cdata->wp = wp->id; 1567 1568 c->references++; 1569 file_read(c, "-", window_pane_input_callback, cdata); 1570 1571 return (0); 1572 } 1573 1574 void * 1575 window_pane_get_new_data(struct window_pane *wp, 1576 struct window_pane_offset *wpo, size_t *size) 1577 { 1578 size_t used = wpo->used - wp->base_offset; 1579 1580 *size = EVBUFFER_LENGTH(wp->event->input) - used; 1581 return (EVBUFFER_DATA(wp->event->input) + used); 1582 } 1583 1584 void 1585 window_pane_update_used_data(struct window_pane *wp, 1586 struct window_pane_offset *wpo, size_t size) 1587 { 1588 size_t used = wpo->used - wp->base_offset; 1589 1590 if (size > EVBUFFER_LENGTH(wp->event->input) - used) 1591 size = EVBUFFER_LENGTH(wp->event->input) - used; 1592 wpo->used += size; 1593 } 1594 1595 void 1596 window_set_fill_character(struct window *w) 1597 { 1598 const char *value; 1599 struct utf8_data *ud; 1600 1601 free(w->fill_character); 1602 w->fill_character = NULL; 1603 1604 value = options_get_string(w->options, "fill-character"); 1605 if (*value != '\0' && utf8_isvalid(value)) { 1606 ud = utf8_fromcstr(value); 1607 if (ud != NULL && ud[0].width == 1) 1608 w->fill_character = ud; 1609 } 1610 } 1611