diff options
author | Ryan Dwyer <RyanDwyer@users.noreply.github.com> | 2018-07-24 19:23:04 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-24 19:23:04 +1000 |
commit | e02a6718c2c7313309b45e499034d614ee6207fc (patch) | |
tree | 429de47906f0ba1f114689c48cbabc5be8bb6e71 | |
parent | Invoke mouse bindings (diff) | |
parent | Merge pull request #2284 from frsfnrrg/resolve-workspace-name-todo (diff) | |
download | sway-e02a6718c2c7313309b45e499034d614ee6207fc.tar.gz sway-e02a6718c2c7313309b45e499034d614ee6207fc.tar.zst sway-e02a6718c2c7313309b45e499034d614ee6207fc.zip |
Merge branch 'master' into mouse-bindings
-rw-r--r-- | common/util.c | 16 | ||||
-rw-r--r-- | include/util.h | 8 | ||||
-rw-r--r-- | sway/commands/focus_follows_mouse.c | 4 | ||||
-rw-r--r-- | sway/commands/focus_wrapping.c | 12 | ||||
-rw-r--r-- | sway/commands/force_focus_wrapping.c | 8 | ||||
-rw-r--r-- | sway/commands/fullscreen.c | 14 | ||||
-rw-r--r-- | sway/commands/input/drag_lock.c | 9 | ||||
-rw-r--r-- | sway/commands/input/dwt.c | 9 | ||||
-rw-r--r-- | sway/commands/input/left_handed.c | 11 | ||||
-rw-r--r-- | sway/commands/input/middle_emulation.c | 9 | ||||
-rw-r--r-- | sway/commands/input/natural_scroll.c | 11 | ||||
-rw-r--r-- | sway/commands/input/tap.c | 9 | ||||
-rw-r--r-- | sway/commands/output/dpms.c | 8 | ||||
-rw-r--r-- | sway/commands/show_marks.c | 10 | ||||
-rw-r--r-- | sway/commands/urgent.c | 10 | ||||
-rw-r--r-- | sway/tree/workspace.c | 159 |
16 files changed, 146 insertions, 161 deletions
diff --git a/common/util.c b/common/util.c index e8a88772..467aa4b5 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -123,6 +123,22 @@ uint32_t parse_color(const char *color) { | |||
123 | return res; | 123 | return res; |
124 | } | 124 | } |
125 | 125 | ||
126 | bool parse_boolean(const char *boolean, bool current) { | ||
127 | if (strcasecmp(boolean, "1") == 0 | ||
128 | || strcasecmp(boolean, "yes") == 0 | ||
129 | || strcasecmp(boolean, "on") == 0 | ||
130 | || strcasecmp(boolean, "true") == 0 | ||
131 | || strcasecmp(boolean, "enable") == 0 | ||
132 | || strcasecmp(boolean, "enabled") == 0 | ||
133 | || strcasecmp(boolean, "active") == 0) { | ||
134 | return true; | ||
135 | } else if (strcasecmp(boolean, "toggle") == 0) { | ||
136 | return !current; | ||
137 | } | ||
138 | // All other values are false to match i3 | ||
139 | return false; | ||
140 | } | ||
141 | |||
126 | char* resolve_path(const char* path) { | 142 | char* resolve_path(const char* path) { |
127 | struct stat sb; | 143 | struct stat sb; |
128 | ssize_t r; | 144 | ssize_t r; |
diff --git a/include/util.h b/include/util.h index f68deae8..bda941ce 100644 --- a/include/util.h +++ b/include/util.h | |||
@@ -51,6 +51,14 @@ pid_t get_parent_pid(pid_t pid); | |||
51 | uint32_t parse_color(const char *color); | 51 | uint32_t parse_color(const char *color); |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Given a string that represents a boolean, return the boolean value. This | ||
55 | * function also takes in the current boolean value to support toggling. If | ||
56 | * toggling is not desired, pass in true for current so that toggling values | ||
57 | * get parsed as not true. | ||
58 | */ | ||
59 | bool parse_boolean(const char *boolean, bool current); | ||
60 | |||
61 | /** | ||
54 | * Given a path string, recurseively resolves any symlinks to their targets | 62 | * Given a path string, recurseively resolves any symlinks to their targets |
55 | * (which may be a file, directory) and returns the result. | 63 | * (which may be a file, directory) and returns the result. |
56 | * argument is returned. Caller must free the returned buffer. | 64 | * argument is returned. Caller must free the returned buffer. |
diff --git a/sway/commands/focus_follows_mouse.c b/sway/commands/focus_follows_mouse.c index 661e7852..0b0e334c 100644 --- a/sway/commands/focus_follows_mouse.c +++ b/sway/commands/focus_follows_mouse.c | |||
@@ -1,12 +1,14 @@ | |||
1 | #include <string.h> | 1 | #include <string.h> |
2 | #include <strings.h> | 2 | #include <strings.h> |
3 | #include "sway/commands.h" | 3 | #include "sway/commands.h" |
4 | #include "util.h" | ||
4 | 5 | ||
5 | struct cmd_results *cmd_focus_follows_mouse(int argc, char **argv) { | 6 | struct cmd_results *cmd_focus_follows_mouse(int argc, char **argv) { |
6 | struct cmd_results *error = NULL; | 7 | struct cmd_results *error = NULL; |
7 | if ((error = checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1))) { | 8 | if ((error = checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1))) { |
8 | return error; | 9 | return error; |
9 | } | 10 | } |
10 | config->focus_follows_mouse = !strcasecmp(argv[0], "yes"); | 11 | config->focus_follows_mouse = |
12 | parse_boolean(argv[0], config->focus_follows_mouse); | ||
11 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 13 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
12 | } | 14 | } |
diff --git a/sway/commands/focus_wrapping.c b/sway/commands/focus_wrapping.c index 0a9e0bf2..562ee4f9 100644 --- a/sway/commands/focus_wrapping.c +++ b/sway/commands/focus_wrapping.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include <strings.h> | 1 | #include <strings.h> |
2 | #include "sway/commands.h" | 2 | #include "sway/commands.h" |
3 | #include "sway/config.h" | 3 | #include "sway/config.h" |
4 | #include "util.h" | ||
4 | 5 | ||
5 | struct cmd_results *cmd_focus_wrapping(int argc, char **argv) { | 6 | struct cmd_results *cmd_focus_wrapping(int argc, char **argv) { |
6 | struct cmd_results *error = NULL; | 7 | struct cmd_results *error = NULL; |
@@ -8,15 +9,12 @@ struct cmd_results *cmd_focus_wrapping(int argc, char **argv) { | |||
8 | return error; | 9 | return error; |
9 | } | 10 | } |
10 | 11 | ||
11 | if (strcasecmp(argv[0], "no") == 0) { | 12 | if (strcasecmp(argv[0], "force") == 0) { |
12 | config->focus_wrapping = WRAP_NO; | ||
13 | } else if (strcasecmp(argv[0], "yes") == 0) { | ||
14 | config->focus_wrapping = WRAP_YES; | ||
15 | } else if (strcasecmp(argv[0], "force") == 0) { | ||
16 | config->focus_wrapping = WRAP_FORCE; | 13 | config->focus_wrapping = WRAP_FORCE; |
14 | } else if (parse_boolean(argv[0], config->focus_wrapping == WRAP_YES)) { | ||
15 | config->focus_wrapping = WRAP_YES; | ||
17 | } else { | 16 | } else { |
18 | return cmd_results_new(CMD_INVALID, "focus_wrapping", | 17 | config->focus_wrapping = WRAP_NO; |
19 | "Expected 'focus_wrapping yes|no|force'"); | ||
20 | } | 18 | } |
21 | 19 | ||
22 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 20 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
diff --git a/sway/commands/force_focus_wrapping.c b/sway/commands/force_focus_wrapping.c index bc1d067f..0892d9e9 100644 --- a/sway/commands/force_focus_wrapping.c +++ b/sway/commands/force_focus_wrapping.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include <strings.h> | 1 | #include <strings.h> |
2 | #include "sway/commands.h" | 2 | #include "sway/commands.h" |
3 | #include "sway/config.h" | 3 | #include "sway/config.h" |
4 | #include "util.h" | ||
4 | 5 | ||
5 | struct cmd_results *cmd_force_focus_wrapping(int argc, char **argv) { | 6 | struct cmd_results *cmd_force_focus_wrapping(int argc, char **argv) { |
6 | struct cmd_results *error = | 7 | struct cmd_results *error = |
@@ -9,13 +10,10 @@ struct cmd_results *cmd_force_focus_wrapping(int argc, char **argv) { | |||
9 | return error; | 10 | return error; |
10 | } | 11 | } |
11 | 12 | ||
12 | if (strcasecmp(argv[0], "no") == 0) { | 13 | if (parse_boolean(argv[0], config->focus_wrapping == WRAP_FORCE)) { |
13 | config->focus_wrapping = WRAP_YES; | ||
14 | } else if (strcasecmp(argv[0], "yes") == 0) { | ||
15 | config->focus_wrapping = WRAP_FORCE; | 14 | config->focus_wrapping = WRAP_FORCE; |
16 | } else { | 15 | } else { |
17 | return cmd_results_new(CMD_INVALID, "force_focus_wrapping", | 16 | config->focus_wrapping = WRAP_YES; |
18 | "Expected 'force_focus_wrapping yes|no'"); | ||
19 | } | 17 | } |
20 | 18 | ||
21 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 19 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
diff --git a/sway/commands/fullscreen.c b/sway/commands/fullscreen.c index 0b5beaa2..b423fd23 100644 --- a/sway/commands/fullscreen.c +++ b/sway/commands/fullscreen.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include "sway/tree/container.h" | 5 | #include "sway/tree/container.h" |
6 | #include "sway/tree/view.h" | 6 | #include "sway/tree/view.h" |
7 | #include "sway/tree/layout.h" | 7 | #include "sway/tree/layout.h" |
8 | #include "util.h" | ||
8 | 9 | ||
9 | struct cmd_results *cmd_fullscreen(int argc, char **argv) { | 10 | struct cmd_results *cmd_fullscreen(int argc, char **argv) { |
10 | struct cmd_results *error = NULL; | 11 | struct cmd_results *error = NULL; |
@@ -18,17 +19,10 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) { | |||
18 | "Only views can fullscreen"); | 19 | "Only views can fullscreen"); |
19 | } | 20 | } |
20 | struct sway_view *view = container->sway_view; | 21 | struct sway_view *view = container->sway_view; |
21 | bool wants_fullscreen; | 22 | bool wants_fullscreen = !view->is_fullscreen; |
22 | 23 | ||
23 | if (argc == 0 || strcmp(argv[0], "toggle") == 0) { | 24 | if (argc) { |
24 | wants_fullscreen = !view->is_fullscreen; | 25 | wants_fullscreen = parse_boolean(argv[0], view->is_fullscreen); |
25 | } else if (strcmp(argv[0], "enable") == 0) { | ||
26 | wants_fullscreen = true; | ||
27 | } else if (strcmp(argv[0], "disable") == 0) { | ||
28 | wants_fullscreen = false; | ||
29 | } else { | ||
30 | return cmd_results_new(CMD_INVALID, "fullscreen", | ||
31 | "Expected 'fullscreen' or 'fullscreen <enable|disable|toggle>'"); | ||
32 | } | 26 | } |
33 | 27 | ||
34 | view_set_fullscreen(view, wants_fullscreen); | 28 | view_set_fullscreen(view, wants_fullscreen); |
diff --git a/sway/commands/input/drag_lock.c b/sway/commands/input/drag_lock.c index 9e32816f..f9ddeef2 100644 --- a/sway/commands/input/drag_lock.c +++ b/sway/commands/input/drag_lock.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include "sway/config.h" | 3 | #include "sway/config.h" |
4 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
5 | #include "sway/input/input-manager.h" | 5 | #include "sway/input/input-manager.h" |
6 | #include "util.h" | ||
6 | 7 | ||
7 | struct cmd_results *input_cmd_drag_lock(int argc, char **argv) { | 8 | struct cmd_results *input_cmd_drag_lock(int argc, char **argv) { |
8 | struct cmd_results *error = NULL; | 9 | struct cmd_results *error = NULL; |
@@ -18,14 +19,10 @@ struct cmd_results *input_cmd_drag_lock(int argc, char **argv) { | |||
18 | struct input_config *new_config = | 19 | struct input_config *new_config = |
19 | new_input_config(current_input_config->identifier); | 20 | new_input_config(current_input_config->identifier); |
20 | 21 | ||
21 | if (strcasecmp(argv[0], "enabled") == 0) { | 22 | if (parse_boolean(argv[0], true)) { |
22 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; | 23 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; |
23 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
24 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; | ||
25 | } else { | 24 | } else { |
26 | free_input_config(new_config); | 25 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; |
27 | return cmd_results_new(CMD_INVALID, "drag_lock", | ||
28 | "Expected 'drag_lock <enabled|disabled>'"); | ||
29 | } | 26 | } |
30 | 27 | ||
31 | apply_input_config(new_config); | 28 | apply_input_config(new_config); |
diff --git a/sway/commands/input/dwt.c b/sway/commands/input/dwt.c index 73937507..15134268 100644 --- a/sway/commands/input/dwt.c +++ b/sway/commands/input/dwt.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include "sway/config.h" | 3 | #include "sway/config.h" |
4 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
5 | #include "sway/input/input-manager.h" | 5 | #include "sway/input/input-manager.h" |
6 | #include "util.h" | ||
6 | 7 | ||
7 | struct cmd_results *input_cmd_dwt(int argc, char **argv) { | 8 | struct cmd_results *input_cmd_dwt(int argc, char **argv) { |
8 | struct cmd_results *error = NULL; | 9 | struct cmd_results *error = NULL; |
@@ -17,14 +18,10 @@ struct cmd_results *input_cmd_dwt(int argc, char **argv) { | |||
17 | struct input_config *new_config = | 18 | struct input_config *new_config = |
18 | new_input_config(current_input_config->identifier); | 19 | new_input_config(current_input_config->identifier); |
19 | 20 | ||
20 | if (strcasecmp(argv[0], "enabled") == 0) { | 21 | if (parse_boolean(argv[0], true)) { |
21 | new_config->dwt = LIBINPUT_CONFIG_DWT_ENABLED; | 22 | new_config->dwt = LIBINPUT_CONFIG_DWT_ENABLED; |
22 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
23 | new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED; | ||
24 | } else { | 23 | } else { |
25 | free_input_config(new_config); | 24 | new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED; |
26 | return cmd_results_new(CMD_INVALID, "dwt", | ||
27 | "Expected 'dwt <enabled|disabled>'"); | ||
28 | } | 25 | } |
29 | 26 | ||
30 | apply_input_config(new_config); | 27 | apply_input_config(new_config); |
diff --git a/sway/commands/input/left_handed.c b/sway/commands/input/left_handed.c index 769ce98c..e770043a 100644 --- a/sway/commands/input/left_handed.c +++ b/sway/commands/input/left_handed.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include "sway/config.h" | 3 | #include "sway/config.h" |
4 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
5 | #include "sway/input/input-manager.h" | 5 | #include "sway/input/input-manager.h" |
6 | #include "util.h" | ||
6 | 7 | ||
7 | struct cmd_results *input_cmd_left_handed(int argc, char **argv) { | 8 | struct cmd_results *input_cmd_left_handed(int argc, char **argv) { |
8 | struct cmd_results *error = NULL; | 9 | struct cmd_results *error = NULL; |
@@ -18,15 +19,7 @@ struct cmd_results *input_cmd_left_handed(int argc, char **argv) { | |||
18 | struct input_config *new_config = | 19 | struct input_config *new_config = |
19 | new_input_config(current_input_config->identifier); | 20 | new_input_config(current_input_config->identifier); |
20 | 21 | ||
21 | if (strcasecmp(argv[0], "enabled") == 0) { | 22 | new_config->left_handed = parse_boolean(argv[0], true); |
22 | new_config->left_handed = 1; | ||
23 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
24 | new_config->left_handed = 0; | ||
25 | } else { | ||
26 | free_input_config(new_config); | ||
27 | return cmd_results_new(CMD_INVALID, "left_handed", | ||
28 | "Expected 'left_handed <enabled|disabled>'"); | ||
29 | } | ||
30 | 23 | ||
31 | apply_input_config(new_config); | 24 | apply_input_config(new_config); |
32 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 25 | 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 7ca01629..414d4d2b 100644 --- a/sway/commands/input/middle_emulation.c +++ b/sway/commands/input/middle_emulation.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include "sway/config.h" | 3 | #include "sway/config.h" |
4 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
5 | #include "sway/input/input-manager.h" | 5 | #include "sway/input/input-manager.h" |
6 | #include "util.h" | ||
6 | 7 | ||
7 | struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) { | 8 | struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) { |
8 | struct cmd_results *error = NULL; | 9 | struct cmd_results *error = NULL; |
@@ -18,15 +19,11 @@ struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) { | |||
18 | struct input_config *new_config = | 19 | struct input_config *new_config = |
19 | new_input_config(current_input_config->identifier); | 20 | new_input_config(current_input_config->identifier); |
20 | 21 | ||
21 | if (strcasecmp(argv[0], "enabled") == 0) { | 22 | if (parse_boolean(argv[0], true)) { |
22 | new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; | 23 | new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; |
23 | } else if (strcasecmp(argv[0], "disabled") == 0) { | 24 | } else { |
24 | new_config->middle_emulation = | 25 | new_config->middle_emulation = |
25 | LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; | 26 | LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; |
26 | } else { | ||
27 | free_input_config(new_config); | ||
28 | return cmd_results_new(CMD_INVALID, "middle_emulation", | ||
29 | "Expected 'middle_emulation <enabled|disabled>'"); | ||
30 | } | 27 | } |
31 | 28 | ||
32 | apply_input_config(new_config); | 29 | apply_input_config(new_config); |
diff --git a/sway/commands/input/natural_scroll.c b/sway/commands/input/natural_scroll.c index 55236790..77c3ff00 100644 --- a/sway/commands/input/natural_scroll.c +++ b/sway/commands/input/natural_scroll.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include "sway/config.h" | 3 | #include "sway/config.h" |
4 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
5 | #include "sway/input/input-manager.h" | 5 | #include "sway/input/input-manager.h" |
6 | #include "util.h" | ||
6 | 7 | ||
7 | struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { | 8 | struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { |
8 | struct cmd_results *error = NULL; | 9 | struct cmd_results *error = NULL; |
@@ -18,15 +19,7 @@ struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { | |||
18 | struct input_config *new_config = | 19 | struct input_config *new_config = |
19 | new_input_config(current_input_config->identifier); | 20 | new_input_config(current_input_config->identifier); |
20 | 21 | ||
21 | if (strcasecmp(argv[0], "enabled") == 0) { | 22 | new_config->natural_scroll = parse_boolean(argv[0], true); |
22 | new_config->natural_scroll = 1; | ||
23 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
24 | new_config->natural_scroll = 0; | ||
25 | } else { | ||
26 | free_input_config(new_config); | ||
27 | return cmd_results_new(CMD_INVALID, "natural_scroll", | ||
28 | "Expected 'natural_scroll <enabled|disabled>'"); | ||
29 | } | ||
30 | 23 | ||
31 | apply_input_config(new_config); | 24 | apply_input_config(new_config); |
32 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
diff --git a/sway/commands/input/tap.c b/sway/commands/input/tap.c index a8d1a10c..ac3b8237 100644 --- a/sway/commands/input/tap.c +++ b/sway/commands/input/tap.c | |||
@@ -4,6 +4,7 @@ | |||
4 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
5 | #include "sway/input/input-manager.h" | 5 | #include "sway/input/input-manager.h" |
6 | #include "log.h" | 6 | #include "log.h" |
7 | #include "util.h" | ||
7 | 8 | ||
8 | struct cmd_results *input_cmd_tap(int argc, char **argv) { | 9 | struct cmd_results *input_cmd_tap(int argc, char **argv) { |
9 | struct cmd_results *error = NULL; | 10 | struct cmd_results *error = NULL; |
@@ -18,14 +19,10 @@ struct cmd_results *input_cmd_tap(int argc, char **argv) { | |||
18 | struct input_config *new_config = | 19 | struct input_config *new_config = |
19 | new_input_config(current_input_config->identifier); | 20 | new_input_config(current_input_config->identifier); |
20 | 21 | ||
21 | if (strcasecmp(argv[0], "enabled") == 0) { | 22 | if (parse_boolean(argv[0], true)) { |
22 | new_config->tap = LIBINPUT_CONFIG_TAP_ENABLED; | 23 | new_config->tap = LIBINPUT_CONFIG_TAP_ENABLED; |
23 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
24 | new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED; | ||
25 | } else { | 24 | } else { |
26 | free_input_config(new_config); | 25 | new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED; |
27 | return cmd_results_new(CMD_INVALID, "tap", | ||
28 | "Expected 'tap <enabled|disabled>'"); | ||
29 | } | 26 | } |
30 | 27 | ||
31 | wlr_log(WLR_DEBUG, "apply-tap for device: %s", | 28 | wlr_log(WLR_DEBUG, "apply-tap for device: %s", |
diff --git a/sway/commands/output/dpms.c b/sway/commands/output/dpms.c index 0959ea6b..3492061e 100644 --- a/sway/commands/output/dpms.c +++ b/sway/commands/output/dpms.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include "sway/commands.h" | 1 | #include "sway/commands.h" |
2 | #include "sway/config.h" | 2 | #include "sway/config.h" |
3 | #include "util.h" | ||
3 | 4 | ||
4 | struct cmd_results *output_cmd_dpms(int argc, char **argv) { | 5 | struct cmd_results *output_cmd_dpms(int argc, char **argv) { |
5 | if (!config->handler_context.output_config) { | 6 | if (!config->handler_context.output_config) { |
@@ -9,13 +10,10 @@ struct cmd_results *output_cmd_dpms(int argc, char **argv) { | |||
9 | return cmd_results_new(CMD_INVALID, "output", "Missing dpms argument."); | 10 | return cmd_results_new(CMD_INVALID, "output", "Missing dpms argument."); |
10 | } | 11 | } |
11 | 12 | ||
12 | if (strcmp(*argv, "on") == 0) { | 13 | if (parse_boolean(argv[0], true)) { |
13 | config->handler_context.output_config->dpms_state = DPMS_ON; | 14 | config->handler_context.output_config->dpms_state = DPMS_ON; |
14 | } else if (strcmp(*argv, "off") == 0) { | ||
15 | config->handler_context.output_config->dpms_state = DPMS_OFF; | ||
16 | } else { | 15 | } else { |
17 | return cmd_results_new(CMD_INVALID, "output", | 16 | config->handler_context.output_config->dpms_state = DPMS_OFF; |
18 | "Invalid dpms state, valid states are on/off."); | ||
19 | } | 17 | } |
20 | 18 | ||
21 | config->handler_context.leftovers.argc = argc - 1; | 19 | config->handler_context.leftovers.argc = argc - 1; |
diff --git a/sway/commands/show_marks.c b/sway/commands/show_marks.c index c7fdc538..434a0e27 100644 --- a/sway/commands/show_marks.c +++ b/sway/commands/show_marks.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include "list.h" | 7 | #include "list.h" |
8 | #include "log.h" | 8 | #include "log.h" |
9 | #include "stringop.h" | 9 | #include "stringop.h" |
10 | #include "util.h" | ||
10 | 11 | ||
11 | static void rebuild_marks_iterator(struct sway_container *con, void *data) { | 12 | static void rebuild_marks_iterator(struct sway_container *con, void *data) { |
12 | if (con->type == C_VIEW) { | 13 | if (con->type == C_VIEW) { |
@@ -20,14 +21,7 @@ struct cmd_results *cmd_show_marks(int argc, char **argv) { | |||
20 | return error; | 21 | return error; |
21 | } | 22 | } |
22 | 23 | ||
23 | if (strcmp(*argv, "yes") == 0) { | 24 | config->show_marks = parse_boolean(argv[0], config->show_marks); |
24 | config->show_marks = true; | ||
25 | } else if (strcmp(*argv, "no") == 0) { | ||
26 | config->show_marks = false; | ||
27 | } else { | ||
28 | return cmd_results_new(CMD_INVALID, "show_marks", | ||
29 | "Expected 'show_marks <yes|no>'"); | ||
30 | } | ||
31 | 25 | ||
32 | if (config->show_marks) { | 26 | if (config->show_marks) { |
33 | container_for_each_descendant_dfs(&root_container, | 27 | container_for_each_descendant_dfs(&root_container, |
diff --git a/sway/commands/urgent.c b/sway/commands/urgent.c index d199858a..51c497c4 100644 --- a/sway/commands/urgent.c +++ b/sway/commands/urgent.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include "sway/tree/container.h" | 5 | #include "sway/tree/container.h" |
6 | #include "sway/tree/view.h" | 6 | #include "sway/tree/view.h" |
7 | #include "sway/tree/layout.h" | 7 | #include "sway/tree/layout.h" |
8 | #include "util.h" | ||
8 | 9 | ||
9 | struct cmd_results *cmd_urgent(int argc, char **argv) { | 10 | struct cmd_results *cmd_urgent(int argc, char **argv) { |
10 | struct cmd_results *error = NULL; | 11 | struct cmd_results *error = NULL; |
@@ -19,17 +20,12 @@ struct cmd_results *cmd_urgent(int argc, char **argv) { | |||
19 | } | 20 | } |
20 | struct sway_view *view = container->sway_view; | 21 | struct sway_view *view = container->sway_view; |
21 | 22 | ||
22 | if (strcmp(argv[0], "enable") == 0) { | 23 | if (strcmp(argv[0], "allow") == 0) { |
23 | view_set_urgent(view, true); | ||
24 | } else if (strcmp(argv[0], "disable") == 0) { | ||
25 | view_set_urgent(view, false); | ||
26 | } else if (strcmp(argv[0], "allow") == 0) { | ||
27 | view->allow_request_urgent = true; | 24 | view->allow_request_urgent = true; |
28 | } else if (strcmp(argv[0], "deny") == 0) { | 25 | } else if (strcmp(argv[0], "deny") == 0) { |
29 | view->allow_request_urgent = false; | 26 | view->allow_request_urgent = false; |
30 | } else { | 27 | } else { |
31 | return cmd_results_new(CMD_INVALID, "urgent", | 28 | view_set_urgent(view, parse_boolean(argv[0], view_is_urgent(view))); |
32 | "Expected 'urgent <enable|disable|allow|deny>'"); | ||
33 | } | 29 | } |
34 | 30 | ||
35 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 31 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 622f01ec..e450b87f 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -107,96 +107,103 @@ static bool workspace_valid_on_output(const char *output_name, | |||
107 | return true; | 107 | return true; |
108 | } | 108 | } |
109 | 109 | ||
110 | char *workspace_next_name(const char *output_name) { | 110 | static void workspace_name_from_binding(const struct sway_binding * binding, |
111 | wlr_log(WLR_DEBUG, "Workspace: Generating new workspace name for output %s", | 111 | const char* output_name, int *min_order, char **earliest_name) { |
112 | output_name); | 112 | char *cmdlist = strdup(binding->command); |
113 | // Scan all workspace bindings to find the next available workspace name, | 113 | char *dup = cmdlist; |
114 | // if none are found/available then default to a number | 114 | char *name = NULL; |
115 | struct sway_mode *mode = config->current_mode; | 115 | |
116 | 116 | // workspace n | |
117 | // TODO: iterate over keycode bindings too | 117 | char *cmd = argsep(&cmdlist, " "); |
118 | int order = INT_MAX; | 118 | if (cmdlist) { |
119 | char *target = NULL; | 119 | name = argsep(&cmdlist, ",;"); |
120 | for (int i = 0; i < mode->keysym_bindings->length; ++i) { | 120 | } |
121 | struct sway_binding *binding = mode->keysym_bindings->items[i]; | 121 | |
122 | char *cmdlist = strdup(binding->command); | 122 | if (strcmp("workspace", cmd) == 0 && name) { |
123 | char *dup = cmdlist; | 123 | char *_target = strdup(name); |
124 | char *name = NULL; | 124 | _target = do_var_replacement(_target); |
125 | 125 | strip_quotes(_target); | |
126 | // workspace n | 126 | while (isspace(*_target)) { |
127 | char *cmd = argsep(&cmdlist, " "); | 127 | memmove(_target, _target+1, strlen(_target+1)); |
128 | if (cmdlist) { | ||
129 | name = argsep(&cmdlist, ",;"); | ||
130 | } | 128 | } |
129 | wlr_log(WLR_DEBUG, "Got valid workspace command for target: '%s'", | ||
130 | _target); | ||
131 | 131 | ||
132 | if (strcmp("workspace", cmd) == 0 && name) { | 132 | // Make sure that the command references an actual workspace |
133 | char *_target = strdup(name); | 133 | // not a command about workspaces |
134 | _target = do_var_replacement(_target); | 134 | if (strcmp(_target, "next") == 0 || |
135 | strip_quotes(_target); | ||
136 | while (isspace(*_target)) { | ||
137 | memmove(_target, _target+1, strlen(_target+1)); | ||
138 | } | ||
139 | wlr_log(WLR_DEBUG, "Got valid workspace command for target: '%s'", | ||
140 | _target); | ||
141 | |||
142 | // Make sure that the command references an actual workspace | ||
143 | // not a command about workspaces | ||
144 | if (strcmp(_target, "next") == 0 || | ||
145 | strcmp(_target, "prev") == 0 || | 135 | strcmp(_target, "prev") == 0 || |
146 | strcmp(_target, "next_on_output") == 0 || | 136 | strcmp(_target, "next_on_output") == 0 || |
147 | strcmp(_target, "prev_on_output") == 0 || | 137 | strcmp(_target, "prev_on_output") == 0 || |
148 | strcmp(_target, "number") == 0 || | 138 | strcmp(_target, "number") == 0 || |
149 | strcmp(_target, "back_and_forth") == 0 || | 139 | strcmp(_target, "back_and_forth") == 0 || |
150 | strcmp(_target, "current") == 0) | 140 | strcmp(_target, "current") == 0) { |
151 | { | 141 | free(_target); |
152 | free(_target); | 142 | free(dup); |
153 | free(dup); | 143 | return; |
154 | continue; | 144 | } |
155 | } | ||
156 | |||
157 | // If the command is workspace number <name>, isolate the name | ||
158 | if (strncmp(_target, "number ", strlen("number ")) == 0) { | ||
159 | size_t length = strlen(_target) - strlen("number ") + 1; | ||
160 | char *temp = malloc(length); | ||
161 | strncpy(temp, _target + strlen("number "), length - 1); | ||
162 | temp[length - 1] = '\0'; | ||
163 | free(_target); | ||
164 | _target = temp; | ||
165 | wlr_log(WLR_DEBUG, "Isolated name from workspace number: '%s'", _target); | ||
166 | |||
167 | // Make sure the workspace number doesn't already exist | ||
168 | if (workspace_by_number(_target)) { | ||
169 | free(_target); | ||
170 | free(dup); | ||
171 | continue; | ||
172 | } | ||
173 | } | ||
174 | 145 | ||
175 | // Make sure that the workspace doesn't already exist | 146 | // If the command is workspace number <name>, isolate the name |
176 | if (workspace_by_name(_target)) { | 147 | if (strncmp(_target, "number ", strlen("number ")) == 0) { |
148 | size_t length = strlen(_target) - strlen("number ") + 1; | ||
149 | char *temp = malloc(length); | ||
150 | strncpy(temp, _target + strlen("number "), length - 1); | ||
151 | temp[length - 1] = '\0'; | ||
152 | free(_target); | ||
153 | _target = temp; | ||
154 | wlr_log(WLR_DEBUG, "Isolated name from workspace number: '%s'", _target); | ||
155 | |||
156 | // Make sure the workspace number doesn't already exist | ||
157 | if (workspace_by_number(_target)) { | ||
177 | free(_target); | 158 | free(_target); |
178 | free(dup); | 159 | free(dup); |
179 | continue; | 160 | return; |
180 | } | 161 | } |
162 | } | ||
181 | 163 | ||
182 | // make sure that the workspace can appear on the given | 164 | // Make sure that the workspace doesn't already exist |
183 | // output | 165 | if (workspace_by_name(_target)) { |
184 | if (!workspace_valid_on_output(output_name, _target)) { | 166 | free(_target); |
185 | free(_target); | 167 | free(dup); |
186 | free(dup); | 168 | return; |
187 | continue; | 169 | } |
188 | } | ||
189 | 170 | ||
190 | if (binding->order < order) { | 171 | // make sure that the workspace can appear on the given |
191 | order = binding->order; | 172 | // output |
192 | free(target); | 173 | if (!workspace_valid_on_output(output_name, _target)) { |
193 | target = _target; | 174 | free(_target); |
194 | wlr_log(WLR_DEBUG, "Workspace: Found free name %s", _target); | 175 | free(dup); |
195 | } else { | 176 | return; |
196 | free(_target); | ||
197 | } | ||
198 | } | 177 | } |
199 | free(dup); | 178 | |
179 | if (binding->order < *min_order) { | ||
180 | *min_order = binding->order; | ||
181 | free(*earliest_name); | ||
182 | *earliest_name = _target; | ||
183 | wlr_log(WLR_DEBUG, "Workspace: Found free name %s", _target); | ||
184 | } else { | ||
185 | free(_target); | ||
186 | } | ||
187 | } | ||
188 | free(dup); | ||
189 | } | ||
190 | |||
191 | char *workspace_next_name(const char *output_name) { | ||
192 | wlr_log(WLR_DEBUG, "Workspace: Generating new workspace name for output %s", | ||
193 | output_name); | ||
194 | // Scan all workspace bindings to find the next available workspace name, | ||
195 | // if none are found/available then default to a number | ||
196 | struct sway_mode *mode = config->current_mode; | ||
197 | |||
198 | int order = INT_MAX; | ||
199 | char *target = NULL; | ||
200 | for (int i = 0; i < mode->keysym_bindings->length; ++i) { | ||
201 | workspace_name_from_binding(mode->keysym_bindings->items[i], | ||
202 | output_name, &order, &target); | ||
203 | } | ||
204 | for (int i = 0; i < mode->keycode_bindings->length; ++i) { | ||
205 | workspace_name_from_binding(mode->keycode_bindings->items[i], | ||
206 | output_name, &order, &target); | ||
200 | } | 207 | } |
201 | if (target != NULL) { | 208 | if (target != NULL) { |
202 | return target; | 209 | return target; |