mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Merge branch 'master' into mouse-bindings
This commit is contained in:
		
						commit
						e02a6718c2
					
				
					 16 changed files with 150 additions and 165 deletions
				
			
		| 
						 | 
					@ -123,6 +123,22 @@ uint32_t parse_color(const char *color) {
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool parse_boolean(const char *boolean, bool current) {
 | 
				
			||||||
 | 
						if (strcasecmp(boolean, "1") == 0
 | 
				
			||||||
 | 
								|| strcasecmp(boolean, "yes") == 0
 | 
				
			||||||
 | 
								|| strcasecmp(boolean, "on") == 0
 | 
				
			||||||
 | 
								|| strcasecmp(boolean, "true") == 0
 | 
				
			||||||
 | 
								|| strcasecmp(boolean, "enable") == 0
 | 
				
			||||||
 | 
								|| strcasecmp(boolean, "enabled") == 0
 | 
				
			||||||
 | 
								|| strcasecmp(boolean, "active") == 0) {
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						} else if (strcasecmp(boolean, "toggle") == 0) {
 | 
				
			||||||
 | 
							return !current;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// All other values are false to match i3
 | 
				
			||||||
 | 
						return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char* resolve_path(const char* path) {
 | 
					char* resolve_path(const char* path) {
 | 
				
			||||||
	struct stat sb;
 | 
						struct stat sb;
 | 
				
			||||||
	ssize_t r;
 | 
						ssize_t r;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,6 +50,14 @@ pid_t get_parent_pid(pid_t pid);
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
uint32_t parse_color(const char *color);
 | 
					uint32_t parse_color(const char *color);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Given a string that represents a boolean, return the boolean value. This
 | 
				
			||||||
 | 
					 * function also takes in the current boolean value to support toggling. If
 | 
				
			||||||
 | 
					 * toggling is not desired, pass in true for current so that toggling values
 | 
				
			||||||
 | 
					 * get parsed as not true.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					bool parse_boolean(const char *boolean, bool current);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Given a path string, recurseively resolves any symlinks to their targets
 | 
					 * Given a path string, recurseively resolves any symlinks to their targets
 | 
				
			||||||
 * (which may be a file, directory) and returns the result.
 | 
					 * (which may be a file, directory) and returns the result.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,12 +1,14 @@
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <strings.h>
 | 
					#include <strings.h>
 | 
				
			||||||
#include "sway/commands.h"
 | 
					#include "sway/commands.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cmd_results *cmd_focus_follows_mouse(int argc, char **argv) {
 | 
					struct cmd_results *cmd_focus_follows_mouse(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error = NULL;
 | 
						struct cmd_results *error = NULL;
 | 
				
			||||||
	if ((error = checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1))) {
 | 
						if ((error = checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1))) {
 | 
				
			||||||
		return error;
 | 
							return error;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	config->focus_follows_mouse = !strcasecmp(argv[0], "yes");
 | 
						config->focus_follows_mouse =
 | 
				
			||||||
 | 
							parse_boolean(argv[0], config->focus_follows_mouse);
 | 
				
			||||||
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
						return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
#include <strings.h>
 | 
					#include <strings.h>
 | 
				
			||||||
#include "sway/commands.h"
 | 
					#include "sway/commands.h"
 | 
				
			||||||
#include "sway/config.h"
 | 
					#include "sway/config.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cmd_results *cmd_focus_wrapping(int argc, char **argv) {
 | 
					struct cmd_results *cmd_focus_wrapping(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error = NULL;
 | 
						struct cmd_results *error = NULL;
 | 
				
			||||||
| 
						 | 
					@ -8,15 +9,12 @@ struct cmd_results *cmd_focus_wrapping(int argc, char **argv) {
 | 
				
			||||||
		return error;
 | 
							return error;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcasecmp(argv[0], "no") == 0) {
 | 
						if (strcasecmp(argv[0], "force") == 0) {
 | 
				
			||||||
		config->focus_wrapping = WRAP_NO;
 | 
					 | 
				
			||||||
	} else if (strcasecmp(argv[0], "yes") == 0) {
 | 
					 | 
				
			||||||
		config->focus_wrapping = WRAP_YES;
 | 
					 | 
				
			||||||
	} else if (strcasecmp(argv[0], "force") == 0) {
 | 
					 | 
				
			||||||
		config->focus_wrapping = WRAP_FORCE;
 | 
							config->focus_wrapping = WRAP_FORCE;
 | 
				
			||||||
 | 
						} else if (parse_boolean(argv[0], config->focus_wrapping == WRAP_YES)) {
 | 
				
			||||||
 | 
							config->focus_wrapping = WRAP_YES;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "focus_wrapping",
 | 
							config->focus_wrapping = WRAP_NO;
 | 
				
			||||||
				"Expected 'focus_wrapping yes|no|force'");
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
						return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
#include <strings.h>
 | 
					#include <strings.h>
 | 
				
			||||||
#include "sway/commands.h"
 | 
					#include "sway/commands.h"
 | 
				
			||||||
#include "sway/config.h"
 | 
					#include "sway/config.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cmd_results *cmd_force_focus_wrapping(int argc, char **argv) {
 | 
					struct cmd_results *cmd_force_focus_wrapping(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error =
 | 
						struct cmd_results *error =
 | 
				
			||||||
| 
						 | 
					@ -9,13 +10,10 @@ struct cmd_results *cmd_force_focus_wrapping(int argc, char **argv) {
 | 
				
			||||||
		return error;
 | 
							return error;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcasecmp(argv[0], "no") == 0) {
 | 
						if (parse_boolean(argv[0], config->focus_wrapping == WRAP_FORCE)) {
 | 
				
			||||||
		config->focus_wrapping = WRAP_YES;
 | 
					 | 
				
			||||||
	} else if (strcasecmp(argv[0], "yes") == 0) {
 | 
					 | 
				
			||||||
		config->focus_wrapping = WRAP_FORCE;
 | 
							config->focus_wrapping = WRAP_FORCE;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "force_focus_wrapping",
 | 
							config->focus_wrapping = WRAP_YES;
 | 
				
			||||||
				"Expected 'force_focus_wrapping yes|no'");
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
						return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@
 | 
				
			||||||
#include "sway/tree/container.h"
 | 
					#include "sway/tree/container.h"
 | 
				
			||||||
#include "sway/tree/view.h"
 | 
					#include "sway/tree/view.h"
 | 
				
			||||||
#include "sway/tree/layout.h"
 | 
					#include "sway/tree/layout.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cmd_results *cmd_fullscreen(int argc, char **argv) {
 | 
					struct cmd_results *cmd_fullscreen(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error = NULL;
 | 
						struct cmd_results *error = NULL;
 | 
				
			||||||
| 
						 | 
					@ -18,17 +19,10 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) {
 | 
				
			||||||
				"Only views can fullscreen");
 | 
									"Only views can fullscreen");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	struct sway_view *view = container->sway_view;
 | 
						struct sway_view *view = container->sway_view;
 | 
				
			||||||
	bool wants_fullscreen;
 | 
						bool wants_fullscreen = !view->is_fullscreen;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (argc == 0 || strcmp(argv[0], "toggle") == 0) {
 | 
						if (argc) {
 | 
				
			||||||
		wants_fullscreen = !view->is_fullscreen;
 | 
							wants_fullscreen = parse_boolean(argv[0], view->is_fullscreen);
 | 
				
			||||||
	} else if (strcmp(argv[0], "enable") == 0) {
 | 
					 | 
				
			||||||
		wants_fullscreen = true;
 | 
					 | 
				
			||||||
	} else if (strcmp(argv[0], "disable") == 0) {
 | 
					 | 
				
			||||||
		wants_fullscreen = false;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "fullscreen",
 | 
					 | 
				
			||||||
				"Expected 'fullscreen' or 'fullscreen <enable|disable|toggle>'");
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	view_set_fullscreen(view, wants_fullscreen);
 | 
						view_set_fullscreen(view, wants_fullscreen);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@
 | 
				
			||||||
#include "sway/config.h"
 | 
					#include "sway/config.h"
 | 
				
			||||||
#include "sway/commands.h"
 | 
					#include "sway/commands.h"
 | 
				
			||||||
#include "sway/input/input-manager.h"
 | 
					#include "sway/input/input-manager.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cmd_results *input_cmd_drag_lock(int argc, char **argv) {
 | 
					struct cmd_results *input_cmd_drag_lock(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error = NULL;
 | 
						struct cmd_results *error = NULL;
 | 
				
			||||||
| 
						 | 
					@ -18,14 +19,10 @@ struct cmd_results *input_cmd_drag_lock(int argc, char **argv) {
 | 
				
			||||||
	struct input_config *new_config =
 | 
						struct input_config *new_config =
 | 
				
			||||||
		new_input_config(current_input_config->identifier);
 | 
							new_input_config(current_input_config->identifier);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcasecmp(argv[0], "enabled") == 0) {
 | 
						if (parse_boolean(argv[0], true)) {
 | 
				
			||||||
		new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED;
 | 
							new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED;
 | 
				
			||||||
	} else if (strcasecmp(argv[0], "disabled") == 0) {
 | 
					 | 
				
			||||||
		new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		free_input_config(new_config);
 | 
							new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;
 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "drag_lock",
 | 
					 | 
				
			||||||
			"Expected 'drag_lock <enabled|disabled>'");
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	apply_input_config(new_config);
 | 
						apply_input_config(new_config);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@
 | 
				
			||||||
#include "sway/config.h"
 | 
					#include "sway/config.h"
 | 
				
			||||||
#include "sway/commands.h"
 | 
					#include "sway/commands.h"
 | 
				
			||||||
#include "sway/input/input-manager.h"
 | 
					#include "sway/input/input-manager.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cmd_results *input_cmd_dwt(int argc, char **argv) {
 | 
					struct cmd_results *input_cmd_dwt(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error = NULL;
 | 
						struct cmd_results *error = NULL;
 | 
				
			||||||
| 
						 | 
					@ -17,14 +18,10 @@ struct cmd_results *input_cmd_dwt(int argc, char **argv) {
 | 
				
			||||||
	struct input_config *new_config =
 | 
						struct input_config *new_config =
 | 
				
			||||||
		new_input_config(current_input_config->identifier);
 | 
							new_input_config(current_input_config->identifier);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcasecmp(argv[0], "enabled") == 0) {
 | 
						if (parse_boolean(argv[0], true)) {
 | 
				
			||||||
		new_config->dwt = LIBINPUT_CONFIG_DWT_ENABLED;
 | 
							new_config->dwt = LIBINPUT_CONFIG_DWT_ENABLED;
 | 
				
			||||||
	} else if (strcasecmp(argv[0], "disabled") == 0) {
 | 
					 | 
				
			||||||
		new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED;
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		free_input_config(new_config);
 | 
							new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED;
 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "dwt",
 | 
					 | 
				
			||||||
			"Expected 'dwt <enabled|disabled>'");
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	apply_input_config(new_config);
 | 
						apply_input_config(new_config);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@
 | 
				
			||||||
#include "sway/config.h"
 | 
					#include "sway/config.h"
 | 
				
			||||||
#include "sway/commands.h"
 | 
					#include "sway/commands.h"
 | 
				
			||||||
#include "sway/input/input-manager.h"
 | 
					#include "sway/input/input-manager.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cmd_results *input_cmd_left_handed(int argc, char **argv) {
 | 
					struct cmd_results *input_cmd_left_handed(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error = NULL;
 | 
						struct cmd_results *error = NULL;
 | 
				
			||||||
| 
						 | 
					@ -18,15 +19,7 @@ struct cmd_results *input_cmd_left_handed(int argc, char **argv) {
 | 
				
			||||||
	struct input_config *new_config =
 | 
						struct input_config *new_config =
 | 
				
			||||||
		new_input_config(current_input_config->identifier);
 | 
							new_input_config(current_input_config->identifier);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcasecmp(argv[0], "enabled") == 0) {
 | 
						new_config->left_handed = parse_boolean(argv[0], true);
 | 
				
			||||||
		new_config->left_handed = 1;
 | 
					 | 
				
			||||||
	} else if (strcasecmp(argv[0], "disabled") == 0) {
 | 
					 | 
				
			||||||
		new_config->left_handed = 0;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		free_input_config(new_config);
 | 
					 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "left_handed",
 | 
					 | 
				
			||||||
			"Expected 'left_handed <enabled|disabled>'");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	apply_input_config(new_config);
 | 
						apply_input_config(new_config);
 | 
				
			||||||
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
						return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@
 | 
				
			||||||
#include "sway/config.h"
 | 
					#include "sway/config.h"
 | 
				
			||||||
#include "sway/commands.h"
 | 
					#include "sway/commands.h"
 | 
				
			||||||
#include "sway/input/input-manager.h"
 | 
					#include "sway/input/input-manager.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) {
 | 
					struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error = NULL;
 | 
						struct cmd_results *error = NULL;
 | 
				
			||||||
| 
						 | 
					@ -18,15 +19,11 @@ struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) {
 | 
				
			||||||
	struct input_config *new_config =
 | 
						struct input_config *new_config =
 | 
				
			||||||
		new_input_config(current_input_config->identifier);
 | 
							new_input_config(current_input_config->identifier);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcasecmp(argv[0], "enabled") == 0) {
 | 
						if (parse_boolean(argv[0], true)) {
 | 
				
			||||||
		new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED;
 | 
							new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED;
 | 
				
			||||||
	} else if (strcasecmp(argv[0], "disabled") == 0) {
 | 
						} else {
 | 
				
			||||||
		new_config->middle_emulation =
 | 
							new_config->middle_emulation =
 | 
				
			||||||
			LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;
 | 
								LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;
 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		free_input_config(new_config);
 | 
					 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "middle_emulation",
 | 
					 | 
				
			||||||
			"Expected 'middle_emulation <enabled|disabled>'");
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	apply_input_config(new_config);
 | 
						apply_input_config(new_config);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@
 | 
				
			||||||
#include "sway/config.h"
 | 
					#include "sway/config.h"
 | 
				
			||||||
#include "sway/commands.h"
 | 
					#include "sway/commands.h"
 | 
				
			||||||
#include "sway/input/input-manager.h"
 | 
					#include "sway/input/input-manager.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) {
 | 
					struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error = NULL;
 | 
						struct cmd_results *error = NULL;
 | 
				
			||||||
| 
						 | 
					@ -18,15 +19,7 @@ struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) {
 | 
				
			||||||
	struct input_config *new_config =
 | 
						struct input_config *new_config =
 | 
				
			||||||
		new_input_config(current_input_config->identifier);
 | 
							new_input_config(current_input_config->identifier);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcasecmp(argv[0], "enabled") == 0) {
 | 
						new_config->natural_scroll = parse_boolean(argv[0], true);
 | 
				
			||||||
		new_config->natural_scroll = 1;
 | 
					 | 
				
			||||||
	} else if (strcasecmp(argv[0], "disabled") == 0) {
 | 
					 | 
				
			||||||
		new_config->natural_scroll = 0;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		free_input_config(new_config);
 | 
					 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "natural_scroll",
 | 
					 | 
				
			||||||
			"Expected 'natural_scroll <enabled|disabled>'");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	apply_input_config(new_config);
 | 
						apply_input_config(new_config);
 | 
				
			||||||
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
						return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@
 | 
				
			||||||
#include "sway/commands.h"
 | 
					#include "sway/commands.h"
 | 
				
			||||||
#include "sway/input/input-manager.h"
 | 
					#include "sway/input/input-manager.h"
 | 
				
			||||||
#include "log.h"
 | 
					#include "log.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cmd_results *input_cmd_tap(int argc, char **argv) {
 | 
					struct cmd_results *input_cmd_tap(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error = NULL;
 | 
						struct cmd_results *error = NULL;
 | 
				
			||||||
| 
						 | 
					@ -18,14 +19,10 @@ struct cmd_results *input_cmd_tap(int argc, char **argv) {
 | 
				
			||||||
	struct input_config *new_config =
 | 
						struct input_config *new_config =
 | 
				
			||||||
		new_input_config(current_input_config->identifier);
 | 
							new_input_config(current_input_config->identifier);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcasecmp(argv[0], "enabled") == 0) {
 | 
						if (parse_boolean(argv[0], true)) {
 | 
				
			||||||
		new_config->tap = LIBINPUT_CONFIG_TAP_ENABLED;
 | 
							new_config->tap = LIBINPUT_CONFIG_TAP_ENABLED;
 | 
				
			||||||
	} else if (strcasecmp(argv[0], "disabled") == 0) {
 | 
					 | 
				
			||||||
		new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED;
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		free_input_config(new_config);
 | 
							new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED;
 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "tap",
 | 
					 | 
				
			||||||
			"Expected 'tap <enabled|disabled>'");
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wlr_log(WLR_DEBUG, "apply-tap for device: %s",
 | 
						wlr_log(WLR_DEBUG, "apply-tap for device: %s",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
#include "sway/commands.h"
 | 
					#include "sway/commands.h"
 | 
				
			||||||
#include "sway/config.h"
 | 
					#include "sway/config.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cmd_results *output_cmd_dpms(int argc, char **argv) {
 | 
					struct cmd_results *output_cmd_dpms(int argc, char **argv) {
 | 
				
			||||||
	if (!config->handler_context.output_config) {
 | 
						if (!config->handler_context.output_config) {
 | 
				
			||||||
| 
						 | 
					@ -9,13 +10,10 @@ struct cmd_results *output_cmd_dpms(int argc, char **argv) {
 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "output", "Missing dpms argument.");
 | 
							return cmd_results_new(CMD_INVALID, "output", "Missing dpms argument.");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcmp(*argv, "on") == 0) {
 | 
						if (parse_boolean(argv[0], true)) {
 | 
				
			||||||
		config->handler_context.output_config->dpms_state = DPMS_ON;
 | 
							config->handler_context.output_config->dpms_state = DPMS_ON;
 | 
				
			||||||
	} else if (strcmp(*argv, "off") == 0) {
 | 
					 | 
				
			||||||
		config->handler_context.output_config->dpms_state = DPMS_OFF;
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "output",
 | 
							config->handler_context.output_config->dpms_state = DPMS_OFF;
 | 
				
			||||||
				"Invalid dpms state, valid states are on/off.");
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	config->handler_context.leftovers.argc = argc - 1;
 | 
						config->handler_context.leftovers.argc = argc - 1;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@
 | 
				
			||||||
#include "list.h"
 | 
					#include "list.h"
 | 
				
			||||||
#include "log.h"
 | 
					#include "log.h"
 | 
				
			||||||
#include "stringop.h"
 | 
					#include "stringop.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void rebuild_marks_iterator(struct sway_container *con, void *data) {
 | 
					static void rebuild_marks_iterator(struct sway_container *con, void *data) {
 | 
				
			||||||
	if (con->type == C_VIEW) {
 | 
						if (con->type == C_VIEW) {
 | 
				
			||||||
| 
						 | 
					@ -20,14 +21,7 @@ struct cmd_results *cmd_show_marks(int argc, char **argv) {
 | 
				
			||||||
		return error;
 | 
							return error;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcmp(*argv, "yes") == 0) {
 | 
						config->show_marks = parse_boolean(argv[0], config->show_marks);
 | 
				
			||||||
		config->show_marks = true;
 | 
					 | 
				
			||||||
	} else if (strcmp(*argv, "no") == 0) {
 | 
					 | 
				
			||||||
		config->show_marks = false;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "show_marks",
 | 
					 | 
				
			||||||
				"Expected 'show_marks <yes|no>'");
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (config->show_marks) {
 | 
						if (config->show_marks) {
 | 
				
			||||||
		container_for_each_descendant_dfs(&root_container,
 | 
							container_for_each_descendant_dfs(&root_container,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@
 | 
				
			||||||
#include "sway/tree/container.h"
 | 
					#include "sway/tree/container.h"
 | 
				
			||||||
#include "sway/tree/view.h"
 | 
					#include "sway/tree/view.h"
 | 
				
			||||||
#include "sway/tree/layout.h"
 | 
					#include "sway/tree/layout.h"
 | 
				
			||||||
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct cmd_results *cmd_urgent(int argc, char **argv) {
 | 
					struct cmd_results *cmd_urgent(int argc, char **argv) {
 | 
				
			||||||
	struct cmd_results *error = NULL;
 | 
						struct cmd_results *error = NULL;
 | 
				
			||||||
| 
						 | 
					@ -19,17 +20,12 @@ struct cmd_results *cmd_urgent(int argc, char **argv) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	struct sway_view *view = container->sway_view;
 | 
						struct sway_view *view = container->sway_view;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcmp(argv[0], "enable") == 0) {
 | 
						if (strcmp(argv[0], "allow") == 0) {
 | 
				
			||||||
		view_set_urgent(view, true);
 | 
					 | 
				
			||||||
	} else if (strcmp(argv[0], "disable") == 0) {
 | 
					 | 
				
			||||||
		view_set_urgent(view, false);
 | 
					 | 
				
			||||||
	} else if (strcmp(argv[0], "allow") == 0) {
 | 
					 | 
				
			||||||
		view->allow_request_urgent = true;
 | 
							view->allow_request_urgent = true;
 | 
				
			||||||
	} else if (strcmp(argv[0], "deny") == 0) {
 | 
						} else if (strcmp(argv[0], "deny") == 0) {
 | 
				
			||||||
		view->allow_request_urgent = false;
 | 
							view->allow_request_urgent = false;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return cmd_results_new(CMD_INVALID, "urgent",
 | 
							view_set_urgent(view, parse_boolean(argv[0], view_is_urgent(view)));
 | 
				
			||||||
				"Expected 'urgent <enable|disable|allow|deny>'");
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
						return cmd_results_new(CMD_SUCCESS, NULL, NULL);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -107,6 +107,87 @@ static bool workspace_valid_on_output(const char *output_name,
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void workspace_name_from_binding(const struct sway_binding * binding,
 | 
				
			||||||
 | 
							const char* output_name, int *min_order, char **earliest_name) {
 | 
				
			||||||
 | 
						char *cmdlist = strdup(binding->command);
 | 
				
			||||||
 | 
						char *dup = cmdlist;
 | 
				
			||||||
 | 
						char *name = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// workspace n
 | 
				
			||||||
 | 
						char *cmd = argsep(&cmdlist, " ");
 | 
				
			||||||
 | 
						if (cmdlist) {
 | 
				
			||||||
 | 
							name = argsep(&cmdlist, ",;");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (strcmp("workspace", cmd) == 0 && name) {
 | 
				
			||||||
 | 
							char *_target = strdup(name);
 | 
				
			||||||
 | 
							_target = do_var_replacement(_target);
 | 
				
			||||||
 | 
							strip_quotes(_target);
 | 
				
			||||||
 | 
							while (isspace(*_target)) {
 | 
				
			||||||
 | 
								memmove(_target, _target+1, strlen(_target+1));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							wlr_log(WLR_DEBUG, "Got valid workspace command for target: '%s'",
 | 
				
			||||||
 | 
									_target);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Make sure that the command references an actual workspace
 | 
				
			||||||
 | 
							// not a command about workspaces
 | 
				
			||||||
 | 
							if (strcmp(_target, "next") == 0 ||
 | 
				
			||||||
 | 
									strcmp(_target, "prev") == 0 ||
 | 
				
			||||||
 | 
									strcmp(_target, "next_on_output") == 0 ||
 | 
				
			||||||
 | 
									strcmp(_target, "prev_on_output") == 0 ||
 | 
				
			||||||
 | 
									strcmp(_target, "number") == 0 ||
 | 
				
			||||||
 | 
									strcmp(_target, "back_and_forth") == 0 ||
 | 
				
			||||||
 | 
									strcmp(_target, "current") == 0) {
 | 
				
			||||||
 | 
								free(_target);
 | 
				
			||||||
 | 
								free(dup);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// If the command is workspace number <name>, isolate the name
 | 
				
			||||||
 | 
							if (strncmp(_target, "number ", strlen("number ")) == 0) {
 | 
				
			||||||
 | 
								size_t length = strlen(_target) - strlen("number ") + 1;
 | 
				
			||||||
 | 
								char *temp = malloc(length);
 | 
				
			||||||
 | 
								strncpy(temp, _target + strlen("number "), length - 1);
 | 
				
			||||||
 | 
								temp[length - 1] = '\0';
 | 
				
			||||||
 | 
								free(_target);
 | 
				
			||||||
 | 
								_target = temp;
 | 
				
			||||||
 | 
								wlr_log(WLR_DEBUG, "Isolated name from workspace number: '%s'", _target);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Make sure the workspace number doesn't already exist
 | 
				
			||||||
 | 
								if (workspace_by_number(_target)) {
 | 
				
			||||||
 | 
									free(_target);
 | 
				
			||||||
 | 
									free(dup);
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Make sure that the workspace doesn't already exist
 | 
				
			||||||
 | 
							if (workspace_by_name(_target)) {
 | 
				
			||||||
 | 
								free(_target);
 | 
				
			||||||
 | 
								free(dup);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// make sure that the workspace can appear on the given
 | 
				
			||||||
 | 
							// output
 | 
				
			||||||
 | 
							if (!workspace_valid_on_output(output_name, _target)) {
 | 
				
			||||||
 | 
								free(_target);
 | 
				
			||||||
 | 
								free(dup);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (binding->order < *min_order) {
 | 
				
			||||||
 | 
								*min_order = binding->order;
 | 
				
			||||||
 | 
								free(*earliest_name);
 | 
				
			||||||
 | 
								*earliest_name = _target;
 | 
				
			||||||
 | 
								wlr_log(WLR_DEBUG, "Workspace: Found free name %s", _target);
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								free(_target);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						free(dup);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *workspace_next_name(const char *output_name) {
 | 
					char *workspace_next_name(const char *output_name) {
 | 
				
			||||||
	wlr_log(WLR_DEBUG, "Workspace: Generating new workspace name for output %s",
 | 
						wlr_log(WLR_DEBUG, "Workspace: Generating new workspace name for output %s",
 | 
				
			||||||
			output_name);
 | 
								output_name);
 | 
				
			||||||
| 
						 | 
					@ -114,89 +195,15 @@ char *workspace_next_name(const char *output_name) {
 | 
				
			||||||
	// if none are found/available then default to a number
 | 
						// if none are found/available then default to a number
 | 
				
			||||||
	struct sway_mode *mode = config->current_mode;
 | 
						struct sway_mode *mode = config->current_mode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// TODO: iterate over keycode bindings too
 | 
					 | 
				
			||||||
	int order = INT_MAX;
 | 
						int order = INT_MAX;
 | 
				
			||||||
	char *target = NULL;
 | 
						char *target = NULL;
 | 
				
			||||||
	for (int i = 0; i < mode->keysym_bindings->length; ++i) {
 | 
						for (int i = 0; i < mode->keysym_bindings->length; ++i) {
 | 
				
			||||||
		struct sway_binding *binding = mode->keysym_bindings->items[i];
 | 
							workspace_name_from_binding(mode->keysym_bindings->items[i],
 | 
				
			||||||
		char *cmdlist = strdup(binding->command);
 | 
									output_name, &order, &target);
 | 
				
			||||||
		char *dup = cmdlist;
 | 
						}
 | 
				
			||||||
		char *name = NULL;
 | 
						for (int i = 0; i < mode->keycode_bindings->length; ++i) {
 | 
				
			||||||
 | 
							workspace_name_from_binding(mode->keycode_bindings->items[i],
 | 
				
			||||||
		// workspace n
 | 
									output_name, &order, &target);
 | 
				
			||||||
		char *cmd = argsep(&cmdlist, " ");
 | 
					 | 
				
			||||||
		if (cmdlist) {
 | 
					 | 
				
			||||||
			name = argsep(&cmdlist, ",;");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (strcmp("workspace", cmd) == 0 && name) {
 | 
					 | 
				
			||||||
			char *_target = strdup(name);
 | 
					 | 
				
			||||||
			_target = do_var_replacement(_target);
 | 
					 | 
				
			||||||
			strip_quotes(_target);
 | 
					 | 
				
			||||||
			while (isspace(*_target)) {
 | 
					 | 
				
			||||||
				memmove(_target, _target+1, strlen(_target+1));
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			wlr_log(WLR_DEBUG, "Got valid workspace command for target: '%s'",
 | 
					 | 
				
			||||||
					_target);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Make sure that the command references an actual workspace
 | 
					 | 
				
			||||||
			// not a command about workspaces
 | 
					 | 
				
			||||||
			if (strcmp(_target, "next") == 0 ||
 | 
					 | 
				
			||||||
				strcmp(_target, "prev") == 0 ||
 | 
					 | 
				
			||||||
				strcmp(_target, "next_on_output") == 0 ||
 | 
					 | 
				
			||||||
				strcmp(_target, "prev_on_output") == 0 ||
 | 
					 | 
				
			||||||
				strcmp(_target, "number") == 0 ||
 | 
					 | 
				
			||||||
				strcmp(_target, "back_and_forth") == 0 ||
 | 
					 | 
				
			||||||
				strcmp(_target, "current") == 0)
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				free(_target);
 | 
					 | 
				
			||||||
				free(dup);
 | 
					 | 
				
			||||||
				continue;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// If the command is workspace number <name>, isolate the name
 | 
					 | 
				
			||||||
			if (strncmp(_target, "number ", strlen("number ")) == 0) {
 | 
					 | 
				
			||||||
				size_t length = strlen(_target) - strlen("number ") + 1;
 | 
					 | 
				
			||||||
				char *temp = malloc(length);
 | 
					 | 
				
			||||||
				strncpy(temp, _target + strlen("number "), length - 1);
 | 
					 | 
				
			||||||
				temp[length - 1] = '\0';
 | 
					 | 
				
			||||||
				free(_target);
 | 
					 | 
				
			||||||
				_target = temp;
 | 
					 | 
				
			||||||
				wlr_log(WLR_DEBUG, "Isolated name from workspace number: '%s'", _target);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				// Make sure the workspace number doesn't already exist
 | 
					 | 
				
			||||||
				if (workspace_by_number(_target)) {
 | 
					 | 
				
			||||||
					free(_target);
 | 
					 | 
				
			||||||
					free(dup);
 | 
					 | 
				
			||||||
					continue;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Make sure that the workspace doesn't already exist
 | 
					 | 
				
			||||||
			if (workspace_by_name(_target)) {
 | 
					 | 
				
			||||||
				free(_target);
 | 
					 | 
				
			||||||
				free(dup);
 | 
					 | 
				
			||||||
				continue;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// make sure that the workspace can appear on the given
 | 
					 | 
				
			||||||
			// output
 | 
					 | 
				
			||||||
			if (!workspace_valid_on_output(output_name, _target)) {
 | 
					 | 
				
			||||||
				free(_target);
 | 
					 | 
				
			||||||
				free(dup);
 | 
					 | 
				
			||||||
				continue;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (binding->order < order) {
 | 
					 | 
				
			||||||
				order = binding->order;
 | 
					 | 
				
			||||||
				free(target);
 | 
					 | 
				
			||||||
				target = _target;
 | 
					 | 
				
			||||||
				wlr_log(WLR_DEBUG, "Workspace: Found free name %s", _target);
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				free(_target);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		free(dup);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (target != NULL) {
 | 
						if (target != NULL) {
 | 
				
			||||||
		return target;
 | 
							return target;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue