mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Use the correct size for new windows when window-size is latest,
reported by Vamsi Krishna Avula in GitHub issue 1917.
This commit is contained in:
		@@ -98,9 +98,9 @@ cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			|||||||
		sy += adjust;
 | 
							sy += adjust;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (args_has(args, 'A'))
 | 
						if (args_has(args, 'A'))
 | 
				
			||||||
		default_window_size(s, w, &sx, &sy, WINDOW_SIZE_LARGEST);
 | 
							default_window_size(NULL, s, w, &sx, &sy, WINDOW_SIZE_LARGEST);
 | 
				
			||||||
	else if (args_has(args, 'a'))
 | 
						else if (args_has(args, 'a'))
 | 
				
			||||||
		default_window_size(s, w, &sx, &sy, WINDOW_SIZE_SMALLEST);
 | 
							default_window_size(NULL, s, w, &sx, &sy, WINDOW_SIZE_SMALLEST);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	options_set_number(w->options, "window-size", WINDOW_SIZE_MANUAL);
 | 
						options_set_number(w->options, "window-size", WINDOW_SIZE_MANUAL);
 | 
				
			||||||
	resize_window(w, sx, sy);
 | 
						resize_window(w, sx, sy);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										67
									
								
								resize.c
									
									
									
									
									
								
							
							
						
						
									
										67
									
								
								resize.c
									
									
									
									
									
								
							@@ -76,30 +76,28 @@ ignore_client_size(struct client *c)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
default_window_size(struct session *s, struct window *w, u_int *sx, u_int *sy,
 | 
					default_window_size(struct client *c, struct session *s, struct window *w,
 | 
				
			||||||
    int type)
 | 
					    u_int *sx, u_int *sy, int type)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct client	*c;
 | 
						struct client	*loop;
 | 
				
			||||||
	u_int		 cx, cy;
 | 
						u_int		 cx, cy;
 | 
				
			||||||
	const char	*value;
 | 
						const char	*value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (type == -1)
 | 
						if (type == -1)
 | 
				
			||||||
		type = options_get_number(global_w_options, "window-size");
 | 
							type = options_get_number(global_w_options, "window-size");
 | 
				
			||||||
	if (type == WINDOW_SIZE_MANUAL)
 | 
						switch (type) {
 | 
				
			||||||
		goto manual;
 | 
						case WINDOW_SIZE_LARGEST:
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (type == WINDOW_SIZE_LARGEST) {
 | 
					 | 
				
			||||||
		*sx = *sy = 0;
 | 
							*sx = *sy = 0;
 | 
				
			||||||
		TAILQ_FOREACH(c, &clients, entry) {
 | 
							TAILQ_FOREACH(loop, &clients, entry) {
 | 
				
			||||||
			if (ignore_client_size(c))
 | 
								if (ignore_client_size(loop))
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			if (w != NULL && !session_has(c->session, w))
 | 
								if (w != NULL && !session_has(loop->session, w))
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			if (w == NULL && c->session != s)
 | 
								if (w == NULL && loop->session != s)
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			cx = c->tty.sx;
 | 
								cx = loop->tty.sx;
 | 
				
			||||||
			cy = c->tty.sy - status_line_size(c);
 | 
								cy = loop->tty.sy - status_line_size(loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (cx > *sx)
 | 
								if (cx > *sx)
 | 
				
			||||||
				*sx = cx;
 | 
									*sx = cx;
 | 
				
			||||||
@@ -108,18 +106,19 @@ default_window_size(struct session *s, struct window *w, u_int *sx, u_int *sy,
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		if (*sx == 0 || *sy == 0)
 | 
							if (*sx == 0 || *sy == 0)
 | 
				
			||||||
			goto manual;
 | 
								goto manual;
 | 
				
			||||||
	} else {
 | 
							break;
 | 
				
			||||||
 | 
						case WINDOW_SIZE_SMALLEST:
 | 
				
			||||||
		*sx = *sy = UINT_MAX;
 | 
							*sx = *sy = UINT_MAX;
 | 
				
			||||||
		TAILQ_FOREACH(c, &clients, entry) {
 | 
							TAILQ_FOREACH(loop, &clients, entry) {
 | 
				
			||||||
			if (ignore_client_size(c))
 | 
								if (ignore_client_size(loop))
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			if (w != NULL && !session_has(c->session, w))
 | 
								if (w != NULL && !session_has(loop->session, w))
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			if (w == NULL && c->session != s)
 | 
								if (w == NULL && loop->session != s)
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			cx = c->tty.sx;
 | 
								cx = loop->tty.sx;
 | 
				
			||||||
			cy = c->tty.sy - status_line_size(c);
 | 
								cy = loop->tty.sy - status_line_size(loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (cx < *sx)
 | 
								if (cx < *sx)
 | 
				
			||||||
				*sx = cx;
 | 
									*sx = cx;
 | 
				
			||||||
@@ -128,6 +127,34 @@ default_window_size(struct session *s, struct window *w, u_int *sx, u_int *sy,
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		if (*sx == UINT_MAX || *sy == UINT_MAX)
 | 
							if (*sx == UINT_MAX || *sy == UINT_MAX)
 | 
				
			||||||
			goto manual;
 | 
								goto manual;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case WINDOW_SIZE_LATEST:
 | 
				
			||||||
 | 
							if (c != NULL && !ignore_client_size(c)) {
 | 
				
			||||||
 | 
								*sx = c->tty.sx;
 | 
				
			||||||
 | 
								*sy = c->tty.sy - status_line_size(c);
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								*sx = *sy = UINT_MAX;
 | 
				
			||||||
 | 
								TAILQ_FOREACH(loop, &clients, entry) {
 | 
				
			||||||
 | 
									if (ignore_client_size(loop))
 | 
				
			||||||
 | 
										continue;
 | 
				
			||||||
 | 
									if (w != NULL && loop != w->latest)
 | 
				
			||||||
 | 
										continue;
 | 
				
			||||||
 | 
									s = loop->session;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									cx = loop->tty.sx;
 | 
				
			||||||
 | 
									cy = loop->tty.sy - status_line_size(loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (cx < *sx)
 | 
				
			||||||
 | 
										*sx = cx;
 | 
				
			||||||
 | 
									if (cy < *sy)
 | 
				
			||||||
 | 
										*sy = cy;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (*sx == UINT_MAX || *sy == UINT_MAX)
 | 
				
			||||||
 | 
									goto manual;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case WINDOW_SIZE_MANUAL:
 | 
				
			||||||
 | 
							goto manual;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	goto done;
 | 
						goto done;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								spawn.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								spawn.c
									
									
									
									
									
								
							@@ -155,7 +155,7 @@ spawn_window(struct spawn_context *sc, char **cause)
 | 
				
			|||||||
			xasprintf(cause, "couldn't add window %d", idx);
 | 
								xasprintf(cause, "couldn't add window %d", idx);
 | 
				
			||||||
			return (NULL);
 | 
								return (NULL);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		default_window_size(s, NULL, &sx, &sy, -1);
 | 
							default_window_size(sc->c, s, NULL, &sx, &sy, -1);
 | 
				
			||||||
		if ((w = window_create(sx, sy)) == NULL) {
 | 
							if ((w = window_create(sx, sy)) == NULL) {
 | 
				
			||||||
			winlink_remove(&s->windows, sc->wl);
 | 
								winlink_remove(&s->windows, sc->wl);
 | 
				
			||||||
			xasprintf(cause, "couldn't create window %d", idx);
 | 
								xasprintf(cause, "couldn't create window %d", idx);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							@@ -2196,8 +2196,8 @@ void	 status_prompt_save_history(void);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* resize.c */
 | 
					/* resize.c */
 | 
				
			||||||
void	 resize_window(struct window *, u_int, u_int);
 | 
					void	 resize_window(struct window *, u_int, u_int);
 | 
				
			||||||
void	 default_window_size(struct session *, struct window *, u_int *,
 | 
					void	 default_window_size(struct client *, struct session *, struct window *,
 | 
				
			||||||
	     u_int *, int);
 | 
						     u_int *, u_int *, int);
 | 
				
			||||||
void	 recalculate_size(struct window *);
 | 
					void	 recalculate_size(struct window *);
 | 
				
			||||||
void	 recalculate_sizes(void);
 | 
					void	 recalculate_sizes(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user