diff options
Diffstat (limited to 'sway/commands')
| -rw-r--r-- | sway/commands/bar.c | 2 | ||||
| -rw-r--r-- | sway/commands/bar/status_edge_padding.c | 21 | ||||
| -rw-r--r-- | sway/commands/bar/status_padding.c | 21 | ||||
| -rw-r--r-- | sway/commands/input/events.c | 76 | ||||
| -rw-r--r-- | sway/commands/input/scroll_button.c | 34 | ||||
| -rw-r--r-- | sway/commands/seat/cursor.c | 41 | 
6 files changed, 168 insertions, 27 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c index ee5a8ebf..2a82d508 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c @@ -24,6 +24,8 @@ static struct cmd_handler bar_handlers[] = {  	{ "position", bar_cmd_position },  	{ "separator_symbol", bar_cmd_separator_symbol },  	{ "status_command", bar_cmd_status_command }, +	{ "status_edge_padding", bar_cmd_status_edge_padding }, +	{ "status_padding", bar_cmd_status_padding },  	{ "strip_workspace_name", bar_cmd_strip_workspace_name },  	{ "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },  	{ "tray_bindsym", bar_cmd_tray_bindsym }, diff --git a/sway/commands/bar/status_edge_padding.c b/sway/commands/bar/status_edge_padding.c new file mode 100644 index 00000000..f3b10631 --- /dev/null +++ b/sway/commands/bar/status_edge_padding.c @@ -0,0 +1,21 @@ +#include <stdlib.h> +#include <string.h> +#include "sway/commands.h" +#include "log.h" + +struct cmd_results *bar_cmd_status_edge_padding(int argc, char **argv) { +	struct cmd_results *error = NULL; +	if ((error = checkarg(argc, "status_edge_padding", EXPECTED_EQUAL_TO, 1))) { +		return error; +	} +	char *end; +	int padding = strtol(argv[0], &end, 10); +	if (strlen(end) || padding < 0) { +		return cmd_results_new(CMD_INVALID, "status_edge_padding", +				"Padding must be a positive integer"); +	} +	config->current_bar->status_edge_padding = padding; +	wlr_log(WLR_DEBUG, "Status edge padding on bar %s: %d", +			config->current_bar->id, config->current_bar->status_edge_padding); +	return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/bar/status_padding.c b/sway/commands/bar/status_padding.c new file mode 100644 index 00000000..13b8eb6b --- /dev/null +++ b/sway/commands/bar/status_padding.c @@ -0,0 +1,21 @@ +#include <stdlib.h> +#include <string.h> +#include "sway/commands.h" +#include "log.h" + +struct cmd_results *bar_cmd_status_padding(int argc, char **argv) { +	struct cmd_results *error = NULL; +	if ((error = checkarg(argc, "status_padding", EXPECTED_EQUAL_TO, 1))) { +		return error; +	} +	char *end; +	int padding = strtol(argv[0], &end, 10); +	if (strlen(end) || padding < 0) { +		return cmd_results_new(CMD_INVALID, "status_padding", +				"Padding must be a positive integer"); +	} +	config->current_bar->status_padding = padding; +	wlr_log(WLR_DEBUG, "Status padding on bar %s: %d", +			config->current_bar->id, config->current_bar->status_padding); +	return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c index e7ed69c6..69f46269 100644 --- a/sway/commands/input/events.c +++ b/sway/commands/input/events.c @@ -1,10 +1,69 @@ +#include <limits.h>  #include <string.h>  #include <strings.h> +#include <wlr/backend/libinput.h>  #include "sway/config.h"  #include "sway/commands.h"  #include "sway/input/input-manager.h"  #include "log.h" +static void toggle_send_events_for_device(struct input_config *ic, +		struct sway_input_device *input_device) { +	struct wlr_input_device *wlr_device = input_device->wlr_device; +	if (!wlr_input_device_is_libinput(wlr_device)) { +		return; +	} +	struct libinput_device *libinput_dev +		= wlr_libinput_get_device_handle(wlr_device); + +	enum libinput_config_send_events_mode mode = +		libinput_device_config_send_events_get_mode(libinput_dev); +	uint32_t possible = +		libinput_device_config_send_events_get_modes(libinput_dev); + +	switch (mode) { +	case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED: +		mode = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; +		if (possible & mode) { +			break; +		} +		// fall through +	case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE: +		mode = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; +		if (possible & mode) { +			break; +		} +		// fall through +	case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED: +	default: +		mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; +		break; +	} + +	ic->send_events = mode; +} + +static void toggle_send_events(struct input_config *ic) { +	struct sway_input_device *input_device = NULL; +	wl_list_for_each(input_device, &server.input->devices, link) { +		if (strcmp(input_device->identifier, ic->identifier) == 0) { +			toggle_send_events_for_device(ic, input_device); +		} +	} +} + +static void toggle_wildcard_send_events() { +	struct sway_input_device *input_device = NULL; +	wl_list_for_each(input_device, &server.input->devices, link) { +		struct input_config *ic = new_input_config(input_device->identifier); +		if (!ic) { +			break; +		} +		toggle_send_events_for_device(ic, input_device); +		store_input_config(ic); +	} +} +  struct cmd_results *input_cmd_events(int argc, char **argv) {  	struct cmd_results *error = NULL;  	if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) { @@ -23,9 +82,24 @@ struct cmd_results *input_cmd_events(int argc, char **argv) {  	} else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) {  		ic->send_events =  			LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; -	} else { +	} else if (config->reading) {  		return cmd_results_new(CMD_INVALID, "events",  			"Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); +	} else if (strcasecmp(argv[0], "toggle") == 0) { +		if (strcmp(ic->identifier, "*") == 0) { +			// Update the device input configs and then reset the wildcard +			// config send events mode so that is does not override the device +			// ones. The device ones will be applied when attempting to apply +			// the wildcard config +			toggle_wildcard_send_events(); +			ic->send_events = INT_MIN; +		} else { +			toggle_send_events(ic); +		} +	} else { +		return cmd_results_new(CMD_INVALID, "events", +			"Expected 'events <enabled|disabled|disabled_on_external_mouse|" +			"toggle>'");  	}  	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 1958f23c..d82a1fe1 100644 --- a/sway/commands/input/scroll_button.c +++ b/sway/commands/input/scroll_button.c @@ -1,9 +1,7 @@ -#include <string.h> -#include <strings.h> -#include <errno.h> +#include <libevdev/libevdev.h>  #include "sway/config.h"  #include "sway/commands.h" -#include "sway/input/input-manager.h" +#include "sway/input/cursor.h"  struct cmd_results *input_cmd_scroll_button(int argc, char **argv) {  	struct cmd_results *error = NULL; @@ -16,22 +14,26 @@ struct cmd_results *input_cmd_scroll_button(int argc, char **argv) {  			"No input device defined.");  	} -	errno = 0; -	char *endptr; -	int scroll_button = strtol(*argv, &endptr, 10); -	if (endptr == *argv && scroll_button == 0) { -		return cmd_results_new(CMD_INVALID, "scroll_button", -				"Scroll button identifier must be an integer."); +	if (strcmp(*argv, "disable") == 0) { +		ic->scroll_button = 0; +		return cmd_results_new(CMD_SUCCESS, NULL, NULL);  	} -	if (errno == ERANGE) { + +	char *message = NULL; +	uint32_t button = get_mouse_button(*argv, &message); +	if (message) { +		error = cmd_results_new(CMD_INVALID, "scroll_button", 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, "scroll_button", -				"Scroll button identifier out of range."); -	} -	if (scroll_button < 0) { +				"X11 axis buttons are not supported for scroll_button"); +	} else if (!button) {  		return cmd_results_new(CMD_INVALID, "scroll_button", -				"Scroll button identifier cannot be negative."); +				"Unknown button %s", *argv);  	} -	ic->scroll_button = scroll_button; +	ic->scroll_button = button;  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  } diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 1fbc68a1..8d9e426a 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c @@ -3,6 +3,7 @@  #include <strings.h>  #include <wlr/types/wlr_cursor.h> +#include <wlr/types/wlr_pointer.h>  #include "sway/commands.h"  #include "sway/input/cursor.h" @@ -11,7 +12,7 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor,  static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or "  					"'cursor <set> <x> <y>' or " -					"'curor <press|release> <left|right|1|2|3...>'"; +					"'curor <press|release> <button[1-9]|event-name-or-code>'";  static struct cmd_results *handle_command(struct sway_cursor *cursor,  		int argc, char **argv) { @@ -91,15 +92,35 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor,  		return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);  	} -	if (strcasecmp(button_str, "left") == 0) { -		button = BTN_LEFT; -	} else if (strcasecmp(button_str, "right") == 0) { -		button = BTN_RIGHT; -	} else { -		button = strtol(button_str, NULL, 10); -		if (button == 0) { -			return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); -		} +	char *message = NULL; +	button = get_mouse_button(button_str, &message); +	if (message) { +		struct cmd_results *error = +			cmd_results_new(CMD_INVALID, "cursor", message); +		free(message); +		return error; +	} else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN +			|| button == SWAY_SCROLL_LEFT || button == SWAY_SCROLL_RIGHT) { +		// Dispatch axis event +		enum wlr_axis_orientation orientation = +			(button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN) +			? WLR_AXIS_ORIENTATION_VERTICAL +			: WLR_AXIS_ORIENTATION_HORIZONTAL; +		double delta = (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_LEFT) +			? -1 : 1; +		struct wlr_event_pointer_axis event = { +			.device = NULL, +			.time_msec = 0, +			.source = WLR_AXIS_SOURCE_WHEEL, +			.orientation = orientation, +			.delta = delta * 15, +			.delta_discrete = delta +		}; +		dispatch_cursor_axis(cursor, &event); +		return cmd_results_new(CMD_SUCCESS, NULL, NULL); +	} else if (!button) { +		return cmd_results_new(CMD_INVALID, "curor", +				"Unknown button %s", button_str);  	}  	dispatch_cursor_button(cursor, NULL, 0, button, state);  	return cmd_results_new(CMD_SUCCESS, NULL, NULL);  | 
