mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Coding style enforcement
This was done by hand, so I might have missed things. If anyone knows of a good C style enforcement tool, let me know.
This commit is contained in:
		
							parent
							
								
									af1b3d9755
								
							
						
					
					
						commit
						2139001c9f
					
				
					 11 changed files with 119 additions and 136 deletions
				
			
		| 
						 | 
					@ -30,7 +30,6 @@ struct sway_container {
 | 
				
			||||||
	wlc_handle handle;
 | 
						wlc_handle handle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	enum swayc_types type;
 | 
						enum swayc_types type;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	enum swayc_layouts layout;
 | 
						enum swayc_layouts layout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Not including borders or margins
 | 
						// Not including borders or margins
 | 
				
			||||||
| 
						 | 
					@ -42,9 +41,7 @@ struct sway_container {
 | 
				
			||||||
	int x, y;
 | 
						int x, y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool visible;
 | 
						bool visible;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	bool is_floating;
 | 
						bool is_floating;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	bool is_focused;
 | 
						bool is_focused;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int weight;
 | 
						int weight;
 | 
				
			||||||
| 
						 | 
					@ -52,8 +49,6 @@ struct sway_container {
 | 
				
			||||||
	char *name;
 | 
						char *name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	list_t *children;
 | 
						list_t *children;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Special list for floating windows in workspaces
 | 
					 | 
				
			||||||
	list_t *floating;
 | 
						list_t *floating;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct sway_container *parent;
 | 
						struct sway_container *parent;
 | 
				
			||||||
| 
						 | 
					@ -72,7 +67,7 @@ swayc_t *new_floating_view(wlc_handle handle);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
swayc_t *destroy_output(swayc_t *output);
 | 
					swayc_t *destroy_output(swayc_t *output);
 | 
				
			||||||
//destroys workspace if empty and returns parent pointer, else returns NULL
 | 
					// Destroys workspace if empty and returns parent pointer, else returns NULL
 | 
				
			||||||
swayc_t *destroy_workspace(swayc_t *workspace);
 | 
					swayc_t *destroy_workspace(swayc_t *workspace);
 | 
				
			||||||
swayc_t *destroy_container(swayc_t *container);
 | 
					swayc_t *destroy_container(swayc_t *container);
 | 
				
			||||||
swayc_t *destroy_view(swayc_t *view);
 | 
					swayc_t *destroy_view(swayc_t *view);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -292,9 +292,11 @@ static bool cmd_layout(struct sway_config *config, int argc, char **argv) {
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	swayc_t *parent = get_focused_container(&root_container);
 | 
						swayc_t *parent = get_focused_container(&root_container);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (parent->type == C_VIEW) {
 | 
						while (parent->type == C_VIEW) {
 | 
				
			||||||
		parent = parent->parent;
 | 
							parent = parent->parent;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcasecmp(argv[0], "splith") == 0) {
 | 
						if (strcasecmp(argv[0], "splith") == 0) {
 | 
				
			||||||
		parent->layout = L_HORIZ;
 | 
							parent->layout = L_HORIZ;
 | 
				
			||||||
	} else if (strcasecmp(argv[0], "splitv") == 0) {
 | 
						} else if (strcasecmp(argv[0], "splitv") == 0) {
 | 
				
			||||||
| 
						 | 
					@ -343,19 +345,17 @@ static bool _do_split(struct sway_config *config, int argc, char **argv, int lay
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	swayc_t *focused = get_focused_container(&root_container);
 | 
						swayc_t *focused = get_focused_container(&root_container);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Case that focus is on an workspace with 0/1 children.change its layout */
 | 
					 | 
				
			||||||
	if (focused->type == C_WORKSPACE && focused->children->length <= 1) {
 | 
						if (focused->type == C_WORKSPACE && focused->children->length <= 1) {
 | 
				
			||||||
 | 
							/* Case that focus is on an workspace with 0/1 children.change its layout */
 | 
				
			||||||
		sway_log(L_DEBUG, "changing workspace layout");
 | 
							sway_log(L_DEBUG, "changing workspace layout");
 | 
				
			||||||
		focused->layout = layout;
 | 
							focused->layout = layout;
 | 
				
			||||||
	}
 | 
						} else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) {
 | 
				
			||||||
		/* Case of no siblings. change parent layout */
 | 
							/* Case of no siblings. change parent layout */
 | 
				
			||||||
	else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) {
 | 
					 | 
				
			||||||
		sway_log(L_DEBUG, "changing container layout");
 | 
							sway_log(L_DEBUG, "changing container layout");
 | 
				
			||||||
		focused->parent->layout = layout;
 | 
							focused->parent->layout = layout;
 | 
				
			||||||
	}
 | 
						} else {
 | 
				
			||||||
		/* regular case where new split container is build around focused container
 | 
							/* regular case where new split container is build around focused container
 | 
				
			||||||
		 * or in case of workspace, container inherits its children */
 | 
							 * or in case of workspace, container inherits its children */
 | 
				
			||||||
	else {
 | 
					 | 
				
			||||||
		sway_log(L_DEBUG, "Adding new container around current focused container");
 | 
							sway_log(L_DEBUG, "Adding new container around current focused container");
 | 
				
			||||||
		swayc_t *parent = new_container(focused, layout);
 | 
							swayc_t *parent = new_container(focused, layout);
 | 
				
			||||||
		set_focused_container(focused);
 | 
							set_focused_container(focused);
 | 
				
			||||||
| 
						 | 
					@ -369,6 +369,7 @@ static bool cmd_split(struct sway_config *config, int argc, char **argv) {
 | 
				
			||||||
	if (!checkarg(argc, "split", EXPECTED_EQUAL_TO, 1)) {
 | 
						if (!checkarg(argc, "split", EXPECTED_EQUAL_TO, 1)) {
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
 | 
						if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
 | 
				
			||||||
		_do_split(config, argc - 1, argv + 1, L_VERT);
 | 
							_do_split(config, argc - 1, argv + 1, L_VERT);
 | 
				
			||||||
	} else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) {
 | 
						} else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) {
 | 
				
			||||||
| 
						 | 
					@ -377,6 +378,7 @@ static bool cmd_split(struct sway_config *config, int argc, char **argv) {
 | 
				
			||||||
		sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical).");
 | 
							sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical).");
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,13 +50,6 @@ swayc_t *new_output(wlc_handle handle) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	add_child(&root_container, output);
 | 
						add_child(&root_container, output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//TODO still dont know why this is here?
 | 
					 | 
				
			||||||
//	int total_width = 0;
 | 
					 | 
				
			||||||
//	int i;
 | 
					 | 
				
			||||||
//	for (i = 0; i < root_container.children->length; ++i) {
 | 
					 | 
				
			||||||
//		total_width += ((swayc_t*)root_container.children->items[i])->width;
 | 
					 | 
				
			||||||
//	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Create workspace
 | 
						// Create workspace
 | 
				
			||||||
	char *ws_name = NULL;
 | 
						char *ws_name = NULL;
 | 
				
			||||||
	if (name) {
 | 
						if (name) {
 | 
				
			||||||
| 
						 | 
					@ -73,6 +66,7 @@ swayc_t *new_output(wlc_handle handle) {
 | 
				
			||||||
	if (!ws_name) {
 | 
						if (!ws_name) {
 | 
				
			||||||
		ws_name = workspace_next_name();
 | 
							ws_name = workspace_next_name();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// create and initilize default workspace
 | 
						// create and initilize default workspace
 | 
				
			||||||
	swayc_t *ws = new_workspace(output, ws_name);
 | 
						swayc_t *ws = new_workspace(output, ws_name);
 | 
				
			||||||
	ws->is_focused = true;
 | 
						ws->is_focused = true;
 | 
				
			||||||
| 
						 | 
					@ -129,9 +123,7 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) {
 | 
				
			||||||
		// give them proper layouts
 | 
							// give them proper layouts
 | 
				
			||||||
		cont->layout = workspace->layout;
 | 
							cont->layout = workspace->layout;
 | 
				
			||||||
		workspace->layout = layout;
 | 
							workspace->layout = layout;
 | 
				
			||||||
	}
 | 
						} else { // Or is built around container
 | 
				
			||||||
	//Or is built around container
 | 
					 | 
				
			||||||
	else {
 | 
					 | 
				
			||||||
		swayc_t *parent = replace_child(child, cont);
 | 
							swayc_t *parent = replace_child(child, cont);
 | 
				
			||||||
		if (parent) {
 | 
							if (parent) {
 | 
				
			||||||
			add_child(cont, child);
 | 
								add_child(cont, child);
 | 
				
			||||||
| 
						 | 
					@ -157,12 +149,11 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
 | 
				
			||||||
	// TODO: properly set this
 | 
						// TODO: properly set this
 | 
				
			||||||
	view->is_floating = false;
 | 
						view->is_floating = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//Case of focused workspace, just create as child of it
 | 
					 | 
				
			||||||
	if (sibling->type == C_WORKSPACE) {
 | 
						if (sibling->type == C_WORKSPACE) {
 | 
				
			||||||
 | 
							// Case of focused workspace, just create as child of it
 | 
				
			||||||
		add_child(sibling, view);
 | 
							add_child(sibling, view);
 | 
				
			||||||
	}
 | 
						} else {
 | 
				
			||||||
		// Regular case, create as sibling of current container
 | 
							// Regular case, create as sibling of current container
 | 
				
			||||||
	else {
 | 
					 | 
				
			||||||
		add_sibling(sibling, view);
 | 
							add_sibling(sibling, view);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return view;
 | 
						return view;
 | 
				
			||||||
| 
						 | 
					@ -303,5 +294,3 @@ void set_view_visibility(swayc_t *view, void *data) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	view->visible = (*p == 2);
 | 
						view->visible = (*p == 2);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,7 @@ bool locked_container_focus = false;
 | 
				
			||||||
bool locked_view_focus = false;
 | 
					bool locked_view_focus = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// switches parent focus to c. will switch it accordingly
 | 
					// switches parent focus to c. will switch it accordingly
 | 
				
			||||||
//TODO, everything needs a handle, so we can set front/back position properly
 | 
					// TODO: Everything needs a handle, so we can set front/back position properly
 | 
				
			||||||
static void update_focus(swayc_t *c) {
 | 
					static void update_focus(swayc_t *c) {
 | 
				
			||||||
	// Handle if focus switches
 | 
						// Handle if focus switches
 | 
				
			||||||
	swayc_t *parent = c->parent;
 | 
						swayc_t *parent = c->parent;
 | 
				
			||||||
| 
						 | 
					@ -189,4 +189,3 @@ swayc_t *get_focused_view(swayc_t *parent) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return parent;
 | 
						return parent;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -220,14 +220,13 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s
 | 
				
			||||||
	swayc_t *c = NULL;
 | 
						swayc_t *c = NULL;
 | 
				
			||||||
	switch(state) {
 | 
						switch(state) {
 | 
				
			||||||
	case WLC_BIT_FULLSCREEN:
 | 
						case WLC_BIT_FULLSCREEN:
 | 
				
			||||||
		//I3 just lets it become fullscreen
 | 
							// i3 just lets it become fullscreen
 | 
				
			||||||
		wlc_view_set_state(view, state, toggle);
 | 
							wlc_view_set_state(view, state, toggle);
 | 
				
			||||||
		c = get_swayc_for_handle(view, &root_container);
 | 
							c = get_swayc_for_handle(view, &root_container);
 | 
				
			||||||
		sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d",view,c->name,toggle);
 | 
							sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d",view,c->name,toggle);
 | 
				
			||||||
		if (c) {
 | 
							if (c) {
 | 
				
			||||||
			arrange_windows(c->parent, -1, -1);
 | 
								arrange_windows(c->parent, -1, -1);
 | 
				
			||||||
			//Set it as focused window for that workspace if its going
 | 
								// Set it as focused window for that workspace if its going fullscreen
 | 
				
			||||||
			//fullscreen
 | 
					 | 
				
			||||||
			if (toggle) {
 | 
								if (toggle) {
 | 
				
			||||||
				swayc_t *ws = c;
 | 
									swayc_t *ws = c;
 | 
				
			||||||
				while (ws->type != C_WORKSPACE) {
 | 
									while (ws->type != C_WORKSPACE) {
 | 
				
			||||||
| 
						 | 
					@ -248,8 +247,8 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers
 | 
					static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers,
 | 
				
			||||||
		*modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) {
 | 
							uint32_t key, uint32_t sym, enum wlc_key_state state) {
 | 
				
			||||||
	enum { QSIZE = 32 };
 | 
						enum { QSIZE = 32 };
 | 
				
			||||||
	if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) {
 | 
						if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) {
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,8 +63,8 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
 | 
				
			||||||
swayc_t *remove_child(swayc_t *child) {
 | 
					swayc_t *remove_child(swayc_t *child) {
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
	swayc_t *parent = child->parent;
 | 
						swayc_t *parent = child->parent;
 | 
				
			||||||
	// Special case for floating views
 | 
					 | 
				
			||||||
	if (child->is_floating) {
 | 
						if (child->is_floating) {
 | 
				
			||||||
 | 
							// Special case for floating views
 | 
				
			||||||
		for (i = 0; i < parent->floating->length; ++i) {
 | 
							for (i = 0; i < parent->floating->length; ++i) {
 | 
				
			||||||
			if (parent->floating->items[i] == child) {
 | 
								if (parent->floating->items[i] == child) {
 | 
				
			||||||
				list_del(parent->floating, i);
 | 
									list_del(parent->floating, i);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,8 +17,7 @@ static const char *verbosity_colors[] = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void init_log(int verbosity) {
 | 
					void init_log(int verbosity) {
 | 
				
			||||||
	v = verbosity;
 | 
						v = verbosity;
 | 
				
			||||||
	/* set FD_CLOEXEC flag to prevent programs called with exec to write into
 | 
						/* set FD_CLOEXEC flag to prevent programs called with exec to write into logs */
 | 
				
			||||||
	 * logs */
 | 
					 | 
				
			||||||
	int i, flag;
 | 
						int i, flag;
 | 
				
			||||||
	int fd[] = { STDOUT_FILENO, STDIN_FILENO, STDERR_FILENO };
 | 
						int fd[] = { STDOUT_FILENO, STDIN_FILENO, STDERR_FILENO };
 | 
				
			||||||
	for (i = 0; i < 3; ++i) {
 | 
						for (i = 0; i < 3; ++i) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue