mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Add flags to refresh-client (-U -D -L -R and -c) to pan a window that
is larger than the client manually. Bound to S-Up, S-Down, S-Left, S-Right and Delete manually. Also add aliases for keys DC = Delete, IC = Insert, and make refresh-client -C accept XxY as well as X,Y to match default-size.
This commit is contained in:
		@@ -18,6 +18,8 @@
 | 
			
		||||
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "tmux.h"
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
@@ -31,8 +33,8 @@ const struct cmd_entry cmd_refresh_client_entry = {
 | 
			
		||||
	.name = "refresh-client",
 | 
			
		||||
	.alias = "refresh",
 | 
			
		||||
 | 
			
		||||
	.args = { "C:St:", 0, 0 },
 | 
			
		||||
	.usage = "[-S] [-C size] " CMD_TARGET_CLIENT_USAGE,
 | 
			
		||||
	.args = { "cC:DLRSt:U", 0, 1 },
 | 
			
		||||
	.usage = "[-DLRSU] [-C size] " CMD_TARGET_CLIENT_USAGE " [adjustment]",
 | 
			
		||||
 | 
			
		||||
	.flags = CMD_AFTERHOOK,
 | 
			
		||||
	.exec = cmd_refresh_client_exec
 | 
			
		||||
@@ -43,23 +45,77 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
 | 
			
		||||
{
 | 
			
		||||
	struct args	*args = self->args;
 | 
			
		||||
	struct client	*c;
 | 
			
		||||
	const char	*size;
 | 
			
		||||
	u_int		 w, h;
 | 
			
		||||
	struct tty	*tty;
 | 
			
		||||
	struct window	*w;
 | 
			
		||||
	const char	*size, *errstr;
 | 
			
		||||
	u_int		 x, y, adjust;
 | 
			
		||||
 | 
			
		||||
	if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
 | 
			
		||||
		return (CMD_RETURN_ERROR);
 | 
			
		||||
	tty = &c->tty;
 | 
			
		||||
 | 
			
		||||
	if (args_has(args, 'c') ||
 | 
			
		||||
	    args_has(args, 'L') ||
 | 
			
		||||
	    args_has(args, 'R') ||
 | 
			
		||||
	    args_has(args, 'U') ||
 | 
			
		||||
	    args_has(args, 'D'))
 | 
			
		||||
	{
 | 
			
		||||
		if (args->argc == 0)
 | 
			
		||||
			adjust = 1;
 | 
			
		||||
		else {
 | 
			
		||||
			adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
 | 
			
		||||
			if (errstr != NULL) {
 | 
			
		||||
				cmdq_error(item, "adjustment %s", errstr);
 | 
			
		||||
				return (CMD_RETURN_ERROR);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (args_has(args, 'c'))
 | 
			
		||||
		    c->pan_window = NULL;
 | 
			
		||||
		else {
 | 
			
		||||
			w = c->session->curw->window;
 | 
			
		||||
			if (c->pan_window != w) {
 | 
			
		||||
				c->pan_window = w;
 | 
			
		||||
				c->pan_ox = tty->oox;
 | 
			
		||||
				c->pan_oy = tty->ooy;
 | 
			
		||||
			}
 | 
			
		||||
			if (args_has(args, 'L')) {
 | 
			
		||||
				if (c->pan_ox > adjust)
 | 
			
		||||
					c->pan_ox -= adjust;
 | 
			
		||||
				else
 | 
			
		||||
					c->pan_ox = 0;
 | 
			
		||||
			} else if (args_has(args, 'R')) {
 | 
			
		||||
				c->pan_ox += adjust;
 | 
			
		||||
				if (c->pan_ox > w->sx - tty->osx)
 | 
			
		||||
					c->pan_ox = w->sx - tty->osx;
 | 
			
		||||
			} else if (args_has(args, 'U')) {
 | 
			
		||||
				if (c->pan_oy > adjust)
 | 
			
		||||
					c->pan_oy -= adjust;
 | 
			
		||||
				else
 | 
			
		||||
					c->pan_oy = 0;
 | 
			
		||||
			} else if (args_has(args, 'D')) {
 | 
			
		||||
				c->pan_oy += adjust;
 | 
			
		||||
				if (c->pan_oy > w->sy - tty->osy)
 | 
			
		||||
					c->pan_oy = w->sy - tty->osy;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		tty_update_client_offset(c);
 | 
			
		||||
		server_redraw_client(c);
 | 
			
		||||
		return (CMD_RETURN_NORMAL);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (args_has(args, 'C')) {
 | 
			
		||||
		if ((size = args_get(args, 'C')) == NULL) {
 | 
			
		||||
			cmdq_error(item, "missing size");
 | 
			
		||||
			return (CMD_RETURN_ERROR);
 | 
			
		||||
		}
 | 
			
		||||
		if (sscanf(size, "%u,%u", &w, &h) != 2) {
 | 
			
		||||
		if (sscanf(size, "%u,%u", &x, &y) != 2 &&
 | 
			
		||||
		    sscanf(size, "%ux%u", &x, &y)) {
 | 
			
		||||
			cmdq_error(item, "bad size argument");
 | 
			
		||||
			return (CMD_RETURN_ERROR);
 | 
			
		||||
		}
 | 
			
		||||
		if (w < PANE_MINIMUM || w > 5000 ||
 | 
			
		||||
		    h < PANE_MINIMUM || h > 5000) {
 | 
			
		||||
		if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
 | 
			
		||||
		    y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
 | 
			
		||||
			cmdq_error(item, "size too small or too big");
 | 
			
		||||
			return (CMD_RETURN_ERROR);
 | 
			
		||||
		}
 | 
			
		||||
@@ -67,16 +123,18 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
 | 
			
		||||
			cmdq_error(item, "not a control client");
 | 
			
		||||
			return (CMD_RETURN_ERROR);
 | 
			
		||||
		}
 | 
			
		||||
		tty_set_size(&c->tty, w, h);
 | 
			
		||||
		tty_set_size(&c->tty, x, y);
 | 
			
		||||
		c->flags |= CLIENT_SIZECHANGED;
 | 
			
		||||
		recalculate_sizes();
 | 
			
		||||
	} else if (args_has(args, 'S')) {
 | 
			
		||||
		return (CMD_RETURN_NORMAL);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (args_has(args, 'S')) {
 | 
			
		||||
		c->flags |= CLIENT_STATUSFORCE;
 | 
			
		||||
		server_status_client(c);
 | 
			
		||||
	} else {
 | 
			
		||||
		c->flags |= CLIENT_STATUSFORCE;
 | 
			
		||||
		server_redraw_client(c);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return (CMD_RETURN_NORMAL);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -258,6 +258,11 @@ key_bindings_init(void)
 | 
			
		||||
		"bind M-n next-window -a",
 | 
			
		||||
		"bind M-o rotate-window -D",
 | 
			
		||||
		"bind M-p previous-window -a",
 | 
			
		||||
		"bind -r S-Up refresh-client -U 10",
 | 
			
		||||
		"bind -r S-Down refresh-client -D 10",
 | 
			
		||||
		"bind -r S-Left refresh-client -L 10",
 | 
			
		||||
		"bind -r S-Right refresh-client -R 10",
 | 
			
		||||
		"bind -r DC refresh-client -c",
 | 
			
		||||
		"bind -r M-Up resize-pane -U 5",
 | 
			
		||||
		"bind -r M-Down resize-pane -D 5",
 | 
			
		||||
		"bind -r M-Left resize-pane -L 5",
 | 
			
		||||
 
 | 
			
		||||
@@ -43,7 +43,9 @@ static const struct {
 | 
			
		||||
	{ "F11",	KEYC_F11 },
 | 
			
		||||
	{ "F12",	KEYC_F12 },
 | 
			
		||||
	{ "IC",		KEYC_IC },
 | 
			
		||||
	{ "Insert",     KEYC_IC },
 | 
			
		||||
	{ "DC",		KEYC_DC },
 | 
			
		||||
	{ "Delete",     KEYC_DC },
 | 
			
		||||
	{ "Home",	KEYC_HOME },
 | 
			
		||||
	{ "End",	KEYC_END },
 | 
			
		||||
	{ "NPage",	KEYC_NPAGE },
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								tmux.1
									
									
									
									
									
								
							@@ -930,9 +930,11 @@ is used, the
 | 
			
		||||
.Ic update-environment
 | 
			
		||||
option will not be applied.
 | 
			
		||||
.It Xo Ic refresh-client
 | 
			
		||||
.Op Fl C Ar width,height
 | 
			
		||||
.Op Fl cDLRU
 | 
			
		||||
.Op Fl C Ar XxY
 | 
			
		||||
.Op Fl S
 | 
			
		||||
.Op Fl t Ar target-client
 | 
			
		||||
.Op Ar adjustment
 | 
			
		||||
.Xc
 | 
			
		||||
.D1 (alias: Ic refresh )
 | 
			
		||||
Refresh the current client if bound to a key, or a single client if one is given
 | 
			
		||||
@@ -942,6 +944,36 @@ If
 | 
			
		||||
.Fl S
 | 
			
		||||
is specified, only update the client's status line.
 | 
			
		||||
.Pp
 | 
			
		||||
The
 | 
			
		||||
.Fl U ,
 | 
			
		||||
.Fl D ,
 | 
			
		||||
.Fl L
 | 
			
		||||
.Fl R ,
 | 
			
		||||
and
 | 
			
		||||
.Fl c
 | 
			
		||||
flags allow the visible portion of a window which is larger than the client
 | 
			
		||||
to be changed.
 | 
			
		||||
.Fl U
 | 
			
		||||
moves the visible part up by
 | 
			
		||||
.Ar adjustment
 | 
			
		||||
rows and
 | 
			
		||||
.Fl D
 | 
			
		||||
down,
 | 
			
		||||
.Fl L
 | 
			
		||||
left by
 | 
			
		||||
.Ar adjustment
 | 
			
		||||
columns and
 | 
			
		||||
.Fl R
 | 
			
		||||
right.
 | 
			
		||||
.Fl c
 | 
			
		||||
returns to tracking the cursor automatically.
 | 
			
		||||
If
 | 
			
		||||
.Ar adjustment
 | 
			
		||||
is omitted, 1 is used.
 | 
			
		||||
Note that the visible position is a property of the client not of the
 | 
			
		||||
window, changing the current window in the attached session will reset
 | 
			
		||||
it.
 | 
			
		||||
.Pp
 | 
			
		||||
.Fl C
 | 
			
		||||
sets the width and height of a control client.
 | 
			
		||||
.It Xo Ic rename-session
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1421,6 +1421,10 @@ struct client {
 | 
			
		||||
 | 
			
		||||
	int		 references;
 | 
			
		||||
 | 
			
		||||
	void		*pan_window;
 | 
			
		||||
	u_int		 pan_ox;
 | 
			
		||||
	u_int		 pan_oy;
 | 
			
		||||
 | 
			
		||||
	TAILQ_ENTRY(client) entry;
 | 
			
		||||
};
 | 
			
		||||
TAILQ_HEAD(clients, client);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										13
									
								
								tty.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								tty.c
									
									
									
									
									
								
							@@ -738,12 +738,24 @@ tty_window_offset1(struct tty *tty, u_int *ox, u_int *oy, u_int *sx, u_int *sy)
 | 
			
		||||
		*oy = 0;
 | 
			
		||||
		*sx = w->sx;
 | 
			
		||||
		*sy = w->sy;
 | 
			
		||||
 | 
			
		||||
		c->pan_window = NULL;
 | 
			
		||||
		return (0);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	*sx = tty->sx;
 | 
			
		||||
	*sy = tty->sy - lines;
 | 
			
		||||
 | 
			
		||||
	if (c->pan_window == w) {
 | 
			
		||||
		if (c->pan_ox + *sx > w->sx)
 | 
			
		||||
			c->pan_ox = w->sx - *sx;
 | 
			
		||||
		*ox = c->pan_ox;
 | 
			
		||||
		if (c->pan_oy + *sy > w->sy)
 | 
			
		||||
			c->pan_oy = w->sy - *sy;
 | 
			
		||||
		*oy = c->pan_oy;
 | 
			
		||||
		return (1);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (~wp->screen->mode & MODE_CURSOR) {
 | 
			
		||||
		*ox = 0;
 | 
			
		||||
		*oy = 0;
 | 
			
		||||
@@ -766,6 +778,7 @@ tty_window_offset1(struct tty *tty, u_int *ox, u_int *oy, u_int *sx, u_int *sy)
 | 
			
		||||
			*oy = cy - *sy / 2;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	c->pan_window = NULL;
 | 
			
		||||
	return (1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user