2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* 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 <sys/types.h>
|
2016-06-15 09:13:46 +00:00
|
|
|
#include <sys/ioctl.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2019-06-24 08:20:02 +00:00
|
|
|
#include <ctype.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2009-06-24 22:49:56 +00:00
|
|
|
#include <fnmatch.h>
|
2019-06-13 19:46:00 +00:00
|
|
|
#include <regex.h>
|
2017-07-12 10:04:51 +00:00
|
|
|
#include <signal.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-06-16 10:55:47 +00:00
|
|
|
#include <time.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <util.h>
|
2017-06-04 09:02:36 +00:00
|
|
|
#include <vis.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
2009-07-19 13:21:40 +00:00
|
|
|
* Each window is attached to a number of panes, each of which is a pty. This
|
2009-06-01 22:58:49 +00:00
|
|
|
* file contains code to handle them.
|
|
|
|
*
|
|
|
|
* A pane has two buffers attached, these are filled and emptied by the main
|
|
|
|
* server poll loop. Output data is received from pty's in screen format,
|
|
|
|
* translated and returned as a series of escape sequences and strings via
|
|
|
|
* input_parse (in input.c). Input data is received as key codes and written
|
|
|
|
* directly via input_key.
|
|
|
|
*
|
|
|
|
* Each pane also has a "virtual" screen (screen.c) which contains the current
|
|
|
|
* state and is redisplayed when the window is reattached to a client.
|
|
|
|
*
|
|
|
|
* Windows are stored directly on a global array and wrapped in any number of
|
|
|
|
* winlink structs to be linked onto local session RB trees. A reference count
|
|
|
|
* is maintained and a window removed from the global list and destroyed when
|
|
|
|
* it reaches zero.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Global window list. */
|
|
|
|
struct windows windows;
|
|
|
|
|
2011-03-27 20:27:26 +00:00
|
|
|
/* Global panes tree. */
|
|
|
|
struct window_pane_tree all_window_panes;
|
2016-09-16 13:43:41 +00:00
|
|
|
static u_int next_window_pane_id;
|
|
|
|
static u_int next_window_id;
|
|
|
|
static u_int next_active_point;
|
2014-01-28 22:19:17 +00:00
|
|
|
|
2019-05-03 20:44:24 +00:00
|
|
|
struct window_pane_input_data {
|
|
|
|
struct cmdq_item *item;
|
|
|
|
u_int wp;
|
2023-01-06 07:09:27 +00:00
|
|
|
struct client_file *file;
|
2019-05-03 20:44:24 +00:00
|
|
|
};
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static struct window_pane *window_pane_create(struct window *, u_int, u_int,
|
|
|
|
u_int);
|
|
|
|
static void window_pane_destroy(struct window_pane *);
|
|
|
|
|
2015-04-22 15:30:11 +00:00
|
|
|
RB_GENERATE(windows, window, entry, window_cmp);
|
2016-10-11 13:21:59 +00:00
|
|
|
RB_GENERATE(winlinks, winlink, entry, winlink_cmp);
|
|
|
|
RB_GENERATE(window_pane_tree, window_pane, tree_entry, window_pane_cmp);
|
2015-04-22 15:30:11 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
window_cmp(struct window *w1, struct window *w2)
|
|
|
|
{
|
|
|
|
return (w1->id - w2->id);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
int
|
|
|
|
winlink_cmp(struct winlink *wl1, struct winlink *wl2)
|
|
|
|
{
|
|
|
|
return (wl1->idx - wl2->idx);
|
|
|
|
}
|
|
|
|
|
2011-03-27 20:27:26 +00:00
|
|
|
int
|
|
|
|
window_pane_cmp(struct window_pane *wp1, struct window_pane *wp2)
|
|
|
|
{
|
|
|
|
return (wp1->id - wp2->id);
|
|
|
|
}
|
|
|
|
|
2009-07-15 08:00:49 +00:00
|
|
|
struct winlink *
|
|
|
|
winlink_find_by_window(struct winlinks *wwl, struct window *w)
|
|
|
|
{
|
|
|
|
struct winlink *wl;
|
|
|
|
|
|
|
|
RB_FOREACH(wl, winlinks, wwl) {
|
|
|
|
if (wl->window == w)
|
|
|
|
return (wl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
struct winlink *
|
|
|
|
winlink_find_by_index(struct winlinks *wwl, int idx)
|
|
|
|
{
|
|
|
|
struct winlink wl;
|
|
|
|
|
|
|
|
if (idx < 0)
|
|
|
|
fatalx("bad index");
|
|
|
|
|
|
|
|
wl.idx = idx;
|
|
|
|
return (RB_FIND(winlinks, wwl, &wl));
|
|
|
|
}
|
|
|
|
|
2012-01-30 09:39:34 +00:00
|
|
|
struct winlink *
|
|
|
|
winlink_find_by_window_id(struct winlinks *wwl, u_int id)
|
|
|
|
{
|
|
|
|
struct winlink *wl;
|
|
|
|
|
|
|
|
RB_FOREACH(wl, winlinks, wwl) {
|
|
|
|
if (wl->window->id == id)
|
|
|
|
return (wl);
|
|
|
|
}
|
2012-04-01 20:53:47 +00:00
|
|
|
return (NULL);
|
2012-01-30 09:39:34 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2009-08-13 20:11:58 +00:00
|
|
|
winlink_next_index(struct winlinks *wwl, int idx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-08-13 20:11:58 +00:00
|
|
|
int i;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-13 20:11:58 +00:00
|
|
|
i = idx;
|
|
|
|
do {
|
2009-06-01 22:58:49 +00:00
|
|
|
if (winlink_find_by_index(wwl, i) == NULL)
|
|
|
|
return (i);
|
2009-08-13 20:11:58 +00:00
|
|
|
if (i == INT_MAX)
|
|
|
|
i = 0;
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
} while (i != idx);
|
|
|
|
return (-1);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u_int
|
|
|
|
winlink_count(struct winlinks *wwl)
|
|
|
|
{
|
|
|
|
struct winlink *wl;
|
|
|
|
u_int n;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
RB_FOREACH(wl, winlinks, wwl)
|
|
|
|
n++;
|
|
|
|
|
|
|
|
return (n);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct winlink *
|
2011-01-25 22:31:50 +00:00
|
|
|
winlink_add(struct winlinks *wwl, int idx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct winlink *wl;
|
|
|
|
|
2009-08-13 20:11:58 +00:00
|
|
|
if (idx < 0) {
|
|
|
|
if ((idx = winlink_next_index(wwl, -idx - 1)) == -1)
|
|
|
|
return (NULL);
|
|
|
|
} else if (winlink_find_by_index(wwl, idx) != NULL)
|
2009-06-01 22:58:49 +00:00
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
wl = xcalloc(1, sizeof *wl);
|
|
|
|
wl->idx = idx;
|
|
|
|
RB_INSERT(winlinks, wwl, wl);
|
|
|
|
|
|
|
|
return (wl);
|
|
|
|
}
|
|
|
|
|
2011-01-25 22:31:50 +00:00
|
|
|
void
|
|
|
|
winlink_set_window(struct winlink *wl, struct window *w)
|
|
|
|
{
|
2016-10-19 09:22:07 +00:00
|
|
|
if (wl->window != NULL) {
|
|
|
|
TAILQ_REMOVE(&wl->window->winlinks, wl, wentry);
|
2017-04-28 19:13:55 +00:00
|
|
|
window_remove_ref(wl->window, __func__);
|
2016-10-19 09:22:07 +00:00
|
|
|
}
|
|
|
|
TAILQ_INSERT_TAIL(&w->winlinks, wl, wentry);
|
2011-01-25 22:31:50 +00:00
|
|
|
wl->window = w;
|
2017-04-28 19:13:55 +00:00
|
|
|
window_add_ref(w, __func__);
|
2011-01-25 22:31:50 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
|
|
|
winlink_remove(struct winlinks *wwl, struct winlink *wl)
|
|
|
|
{
|
|
|
|
struct window *w = wl->window;
|
|
|
|
|
2016-10-19 09:22:07 +00:00
|
|
|
if (w != NULL) {
|
|
|
|
TAILQ_REMOVE(&w->winlinks, wl, wentry);
|
2017-04-28 19:13:55 +00:00
|
|
|
window_remove_ref(w, __func__);
|
2016-10-19 09:22:07 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
RB_REMOVE(winlinks, wwl, wl);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(wl);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct winlink *
|
2009-11-26 21:37:13 +00:00
|
|
|
winlink_next(struct winlink *wl)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
return (RB_NEXT(winlinks, wwl, wl));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct winlink *
|
2009-11-26 21:37:13 +00:00
|
|
|
winlink_previous(struct winlink *wl)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
return (RB_PREV(winlinks, wwl, wl));
|
|
|
|
}
|
|
|
|
|
2010-06-21 01:46:36 +00:00
|
|
|
struct winlink *
|
2010-07-14 18:37:49 +00:00
|
|
|
winlink_next_by_number(struct winlink *wl, struct session *s, int n)
|
2010-06-21 01:46:36 +00:00
|
|
|
{
|
|
|
|
for (; n > 0; n--) {
|
|
|
|
if ((wl = RB_NEXT(winlinks, wwl, wl)) == NULL)
|
2010-07-14 18:37:49 +00:00
|
|
|
wl = RB_MIN(winlinks, &s->windows);
|
2010-06-21 01:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (wl);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct winlink *
|
2010-07-14 18:37:49 +00:00
|
|
|
winlink_previous_by_number(struct winlink *wl, struct session *s, int n)
|
2010-06-21 01:46:36 +00:00
|
|
|
{
|
|
|
|
for (; n > 0; n--) {
|
|
|
|
if ((wl = RB_PREV(winlinks, wwl, wl)) == NULL)
|
2010-07-14 18:37:49 +00:00
|
|
|
wl = RB_MAX(winlinks, &s->windows);
|
2010-06-21 01:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (wl);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
|
|
|
winlink_stack_push(struct winlink_stack *stack, struct winlink *wl)
|
|
|
|
{
|
|
|
|
if (wl == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
winlink_stack_remove(stack, wl);
|
2009-10-10 10:02:48 +00:00
|
|
|
TAILQ_INSERT_HEAD(stack, wl, sentry);
|
2023-07-10 09:24:53 +00:00
|
|
|
wl->flags |= WINLINK_VISITED;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
winlink_stack_remove(struct winlink_stack *stack, struct winlink *wl)
|
|
|
|
{
|
2023-07-10 09:24:53 +00:00
|
|
|
if (wl != NULL && (wl->flags & WINLINK_VISITED)) {
|
|
|
|
TAILQ_REMOVE(stack, wl, sentry);
|
|
|
|
wl->flags &= ~WINLINK_VISITED;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-25 18:09:28 +00:00
|
|
|
struct window *
|
2015-04-25 18:56:05 +00:00
|
|
|
window_find_by_id_str(const char *s)
|
2015-04-25 18:09:28 +00:00
|
|
|
{
|
|
|
|
const char *errstr;
|
|
|
|
u_int id;
|
|
|
|
|
|
|
|
if (*s != '@')
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
id = strtonum(s + 1, 0, UINT_MAX, &errstr);
|
|
|
|
if (errstr != NULL)
|
|
|
|
return (NULL);
|
|
|
|
return (window_find_by_id(id));
|
|
|
|
}
|
|
|
|
|
2012-01-30 09:39:34 +00:00
|
|
|
struct window *
|
|
|
|
window_find_by_id(u_int id)
|
|
|
|
{
|
2015-04-22 15:30:11 +00:00
|
|
|
struct window w;
|
2012-01-30 09:39:34 +00:00
|
|
|
|
2015-04-22 15:30:11 +00:00
|
|
|
w.id = id;
|
|
|
|
return (RB_FIND(windows, &windows, &w));
|
2012-01-30 09:39:34 +00:00
|
|
|
}
|
|
|
|
|
2015-08-29 08:30:54 +00:00
|
|
|
void
|
|
|
|
window_update_activity(struct window *w)
|
|
|
|
{
|
|
|
|
gettimeofday(&w->activity_time, NULL);
|
|
|
|
alerts_queue(w, WINDOW_ACTIVITY);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
struct window *
|
2019-11-28 09:45:15 +00:00
|
|
|
window_create(u_int sx, u_int sy, u_int xpixel, u_int ypixel)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window *w;
|
|
|
|
|
2019-11-28 09:45:15 +00:00
|
|
|
if (xpixel == 0)
|
|
|
|
xpixel = DEFAULT_XPIXEL;
|
|
|
|
if (ypixel == 0)
|
|
|
|
ypixel = DEFAULT_YPIXEL;
|
|
|
|
|
2009-11-04 23:54:57 +00:00
|
|
|
w = xcalloc(1, sizeof *w);
|
2019-10-28 09:07:59 +00:00
|
|
|
w->name = xstrdup("");
|
2019-06-20 11:59:59 +00:00
|
|
|
w->flags = 0;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
TAILQ_INIT(&w->panes);
|
2023-07-10 09:24:53 +00:00
|
|
|
TAILQ_INIT(&w->last_panes);
|
2009-06-01 22:58:49 +00:00
|
|
|
w->active = NULL;
|
|
|
|
|
2009-07-28 06:48:44 +00:00
|
|
|
w->lastlayout = -1;
|
2009-07-19 13:21:40 +00:00
|
|
|
w->layout_root = NULL;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
w->sx = sx;
|
|
|
|
w->sy = sy;
|
2021-08-27 17:15:57 +00:00
|
|
|
w->manual_sx = sx;
|
|
|
|
w->manual_sy = sy;
|
2019-11-28 09:45:15 +00:00
|
|
|
w->xpixel = xpixel;
|
|
|
|
w->ypixel = ypixel;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
w->options = options_create(global_w_options);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
w->references = 0;
|
2016-10-19 09:22:07 +00:00
|
|
|
TAILQ_INIT(&w->winlinks);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2015-04-22 15:30:11 +00:00
|
|
|
w->id = next_window_id++;
|
2015-05-07 11:42:56 +00:00
|
|
|
RB_INSERT(windows, &windows, w);
|
2015-04-22 15:30:11 +00:00
|
|
|
|
2022-03-16 17:00:17 +00:00
|
|
|
window_set_fill_character(w);
|
2015-08-29 08:30:54 +00:00
|
|
|
window_update_activity(w);
|
|
|
|
|
2021-06-10 07:24:45 +00:00
|
|
|
log_debug("%s: @%u create %ux%u (%ux%u)", __func__, w->id, sx, sy,
|
|
|
|
w->xpixel, w->ypixel);
|
2009-06-01 22:58:49 +00:00
|
|
|
return (w);
|
|
|
|
}
|
|
|
|
|
2019-06-30 19:21:53 +00:00
|
|
|
static void
|
2009-06-01 22:58:49 +00:00
|
|
|
window_destroy(struct window *w)
|
|
|
|
{
|
2017-04-28 19:13:55 +00:00
|
|
|
log_debug("window @%u destroyed (%d references)", w->id, w->references);
|
2016-10-19 09:22:07 +00:00
|
|
|
|
2024-03-21 11:30:42 +00:00
|
|
|
window_unzoom(w, 0);
|
2015-04-22 15:30:11 +00:00
|
|
|
RB_REMOVE(windows, &windows, w);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
if (w->layout_root != NULL)
|
2015-07-17 13:09:07 +00:00
|
|
|
layout_free_cell(w->layout_root);
|
|
|
|
if (w->saved_layout_root != NULL)
|
|
|
|
layout_free_cell(w->saved_layout_root);
|
2015-04-28 10:43:13 +00:00
|
|
|
free(w->old_layout);
|
2009-07-19 13:21:40 +00:00
|
|
|
|
2019-04-26 10:24:26 +00:00
|
|
|
window_destroy_panes(w);
|
|
|
|
|
2015-08-29 00:29:15 +00:00
|
|
|
if (event_initialized(&w->name_event))
|
|
|
|
evtimer_del(&w->name_event);
|
2015-08-28 16:10:46 +00:00
|
|
|
|
2015-08-29 08:30:54 +00:00
|
|
|
if (event_initialized(&w->alerts_timer))
|
|
|
|
evtimer_del(&w->alerts_timer);
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
if (event_initialized(&w->offset_timer))
|
|
|
|
event_del(&w->offset_timer);
|
2015-08-29 08:30:54 +00:00
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
options_free(w->options);
|
2022-03-16 17:00:17 +00:00
|
|
|
free(w->fill_character);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2012-07-10 11:53:01 +00:00
|
|
|
free(w->name);
|
|
|
|
free(w);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 08:16:03 +00:00
|
|
|
int
|
|
|
|
window_pane_destroy_ready(struct window_pane *wp)
|
|
|
|
{
|
2017-07-03 12:38:50 +00:00
|
|
|
int n;
|
|
|
|
|
|
|
|
if (wp->pipe_fd != -1) {
|
|
|
|
if (EVBUFFER_LENGTH(wp->pipe_event->output) != 0)
|
|
|
|
return (0);
|
|
|
|
if (ioctl(wp->fd, FIONREAD, &n) != -1 && n > 0)
|
|
|
|
return (0);
|
|
|
|
}
|
2017-07-03 08:16:03 +00:00
|
|
|
|
|
|
|
if (~wp->flags & PANE_EXITED)
|
|
|
|
return (0);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2012-08-21 10:00:33 +00:00
|
|
|
void
|
2017-04-28 19:13:55 +00:00
|
|
|
window_add_ref(struct window *w, const char *from)
|
|
|
|
{
|
|
|
|
w->references++;
|
|
|
|
log_debug("%s: @%u %s, now %d", __func__, w->id, from, w->references);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_remove_ref(struct window *w, const char *from)
|
2012-08-21 10:00:33 +00:00
|
|
|
{
|
|
|
|
w->references--;
|
2017-04-28 19:13:55 +00:00
|
|
|
log_debug("%s: @%u %s, now %d", __func__, w->id, from, w->references);
|
|
|
|
|
2012-08-21 10:00:33 +00:00
|
|
|
if (w->references == 0)
|
|
|
|
window_destroy(w);
|
|
|
|
}
|
|
|
|
|
2012-02-02 00:10:11 +00:00
|
|
|
void
|
|
|
|
window_set_name(struct window *w, const char *new_name)
|
|
|
|
{
|
2012-07-10 11:53:01 +00:00
|
|
|
free(w->name);
|
2017-06-04 09:02:36 +00:00
|
|
|
utf8_stravis(&w->name, new_name, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL);
|
2016-10-16 22:06:40 +00:00
|
|
|
notify_window("window-renamed", w);
|
2012-02-02 00:10:11 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 19:54:22 +00:00
|
|
|
void
|
2019-11-28 09:45:15 +00:00
|
|
|
window_resize(struct window *w, u_int sx, u_int sy, int xpixel, int ypixel)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-11-28 09:45:15 +00:00
|
|
|
if (xpixel == 0)
|
|
|
|
xpixel = DEFAULT_XPIXEL;
|
|
|
|
if (ypixel == 0)
|
|
|
|
ypixel = DEFAULT_YPIXEL;
|
|
|
|
|
|
|
|
log_debug("%s: @%u resize %ux%u (%ux%u)", __func__, w->id, sx, sy,
|
2020-03-16 08:23:24 +00:00
|
|
|
xpixel == -1 ? w->xpixel : (u_int)xpixel,
|
|
|
|
ypixel == -1 ? w->ypixel : (u_int)ypixel);
|
2009-06-01 22:58:49 +00:00
|
|
|
w->sx = sx;
|
|
|
|
w->sy = sy;
|
2019-11-28 09:45:15 +00:00
|
|
|
if (xpixel != -1)
|
|
|
|
w->xpixel = xpixel;
|
|
|
|
if (ypixel != -1)
|
|
|
|
w->ypixel = ypixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-06-10 07:33:41 +00:00
|
|
|
window_pane_send_resize(struct window_pane *wp, u_int sx, u_int sy)
|
2019-11-28 09:45:15 +00:00
|
|
|
{
|
|
|
|
struct window *w = wp->window;
|
|
|
|
struct winsize ws;
|
|
|
|
|
|
|
|
if (wp->fd == -1)
|
|
|
|
return;
|
2020-06-05 11:20:51 +00:00
|
|
|
|
2021-06-10 07:33:41 +00:00
|
|
|
log_debug("%s: %%%u resize to %u,%u", __func__, wp->id, sx, sy);
|
2019-11-28 09:45:15 +00:00
|
|
|
|
|
|
|
memset(&ws, 0, sizeof ws);
|
2021-06-10 07:33:41 +00:00
|
|
|
ws.ws_col = sx;
|
2020-05-16 16:50:55 +00:00
|
|
|
ws.ws_row = sy;
|
2019-11-28 09:45:15 +00:00
|
|
|
ws.ws_xpixel = w->xpixel * ws.ws_col;
|
|
|
|
ws.ws_ypixel = w->ypixel * ws.ws_row;
|
|
|
|
if (ioctl(wp->fd, TIOCSWINSZ, &ws) == -1)
|
|
|
|
fatal("ioctl failed");
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 21:34:21 +00:00
|
|
|
int
|
|
|
|
window_has_pane(struct window *w, struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window_pane *wp1;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(wp1, &w->panes, entry) {
|
|
|
|
if (wp1 == wp)
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2021-08-13 06:52:51 +00:00
|
|
|
void
|
|
|
|
window_update_focus(struct window *w)
|
|
|
|
{
|
|
|
|
if (w != NULL) {
|
|
|
|
log_debug("%s: @%u", __func__, w->id);
|
|
|
|
window_pane_update_focus(w->active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_pane_update_focus(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct client *c;
|
|
|
|
int focused = 0;
|
|
|
|
|
2024-04-10 07:15:21 +00:00
|
|
|
if (wp != NULL && (~wp->flags & PANE_EXITED)) {
|
2021-08-13 06:52:51 +00:00
|
|
|
if (wp != wp->window->active)
|
|
|
|
focused = 0;
|
|
|
|
else {
|
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
|
|
|
if (c->session != NULL &&
|
|
|
|
c->session->attached != 0 &&
|
|
|
|
(c->flags & CLIENT_FOCUSED) &&
|
2024-10-05 12:10:16 +00:00
|
|
|
c->session->curw->window == wp->window &&
|
|
|
|
c->overlay_draw == NULL) {
|
2021-08-13 06:52:51 +00:00
|
|
|
focused = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!focused && (wp->flags & PANE_FOCUSED)) {
|
|
|
|
log_debug("%s: %%%u focus out", __func__, wp->id);
|
|
|
|
if (wp->base.mode & MODE_FOCUSON)
|
|
|
|
bufferevent_write(wp->event, "\033[O", 3);
|
|
|
|
notify_pane("pane-focus-out", wp);
|
|
|
|
wp->flags &= ~PANE_FOCUSED;
|
|
|
|
} else if (focused && (~wp->flags & PANE_FOCUSED)) {
|
|
|
|
log_debug("%s: %%%u focus in", __func__, wp->id);
|
|
|
|
if (wp->base.mode & MODE_FOCUSON)
|
|
|
|
bufferevent_write(wp->event, "\033[I", 3);
|
|
|
|
notify_pane("pane-focus-in", wp);
|
|
|
|
wp->flags |= PANE_FOCUSED;
|
|
|
|
} else
|
|
|
|
log_debug("%s: %%%u focus unchanged", __func__, wp->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-21 22:22:04 +00:00
|
|
|
int
|
2019-04-17 14:37:48 +00:00
|
|
|
window_set_active_pane(struct window *w, struct window_pane *wp, int notify)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2023-07-10 09:24:53 +00:00
|
|
|
struct window_pane *lastwp;
|
|
|
|
|
2019-04-17 14:37:48 +00:00
|
|
|
log_debug("%s: pane %%%u", __func__, wp->id);
|
|
|
|
|
2010-11-14 08:58:25 +00:00
|
|
|
if (wp == w->active)
|
2014-10-21 22:22:04 +00:00
|
|
|
return (0);
|
2023-07-10 09:24:53 +00:00
|
|
|
lastwp = w->active;
|
|
|
|
|
|
|
|
window_pane_stack_remove(&w->last_panes, wp);
|
|
|
|
window_pane_stack_push(&w->last_panes, lastwp);
|
2019-04-17 14:37:48 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
w->active = wp;
|
2014-05-08 06:03:30 +00:00
|
|
|
w->active->active_point = next_active_point++;
|
2015-08-28 07:49:24 +00:00
|
|
|
w->active->flags |= PANE_CHANGED;
|
2019-04-17 14:37:48 +00:00
|
|
|
|
2021-08-13 06:52:51 +00:00
|
|
|
if (options_get_number(global_options, "focus-events")) {
|
2023-07-10 09:24:53 +00:00
|
|
|
window_pane_update_focus(lastwp);
|
2021-08-13 06:52:51 +00:00
|
|
|
window_pane_update_focus(w->active);
|
|
|
|
}
|
|
|
|
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
tty_update_window_offset(w);
|
2019-04-17 14:37:48 +00:00
|
|
|
|
|
|
|
if (notify)
|
|
|
|
notify_window("window-pane-changed", w);
|
2014-10-21 22:22:04 +00:00
|
|
|
return (1);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 20:49:55 +00:00
|
|
|
static int
|
|
|
|
window_pane_get_palette(struct window_pane *wp, int c)
|
|
|
|
{
|
|
|
|
if (wp == NULL)
|
|
|
|
return (-1);
|
|
|
|
return (colour_palette_get(&wp->palette, c));
|
|
|
|
}
|
|
|
|
|
2015-09-14 11:34:50 +00:00
|
|
|
void
|
|
|
|
window_redraw_active_switch(struct window *w, struct window_pane *wp)
|
|
|
|
{
|
2020-05-16 14:53:23 +00:00
|
|
|
struct grid_cell *gc1, *gc2;
|
|
|
|
int c1, c2;
|
2015-09-14 11:34:50 +00:00
|
|
|
|
|
|
|
if (wp == w->active)
|
|
|
|
return;
|
|
|
|
|
2019-06-20 11:59:59 +00:00
|
|
|
for (;;) {
|
|
|
|
/*
|
|
|
|
* If the active and inactive styles or palettes are different,
|
|
|
|
* need to redraw the panes.
|
|
|
|
*/
|
2020-05-16 14:53:23 +00:00
|
|
|
gc1 = &wp->cached_gc;
|
|
|
|
gc2 = &wp->cached_active_gc;
|
|
|
|
if (!grid_cells_look_equal(gc1, gc2))
|
2019-06-20 11:59:59 +00:00
|
|
|
wp->flags |= PANE_REDRAW;
|
|
|
|
else {
|
2020-05-16 14:53:23 +00:00
|
|
|
c1 = window_pane_get_palette(wp, gc1->fg);
|
|
|
|
c2 = window_pane_get_palette(wp, gc2->fg);
|
2019-06-20 11:59:59 +00:00
|
|
|
if (c1 != c2)
|
|
|
|
wp->flags |= PANE_REDRAW;
|
|
|
|
else {
|
2020-05-16 14:53:23 +00:00
|
|
|
c1 = window_pane_get_palette(wp, gc1->bg);
|
|
|
|
c2 = window_pane_get_palette(wp, gc2->bg);
|
2019-06-20 11:59:59 +00:00
|
|
|
if (c1 != c2)
|
|
|
|
wp->flags |= PANE_REDRAW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wp == w->active)
|
|
|
|
break;
|
|
|
|
wp = w->active;
|
|
|
|
}
|
2015-09-14 11:34:50 +00:00
|
|
|
}
|
|
|
|
|
2011-06-05 10:53:05 +00:00
|
|
|
struct window_pane *
|
|
|
|
window_get_active_at(struct window *w, u_int x, u_int y)
|
2009-10-10 14:51:16 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
2024-11-05 09:41:17 +00:00
|
|
|
int pane_scrollbars;
|
|
|
|
u_int sb_pos, sb_w, xoff, sx;
|
|
|
|
|
|
|
|
pane_scrollbars = options_get_number(w->options, "pane-scrollbars");
|
|
|
|
sb_pos = options_get_number(w->options, "pane-scrollbars-position");
|
2009-10-10 14:51:16 +00:00
|
|
|
|
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
2019-03-12 13:56:30 +00:00
|
|
|
if (!window_pane_visible(wp))
|
|
|
|
continue;
|
2024-11-05 09:41:17 +00:00
|
|
|
|
|
|
|
if (pane_scrollbars == PANE_SCROLLBARS_ALWAYS ||
|
|
|
|
(pane_scrollbars == PANE_SCROLLBARS_MODAL &&
|
2024-11-15 13:12:20 +00:00
|
|
|
window_pane_mode(wp) != WINDOW_PANE_NO_MODE)) {
|
|
|
|
sb_w = wp->scrollbar_style.width +
|
|
|
|
wp->scrollbar_style.pad;
|
|
|
|
} else
|
2024-11-05 09:41:17 +00:00
|
|
|
sb_w = 0;
|
|
|
|
|
|
|
|
if (sb_pos == PANE_SCROLLBARS_LEFT) {
|
|
|
|
xoff = wp->xoff - sb_w;
|
|
|
|
sx = wp->sx + sb_w;
|
|
|
|
} else { /* sb_pos == PANE_SCROLLBARS_RIGHT */
|
|
|
|
xoff = wp->xoff;
|
|
|
|
sx = wp->sx + sb_w;
|
|
|
|
}
|
|
|
|
if (x < xoff || x > xoff + sx)
|
2009-10-10 14:51:16 +00:00
|
|
|
continue;
|
2011-06-05 10:53:05 +00:00
|
|
|
if (y < wp->yoff || y > wp->yoff + wp->sy)
|
2009-10-10 14:51:16 +00:00
|
|
|
continue;
|
2011-06-05 10:53:05 +00:00
|
|
|
return (wp);
|
2009-10-10 14:51:16 +00:00
|
|
|
}
|
2011-06-05 10:53:05 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct window_pane *
|
|
|
|
window_find_string(struct window *w, const char *s)
|
|
|
|
{
|
2020-02-14 13:57:58 +00:00
|
|
|
u_int x, y, top = 0, bottom = w->sy - 1;
|
|
|
|
int status;
|
2011-06-05 10:53:05 +00:00
|
|
|
|
|
|
|
x = w->sx / 2;
|
|
|
|
y = w->sy / 2;
|
|
|
|
|
2020-02-14 13:57:58 +00:00
|
|
|
status = options_get_number(w->options, "pane-border-status");
|
|
|
|
if (status == PANE_STATUS_TOP)
|
|
|
|
top++;
|
|
|
|
else if (status == PANE_STATUS_BOTTOM)
|
|
|
|
bottom--;
|
|
|
|
|
2011-06-05 10:53:05 +00:00
|
|
|
if (strcasecmp(s, "top") == 0)
|
2020-02-14 13:57:58 +00:00
|
|
|
y = top;
|
2011-06-05 10:53:05 +00:00
|
|
|
else if (strcasecmp(s, "bottom") == 0)
|
2020-02-14 13:57:58 +00:00
|
|
|
y = bottom;
|
2011-06-05 10:53:05 +00:00
|
|
|
else if (strcasecmp(s, "left") == 0)
|
|
|
|
x = 0;
|
|
|
|
else if (strcasecmp(s, "right") == 0)
|
|
|
|
x = w->sx - 1;
|
|
|
|
else if (strcasecmp(s, "top-left") == 0) {
|
|
|
|
x = 0;
|
2020-02-14 13:57:58 +00:00
|
|
|
y = top;
|
2011-06-05 10:53:05 +00:00
|
|
|
} else if (strcasecmp(s, "top-right") == 0) {
|
|
|
|
x = w->sx - 1;
|
2020-02-14 13:57:58 +00:00
|
|
|
y = top;
|
2011-06-05 10:53:05 +00:00
|
|
|
} else if (strcasecmp(s, "bottom-left") == 0) {
|
|
|
|
x = 0;
|
2020-02-14 13:57:58 +00:00
|
|
|
y = bottom;
|
2011-06-05 10:53:05 +00:00
|
|
|
} else if (strcasecmp(s, "bottom-right") == 0) {
|
|
|
|
x = w->sx - 1;
|
2020-02-14 13:57:58 +00:00
|
|
|
y = bottom;
|
2011-06-05 10:53:05 +00:00
|
|
|
} else
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
return (window_get_active_at(w, x, y));
|
2009-10-10 14:51:16 +00:00
|
|
|
}
|
|
|
|
|
2013-03-24 09:57:59 +00:00
|
|
|
int
|
|
|
|
window_zoom(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct window *w = wp->window;
|
|
|
|
struct window_pane *wp1;
|
|
|
|
|
|
|
|
if (w->flags & WINDOW_ZOOMED)
|
|
|
|
return (-1);
|
|
|
|
|
2013-03-25 11:39:11 +00:00
|
|
|
if (window_count_panes(w) == 1)
|
|
|
|
return (-1);
|
|
|
|
|
2013-03-24 09:57:59 +00:00
|
|
|
if (w->active != wp)
|
2019-04-17 14:37:48 +00:00
|
|
|
window_set_active_pane(w, wp, 1);
|
2013-03-24 09:57:59 +00:00
|
|
|
|
|
|
|
TAILQ_FOREACH(wp1, &w->panes, entry) {
|
|
|
|
wp1->saved_layout_cell = wp1->layout_cell;
|
|
|
|
wp1->layout_cell = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
w->saved_layout_root = w->layout_root;
|
|
|
|
layout_init(w, wp);
|
|
|
|
w->flags |= WINDOW_ZOOMED;
|
2016-10-16 22:06:40 +00:00
|
|
|
notify_window("window-layout-changed", w);
|
2013-03-24 09:57:59 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2024-03-21 11:30:42 +00:00
|
|
|
window_unzoom(struct window *w, int notify)
|
2013-03-24 09:57:59 +00:00
|
|
|
{
|
2013-03-26 10:54:48 +00:00
|
|
|
struct window_pane *wp;
|
2013-03-24 09:57:59 +00:00
|
|
|
|
|
|
|
if (!(w->flags & WINDOW_ZOOMED))
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
w->flags &= ~WINDOW_ZOOMED;
|
|
|
|
layout_free(w);
|
|
|
|
w->layout_root = w->saved_layout_root;
|
2015-04-21 22:38:49 +00:00
|
|
|
w->saved_layout_root = NULL;
|
2013-03-24 09:57:59 +00:00
|
|
|
|
2013-03-26 10:54:48 +00:00
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
wp->layout_cell = wp->saved_layout_cell;
|
|
|
|
wp->saved_layout_cell = NULL;
|
2013-03-24 09:57:59 +00:00
|
|
|
}
|
2021-03-11 06:31:05 +00:00
|
|
|
layout_fix_panes(w, NULL);
|
2024-03-21 11:30:42 +00:00
|
|
|
|
|
|
|
if (notify)
|
|
|
|
notify_window("window-layout-changed", w);
|
2013-03-24 09:57:59 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2019-08-14 09:58:31 +00:00
|
|
|
int
|
2021-03-11 06:31:05 +00:00
|
|
|
window_push_zoom(struct window *w, int always, int flag)
|
2019-08-14 09:58:31 +00:00
|
|
|
{
|
|
|
|
log_debug("%s: @%u %d", __func__, w->id,
|
|
|
|
flag && (w->flags & WINDOW_ZOOMED));
|
2021-03-11 06:31:05 +00:00
|
|
|
if (flag && (always || (w->flags & WINDOW_ZOOMED)))
|
2019-08-14 09:58:31 +00:00
|
|
|
w->flags |= WINDOW_WASZOOMED;
|
|
|
|
else
|
|
|
|
w->flags &= ~WINDOW_WASZOOMED;
|
2024-03-21 11:30:42 +00:00
|
|
|
return (window_unzoom(w, 1) == 0);
|
2019-08-14 09:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
window_pop_zoom(struct window *w)
|
|
|
|
{
|
|
|
|
log_debug("%s: @%u %d", __func__, w->id,
|
|
|
|
!!(w->flags & WINDOW_WASZOOMED));
|
|
|
|
if (w->flags & WINDOW_WASZOOMED)
|
|
|
|
return (window_zoom(w->active) == 0);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
struct window_pane *
|
2019-04-17 14:37:48 +00:00
|
|
|
window_add_pane(struct window *w, struct window_pane *other, u_int hlimit,
|
|
|
|
int flags)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
|
2017-02-27 13:07:57 +00:00
|
|
|
if (other == NULL)
|
|
|
|
other = w->active;
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
wp = window_pane_create(w, w->sx, w->sy, hlimit);
|
2017-03-13 17:20:11 +00:00
|
|
|
if (TAILQ_EMPTY(&w->panes)) {
|
|
|
|
log_debug("%s: @%u at start", __func__, w->id);
|
2009-06-01 22:58:49 +00:00
|
|
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
2019-04-17 14:37:48 +00:00
|
|
|
} else if (flags & SPAWN_BEFORE) {
|
2017-03-13 17:20:11 +00:00
|
|
|
log_debug("%s: @%u before %%%u", __func__, w->id, wp->id);
|
2019-04-17 14:37:48 +00:00
|
|
|
if (flags & SPAWN_FULLSIZE)
|
2018-03-16 15:15:39 +00:00
|
|
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
|
|
|
else
|
|
|
|
TAILQ_INSERT_BEFORE(other, wp, entry);
|
2017-03-13 17:20:11 +00:00
|
|
|
} else {
|
|
|
|
log_debug("%s: @%u after %%%u", __func__, w->id, wp->id);
|
2019-04-17 14:37:48 +00:00
|
|
|
if (flags & SPAWN_FULLSIZE)
|
2018-03-16 15:15:39 +00:00
|
|
|
TAILQ_INSERT_TAIL(&w->panes, wp, entry);
|
|
|
|
else
|
|
|
|
TAILQ_INSERT_AFTER(&w->panes, other, wp, entry);
|
2017-03-13 17:20:11 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
return (wp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-17 09:13:13 +00:00
|
|
|
window_lost_pane(struct window *w, struct window_pane *wp)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2017-08-28 12:36:38 +00:00
|
|
|
log_debug("%s: @%u pane %%%u", __func__, w->id, wp->id);
|
|
|
|
|
2015-12-15 00:00:01 +00:00
|
|
|
if (wp == marked_pane.wp)
|
2015-06-04 11:43:51 +00:00
|
|
|
server_clear_marked();
|
|
|
|
|
2023-07-10 09:24:53 +00:00
|
|
|
window_pane_stack_remove(&w->last_panes, wp);
|
2010-10-23 12:51:51 +00:00
|
|
|
if (wp == w->active) {
|
2023-07-10 09:24:53 +00:00
|
|
|
w->active = TAILQ_FIRST(&w->last_panes);
|
2010-10-23 13:04:34 +00:00
|
|
|
if (w->active == NULL) {
|
|
|
|
w->active = TAILQ_PREV(wp, window_panes, entry);
|
|
|
|
if (w->active == NULL)
|
|
|
|
w->active = TAILQ_NEXT(wp, entry);
|
|
|
|
}
|
2017-05-04 07:16:43 +00:00
|
|
|
if (w->active != NULL) {
|
2023-07-10 09:24:53 +00:00
|
|
|
window_pane_stack_remove(&w->last_panes, w->active);
|
2015-12-02 23:09:22 +00:00
|
|
|
w->active->flags |= PANE_CHANGED;
|
2017-05-04 07:16:43 +00:00
|
|
|
notify_window("window-pane-changed", w);
|
2022-02-03 07:38:17 +00:00
|
|
|
window_update_focus(w);
|
2017-05-04 07:16:43 +00:00
|
|
|
}
|
2023-07-10 09:24:53 +00:00
|
|
|
}
|
2014-04-17 09:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_remove_pane(struct window *w, struct window_pane *wp)
|
|
|
|
{
|
|
|
|
window_lost_pane(w, wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
|
|
|
window_pane_destroy(wp);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct window_pane *
|
|
|
|
window_pane_at_index(struct window *w, u_int idx)
|
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
u_int n;
|
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
n = options_get_number(w->options, "pane-base-index");
|
2009-06-01 22:58:49 +00:00
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
if (n == idx)
|
|
|
|
return (wp);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2010-07-14 18:37:49 +00:00
|
|
|
struct window_pane *
|
|
|
|
window_pane_next_by_number(struct window *w, struct window_pane *wp, u_int n)
|
|
|
|
{
|
|
|
|
for (; n > 0; n--) {
|
|
|
|
if ((wp = TAILQ_NEXT(wp, entry)) == NULL)
|
|
|
|
wp = TAILQ_FIRST(&w->panes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (wp);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct window_pane *
|
|
|
|
window_pane_previous_by_number(struct window *w, struct window_pane *wp,
|
|
|
|
u_int n)
|
|
|
|
{
|
|
|
|
for (; n > 0; n--) {
|
|
|
|
if ((wp = TAILQ_PREV(wp, window_panes, entry)) == NULL)
|
|
|
|
wp = TAILQ_LAST(&w->panes, window_panes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (wp);
|
|
|
|
}
|
|
|
|
|
2011-11-15 23:19:51 +00:00
|
|
|
int
|
|
|
|
window_pane_index(struct window_pane *wp, u_int *i)
|
2009-07-17 18:45:08 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wq;
|
2011-11-15 23:19:51 +00:00
|
|
|
struct window *w = wp->window;
|
2009-07-17 18:45:08 +00:00
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
*i = options_get_number(w->options, "pane-base-index");
|
2009-07-17 18:45:08 +00:00
|
|
|
TAILQ_FOREACH(wq, &w->panes, entry) {
|
2011-11-15 23:19:51 +00:00
|
|
|
if (wp == wq) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
(*i)++;
|
2009-07-17 18:45:08 +00:00
|
|
|
}
|
2011-11-15 23:19:51 +00:00
|
|
|
|
|
|
|
return (-1);
|
2009-07-17 18:45:08 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
u_int
|
|
|
|
window_count_panes(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
u_int n;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry)
|
|
|
|
n++;
|
|
|
|
return (n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_destroy_panes(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
|
2023-07-10 09:24:53 +00:00
|
|
|
while (!TAILQ_EMPTY(&w->last_panes)) {
|
|
|
|
wp = TAILQ_FIRST(&w->last_panes);
|
|
|
|
window_pane_stack_remove(&w->last_panes, wp);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
while (!TAILQ_EMPTY(&w->panes)) {
|
|
|
|
wp = TAILQ_FIRST(&w->panes);
|
|
|
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
|
|
|
window_pane_destroy(wp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 09:39:07 +00:00
|
|
|
const char *
|
2021-01-20 07:16:54 +00:00
|
|
|
window_printable_flags(struct winlink *wl, int escape)
|
2010-12-30 21:35:17 +00:00
|
|
|
{
|
2017-04-20 09:43:45 +00:00
|
|
|
struct session *s = wl->session;
|
|
|
|
static char flags[32];
|
|
|
|
int pos;
|
2010-12-30 21:35:17 +00:00
|
|
|
|
|
|
|
pos = 0;
|
2021-01-20 07:16:54 +00:00
|
|
|
if (wl->flags & WINLINK_ACTIVITY) {
|
2010-12-30 21:35:17 +00:00
|
|
|
flags[pos++] = '#';
|
2021-01-20 07:16:54 +00:00
|
|
|
if (escape)
|
|
|
|
flags[pos++] = '#';
|
|
|
|
}
|
2010-12-30 21:35:17 +00:00
|
|
|
if (wl->flags & WINLINK_BELL)
|
|
|
|
flags[pos++] = '!';
|
|
|
|
if (wl->flags & WINLINK_SILENCE)
|
|
|
|
flags[pos++] = '~';
|
|
|
|
if (wl == s->curw)
|
|
|
|
flags[pos++] = '*';
|
|
|
|
if (wl == TAILQ_FIRST(&s->lastw))
|
|
|
|
flags[pos++] = '-';
|
2015-12-15 00:00:01 +00:00
|
|
|
if (server_check_marked() && wl == marked_pane.wl)
|
2015-06-04 11:43:51 +00:00
|
|
|
flags[pos++] = 'M';
|
2013-03-24 09:57:59 +00:00
|
|
|
if (wl->window->flags & WINDOW_ZOOMED)
|
|
|
|
flags[pos++] = 'Z';
|
2010-12-30 21:35:17 +00:00
|
|
|
flags[pos] = '\0';
|
2017-04-20 09:39:07 +00:00
|
|
|
return (flags);
|
2010-12-30 21:35:17 +00:00
|
|
|
}
|
|
|
|
|
2015-04-25 18:09:28 +00:00
|
|
|
struct window_pane *
|
|
|
|
window_pane_find_by_id_str(const char *s)
|
|
|
|
{
|
|
|
|
const char *errstr;
|
|
|
|
u_int id;
|
|
|
|
|
|
|
|
if (*s != '%')
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
id = strtonum(s + 1, 0, UINT_MAX, &errstr);
|
|
|
|
if (errstr != NULL)
|
|
|
|
return (NULL);
|
|
|
|
return (window_pane_find_by_id(id));
|
|
|
|
}
|
|
|
|
|
2011-03-27 20:27:26 +00:00
|
|
|
struct window_pane *
|
|
|
|
window_pane_find_by_id(u_int id)
|
|
|
|
{
|
|
|
|
struct window_pane wp;
|
|
|
|
|
|
|
|
wp.id = id;
|
|
|
|
return (RB_FIND(window_pane_tree, &all_window_panes, &wp));
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static struct window_pane *
|
2009-06-01 22:58:49 +00:00
|
|
|
window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
|
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
2015-08-28 17:11:12 +00:00
|
|
|
char host[HOST_NAME_MAX + 1];
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
wp = xcalloc(1, sizeof *wp);
|
|
|
|
wp->window = w;
|
2019-06-20 11:59:59 +00:00
|
|
|
wp->options = options_create(w->options);
|
|
|
|
wp->flags = PANE_STYLECHANGED;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2012-01-30 09:39:34 +00:00
|
|
|
wp->id = next_window_pane_id++;
|
2011-03-27 20:27:26 +00:00
|
|
|
RB_INSERT(window_pane_tree, &all_window_panes, wp);
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
wp->fd = -1;
|
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
TAILQ_INIT(&wp->modes);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2021-06-10 07:33:41 +00:00
|
|
|
TAILQ_INIT (&wp->resize_queue);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-06-05 11:20:51 +00:00
|
|
|
wp->sx = sx;
|
|
|
|
wp->sy = sy;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-10-11 10:04:27 +00:00
|
|
|
wp->pipe_fd = -1;
|
|
|
|
|
2024-06-24 08:30:50 +00:00
|
|
|
wp->control_bg = -1;
|
|
|
|
wp->control_fg = -1;
|
|
|
|
|
2024-11-15 13:12:20 +00:00
|
|
|
style_set_scrollbar_style_from_option(&wp->scrollbar_style,
|
|
|
|
wp->options);
|
|
|
|
|
2021-08-11 20:49:55 +00:00
|
|
|
colour_palette_init(&wp->palette);
|
2021-08-20 17:36:03 +00:00
|
|
|
colour_palette_from_option(&wp->palette, wp->options);
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_init(&wp->base, sx, sy, hlimit);
|
|
|
|
wp->screen = &wp->base;
|
2022-06-17 07:28:05 +00:00
|
|
|
window_pane_default_cursor(wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-04-29 15:00:48 +00:00
|
|
|
screen_init(&wp->status_screen, 1, 1, 0);
|
|
|
|
|
2015-08-28 17:11:12 +00:00
|
|
|
if (gethostname(host, sizeof host) == 0)
|
|
|
|
screen_set_title(&wp->base, host);
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
return (wp);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-06-01 22:58:49 +00:00
|
|
|
window_pane_destroy(struct window_pane *wp)
|
|
|
|
{
|
2021-06-10 07:33:41 +00:00
|
|
|
struct window_pane_resize *r;
|
|
|
|
struct window_pane_resize *r1;
|
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
window_pane_reset_mode_all(wp);
|
2017-05-12 10:45:38 +00:00
|
|
|
free(wp->searchstr);
|
2010-08-25 19:19:43 +00:00
|
|
|
|
2009-11-04 22:43:11 +00:00
|
|
|
if (wp->fd != -1) {
|
|
|
|
bufferevent_free(wp->event);
|
2012-01-29 02:22:11 +00:00
|
|
|
close(wp->fd);
|
2009-11-04 22:43:11 +00:00
|
|
|
}
|
2020-03-31 07:00:34 +00:00
|
|
|
if (wp->ictx != NULL)
|
|
|
|
input_free(wp->ictx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2019-03-18 21:55:04 +00:00
|
|
|
screen_free(&wp->status_screen);
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
screen_free(&wp->base);
|
|
|
|
|
2009-10-11 10:04:27 +00:00
|
|
|
if (wp->pipe_fd != -1) {
|
2009-11-04 22:02:38 +00:00
|
|
|
bufferevent_free(wp->pipe_event);
|
2012-01-29 02:22:11 +00:00
|
|
|
close(wp->pipe_fd);
|
2009-10-11 10:04:27 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 08:30:44 +00:00
|
|
|
if (event_initialized(&wp->resize_timer))
|
|
|
|
event_del(&wp->resize_timer);
|
2021-06-10 07:33:41 +00:00
|
|
|
TAILQ_FOREACH_SAFE(r, &wp->resize_queue, entry, r1) {
|
|
|
|
TAILQ_REMOVE(&wp->resize_queue, r, entry);
|
|
|
|
free(r);
|
|
|
|
}
|
2016-09-28 08:30:44 +00:00
|
|
|
|
2011-03-27 20:27:26 +00:00
|
|
|
RB_REMOVE(window_pane_tree, &all_window_panes, wp);
|
|
|
|
|
2019-06-20 11:59:59 +00:00
|
|
|
options_free(wp->options);
|
2015-10-31 08:13:58 +00:00
|
|
|
free((void *)wp->cwd);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(wp->shell);
|
2014-05-13 08:08:32 +00:00
|
|
|
cmd_free_argv(wp->argc, wp->argv);
|
2021-08-11 20:49:55 +00:00
|
|
|
colour_palette_free(&wp->palette);
|
2012-07-10 11:53:01 +00:00
|
|
|
free(wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-09-16 13:43:41 +00:00
|
|
|
static void
|
2015-11-18 14:27:44 +00:00
|
|
|
window_pane_read_callback(__unused struct bufferevent *bufev, void *data)
|
2009-11-04 22:43:11 +00:00
|
|
|
{
|
2020-05-21 07:24:13 +00:00
|
|
|
struct window_pane *wp = data;
|
|
|
|
struct evbuffer *evb = wp->event->input;
|
|
|
|
struct window_pane_offset *wpo = &wp->pipe_offset;
|
|
|
|
size_t size = EVBUFFER_LENGTH(evb);
|
|
|
|
char *new_data;
|
|
|
|
size_t new_size;
|
|
|
|
struct client *c;
|
2015-05-12 22:40:38 +00:00
|
|
|
|
2020-05-21 07:24:13 +00:00
|
|
|
if (wp->pipe_fd != -1) {
|
|
|
|
new_data = window_pane_get_new_data(wp, wpo, &new_size);
|
|
|
|
if (new_size > 0) {
|
|
|
|
bufferevent_write(wp->pipe_event, new_data, new_size);
|
2020-06-01 09:43:00 +00:00
|
|
|
window_pane_update_used_data(wp, wpo, new_size);
|
2020-05-21 07:24:13 +00:00
|
|
|
}
|
2010-04-04 18:48:37 +00:00
|
|
|
}
|
2009-11-04 22:43:11 +00:00
|
|
|
|
2017-02-08 08:25:12 +00:00
|
|
|
log_debug("%%%u has %zu bytes", wp->id, size);
|
2020-05-21 07:24:13 +00:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
2020-06-01 09:43:00 +00:00
|
|
|
if (c->session != NULL && (c->flags & CLIENT_CONTROL))
|
2020-05-21 07:24:13 +00:00
|
|
|
control_write_output(c, wp);
|
|
|
|
}
|
2020-03-19 14:03:48 +00:00
|
|
|
input_parse_pane(wp);
|
2020-06-01 09:43:00 +00:00
|
|
|
bufferevent_disable(wp->event, EV_READ);
|
2009-11-04 22:43:11 +00:00
|
|
|
}
|
|
|
|
|
2016-09-16 13:43:41 +00:00
|
|
|
static void
|
2015-11-18 14:27:44 +00:00
|
|
|
window_pane_error_callback(__unused struct bufferevent *bufev,
|
|
|
|
__unused short what, void *data)
|
2009-11-04 22:43:11 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wp = data;
|
|
|
|
|
2017-07-03 08:16:03 +00:00
|
|
|
log_debug("%%%u error", wp->id);
|
2017-07-03 12:38:50 +00:00
|
|
|
wp->flags |= PANE_EXITED;
|
2017-07-03 08:16:03 +00:00
|
|
|
|
|
|
|
if (window_pane_destroy_ready(wp))
|
|
|
|
server_destroy_pane(wp, 1);
|
2009-11-04 22:43:11 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 14:37:48 +00:00
|
|
|
void
|
|
|
|
window_pane_set_event(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
setblocking(wp->fd, 0);
|
|
|
|
|
|
|
|
wp->event = bufferevent_new(wp->fd, window_pane_read_callback,
|
|
|
|
NULL, window_pane_error_callback, wp);
|
2022-08-24 07:22:30 +00:00
|
|
|
if (wp->event == NULL)
|
|
|
|
fatalx("out of memory");
|
2021-08-11 20:49:55 +00:00
|
|
|
wp->ictx = input_init(wp, wp->event, &wp->palette);
|
2019-04-17 14:37:48 +00:00
|
|
|
|
|
|
|
bufferevent_enable(wp->event, EV_READ|EV_WRITE);
|
|
|
|
}
|
|
|
|
|
2009-07-21 19:54:22 +00:00
|
|
|
void
|
2009-06-01 22:58:49 +00:00
|
|
|
window_pane_resize(struct window_pane *wp, u_int sx, u_int sy)
|
|
|
|
{
|
2019-03-12 11:16:49 +00:00
|
|
|
struct window_mode_entry *wme;
|
2021-06-10 07:33:41 +00:00
|
|
|
struct window_pane_resize *r;
|
2019-03-12 11:16:49 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
if (sx == wp->sx && sy == wp->sy)
|
2009-07-21 19:54:22 +00:00
|
|
|
return;
|
2021-06-10 07:33:41 +00:00
|
|
|
|
2022-05-30 12:55:25 +00:00
|
|
|
r = xmalloc(sizeof *r);
|
2021-06-10 07:33:41 +00:00
|
|
|
r->sx = sx;
|
|
|
|
r->sy = sy;
|
|
|
|
r->osx = wp->sx;
|
|
|
|
r->osy = wp->sy;
|
|
|
|
TAILQ_INSERT_TAIL (&wp->resize_queue, r, entry);
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
wp->sx = sx;
|
|
|
|
wp->sy = sy;
|
|
|
|
|
2019-06-26 13:05:24 +00:00
|
|
|
log_debug("%s: %%%u resize %ux%u", __func__, wp->id, sx, sy);
|
2020-03-31 07:00:34 +00:00
|
|
|
screen_resize(&wp->base, sx, sy, wp->base.saved_grid == NULL);
|
2019-03-12 11:16:49 +00:00
|
|
|
|
|
|
|
wme = TAILQ_FIRST(&wp->modes);
|
|
|
|
if (wme != NULL && wme->mode->resize != NULL)
|
|
|
|
wme->mode->resize(wme, sx, sy);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-04-10 07:44:26 +00:00
|
|
|
window_pane_set_mode(struct window_pane *wp, struct window_pane *swp,
|
|
|
|
const struct window_mode *mode, struct cmd_find_state *fs,
|
|
|
|
struct args *args)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-12 11:16:49 +00:00
|
|
|
struct window_mode_entry *wme;
|
2024-11-05 09:41:17 +00:00
|
|
|
struct window *w = wp->window;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
if (!TAILQ_EMPTY(&wp->modes) && TAILQ_FIRST(&wp->modes)->mode == mode)
|
2009-06-01 22:58:49 +00:00
|
|
|
return (1);
|
2019-03-07 20:24:21 +00:00
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
TAILQ_FOREACH(wme, &wp->modes, entry) {
|
|
|
|
if (wme->mode == mode)
|
|
|
|
break;
|
|
|
|
}
|
2019-03-18 15:25:36 +00:00
|
|
|
if (wme != NULL) {
|
2019-03-12 11:16:49 +00:00
|
|
|
TAILQ_REMOVE(&wp->modes, wme, entry);
|
2019-03-18 15:25:36 +00:00
|
|
|
TAILQ_INSERT_HEAD(&wp->modes, wme, entry);
|
|
|
|
} else {
|
2019-03-12 11:16:49 +00:00
|
|
|
wme = xcalloc(1, sizeof *wme);
|
|
|
|
wme->wp = wp;
|
2020-04-10 07:44:26 +00:00
|
|
|
wme->swp = swp;
|
2019-03-12 11:16:49 +00:00
|
|
|
wme->mode = mode;
|
|
|
|
wme->prefix = 1;
|
2019-03-18 15:25:36 +00:00
|
|
|
TAILQ_INSERT_HEAD(&wp->modes, wme, entry);
|
2019-03-12 11:16:49 +00:00
|
|
|
wme->screen = wme->mode->init(wme, fs, args);
|
|
|
|
}
|
|
|
|
wp->screen = wme->screen;
|
2024-11-05 09:41:17 +00:00
|
|
|
|
|
|
|
wp->flags |= (PANE_REDRAW|PANE_REDRAWSCROLLBAR|PANE_CHANGED);
|
|
|
|
layout_fix_panes(w, NULL);
|
2016-03-01 12:05:15 +00:00
|
|
|
|
2020-05-16 15:01:30 +00:00
|
|
|
server_redraw_window_borders(wp->window);
|
2016-03-01 12:05:15 +00:00
|
|
|
server_status_window(wp->window);
|
2017-05-04 07:16:43 +00:00
|
|
|
notify_pane("pane-mode-changed", wp);
|
2019-03-12 11:16:49 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_pane_reset_mode(struct window_pane *wp)
|
|
|
|
{
|
2019-03-12 11:16:49 +00:00
|
|
|
struct window_mode_entry *wme, *next;
|
2024-11-05 09:41:17 +00:00
|
|
|
struct window *w = wp->window;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
if (TAILQ_EMPTY(&wp->modes))
|
|
|
|
return;
|
2016-06-15 09:13:46 +00:00
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
wme = TAILQ_FIRST(&wp->modes);
|
|
|
|
TAILQ_REMOVE(&wp->modes, wme, entry);
|
|
|
|
wme->mode->free(wme);
|
|
|
|
free(wme);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
next = TAILQ_FIRST(&wp->modes);
|
|
|
|
if (next == NULL) {
|
2023-03-27 08:47:57 +00:00
|
|
|
wp->flags &= ~PANE_UNSEENCHANGES;
|
2019-03-12 11:16:49 +00:00
|
|
|
log_debug("%s: no next mode", __func__);
|
|
|
|
wp->screen = &wp->base;
|
|
|
|
} else {
|
|
|
|
log_debug("%s: next mode is %s", __func__, next->mode->name);
|
|
|
|
wp->screen = next->screen;
|
2019-05-30 20:54:03 +00:00
|
|
|
if (next->mode->resize != NULL)
|
2019-03-12 11:16:49 +00:00
|
|
|
next->mode->resize(next, wp->sx, wp->sy);
|
|
|
|
}
|
2024-11-05 09:41:17 +00:00
|
|
|
|
|
|
|
wp->flags |= (PANE_REDRAW|PANE_REDRAWSCROLLBAR|PANE_CHANGED);
|
|
|
|
layout_fix_panes(w, NULL);
|
2016-03-01 12:05:15 +00:00
|
|
|
|
2020-05-16 15:01:30 +00:00
|
|
|
server_redraw_window_borders(wp->window);
|
2016-03-01 12:05:15 +00:00
|
|
|
server_status_window(wp->window);
|
2017-05-04 07:16:43 +00:00
|
|
|
notify_pane("pane-mode-changed", wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
void
|
|
|
|
window_pane_reset_mode_all(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
while (!TAILQ_EMPTY(&wp->modes))
|
|
|
|
window_pane_reset_mode(wp);
|
|
|
|
}
|
|
|
|
|
2024-10-01 06:15:47 +00:00
|
|
|
static void
|
|
|
|
window_pane_copy_paste(struct window_pane *wp, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct window_pane *loop;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(loop, &wp->window->panes, entry) {
|
|
|
|
if (loop != wp &&
|
|
|
|
TAILQ_EMPTY(&loop->modes) &&
|
|
|
|
loop->fd != -1 &&
|
|
|
|
(~loop->flags & PANE_INPUTOFF) &&
|
|
|
|
window_pane_visible(loop) &&
|
|
|
|
options_get_number(loop->options, "synchronize-panes")) {
|
|
|
|
log_debug("%s: %.*s", __func__, (int)len, buf);
|
|
|
|
bufferevent_write(loop->event, buf, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-15 08:31:50 +00:00
|
|
|
static void
|
|
|
|
window_pane_copy_key(struct window_pane *wp, key_code key)
|
|
|
|
{
|
|
|
|
struct window_pane *loop;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(loop, &wp->window->panes, entry) {
|
|
|
|
if (loop != wp &&
|
|
|
|
TAILQ_EMPTY(&loop->modes) &&
|
|
|
|
loop->fd != -1 &&
|
|
|
|
(~loop->flags & PANE_INPUTOFF) &&
|
|
|
|
window_pane_visible(loop) &&
|
|
|
|
options_get_number(loop->options, "synchronize-panes"))
|
|
|
|
input_key_pane(loop, key, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 06:15:47 +00:00
|
|
|
void
|
2024-12-06 09:06:56 +00:00
|
|
|
window_pane_paste(struct window_pane *wp, key_code key, char *buf, size_t len)
|
2024-10-01 06:15:47 +00:00
|
|
|
{
|
|
|
|
if (!TAILQ_EMPTY(&wp->modes))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wp->fd == -1 || wp->flags & PANE_INPUTOFF)
|
|
|
|
return;
|
|
|
|
|
2024-12-06 09:06:56 +00:00
|
|
|
if (KEYC_IS_PASTE(key) && (~wp->screen->mode & MODE_BRACKETPASTE))
|
|
|
|
return;
|
|
|
|
|
2024-10-01 06:15:47 +00:00
|
|
|
log_debug("%s: %.*s", __func__, (int)len, buf);
|
|
|
|
bufferevent_write(wp->event, buf, len);
|
|
|
|
|
|
|
|
if (options_get_number(wp->options, "synchronize-panes"))
|
|
|
|
window_pane_copy_paste(wp, buf, len);
|
|
|
|
}
|
|
|
|
|
2020-01-13 07:51:54 +00:00
|
|
|
int
|
2015-04-19 21:34:21 +00:00
|
|
|
window_pane_key(struct window_pane *wp, struct client *c, struct session *s,
|
2018-12-18 13:20:44 +00:00
|
|
|
struct winlink *wl, key_code key, struct mouse_event *m)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2019-03-12 11:16:49 +00:00
|
|
|
struct window_mode_entry *wme;
|
2009-10-09 07:27:00 +00:00
|
|
|
|
2015-04-19 21:34:21 +00:00
|
|
|
if (KEYC_IS_MOUSE(key) && m == NULL)
|
2020-01-13 07:51:54 +00:00
|
|
|
return (-1);
|
2015-04-19 21:34:21 +00:00
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
wme = TAILQ_FIRST(&wp->modes);
|
2019-03-07 20:24:21 +00:00
|
|
|
if (wme != NULL) {
|
2020-05-16 16:50:55 +00:00
|
|
|
if (wme->mode->key != NULL && c != NULL) {
|
|
|
|
key &= ~KEYC_MASK_FLAGS;
|
|
|
|
wme->mode->key(wme, c, s, wl, key, m);
|
|
|
|
}
|
2020-01-13 07:51:54 +00:00
|
|
|
return (0);
|
2009-10-10 15:29:34 +00:00
|
|
|
}
|
2009-10-09 07:27:00 +00:00
|
|
|
|
2014-08-11 22:14:30 +00:00
|
|
|
if (wp->fd == -1 || wp->flags & PANE_INPUTOFF)
|
2020-01-13 07:51:54 +00:00
|
|
|
return (0);
|
2014-08-11 22:14:30 +00:00
|
|
|
|
2020-03-19 14:03:48 +00:00
|
|
|
if (input_key_pane(wp, key, m) != 0)
|
2020-01-13 07:51:54 +00:00
|
|
|
return (-1);
|
2015-04-19 21:34:21 +00:00
|
|
|
|
|
|
|
if (KEYC_IS_MOUSE(key))
|
2020-01-13 07:51:54 +00:00
|
|
|
return (0);
|
2020-12-15 08:31:50 +00:00
|
|
|
if (options_get_number(wp->options, "synchronize-panes"))
|
|
|
|
window_pane_copy_key(wp, key);
|
2020-01-13 07:51:54 +00:00
|
|
|
return (0);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-14 07:23:36 +00:00
|
|
|
int
|
2017-08-28 12:36:38 +00:00
|
|
|
window_pane_visible(struct window_pane *wp)
|
2009-07-14 07:23:36 +00:00
|
|
|
{
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
if (~wp->window->flags & WINDOW_ZOOMED)
|
|
|
|
return (1);
|
|
|
|
return (wp == wp->window->active);
|
2009-07-14 07:23:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-13 08:03:50 +00:00
|
|
|
int
|
|
|
|
window_pane_exited(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
return (wp->fd == -1 || (wp->flags & PANE_EXITED));
|
|
|
|
}
|
|
|
|
|
2017-05-29 18:06:34 +00:00
|
|
|
u_int
|
2019-06-13 19:46:00 +00:00
|
|
|
window_pane_search(struct window_pane *wp, const char *term, int regex,
|
|
|
|
int ignore)
|
2017-05-29 18:06:34 +00:00
|
|
|
{
|
|
|
|
struct screen *s = &wp->base;
|
2019-06-13 19:46:00 +00:00
|
|
|
regex_t r;
|
|
|
|
char *new = NULL, *line;
|
2017-05-29 18:06:34 +00:00
|
|
|
u_int i;
|
2019-06-13 19:46:00 +00:00
|
|
|
int flags = 0, found;
|
2019-06-24 08:20:02 +00:00
|
|
|
size_t n;
|
2017-05-29 18:06:34 +00:00
|
|
|
|
2019-06-13 19:46:00 +00:00
|
|
|
if (!regex) {
|
|
|
|
if (ignore)
|
|
|
|
flags |= FNM_CASEFOLD;
|
|
|
|
xasprintf(&new, "*%s*", term);
|
|
|
|
} else {
|
|
|
|
if (ignore)
|
|
|
|
flags |= REG_ICASE;
|
|
|
|
if (regcomp(&r, term, flags|REG_EXTENDED) != 0)
|
|
|
|
return (0);
|
|
|
|
}
|
2017-05-29 18:06:34 +00:00
|
|
|
|
|
|
|
for (i = 0; i < screen_size_y(s); i++) {
|
|
|
|
line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
|
2019-06-24 08:20:02 +00:00
|
|
|
for (n = strlen(line); n > 0; n--) {
|
|
|
|
if (!isspace((u_char)line[n - 1]))
|
|
|
|
break;
|
|
|
|
line[n - 1] = '\0';
|
|
|
|
}
|
|
|
|
log_debug("%s: %s", __func__, line);
|
2019-06-13 19:46:00 +00:00
|
|
|
if (!regex)
|
2020-04-09 13:49:21 +00:00
|
|
|
found = (fnmatch(new, line, flags) == 0);
|
2019-06-13 19:46:00 +00:00
|
|
|
else
|
|
|
|
found = (regexec(&r, line, 0, NULL, 0) == 0);
|
2017-05-29 18:06:34 +00:00
|
|
|
free(line);
|
2019-06-13 19:46:00 +00:00
|
|
|
if (found)
|
|
|
|
break;
|
2017-05-29 18:06:34 +00:00
|
|
|
}
|
2019-06-13 19:46:00 +00:00
|
|
|
if (!regex)
|
|
|
|
free(new);
|
|
|
|
else
|
|
|
|
regfree(&r);
|
2017-05-29 18:06:34 +00:00
|
|
|
|
|
|
|
if (i == screen_size_y(s))
|
|
|
|
return (0);
|
|
|
|
return (i + 1);
|
|
|
|
}
|
|
|
|
|
2014-05-08 06:03:30 +00:00
|
|
|
/* Get MRU pane from a list. */
|
2016-09-16 13:43:41 +00:00
|
|
|
static struct window_pane *
|
2015-04-25 18:56:05 +00:00
|
|
|
window_pane_choose_best(struct window_pane **list, u_int size)
|
2014-05-08 06:03:30 +00:00
|
|
|
{
|
|
|
|
struct window_pane *next, *best;
|
|
|
|
u_int i;
|
|
|
|
|
2015-04-25 18:56:05 +00:00
|
|
|
if (size == 0)
|
2014-05-08 06:03:30 +00:00
|
|
|
return (NULL);
|
|
|
|
|
2015-04-25 18:56:05 +00:00
|
|
|
best = list[0];
|
|
|
|
for (i = 1; i < size; i++) {
|
|
|
|
next = list[i];
|
2014-05-08 06:03:30 +00:00
|
|
|
if (next->active_point > best->active_point)
|
|
|
|
best = next;
|
|
|
|
}
|
|
|
|
return (best);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the pane directly above another. We build a list of those adjacent to
|
|
|
|
* top edge and then choose the best.
|
|
|
|
*/
|
2010-03-22 19:07:52 +00:00
|
|
|
struct window_pane *
|
|
|
|
window_pane_find_up(struct window_pane *wp)
|
|
|
|
{
|
2019-06-26 13:03:47 +00:00
|
|
|
struct window *w;
|
2015-04-25 18:56:05 +00:00
|
|
|
struct window_pane *next, *best, **list;
|
|
|
|
u_int edge, left, right, end, size;
|
2017-03-21 09:49:10 +00:00
|
|
|
int status, found;
|
2010-03-22 19:07:52 +00:00
|
|
|
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
if (wp == NULL)
|
2010-03-22 19:07:52 +00:00
|
|
|
return (NULL);
|
2019-06-26 13:03:47 +00:00
|
|
|
w = wp->window;
|
|
|
|
status = options_get_number(w->options, "pane-border-status");
|
2015-04-25 18:56:05 +00:00
|
|
|
|
|
|
|
list = NULL;
|
|
|
|
size = 0;
|
2014-05-08 06:03:30 +00:00
|
|
|
|
|
|
|
edge = wp->yoff;
|
2019-06-26 13:03:47 +00:00
|
|
|
if (status == PANE_STATUS_TOP) {
|
|
|
|
if (edge == 1)
|
|
|
|
edge = w->sy + 1;
|
|
|
|
} else if (status == PANE_STATUS_BOTTOM) {
|
|
|
|
if (edge == 0)
|
|
|
|
edge = w->sy;
|
|
|
|
} else {
|
|
|
|
if (edge == 0)
|
|
|
|
edge = w->sy + 1;
|
|
|
|
}
|
2010-03-22 19:07:52 +00:00
|
|
|
|
|
|
|
left = wp->xoff;
|
2014-05-08 06:03:30 +00:00
|
|
|
right = wp->xoff + wp->sx;
|
2010-03-22 19:07:52 +00:00
|
|
|
|
2019-06-26 13:03:47 +00:00
|
|
|
TAILQ_FOREACH(next, &w->panes, entry) {
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
if (next == wp)
|
2010-03-22 19:07:52 +00:00
|
|
|
continue;
|
2014-05-08 06:03:30 +00:00
|
|
|
if (next->yoff + next->sy + 1 != edge)
|
2010-03-22 19:07:52 +00:00
|
|
|
continue;
|
2014-05-08 06:03:30 +00:00
|
|
|
end = next->xoff + next->sx - 1;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
if (next->xoff < left && end > right)
|
|
|
|
found = 1;
|
|
|
|
else if (next->xoff >= left && next->xoff <= right)
|
|
|
|
found = 1;
|
|
|
|
else if (end >= left && end <= right)
|
|
|
|
found = 1;
|
2015-04-25 18:56:05 +00:00
|
|
|
if (!found)
|
|
|
|
continue;
|
|
|
|
list = xreallocarray(list, size + 1, sizeof *list);
|
|
|
|
list[size++] = next;
|
2010-03-22 19:07:52 +00:00
|
|
|
}
|
2014-05-08 06:03:30 +00:00
|
|
|
|
2015-04-25 18:56:05 +00:00
|
|
|
best = window_pane_choose_best(list, size);
|
|
|
|
free(list);
|
2014-05-08 06:03:30 +00:00
|
|
|
return (best);
|
2010-03-22 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the pane directly below another. */
|
|
|
|
struct window_pane *
|
|
|
|
window_pane_find_down(struct window_pane *wp)
|
|
|
|
{
|
2019-06-26 13:03:47 +00:00
|
|
|
struct window *w;
|
2015-04-25 18:56:05 +00:00
|
|
|
struct window_pane *next, *best, **list;
|
|
|
|
u_int edge, left, right, end, size;
|
2017-03-21 09:49:10 +00:00
|
|
|
int status, found;
|
2010-03-22 19:07:52 +00:00
|
|
|
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
if (wp == NULL)
|
2010-03-22 19:07:52 +00:00
|
|
|
return (NULL);
|
2019-06-26 13:03:47 +00:00
|
|
|
w = wp->window;
|
|
|
|
status = options_get_number(w->options, "pane-border-status");
|
2015-04-25 18:56:05 +00:00
|
|
|
|
|
|
|
list = NULL;
|
|
|
|
size = 0;
|
2014-05-08 06:03:30 +00:00
|
|
|
|
|
|
|
edge = wp->yoff + wp->sy + 1;
|
2019-06-26 13:03:47 +00:00
|
|
|
if (status == PANE_STATUS_TOP) {
|
|
|
|
if (edge >= w->sy)
|
|
|
|
edge = 1;
|
|
|
|
} else if (status == PANE_STATUS_BOTTOM) {
|
|
|
|
if (edge >= w->sy - 1)
|
|
|
|
edge = 0;
|
|
|
|
} else {
|
2019-06-26 18:44:22 +00:00
|
|
|
if (edge >= w->sy)
|
2019-06-26 13:03:47 +00:00
|
|
|
edge = 0;
|
|
|
|
}
|
2010-03-22 19:07:52 +00:00
|
|
|
|
|
|
|
left = wp->xoff;
|
2014-05-08 06:03:30 +00:00
|
|
|
right = wp->xoff + wp->sx;
|
2010-03-22 19:07:52 +00:00
|
|
|
|
2019-06-26 13:03:47 +00:00
|
|
|
TAILQ_FOREACH(next, &w->panes, entry) {
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
if (next == wp)
|
2010-03-22 19:07:52 +00:00
|
|
|
continue;
|
2014-05-08 06:03:30 +00:00
|
|
|
if (next->yoff != edge)
|
2010-03-22 19:07:52 +00:00
|
|
|
continue;
|
2014-05-08 06:03:30 +00:00
|
|
|
end = next->xoff + next->sx - 1;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
if (next->xoff < left && end > right)
|
|
|
|
found = 1;
|
|
|
|
else if (next->xoff >= left && next->xoff <= right)
|
|
|
|
found = 1;
|
|
|
|
else if (end >= left && end <= right)
|
|
|
|
found = 1;
|
2015-04-25 18:56:05 +00:00
|
|
|
if (!found)
|
|
|
|
continue;
|
|
|
|
list = xreallocarray(list, size + 1, sizeof *list);
|
|
|
|
list[size++] = next;
|
2010-03-22 19:07:52 +00:00
|
|
|
}
|
2014-05-08 06:03:30 +00:00
|
|
|
|
2015-04-25 18:56:05 +00:00
|
|
|
best = window_pane_choose_best(list, size);
|
|
|
|
free(list);
|
2014-05-08 06:03:30 +00:00
|
|
|
return (best);
|
2010-03-22 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
2014-05-08 06:03:30 +00:00
|
|
|
/* Find the pane directly to the left of another. */
|
2010-03-22 19:07:52 +00:00
|
|
|
struct window_pane *
|
|
|
|
window_pane_find_left(struct window_pane *wp)
|
|
|
|
{
|
2019-06-26 13:03:47 +00:00
|
|
|
struct window *w;
|
2015-04-25 18:56:05 +00:00
|
|
|
struct window_pane *next, *best, **list;
|
|
|
|
u_int edge, top, bottom, end, size;
|
2014-05-08 06:03:30 +00:00
|
|
|
int found;
|
2010-03-22 19:07:52 +00:00
|
|
|
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
if (wp == NULL)
|
2010-03-22 19:07:52 +00:00
|
|
|
return (NULL);
|
2019-06-26 13:03:47 +00:00
|
|
|
w = wp->window;
|
2015-04-25 18:56:05 +00:00
|
|
|
|
|
|
|
list = NULL;
|
|
|
|
size = 0;
|
2014-05-08 06:03:30 +00:00
|
|
|
|
|
|
|
edge = wp->xoff;
|
|
|
|
if (edge == 0)
|
2019-06-26 13:03:47 +00:00
|
|
|
edge = w->sx + 1;
|
2010-03-22 19:07:52 +00:00
|
|
|
|
|
|
|
top = wp->yoff;
|
2014-05-08 06:03:30 +00:00
|
|
|
bottom = wp->yoff + wp->sy;
|
2010-03-22 19:07:52 +00:00
|
|
|
|
2019-06-26 13:03:47 +00:00
|
|
|
TAILQ_FOREACH(next, &w->panes, entry) {
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
if (next == wp)
|
2010-03-22 19:07:52 +00:00
|
|
|
continue;
|
2014-05-08 06:03:30 +00:00
|
|
|
if (next->xoff + next->sx + 1 != edge)
|
2010-03-22 19:07:52 +00:00
|
|
|
continue;
|
2014-05-08 06:03:30 +00:00
|
|
|
end = next->yoff + next->sy - 1;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
if (next->yoff < top && end > bottom)
|
|
|
|
found = 1;
|
|
|
|
else if (next->yoff >= top && next->yoff <= bottom)
|
|
|
|
found = 1;
|
|
|
|
else if (end >= top && end <= bottom)
|
|
|
|
found = 1;
|
2015-04-25 18:56:05 +00:00
|
|
|
if (!found)
|
|
|
|
continue;
|
|
|
|
list = xreallocarray(list, size + 1, sizeof *list);
|
|
|
|
list[size++] = next;
|
2010-03-22 19:07:52 +00:00
|
|
|
}
|
2014-05-08 06:03:30 +00:00
|
|
|
|
2015-04-25 18:56:05 +00:00
|
|
|
best = window_pane_choose_best(list, size);
|
|
|
|
free(list);
|
2014-05-08 06:03:30 +00:00
|
|
|
return (best);
|
2010-03-22 19:07:52 +00:00
|
|
|
}
|
|
|
|
|
2014-05-08 06:03:30 +00:00
|
|
|
/* Find the pane directly to the right of another. */
|
2010-03-22 19:07:52 +00:00
|
|
|
struct window_pane *
|
|
|
|
window_pane_find_right(struct window_pane *wp)
|
|
|
|
{
|
2019-06-26 13:03:47 +00:00
|
|
|
struct window *w;
|
2015-04-25 18:56:05 +00:00
|
|
|
struct window_pane *next, *best, **list;
|
|
|
|
u_int edge, top, bottom, end, size;
|
2014-05-08 06:03:30 +00:00
|
|
|
int found;
|
2010-03-22 19:07:52 +00:00
|
|
|
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
if (wp == NULL)
|
2010-03-22 19:07:52 +00:00
|
|
|
return (NULL);
|
2019-06-26 13:03:47 +00:00
|
|
|
w = wp->window;
|
2015-04-25 18:56:05 +00:00
|
|
|
|
|
|
|
list = NULL;
|
|
|
|
size = 0;
|
2014-05-08 06:03:30 +00:00
|
|
|
|
|
|
|
edge = wp->xoff + wp->sx + 1;
|
2019-06-26 13:03:47 +00:00
|
|
|
if (edge >= w->sx)
|
2014-05-08 06:03:30 +00:00
|
|
|
edge = 0;
|
2010-03-22 19:07:52 +00:00
|
|
|
|
|
|
|
top = wp->yoff;
|
2014-05-08 06:03:30 +00:00
|
|
|
bottom = wp->yoff + wp->sy;
|
2010-03-22 19:07:52 +00:00
|
|
|
|
2019-06-26 13:03:47 +00:00
|
|
|
TAILQ_FOREACH(next, &w->panes, entry) {
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
if (next == wp)
|
2010-03-22 19:07:52 +00:00
|
|
|
continue;
|
2014-05-08 06:03:30 +00:00
|
|
|
if (next->xoff != edge)
|
2010-03-22 19:07:52 +00:00
|
|
|
continue;
|
2014-05-08 06:03:30 +00:00
|
|
|
end = next->yoff + next->sy - 1;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
if (next->yoff < top && end > bottom)
|
|
|
|
found = 1;
|
|
|
|
else if (next->yoff >= top && next->yoff <= bottom)
|
|
|
|
found = 1;
|
|
|
|
else if (end >= top && end <= bottom)
|
|
|
|
found = 1;
|
2015-04-25 18:56:05 +00:00
|
|
|
if (!found)
|
|
|
|
continue;
|
|
|
|
list = xreallocarray(list, size + 1, sizeof *list);
|
|
|
|
list[size++] = next;
|
2010-03-22 19:07:52 +00:00
|
|
|
}
|
2014-05-08 06:03:30 +00:00
|
|
|
|
2015-04-25 18:56:05 +00:00
|
|
|
best = window_pane_choose_best(list, size);
|
|
|
|
free(list);
|
2014-05-08 06:03:30 +00:00
|
|
|
return (best);
|
2010-03-22 19:07:52 +00:00
|
|
|
}
|
2012-07-08 07:27:32 +00:00
|
|
|
|
2023-07-10 09:24:53 +00:00
|
|
|
void
|
|
|
|
window_pane_stack_push(struct window_panes *stack, struct window_pane *wp)
|
|
|
|
{
|
|
|
|
if (wp != NULL) {
|
|
|
|
window_pane_stack_remove(stack, wp);
|
|
|
|
TAILQ_INSERT_HEAD(stack, wp, sentry);
|
|
|
|
wp->flags |= PANE_VISITED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_pane_stack_remove(struct window_panes *stack, struct window_pane *wp)
|
|
|
|
{
|
|
|
|
if (wp != NULL && (wp->flags & PANE_VISITED)) {
|
|
|
|
TAILQ_REMOVE(stack, wp, sentry);
|
|
|
|
wp->flags &= ~PANE_VISITED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-08 07:27:32 +00:00
|
|
|
/* Clear alert flags for a winlink */
|
|
|
|
void
|
|
|
|
winlink_clear_flags(struct winlink *wl)
|
|
|
|
{
|
2016-10-19 09:22:07 +00:00
|
|
|
struct winlink *loop;
|
2012-07-08 07:27:32 +00:00
|
|
|
|
2016-10-19 09:22:07 +00:00
|
|
|
wl->window->flags &= ~WINDOW_ALERTFLAGS;
|
|
|
|
TAILQ_FOREACH(loop, &wl->window->winlinks, wentry) {
|
|
|
|
if ((loop->flags & WINLINK_ALERTFLAGS) != 0) {
|
|
|
|
loop->flags &= ~WINLINK_ALERTFLAGS;
|
|
|
|
server_status_session(loop->session);
|
2012-07-08 07:27:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-17 16:50:28 +00:00
|
|
|
|
2017-02-22 09:01:32 +00:00
|
|
|
/* Shuffle window indexes up. */
|
2015-06-17 16:50:28 +00:00
|
|
|
int
|
2020-06-13 09:05:53 +00:00
|
|
|
winlink_shuffle_up(struct session *s, struct winlink *wl, int before)
|
2015-06-17 16:50:28 +00:00
|
|
|
{
|
|
|
|
int idx, last;
|
|
|
|
|
2019-04-17 14:37:48 +00:00
|
|
|
if (wl == NULL)
|
|
|
|
return (-1);
|
2020-06-13 09:05:53 +00:00
|
|
|
if (before)
|
|
|
|
idx = wl->idx;
|
|
|
|
else
|
|
|
|
idx = wl->idx + 1;
|
2015-06-17 16:50:28 +00:00
|
|
|
|
|
|
|
/* Find the next free index. */
|
|
|
|
for (last = idx; last < INT_MAX; last++) {
|
|
|
|
if (winlink_find_by_index(&s->windows, last) == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (last == INT_MAX)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
/* Move everything from last - 1 to idx up a bit. */
|
|
|
|
for (; last > idx; last--) {
|
|
|
|
wl = winlink_find_by_index(&s->windows, last - 1);
|
2020-06-13 09:05:53 +00:00
|
|
|
RB_REMOVE(winlinks, &s->windows, wl);
|
|
|
|
wl->idx++;
|
|
|
|
RB_INSERT(winlinks, &s->windows, wl);
|
2015-06-17 16:50:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (idx);
|
|
|
|
}
|
2019-05-03 20:44:24 +00:00
|
|
|
|
|
|
|
static void
|
2019-12-12 11:39:56 +00:00
|
|
|
window_pane_input_callback(struct client *c, __unused const char *path,
|
|
|
|
int error, int closed, struct evbuffer *buffer, void *data)
|
2019-05-03 20:44:24 +00:00
|
|
|
{
|
|
|
|
struct window_pane_input_data *cdata = data;
|
|
|
|
struct window_pane *wp;
|
2019-12-12 11:39:56 +00:00
|
|
|
u_char *buf = EVBUFFER_DATA(buffer);
|
|
|
|
size_t len = EVBUFFER_LENGTH(buffer);
|
2019-05-03 20:44:24 +00:00
|
|
|
|
|
|
|
wp = window_pane_find_by_id(cdata->wp);
|
2023-01-06 07:09:27 +00:00
|
|
|
if (cdata->file != NULL && (wp == NULL || c->flags & CLIENT_DEAD)) {
|
2023-01-08 22:17:04 +00:00
|
|
|
if (wp == NULL) {
|
|
|
|
c->retval = 1;
|
2019-09-10 19:35:34 +00:00
|
|
|
c->flags |= CLIENT_EXIT;
|
2023-01-08 22:17:04 +00:00
|
|
|
}
|
2023-01-06 07:09:27 +00:00
|
|
|
file_cancel(cdata->file);
|
|
|
|
} else if (cdata->file == NULL || closed || error != 0) {
|
2019-06-18 11:08:42 +00:00
|
|
|
cmdq_continue(cdata->item);
|
2019-12-12 11:39:56 +00:00
|
|
|
server_client_unref(c);
|
|
|
|
free(cdata);
|
2023-01-06 07:09:27 +00:00
|
|
|
} else
|
|
|
|
input_parse_buffer(wp, buf, len);
|
2019-12-12 11:39:56 +00:00
|
|
|
evbuffer_drain(buffer, len);
|
2019-05-03 20:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
window_pane_start_input(struct window_pane *wp, struct cmdq_item *item,
|
|
|
|
char **cause)
|
|
|
|
{
|
2020-04-13 10:59:58 +00:00
|
|
|
struct client *c = cmdq_get_client(item);
|
2019-05-03 20:44:24 +00:00
|
|
|
struct window_pane_input_data *cdata;
|
|
|
|
|
|
|
|
if (~wp->flags & PANE_EMPTY) {
|
|
|
|
*cause = xstrdup("pane is not empty");
|
|
|
|
return (-1);
|
|
|
|
}
|
2021-10-07 07:52:13 +00:00
|
|
|
if (c->flags & (CLIENT_DEAD|CLIENT_EXITED))
|
|
|
|
return (1);
|
|
|
|
if (c->session != NULL)
|
|
|
|
return (1);
|
2019-05-03 20:44:24 +00:00
|
|
|
|
|
|
|
cdata = xmalloc(sizeof *cdata);
|
|
|
|
cdata->item = item;
|
|
|
|
cdata->wp = wp->id;
|
2023-01-06 07:09:27 +00:00
|
|
|
cdata->file = file_read(c, "-", window_pane_input_callback, cdata);
|
2019-12-12 11:39:56 +00:00
|
|
|
c->references++;
|
|
|
|
|
|
|
|
return (0);
|
2019-05-03 20:44:24 +00:00
|
|
|
}
|
2020-05-21 07:24:13 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
window_pane_get_new_data(struct window_pane *wp,
|
|
|
|
struct window_pane_offset *wpo, size_t *size)
|
|
|
|
{
|
|
|
|
size_t used = wpo->used - wp->base_offset;
|
|
|
|
|
|
|
|
*size = EVBUFFER_LENGTH(wp->event->input) - used;
|
|
|
|
return (EVBUFFER_DATA(wp->event->input) + used);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_pane_update_used_data(struct window_pane *wp,
|
2020-06-01 09:43:00 +00:00
|
|
|
struct window_pane_offset *wpo, size_t size)
|
2020-05-21 07:24:13 +00:00
|
|
|
{
|
|
|
|
size_t used = wpo->used - wp->base_offset;
|
|
|
|
|
|
|
|
if (size > EVBUFFER_LENGTH(wp->event->input) - used)
|
|
|
|
size = EVBUFFER_LENGTH(wp->event->input) - used;
|
|
|
|
wpo->used += size;
|
|
|
|
}
|
2022-03-16 17:00:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
window_set_fill_character(struct window *w)
|
|
|
|
{
|
|
|
|
const char *value;
|
|
|
|
struct utf8_data *ud;
|
|
|
|
|
|
|
|
free(w->fill_character);
|
|
|
|
w->fill_character = NULL;
|
|
|
|
|
|
|
|
value = options_get_string(w->options, "fill-character");
|
|
|
|
if (*value != '\0' && utf8_isvalid(value)) {
|
|
|
|
ud = utf8_fromcstr(value);
|
|
|
|
if (ud != NULL && ud[0].width == 1)
|
|
|
|
w->fill_character = ud;
|
|
|
|
}
|
|
|
|
}
|
2022-06-17 07:28:05 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
window_pane_default_cursor(struct window_pane *wp)
|
|
|
|
{
|
2024-10-01 08:01:19 +00:00
|
|
|
screen_set_default_cursor(wp->screen, wp->options);
|
2022-06-17 07:28:05 +00:00
|
|
|
}
|
2024-08-26 07:14:40 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
window_pane_mode(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
if (TAILQ_FIRST(&wp->modes) != NULL) {
|
|
|
|
if (TAILQ_FIRST(&wp->modes)->mode == &window_copy_mode)
|
|
|
|
return (WINDOW_PANE_COPY_MODE);
|
|
|
|
if (TAILQ_FIRST(&wp->modes)->mode == &window_view_mode)
|
|
|
|
return (WINDOW_PANE_VIEW_MODE);
|
|
|
|
}
|
|
|
|
return (WINDOW_PANE_NO_MODE);
|
|
|
|
}
|
2024-11-15 09:01:16 +00:00
|
|
|
|
|
|
|
/* Return 1 if scrollbar is or should be displayed. */
|
|
|
|
int
|
|
|
|
window_pane_show_scrollbar(struct window_pane *wp, int sb_option)
|
|
|
|
{
|
|
|
|
if (SCREEN_IS_ALTERNATE(wp->screen))
|
|
|
|
return (0);
|
|
|
|
if (sb_option == PANE_SCROLLBARS_ALWAYS ||
|
|
|
|
(sb_option == PANE_SCROLLBARS_MODAL &&
|
|
|
|
window_pane_mode(wp) != WINDOW_PANE_NO_MODE))
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|