Exemplo n.º 1
0
struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) {
	const char *cmd_name = "tray_padding";
#ifndef ENABLE_TRAY
	return cmd_results_new(CMD_INVALID, cmd_name, "Invalid %s command"
			"%s called, but sway was compiled without tray support",
			cmd_name, cmd_name);
#else
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, cmd_name, EXPECTED_AT_LEAST, 1))) {
		return error;
	}

	if (!config->current_bar) {
		return cmd_results_new(CMD_FAILURE, cmd_name, "No bar defined.");
	}

	if (argc == 1 || (argc == 2 && strcasecmp("px", argv[1]) == 0)) {
		char *inv;
		uint32_t padding = strtoul(argv[0], &inv, 10);
		if (*inv == '\0' || strcasecmp(inv, "px") == 0) {
			config->current_bar->tray_padding = padding;
			sway_log(L_DEBUG, "Enabling tray padding of %d px on bar: %s", padding, config->current_bar->id);
			return cmd_results_new(CMD_SUCCESS, NULL, NULL);
		}
	}
	return cmd_results_new(CMD_FAILURE, cmd_name,
		"Expected 'tray_padding <padding>[px]'");
#endif
}
Exemplo n.º 2
0
static struct cmd_results *parse_border_color(struct border_colors *border_colors, const char *cmd_name, int argc, char **argv) {
	struct cmd_results *error = NULL;
	if (argc != 5) {
		return cmd_results_new(CMD_INVALID, cmd_name, "Requires exactly five color values");
	}

	uint32_t colors[5];
	int i;
	for (i = 0; i < 5; i++) {
		char buffer[10];
		error = add_color(cmd_name, buffer, argv[i]);
		if (error) {
			return error;
		}
		colors[i] = strtoul(buffer+1, NULL, 16);
	}

	border_colors->border = colors[0];
	border_colors->background = colors[1];
	border_colors->text = colors[2];
	border_colors->indicator = colors[3];
	border_colors->child_border = colors[4];

	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Exemplo n.º 3
0
struct cmd_results *cmd_scratchpad(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if (config->reading) return cmd_results_new(CMD_FAILURE, "scratchpad", "Can't be used in config file.");
	if (!config->active) return cmd_results_new(CMD_FAILURE, "scratchpad", "Can only be used when sway is running.");
	if ((error = checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1))) {
		return error;
	}

	if (strcasecmp(argv[0], "show") == 0 && scratchpad->length > 0) {
		if (!sp_view) {
			sp_view = fetch_view_from_scratchpad();
		} else {
			if (swayc_active_workspace() != sp_view->parent) {
				hide_view_in_scratchpad(sp_view);
				if (sp_index == 0) {
					sp_index = scratchpad->length;
				}
				sp_index--;
				sp_view = fetch_view_from_scratchpad();
			} else {
				hide_view_in_scratchpad(sp_view);
				sp_view = NULL;
			}
		}
		return cmd_results_new(CMD_SUCCESS, NULL, NULL);
	}
	return cmd_results_new(CMD_FAILURE, "scratchpad", "Expected 'scratchpad show' when scratchpad is not empty.");
}
Exemplo n.º 4
0
struct cmd_results *cmd_kill(int argc, char **argv) {
	if (config->reading) return cmd_results_new(CMD_FAILURE, "kill", "Can't be used in config file.");
	if (!config->active) return cmd_results_new(CMD_FAILURE, "kill", "Can only be used when sway is running.");

