mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Merge pull request #2499 from RyanDwyer/refactor-destroy-functions
Refactor destroy functions and save workspaces when there's no outputs
This commit is contained in:
		
						commit
						e86d99acd6
					
				
					 19 changed files with 267 additions and 308 deletions
				
			
		| 
						 | 
					@ -39,6 +39,12 @@ struct sway_output {
 | 
				
			||||||
	} events;
 | 
						} events;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct sway_container *output_create(struct sway_output *sway_output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void output_destroy(struct sway_container *output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void output_begin_destroy(struct sway_container *output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef void (*sway_surface_iterator_func_t)(struct sway_output *output,
 | 
					typedef void (*sway_surface_iterator_func_t)(struct sway_output *output,
 | 
				
			||||||
	struct wlr_surface *surface, struct wlr_box *box, float rotation,
 | 
						struct wlr_surface *surface, struct wlr_box *box, float rotation,
 | 
				
			||||||
	void *user_data);
 | 
						void *user_data);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -176,27 +176,6 @@ struct sway_container *container_create(enum sway_container_type type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const char *container_type_to_str(enum sway_container_type type);
 | 
					const char *container_type_to_str(enum sway_container_type type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct sway_container *output_create(struct sway_output *sway_output);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Create a new container container. A container container can be a a child of
 | 
					 | 
				
			||||||
 * a workspace container or another container container.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
struct sway_container *container_container_create();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Create a new output. Outputs are children of the root container and have no
 | 
					 | 
				
			||||||
 * order in the tree structure.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
struct sway_container *output_create(struct sway_output *sway_output);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Create a new workspace container. Workspaces are children of an output
 | 
					 | 
				
			||||||
 * container and are ordered alphabetically by name.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
struct sway_container *workspace_create(struct sway_container *output,
 | 
					 | 
				
			||||||
		const char *name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Create a new view container. A view can be a child of a workspace container
 | 
					 * Create a new view container. A view can be a child of a workspace container
 | 
				
			||||||
 * or a container container and are rendered in the order and structure of
 | 
					 * or a container container and are rendered in the order and structure of
 | 
				
			||||||
| 
						 | 
					@ -205,9 +184,9 @@ struct sway_container *workspace_create(struct sway_container *output,
 | 
				
			||||||
struct sway_container *container_view_create(
 | 
					struct sway_container *container_view_create(
 | 
				
			||||||
		struct sway_container *sibling, struct sway_view *sway_view);
 | 
							struct sway_container *sibling, struct sway_view *sway_view);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void container_free(struct sway_container *cont);
 | 
					void container_destroy(struct sway_container *con);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct sway_container *container_destroy(struct sway_container *container);
 | 
					void container_begin_destroy(struct sway_container *con);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct sway_container *container_close(struct sway_container *container);
 | 
					struct sway_container *container_close(struct sway_container *container);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -255,10 +234,7 @@ void container_update_textures_recursive(struct sway_container *con);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void container_damage_whole(struct sway_container *container);
 | 
					void container_damage_whole(struct sway_container *container);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool container_reap_empty(struct sway_container *con);
 | 
					struct sway_container *container_reap_empty(struct sway_container *con);
 | 
				
			||||||
 | 
					 | 
				
			||||||
struct sway_container *container_reap_empty_recursive(
 | 
					 | 
				
			||||||
		struct sway_container *con);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct sway_container *container_flatten(struct sway_container *container);
 | 
					struct sway_container *container_flatten(struct sway_container *container);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,7 @@ struct sway_root {
 | 
				
			||||||
	struct wl_list outputs; // sway_output::link
 | 
						struct wl_list outputs; // sway_output::link
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	list_t *scratchpad; // struct sway_container
 | 
						list_t *scratchpad; // struct sway_container
 | 
				
			||||||
 | 
						list_t *saved_workspaces; // For when there's no connected outputs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct {
 | 
						struct {
 | 
				
			||||||
		struct wl_signal new_container;
 | 
							struct wl_signal new_container;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -284,10 +284,10 @@ void view_for_each_popup(struct sway_view *view,
 | 
				
			||||||
void view_init(struct sway_view *view, enum sway_view_type type,
 | 
					void view_init(struct sway_view *view, enum sway_view_type type,
 | 
				
			||||||
	const struct sway_view_impl *impl);
 | 
						const struct sway_view_impl *impl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void view_free(struct sway_view *view);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void view_destroy(struct sway_view *view);
 | 
					void view_destroy(struct sway_view *view);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void view_begin_destroy(struct sway_view *view);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void view_map(struct sway_view *view, struct wlr_surface *wlr_surface);
 | 
					void view_map(struct sway_view *view, struct wlr_surface *wlr_surface);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void view_unmap(struct sway_view *view);
 | 
					void view_unmap(struct sway_view *view);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,6 +18,15 @@ extern char *prev_workspace_name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct sway_container *workspace_get_initial_output(const char *name);
 | 
					struct sway_container *workspace_get_initial_output(const char *name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct sway_container *workspace_create(struct sway_container *output,
 | 
				
			||||||
 | 
							const char *name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void workspace_destroy(struct sway_container *workspace);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void workspace_begin_destroy(struct sway_container *workspace);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void workspace_consider_destroy(struct sway_container *ws);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *workspace_next_name(const char *output_name);
 | 
					char *workspace_next_name(const char *output_name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool workspace_switch(struct sway_container *workspace,
 | 
					bool workspace_switch(struct sway_container *workspace,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -247,7 +247,7 @@ static void workspace_move_to_output(struct sway_container *workspace,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Try to remove an empty workspace from the destination output.
 | 
						// Try to remove an empty workspace from the destination output.
 | 
				
			||||||
	container_reap_empty_recursive(new_output_focus);
 | 
						container_reap_empty(new_output_focus);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	output_sort_workspaces(output);
 | 
						output_sort_workspaces(output);
 | 
				
			||||||
	seat_set_focus(seat, output);
 | 
						seat_set_focus(seat, output);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -181,13 +181,11 @@ void apply_output_config(struct output_config *oc, struct sway_container *output
 | 
				
			||||||
	struct wlr_output *wlr_output = output->sway_output->wlr_output;
 | 
						struct wlr_output *wlr_output = output->sway_output->wlr_output;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (oc && oc->enabled == 0) {
 | 
						if (oc && oc->enabled == 0) {
 | 
				
			||||||
		struct sway_output *sway_output = output->sway_output;
 | 
					 | 
				
			||||||
		if (output->sway_output->bg_pid != 0) {
 | 
							if (output->sway_output->bg_pid != 0) {
 | 
				
			||||||
			terminate_swaybg(output->sway_output->bg_pid);
 | 
								terminate_swaybg(output->sway_output->bg_pid);
 | 
				
			||||||
			output->sway_output->bg_pid = 0;
 | 
								output->sway_output->bg_pid = 0;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		container_destroy(output);
 | 
							output_begin_destroy(output);
 | 
				
			||||||
		sway_output->swayc = NULL;
 | 
					 | 
				
			||||||
		wlr_output_layout_remove(root_container.sway_root->output_layout,
 | 
							wlr_output_layout_remove(root_container.sway_root->output_layout,
 | 
				
			||||||
			wlr_output);
 | 
								wlr_output);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -498,7 +498,7 @@ void output_damage_whole_container(struct sway_output *output,
 | 
				
			||||||
static void damage_handle_destroy(struct wl_listener *listener, void *data) {
 | 
					static void damage_handle_destroy(struct wl_listener *listener, void *data) {
 | 
				
			||||||
	struct sway_output *output =
 | 
						struct sway_output *output =
 | 
				
			||||||
		wl_container_of(listener, output, damage_destroy);
 | 
							wl_container_of(listener, output, damage_destroy);
 | 
				
			||||||
	container_destroy(output->swayc);
 | 
						output_begin_destroy(output->swayc);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void handle_destroy(struct wl_listener *listener, void *data) {
 | 
					static void handle_destroy(struct wl_listener *listener, void *data) {
 | 
				
			||||||
| 
						 | 
					@ -506,7 +506,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
 | 
				
			||||||
	wl_signal_emit(&output->events.destroy, output);
 | 
						wl_signal_emit(&output->events.destroy, output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (output->swayc) {
 | 
						if (output->swayc) {
 | 
				
			||||||
		container_destroy(output->swayc);
 | 
							output_begin_destroy(output->swayc);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_list_remove(&output->link);
 | 
						wl_list_remove(&output->link);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,7 +54,22 @@ static void transaction_destroy(struct sway_transaction *transaction) {
 | 
				
			||||||
			con->instruction = NULL;
 | 
								con->instruction = NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (con->destroying && con->ntxnrefs == 0) {
 | 
							if (con->destroying && con->ntxnrefs == 0) {
 | 
				
			||||||
			container_free(con);
 | 
								switch (con->type) {
 | 
				
			||||||
 | 
								case C_ROOT:
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								case C_OUTPUT:
 | 
				
			||||||
 | 
									output_destroy(con);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								case C_WORKSPACE:
 | 
				
			||||||
 | 
									workspace_destroy(con);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								case C_CONTAINER:
 | 
				
			||||||
 | 
								case C_VIEW:
 | 
				
			||||||
 | 
									container_destroy(con);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								case C_TYPES:
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		free(instruction);
 | 
							free(instruction);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -448,7 +448,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
 | 
				
			||||||
	wl_list_remove(&xdg_shell_view->map.link);
 | 
						wl_list_remove(&xdg_shell_view->map.link);
 | 
				
			||||||
	wl_list_remove(&xdg_shell_view->unmap.link);
 | 
						wl_list_remove(&xdg_shell_view->unmap.link);
 | 
				
			||||||
	view->wlr_xdg_surface = NULL;
 | 
						view->wlr_xdg_surface = NULL;
 | 
				
			||||||
	view_destroy(view);
 | 
						view_begin_destroy(view);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct sway_view *view_from_wlr_xdg_surface(
 | 
					struct sway_view *view_from_wlr_xdg_surface(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -441,7 +441,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
 | 
				
			||||||
	wl_list_remove(&xdg_shell_v6_view->map.link);
 | 
						wl_list_remove(&xdg_shell_v6_view->map.link);
 | 
				
			||||||
	wl_list_remove(&xdg_shell_v6_view->unmap.link);
 | 
						wl_list_remove(&xdg_shell_v6_view->unmap.link);
 | 
				
			||||||
	view->wlr_xdg_surface_v6 = NULL;
 | 
						view->wlr_xdg_surface_v6 = NULL;
 | 
				
			||||||
	view_destroy(view);
 | 
						view_begin_destroy(view);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct sway_view *view_from_wlr_xdg_surface_v6(
 | 
					struct sway_view *view_from_wlr_xdg_surface_v6(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -341,7 +341,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
 | 
				
			||||||
	wl_list_remove(&xwayland_view->set_hints.link);
 | 
						wl_list_remove(&xwayland_view->set_hints.link);
 | 
				
			||||||
	wl_list_remove(&xwayland_view->map.link);
 | 
						wl_list_remove(&xwayland_view->map.link);
 | 
				
			||||||
	wl_list_remove(&xwayland_view->unmap.link);
 | 
						wl_list_remove(&xwayland_view->unmap.link);
 | 
				
			||||||
	view_destroy(&xwayland_view->view);
 | 
						view_begin_destroy(&xwayland_view->view);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void handle_unmap(struct wl_listener *listener, void *data) {
 | 
					static void handle_unmap(struct wl_listener *listener, void *data) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -694,14 +694,12 @@ void seat_set_focus_warp(struct sway_seat *seat,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// clean up unfocused empty workspace on new output
 | 
						// clean up unfocused empty workspace on new output
 | 
				
			||||||
	if (new_output_last_ws) {
 | 
						if (new_output_last_ws) {
 | 
				
			||||||
		if (!workspace_is_visible(new_output_last_ws)
 | 
							workspace_consider_destroy(new_output_last_ws);
 | 
				
			||||||
				&& workspace_is_empty(new_output_last_ws)) {
 | 
							if (new_output_last_ws->destroying &&
 | 
				
			||||||
			if (last_workspace == new_output_last_ws) {
 | 
									last_workspace == new_output_last_ws) {
 | 
				
			||||||
			last_focus = NULL;
 | 
								last_focus = NULL;
 | 
				
			||||||
			last_workspace = NULL;
 | 
								last_workspace = NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
			container_destroy(new_output_last_ws);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Close any popups on the old focus
 | 
						// Close any popups on the old focus
 | 
				
			||||||
| 
						 | 
					@ -716,13 +714,10 @@ void seat_set_focus_warp(struct sway_seat *seat,
 | 
				
			||||||
			if (notify && last_workspace != new_workspace) {
 | 
								if (notify && last_workspace != new_workspace) {
 | 
				
			||||||
				 ipc_event_workspace(last_workspace, new_workspace, "focus");
 | 
									 ipc_event_workspace(last_workspace, new_workspace, "focus");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (!workspace_is_visible(last_workspace)
 | 
								workspace_consider_destroy(last_workspace);
 | 
				
			||||||
					&& workspace_is_empty(last_workspace)) {
 | 
								if (last_workspace->destroying && last_workspace == last_focus) {
 | 
				
			||||||
				if (last_workspace == last_focus) {
 | 
					 | 
				
			||||||
				last_focus = NULL;
 | 
									last_focus = NULL;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
				container_destroy(last_workspace);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (config->mouse_warping && warp) {
 | 
							if (config->mouse_warping && warp) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -104,209 +104,52 @@ struct sway_container *container_create(enum sway_container_type type) {
 | 
				
			||||||
	return c;
 | 
						return c;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void container_workspace_free(struct sway_workspace *ws) {
 | 
					void container_destroy(struct sway_container *con) {
 | 
				
			||||||
	list_foreach(ws->output_priority, free);
 | 
						if (!sway_assert(con->type == C_CONTAINER || con->type == C_VIEW,
 | 
				
			||||||
	list_free(ws->output_priority);
 | 
									"Expected a container or view")) {
 | 
				
			||||||
	list_free(ws->floating);
 | 
							return;
 | 
				
			||||||
	free(ws);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if (!sway_assert(con->destroying,
 | 
				
			||||||
void container_free(struct sway_container *cont) {
 | 
					 | 
				
			||||||
	if (!sway_assert(cont->destroying,
 | 
					 | 
				
			||||||
				"Tried to free container which wasn't marked as destroying")) {
 | 
									"Tried to free container which wasn't marked as destroying")) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (!sway_assert(cont->ntxnrefs == 0, "Tried to free container "
 | 
						if (!sway_assert(con->ntxnrefs == 0, "Tried to free container "
 | 
				
			||||||
				"which is still referenced by transactions")) {
 | 
									"which is still referenced by transactions")) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	free(cont->name);
 | 
						free(con->name);
 | 
				
			||||||
	free(cont->formatted_title);
 | 
						free(con->formatted_title);
 | 
				
			||||||
	wlr_texture_destroy(cont->title_focused);
 | 
						wlr_texture_destroy(con->title_focused);
 | 
				
			||||||
	wlr_texture_destroy(cont->title_focused_inactive);
 | 
						wlr_texture_destroy(con->title_focused_inactive);
 | 
				
			||||||
	wlr_texture_destroy(cont->title_unfocused);
 | 
						wlr_texture_destroy(con->title_unfocused);
 | 
				
			||||||
	wlr_texture_destroy(cont->title_urgent);
 | 
						wlr_texture_destroy(con->title_urgent);
 | 
				
			||||||
	list_free(cont->children);
 | 
						list_free(con->children);
 | 
				
			||||||
	list_free(cont->current.children);
 | 
						list_free(con->current.children);
 | 
				
			||||||
	list_free(cont->outputs);
 | 
						list_free(con->outputs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (cont->type) {
 | 
						if (con->type == C_VIEW) {
 | 
				
			||||||
	case C_ROOT:
 | 
							struct sway_view *view = con->sway_view;
 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	case C_OUTPUT:
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	case C_WORKSPACE:
 | 
					 | 
				
			||||||
		container_workspace_free(cont->sway_workspace);
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	case C_CONTAINER:
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	case C_VIEW:
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			struct sway_view *view = cont->sway_view;
 | 
					 | 
				
			||||||
		view->swayc = NULL;
 | 
							view->swayc = NULL;
 | 
				
			||||||
		free(view->title_format);
 | 
							free(view->title_format);
 | 
				
			||||||
		view->title_format = NULL;
 | 
							view->title_format = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (view->destroying) {
 | 
							if (view->destroying) {
 | 
				
			||||||
				view_free(view);
 | 
								view_destroy(view);
 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	case C_TYPES:
 | 
					 | 
				
			||||||
		sway_assert(false, "Didn't expect to see C_TYPES here");
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	free(cont);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static struct sway_container *container_destroy_noreaping(
 | 
					 | 
				
			||||||
		struct sway_container *con);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static struct sway_container *container_workspace_destroy(
 | 
					 | 
				
			||||||
		struct sway_container *workspace) {
 | 
					 | 
				
			||||||
	if (!sway_assert(workspace, "cannot destroy null workspace")) {
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	struct sway_container *output = container_parent(workspace, C_OUTPUT);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// If we're destroying the output, it will be NULL here. Return the root so
 | 
					 | 
				
			||||||
	// that it doesn't appear that the workspace has refused to be destoyed,
 | 
					 | 
				
			||||||
	// which would leave it in a broken state with no parent.
 | 
					 | 
				
			||||||
	if (output == NULL) {
 | 
					 | 
				
			||||||
		return &root_container;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Do not destroy this if it's the last workspace on this output
 | 
					 | 
				
			||||||
	if (output->children->length == 1) {
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	wlr_log(WLR_DEBUG, "destroying workspace '%s'", workspace->name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!workspace_is_empty(workspace)) {
 | 
					 | 
				
			||||||
		// Move children to a different workspace on this output
 | 
					 | 
				
			||||||
		struct sway_container *new_workspace = NULL;
 | 
					 | 
				
			||||||
		for (int i = 0; i < output->children->length; i++) {
 | 
					 | 
				
			||||||
			if (output->children->items[i] != workspace) {
 | 
					 | 
				
			||||||
				new_workspace = output->children->items[i];
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		wlr_log(WLR_DEBUG, "moving children to different workspace '%s' -> '%s'",
 | 
						free(con);
 | 
				
			||||||
			workspace->name, new_workspace->name);
 | 
					 | 
				
			||||||
		for (int i = 0; i < workspace->children->length; i++) {
 | 
					 | 
				
			||||||
			container_move_to(workspace->children->items[i], new_workspace);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		list_t *floating = workspace->sway_workspace->floating;
 | 
					 | 
				
			||||||
		for (int i = 0; i < floating->length; i++) {
 | 
					 | 
				
			||||||
			struct sway_container *floater = floating->items[i];
 | 
					 | 
				
			||||||
			container_remove_child(floater);
 | 
					 | 
				
			||||||
			workspace_add_floating(new_workspace, floater);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return output;
 | 
					void container_begin_destroy(struct sway_container *con) {
 | 
				
			||||||
}
 | 
						if (!sway_assert(con->type == C_CONTAINER || con->type == C_VIEW,
 | 
				
			||||||
 | 
									"Expected a container or view")) {
 | 
				
			||||||
static void untrack_output(struct sway_container *con, void *data) {
 | 
							return;
 | 
				
			||||||
	struct sway_output *output = data;
 | 
					 | 
				
			||||||
	int index = list_find(con->outputs, output);
 | 
					 | 
				
			||||||
	if (index != -1) {
 | 
					 | 
				
			||||||
		list_del(con->outputs, index);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static struct sway_container *container_output_destroy(
 | 
					 | 
				
			||||||
		struct sway_container *output) {
 | 
					 | 
				
			||||||
	if (!sway_assert(output, "cannot destroy null output")) {
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (output->children->length > 0) {
 | 
					 | 
				
			||||||
		// TODO save workspaces when there are no outputs.
 | 
					 | 
				
			||||||
		// TODO also check if there will ever be no outputs except for exiting
 | 
					 | 
				
			||||||
		// program
 | 
					 | 
				
			||||||
		if (root_container.children->length > 1) {
 | 
					 | 
				
			||||||
			// Move workspace from this output to another output
 | 
					 | 
				
			||||||
			struct sway_container *fallback_output =
 | 
					 | 
				
			||||||
				root_container.children->items[0];
 | 
					 | 
				
			||||||
			if (fallback_output == output) {
 | 
					 | 
				
			||||||
				fallback_output = root_container.children->items[1];
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			while (output->children->length) {
 | 
					 | 
				
			||||||
				struct sway_container *workspace = output->children->items[0];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				struct sway_container *new_output =
 | 
					 | 
				
			||||||
					workspace_output_get_highest_available(workspace, output);
 | 
					 | 
				
			||||||
				if (!new_output) {
 | 
					 | 
				
			||||||
					new_output = fallback_output;
 | 
					 | 
				
			||||||
					workspace_output_add_priority(workspace, new_output);
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				container_remove_child(workspace);
 | 
					 | 
				
			||||||
				if (!workspace_is_empty(workspace)) {
 | 
					 | 
				
			||||||
					container_add_child(new_output, workspace);
 | 
					 | 
				
			||||||
					ipc_event_workspace(NULL, workspace, "move");
 | 
					 | 
				
			||||||
				} else {
 | 
					 | 
				
			||||||
					container_destroy(workspace);
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				output_sort_workspaces(new_output);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	root_for_each_container(untrack_output, output->sway_output);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	wl_list_remove(&output->sway_output->mode.link);
 | 
					 | 
				
			||||||
	wl_list_remove(&output->sway_output->transform.link);
 | 
					 | 
				
			||||||
	wl_list_remove(&output->sway_output->scale.link);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	wl_list_remove(&output->sway_output->damage_destroy.link);
 | 
					 | 
				
			||||||
	wl_list_remove(&output->sway_output->damage_frame.link);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	output->sway_output->swayc = NULL;
 | 
					 | 
				
			||||||
	output->sway_output = NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	wlr_log(WLR_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return &root_container;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Implement the actual destroy logic, without reaping.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static struct sway_container *container_destroy_noreaping(
 | 
					 | 
				
			||||||
		struct sway_container *con) {
 | 
					 | 
				
			||||||
	if (con == NULL) {
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (con->destroying) {
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_signal_emit(&con->events.destroy, con);
 | 
						wl_signal_emit(&con->events.destroy, con);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// emit IPC event
 | 
					 | 
				
			||||||
	if (con->type == C_VIEW) {
 | 
						if (con->type == C_VIEW) {
 | 
				
			||||||
		ipc_event_window(con, "close");
 | 
							ipc_event_window(con, "close");
 | 
				
			||||||
	} else if (con->type == C_WORKSPACE) {
 | 
					 | 
				
			||||||
		ipc_event_workspace(NULL, con, "empty");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// The below functions move their children to somewhere else.
 | 
					 | 
				
			||||||
	if (con->type == C_OUTPUT) {
 | 
					 | 
				
			||||||
		container_output_destroy(con);
 | 
					 | 
				
			||||||
	} else if (con->type == C_WORKSPACE) {
 | 
					 | 
				
			||||||
		// Workspaces will refuse to be destroyed if they're the last workspace
 | 
					 | 
				
			||||||
		// on their output.
 | 
					 | 
				
			||||||
		if (!container_workspace_destroy(con)) {
 | 
					 | 
				
			||||||
			return NULL;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	container_end_mouse_operation(con);
 | 
						container_end_mouse_operation(con);
 | 
				
			||||||
| 
						 | 
					@ -318,51 +161,22 @@ static struct sway_container *container_destroy_noreaping(
 | 
				
			||||||
		root_scratchpad_remove_container(con);
 | 
							root_scratchpad_remove_container(con);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!con->parent) {
 | 
						if (con->parent) {
 | 
				
			||||||
		return NULL;
 | 
							container_remove_child(con);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return container_remove_child(con);
 | 
					struct sway_container *container_reap_empty(struct sway_container *con) {
 | 
				
			||||||
}
 | 
						while (con && con->type == C_CONTAINER) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
bool container_reap_empty(struct sway_container *con) {
 | 
					 | 
				
			||||||
	switch (con->type) {
 | 
					 | 
				
			||||||
	case C_ROOT:
 | 
					 | 
				
			||||||
	case C_OUTPUT:
 | 
					 | 
				
			||||||
		// dont reap these
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	case C_WORKSPACE:
 | 
					 | 
				
			||||||
		if (!workspace_is_visible(con) && workspace_is_empty(con)) {
 | 
					 | 
				
			||||||
			wlr_log(WLR_DEBUG, "Destroying workspace via reaper");
 | 
					 | 
				
			||||||
			container_destroy_noreaping(con);
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	case C_CONTAINER:
 | 
					 | 
				
			||||||
		if (con->children->length == 0) {
 | 
					 | 
				
			||||||
			container_destroy_noreaping(con);
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	case C_VIEW:
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	case C_TYPES:
 | 
					 | 
				
			||||||
		sway_assert(false, "container_reap_empty called on an invalid "
 | 
					 | 
				
			||||||
			"container");
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return false;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct sway_container *container_reap_empty_recursive(
 | 
					 | 
				
			||||||
		struct sway_container *con) {
 | 
					 | 
				
			||||||
	while (con) {
 | 
					 | 
				
			||||||
		struct sway_container *next = con->parent;
 | 
							struct sway_container *next = con->parent;
 | 
				
			||||||
		if (!container_reap_empty(con)) {
 | 
							if (con->children->length == 0) {
 | 
				
			||||||
			break;
 | 
								container_begin_destroy(con);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		con = next;
 | 
							con = next;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if (con && con->type == C_WORKSPACE) {
 | 
				
			||||||
 | 
							workspace_consider_destroy(con);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return con;
 | 
						return con;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -371,34 +185,12 @@ struct sway_container *container_flatten(struct sway_container *container) {
 | 
				
			||||||
		struct sway_container *child = container->children->items[0];
 | 
							struct sway_container *child = container->children->items[0];
 | 
				
			||||||
		struct sway_container *parent = container->parent;
 | 
							struct sway_container *parent = container->parent;
 | 
				
			||||||
		container_replace_child(container, child);
 | 
							container_replace_child(container, child);
 | 
				
			||||||
		container_destroy_noreaping(container);
 | 
							container_begin_destroy(container);
 | 
				
			||||||
		container = parent;
 | 
							container = parent;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return container;
 | 
						return container;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * container_destroy() is the first step in destroying a container. We'll emit
 | 
					 | 
				
			||||||
 * events, detach it from the tree and mark it as destroying. The container will
 | 
					 | 
				
			||||||
 * remain in memory until it's no longer used by a transaction, then it will be
 | 
					 | 
				
			||||||
 * freed via container_free().
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This function just wraps container_destroy_noreaping(), then does reaping.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
struct sway_container *container_destroy(struct sway_container *con) {
 | 
					 | 
				
			||||||
	if (con->is_fullscreen) {
 | 
					 | 
				
			||||||
		struct sway_container *ws = container_parent(con, C_WORKSPACE);
 | 
					 | 
				
			||||||
		ws->sway_workspace->fullscreen = NULL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	struct sway_container *parent = container_destroy_noreaping(con);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!parent) {
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return container_reap_empty_recursive(parent);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void container_close_func(struct sway_container *container, void *data) {
 | 
					static void container_close_func(struct sway_container *container, void *data) {
 | 
				
			||||||
	if (container->type == C_VIEW) {
 | 
						if (container->type == C_VIEW) {
 | 
				
			||||||
		view_close(container->sway_view);
 | 
							view_close(container->sway_view);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -302,7 +302,7 @@ static void workspace_rejigger(struct sway_container *ws,
 | 
				
			||||||
		move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT;
 | 
							move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	container_flatten(ws);
 | 
						container_flatten(ws);
 | 
				
			||||||
	container_reap_empty_recursive(original_parent);
 | 
						container_reap_empty(original_parent);
 | 
				
			||||||
	container_create_notify(new_parent);
 | 
						container_create_notify(new_parent);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -325,7 +325,7 @@ static void move_out_of_tabs_stacks(struct sway_container *container,
 | 
				
			||||||
		container_insert_child(new_parent->parent, container, offs < 0 ? 0 : 1);
 | 
							container_insert_child(new_parent->parent, container, offs < 0 ? 0 : 1);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		container_insert_child(new_parent, container, offs < 0 ? 0 : 1);
 | 
							container_insert_child(new_parent, container, offs < 0 ? 0 : 1);
 | 
				
			||||||
		container_reap_empty_recursive(new_parent->parent);
 | 
							container_reap_empty(new_parent->parent);
 | 
				
			||||||
		container_flatten(new_parent->parent);
 | 
							container_flatten(new_parent->parent);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	container_create_notify(new_parent);
 | 
						container_create_notify(new_parent);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,7 @@
 | 
				
			||||||
#include "log.h"
 | 
					#include "log.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void restore_workspaces(struct sway_container *output) {
 | 
					static void restore_workspaces(struct sway_container *output) {
 | 
				
			||||||
 | 
						// Workspace output priority
 | 
				
			||||||
	for (int i = 0; i < root_container.children->length; i++) {
 | 
						for (int i = 0; i < root_container.children->length; i++) {
 | 
				
			||||||
		struct sway_container *other = root_container.children->items[i];
 | 
							struct sway_container *other = root_container.children->items[i];
 | 
				
			||||||
		if (other == output) {
 | 
							if (other == output) {
 | 
				
			||||||
| 
						 | 
					@ -29,6 +30,15 @@ static void restore_workspaces(struct sway_container *output) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Saved workspaces
 | 
				
			||||||
 | 
						list_t *saved = root_container.sway_root->saved_workspaces;
 | 
				
			||||||
 | 
						for (int i = 0; i < saved->length; ++i) {
 | 
				
			||||||
 | 
							struct sway_container *ws = saved->items[i];
 | 
				
			||||||
 | 
							container_add_child(output, ws);
 | 
				
			||||||
 | 
							ipc_event_workspace(NULL, ws, "move");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						saved->length = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	output_sort_workspaces(output);
 | 
						output_sort_workspaces(output);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,7 +78,7 @@ struct sway_container *output_create(
 | 
				
			||||||
	output->sway_output = sway_output;
 | 
						output->sway_output = sway_output;
 | 
				
			||||||
	output->name = strdup(name);
 | 
						output->name = strdup(name);
 | 
				
			||||||
	if (output->name == NULL) {
 | 
						if (output->name == NULL) {
 | 
				
			||||||
		container_destroy(output);
 | 
							output_begin_destroy(output);
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -103,6 +113,102 @@ struct sway_container *output_create(
 | 
				
			||||||
	return output;
 | 
						return output;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void output_evacuate(struct sway_container *output) {
 | 
				
			||||||
 | 
						if (!output->children->length) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						struct sway_container *fallback_output = NULL;
 | 
				
			||||||
 | 
						if (root_container.children->length > 1) {
 | 
				
			||||||
 | 
							fallback_output = root_container.children->items[0];
 | 
				
			||||||
 | 
							if (fallback_output == output) {
 | 
				
			||||||
 | 
								fallback_output = root_container.children->items[1];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (output->children->length) {
 | 
				
			||||||
 | 
							struct sway_container *workspace = output->children->items[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							struct sway_container *new_output =
 | 
				
			||||||
 | 
								workspace_output_get_highest_available(workspace, output);
 | 
				
			||||||
 | 
							if (!new_output) {
 | 
				
			||||||
 | 
								new_output = fallback_output;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							container_remove_child(workspace);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (new_output) {
 | 
				
			||||||
 | 
								workspace_output_add_priority(workspace, new_output);
 | 
				
			||||||
 | 
								container_add_child(new_output, workspace);
 | 
				
			||||||
 | 
								output_sort_workspaces(new_output);
 | 
				
			||||||
 | 
								ipc_event_workspace(NULL, workspace, "move");
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								list_add(root_container.sway_root->saved_workspaces, workspace);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void output_destroy(struct sway_container *output) {
 | 
				
			||||||
 | 
						if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (!sway_assert(output->destroying,
 | 
				
			||||||
 | 
									"Tried to free output which wasn't marked as destroying")) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (!sway_assert(output->ntxnrefs == 0, "Tried to free output "
 | 
				
			||||||
 | 
									"which is still referenced by transactions")) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						free(output->name);
 | 
				
			||||||
 | 
						free(output->formatted_title);
 | 
				
			||||||
 | 
						wlr_texture_destroy(output->title_focused);
 | 
				
			||||||
 | 
						wlr_texture_destroy(output->title_focused_inactive);
 | 
				
			||||||
 | 
						wlr_texture_destroy(output->title_unfocused);
 | 
				
			||||||
 | 
						wlr_texture_destroy(output->title_urgent);
 | 
				
			||||||
 | 
						list_free(output->children);
 | 
				
			||||||
 | 
						list_free(output->current.children);
 | 
				
			||||||
 | 
						list_free(output->outputs);
 | 
				
			||||||
 | 
						free(output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// NOTE: We don't actually destroy the sway_output here
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void untrack_output(struct sway_container *con, void *data) {
 | 
				
			||||||
 | 
						struct sway_output *output = data;
 | 
				
			||||||
 | 
						int index = list_find(con->outputs, output);
 | 
				
			||||||
 | 
						if (index != -1) {
 | 
				
			||||||
 | 
							list_del(con->outputs, index);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void output_begin_destroy(struct sway_container *output) {
 | 
				
			||||||
 | 
						if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						wlr_log(WLR_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
 | 
				
			||||||
 | 
						wl_signal_emit(&output->events.destroy, output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						output_evacuate(output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						output->destroying = true;
 | 
				
			||||||
 | 
						container_set_dirty(output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						root_for_each_container(untrack_output, output->sway_output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						wl_list_remove(&output->sway_output->mode.link);
 | 
				
			||||||
 | 
						wl_list_remove(&output->sway_output->transform.link);
 | 
				
			||||||
 | 
						wl_list_remove(&output->sway_output->scale.link);
 | 
				
			||||||
 | 
						wl_list_remove(&output->sway_output->damage_destroy.link);
 | 
				
			||||||
 | 
						wl_list_remove(&output->sway_output->damage_frame.link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						output->sway_output->swayc = NULL;
 | 
				
			||||||
 | 
						output->sway_output = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (output->parent) {
 | 
				
			||||||
 | 
							container_remove_child(output);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void output_for_each_workspace(struct sway_container *output,
 | 
					void output_for_each_workspace(struct sway_container *output,
 | 
				
			||||||
		void (*f)(struct sway_container *con, void *data), void *data) {
 | 
							void (*f)(struct sway_container *con, void *data), void *data) {
 | 
				
			||||||
	if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
 | 
						if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,6 +39,7 @@ void root_create(void) {
 | 
				
			||||||
	wl_list_init(&root_container.sway_root->drag_icons);
 | 
						wl_list_init(&root_container.sway_root->drag_icons);
 | 
				
			||||||
	wl_signal_init(&root_container.sway_root->events.new_container);
 | 
						wl_signal_init(&root_container.sway_root->events.new_container);
 | 
				
			||||||
	root_container.sway_root->scratchpad = create_list();
 | 
						root_container.sway_root->scratchpad = create_list();
 | 
				
			||||||
 | 
						root_container.sway_root->saved_workspaces = create_list();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	root_container.sway_root->output_layout_change.notify =
 | 
						root_container.sway_root->output_layout_change.notify =
 | 
				
			||||||
		output_layout_handle_change;
 | 
							output_layout_handle_change;
 | 
				
			||||||
| 
						 | 
					@ -50,6 +51,7 @@ void root_destroy(void) {
 | 
				
			||||||
	// sway_root
 | 
						// sway_root
 | 
				
			||||||
	wl_list_remove(&root_container.sway_root->output_layout_change.link);
 | 
						wl_list_remove(&root_container.sway_root->output_layout_change.link);
 | 
				
			||||||
	list_free(root_container.sway_root->scratchpad);
 | 
						list_free(root_container.sway_root->scratchpad);
 | 
				
			||||||
 | 
						list_free(root_container.sway_root->saved_workspaces);
 | 
				
			||||||
	wlr_output_layout_destroy(root_container.sway_root->output_layout);
 | 
						wlr_output_layout_destroy(root_container.sway_root->output_layout);
 | 
				
			||||||
	free(root_container.sway_root);
 | 
						free(root_container.sway_root);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,7 +35,7 @@ void view_init(struct sway_view *view, enum sway_view_type type,
 | 
				
			||||||
	wl_signal_init(&view->events.unmap);
 | 
						wl_signal_init(&view->events.unmap);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void view_free(struct sway_view *view) {
 | 
					void view_destroy(struct sway_view *view) {
 | 
				
			||||||
	if (!sway_assert(view->surface == NULL, "Tried to free mapped view")) {
 | 
						if (!sway_assert(view->surface == NULL, "Tried to free mapped view")) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -75,14 +75,14 @@ void view_free(struct sway_view *view) {
 | 
				
			||||||
 * destroying flag will make the view get freed when the transaction is
 | 
					 * destroying flag will make the view get freed when the transaction is
 | 
				
			||||||
 * finished.
 | 
					 * finished.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void view_destroy(struct sway_view *view) {
 | 
					void view_begin_destroy(struct sway_view *view) {
 | 
				
			||||||
	if (!sway_assert(view->surface == NULL, "Tried to destroy a mapped view")) {
 | 
						if (!sway_assert(view->surface == NULL, "Tried to destroy a mapped view")) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	view->destroying = true;
 | 
						view->destroying = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!view->swayc) {
 | 
						if (!view->swayc) {
 | 
				
			||||||
		view_free(view);
 | 
							view_destroy(view);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -560,7 +560,9 @@ void view_unmap(struct sway_view *view) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool was_fullscreen = view->swayc->is_fullscreen;
 | 
						bool was_fullscreen = view->swayc->is_fullscreen;
 | 
				
			||||||
	struct sway_container *surviving_ancestor = container_destroy(view->swayc);
 | 
						struct sway_container *parent = view->swayc->parent;
 | 
				
			||||||
 | 
						container_begin_destroy(view->swayc);
 | 
				
			||||||
 | 
						struct sway_container *surviving_ancestor = container_reap_empty(parent);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If the workspace wasn't reaped
 | 
						// If the workspace wasn't reaped
 | 
				
			||||||
	if (surviving_ancestor && surviving_ancestor->type >= C_WORKSPACE) {
 | 
						if (surviving_ancestor && surviving_ancestor->type >= C_WORKSPACE) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -79,6 +79,65 @@ struct sway_container *workspace_create(struct sway_container *output,
 | 
				
			||||||
	return workspace;
 | 
						return workspace;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void workspace_destroy(struct sway_container *workspace) {
 | 
				
			||||||
 | 
						if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (!sway_assert(workspace->destroying,
 | 
				
			||||||
 | 
									"Tried to free workspace which wasn't marked as destroying")) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (!sway_assert(workspace->ntxnrefs == 0, "Tried to free workspace "
 | 
				
			||||||
 | 
									"which is still referenced by transactions")) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// sway_workspace
 | 
				
			||||||
 | 
						struct sway_workspace *ws = workspace->sway_workspace;
 | 
				
			||||||
 | 
						list_foreach(ws->output_priority, free);
 | 
				
			||||||
 | 
						list_free(ws->output_priority);
 | 
				
			||||||
 | 
						list_free(ws->floating);
 | 
				
			||||||
 | 
						free(ws);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// swayc
 | 
				
			||||||
 | 
						free(workspace->name);
 | 
				
			||||||
 | 
						free(workspace->formatted_title);
 | 
				
			||||||
 | 
						wlr_texture_destroy(workspace->title_focused);
 | 
				
			||||||
 | 
						wlr_texture_destroy(workspace->title_focused_inactive);
 | 
				
			||||||
 | 
						wlr_texture_destroy(workspace->title_unfocused);
 | 
				
			||||||
 | 
						wlr_texture_destroy(workspace->title_urgent);
 | 
				
			||||||
 | 
						list_free(workspace->children);
 | 
				
			||||||
 | 
						list_free(workspace->current.children);
 | 
				
			||||||
 | 
						list_free(workspace->outputs);
 | 
				
			||||||
 | 
						free(workspace);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void workspace_begin_destroy(struct sway_container *workspace) {
 | 
				
			||||||
 | 
						if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						wlr_log(WLR_DEBUG, "Destroying workspace '%s'", workspace->name);
 | 
				
			||||||
 | 
						wl_signal_emit(&workspace->events.destroy, workspace);
 | 
				
			||||||
 | 
						ipc_event_workspace(NULL, workspace, "empty"); // intentional
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						workspace->destroying = true;
 | 
				
			||||||
 | 
						container_set_dirty(workspace);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (workspace->parent) {
 | 
				
			||||||
 | 
							container_remove_child(workspace);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void workspace_consider_destroy(struct sway_container *ws) {
 | 
				
			||||||
 | 
						if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						struct sway_seat *seat = input_manager_current_seat(input_manager);
 | 
				
			||||||
 | 
						if (ws->children->length == 0 && ws->sway_workspace->floating->length == 0
 | 
				
			||||||
 | 
								&& seat_get_active_child(seat, ws->parent) != ws) {
 | 
				
			||||||
 | 
							workspace_begin_destroy(ws);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *prev_workspace_name = NULL;
 | 
					char *prev_workspace_name = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void next_name_map(struct sway_container *ws, void *data) {
 | 
					void next_name_map(struct sway_container *ws, void *data) {
 | 
				
			||||||
| 
						 | 
					@ -421,9 +480,7 @@ bool workspace_switch(struct sway_container *workspace,
 | 
				
			||||||
		// no op. We therefore need to send the IPC event and clean up the old
 | 
							// no op. We therefore need to send the IPC event and clean up the old
 | 
				
			||||||
		// workspace here.
 | 
							// workspace here.
 | 
				
			||||||
		ipc_event_workspace(active_ws, workspace, "focus");
 | 
							ipc_event_workspace(active_ws, workspace, "focus");
 | 
				
			||||||
		if (!workspace_is_visible(active_ws) && workspace_is_empty(active_ws)) {
 | 
							workspace_consider_destroy(active_ws);
 | 
				
			||||||
			container_destroy(active_ws);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	seat_set_focus(seat, next);
 | 
						seat_set_focus(seat, next);
 | 
				
			||||||
	struct sway_container *output = container_parent(workspace, C_OUTPUT);
 | 
						struct sway_container *output = container_parent(workspace, C_OUTPUT);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue