mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Merge pull request #726 from Hummer12007/hwc
Spawn new views to target ws's focused container
This commit is contained in:
		
						commit
						1e95191900
					
				
					 3 changed files with 33 additions and 3 deletions
				
			
		| 
						 | 
					@ -34,6 +34,8 @@ bool set_focused_container_for(swayc_t *ancestor, swayc_t *container);
 | 
				
			||||||
extern bool locked_container_focus;
 | 
					extern bool locked_container_focus;
 | 
				
			||||||
extern bool locked_view_focus;
 | 
					extern bool locked_view_focus;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Prevents wss from being destroyed on focus switch
 | 
				
			||||||
 | 
					extern bool suspend_workspace_cleanup;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool move_focus(enum movement_direction direction);
 | 
					bool move_focus(enum movement_direction direction);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,6 +11,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool locked_container_focus = false;
 | 
					bool locked_container_focus = false;
 | 
				
			||||||
bool locked_view_focus = false;
 | 
					bool locked_view_focus = false;
 | 
				
			||||||
 | 
					bool suspend_workspace_cleanup = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// switches parent focus to c. will switch it accordingly
 | 
					// switches parent focus to c. will switch it accordingly
 | 
				
			||||||
static void update_focus(swayc_t *c) {
 | 
					static void update_focus(swayc_t *c) {
 | 
				
			||||||
| 
						 | 
					@ -40,7 +41,7 @@ static void update_focus(swayc_t *c) {
 | 
				
			||||||
				ipc_event_workspace(prev, c, "focus");
 | 
									ipc_event_workspace(prev, c, "focus");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// if the old workspace has no children, destroy it
 | 
									// if the old workspace has no children, destroy it
 | 
				
			||||||
				if(prev->children->length == 0 && prev->floating->length == 0){
 | 
									if(prev->children->length == 0 && prev->floating->length == 0 && !suspend_workspace_cleanup) {
 | 
				
			||||||
					destroy_workspace(prev);
 | 
										destroy_workspace(prev);
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					// update visibility of old workspace
 | 
										// update visibility of old workspace
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -198,6 +198,27 @@ static bool client_is_panel(struct wl_client *client) {
 | 
				
			||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void ws_cleanup() {
 | 
				
			||||||
 | 
						swayc_t *op, *ws;
 | 
				
			||||||
 | 
						int i = 0, j;
 | 
				
			||||||
 | 
						if (!root_container.children)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						while (i < root_container.children->length) {
 | 
				
			||||||
 | 
							op = root_container.children->items[i++];
 | 
				
			||||||
 | 
							if (!op->children)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							j = 0;
 | 
				
			||||||
 | 
							while (j < op->children->length) {
 | 
				
			||||||
 | 
								ws = op->children->items[j++];
 | 
				
			||||||
 | 
								if (ws->children->length == 0 && ws->floating->length == 0 && ws != op->focused) {
 | 
				
			||||||
 | 
									if (destroy_workspace(ws)) {
 | 
				
			||||||
 | 
										j--;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool handle_view_created(wlc_handle handle) {
 | 
					static bool handle_view_created(wlc_handle handle) {
 | 
				
			||||||
	// if view is child of another view, the use that as focused container
 | 
						// if view is child of another view, the use that as focused container
 | 
				
			||||||
	wlc_handle parent = wlc_view_get_parent(handle);
 | 
						wlc_handle parent = wlc_view_get_parent(handle);
 | 
				
			||||||
| 
						 | 
					@ -226,8 +247,8 @@ static bool handle_view_created(wlc_handle handle) {
 | 
				
			||||||
			// using newview as a temp storage location here,
 | 
								// using newview as a temp storage location here,
 | 
				
			||||||
			// rather than adding yet another workspace var
 | 
								// rather than adding yet another workspace var
 | 
				
			||||||
			newview = workspace_for_pid(pid);
 | 
								newview = workspace_for_pid(pid);
 | 
				
			||||||
			if (newview && newview != current_ws) {
 | 
								if (newview) {
 | 
				
			||||||
				focused = newview;
 | 
									focused = get_focused_container(newview);
 | 
				
			||||||
				return_to_workspace = true;
 | 
									return_to_workspace = true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			newview = NULL;
 | 
								newview = NULL;
 | 
				
			||||||
| 
						 | 
					@ -295,6 +316,9 @@ static bool handle_view_created(wlc_handle handle) {
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Prevent current ws from being destroyed, if empty
 | 
				
			||||||
 | 
						suspend_workspace_cleanup = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (newview) {
 | 
						if (newview) {
 | 
				
			||||||
		set_focused_container(newview);
 | 
							set_focused_container(newview);
 | 
				
			||||||
		swayc_t *output = swayc_parent_by_type(newview, C_OUTPUT);
 | 
							swayc_t *output = swayc_parent_by_type(newview, C_OUTPUT);
 | 
				
			||||||
| 
						 | 
					@ -343,6 +367,9 @@ static bool handle_view_created(wlc_handle handle) {
 | 
				
			||||||
		workspace_switch(current_ws);
 | 
							workspace_switch(current_ws);
 | 
				
			||||||
		set_focused_container(current_ws->focused);
 | 
							set_focused_container(current_ws->focused);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						suspend_workspace_cleanup = false;
 | 
				
			||||||
 | 
						ws_cleanup();
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue