mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	cmd_split: fix toggle split for non-split layouts
Previously, `layout toggle` and `layout toggle split` would set L_VERT when layout was L_HORIZ, otherwise it would set L_HORIZ. This meant that when the layout was L_TABBED or L_STACKED, it would always be L_HORIZ. This extends #4315 (which corrects the handling when multiple layouts are given) to try prev_split_layout, config->default_orientation, and then falling back to L_VERT when the output is taller than wide and L_HORIZ when wider than tall.
This commit is contained in:
		
							parent
							
								
									5ffcea4c28
								
							
						
					
					
						commit
						c312a10cc7
					
				
					 1 changed files with 21 additions and 14 deletions
				
			
		| 
						 | 
					@ -26,19 +26,37 @@ static const char expected_syntax[] =
 | 
				
			||||||
	"'layout toggle [split|all]' or "
 | 
						"'layout toggle [split|all]' or "
 | 
				
			||||||
	"'layout toggle [split|tabbed|stacking|splitv|splith] [split|tabbed|stacking|splitv|splith]...'";
 | 
						"'layout toggle [split|tabbed|stacking|splitv|splith] [split|tabbed|stacking|splitv|splith]...'";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static enum sway_container_layout toggle_split_layout(
 | 
				
			||||||
 | 
							enum sway_container_layout layout,
 | 
				
			||||||
 | 
							enum sway_container_layout prev_split_layout,
 | 
				
			||||||
 | 
							struct sway_output *output) {
 | 
				
			||||||
 | 
						if (layout == L_HORIZ) {
 | 
				
			||||||
 | 
							return L_VERT;
 | 
				
			||||||
 | 
						} else if (layout == L_VERT) {
 | 
				
			||||||
 | 
							return L_HORIZ;
 | 
				
			||||||
 | 
						} else if (prev_split_layout != L_NONE) {
 | 
				
			||||||
 | 
							return prev_split_layout;
 | 
				
			||||||
 | 
						} else if (config->default_orientation != L_NONE) {
 | 
				
			||||||
 | 
							return config->default_orientation;
 | 
				
			||||||
 | 
						} else if (output->height > output->width) {
 | 
				
			||||||
 | 
							return L_VERT;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return L_HORIZ;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static enum sway_container_layout get_layout_toggle(int argc, char **argv,
 | 
					static enum sway_container_layout get_layout_toggle(int argc, char **argv,
 | 
				
			||||||
		enum sway_container_layout layout,
 | 
							enum sway_container_layout layout,
 | 
				
			||||||
		enum sway_container_layout prev_split_layout,
 | 
							enum sway_container_layout prev_split_layout,
 | 
				
			||||||
		struct sway_output *output) {
 | 
							struct sway_output *output) {
 | 
				
			||||||
	// "layout toggle"
 | 
						// "layout toggle"
 | 
				
			||||||
	if (argc == 1) {
 | 
						if (argc == 1) {
 | 
				
			||||||
		return layout == L_HORIZ ? L_VERT : L_HORIZ;
 | 
							return toggle_split_layout(layout, prev_split_layout, output);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (argc == 2) {
 | 
						if (argc == 2) {
 | 
				
			||||||
		// "layout toggle split" (same as "layout toggle")
 | 
							// "layout toggle split" (same as "layout toggle")
 | 
				
			||||||
		if (strcasecmp(argv[1], "split") == 0) {
 | 
							if (strcasecmp(argv[1], "split") == 0) {
 | 
				
			||||||
			return layout == L_HORIZ ? L_VERT : L_HORIZ;
 | 
								return toggle_split_layout(layout, prev_split_layout, output);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// "layout toggle all"
 | 
							// "layout toggle all"
 | 
				
			||||||
		if (strcasecmp(argv[1], "all") == 0) {
 | 
							if (strcasecmp(argv[1], "all") == 0) {
 | 
				
			||||||
| 
						 | 
					@ -68,18 +86,7 @@ static enum sway_container_layout get_layout_toggle(int argc, char **argv,
 | 
				
			||||||
			return parsed;
 | 
								return parsed;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (strcmp(argv[i], "split") == 0) {
 | 
							if (strcmp(argv[i], "split") == 0) {
 | 
				
			||||||
			if (layout == L_HORIZ) {
 | 
								return toggle_split_layout(layout, prev_split_layout, output);
 | 
				
			||||||
				return L_VERT;
 | 
					 | 
				
			||||||
			} else if (layout == L_VERT) {
 | 
					 | 
				
			||||||
				return L_HORIZ;
 | 
					 | 
				
			||||||
			} else if (prev_split_layout != L_NONE) {
 | 
					 | 
				
			||||||
				return prev_split_layout;
 | 
					 | 
				
			||||||
			} else if (config->default_orientation != L_NONE) {
 | 
					 | 
				
			||||||
				return config->default_orientation;
 | 
					 | 
				
			||||||
			} else if (output->height > output->width) {
 | 
					 | 
				
			||||||
				return L_VERT;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			return L_HORIZ;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// invalid layout strings are silently ignored
 | 
							// invalid layout strings are silently ignored
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue