diff options
Diffstat (limited to 'sway/commands')
34 files changed, 418 insertions, 477 deletions
diff --git a/sway/commands/bar/binding_mode_indicator.c b/sway/commands/bar/binding_mode_indicator.c index 0c48bee9..f18b8d7c 100644 --- a/sway/commands/bar/binding_mode_indicator.c +++ b/sway/commands/bar/binding_mode_indicator.c @@ -21,7 +21,9 @@ struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) {  		config->current_bar->binding_mode_indicator = false;  		wlr_log(WLR_DEBUG, "Disabling binding mode indicator on bar: %s",  				config->current_bar->id); +	} else { +		return cmd_results_new(CMD_INVALID, "binding_mode_indicator", +				"Invalid value %s", argv[0]);  	} -	return cmd_results_new(CMD_INVALID, "binding_mode_indicator", -			"Invalid value %s", argv[0]); +	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/bind.c b/sway/commands/bind.c index 047018e0..820c2a6a 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c @@ -321,7 +321,7 @@ void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding)  	}  	config->handler_context.seat = seat; -	struct cmd_results *results = execute_command(binding->command, NULL); +	struct cmd_results *results = execute_command(binding->command, NULL, NULL);  	if (results->status == CMD_SUCCESS) {  		ipc_event_binding(binding_copy);  	} else { diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c index d676e475..2e0876a9 100644 --- a/sway/commands/gaps.c +++ b/sway/commands/gaps.c @@ -1,4 +1,5 @@  #include <string.h> +#include <strings.h>  #include "sway/commands.h"  #include "sway/config.h"  #include "sway/tree/arrange.h" @@ -13,172 +14,173 @@ enum gaps_op {  	GAPS_OP_SUBTRACT  }; -enum gaps_scope { -	GAPS_SCOPE_ALL, -	GAPS_SCOPE_WORKSPACE, -	GAPS_SCOPE_CURRENT +struct gaps_data { +	bool inner; +	enum gaps_op operation; +	int amount;  }; -struct cmd_results *cmd_gaps(int argc, char **argv) { -	struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1); -	if (error) { +// gaps edge_gaps on|off|toggle +static struct cmd_results *gaps_edge_gaps(int argc, char **argv) { +	struct cmd_results *error; +	if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2))) {  		return error;  	} -	if (strcmp(argv[0], "edge_gaps") == 0) { -		if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2))) { -			return error; -		} - -		if (strcmp(argv[1], "on") == 0) { -			config->edge_gaps = true; -		} else if (strcmp(argv[1], "off") == 0) { -			config->edge_gaps = false; -		} else if (strcmp(argv[1], "toggle") == 0) { -			if (!config->active) { -				return cmd_results_new(CMD_INVALID, "gaps", -					"Cannot toggle gaps while not running."); -			} -			config->edge_gaps = !config->edge_gaps; -		} else { +	if (strcmp(argv[1], "on") == 0) { +		config->edge_gaps = true; +	} else if (strcmp(argv[1], "off") == 0) { +		config->edge_gaps = false; +	} else if (strcmp(argv[1], "toggle") == 0) { +		if (!config->active) {  			return cmd_results_new(CMD_INVALID, "gaps", -				"gaps edge_gaps on|off|toggle"); +					"Cannot toggle gaps while not running.");  		} -		arrange_root(); +		config->edge_gaps = !config->edge_gaps;  	} else { -		int amount_idx = 0; // the current index in argv -		enum gaps_op op = GAPS_OP_SET; -		enum gaps_scope scope = GAPS_SCOPE_ALL; -		bool inner = true; - -		if (strcmp(argv[0], "inner") == 0) { -			amount_idx++; -			inner = true; -		} else if (strcmp(argv[0], "outer") == 0) { -			amount_idx++; -			inner = false; -		} +		return cmd_results_new(CMD_INVALID, "gaps", +				"gaps edge_gaps on|off|toggle"); +	} +	arrange_root(); +	return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} -		// If one of the long variants of the gaps command is used -		// (which starts with inner|outer) check the number of args -		if (amount_idx > 0) { // if we've seen inner|outer -			if (argc > 2) { // check the longest variant -				error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4); -				if (error) { -					return error; -				} -			} else { // check the next longest format -				error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2); -				if (error) { -					return error; -				} -			} -		} else { -			error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 1); -			if (error) { -				return error; -			} -		} +// gaps inner|outer <px> +static struct cmd_results *gaps_set_defaults(int argc, char **argv) { +	struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2); +	if (error) { +		return error; +	} -		if (argc == 4) { -			// Long format: all|workspace|current. -			if (strcmp(argv[amount_idx], "all") == 0) { -				amount_idx++; -				scope = GAPS_SCOPE_ALL; -			} else if (strcmp(argv[amount_idx], "workspace") == 0) { -				amount_idx++; -				scope = GAPS_SCOPE_WORKSPACE; -			} else if (strcmp(argv[amount_idx], "current") == 0) { -				amount_idx++; -				scope = GAPS_SCOPE_CURRENT; -			} - -			// Long format: set|plus|minus -			if (strcmp(argv[amount_idx], "set") == 0) { -				amount_idx++; -				op = GAPS_OP_SET; -			} else if (strcmp(argv[amount_idx], "plus") == 0) { -				amount_idx++; -				op = GAPS_OP_ADD; -			} else if (strcmp(argv[amount_idx], "minus") == 0) { -				amount_idx++; -				op = GAPS_OP_SUBTRACT; -			} -		} +	bool inner; +	if (strcasecmp(argv[0], "inner") == 0) { +		inner = true; +	} else if (strcasecmp(argv[0], "outer") == 0) { +		inner = false; +	} else { +		return cmd_results_new(CMD_INVALID, "gaps", +				"Expected 'gaps inner|outer <px>'"); +	} -		char *end; -		double val = strtod(argv[amount_idx], &end); - -		if (strlen(end) && val == 0.0) { // invalid <amount> -			// guess which variant of the command was attempted -			if (argc == 1) { -				return cmd_results_new(CMD_INVALID, "gaps", "gaps <amount>"); -			} -			if (argc == 2) { -				return cmd_results_new(CMD_INVALID, "gaps", -					"gaps inner|outer <amount>"); -			} -			return cmd_results_new(CMD_INVALID, "gaps", -				"gaps inner|outer all|workspace|current set|plus|minus <amount>"); -		} +	char *end; +	int amount = strtol(argv[1], &end, 10); +	if (strlen(end) && strcasecmp(end, "px") != 0) { +		return cmd_results_new(CMD_INVALID, "gaps", +				"Expected 'gaps inner|outer <px>'"); +	} +	if (amount < 0) { +		amount = 0; +	} -		if (amount_idx == 0) { // gaps <amount> -			config->gaps_inner = val; -			config->gaps_outer = val; -			arrange_root(); -			return cmd_results_new(CMD_SUCCESS, NULL, NULL); -		} -		// Other variants. The middle-length variant (gaps inner|outer <amount>) -		// just defaults the scope to "all" and defaults the op to "set". - -		double total; -		switch (op) { -			case GAPS_OP_SUBTRACT: { -				total = (inner ? config->gaps_inner : config->gaps_outer) - val; -				if (total < 0) { -					total = 0; -				} -				break; -			} -			case GAPS_OP_ADD: { -				total = (inner ? config->gaps_inner : config->gaps_outer) + val; -				break; -			} -			case GAPS_OP_SET: { -				total = val; -				break; -			} -		} +	if (inner) { +		config->gaps_inner = amount; +	} else { +		config->gaps_outer = amount; +	} +	return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} -		if (scope == GAPS_SCOPE_ALL) { -			if (inner) { -				config->gaps_inner = total; -			} else { -				config->gaps_outer = total; -			} -			arrange_root(); -		} else { -			if (scope == GAPS_SCOPE_WORKSPACE) { -				struct sway_workspace *ws = config->handler_context.workspace; -				ws->has_gaps = true; -				if (inner) { -					ws->gaps_inner = total; -				} else { -					ws->gaps_outer = total; -				} -				arrange_workspace(ws); -			} else { -				struct sway_container *c = config->handler_context.container; -				c->has_gaps = true; -				if (inner) { -					c->gaps_inner = total; -				} else { -					c->gaps_outer = total; -				} -				arrange_workspace(c->workspace); -			} -		} +static void configure_gaps(struct sway_workspace *ws, void *_data) { +	struct gaps_data *data = _data; +	int *prop = data->inner ? &ws->gaps_inner : &ws->gaps_outer; + +	switch (data->operation) { +	case GAPS_OP_SET: +		*prop = data->amount; +		break; +	case GAPS_OP_ADD: +		*prop += data->amount; +		break; +	case GAPS_OP_SUBTRACT: +		*prop -= data->amount; +		break; +	} +	if (*prop < 0) { +		*prop = 0; +	} +	arrange_workspace(ws); +} + +// gaps inner|outer current|all set|plus|minus <px> +static struct cmd_results *gaps_set_runtime(int argc, char **argv) { +	struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4); +	if (error) { +		return error; +	} + +	struct gaps_data data; + +	if (strcasecmp(argv[0], "inner") == 0) { +		data.inner = true; +	} else if (strcasecmp(argv[0], "outer") == 0) { +		data.inner = false; +	} else { +		return cmd_results_new(CMD_INVALID, "gaps", +				"Expected 'gaps inner|outer current|all set|plus|minus <px>'"); +	} + +	bool all; +	if (strcasecmp(argv[1], "current") == 0) { +		all = false; +	} else if (strcasecmp(argv[1], "all") == 0) { +		all = true; +	} else { +		return cmd_results_new(CMD_INVALID, "gaps", +				"Expected 'gaps inner|outer current|all set|plus|minus <px>'"); +	} + +	if (strcasecmp(argv[2], "set") == 0) { +		data.operation = GAPS_OP_SET; +	} else if (strcasecmp(argv[2], "plus") == 0) { +		data.operation = GAPS_OP_ADD; +	} else if (strcasecmp(argv[2], "minus") == 0) { +		data.operation = GAPS_OP_SUBTRACT; +	} else { +		return cmd_results_new(CMD_INVALID, "gaps", +				"Expected 'gaps inner|outer current|all set|plus|minus <px>'"); +	} + +	char *end; +	data.amount = strtol(argv[3], &end, 10); +	if (strlen(end) && strcasecmp(end, "px") != 0) { +		return cmd_results_new(CMD_INVALID, "gaps", +				"Expected 'gaps inner|outer current|all set|plus|minus <px>'"); +	} + +	if (all) { +		root_for_each_workspace(configure_gaps, &data); +	} else { +		configure_gaps(config->handler_context.workspace, &data);  	}  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } + +// gaps edge_gaps on|off|toggle +// gaps inner|outer <px> - sets defaults for workspaces +// gaps inner|outer current|all set|plus|minus <px> - runtime only +struct cmd_results *cmd_gaps(int argc, char **argv) { +	struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2); +	if (error) { +		return error; +	} + +	if (strcmp(argv[0], "edge_gaps") == 0) { +		return gaps_edge_gaps(argc, argv); +	} + +	if (argc == 2) { +		return gaps_set_defaults(argc, argv); +	} +	if (argc == 4) { +		if (config->active) { +			return gaps_set_runtime(argc, argv); +		} else { +			return cmd_results_new(CMD_INVALID, "gaps", +					"This syntax can only be used when sway is running"); +		} +	} +	return cmd_results_new(CMD_INVALID, "gaps", +			"Expected 'gaps inner|outer <px>' or " +			"'gaps inner|outer current|all set|plus|minus <px>'"); +} diff --git a/sway/commands/input.c b/sway/commands/input.c index 84888fbb..2889d47d 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -9,6 +9,7 @@  static struct cmd_handler input_handlers[] = {  	{ "accel_profile", input_cmd_accel_profile },  	{ "click_method", input_cmd_click_method }, +	{ "drag", input_cmd_drag },  	{ "drag_lock", input_cmd_drag_lock },  	{ "dwt", input_cmd_dwt },  	{ "events", input_cmd_events }, @@ -66,7 +67,15 @@ struct cmd_results *cmd_input(int argc, char **argv) {  			input_handlers, sizeof(input_handlers));  	} -	free_input_config(config->handler_context.input_config); +	if (!res || res->status == CMD_SUCCESS) { +		struct input_config *ic = +			store_input_config(config->handler_context.input_config); + +		input_manager_apply_input_config(input_manager, ic); +	} else { +		free_input_config(config->handler_context.input_config); +	} +  	config->handler_context.input_config = NULL;  	return res; diff --git a/sway/commands/input/accel_profile.c b/sway/commands/input/accel_profile.c index a4108ec3..f7016790 100644 --- a/sway/commands/input/accel_profile.c +++ b/sway/commands/input/accel_profile.c @@ -9,25 +9,20 @@ struct cmd_results *input_cmd_accel_profile(int argc, char **argv) {  	if ((error = checkarg(argc, "accel_profile", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "accel_profile",  				"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	if (strcasecmp(argv[0], "adaptive") == 0) { -		new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; +		ic->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;  	} else if (strcasecmp(argv[0], "flat") == 0) { -		new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; +		ic->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;  	} else { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "accel_profile",  				"Expected 'accel_profile <adaptive|flat>'");  	} -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/click_method.c b/sway/commands/input/click_method.c index 5d0d8cc2..4d7e1c93 100644 --- a/sway/commands/input/click_method.c +++ b/sway/commands/input/click_method.c @@ -10,27 +10,22 @@ struct cmd_results *input_cmd_click_method(int argc, char **argv) {  	if ((error = checkarg(argc, "click_method", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "click_method",  			"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	if (strcasecmp(argv[0], "none") == 0) { -		new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE; +		ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE;  	} else if (strcasecmp(argv[0], "button_areas") == 0) { -		new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; +		ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;  	} else if (strcasecmp(argv[0], "clickfinger") == 0) { -		new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; +		ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;  	} else { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "click_method",  			"Expected 'click_method <none|button_areas|clickfinger'");  	} -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/drag.c b/sway/commands/input/drag.c new file mode 100644 index 00000000..e325df29 --- /dev/null +++ b/sway/commands/input/drag.c @@ -0,0 +1,26 @@ +#include <string.h> +#include <strings.h> +#include "sway/config.h" +#include "sway/commands.h" +#include "sway/input/input-manager.h" +#include "util.h" + +struct cmd_results *input_cmd_drag(int argc, char **argv) { +	struct cmd_results *error = NULL; +	if ((error = checkarg(argc, "drag", EXPECTED_AT_LEAST, 1))) { +		return error; +	} +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) { +		return cmd_results_new(CMD_FAILURE, +			"drag", "No input device defined."); +	} + +	if (parse_boolean(argv[0], true)) { +		ic->drag = LIBINPUT_CONFIG_DRAG_ENABLED; +	} else { +		ic->drag = LIBINPUT_CONFIG_DRAG_DISABLED; +	} + +	return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/input/drag_lock.c b/sway/commands/input/drag_lock.c index f9ddeef2..db5d5afa 100644 --- a/sway/commands/input/drag_lock.c +++ b/sway/commands/input/drag_lock.c @@ -10,21 +10,17 @@ struct cmd_results *input_cmd_drag_lock(int argc, char **argv) {  	if ((error = checkarg(argc, "drag_lock", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE,  			"drag_lock", "No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	if (parse_boolean(argv[0], true)) { -		new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; +		ic->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED;  	} else { -		new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; +		ic->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;  	} -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/dwt.c b/sway/commands/input/dwt.c index 15134268..0c3881dd 100644 --- a/sway/commands/input/dwt.c +++ b/sway/commands/input/dwt.c @@ -10,20 +10,16 @@ struct cmd_results *input_cmd_dwt(int argc, char **argv) {  	if ((error = checkarg(argc, "dwt", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "dwt", "No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	if (parse_boolean(argv[0], true)) { -		new_config->dwt = LIBINPUT_CONFIG_DWT_ENABLED; +		ic->dwt = LIBINPUT_CONFIG_DWT_ENABLED;  	} else { -		new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED; +		ic->dwt = LIBINPUT_CONFIG_DWT_DISABLED;  	} -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c index abfe3b12..e7ed69c6 100644 --- a/sway/commands/input/events.c +++ b/sway/commands/input/events.c @@ -10,30 +10,23 @@ struct cmd_results *input_cmd_events(int argc, char **argv) {  	if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "events",  			"No input device defined.");  	} -	wlr_log(WLR_DEBUG, "events for device: %s", -		current_input_config->identifier); -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	if (strcasecmp(argv[0], "enabled") == 0) { -		new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; +		ic->send_events = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;  	} else if (strcasecmp(argv[0], "disabled") == 0) { -		new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; +		ic->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;  	} else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) { -		new_config->send_events = +		ic->send_events =  			LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;  	} else { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "events",  			"Expected 'events <enabled|disabled|disabled_on_external_mouse>'");  	} -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/left_handed.c b/sway/commands/input/left_handed.c index e770043a..2e0f757b 100644 --- a/sway/commands/input/left_handed.c +++ b/sway/commands/input/left_handed.c @@ -10,17 +10,13 @@ struct cmd_results *input_cmd_left_handed(int argc, char **argv) {  	if ((error = checkarg(argc, "left_handed", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "left_handed",  			"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier); -	new_config->left_handed = parse_boolean(argv[0], true); +	ic->left_handed = parse_boolean(argv[0], true); -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/map_from_region.c b/sway/commands/input/map_from_region.c index 40f04214..53608a67 100644 --- a/sway/commands/input/map_from_region.c +++ b/sway/commands/input/map_from_region.c @@ -38,50 +38,44 @@ struct cmd_results *input_cmd_map_from_region(int argc, char **argv) {  	if ((error = checkarg(argc, "map_from_region", EXPECTED_EQUAL_TO, 2))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "map_from_region",  			"No input device defined");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier); - -	new_config->mapped_from_region = +	ic->mapped_from_region =  		calloc(1, sizeof(struct input_config_mapped_from_region));  	bool mm1, mm2; -	if (!parse_coords(argv[0], &new_config->mapped_from_region->x1, -			&new_config->mapped_from_region->y1, &mm1)) { -		free(new_config->mapped_from_region); -		free_input_config(new_config); +	if (!parse_coords(argv[0], &ic->mapped_from_region->x1, +			&ic->mapped_from_region->y1, &mm1)) { +		free(ic->mapped_from_region); +		ic->mapped_from_region = NULL;  		return cmd_results_new(CMD_FAILURE, "map_from_region",  			"Invalid top-left coordinates");  	} -	if (!parse_coords(argv[1], &new_config->mapped_from_region->x2, -			&new_config->mapped_from_region->y2, &mm2)) { -		free(new_config->mapped_from_region); -		free_input_config(new_config); +	if (!parse_coords(argv[1], &ic->mapped_from_region->x2, +			&ic->mapped_from_region->y2, &mm2)) { +		free(ic->mapped_from_region); +		ic->mapped_from_region = NULL;  		return cmd_results_new(CMD_FAILURE, "map_from_region",  			"Invalid bottom-right coordinates");  	} -	if (new_config->mapped_from_region->x1 > new_config->mapped_from_region->x2 || -			new_config->mapped_from_region->y1 > new_config->mapped_from_region->y2) { -		free(new_config->mapped_from_region); -		free_input_config(new_config); +	if (ic->mapped_from_region->x1 > ic->mapped_from_region->x2 || +			ic->mapped_from_region->y1 > ic->mapped_from_region->y2) { +		free(ic->mapped_from_region); +		ic->mapped_from_region = NULL;  		return cmd_results_new(CMD_FAILURE, "map_from_region",  			"Invalid rectangle");  	}  	if (mm1 != mm2) { -		free(new_config->mapped_from_region); -		free_input_config(new_config); +		free(ic->mapped_from_region); +		ic->mapped_from_region = NULL;  		return cmd_results_new(CMD_FAILURE, "map_from_region",  			"Both coordinates must be in the same unit");  	} -	new_config->mapped_from_region->mm = mm1; - -	apply_input_config(new_config); +	ic->mapped_from_region->mm = mm1;  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/map_to_output.c b/sway/commands/input/map_to_output.c index 68439bec..8b16c557 100644 --- a/sway/commands/input/map_to_output.c +++ b/sway/commands/input/map_to_output.c @@ -11,17 +11,13 @@ struct cmd_results *input_cmd_map_to_output(int argc, char **argv) {  	if ((error = checkarg(argc, "map_to_output", EXPECTED_EQUAL_TO, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "map_to_output",  			"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier); -	new_config->mapped_to_output = strdup(argv[0]); -	apply_input_config(new_config); +	ic->mapped_to_output = strdup(argv[0]);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/middle_emulation.c b/sway/commands/input/middle_emulation.c index 414d4d2b..80d26838 100644 --- a/sway/commands/input/middle_emulation.c +++ b/sway/commands/input/middle_emulation.c @@ -10,22 +10,17 @@ struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) {  	if ((error = checkarg(argc, "middle_emulation", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "middle_emulation",  			"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	if (parse_boolean(argv[0], true)) { -		new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; +		ic->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED;  	} else { -		new_config->middle_emulation = -			LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; +		ic->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;  	} -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/natural_scroll.c b/sway/commands/input/natural_scroll.c index 77c3ff00..e2a93500 100644 --- a/sway/commands/input/natural_scroll.c +++ b/sway/commands/input/natural_scroll.c @@ -10,17 +10,13 @@ struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) {  	if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "natural_scoll",  			"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier); -	new_config->natural_scroll = parse_boolean(argv[0], true); +	ic->natural_scroll = parse_boolean(argv[0], true); -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/pointer_accel.c b/sway/commands/input/pointer_accel.c index 8bbd0724..df487b1c 100644 --- a/sway/commands/input/pointer_accel.c +++ b/sway/commands/input/pointer_accel.c @@ -9,23 +9,18 @@ struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) {  	if ((error = checkarg(argc, "pointer_accel", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE,  			"pointer_accel", "No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	float pointer_accel = atof(argv[0]);  	if (pointer_accel < -1 || pointer_accel > 1) { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "pointer_accel",  			"Input out of range [-1, 1]");  	} -	new_config->pointer_accel = pointer_accel; +	ic->pointer_accel = pointer_accel; -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/repeat_delay.c b/sway/commands/input/repeat_delay.c index c9ddbf0e..d94b3e4d 100644 --- a/sway/commands/input/repeat_delay.c +++ b/sway/commands/input/repeat_delay.c @@ -9,23 +9,18 @@ struct cmd_results *input_cmd_repeat_delay(int argc, char **argv) {  	if ((error = checkarg(argc, "repeat_delay", EXPECTED_EQUAL_TO, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE,  			"repeat_delay", "No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	int repeat_delay = atoi(argv[0]);  	if (repeat_delay < 0) { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "repeat_delay",  			"Repeat delay cannot be negative");  	} -	new_config->repeat_delay = repeat_delay; +	ic->repeat_delay = repeat_delay; -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/repeat_rate.c b/sway/commands/input/repeat_rate.c index 56878176..ebec4cdb 100644 --- a/sway/commands/input/repeat_rate.c +++ b/sway/commands/input/repeat_rate.c @@ -9,23 +9,18 @@ struct cmd_results *input_cmd_repeat_rate(int argc, char **argv) {  	if ((error = checkarg(argc, "repeat_rate", EXPECTED_EQUAL_TO, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE,  			"repeat_rate", "No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	int repeat_rate = atoi(argv[0]);  	if (repeat_rate < 0) { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "repeat_rate",  			"Repeat rate cannot be negative");  	} -	new_config->repeat_rate = repeat_rate; +	ic->repeat_rate = repeat_rate; -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/scroll_button.c b/sway/commands/input/scroll_button.c index 350fcca2..1958f23c 100644 --- a/sway/commands/input/scroll_button.c +++ b/sway/commands/input/scroll_button.c @@ -10,35 +10,28 @@ struct cmd_results *input_cmd_scroll_button(int argc, char **argv) {  	if ((error = checkarg(argc, "scroll_button", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "scroll_button",  			"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	errno = 0;  	char *endptr;  	int scroll_button = strtol(*argv, &endptr, 10);  	if (endptr == *argv && scroll_button == 0) { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "scroll_button",  				"Scroll button identifier must be an integer.");  	}  	if (errno == ERANGE) { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "scroll_button",  				"Scroll button identifier out of range.");  	}  	if (scroll_button < 0) { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "scroll_button",  				"Scroll button identifier cannot be negative.");  	} -	new_config->scroll_button = scroll_button; +	ic->scroll_button = scroll_button; -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/scroll_method.c b/sway/commands/input/scroll_method.c index 4c6ac6b6..c116b052 100644 --- a/sway/commands/input/scroll_method.c +++ b/sway/commands/input/scroll_method.c @@ -9,29 +9,24 @@ struct cmd_results *input_cmd_scroll_method(int argc, char **argv) {  	if ((error = checkarg(argc, "scroll_method", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "scroll_method",  			"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	if (strcasecmp(argv[0], "none") == 0) { -		new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; +		ic->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL;  	} else if (strcasecmp(argv[0], "two_finger") == 0) { -		new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG; +		ic->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG;  	} else if (strcasecmp(argv[0], "edge") == 0) { -		new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE; +		ic->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE;  	} else if (strcasecmp(argv[0], "on_button_down") == 0) { -		new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; +		ic->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;  	} else { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "scroll_method",  			"Expected 'scroll_method <none|two_finger|edge|on_button_down>'");  	} -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/tap.c b/sway/commands/input/tap.c index ac3b8237..c455b696 100644 --- a/sway/commands/input/tap.c +++ b/sway/commands/input/tap.c @@ -11,22 +11,16 @@ struct cmd_results *input_cmd_tap(int argc, char **argv) {  	if ((error = checkarg(argc, "tap", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "tap", "No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	if (parse_boolean(argv[0], true)) { -		new_config->tap = LIBINPUT_CONFIG_TAP_ENABLED; +		ic->tap = LIBINPUT_CONFIG_TAP_ENABLED;  	} else { -		new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED; +		ic->tap = LIBINPUT_CONFIG_TAP_DISABLED;  	} -	wlr_log(WLR_DEBUG, "apply-tap for device: %s", -		current_input_config->identifier); -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/tap_button_map.c b/sway/commands/input/tap_button_map.c index bdbba472..dff2985b 100644 --- a/sway/commands/input/tap_button_map.c +++ b/sway/commands/input/tap_button_map.c @@ -9,25 +9,20 @@ struct cmd_results *input_cmd_tap_button_map(int argc, char **argv) {  	if ((error = checkarg(argc, "tap_button_map", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "tap_button_map",  				"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	if (strcasecmp(argv[0], "lrm") == 0) { -		new_config->tap_button_map = LIBINPUT_CONFIG_TAP_MAP_LRM; +		ic->tap_button_map = LIBINPUT_CONFIG_TAP_MAP_LRM;  	} else if (strcasecmp(argv[0], "lmr") == 0) { -		new_config->tap_button_map = LIBINPUT_CONFIG_TAP_MAP_LMR; +		ic->tap_button_map = LIBINPUT_CONFIG_TAP_MAP_LMR;  	} else { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "tap_button_map",  			"Expected 'tap_button_map <lrm|lmr>'");  	} -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/xkb_capslock.c b/sway/commands/input/xkb_capslock.c index 5442c463..669b4ea9 100644 --- a/sway/commands/input/xkb_capslock.c +++ b/sway/commands/input/xkb_capslock.c @@ -9,25 +9,20 @@ struct cmd_results *input_cmd_xkb_capslock(int argc, char **argv) {  	if ((error = checkarg(argc, "xkb_capslock", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "xkb_capslock",   			"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	if (strcasecmp(argv[0], "enabled") == 0) { -		new_config->xkb_capslock = 1; +		ic->xkb_capslock = 1;  	} else if (strcasecmp(argv[0], "disabled") == 0) { -		new_config->xkb_capslock = 0;  +		ic->xkb_capslock = 0;  	} else { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "xkb_capslock",  			"Expected 'xkb_capslock <enabled|disabled>'");  	} -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/xkb_layout.c b/sway/commands/input/xkb_layout.c index 9fa5a344..5fccd4a3 100644 --- a/sway/commands/input/xkb_layout.c +++ b/sway/commands/input/xkb_layout.c @@ -9,18 +9,15 @@ struct cmd_results *input_cmd_xkb_layout(int argc, char **argv) {  	if ((error = checkarg(argc, "xkb_layout", EXPECTED_EQUAL_TO, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { -		return cmd_results_new(CMD_FAILURE, "xkb_layout", "No input device defined."); +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) { +		return cmd_results_new(CMD_FAILURE, "xkb_layout", +				"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier); -	new_config->xkb_layout = strdup(argv[0]); +	ic->xkb_layout = strdup(argv[0]); -	wlr_log(WLR_DEBUG, "apply-xkb_layout for device: %s layout: %s", -		current_input_config->identifier, new_config->xkb_layout); -	apply_input_config(new_config); +	wlr_log(WLR_DEBUG, "set-xkb_layout for config: %s layout: %s", +			ic->identifier, ic->xkb_layout);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/xkb_model.c b/sway/commands/input/xkb_model.c index 0d082625..c4d04638 100644 --- a/sway/commands/input/xkb_model.c +++ b/sway/commands/input/xkb_model.c @@ -9,18 +9,15 @@ struct cmd_results *input_cmd_xkb_model(int argc, char **argv) {  	if ((error = checkarg(argc, "xkb_model", EXPECTED_EQUAL_TO, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { -		return cmd_results_new(CMD_FAILURE, "xkb_model", "No input device defined."); +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) { +		return cmd_results_new(CMD_FAILURE, "xkb_model", +				"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier); -	new_config->xkb_model = strdup(argv[0]); +	ic->xkb_model = strdup(argv[0]); -	wlr_log(WLR_DEBUG, "apply-xkb_model for device: %s model: %s", -		current_input_config->identifier, new_config->xkb_model); -	apply_input_config(new_config); +	wlr_log(WLR_DEBUG, "set-xkb_model for config: %s model: %s", +			ic->identifier, ic->xkb_model);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/xkb_numlock.c b/sway/commands/input/xkb_numlock.c index 39675366..1367da44 100644 --- a/sway/commands/input/xkb_numlock.c +++ b/sway/commands/input/xkb_numlock.c @@ -9,25 +9,20 @@ struct cmd_results *input_cmd_xkb_numlock(int argc, char **argv) {  	if ((error = checkarg(argc, "xkb_numlock", EXPECTED_AT_LEAST, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) {  		return cmd_results_new(CMD_FAILURE, "xkb_numlock",   			"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier);  	if (strcasecmp(argv[0], "enabled") == 0) { -		new_config->xkb_numlock = 1; +		ic->xkb_numlock = 1;  	} else if (strcasecmp(argv[0], "disabled") == 0) { -		new_config->xkb_numlock = 0;  +		ic->xkb_numlock = 0;  	} else { -		free_input_config(new_config);  		return cmd_results_new(CMD_INVALID, "xkb_numlock",  			"Expected 'xkb_numlock <enabled|disabled>'");  	} -	apply_input_config(new_config);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/xkb_options.c b/sway/commands/input/xkb_options.c index 3059d941..794ab6e9 100644 --- a/sway/commands/input/xkb_options.c +++ b/sway/commands/input/xkb_options.c @@ -9,18 +9,15 @@ struct cmd_results *input_cmd_xkb_options(int argc, char **argv) {  	if ((error = checkarg(argc, "xkb_options", EXPECTED_EQUAL_TO, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { -		return cmd_results_new(CMD_FAILURE, "xkb_options", "No input device defined."); +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) { +		return cmd_results_new(CMD_FAILURE, "xkb_options", +				"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier); -	new_config->xkb_options = strdup(argv[0]); +	ic->xkb_options = strdup(argv[0]); -	wlr_log(WLR_DEBUG, "apply-xkb_options for device: %s options: %s", -		current_input_config->identifier, new_config->xkb_options); -	apply_input_config(new_config); +	wlr_log(WLR_DEBUG, "set-xkb_options for config: %s options: %s", +			ic->identifier, ic->xkb_options);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/xkb_rules.c b/sway/commands/input/xkb_rules.c index 560f088e..257c3288 100644 --- a/sway/commands/input/xkb_rules.c +++ b/sway/commands/input/xkb_rules.c @@ -9,18 +9,15 @@ struct cmd_results *input_cmd_xkb_rules(int argc, char **argv) {  	if ((error = checkarg(argc, "xkb_rules", EXPECTED_EQUAL_TO, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { -		return cmd_results_new(CMD_FAILURE, "xkb_rules", "No input device defined."); +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) { +		return cmd_results_new(CMD_FAILURE, "xkb_rules", +				"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier); -	new_config->xkb_rules = strdup(argv[0]); +	ic->xkb_rules = strdup(argv[0]); -	wlr_log(WLR_DEBUG, "apply-xkb_rules for device: %s rules: %s", -		current_input_config->identifier, new_config->xkb_rules); -	apply_input_config(new_config); +	wlr_log(WLR_DEBUG, "set-xkb_rules for config: %s rules: %s", +			ic->identifier, ic->xkb_rules);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/input/xkb_variant.c b/sway/commands/input/xkb_variant.c index 0aa03440..3832dc8e 100644 --- a/sway/commands/input/xkb_variant.c +++ b/sway/commands/input/xkb_variant.c @@ -9,18 +9,15 @@ struct cmd_results *input_cmd_xkb_variant(int argc, char **argv) {  	if ((error = checkarg(argc, "xkb_variant", EXPECTED_EQUAL_TO, 1))) {  		return error;  	} -	struct input_config *current_input_config = -		config->handler_context.input_config; -	if (!current_input_config) { -		return cmd_results_new(CMD_FAILURE, "xkb_variant", "No input device defined."); +	struct input_config *ic = config->handler_context.input_config; +	if (!ic) { +		return cmd_results_new(CMD_FAILURE, "xkb_variant", +				"No input device defined.");  	} -	struct input_config *new_config = -		new_input_config(current_input_config->identifier); -	new_config->xkb_variant = strdup(argv[0]); +	ic->xkb_variant = strdup(argv[0]); -	wlr_log(WLR_DEBUG, "apply-xkb_variant for device: %s variant: %s", -		current_input_config->identifier, new_config->xkb_variant); -	apply_input_config(new_config); +	wlr_log(WLR_DEBUG, "set-xkb_variant for config: %s variant: %s", +			ic->identifier, ic->xkb_variant);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/layout.c b/sway/commands/layout.c index ef3ec1cb..c2ce2e78 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -138,15 +138,14 @@ struct cmd_results *cmd_layout(int argc, char **argv) {  			}  			container->layout = new_layout;  			container_update_representation(container); -			arrange_container(container);  		} else {  			if (old_layout != L_TABBED && old_layout != L_STACKED) {  				workspace->prev_split_layout = old_layout;  			}  			workspace->layout = new_layout;  			workspace_update_representation(workspace); -			arrange_workspace(workspace);  		} +		arrange_workspace(workspace);  	}  	return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/move.c b/sway/commands/move.c index 849a18ad..fc2f1cc1 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -259,50 +259,24 @@ static void container_move_to_container(struct sway_container *container,   * In other words, rejigger it. */  static void workspace_rejigger(struct sway_workspace *ws,  		struct sway_container *child, enum movement_direction move_dir) { +	if (!child->parent && ws->tiling->length == 1) { +		ws->layout = +			move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT; +		workspace_update_representation(ws); +		return; +	}  	container_detach(child); -	workspace_wrap_children(ws); +	struct sway_container *new_parent = workspace_wrap_children(ws);  	int index = move_dir == MOVE_LEFT || move_dir == MOVE_UP ? 0 : 1;  	workspace_insert_tiling(ws, child, index); +	container_flatten(new_parent);  	ws->layout =  		move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT;  	workspace_update_representation(ws);  	child->width = child->height = 0;  } -static void move_out_of_tabs_stacks(struct sway_container *container, -		struct sway_container *current, enum movement_direction move_dir, -		int offs) { -	enum sway_container_layout layout = move_dir == -		MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT; -	list_t *siblings = container_get_siblings(container); -	if (container == current && siblings->length == 1) { -		wlr_log(WLR_DEBUG, "Changing layout of parent"); -		if (container->parent) { -			container->parent->layout = layout; -			container_update_representation(container); -		} else { -			container->workspace->layout = layout; -			workspace_update_representation(container->workspace); -		} -		return; -	} - -	wlr_log(WLR_DEBUG, "Moving out of tab/stack into a split"); -	if (current->parent) { -		struct sway_container *new_parent = -			container_split(current->parent, layout); -		container_insert_child(new_parent, container, offs < 0 ? 0 : 1); -		container_reap_empty(new_parent); -		container_flatten(new_parent); -	} else { -		// Changing a workspace -		struct sway_workspace *workspace = container->workspace; -		workspace_split(workspace, layout); -		workspace_insert_tiling(workspace, container, offs < 0 ? 0 : 1); -	} -} -  // Returns true if moved  static bool container_move_in_direction(struct sway_container *container,  		enum movement_direction move_dir) { @@ -334,7 +308,6 @@ static bool container_move_in_direction(struct sway_container *container,  	int offs = move_dir == MOVE_LEFT || move_dir == MOVE_UP ? -1 : 1;  	while (current) { -		struct sway_container *parent = current->parent;  		list_t *siblings = container_get_siblings(current);  		enum sway_container_layout layout = container_parent_layout(current);  		int index = list_find(siblings, current); @@ -343,15 +316,8 @@ static bool container_move_in_direction(struct sway_container *container,  		if (is_parallel(layout, move_dir)) {  			if (desired == -1 || desired == siblings->length) {  				if (current->parent == container->parent) { -					if (!(parent && parent->is_fullscreen) && -							(layout == L_TABBED || layout == L_STACKED)) { -						move_out_of_tabs_stacks(container, current, -								move_dir, offs); -						return true; -					} else { -						current = current->parent; -						continue; -					} +					current = current->parent; +					continue;  				} else {  					// Special case  					if (current->parent) { @@ -369,10 +335,6 @@ static bool container_move_in_direction(struct sway_container *container,  						siblings->items[desired], move_dir);  				return true;  			} -		} else if (!(parent && parent->is_fullscreen) && -				(layout == L_TABBED || layout == L_STACKED)) { -			move_out_of_tabs_stacks(container, current, move_dir, offs); -			return true;  		}  		current = current->parent; @@ -388,10 +350,8 @@ static bool container_move_in_direction(struct sway_container *container,  	// Maybe rejigger the workspace  	struct sway_workspace *ws = container->workspace;  	if (!is_parallel(ws->layout, move_dir)) { -		if (ws->tiling->length >= 2) { -			workspace_rejigger(ws, container, move_dir); -			return true; -		} +		workspace_rejigger(ws, container, move_dir); +		return true;  	} else if (ws->layout == L_TABBED || ws->layout == L_STACKED) {  		workspace_rejigger(ws, container, move_dir);  		return true; diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 9e370d43..30fb47c4 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c @@ -123,19 +123,13 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {  			}  			free(src);  		} else { -			// Escape spaces and quotes in the final path for swaybg +			// Escape double quotes in the final path for swaybg  			for (size_t i = 0; i < strlen(src); i++) { -				switch (src[i]) { -					case ' ': -					case '\'': -					case '\"': -						src = realloc(src, strlen(src) + 2); -						memmove(src + i + 1, src + i, strlen(src + i) + 1); -						*(src + i) = '\\'; -						i++; -						break; -					default: -						break; +				if (src[i] == '"') { +					src = realloc(src, strlen(src) + 2); +					memmove(src + i + 1, src + i, strlen(src + i) + 1); +					*(src + i) = '\\'; +					i++;  				}  			} diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 99e9dbda..1343b165 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -179,11 +179,11 @@ static void container_recursive_resize(struct sway_container *container,  	}  } -static void resize_tiled(struct sway_container *parent, int amount, +static bool resize_tiled(struct sway_container *parent, int amount,  		enum resize_axis axis) {  	struct sway_container *focused = parent;  	if (!parent) { -		return; +		return false;  	}  	enum sway_container_layout parallel_layout = @@ -216,7 +216,7 @@ static void resize_tiled(struct sway_container *parent, int amount,  	}  	if (!parent) {  		// Can't resize in this direction -		return; +		return false;  	}  	// Implement up/down/left/right direction by zeroing one of the weights, @@ -248,22 +248,22 @@ static void resize_tiled(struct sway_container *parent, int amount,  			if (sibling_pos < parent_pos && minor_weight) {  				double pixels = -amount / minor_weight;  				if (major_weight && (sibling_size + pixels / 2) < min_sane) { -					return; // Too small +					return false; // Too small  				} else if (!major_weight && sibling_size + pixels < min_sane) { -					return; // Too small +					return false; // Too small  				}  			} else if (sibling_pos > parent_pos && major_weight) {  				double pixels = -amount / major_weight;  				if (minor_weight && (sibling_size + pixels / 2) < min_sane) { -					return; // Too small +					return false; // Too small  				} else if (!minor_weight && sibling_size + pixels < min_sane) { -					return; // Too small +					return false; // Too small  				}  			}  		} else {  			double pixels = amount;  			if (parent_size + pixels < min_sane) { -				return; // Too small +				return false; // Too small  			}  		}  	} @@ -317,9 +317,10 @@ static void resize_tiled(struct sway_container *parent, int amount,  	} else {  		arrange_workspace(parent->workspace);  	} +	return true;  } -void container_resize_tiled(struct sway_container *parent, +bool container_resize_tiled(struct sway_container *parent,  		enum wlr_edges edge, int amount) {  	enum resize_axis axis = RESIZE_AXIS_INVALID;  	switch (edge) { @@ -338,7 +339,7 @@ void container_resize_tiled(struct sway_container *parent,  	case WLR_EDGE_NONE:  		break;  	} -	resize_tiled(parent, amount, axis); +	return resize_tiled(parent, amount, axis);  }  /** @@ -395,6 +396,10 @@ static struct cmd_results *resize_adjust_floating(enum resize_axis axis,  	case RESIZE_AXIS_INVALID:  		return cmd_results_new(CMD_INVALID, "resize", "Invalid axis/direction");  	} +	if (grow_x == 0 && grow_y == 0) { +		return cmd_results_new(CMD_INVALID, "resize", +				"Cannot resize any further"); +	}  	con->x += grow_x;  	con->y += grow_y;  	con->width += grow_width; @@ -442,7 +447,10 @@ static struct cmd_results *resize_adjust_tiled(enum resize_axis axis,  		}  	} -	resize_tiled(current, amount->amount, axis); +	if (!resize_tiled(current, amount->amount, axis)) { +		return cmd_results_new(CMD_INVALID, "resize", +				"Cannot resize any further"); +	}  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index f026a39d..63f29641 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c @@ -10,6 +10,28 @@  #include "log.h"  #include "stringop.h" +static struct workspace_config *workspace_config_find_or_create(char *ws_name) { +	struct workspace_config *wsc = workspace_find_config(ws_name); +	if (wsc) { +		return wsc; +	} +	wsc = calloc(1, sizeof(struct workspace_config)); +	if (!wsc) { +		return NULL; +	} +	wsc->workspace = strdup(ws_name); +	wsc->gaps_inner = -1; +	wsc->gaps_outer = -1; +	list_add(config->workspace_configs, wsc); +	return wsc; +} + +void free_workspace_config(struct workspace_config *wsc) { +	free(wsc->workspace); +	free(wsc->output); +	free(wsc); +} +  struct cmd_results *cmd_workspace(int argc, char **argv) {  	struct cmd_results *error = NULL;  	if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { @@ -17,6 +39,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {  	}  	int output_location = -1; +	int gaps_location = -1;  	for (int i = 0; i < argc; ++i) {  		if (strcasecmp(argv[i], "output") == 0) { @@ -24,25 +47,54 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {  			break;  		}  	} +	for (int i = 0; i < argc; ++i) { +		if (strcasecmp(argv[i], "gaps") == 0) { +			gaps_location = i; +			break; +		} +	}  	if (output_location >= 0) {  		if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) {  			return error;  		} -		struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); -		if (!wso) { +		char *ws_name = join_args(argv, argc - 2); +		struct workspace_config *wsc = workspace_config_find_or_create(ws_name); +		free(ws_name); +		if (!wsc) {  			return cmd_results_new(CMD_FAILURE, "workspace output",  					"Unable to allocate workspace output");  		} -		wso->workspace = join_args(argv, argc - 2); -		wso->output = strdup(argv[output_location + 1]); -		int i = -1; -		if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) { -			struct workspace_output *old = config->workspace_outputs->items[i]; -			free(old); // workspaces can only be assigned to a single output -			list_del(config->workspace_outputs, i); +		free(wsc->output); +		wsc->output = strdup(argv[output_location + 1]); +	} else if (gaps_location >= 0) { +		if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, gaps_location + 3))) { +			return error; +		} +		char *ws_name = join_args(argv, argc - 3); +		struct workspace_config *wsc = workspace_config_find_or_create(ws_name); +		free(ws_name); +		if (!wsc) { +			return cmd_results_new(CMD_FAILURE, "workspace gaps", +					"Unable to allocate workspace output"); +		} +		int *prop = NULL; +		if (strcasecmp(argv[gaps_location + 1], "inner") == 0) { +			prop = &wsc->gaps_inner; +		} else if (strcasecmp(argv[gaps_location + 1], "outer") == 0) { +			prop = &wsc->gaps_outer; +		} else { +			return cmd_results_new(CMD_FAILURE, "workspace gaps", +					"Expected 'workspace <ws> gaps inner|outer <px>'"); +		} +		char *end; +		int val = strtol(argv[gaps_location + 2], &end, 10); + +		if (strlen(end)) { +			free(end); +			return cmd_results_new(CMD_FAILURE, "workspace gaps", +					"Expected 'workspace <ws> gaps inner|outer <px>'");  		} -		wlr_log(WLR_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output); -		list_add(config->workspace_outputs, wso); +		*prop = val >= 0 ? val : 0;  	} else {  		if (config->reading || !config->active) {  			return cmd_results_new(CMD_DEFER, "workspace", NULL);  | 