	swayc_t *container = current_container;
	close_views(container);
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Exemplo n.º 5
0
struct cmd_results *cmd_exit(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if (config->reading) return cmd_results_new(CMD_FAILURE, "exit", "Can't be used in config file.");
	if ((error = checkarg(argc, "exit", EXPECTED_EQUAL_TO, 0))) {
		return error;
	}
	// Close all views
	close_views(&root_container);
	sway_terminate(EXIT_SUCCESS);
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Exemplo n.º 6
0
struct cmd_results *cmd_assign(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "assign", EXPECTED_AT_LEAST, 2))) {
		return error;
	}

	// Create criteria
	char *err_str = NULL;
	struct criteria *criteria = criteria_parse(argv[0], &err_str);
	if (!criteria) {
		error = cmd_results_new(CMD_INVALID, err_str);
		free(err_str);
		return error;
	}

	--argc; ++argv;

	if (strncmp(*argv, "→", strlen("→")) == 0) {
		if (argc < 2) {
			free(criteria);
			return cmd_results_new(CMD_INVALID, "Missing workspace");
		}
		--argc;
		++argv;
	}

	if (strcmp(*argv, "output") == 0) {
		criteria->type = CT_ASSIGN_OUTPUT;
		--argc; ++argv;
	} else {
		if (strcmp(*argv, "workspace") == 0) {
			--argc; ++argv;
		}
		if (strcmp(*argv, "number") == 0) {
			--argc; ++argv;
			if (argv[0][0] < '0' || argv[0][0] > '9') {
				free(criteria);
				return cmd_results_new(CMD_INVALID,
						"Invalid workspace number '%s'", argv[0]);
			}
			criteria->type = CT_ASSIGN_WORKSPACE_NUMBER;
		} else {
			criteria->type = CT_ASSIGN_WORKSPACE;
		}
	}

	criteria->target = join_args(argv, argc);

	list_add(config->criteria, criteria);
	sway_log(SWAY_DEBUG, "assign: '%s' -> '%s' added", criteria->raw,
			criteria->target);

	return cmd_results_new(CMD_SUCCESS, NULL);
}
Exemplo n.º 7
0
struct cmd_results *cmd_resize(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if (config->reading) return cmd_results_new(CMD_FAILURE, "resize", "Can't be used in config file.");
	if (!config->active) return cmd_results_new(CMD_FAILURE, "resize", "Can only be used when sway is running.");

	if (strcasecmp(argv[0], "set") == 0) {
		return cmd_resize_set(argc - 1, &argv[1]);
	}

	if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) {
		return error;
	}

	int dim_arg = argc - 1;

	enum resize_dim_types dim_type = RESIZE_DIM_DEFAULT;
	if (strcasecmp(argv[dim_arg], "ppt") == 0) {
		dim_type = RESIZE_DIM_PPT;
		dim_arg--;
	} else if (strcasecmp(argv[dim_arg], "px") == 0) {
		dim_type = RESIZE_DIM_PX;
		dim_arg--;
	}

	int amount = (int)strtol(argv[dim_arg], NULL, 10);
	if (errno == ERANGE || amount == 0) {
		errno = 0;
		amount = 10; // this is the default resize dimension used by i3 for both px and ppt
		sway_log(L_DEBUG, "Tried to get resize dimension out of '%s' but failed; setting dimension to default %d",
			argv[dim_arg], amount);
	}

	bool use_width = false;
	if (strcasecmp(argv[1], "width") == 0) {
		use_width = true;
	} else if (strcasecmp(argv[1], "height") != 0) {
		return cmd_results_new(CMD_INVALID, "resize",
			"Expected 'resize <shrink|grow> <width|height> [<amount>] [px|ppt]'");
	}

	if (strcasecmp(argv[0], "shrink") == 0) {
		amount *= -1;
	} else if (strcasecmp(argv[0], "grow") != 0) {
		return cmd_results_new(CMD_INVALID, "resize",
			"Expected 'resize <shrink|grow> <width|height> [<amount>] [px|ppt]'");
	}

	resize(amount, use_width, dim_type);
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Exemplo n.º 8
0
struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) {
		return error;
	}
	struct input_config *ic = config->handler_context.input_config;
	if (!ic) {
		return cmd_results_new(CMD_FAILURE, "No input device defined.");
	}

	ic->natural_scroll = parse_boolean(argv[0], true);

	return cmd_results_new(CMD_SUCCESS, NULL);
}
Exemplo n.º 9
0
struct cmd_results *cmd_reload(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if (config->reading) return cmd_results_new(CMD_FAILURE, "reload", "Can't be used in config file.");
	if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) {
		return error;
	}
	if (!load_main_config(config->current_config, true)) {
		return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config.");
	}

	load_swaybars();

	arrange_windows(&root_container, -1, -1);
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Exemplo n.º 10
0
struct cmd_results *bar_cmd_height(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "height", EXPECTED_EQUAL_TO, 1))) {
		return error;
	}
	int height = atoi(argv[0]);
	if (height < 0) {
		return cmd_results_new(CMD_INVALID,
				"Invalid height value: %s", argv[0]);
	}
	config->current_bar->height = height;
	sway_log(SWAY_DEBUG, "Setting bar height to %d on bar: %s",
			height, config->current_bar->id);
	return cmd_results_new(CMD_SUCCESS, NULL);
}
Exemplo n.º 11
0
struct cmd_results *cmd_commands(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "commands", EXPECTED_EQUAL_TO, 1))) {
		return error;
	}

	if (strcmp(argv[0], "{") != 0) {
		return cmd_results_new(CMD_FAILURE, "commands", "Expected block declaration");
	}

	if (!config->reading) {
		return cmd_results_new(CMD_FAILURE, "commands", "Can only be used in config file.");
	}

	return cmd_results_new(CMD_BLOCK_COMMANDS, NULL, NULL);
}
Exemplo n.º 12
0
static enum secure_feature get_features(int argc, char **argv,
		struct cmd_results **error) {
	enum secure_feature features = 0;

	struct {
		char *name;
		enum secure_feature feature;
	} feature_names[] = {
		{ "lock", FEATURE_LOCK },
		{ "panel", FEATURE_PANEL },
		{ "background", FEATURE_BACKGROUND },
		{ "screenshot", FEATURE_SCREENSHOT },
		{ "fullscreen", FEATURE_FULLSCREEN },
		{ "keyboard", FEATURE_KEYBOARD },
		{ "mouse", FEATURE_MOUSE },
		{ "ipc", FEATURE_IPC },
	};

	for (int i = 1; i < argc; ++i) {
		size_t j;
		for (j = 0; j < sizeof(feature_names) / sizeof(feature_names[0]); ++j) {
			if (strcmp(feature_names[j].name, argv[i]) == 0) {
				break;
			}
		}
		if (j == sizeof(feature_names) / sizeof(feature_names[0])) {
			*error = cmd_results_new(CMD_INVALID,
					"permit", "Invalid feature grant %s", argv[i]);
			return 0;
		}
		features |= feature_names[j].feature;
	}
	return features;
}
Exemplo n.º 13
0
struct cmd_results *cmd_floating_maximum_size(int argc, char **argv) {
	struct cmd_results *error = NULL;
	int32_t width;
	int32_t height;
	char *ptr;

