mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Layout tiled using a width/height fraction
Instead of using container->width/height as both the input and output of the layout calculation have container->width_fraction/height_fraction as the share of the parent this container occupies and calculate the layout based on that. That way the container arrangement can always be recalculated even if width/height have been altered by things like fullscreen. To do this several parts are reworked: - The vertical and horizontal arrangement code is ajusted to work with fractions instead of directly with width/height - The resize code is then changed to manipulate the fractions when working on tiled containers. - Finally the places that manipulated width/height are adjusted to match. The adjusted parts are container split, swap, and the input seat code. It's possible that some parts of the code are now adjusting width and height only for those to be immediately recalculated. That's harmless and since non-tiled containers are still sized with width/height directly it may avoid breaking other corner cases. Fixes #3547 Fixes #4297
This commit is contained in:
		
							parent
							
								
									1312b5bb9f
								
							
						
					
					
						commit
						e3a3917d3a
					
				
					 7 changed files with 85 additions and 37 deletions
				
			
		| 
						 | 
				
			
			@ -131,6 +131,7 @@ static void container_move_to_container_from_direction(
 | 
			
		|||
						container, index);
 | 
			
		||||
			}
 | 
			
		||||
			container->width = container->height = 0;
 | 
			
		||||
			container->width_fraction = container->height_fraction = 0;
 | 
			
		||||
		}
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -142,6 +143,7 @@ static void container_move_to_container_from_direction(
 | 
			
		|||
			0 : destination->children->length;
 | 
			
		||||
		container_insert_child(destination, container, index);
 | 
			
		||||
		container->width = container->height = 0;
 | 
			
		||||
		container->width_fraction = container->height_fraction = 0;
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -163,6 +165,7 @@ static void container_move_to_workspace_from_direction(
 | 
			
		|||
		struct sway_container *container, struct sway_workspace *workspace,
 | 
			
		||||
		enum wlr_direction move_dir) {
 | 
			
		||||
	container->width = container->height = 0;
 | 
			
		||||
	container->width_fraction = container->height_fraction = 0;
 | 
			
		||||
 | 
			
		||||
	if (is_parallel(workspace->layout, move_dir)) {
 | 
			
		||||
		sway_log(SWAY_DEBUG, "Reparenting container (parallel)");
 | 
			
		||||
| 
						 | 
				
			
			@ -206,7 +209,7 @@ static void container_move_to_workspace(struct sway_container *container,
 | 
			
		|||
	} else {
 | 
			
		||||
		container_detach(container);
 | 
			
		||||
		container->width = container->height = 0;
 | 
			
		||||
		container->saved_width = container->saved_height = 0;
 | 
			
		||||
		container->width_fraction = container->height_fraction = 0;
 | 
			
		||||
		workspace_add_tiling(workspace, container);
 | 
			
		||||
		container_update_representation(container);
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -234,7 +237,7 @@ static void container_move_to_container(struct sway_container *container,
 | 
			
		|||
	container_detach(container);
 | 
			
		||||
	container_remove_gaps(container);
 | 
			
		||||
	container->width = container->height = 0;
 | 
			
		||||
	container->saved_width = container->saved_height = 0;
 | 
			
		||||
	container->width_fraction = container->height_fraction = 0;
 | 
			
		||||
 | 
			
		||||
	if (destination->view) {
 | 
			
		||||
		container_add_sibling(destination, container, 1);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -174,10 +174,14 @@ void container_resize_tiled(struct sway_container *con,
 | 
			
		|||
		if (prev && prev->width - sibling_amount < MIN_SANE_W) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		con->width += amount;
 | 
			
		||||
		next->width -= sibling_amount;
 | 
			
		||||
 | 
			
		||||
		con->width_fraction +=
 | 
			
		||||
			((double)amount / con->width) * con->width_fraction;
 | 
			
		||||
		next->width_fraction -=
 | 
			
		||||
			((double)sibling_amount / con->width) * con->width_fraction;
 | 
			
		||||
		if (prev) {
 | 
			
		||||
			prev->width -= sibling_amount;
 | 
			
		||||
			prev->width_fraction -=
 | 
			
		||||
				((double)sibling_amount / con->width) * con->width_fraction;
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		if (con->height + amount < MIN_SANE_H) {
 | 
			
		||||
| 
						 | 
				
			
			@ -189,10 +193,14 @@ void container_resize_tiled(struct sway_container *con,
 | 
			
		|||
		if (prev && prev->height - sibling_amount < MIN_SANE_H) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		con->height += amount;
 | 
			
		||||
		next->height -= sibling_amount;
 | 
			
		||||
 | 
			
		||||
		con->height_fraction +=
 | 
			
		||||
			((double)amount / con->height) * con->height_fraction;
 | 
			
		||||
		next->height_fraction -=
 | 
			
		||||
			((double)sibling_amount / con->height) * con->height_fraction;
 | 
			
		||||
		if (prev) {
 | 
			
		||||
			prev->height -= sibling_amount;
 | 
			
		||||
			prev->height_fraction -=
 | 
			
		||||
				((double)sibling_amount / con->height) * con->height_fraction;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -280,10 +288,11 @@ static struct cmd_results *resize_adjust_tiled(uint32_t axis,
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	double old_width = current->width;
 | 
			
		||||
	double old_height = current->height;
 | 
			
		||||
	double old_width = current->width_fraction;
 | 
			
		||||
	double old_height = current->height_fraction;
 | 
			
		||||
	container_resize_tiled(current, axis, amount->amount);
 | 
			
		||||
	if (current->width == old_width && current->height == old_height) {
 | 
			
		||||
	if (current->width_fraction == old_width &&
 | 
			
		||||
			current->height_fraction == old_height) {
 | 
			
		||||
		return cmd_results_new(CMD_INVALID, "Cannot resize any further");
 | 
			
		||||
	}
 | 
			
		||||
	return cmd_results_new(CMD_SUCCESS, NULL);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,6 +20,8 @@ static void swap_places(struct sway_container *con1,
 | 
			
		|||
	temp->y = con1->y;
 | 
			
		||||
	temp->width = con1->width;
 | 
			
		||||
	temp->height = con1->height;
 | 
			
		||||
	temp->width_fraction = con1->width_fraction;
 | 
			
		||||
	temp->height_fraction = con1->height_fraction;
 | 
			
		||||
	temp->parent = con1->parent;
 | 
			
		||||
	temp->workspace = con1->workspace;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -27,11 +29,15 @@ static void swap_places(struct sway_container *con1,
 | 
			
		|||
	con1->y = con2->y;
 | 
			
		||||
	con1->width = con2->width;
 | 
			
		||||
	con1->height = con2->height;
 | 
			
		||||
	con1->width_fraction = con2->width_fraction;
 | 
			
		||||
	con1->height_fraction = con2->height_fraction;
 | 
			
		||||
 | 
			
		||||
	con2->x = temp->x;
 | 
			
		||||
	con2->y = temp->y;
 | 
			
		||||
	con2->width = temp->width;
 | 
			
		||||
	con2->height = temp->height;
 | 
			
		||||
	con2->width_fraction = temp->width_fraction;
 | 
			
		||||
	con2->height_fraction = temp->height_fraction;
 | 
			
		||||
 | 
			
		||||
	int temp_index = container_sibling_index(con1);
 | 
			
		||||
	if (con2->parent) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue