2014-11-08 12:27:43 +00:00
|
|
|
/* $OpenBSD$ */
|
2007-07-09 19:04:12 +00:00
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2007-07-09 19:04:12 +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>
|
2007-07-09 19:04:12 +00:00
|
|
|
|
2019-06-24 08:20:02 +00:00
|
|
|
#include <ctype.h>
|
2009-01-23 16:59:14 +00:00
|
|
|
#include <errno.h>
|
2007-07-09 19:04:12 +00:00
|
|
|
#include <fcntl.h>
|
2009-06-25 16:04:24 +00:00
|
|
|
#include <fnmatch.h>
|
2019-06-13 19:46:00 +00:00
|
|
|
#include <regex.h>
|
2017-06-04 10:23:48 +00:00
|
|
|
#include <signal.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <stdint.h>
|
2007-07-09 19:04:12 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-06-16 10:55:47 +00:00
|
|
|
#include <time.h>
|
2007-07-09 19:04:12 +00:00
|
|
|
#include <unistd.h>
|
2007-10-19 20:47:09 +00:00
|
|
|
|
2009-05-13 23:27:00 +00:00
|
|
|
#include "tmux.h"
|
|
|
|
|
2007-07-09 19:04:12 +00:00
|
|
|
/*
|
2009-07-20 15:42:05 +00:00
|
|
|
* Each window is attached to a number of panes, each of which is a pty. This
|
2009-01-11 23:31:46 +00:00
|
|
|
* file contains code to handle them.
|
2007-07-09 19:04:12 +00:00
|
|
|
*
|
2009-01-11 23:31:46 +00:00
|
|
|
* A pane has two buffers attached, these are filled and emptied by the main
|
2007-08-27 10:08:44 +00:00
|
|
|
* server poll loop. Output data is received from pty's in screen format,
|
2007-11-07 19:41:17 +00:00
|
|
|
* 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
|
2008-01-02 19:22:21 +00:00
|
|
|
* directly via input_key.
|
2007-07-09 19:04:12 +00:00
|
|
|
*
|
2009-01-11 23:31:46 +00:00
|
|
|
* 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.
|
2007-07-09 19:04:12 +00:00
|
|
|
*
|
2007-10-26 12:29:07 +00:00
|
|
|
* Windows are stored directly on a global array and wrapped in any number of
|
2007-11-07 19:41:17 +00:00
|
|
|
* winlink structs to be linked onto local session RB trees. A reference count
|
2007-10-26 12:29:07 +00:00
|
|
|
* is maintained and a window removed from the global list and destroyed when
|
2007-11-07 19:41:17 +00:00
|
|
|
* it reaches zero.
|
2007-07-09 19:04:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Global window list. */
|
2007-10-26 12:29:07 +00:00
|
|
|
struct windows windows;
|
|
|
|
|
2011-04-06 22:16:33 +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;
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-10-26 12:29:07 +00:00
|
|
|
int
|
|
|
|
winlink_cmp(struct winlink *wl1, struct winlink *wl2)
|
|
|
|
{
|
|
|
|
return (wl1->idx - wl2->idx);
|
|
|
|
}
|
|
|
|
|
2011-04-06 22:16:33 +00:00
|
|
|
int
|
|
|
|
window_pane_cmp(struct window_pane *wp1, struct window_pane *wp2)
|
|
|
|
{
|
|
|
|
return (wp1->id - wp2->id);
|
|
|
|
}
|
|
|
|
|
2009-07-15 17:45:09 +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);
|
|
|
|
}
|
|
|
|
|
2007-10-26 12:29:07 +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-31 12:01:43 +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-10 09:54:29 +00:00
|
|
|
return (NULL);
|
2012-01-31 12:01:43 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static int
|
2009-08-16 19:16:27 +00:00
|
|
|
winlink_next_index(struct winlinks *wwl, int idx)
|
2007-10-26 12:29:07 +00:00
|
|
|
{
|
2009-08-16 19:16:27 +00:00
|
|
|
int i;
|
2007-10-26 12:29:07 +00:00
|
|
|
|
2009-08-16 19:16:27 +00:00
|
|
|
i = idx;
|
|
|
|
do {
|
2007-10-26 12:29:07 +00:00
|
|
|
if (winlink_find_by_index(wwl, i) == NULL)
|
|
|
|
return (i);
|
2009-08-16 19:16:27 +00:00
|
|
|
if (i == INT_MAX)
|
|
|
|
i = 0;
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
} while (i != idx);
|
|
|
|
return (-1);
|
2007-10-26 12:29:07 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 14:43:43 +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);
|
|
|
|
}
|
|
|
|
|
2007-10-26 12:29:07 +00:00
|
|
|
struct winlink *
|
2011-02-15 15:09:52 +00:00
|
|
|
winlink_add(struct winlinks *wwl, int idx)
|
2007-10-26 12:29:07 +00:00
|
|
|
{
|
|
|
|
struct winlink *wl;
|
|
|
|
|
2009-08-16 19:16:27 +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)
|
2007-10-26 12:29:07 +00:00
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
wl = xcalloc(1, sizeof *wl);
|
|
|
|
wl->idx = idx;
|
|
|
|
RB_INSERT(winlinks, wwl, wl);
|
|
|
|
|
|
|
|
return (wl);
|
|
|
|
}
|
|
|
|
|
2011-02-15 15:09:52 +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-02-15 15:09:52 +00:00
|
|
|
wl->window = w;
|
2017-04-28 19:13:55 +00:00
|
|
|
window_add_ref(w, __func__);
|
2011-02-15 15:09:52 +00:00
|
|
|
}
|
|
|
|
|
2007-10-26 12:29:07 +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
|
|
|
}
|
|
|
|
|
2007-10-26 12:29:07 +00:00
|
|
|
RB_REMOVE(winlinks, wwl, wl);
|
2012-07-11 19:34:16 +00:00
|
|
|
free(wl);
|
2007-10-26 12:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct winlink *
|
2009-11-28 14:50:37 +00:00
|
|
|
winlink_next(struct winlink *wl)
|
2007-10-26 12:29:07 +00:00
|
|
|
{
|
|
|
|
return (RB_NEXT(winlinks, wwl, wl));
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
2007-10-26 12:29:07 +00:00
|
|
|
|
|
|
|
struct winlink *
|
2009-11-28 14:50:37 +00:00
|
|
|
winlink_previous(struct winlink *wl)
|
2007-10-26 12:29:07 +00:00
|
|
|
{
|
2008-06-03 18:38:51 +00:00
|
|
|
return (RB_PREV(winlinks, wwl, wl));
|
2007-12-06 09:46:23 +00:00
|
|
|
}
|
2007-07-09 19:04:12 +00:00
|
|
|
|
2010-06-22 23:29:05 +00:00
|
|
|
struct winlink *
|
2010-07-17 14:38:13 +00:00
|
|
|
winlink_next_by_number(struct winlink *wl, struct session *s, int n)
|
2010-06-22 23:29:05 +00:00
|
|
|
{
|
|
|
|
for (; n > 0; n--) {
|
|
|
|
if ((wl = RB_NEXT(winlinks, wwl, wl)) == NULL)
|
2010-07-17 14:38:13 +00:00
|
|
|
wl = RB_MIN(winlinks, &s->windows);
|
2010-06-22 23:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (wl);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct winlink *
|
2010-07-17 14:38:13 +00:00
|
|
|
winlink_previous_by_number(struct winlink *wl, struct session *s, int n)
|
2010-06-22 23:29:05 +00:00
|
|
|
{
|
|
|
|
for (; n > 0; n--) {
|
|
|
|
if ((wl = RB_PREV(winlinks, wwl, wl)) == NULL)
|
2010-07-17 14:38:13 +00:00
|
|
|
wl = RB_MAX(winlinks, &s->windows);
|
2010-06-22 23:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (wl);
|
|
|
|
}
|
|
|
|
|
2008-11-16 10:10:26 +00:00
|
|
|
void
|
|
|
|
winlink_stack_push(struct winlink_stack *stack, struct winlink *wl)
|
|
|
|
{
|
|
|
|
if (wl == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
winlink_stack_remove(stack, wl);
|
2009-10-11 23:38:16 +00:00
|
|
|
TAILQ_INSERT_HEAD(stack, wl, sentry);
|
2008-11-16 10:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
winlink_stack_remove(struct winlink_stack *stack, struct winlink *wl)
|
|
|
|
{
|
|
|
|
struct winlink *wl2;
|
|
|
|
|
|
|
|
if (wl == NULL)
|
|
|
|
return;
|
2009-12-04 22:14:47 +00:00
|
|
|
|
2009-10-11 23:38:16 +00:00
|
|
|
TAILQ_FOREACH(wl2, stack, sentry) {
|
2008-11-16 10:10:26 +00:00
|
|
|
if (wl2 == wl) {
|
2009-10-11 23:38:16 +00:00
|
|
|
TAILQ_REMOVE(stack, wl, sentry);
|
2008-11-16 10:10:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-31 12:01:43 +00:00
|
|
|
struct window *
|
|
|
|
window_find_by_id(u_int id)
|
|
|
|
{
|
2015-04-22 15:30:11 +00:00
|
|
|
struct window w;
|
2012-01-31 12:01:43 +00:00
|
|
|
|
2015-04-22 15:30:11 +00:00
|
|
|
w.id = id;
|
|
|
|
return (RB_FIND(windows, &windows, &w));
|
2012-01-31 12:01:43 +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);
|
|
|
|
}
|
|
|
|
|
2007-07-09 19:04:12 +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)
|
2007-07-09 19:04:12 +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-08 23:22:24 +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-01-14 19:29:32 +00:00
|
|
|
|
|
|
|
TAILQ_INIT(&w->panes);
|
|
|
|
w->active = NULL;
|
2009-01-11 23:31:46 +00:00
|
|
|
|
2009-07-28 23:04:29 +00:00
|
|
|
w->lastlayout = -1;
|
2009-07-20 15:42:05 +00:00
|
|
|
w->layout_root = NULL;
|
2009-12-04 22:14:47 +00:00
|
|
|
|
2009-01-11 23:31:46 +00:00
|
|
|
w->sx = sx;
|
|
|
|
w->sy = sy;
|
2019-11-28 09:45:15 +00:00
|
|
|
w->xpixel = xpixel;
|
|
|
|
w->ypixel = ypixel;
|
2008-06-29 07:04:31 +00:00
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
w->options = options_create(global_w_options);
|
2007-07-09 19:04:12 +00:00
|
|
|
|
2007-10-26 12:29:07 +00:00
|
|
|
w->references = 0;
|
2016-10-19 09:22:07 +00:00
|
|
|
TAILQ_INIT(&w->winlinks);
|
2007-07-09 19:04:12 +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
|
|
|
|
2015-08-29 08:30:54 +00:00
|
|
|
window_update_activity(w);
|
|
|
|
|
2009-03-07 09:29:54 +00:00
|
|
|
return (w);
|
|
|
|
}
|
|
|
|
|
2019-06-30 19:21:53 +00:00
|
|
|
static void
|
2009-01-11 23:31:46 +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
|
|
|
|
2015-04-22 15:30:11 +00:00
|
|
|
RB_REMOVE(windows, &windows, w);
|
2009-01-11 23:31:46 +00:00
|
|
|
|
2009-07-20 15:42:05 +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-20 15:42:05 +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 the client.
This adds 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. 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).
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-width -x or -y.
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 higher memory use if you make a window that big. The
minimum size is the size required for the current layout including
borders.
This change allows some code improvements, most notably that since
windows can now never be cropped, that code can be removed from the
layout code, and since panes can now never be outside the size of the
window, window_pane_visible can be removed.
2018-08-20 14:22:14 +00:00
|
|
|
if (event_initialized(&w->offset_timer))
|
|
|
|
event_del(&w->offset_timer);
|
2009-11-08 23:22:24 +00:00
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
options_free(w->options);
|
2009-01-11 23:31:46 +00:00
|
|
|
|
2012-07-11 19:34:16 +00:00
|
|
|
free(w->name);
|
|
|
|
free(w);
|
2009-01-11 23:31:46 +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-31 09:22:08 +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-31 09:22:08 +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-31 09:22:08 +00:00
|
|
|
if (w->references == 0)
|
|
|
|
window_destroy(w);
|
|
|
|
}
|
|
|
|
|
2012-02-02 02:00:12 +00:00
|
|
|
void
|
|
|
|
window_set_name(struct window *w, const char *new_name)
|
|
|
|
{
|
2012-07-11 19:34:16 +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 02:00:12 +00:00
|
|
|
}
|
|
|
|
|
2009-07-22 17:46:53 +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-01-11 23:31:46 +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-01-14 19:29:32 +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
|
2020-06-05 11:20:51 +00:00
|
|
|
window_pane_send_resize(struct window_pane *wp, int force)
|
2019-11-28 09:45:15 +00:00
|
|
|
{
|
|
|
|
struct window *w = wp->window;
|
|
|
|
struct winsize ws;
|
2020-06-05 11:20:51 +00:00
|
|
|
u_int sy;
|
2019-11-28 09:45:15 +00:00
|
|
|
|
|
|
|
if (wp->fd == -1)
|
|
|
|
return;
|
2020-06-05 11:20:51 +00:00
|
|
|
|
|
|
|
if (!force)
|
|
|
|
sy = wp->sy;
|
|
|
|
else if (wp->sy <= 1)
|
|
|
|
sy = wp->sy + 1;
|
|
|
|
else
|
|
|
|
sy = wp->sy - 1;
|
2020-05-16 13:57:36 +00:00
|
|
|
log_debug("%s: %%%u resize to %u,%u", __func__, wp->id, wp->sx, sy);
|
2019-11-28 09:45:15 +00:00
|
|
|
|
|
|
|
memset(&ws, 0, sizeof ws);
|
|
|
|
ws.ws_col = wp->sx;
|
2020-05-16 13:57:36 +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)
|
2019-11-28 12:30:43 +00:00
|
|
|
#ifdef __sun
|
|
|
|
/*
|
|
|
|
* Some versions of Solaris apparently can return an error when
|
|
|
|
* resizing; don't know why this happens, can't reproduce on
|
|
|
|
* other platforms and ignoring it doesn't seem to cause any
|
|
|
|
* issues.
|
|
|
|
*/
|
|
|
|
if (errno != EINVAL && errno != ENXIO)
|
|
|
|
#endif
|
2019-11-28 09:45:15 +00:00
|
|
|
fatal("ioctl failed");
|
2009-01-14 19:29:32 +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);
|
|
|
|
}
|
|
|
|
|
2014-10-21 22:22:04 +00:00
|
|
|
int
|
2019-04-07 12:01:03 +00:00
|
|
|
window_set_active_pane(struct window *w, struct window_pane *wp, int notify)
|
2009-01-14 19:29:32 +00:00
|
|
|
{
|
2019-04-07 12:01:03 +00:00
|
|
|
log_debug("%s: pane %%%u", __func__, wp->id);
|
|
|
|
|
2010-12-06 21:53:50 +00:00
|
|
|
if (wp == w->active)
|
2014-10-21 22:22:04 +00:00
|
|
|
return (0);
|
2010-10-24 01:34:30 +00:00
|
|
|
w->last = w->active;
|
2019-04-07 12:01:03 +00:00
|
|
|
|
2009-01-14 19:29:32 +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-07 12:01:03 +00:00
|
|
|
|
Support for windows larger than the client.
This adds 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. 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).
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-width -x or -y.
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 higher memory use if you make a window that big. The
minimum size is the size required for the current layout including
borders.
This change allows some code improvements, most notably that since
windows can now never be cropped, that code can be removed from the
layout code, and since panes can now never be outside the size of the
window, window_pane_visible can be removed.
2018-08-20 14:22:14 +00:00
|
|
|
tty_update_window_offset(w);
|
2019-04-07 12:01:03 +00:00
|
|
|
|
|
|
|
if (notify)
|
|
|
|
notify_window("window-pane-changed", w);
|
2014-10-21 22:22:04 +00:00
|
|
|
return (1);
|
2009-01-14 19:29:32 +00:00
|
|
|
}
|
|
|
|
|
2015-09-14 11:34:50 +00:00
|
|
|
void
|
|
|
|
window_redraw_active_switch(struct window *w, struct window_pane *wp)
|
|
|
|
{
|
2020-04-27 14:15:12 +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-04-27 14:15:12 +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-04-27 14:15:12 +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-04-27 14:15:12 +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-23 19:21:26 +00:00
|
|
|
struct window_pane *
|
|
|
|
window_get_active_at(struct window *w, u_int x, u_int y)
|
2009-10-11 23:46:02 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
2019-03-12 13:56:30 +00:00
|
|
|
if (!window_pane_visible(wp))
|
|
|
|
continue;
|
2011-06-23 19:21:26 +00:00
|
|
|
if (x < wp->xoff || x > wp->xoff + wp->sx)
|
2009-10-11 23:46:02 +00:00
|
|
|
continue;
|
2011-06-23 19:21:26 +00:00
|
|
|
if (y < wp->yoff || y > wp->yoff + wp->sy)
|
2009-10-11 23:46:02 +00:00
|
|
|
continue;
|
2011-06-23 19:21:26 +00:00
|
|
|
return (wp);
|
2009-10-11 23:46:02 +00:00
|
|
|
}
|
2011-06-23 19:21:26 +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-23 19:21:26 +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-23 19:21:26 +00:00
|
|
|
if (strcasecmp(s, "top") == 0)
|
2020-02-14 13:57:58 +00:00
|
|
|
y = top;
|
2011-06-23 19:21:26 +00:00
|
|
|
else if (strcasecmp(s, "bottom") == 0)
|
2020-02-14 13:57:58 +00:00
|
|
|
y = bottom;
|
2011-06-23 19:21:26 +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-23 19:21:26 +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-23 19:21:26 +00:00
|
|
|
} else if (strcasecmp(s, "bottom-left") == 0) {
|
|
|
|
x = 0;
|
2020-02-14 13:57:58 +00:00
|
|
|
y = bottom;
|
2011-06-23 19:21:26 +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-23 19:21:26 +00:00
|
|
|
} else
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
return (window_get_active_at(w, x, y));
|
2009-10-11 23:46:02 +00:00
|
|
|
}
|
|
|
|
|
2013-02-24 00:25:03 +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-12 12:18:52 +00:00
|
|
|
if (window_count_panes(w) == 1)
|
|
|
|
return (-1);
|
|
|
|
|
2013-02-24 00:25:03 +00:00
|
|
|
if (w->active != wp)
|
2019-04-07 12:01:03 +00:00
|
|
|
window_set_active_pane(w, wp, 1);
|
2013-02-24 00:25:03 +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-02-24 00:25:03 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
window_unzoom(struct window *w)
|
|
|
|
{
|
2013-03-26 10:54:48 +00:00
|
|
|
struct window_pane *wp;
|
2013-02-24 00:25:03 +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-02-24 00:25:03 +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-02-24 00:25:03 +00:00
|
|
|
}
|
2021-03-11 06:31:05 +00:00
|
|
|
layout_fix_panes(w, NULL);
|
2016-10-16 22:06:40 +00:00
|
|
|
notify_window("window-layout-changed", w);
|
2013-02-24 00:25:03 +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;
|
|
|
|
return (window_unzoom(w) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-14 19:29:32 +00:00
|
|
|
struct window_pane *
|
2019-04-07 12:01:03 +00:00
|
|
|
window_add_pane(struct window *w, struct window_pane *other, u_int hlimit,
|
|
|
|
int flags)
|
2009-01-12 18:22:47 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
|
2017-02-27 13:07:57 +00:00
|
|
|
if (other == NULL)
|
|
|
|
other = w->active;
|
|
|
|
|
2009-07-20 15:42:05 +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-01-14 19:29:32 +00:00
|
|
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
2019-04-07 12:01:03 +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-07 12:01:03 +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-07 12:01:03 +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-01-14 19:29:32 +00:00
|
|
|
return (wp);
|
2009-01-11 23:31:46 +00:00
|
|
|
}
|
|
|
|
|
2009-01-14 19:29:32 +00:00
|
|
|
void
|
2014-04-17 09:13:13 +00:00
|
|
|
window_lost_pane(struct window *w, struct window_pane *wp)
|
2009-01-11 23:31:46 +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();
|
|
|
|
|
2010-10-24 01:32:35 +00:00
|
|
|
if (wp == w->active) {
|
2010-10-24 01:34:30 +00:00
|
|
|
w->active = w->last;
|
|
|
|
w->last = NULL;
|
|
|
|
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) {
|
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);
|
|
|
|
}
|
2010-10-24 01:34:30 +00:00
|
|
|
} else if (wp == w->last)
|
|
|
|
w->last = NULL;
|
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-01-14 19:29:32 +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-01-14 19:29:32 +00:00
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
if (n == idx)
|
|
|
|
return (wp);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2010-07-17 14:38:13 +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-25 13:30:45 +00:00
|
|
|
int
|
|
|
|
window_pane_index(struct window_pane *wp, u_int *i)
|
2009-07-17 18:32:54 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wq;
|
2011-11-25 13:30:45 +00:00
|
|
|
struct window *w = wp->window;
|
2009-07-17 18:32:54 +00:00
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
*i = options_get_number(w->options, "pane-base-index");
|
2009-07-17 18:32:54 +00:00
|
|
|
TAILQ_FOREACH(wq, &w->panes, entry) {
|
2011-11-25 13:30:45 +00:00
|
|
|
if (wp == wq) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
(*i)++;
|
2009-07-17 18:32:54 +00:00
|
|
|
}
|
2011-11-25 13:30:45 +00:00
|
|
|
|
|
|
|
return (-1);
|
2009-07-17 18:32:54 +00:00
|
|
|
}
|
|
|
|
|
2009-01-14 19:29:32 +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;
|
2009-01-12 18:22:47 +00:00
|
|
|
|
2009-01-14 19:29:32 +00:00
|
|
|
while (!TAILQ_EMPTY(&w->panes)) {
|
|
|
|
wp = TAILQ_FIRST(&w->panes);
|
|
|
|
TAILQ_REMOVE(&w->panes, wp, entry);
|
|
|
|
window_pane_destroy(wp);
|
2009-01-11 23:31:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
2011-01-07 16:55:40 +00:00
|
|
|
{
|
2017-04-20 09:43:45 +00:00
|
|
|
struct session *s = wl->session;
|
|
|
|
static char flags[32];
|
|
|
|
int pos;
|
2011-01-07 16:55:40 +00:00
|
|
|
|
|
|
|
pos = 0;
|
2021-01-20 07:16:54 +00:00
|
|
|
if (wl->flags & WINLINK_ACTIVITY) {
|
2011-01-07 16:55:40 +00:00
|
|
|
flags[pos++] = '#';
|
2021-01-20 07:16:54 +00:00
|
|
|
if (escape)
|
|
|
|
flags[pos++] = '#';
|
|
|
|
}
|
2011-01-07 16:55:40 +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-02-24 00:25:03 +00:00
|
|
|
if (wl->window->flags & WINDOW_ZOOMED)
|
|
|
|
flags[pos++] = 'Z';
|
2011-01-07 16:55:40 +00:00
|
|
|
flags[pos] = '\0';
|
2017-04-20 09:39:07 +00:00
|
|
|
return (flags);
|
2011-01-07 16:55:40 +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-04-06 22:16:33 +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-01-11 23:31:46 +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-01-11 23:31:46 +00:00
|
|
|
|
2009-01-14 19:29:32 +00:00
|
|
|
wp = xcalloc(1, sizeof *wp);
|
2009-01-11 23:31:46 +00:00
|
|
|
wp->window = w;
|
2019-06-20 11:59:59 +00:00
|
|
|
wp->options = options_create(w->options);
|
|
|
|
wp->flags = PANE_STYLECHANGED;
|
2009-01-11 23:31:46 +00:00
|
|
|
|
2012-01-31 12:01:43 +00:00
|
|
|
wp->id = next_window_pane_id++;
|
2011-04-06 22:16:33 +00:00
|
|
|
RB_INSERT(window_pane_tree, &all_window_panes, wp);
|
|
|
|
|
2014-05-13 08:08:32 +00:00
|
|
|
wp->argc = 0;
|
|
|
|
wp->argv = NULL;
|
2009-09-02 01:02:44 +00:00
|
|
|
wp->shell = NULL;
|
2015-10-31 08:13:58 +00:00
|
|
|
wp->cwd = NULL;
|
2009-01-11 23:31:46 +00:00
|
|
|
|
|
|
|
wp->fd = -1;
|
2009-11-08 23:02:56 +00:00
|
|
|
wp->event = NULL;
|
2009-01-11 23:31:46 +00:00
|
|
|
|
2020-04-28 12:50:07 +00:00
|
|
|
wp->fg = 8;
|
|
|
|
wp->bg = 8;
|
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
TAILQ_INIT(&wp->modes);
|
2009-01-11 23:31:46 +00:00
|
|
|
|
2009-07-20 15:42:05 +00:00
|
|
|
wp->layout_cell = NULL;
|
|
|
|
|
2009-04-01 18:21:42 +00:00
|
|
|
wp->xoff = 0;
|
2009-12-04 22:14:47 +00:00
|
|
|
wp->yoff = 0;
|
2009-04-01 18:21:42 +00:00
|
|
|
|
2020-06-05 11:20:51 +00:00
|
|
|
wp->sx = sx;
|
|
|
|
wp->sy = sy;
|
2009-01-12 18:22:47 +00:00
|
|
|
|
2009-10-12 00:35:08 +00:00
|
|
|
wp->pipe_fd = -1;
|
2009-11-08 22:59:53 +00:00
|
|
|
wp->pipe_event = NULL;
|
2009-10-12 00:35:08 +00:00
|
|
|
|
2009-01-11 23:31:46 +00:00
|
|
|
screen_init(&wp->base, sx, sy, hlimit);
|
|
|
|
wp->screen = &wp->base;
|
|
|
|
|
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-01-11 23:31:46 +00:00
|
|
|
return (wp);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:21:59 +00:00
|
|
|
static void
|
2009-01-11 23:31:46 +00:00
|
|
|
window_pane_destroy(struct window_pane *wp)
|
|
|
|
{
|
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-29 14:46:13 +00:00
|
|
|
|
2009-11-08 23:02:56 +00:00
|
|
|
if (wp->fd != -1) {
|
2014-02-24 23:07:22 +00:00
|
|
|
#ifdef HAVE_UTEMPTER
|
|
|
|
utempter_remove_record(wp->fd);
|
|
|
|
#endif
|
2009-11-08 23:02:56 +00:00
|
|
|
bufferevent_free(wp->event);
|
2012-01-29 12:53:33 +00:00
|
|
|
close(wp->fd);
|
2009-11-08 23:02:56 +00:00
|
|
|
}
|
2020-03-31 07:00:34 +00:00
|
|
|
if (wp->ictx != NULL)
|
|
|
|
input_free(wp->ictx);
|
2009-01-11 23:31:46 +00:00
|
|
|
|
2019-03-18 21:55:04 +00:00
|
|
|
screen_free(&wp->status_screen);
|
|
|
|
|
2009-01-11 23:31:46 +00:00
|
|
|
screen_free(&wp->base);
|
|
|
|
|
2009-10-12 00:35:08 +00:00
|
|
|
if (wp->pipe_fd != -1) {
|
2009-11-08 22:59:53 +00:00
|
|
|
bufferevent_free(wp->pipe_event);
|
2012-01-29 12:53:33 +00:00
|
|
|
close(wp->pipe_fd);
|
2009-10-12 00:35:08 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 08:30:44 +00:00
|
|
|
if (event_initialized(&wp->resize_timer))
|
|
|
|
event_del(&wp->resize_timer);
|
2020-06-05 11:20:51 +00:00
|
|
|
if (event_initialized(&wp->force_timer))
|
|
|
|
event_del(&wp->force_timer);
|
2016-09-28 08:30:44 +00:00
|
|
|
|
2011-04-06 22:16:33 +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-11 19:34:16 +00:00
|
|
|
free(wp->shell);
|
2014-05-13 08:08:32 +00:00
|
|
|
cmd_free_argv(wp->argc, wp->argv);
|
2017-01-07 15:28:13 +00:00
|
|
|
free(wp->palette);
|
2012-07-11 19:34:16 +00:00
|
|
|
free(wp);
|
2009-01-11 23:31:46 +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)
|
2012-03-29 21:05:16 +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;
|
2012-03-29 21:05:16 +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-06 21:58:33 +00:00
|
|
|
}
|
2009-11-08 23:02:56 +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-08 23:02:56 +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-08 23:02:56 +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-08 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-07 12:01:03 +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);
|
2020-03-31 07:00:34 +00:00
|
|
|
wp->ictx = input_init(wp, wp->event);
|
2019-04-07 12:01:03 +00:00
|
|
|
|
|
|
|
bufferevent_enable(wp->event, EV_READ|EV_WRITE);
|
|
|
|
}
|
|
|
|
|
2009-07-22 17:46:53 +00:00
|
|
|
void
|
2009-01-11 23:31:46 +00:00
|
|
|
window_pane_resize(struct window_pane *wp, u_int sx, u_int sy)
|
2007-07-09 19:04:12 +00:00
|
|
|
{
|
2019-03-12 11:16:49 +00:00
|
|
|
struct window_mode_entry *wme;
|
|
|
|
|
2009-01-12 18:22:47 +00:00
|
|
|
if (sx == wp->sx && sy == wp->sy)
|
2009-07-22 17:46:53 +00:00
|
|
|
return;
|
2009-01-12 18:22:47 +00:00
|
|
|
wp->sx = sx;
|
|
|
|
wp->sy = sy;
|
2007-12-06 09:46:23 +00:00
|
|
|
|
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);
|
2020-06-05 11:20:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the pane has already been resized, set the force flag and make
|
|
|
|
* the application resize twice to force it to redraw.
|
|
|
|
*/
|
|
|
|
if (wp->flags & PANE_RESIZE)
|
|
|
|
wp->flags |= PANE_RESIZEFORCE;
|
|
|
|
wp->flags |= PANE_RESIZE;
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-07 15:28:13 +00:00
|
|
|
void
|
|
|
|
window_pane_set_palette(struct window_pane *wp, u_int n, int colour)
|
|
|
|
{
|
|
|
|
if (n > 0xff)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wp->palette == NULL)
|
|
|
|
wp->palette = xcalloc(0x100, sizeof *wp->palette);
|
|
|
|
|
|
|
|
wp->palette[n] = colour;
|
|
|
|
wp->flags |= PANE_REDRAW;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_pane_unset_palette(struct window_pane *wp, u_int n)
|
|
|
|
{
|
|
|
|
if (n > 0xff || wp->palette == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wp->palette[n] = 0;
|
|
|
|
wp->flags |= PANE_REDRAW;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_pane_reset_palette(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
if (wp->palette == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
free(wp->palette);
|
|
|
|
wp->palette = NULL;
|
|
|
|
wp->flags |= PANE_REDRAW;
|
|
|
|
}
|
|
|
|
|
2017-01-12 10:15:55 +00:00
|
|
|
int
|
2019-03-14 09:53:52 +00:00
|
|
|
window_pane_get_palette(struct window_pane *wp, int c)
|
2017-01-12 10:15:55 +00:00
|
|
|
{
|
|
|
|
int new;
|
|
|
|
|
|
|
|
if (wp == NULL || wp->palette == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
new = -1;
|
|
|
|
if (c < 8)
|
|
|
|
new = wp->palette[c];
|
|
|
|
else if (c >= 90 && c <= 97)
|
|
|
|
new = wp->palette[8 + c - 90];
|
|
|
|
else if (c & COLOUR_FLAG_256)
|
|
|
|
new = wp->palette[c & ~COLOUR_FLAG_256];
|
|
|
|
if (new == 0)
|
|
|
|
return (-1);
|
|
|
|
return (new);
|
|
|
|
}
|
|
|
|
|
2007-12-06 10:04:43 +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)
|
2007-12-06 10:04:43 +00:00
|
|
|
{
|
2019-03-12 11:16:49 +00:00
|
|
|
struct window_mode_entry *wme;
|
2007-12-06 10:04:43 +00:00
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
if (!TAILQ_EMPTY(&wp->modes) && TAILQ_FIRST(&wp->modes)->mode == mode)
|
2007-12-06 10:04:43 +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;
|
2015-08-29 00:39:18 +00:00
|
|
|
wp->flags |= (PANE_REDRAW|PANE_CHANGED);
|
2016-03-01 12:05:15 +00:00
|
|
|
|
2020-04-29 07:55:21 +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
|
|
|
|
2007-12-06 10:04:43 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-11 23:31:46 +00:00
|
|
|
window_pane_reset_mode(struct window_pane *wp)
|
2007-12-06 10:04:43 +00:00
|
|
|
{
|
2019-03-12 11:16:49 +00:00
|
|
|
struct window_mode_entry *wme, *next;
|
2007-12-06 10:04:43 +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);
|
2007-12-06 10:04:43 +00:00
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
next = TAILQ_FIRST(&wp->modes);
|
|
|
|
if (next == NULL) {
|
|
|
|
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);
|
|
|
|
}
|
2015-08-29 00:39:18 +00:00
|
|
|
wp->flags |= (PANE_REDRAW|PANE_CHANGED);
|
2016-03-01 12:05:15 +00:00
|
|
|
|
2020-04-29 07:55:21 +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);
|
2007-12-06 10:04:43 +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);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
2007-11-21 13:11:41 +00:00
|
|
|
{
|
2019-03-12 11:16:49 +00:00
|
|
|
struct window_mode_entry *wme;
|
2009-10-09 13:07:04 +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-15 11:16:41 +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-12 00:04:56 +00:00
|
|
|
}
|
2009-10-09 13:07:04 +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);
|
2007-11-21 13:11:41 +00:00
|
|
|
}
|
2009-01-28 19:52:21 +00:00
|
|
|
|
2018-09-10 06:19:17 +00:00
|
|
|
int
|
|
|
|
window_pane_visible(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
if (~wp->window->flags & WINDOW_ZOOMED)
|
|
|
|
return (1);
|
|
|
|
return (wp == wp->window->active);
|
|
|
|
}
|
|
|
|
|
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-15 22:03:38 +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-15 22:03:38 +00:00
|
|
|
|
Support for windows larger than the client.
This adds 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. 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).
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-width -x or -y.
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 higher memory use if you make a window that big. The
minimum size is the size required for the current layout including
borders.
This change allows some code improvements, most notably that since
windows can now never be cropped, that code can be removed from the
layout code, and since panes can now never be outside the size of the
window, window_pane_visible can be removed.
2018-08-20 14:22:14 +00:00
|
|
|
if (wp == NULL)
|
2010-03-15 22:03:38 +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-15 22:03:38 +00:00
|
|
|
|
|
|
|
left = wp->xoff;
|
2014-05-08 06:03:30 +00:00
|
|
|
right = wp->xoff + wp->sx;
|
2010-03-15 22:03:38 +00:00
|
|
|
|
2019-06-26 13:03:47 +00:00
|
|
|
TAILQ_FOREACH(next, &w->panes, entry) {
|
Support for windows larger than the client.
This adds 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. 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).
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-width -x or -y.
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 higher memory use if you make a window that big. The
minimum size is the size required for the current layout including
borders.
This change allows some code improvements, most notably that since
windows can now never be cropped, that code can be removed from the
layout code, and since panes can now never be outside the size of the
window, window_pane_visible can be removed.
2018-08-20 14:22:14 +00:00
|
|
|
if (next == wp)
|
2010-03-15 22:03:38 +00:00
|
|
|
continue;
|
2014-05-08 06:03:30 +00:00
|
|
|
if (next->yoff + next->sy + 1 != edge)
|
2010-03-15 22:03:38 +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-15 22:03:38 +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-15 22:03:38 +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-15 22:03:38 +00:00
|
|
|
|
Support for windows larger than the client.
This adds 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. 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).
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-width -x or -y.
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 higher memory use if you make a window that big. The
minimum size is the size required for the current layout including
borders.
This change allows some code improvements, most notably that since
windows can now never be cropped, that code can be removed from the
layout code, and since panes can now never be outside the size of the
window, window_pane_visible can be removed.
2018-08-20 14:22:14 +00:00
|
|
|
if (wp == NULL)
|
2010-03-15 22:03:38 +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-15 22:03:38 +00:00
|
|
|
|
|
|
|
left = wp->xoff;
|
2014-05-08 06:03:30 +00:00
|
|
|
right = wp->xoff + wp->sx;
|
2010-03-15 22:03:38 +00:00
|
|
|
|
2019-06-26 13:03:47 +00:00
|
|
|
TAILQ_FOREACH(next, &w->panes, entry) {
|
Support for windows larger than the client.
This adds 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. 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).
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-width -x or -y.
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 higher memory use if you make a window that big. The
minimum size is the size required for the current layout including
borders.
This change allows some code improvements, most notably that since
windows can now never be cropped, that code can be removed from the
layout code, and since panes can now never be outside the size of the
window, window_pane_visible can be removed.
2018-08-20 14:22:14 +00:00
|
|
|
if (next == wp)
|
2010-03-15 22:03:38 +00:00
|
|
|
continue;
|
2014-05-08 06:03:30 +00:00
|
|
|
if (next->yoff != edge)
|
2010-03-15 22:03:38 +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-15 22:03:38 +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-15 22:03:38 +00:00
|
|
|
}
|
|
|
|
|
2014-05-08 06:03:30 +00:00
|
|
|
/* Find the pane directly to the left of another. */
|
2010-03-15 22:03:38 +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-15 22:03:38 +00:00
|
|
|
|
Support for windows larger than the client.
This adds 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. 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).
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-width -x or -y.
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 higher memory use if you make a window that big. The
minimum size is the size required for the current layout including
borders.
This change allows some code improvements, most notably that since
windows can now never be cropped, that code can be removed from the
layout code, and since panes can now never be outside the size of the
window, window_pane_visible can be removed.
2018-08-20 14:22:14 +00:00
|
|
|
if (wp == NULL)
|
2010-03-15 22:03:38 +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-15 22:03:38 +00:00
|
|
|
|
|
|
|
top = wp->yoff;
|
2014-05-08 06:03:30 +00:00
|
|
|
bottom = wp->yoff + wp->sy;
|
2010-03-15 22:03:38 +00:00
|
|
|
|
2019-06-26 13:03:47 +00:00
|
|
|
TAILQ_FOREACH(next, &w->panes, entry) {
|
Support for windows larger than the client.
This adds 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. 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).
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-width -x or -y.
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 higher memory use if you make a window that big. The
minimum size is the size required for the current layout including
borders.
This change allows some code improvements, most notably that since
windows can now never be cropped, that code can be removed from the
layout code, and since panes can now never be outside the size of the
window, window_pane_visible can be removed.
2018-08-20 14:22:14 +00:00
|
|
|
if (next == wp)
|
2010-03-15 22:03:38 +00:00
|
|
|
continue;
|
2014-05-08 06:03:30 +00:00
|
|
|
if (next->xoff + next->sx + 1 != edge)
|
2010-03-15 22:03:38 +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-15 22:03:38 +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-15 22:03:38 +00:00
|
|
|
}
|
|
|
|
|
2014-05-08 06:03:30 +00:00
|
|
|
/* Find the pane directly to the right of another. */
|
2010-03-15 22:03:38 +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-15 22:03:38 +00:00
|
|
|
|
Support for windows larger than the client.
This adds 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. 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).
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-width -x or -y.
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 higher memory use if you make a window that big. The
minimum size is the size required for the current layout including
borders.
This change allows some code improvements, most notably that since
windows can now never be cropped, that code can be removed from the
layout code, and since panes can now never be outside the size of the
window, window_pane_visible can be removed.
2018-08-20 14:22:14 +00:00
|
|
|
if (wp == NULL)
|
2010-03-15 22:03:38 +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-15 22:03:38 +00:00
|
|
|
|
|
|
|
top = wp->yoff;
|
2014-05-08 06:03:30 +00:00
|
|
|
bottom = wp->yoff + wp->sy;
|
2010-03-15 22:03:38 +00:00
|
|
|
|
2019-06-26 13:03:47 +00:00
|
|
|
TAILQ_FOREACH(next, &w->panes, entry) {
|
Support for windows larger than the client.
This adds 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. 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).
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-width -x or -y.
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 higher memory use if you make a window that big. The
minimum size is the size required for the current layout including
borders.
This change allows some code improvements, most notably that since
windows can now never be cropped, that code can be removed from the
layout code, and since panes can now never be outside the size of the
window, window_pane_visible can be removed.
2018-08-20 14:22:14 +00:00
|
|
|
if (next == wp)
|
2010-03-15 22:03:38 +00:00
|
|
|
continue;
|
2014-05-08 06:03:30 +00:00
|
|
|
if (next->xoff != edge)
|
2010-03-15 22:03:38 +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-15 22:03:38 +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-15 22:03:38 +00:00
|
|
|
}
|
2012-07-11 17:06:11 +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-11 17:06:11 +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-11 17:06:11 +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-07 12:01:03 +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);
|
2019-12-12 11:39:56 +00:00
|
|
|
if (wp == NULL || closed || error != 0 || c->flags & CLIENT_DEAD) {
|
2019-09-10 19:35:34 +00:00
|
|
|
if (wp == NULL)
|
|
|
|
c->flags |= CLIENT_EXIT;
|
2019-05-03 20:44:24 +00:00
|
|
|
|
2019-12-12 11:39:56 +00:00
|
|
|
evbuffer_drain(buffer, len);
|
2019-06-18 11:08:42 +00:00
|
|
|
cmdq_continue(cdata->item);
|
2019-05-03 20:44:24 +00:00
|
|
|
|
2019-12-12 11:39:56 +00:00
|
|
|
server_client_unref(c);
|
|
|
|
free(cdata);
|
2019-05-03 20:44:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-05-07 10:25:15 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
cdata = xmalloc(sizeof *cdata);
|
|
|
|
cdata->item = item;
|
|
|
|
cdata->wp = wp->id;
|
|
|
|
|
2019-12-12 11:39:56 +00:00
|
|
|
c->references++;
|
|
|
|
file_read(c, "-", window_pane_input_callback, cdata);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|