	if ((error = checkarg(argc, "floating_maximum_size", EXPECTED_EQUAL_TO, 3))) {
		return error;
	}
	width = strtol(argv[0], &ptr, 10);
	height = strtol(argv[2], &ptr, 10);

	if (width < -1) {
		sway_log(L_DEBUG, "floating_maximum_size invalid width value: '%s'", argv[0]);

	} else {
		config->floating_maximum_width = width;

	}

	if (height < -1) {
		sway_log(L_DEBUG, "floating_maximum_size invalid height value: '%s'", argv[2]);
	}
	else {
		config->floating_maximum_height = height;

	}

	sway_log(L_DEBUG, "New floating_maximum_size: '%d' x '%d'", config->floating_maximum_width,
		config->floating_maximum_height);

	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Exemplo n.º 14
0
struct cmd_results *cmd_smart_gaps(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "smart_gaps", EXPECTED_EQUAL_TO, 1))) {
		return error;
	}

	if (strcasecmp(argv[0], "on") == 0) {
		config->smart_gaps = true;
	} else if (strcasecmp(argv[0], "off") == 0) {
		config->smart_gaps = false;
	} else {
		return cmd_results_new(CMD_INVALID, "smart_gaps", "Expected 'smart_gaps <on|off>'");
	}

	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Exemplo n.º 15
0
struct cmd_results *cmd_unmark(int argc, char **argv) {
	// Determine the container
	struct sway_container *con = NULL;
	if (config->handler_context.using_criteria) {
		con = config->handler_context.container;
	}

	// Determine the mark
	char *mark = NULL;
	if (argc > 0) {
		mark = join_args(argv, argc);
	}

	if (con && mark) {
		// Remove the mark from the given container
		if (container_has_mark(con, mark)) {
			container_find_and_unmark(mark);
		}
	} else if (con && !mark) {
		// Clear all marks from the given container
		container_clear_marks(con);
		container_update_marks_textures(con);
	} else if (!con && mark) {
		// Remove mark from whichever container has it
		container_find_and_unmark(mark);
	} else {
		// Remove all marks from all containers
		root_for_each_container(remove_all_marks_iterator, NULL);
	}
	free(mark);

	return cmd_results_new(CMD_SUCCESS, NULL);
}
Exemplo n.º 16
0
struct cmd_results *cmd_default_orientation(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "default_orientation", EXPECTED_EQUAL_TO, 1))) {
		return error;
	}
	if (strcasecmp(argv[0], "horizontal") == 0) {
		config->default_orientation = L_HORIZ;
	} else if (strcasecmp(argv[0], "vertical") == 0) {
		config->default_orientation = L_VERT;
	} else if (strcasecmp(argv[0], "auto") == 0) {
		// Do nothing
	} else {
		return cmd_results_new(CMD_INVALID,
				"Expected 'orientation <horizontal|vertical|auto>'");
	}
	return cmd_results_new(CMD_SUCCESS, NULL);
}
Exemplo n.º 17
0
struct cmd_results *check_security_config() {
	if (!current_config_path || strncmp(SYSCONFDIR "/sway/security.d/", current_config_path,
				strlen(SYSCONFDIR "/sway/security.d/")) != 0) {
		return cmd_results_new(CMD_INVALID, "permit",
				"This command is only permitted to run from " SYSCONFDIR "/sway/security.d/*");
	}
	return NULL;
}
Exemplo n.º 18
0
struct cmd_results *cmd_exit(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "exit", EXPECTED_EQUAL_TO, 0))) {
		return error;
	}
	sway_terminate(0);
	return cmd_results_new(CMD_SUCCESS, NULL);
}
Exemplo n.º 19
0
struct cmd_results *input_cmd_repeat_rate(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "repeat_rate", EXPECTED_EQUAL_TO, 1))) {
		return error;
	}
	struct input_config *ic = config->handler_context.input_config;
	if (!ic) {
		return cmd_results_new(CMD_FAILURE, "No input device defined.");
	}

	int repeat_rate = atoi(argv[0]);
	if (repeat_rate < 0) {
		return cmd_results_new(CMD_INVALID, "Repeat rate cannot be negative");
	}
	ic->repeat_rate = repeat_rate;

	return cmd_results_new(CMD_SUCCESS, NULL);
}
Exemplo n.º 20
0
struct cmd_results *cmd_client_background(int argc, char **argv) {
	char buffer[10];
	struct cmd_results *error = NULL;
	uint32_t background;

	if (argc != 1) {
		return cmd_results_new(CMD_INVALID, "client.background", "Requires exactly one color value");
	}

	error = add_color("client.background", buffer, argv[0]);
	if (error) {
		return error;
	}

	background = strtoul(buffer+1, NULL, 16);
	config->border_colors.background = background;
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Exemplo n.º 21
0
struct cmd_results *cmd_focus_follows_mouse(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1))) {
		return error;
	}

	config->focus_follows_mouse = !strcasecmp(argv[0], "yes");
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Exemplo n.º 22
0
Arquivo: bar.c Projeto: SirCmpwn/sway
struct cmd_results *cmd_bar(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 1))) {
		return error;
	}

	if (config->reading && strcmp("{", argv[0]) != 0) {
		return cmd_results_new(CMD_INVALID, "bar",
				"Expected '{' at start of bar config definition.");
	}

	if (!config->reading) {
		if (argc > 1) {
			if (strcasecmp("mode", argv[0]) == 0) {
				return bar_cmd_mode(argc-1, argv + 1);
			}

			if (strcasecmp("hidden_state", argv[0]) == 0) {
				return bar_cmd_hidden_state(argc-1, argv + 1);
			}
		}

		return cmd_results_new(CMD_FAILURE, "bar", "Can only be used in config file.");
	}

	// Create new bar with default values
	struct bar_config *bar = default_bar_config();

	// set bar id
	int i;
	for (i = 0; i < config->bars->length; ++i) {
		if (bar == config->bars->items[i]) {
			const int len = 5 + numlen(i); // "bar-" + i + \0
			bar->id = malloc(len * sizeof(char));
			snprintf(bar->id, len, "bar-%d", i);
			break;
		}
	}

	// Set current bar
	config->current_bar = bar;
	sway_log(L_DEBUG, "Configuring bar %s", bar->id);
	return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL);
}
Exemplo n.º 23
0
struct cmd_results *bar_cmd_output(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) {
		return error;
	}

	if (!config->current_bar) {
		return cmd_results_new(CMD_FAILURE, "output", "No bar defined.");
	}

	const char *output = argv[0];
	list_t *outputs = config->current_bar->outputs;
	if (!outputs) {
		outputs = create_list();
		config->current_bar->outputs = outputs;
	}

	int i;
	int add_output = 1;
	if (strcmp("*", output) == 0) {
		// remove all previous defined outputs and replace with '*'
		for (i = 0; i < outputs->length; ++i) {
			free(outputs->items[i]);
			list_del(outputs, i);
		}
	} else {
		// only add output if not already defined with either the same
		// name or as '*'
		for (i = 0; i < outputs->length; ++i) {
			const char *find = outputs->items[i];
			if (strcmp("*", find) == 0 || strcmp(output, find) == 0) {
				add_output = 0;
				break;
			}
		}
	}

	if (add_output) {
		list_add(outputs, strdup(output));
		sway_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output);
	}

	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Exemplo n.º 24
0
struct cmd_results *cmd_tiling_drag(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "tiling_drag", EXPECTED_EQUAL_TO, 1))) {
		return error;
	}

	config->tiling_drag = parse_boolean(argv[0], config->tiling_drag);

	return cmd_results_new(CMD_SUCCESS, NULL);
}
Exemplo n.º 25
0
struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "wrap_scroll", EXPECTED_EQUAL_TO, 1))) {
		return error;
	}
	if (!config->current_bar) {
		return cmd_results_new(CMD_FAILURE, "No bar defined.");
	}
	config->current_bar->wrap_scroll = 
			parse_boolean(argv[0], config->current_bar->wrap_scroll);
	if (config->current_bar->wrap_scroll) {
		sway_log(SWAY_DEBUG, "Enabling wrap scroll on bar: %s",
			config->current_bar->id);
	} else {
		sway_log(SWAY_DEBUG, "Disabling wrap scroll on bar: %s",
				config->current_bar->id);
	}
	return cmd_results_new(CMD_SUCCESS, NULL);
}
Exemplo n.º 26
0
struct cmd_results *cmd_title_format(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "title_format", EXPECTED_AT_LEAST, 1))) {
		return error;
	}
	struct sway_container *container = config->handler_context.container;
	if (!container || !container->view) {
		return cmd_results_new(CMD_INVALID,
				"Only views can have a title_format");
	}
	struct sway_view *view = container->view;
	char *format = join_args(argv, argc);
	if (view->title_format) {
		free(view->title_format);
	}
	view->title_format = format;
	view_update_title(view, true);
	config_update_font_height(true);
	return cmd_results_new(CMD_SUCCESS, NULL);
}
Exemplo n.º 27
0
struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) {
		return error;
	}
	if (!current_input_config) {
		return cmd_results_new(CMD_FAILURE, "natural_scoll", "No input device defined.");
	}
	struct input_config *new_config = new_input_config(current_input_config->identifier);

	if (strcasecmp(argv[0], "enabled") == 0) {
		new_config->natural_scroll = 1;
	} else if (strcasecmp(argv[0], "disabled") == 0) {
		new_config->natural_scroll = 0;
	} else {
		return cmd_results_new(CMD_INVALID, "natural_scroll", "Expected 'natural_scroll <enabled|disabled>'");
	}

	input_cmd_apply(new_config);
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Exemplo n.º 28
0
struct cmd_results *cmd_debuglog(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "debuglog", EXPECTED_EQUAL_TO, 1))) {
		return error;
	} else if (strcasecmp(argv[0], "toggle") == 0) {
		if (config->reading) {
			return cmd_results_new(CMD_FAILURE, "debuglog toggle", "Can't be used in config file.");
		}
		if (toggle_debug_logging()) {
			sway_log(L_DEBUG, "Debuglog turned on.");
		}
	} else if (strcasecmp(argv[0], "on") == 0) {
		set_log_level(L_DEBUG);
		sway_log(L_DEBUG, "Debuglog turned on.");
	} else if (strcasecmp(argv[0], "off") == 0) {
		reset_log_level();
	} else {
		return cmd_results_new(CMD_FAILURE, "debuglog", "Expected 'debuglog on|off|toggle'");
	}
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Exemplo n.º 29
0
struct cmd_results *input_cmd_scroll_button(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "scroll_button", EXPECTED_AT_LEAST, 1))) {
		return error;
	}
	struct input_config *ic = config->handler_context.input_config;
	if (!ic) {
		return cmd_results_new(CMD_FAILURE, "No input device defined.");
	}

	if (strcmp(*argv, "disable") == 0) {
		ic->scroll_button = 0;
		return cmd_results_new(CMD_SUCCESS, NULL);
	}

	char *message = NULL;
	uint32_t button = get_mouse_button(*argv, &message);
	if (message) {
		error = cmd_results_new(CMD_INVALID, message);
		free(message);
		return error;
	} else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN
			|| button == SWAY_SCROLL_LEFT || button == SWAY_SCROLL_RIGHT) {
		return cmd_results_new(CMD_INVALID,
				"X11 axis buttons are not supported for scroll_button");
	} else if (!button) {
		return cmd_results_new(CMD_INVALID, "Unknown button %s", *argv);
	}
	ic->scroll_button = button;

	return cmd_results_new(CMD_SUCCESS, NULL);
}
Exemplo n.º 30
0
struct cmd_results *input_cmd_scroll_factor(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "scroll_factor", EXPECTED_AT_LEAST, 1))) {
		return error;
	}
	struct input_config *ic = config->handler_context.input_config;
	if (!ic) {
		return cmd_results_new(CMD_FAILURE, "No input device defined.");
	}

	float scroll_factor = parse_float(argv[0]);
	if (isnan(scroll_factor)) {
		return cmd_results_new(CMD_INVALID,
			"Invalid scroll factor; expected float.");
	} else if (scroll_factor < 0) {
		return cmd_results_new(CMD_INVALID,
			"Scroll factor cannot be negative.");
	}
	ic->scroll_factor = scroll_factor;

	return cmd_results_new(CMD_SUCCESS, NULL);
}