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-03-18 14:10:25 +00:00
|
|
|
/* List of window modes. */
|
|
|
|
const struct window_mode *all_window_modes[] = {
|
|
|
|
&window_buffer_mode,
|
|
|
|
&window_client_mode,
|
|
|
|
&window_clock_mode,
|
|
|
|
&window_copy_mode,
|
|
|
|
&window_tree_mode,
|
|
|
|
&window_view_mode,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
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 *
|
2016-10-15 09:27:52 +00:00
|
|
|
window_create(u_int sx, u_int sy)
|
2007-07-09 19:04:12 +00:00
|
|
|
{
|
|
|
|
struct window *w;
|
|
|
|
|
2009-11-08 23:22:24 +00:00
|
|
|
w = xcalloc(1, sizeof *w);
|
2009-01-23 16:59:14 +00:00
|
|
|
w->name = NULL;
|
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;
|
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
|
2009-01-11 23:31:46 +00:00
|
|
|
window_resize(struct window *w, u_int sx, u_int sy)
|
|
|
|
{
|
2019-06-26 13:05:24 +00:00
|
|
|
log_debug("%s: @%u resize %ux%u", __func__, w->id, sx, sy);
|
2009-01-14 19:29:32 +00:00
|
|
|
w->sx = sx;
|
|
|
|
w->sy = sy;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2019-06-20 11:59:59 +00:00
|
|
|
struct style *sy1, *sy2;
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
sy1 = &wp->cached_style;
|
|
|
|
sy2 = &wp->cached_active_style;
|
|
|
|
if (!style_equal(sy1, sy2))
|
|
|
|
wp->flags |= PANE_REDRAW;
|
|
|
|
else {
|
|
|
|
c1 = window_pane_get_palette(wp, sy1->gc.fg);
|
|
|
|
c2 = window_pane_get_palette(wp, sy2->gc.fg);
|
|
|
|
if (c1 != c2)
|
|
|
|
wp->flags |= PANE_REDRAW;
|
|
|
|
else {
|
|
|
|
c1 = window_pane_get_palette(wp, sy1->gc.bg);
|
|
|
|
c2 = window_pane_get_palette(wp, sy2->gc.bg);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
u_int x, y;
|
|
|
|
|
|
|
|
x = w->sx / 2;
|
|
|
|
y = w->sy / 2;
|
|
|
|
|
|
|
|
if (strcasecmp(s, "top") == 0)
|
|
|
|
y = 0;
|
|
|
|
else if (strcasecmp(s, "bottom") == 0)
|
|
|
|
y = w->sy - 1;
|
|
|
|
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;
|
|
|
|
y = 0;
|
|
|
|
} else if (strcasecmp(s, "top-right") == 0) {
|
|
|
|
x = w->sx - 1;
|
|
|
|
y = 0;
|
|
|
|
} else if (strcasecmp(s, "bottom-left") == 0) {
|
|
|
|
x = 0;
|
|
|
|
y = w->sy - 1;
|
|
|
|
} else if (strcasecmp(s, "bottom-right") == 0) {
|
|
|
|
x = w->sx - 1;
|
|
|
|
y = w->sy - 1;
|
|
|
|
} 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
|
|
|
}
|
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
|
|
|
layout_fix_panes(w);
|
2016-10-16 22:06:40 +00:00
|
|
|
notify_window("window-layout-changed", w);
|
2013-02-24 00:25:03 +00:00
|
|
|
|
|
|
|
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 *
|
2018-09-26 15:42:29 +00:00
|
|
|
window_printable_flags(struct winlink *wl)
|
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;
|
|
|
|
if (wl->flags & WINLINK_ACTIVITY)
|
|
|
|
flags[pos++] = '#';
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2017-05-31 10:15:51 +00:00
|
|
|
wp->sx = wp->osx = sx;
|
|
|
|
wp->sy = wp->osx = sy;
|
2009-01-12 18:22:47 +00:00
|
|
|
|
2009-10-12 00:35:08 +00:00
|
|
|
wp->pipe_fd = -1;
|
|
|
|
wp->pipe_off = 0;
|
2009-11-08 22:59:53 +00:00
|
|
|
wp->pipe_event = NULL;
|
2009-10-12 00:35:08 +00:00
|
|
|
|
2009-07-14 06:40:33 +00:00
|
|
|
wp->saved_grid = NULL;
|
2019-06-09 06:50:24 +00:00
|
|
|
wp->saved_cx = UINT_MAX;
|
|
|
|
wp->saved_cy = UINT_MAX;
|
2009-07-14 06:40:33 +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
|
|
|
input_init(wp);
|
2009-01-12 18:22:47 +00:00
|
|
|
|
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
|
|
|
}
|
2009-01-11 23:31:46 +00:00
|
|
|
|
|
|
|
input_free(wp);
|
|
|
|
|
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-07-14 06:40:33 +00:00
|
|
|
if (wp->saved_grid != NULL)
|
|
|
|
grid_destroy(wp->saved_grid);
|
2009-01-11 23:31:46 +00:00
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
{
|
|
|
|
struct window_pane *wp = data;
|
2015-05-12 22:40:38 +00:00
|
|
|
struct evbuffer *evb = wp->event->input;
|
2016-09-16 13:43:41 +00:00
|
|
|
size_t size = EVBUFFER_LENGTH(evb);
|
2015-05-12 22:40:38 +00:00
|
|
|
char *new_data;
|
2016-04-29 13:36:10 +00:00
|
|
|
size_t new_size;
|
2012-03-29 21:05:16 +00:00
|
|
|
|
2016-09-16 13:43:41 +00:00
|
|
|
new_size = size - wp->pipe_off;
|
2010-04-06 21:58:33 +00:00
|
|
|
if (wp->pipe_fd != -1 && new_size > 0) {
|
2015-12-31 18:14:13 +00:00
|
|
|
new_data = EVBUFFER_DATA(evb) + wp->pipe_off;
|
2010-04-06 21:58:33 +00:00
|
|
|
bufferevent_write(wp->pipe_event, new_data, new_size);
|
|
|
|
}
|
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);
|
2010-04-06 21:58:33 +00:00
|
|
|
input_parse(wp);
|
|
|
|
|
2016-10-18 07:38:16 +00:00
|
|
|
wp->pipe_off = EVBUFFER_LENGTH(evb);
|
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);
|
|
|
|
|
|
|
|
bufferevent_setwatermark(wp->event, EV_READ, 0, READ_SIZE);
|
|
|
|
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);
|
2013-02-05 11:08:59 +00:00
|
|
|
screen_resize(&wp->base, sx, sy, wp->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);
|
2007-07-09 19:04:12 +00:00
|
|
|
|
2013-02-22 21:35:29 +00:00
|
|
|
wp->flags |= PANE_RESIZE;
|
2007-07-09 19:04:12 +00:00
|
|
|
}
|
|
|
|
|
2010-03-15 12:51:23 +00:00
|
|
|
/*
|
|
|
|
* Enter alternative screen mode. A copy of the visible screen is saved and the
|
|
|
|
* history is not updated
|
|
|
|
*/
|
|
|
|
void
|
2012-11-27 20:08:42 +00:00
|
|
|
window_pane_alternate_on(struct window_pane *wp, struct grid_cell *gc,
|
|
|
|
int cursor)
|
2010-03-15 12:51:23 +00:00
|
|
|
{
|
|
|
|
struct screen *s = &wp->base;
|
|
|
|
u_int sx, sy;
|
|
|
|
|
|
|
|
if (wp->saved_grid != NULL)
|
|
|
|
return;
|
2019-06-20 13:40:22 +00:00
|
|
|
if (!options_get_number(wp->options, "alternate-screen"))
|
2010-03-15 12:51:23 +00:00
|
|
|
return;
|
|
|
|
sx = screen_size_x(s);
|
|
|
|
sy = screen_size_y(s);
|
|
|
|
|
|
|
|
wp->saved_grid = grid_create(sx, sy, 0);
|
|
|
|
grid_duplicate_lines(wp->saved_grid, 0, s->grid, screen_hsize(s), sy);
|
2012-11-27 20:08:42 +00:00
|
|
|
if (cursor) {
|
|
|
|
wp->saved_cx = s->cx;
|
|
|
|
wp->saved_cy = s->cy;
|
|
|
|
}
|
2010-03-15 12:51:23 +00:00
|
|
|
memcpy(&wp->saved_cell, gc, sizeof wp->saved_cell);
|
|
|
|
|
2016-10-13 20:27:27 +00:00
|
|
|
grid_view_clear(s->grid, 0, 0, sx, sy, 8);
|
2010-03-15 12:51:23 +00:00
|
|
|
|
|
|
|
wp->base.grid->flags &= ~GRID_HISTORY;
|
|
|
|
|
|
|
|
wp->flags |= PANE_REDRAW;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Exit alternate screen mode and restore the copied grid. */
|
|
|
|
void
|
2012-11-27 20:08:42 +00:00
|
|
|
window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc,
|
|
|
|
int cursor)
|
2010-03-15 12:51:23 +00:00
|
|
|
{
|
|
|
|
struct screen *s = &wp->base;
|
|
|
|
u_int sx, sy;
|
|
|
|
|
2019-06-20 13:40:22 +00:00
|
|
|
if (!options_get_number(wp->options, "alternate-screen"))
|
2010-03-15 12:51:23 +00:00
|
|
|
return;
|
2019-06-09 06:50:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore the cursor position and cell. This happens even if not
|
|
|
|
* currently in the alternate screen.
|
|
|
|
*/
|
|
|
|
if (cursor && wp->saved_cx != UINT_MAX && wp->saved_cy != UINT_MAX) {
|
|
|
|
s->cx = wp->saved_cx;
|
|
|
|
if (s->cx > screen_size_x(s) - 1)
|
|
|
|
s->cx = screen_size_x(s) - 1;
|
|
|
|
s->cy = wp->saved_cy;
|
|
|
|
if (s->cy > screen_size_y(s) - 1)
|
|
|
|
s->cy = screen_size_y(s) - 1;
|
|
|
|
memcpy(gc, &wp->saved_cell, sizeof *gc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wp->saved_grid == NULL)
|
|
|
|
return;
|
2010-03-15 12:51:23 +00:00
|
|
|
sx = screen_size_x(s);
|
|
|
|
sy = screen_size_y(s);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the current size is bigger, temporarily resize to the old size
|
|
|
|
* before copying back.
|
|
|
|
*/
|
|
|
|
if (sy > wp->saved_grid->sy)
|
2013-02-05 11:08:59 +00:00
|
|
|
screen_resize(s, sx, wp->saved_grid->sy, 1);
|
2010-03-15 12:51:23 +00:00
|
|
|
|
2019-06-09 06:50:24 +00:00
|
|
|
/* Restore the saved grid. */
|
2010-03-15 12:51:23 +00:00
|
|
|
grid_duplicate_lines(s->grid, screen_hsize(s), wp->saved_grid, 0, sy);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn history back on (so resize can use it) and then resize back to
|
|
|
|
* the current size.
|
|
|
|
*/
|
|
|
|
wp->base.grid->flags |= GRID_HISTORY;
|
2013-02-05 11:08:59 +00:00
|
|
|
if (sy > wp->saved_grid->sy || sx != wp->saved_grid->sx)
|
|
|
|
screen_resize(s, sx, sy, 1);
|
2010-03-15 12:51:23 +00:00
|
|
|
|
|
|
|
grid_destroy(wp->saved_grid);
|
|
|
|
wp->saved_grid = NULL;
|
|
|
|
|
|
|
|
wp->flags |= PANE_REDRAW;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-06-15 09:13:46 +00:00
|
|
|
static void
|
|
|
|
window_pane_mode_timer(__unused int fd, __unused short events, void *arg)
|
|
|
|
{
|
|
|
|
struct window_pane *wp = arg;
|
|
|
|
struct timeval tv = { .tv_sec = 10 };
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
evtimer_del(&wp->modetimer);
|
|
|
|
evtimer_add(&wp->modetimer, &tv);
|
|
|
|
|
|
|
|
log_debug("%%%u in mode: last=%ld", wp->id, (long)wp->modelast);
|
|
|
|
|
|
|
|
if (wp->modelast < time(NULL) - WINDOW_MODE_TIMEOUT) {
|
|
|
|
if (ioctl(wp->fd, FIONREAD, &n) == -1 || n > 0)
|
2019-03-12 11:16:49 +00:00
|
|
|
window_pane_reset_mode_all(wp);
|
2016-06-15 09:13:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-06 10:04:43 +00:00
|
|
|
int
|
Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.
Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.
Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:
- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;
- items may be sorted in different ways ('O' key);
- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);
- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');
- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');
- the custom format (-F) for the display is no longer available;
- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.
Now that the code is simpler, other improvements will come later.
Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).
Parts written by Thomas Adam.
2017-05-30 21:44:59 +00:00
|
|
|
window_pane_set_mode(struct window_pane *wp, 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 timeval tv = { .tv_sec = 10 };
|
|
|
|
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
|
|
|
|
2016-06-15 09:13:46 +00:00
|
|
|
wp->modelast = time(NULL);
|
2019-03-12 11:16:49 +00:00
|
|
|
if (TAILQ_EMPTY(&wp->modes)) {
|
|
|
|
evtimer_set(&wp->modetimer, window_pane_mode_timer, wp);
|
|
|
|
evtimer_add(&wp->modetimer, &tv);
|
|
|
|
}
|
2016-06-15 09:13:46 +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;
|
|
|
|
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
|
|
|
|
|
|
|
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__);
|
|
|
|
evtimer_del(&wp->modetimer);
|
|
|
|
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
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-11-21 13:11:41 +00:00
|
|
|
void
|
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;
|
2019-03-07 20:24:21 +00:00
|
|
|
struct window_pane *wp2;
|
2009-10-09 13:07:04 +00:00
|
|
|
|
2015-04-19 21:34:21 +00:00
|
|
|
if (KEYC_IS_MOUSE(key) && m == NULL)
|
|
|
|
return;
|
|
|
|
|
2019-03-12 11:16:49 +00:00
|
|
|
wme = TAILQ_FIRST(&wp->modes);
|
2019-03-07 20:24:21 +00:00
|
|
|
if (wme != NULL) {
|
2016-06-15 09:13:46 +00:00
|
|
|
wp->modelast = time(NULL);
|
2019-03-07 20:24:21 +00:00
|
|
|
if (wme->mode->key != NULL)
|
|
|
|
wme->mode->key(wme, c, s, wl, (key & ~KEYC_XTERM), m);
|
2009-10-09 13:07:04 +00:00
|
|
|
return;
|
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)
|
2009-10-12 00:04:56 +00:00
|
|
|
return;
|
2014-08-11 22:14:30 +00:00
|
|
|
|
2015-04-19 21:34:21 +00:00
|
|
|
input_key(wp, key, m);
|
|
|
|
|
|
|
|
if (KEYC_IS_MOUSE(key))
|
|
|
|
return;
|
2015-10-27 15:58:42 +00:00
|
|
|
if (options_get_number(wp->window->options, "synchronize-panes")) {
|
2009-10-09 13:07:04 +00:00
|
|
|
TAILQ_FOREACH(wp2, &wp->window->panes, entry) {
|
2018-09-10 06:19:17 +00:00
|
|
|
if (wp2 != wp &&
|
2019-03-12 11:16:49 +00:00
|
|
|
TAILQ_EMPTY(&wp2->modes) &&
|
2018-09-10 06:19:17 +00:00
|
|
|
wp2->fd != -1 &&
|
|
|
|
(~wp2->flags & PANE_INPUTOFF) &&
|
|
|
|
window_pane_visible(wp2))
|
|
|
|
input_key(wp2, key, NULL);
|
2009-10-09 13:07:04 +00:00
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
found = (fnmatch(new, line, 0) == 0);
|
|
|
|
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
|
|
|
|
winlink_shuffle_up(struct session *s, struct winlink *wl)
|
|
|
|
{
|
|
|
|
int idx, last;
|
|
|
|
|
2019-04-07 12:01:03 +00:00
|
|
|
if (wl == NULL)
|
|
|
|
return (-1);
|
2015-06-17 16:50:28 +00:00
|
|
|
idx = wl->idx + 1;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
server_link_window(s, wl, s, last, 0, 0, NULL);
|
|
|
|
server_unlink_window(s, wl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (idx);
|
|
|
|
}
|
2019-05-03 20:44:24 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
window_pane_input_callback(struct client *c, int closed, void *data)
|
|
|
|
{
|
|
|
|
struct window_pane_input_data *cdata = data;
|
|
|
|
struct window_pane *wp;
|
2019-05-07 10:25:15 +00:00
|
|
|
struct evbuffer *evb = c->stdin_data;
|
|
|
|
u_char *buf = EVBUFFER_DATA(evb);
|
|
|
|
size_t len = EVBUFFER_LENGTH(evb);
|
2019-05-03 20:44:24 +00:00
|
|
|
|
|
|
|
wp = window_pane_find_by_id(cdata->wp);
|
|
|
|
if (wp == NULL || closed || c->flags & CLIENT_DEAD) {
|
2019-09-10 19:35:34 +00:00
|
|
|
if (wp == NULL)
|
|
|
|
c->flags |= CLIENT_EXIT;
|
|
|
|
evbuffer_drain(evb, len);
|
|
|
|
|
2019-05-03 20:44:24 +00:00
|
|
|
c->stdin_callback = NULL;
|
|
|
|
server_client_unref(c);
|
|
|
|
|
2019-06-18 11:08:42 +00:00
|
|
|
cmdq_continue(cdata->item);
|
2019-05-03 20:44:24 +00:00
|
|
|
free(cdata);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-07 10:25:15 +00:00
|
|
|
input_parse_buffer(wp, buf, len);
|
|
|
|
evbuffer_drain(evb, len);
|
2019-05-03 20:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
window_pane_start_input(struct window_pane *wp, struct cmdq_item *item,
|
|
|
|
char **cause)
|
|
|
|
{
|
|
|
|
struct client *c = item->client;
|
|
|
|
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;
|
|
|
|
|
|
|
|
return (server_set_stdin_callback(c, window_pane_input_callback, cdata,
|
|
|
|
cause));
|
|
|
|
}
|