mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	commands: fix layout implementation (also better name for previous split layout)
This commit is contained in:
		
							parent
							
								
									3a980857cb
								
							
						
					
					
						commit
						356063b6c0
					
				
					 4 changed files with 30 additions and 21 deletions
				
			
		| 
						 | 
					@ -113,7 +113,7 @@ struct sway_container {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	enum sway_container_type type;
 | 
						enum sway_container_type type;
 | 
				
			||||||
	enum sway_container_layout layout;
 | 
						enum sway_container_layout layout;
 | 
				
			||||||
	enum sway_container_layout prev_layout;
 | 
						enum sway_container_layout prev_split_layout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool is_sticky;
 | 
						bool is_sticky;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,19 +42,16 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
 | 
				
			||||||
		parent = parent->parent;
 | 
							parent = parent->parent;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcasecmp(argv[0], "default") == 0) {
 | 
						enum sway_container_layout prev = parent->layout;
 | 
				
			||||||
		parent->layout = parent->prev_layout;
 | 
						bool assigned_directly = parse_layout_string(argv[0], &parent->layout);
 | 
				
			||||||
	} else {
 | 
						if (!assigned_directly) {
 | 
				
			||||||
		if (parent->layout != L_TABBED && parent->layout != L_STACKED) {
 | 
							if (strcasecmp(argv[0], "default") == 0) {
 | 
				
			||||||
			parent->prev_layout = parent->layout;
 | 
								parent->layout = parent->prev_split_layout;
 | 
				
			||||||
		}
 | 
							} else if (strcasecmp(argv[0], "toggle") == 0) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
		bool assigned_directly = parse_layout_string(argv[0], &parent->layout);
 | 
					 | 
				
			||||||
		if (!assigned_directly && strcasecmp(argv[0], "toggle") == 0) {
 | 
					 | 
				
			||||||
			if (argc == 1) {
 | 
								if (argc == 1) {
 | 
				
			||||||
				parent->layout =
 | 
									parent->layout =
 | 
				
			||||||
					parent->layout == L_STACKED ? L_TABBED :
 | 
										parent->layout == L_STACKED ? L_TABBED :
 | 
				
			||||||
					parent->layout == L_TABBED ? parent->prev_layout : L_STACKED;
 | 
										parent->layout == L_TABBED ? parent->prev_split_layout : L_STACKED;
 | 
				
			||||||
			} else if (argc == 2) {
 | 
								} else if (argc == 2) {
 | 
				
			||||||
				if (strcasecmp(argv[1], "all") == 0) {
 | 
									if (strcasecmp(argv[1], "all") == 0) {
 | 
				
			||||||
					parent->layout =
 | 
										parent->layout =
 | 
				
			||||||
| 
						 | 
					@ -62,17 +59,20 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
 | 
				
			||||||
						parent->layout == L_VERT ? L_STACKED :
 | 
											parent->layout == L_VERT ? L_STACKED :
 | 
				
			||||||
						parent->layout == L_STACKED ? L_TABBED : L_HORIZ;
 | 
											parent->layout == L_STACKED ? L_TABBED : L_HORIZ;
 | 
				
			||||||
				} else if (strcasecmp(argv[1], "split") == 0) {
 | 
									} else if (strcasecmp(argv[1], "split") == 0) {
 | 
				
			||||||
					parent->layout = parent->layout == L_VERT ? L_HORIZ : L_VERT;
 | 
										parent->layout =
 | 
				
			||||||
 | 
											parent->layout == L_HORIZ ? L_VERT :
 | 
				
			||||||
 | 
											parent->layout == L_VERT ? L_HORIZ : parent->prev_split_layout;
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					return cmd_results_new(CMD_INVALID, "layout", expected_syntax);
 | 
										return cmd_results_new(CMD_INVALID, "layout", expected_syntax);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				bool valid;
 | 
					 | 
				
			||||||
				enum sway_container_layout parsed_layout;
 | 
									enum sway_container_layout parsed_layout;
 | 
				
			||||||
				int curr = 1;
 | 
									int curr = 1;
 | 
				
			||||||
				for (; curr < argc; curr++) {
 | 
									for (; curr < argc; curr++) {
 | 
				
			||||||
					valid = parse_layout_string(argv[curr], &parsed_layout);
 | 
										bool valid = parse_layout_string(argv[curr], &parsed_layout);
 | 
				
			||||||
					if (valid && parsed_layout == parent->layout) {
 | 
										if ((valid && parsed_layout == parent->layout) ||
 | 
				
			||||||
 | 
												(strcmp(argv[curr], "split") == 0 &&
 | 
				
			||||||
 | 
												(parent->layout == L_VERT || parent->layout == L_HORIZ))) {
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -83,6 +83,11 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					if (parse_layout_string(argv[i], &parent->layout)) {
 | 
										if (parse_layout_string(argv[i], &parent->layout)) {
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
 | 
										} else if (strcmp(argv[i], "split") == 0) {
 | 
				
			||||||
 | 
											parent->layout =
 | 
				
			||||||
 | 
												parent->layout == L_HORIZ ? L_VERT :
 | 
				
			||||||
 | 
												parent->layout == L_VERT ? L_HORIZ : parent->prev_split_layout;
 | 
				
			||||||
 | 
											break;
 | 
				
			||||||
					} // invalid layout strings are silently ignored
 | 
										} // invalid layout strings are silently ignored
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -93,9 +98,13 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
 | 
				
			||||||
	if (parent->layout == L_NONE) {
 | 
						if (parent->layout == L_NONE) {
 | 
				
			||||||
		parent->layout = container_get_default_layout(parent);
 | 
							parent->layout = container_get_default_layout(parent);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if (prev != parent->layout) {
 | 
				
			||||||
	container_notify_subtree_changed(parent);
 | 
							if (prev != L_TABBED && prev != L_STACKED) {
 | 
				
			||||||
	arrange_windows(parent);
 | 
								parent->prev_split_layout = prev;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							container_notify_subtree_changed(parent);
 | 
				
			||||||
 | 
							arrange_windows(parent);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
						return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -859,7 +859,7 @@ struct sway_container *container_split(struct sway_container *child,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (child->type == C_WORKSPACE && child->children->length == 0) {
 | 
						if (child->type == C_WORKSPACE && child->children->length == 0) {
 | 
				
			||||||
		// Special case: this just behaves like splitt
 | 
							// Special case: this just behaves like splitt
 | 
				
			||||||
		child->prev_layout = child->layout;
 | 
							child->prev_split_layout = child->layout;
 | 
				
			||||||
		child->layout = layout;
 | 
							child->layout = layout;
 | 
				
			||||||
		return child;
 | 
							return child;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -870,7 +870,7 @@ struct sway_container *container_split(struct sway_container *child,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	remove_gaps(child);
 | 
						remove_gaps(child);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cont->prev_layout = L_NONE;
 | 
						cont->prev_split_layout = L_NONE;
 | 
				
			||||||
	cont->width = child->width;
 | 
						cont->width = child->width;
 | 
				
			||||||
	cont->height = child->height;
 | 
						cont->height = child->height;
 | 
				
			||||||
	cont->x = child->x;
 | 
						cont->x = child->x;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -59,7 +59,7 @@ struct sway_container *workspace_create(struct sway_container *output,
 | 
				
			||||||
	workspace->width = output->width;
 | 
						workspace->width = output->width;
 | 
				
			||||||
	workspace->height = output->height;
 | 
						workspace->height = output->height;
 | 
				
			||||||
	workspace->name = !name ? NULL : strdup(name);
 | 
						workspace->name = !name ? NULL : strdup(name);
 | 
				
			||||||
	workspace->prev_layout = L_NONE;
 | 
						workspace->prev_split_layout = L_NONE;
 | 
				
			||||||
	workspace->layout = container_get_default_layout(output);
 | 
						workspace->layout = container_get_default_layout(output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct sway_workspace *swayws = calloc(1, sizeof(struct sway_workspace));
 | 
						struct sway_workspace *swayws = calloc(1, sizeof(struct sway_workspace));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue