mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Make it so using kill-pane to destroy the last pane in a window destroys the
window instead of being an error.
This commit is contained in:
		@@ -61,8 +61,9 @@ cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (window_count_panes(wl->window) == 1) {
 | 
						if (window_count_panes(wl->window) == 1) {
 | 
				
			||||||
		ctx->error(ctx, "can't kill pane: %d", data->pane);
 | 
							/* Only one pane, kill the window. */
 | 
				
			||||||
		return (-1);
 | 
							server_kill_window(wl->window);
 | 
				
			||||||
 | 
							return (0);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	window_remove_pane(wl->window, wp);
 | 
						window_remove_pane(wl->window, wp);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,37 +44,11 @@ cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	struct cmd_target_data	*data = self->data;
 | 
						struct cmd_target_data	*data = self->data;
 | 
				
			||||||
	struct winlink		*wl;
 | 
						struct winlink		*wl;
 | 
				
			||||||
	struct window		*w;
 | 
					 | 
				
			||||||
	struct session		*s;
 | 
					 | 
				
			||||||
	struct client		*c;
 | 
					 | 
				
			||||||
	u_int		 	 i, j;
 | 
					 | 
				
			||||||
	int		 	 destroyed;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
 | 
						if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
 | 
				
			||||||
		return (-1);
 | 
							return (-1);
 | 
				
			||||||
	w = wl->window;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
 | 
						server_kill_window(wl->window);
 | 
				
			||||||
		s = ARRAY_ITEM(&sessions, i);
 | 
					 | 
				
			||||||
		if (s == NULL || !session_has(s, w))
 | 
					 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
		if ((wl = winlink_find_by_window(&s->windows, w)) == NULL)
 | 
					 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		destroyed = session_detach(s, wl);
 | 
					 | 
				
			||||||
		for (j = 0; j < ARRAY_LENGTH(&clients); j++) {
 | 
					 | 
				
			||||||
			c = ARRAY_ITEM(&clients, j);
 | 
					 | 
				
			||||||
			if (c == NULL || c->session != s)
 | 
					 | 
				
			||||||
				continue;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (destroyed) {
 | 
					 | 
				
			||||||
				c->session = NULL;
 | 
					 | 
				
			||||||
				server_write_client(c, MSG_EXIT, NULL, 0);
 | 
					 | 
				
			||||||
			} else
 | 
					 | 
				
			||||||
				server_redraw_client(c);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	recalculate_sizes();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return (0);
 | 
						return (0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										33
									
								
								server-fn.c
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								server-fn.c
									
									
									
									
									
								
							@@ -228,3 +228,36 @@ wrong:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	return (-1);
 | 
						return (-1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					server_kill_window(struct window *w)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct session	*s;
 | 
				
			||||||
 | 
						struct winlink	*wl;
 | 
				
			||||||
 | 
						struct client	*c;
 | 
				
			||||||
 | 
						u_int		 i, j;
 | 
				
			||||||
 | 
						int		 destroyed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
 | 
				
			||||||
 | 
							s = ARRAY_ITEM(&sessions, i);
 | 
				
			||||||
 | 
							if (s == NULL || !session_has(s, w))
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if ((wl = winlink_find_by_window(&s->windows, w)) == NULL)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							destroyed = session_detach(s, wl);
 | 
				
			||||||
 | 
							for (j = 0; j < ARRAY_LENGTH(&clients); j++) {
 | 
				
			||||||
 | 
								c = ARRAY_ITEM(&clients, j);
 | 
				
			||||||
 | 
								if (c == NULL || c->session != s)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if (destroyed) {
 | 
				
			||||||
 | 
									c->session = NULL;
 | 
				
			||||||
 | 
									server_write_client(c, MSG_EXIT, NULL, 0);
 | 
				
			||||||
 | 
								} else
 | 
				
			||||||
 | 
									server_redraw_client(c);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						recalculate_sizes();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								tmux.1
									
									
									
									
									
								
							@@ -768,6 +768,7 @@ returns success.
 | 
				
			|||||||
.Xc
 | 
					.Xc
 | 
				
			||||||
.D1 (alias: Ic killp )
 | 
					.D1 (alias: Ic killp )
 | 
				
			||||||
Destroy the given pane.
 | 
					Destroy the given pane.
 | 
				
			||||||
 | 
					If no panes remain in the containing window, it is also destroyed.
 | 
				
			||||||
.It Xo Ic kill-server
 | 
					.It Xo Ic kill-server
 | 
				
			||||||
.Xc
 | 
					.Xc
 | 
				
			||||||
Kill the
 | 
					Kill the
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1284,6 +1284,7 @@ void	 server_redraw_window(struct window *);
 | 
				
			|||||||
void	 server_status_window(struct window *);
 | 
					void	 server_status_window(struct window *);
 | 
				
			||||||
void	 server_lock(void);
 | 
					void	 server_lock(void);
 | 
				
			||||||
int	 server_unlock(const char *);
 | 
					int	 server_unlock(const char *);
 | 
				
			||||||
 | 
					void	 server_kill_window(struct window *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* status.c */
 | 
					/* status.c */
 | 
				
			||||||
int	 status_redraw(struct client *);
 | 
					int	 status_redraw(struct client *);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user