diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-11-18 11:22:02 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-11-18 11:22:02 -0500 |
commit | 733993a651c71f7e2198d505960d6bbd31e0e107 (patch) | |
tree | e51732c5872b624e73355f9e5b3f762101f3cd0d /sway/commands | |
parent | Initial (awful) pass on xdg shell support (diff) | |
download | sway-733993a651c71f7e2198d505960d6bbd31e0e107.tar.gz sway-733993a651c71f7e2198d505960d6bbd31e0e107.tar.zst sway-733993a651c71f7e2198d505960d6bbd31e0e107.zip |
Move everything to sway/old/
Diffstat (limited to 'sway/commands')
90 files changed, 0 insertions, 4706 deletions
diff --git a/sway/commands/assign.c b/sway/commands/assign.c deleted file mode 100644 index c3b03bbc..00000000 --- a/sway/commands/assign.c +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include <stdio.h> | ||
3 | #include <string.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/criteria.h" | ||
6 | #include "list.h" | ||
7 | #include "log.h" | ||
8 | |||
9 | struct cmd_results *cmd_assign(int argc, char **argv) { | ||
10 | struct cmd_results *error = NULL; | ||
11 | if ((error = checkarg(argc, "assign", EXPECTED_AT_LEAST, 2))) { | ||
12 | return error; | ||
13 | } | ||
14 | |||
15 | char *criteria = *argv++; | ||
16 | |||
17 | if (strncmp(*argv, "→", strlen("→")) == 0) { | ||
18 | if (argc < 3) { | ||
19 | return cmd_results_new(CMD_INVALID, "assign", "Missing workspace"); | ||
20 | } | ||
21 | argv++; | ||
22 | } | ||
23 | |||
24 | char *movecmd = "move container to workspace "; | ||
25 | int arglen = strlen(movecmd) + strlen(*argv) + 1; | ||
26 | char *cmdlist = calloc(1, arglen); | ||
27 | if (!cmdlist) { | ||
28 | return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate command list"); | ||
29 | } | ||
30 | snprintf(cmdlist, arglen, "%s%s", movecmd, *argv); | ||
31 | |||
32 | struct criteria *crit = malloc(sizeof(struct criteria)); | ||
33 | if (!crit) { | ||
34 | free(cmdlist); | ||
35 | return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate criteria"); | ||
36 | } | ||
37 | crit->crit_raw = strdup(criteria); | ||
38 | crit->cmdlist = cmdlist; | ||
39 | crit->tokens = create_list(); | ||
40 | char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw); | ||
41 | |||
42 | if (err_str) { | ||
43 | error = cmd_results_new(CMD_INVALID, "assign", err_str); | ||
44 | free(err_str); | ||
45 | free_criteria(crit); | ||
46 | } else if (crit->tokens->length == 0) { | ||
47 | error = cmd_results_new(CMD_INVALID, "assign", "Found no name/value pairs in criteria"); | ||
48 | free_criteria(crit); | ||
49 | } else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) { | ||
50 | sway_log(L_DEBUG, "assign: Duplicate, skipping."); | ||
51 | free_criteria(crit); | ||
52 | } else { | ||
53 | sway_log(L_DEBUG, "assign: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist); | ||
54 | list_add(config->criteria, crit); | ||
55 | } | ||
56 | return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
57 | } | ||
diff --git a/sway/commands/bar.c b/sway/commands/bar.c deleted file mode 100644 index 04745a6e..00000000 --- a/sway/commands/bar.c +++ /dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/config.h" | ||
6 | #include "log.h" | ||
7 | #include "util.h" | ||
8 | |||
9 | struct cmd_results *cmd_bar(int argc, char **argv) { | ||
10 | struct cmd_results *error = NULL; | ||
11 | if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 1))) { | ||
12 | return error; | ||
13 | } | ||
14 | |||
15 | if (config->reading && strcmp("{", argv[0]) != 0) { | ||
16 | return cmd_results_new(CMD_INVALID, "bar", | ||
17 | "Expected '{' at start of bar config definition."); | ||
18 | } | ||
19 | |||
20 | if (!config->reading) { | ||
21 | if (argc > 1) { | ||
22 | if (strcasecmp("mode", argv[0]) == 0) { | ||
23 | return bar_cmd_mode(argc-1, argv + 1); | ||
24 | } | ||
25 | |||
26 | if (strcasecmp("hidden_state", argv[0]) == 0) { | ||
27 | return bar_cmd_hidden_state(argc-1, argv + 1); | ||
28 | } | ||
29 | } | ||
30 | |||
31 | return cmd_results_new(CMD_FAILURE, "bar", "Can only be used in config file."); | ||
32 | } | ||
33 | |||
34 | // Create new bar with default values | ||
35 | struct bar_config *bar = default_bar_config(); | ||
36 | if (!bar) { | ||
37 | return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar state"); | ||
38 | } | ||
39 | |||
40 | // set bar id | ||
41 | int i; | ||
42 | for (i = 0; i < config->bars->length; ++i) { | ||
43 | if (bar == config->bars->items[i]) { | ||
44 | const int len = 5 + numlen(i); // "bar-" + i + \0 | ||
45 | bar->id = malloc(len * sizeof(char)); | ||
46 | if (bar->id) { | ||
47 | snprintf(bar->id, len, "bar-%d", i); | ||
48 | } else { | ||
49 | return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar ID"); | ||
50 | } | ||
51 | break; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | // Set current bar | ||
56 | config->current_bar = bar; | ||
57 | sway_log(L_DEBUG, "Configuring bar %s", bar->id); | ||
58 | return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL); | ||
59 | } | ||
diff --git a/sway/commands/bar/activate_button.c b/sway/commands/bar/activate_button.c deleted file mode 100644 index 32a1d3e5..00000000 --- a/sway/commands/bar/activate_button.c +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | |||
5 | struct cmd_results *bar_cmd_activate_button(int argc, char **argv) { | ||
6 | const char *cmd_name = "activate_button"; | ||
7 | #ifndef ENABLE_TRAY | ||
8 | return cmd_results_new(CMD_INVALID, cmd_name, "Invalid %s command " | ||
9 | "%s called, but sway was compiled without tray support", | ||
10 | cmd_name, cmd_name); | ||
11 | #else | ||
12 | struct cmd_results *error = NULL; | ||
13 | if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 1))) { | ||
14 | return error; | ||
15 | } | ||
16 | |||
17 | if (!config->current_bar) { | ||
18 | return cmd_results_new(CMD_FAILURE, cmd_name, "No bar defined."); | ||
19 | } | ||
20 | |||
21 | // User should be able to prefix with 0x or whatever they want | ||
22 | config->current_bar->secondary_button = strtoul(argv[0], NULL, 0); | ||
23 | |||
24 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
25 | #endif | ||
26 | } | ||
diff --git a/sway/commands/bar/binding_mode_indicator.c b/sway/commands/bar/binding_mode_indicator.c deleted file mode 100644 index 64f5b84f..00000000 --- a/sway/commands/bar/binding_mode_indicator.c +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "binding_mode_indicator", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "binding_mode_indicator", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | if (strcasecmp("yes", argv[0]) == 0) { | ||
17 | config->current_bar->binding_mode_indicator = true; | ||
18 | sway_log(L_DEBUG, "Enabling binding mode indicator on bar: %s", config->current_bar->id); | ||
19 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
20 | config->current_bar->binding_mode_indicator = false; | ||
21 | sway_log(L_DEBUG, "Disabling binding mode indicator on bar: %s", config->current_bar->id); | ||
22 | } else { | ||
23 | error = cmd_results_new(CMD_INVALID, "binding_mode_indicator", "Invalid value %s", argv[0]); | ||
24 | return error; | ||
25 | } | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/bar/bindsym.c b/sway/commands/bar/bindsym.c deleted file mode 100644 index 5f90b51a..00000000 --- a/sway/commands/bar/bindsym.c +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/config.h" | ||
5 | #include "list.h" | ||
6 | #include "log.h" | ||
7 | #include "stringop.h" | ||
8 | |||
9 | struct cmd_results *bar_cmd_bindsym(int argc, char **argv) { | ||
10 | struct cmd_results *error = NULL; | ||
11 | if ((error = checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1))) { | ||
12 | return error; | ||
13 | } else if (!config->reading) { | ||
14 | return cmd_results_new(CMD_FAILURE, "bindsym", "Can only be used in config file."); | ||
15 | } | ||
16 | |||
17 | if (!config->current_bar) { | ||
18 | return cmd_results_new(CMD_FAILURE, "bindsym", "No bar defined."); | ||
19 | } | ||
20 | |||
21 | if (strlen(argv[1]) != 7) { | ||
22 | return cmd_results_new(CMD_INVALID, "bindsym", "Invalid mouse binding %s", argv[1]); | ||
23 | } | ||
24 | uint32_t numbutton = (uint32_t)atoi(argv[1] + 6); | ||
25 | if (numbutton < 1 || numbutton > 5 || strncmp(argv[1], "button", 6) != 0) { | ||
26 | return cmd_results_new(CMD_INVALID, "bindsym", "Invalid mouse binding %s", argv[1]); | ||
27 | } | ||
28 | struct sway_mouse_binding *binding = malloc(sizeof(struct sway_mouse_binding)); | ||
29 | if (!binding) { | ||
30 | return cmd_results_new(CMD_FAILURE, "bindsym", "Unable to allocate binding"); | ||
31 | } | ||
32 | binding->button = numbutton; | ||
33 | binding->command = join_args(argv + 1, argc - 1); | ||
34 | |||
35 | struct bar_config *bar = config->current_bar; | ||
36 | int i = list_seq_find(bar->bindings, sway_mouse_binding_cmp_buttons, binding); | ||
37 | if (i > -1) { | ||
38 | sway_log(L_DEBUG, "bindsym - '%s' for swaybar already exists, overwriting", argv[0]); | ||
39 | struct sway_mouse_binding *dup = bar->bindings->items[i]; | ||
40 | free_sway_mouse_binding(dup); | ||
41 | list_del(bar->bindings, i); | ||
42 | } | ||
43 | list_add(bar->bindings, binding); | ||
44 | list_qsort(bar->bindings, sway_mouse_binding_cmp_qsort); | ||
45 | |||
46 | sway_log(L_DEBUG, "bindsym - Bound %s to command %s when clicking swaybar", argv[0], binding->command); | ||
47 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
48 | } | ||
diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c deleted file mode 100644 index 8b3b0aac..00000000 --- a/sway/commands/bar/colors.c +++ /dev/null | |||
@@ -1,129 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | |||
4 | static struct cmd_results *parse_single_color(char **color, const char *cmd_name, int argc, char **argv) { | ||
5 | struct cmd_results *error = NULL; | ||
6 | if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 1))) { | ||
7 | return error; | ||
8 | } | ||
9 | |||
10 | if (!*color) { | ||
11 | *color = malloc(10); | ||
12 | if (!*color) { | ||
13 | return cmd_results_new(CMD_FAILURE, cmd_name, "Unable to allocate color"); | ||
14 | } | ||
15 | } | ||
16 | |||
17 | error = add_color(cmd_name, *color, argv[0]); | ||
18 | if (error) { | ||
19 | return error; | ||
20 | } | ||
21 | |||
22 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
23 | } | ||
24 | |||
25 | static struct cmd_results *parse_three_colors(char ***colors, const char *cmd_name, int argc, char **argv) { | ||
26 | struct cmd_results *error = NULL; | ||
27 | if (argc != 3) { | ||
28 | return cmd_results_new(CMD_INVALID, cmd_name, "Requires exactly three color values"); | ||
29 | } | ||
30 | |||
31 | int i; | ||
32 | for (i = 0; i < 3; i++) { | ||
33 | if (!*colors[i]) { | ||
34 | *(colors[i]) = malloc(10); | ||
35 | if (!*(colors[i])) { | ||
36 | return cmd_results_new(CMD_FAILURE, cmd_name, "Unable to allocate color"); | ||
37 | } | ||
38 | } | ||
39 | error = add_color(cmd_name, *(colors[i]), argv[i]); | ||
40 | if (error) { | ||
41 | return error; | ||
42 | } | ||
43 | } | ||
44 | |||
45 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
46 | } | ||
47 | |||
48 | struct cmd_results *bar_cmd_colors(int argc, char **argv) { | ||
49 | struct cmd_results *error = NULL; | ||
50 | if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) { | ||
51 | return error; | ||
52 | } | ||
53 | |||
54 | if (strcmp("{", argv[0]) != 0) { | ||
55 | return cmd_results_new(CMD_INVALID, "colors", | ||
56 | "Expected '{' at the start of colors config definition."); | ||
57 | } | ||
58 | |||
59 | return cmd_results_new(CMD_BLOCK_BAR_COLORS, NULL, NULL); | ||
60 | } | ||
61 | |||
62 | struct cmd_results *bar_colors_cmd_active_workspace(int argc, char **argv) { | ||
63 | char **colors[3] = { | ||
64 | &(config->current_bar->colors.active_workspace_border), | ||
65 | &(config->current_bar->colors.active_workspace_bg), | ||
66 | &(config->current_bar->colors.active_workspace_text) | ||
67 | }; | ||
68 | return parse_three_colors(colors, "active_workspace", argc, argv); | ||
69 | } | ||
70 | |||
71 | struct cmd_results *bar_colors_cmd_background(int argc, char **argv) { | ||
72 | return parse_single_color(&(config->current_bar->colors.background), "background", argc, argv); | ||
73 | } | ||
74 | |||
75 | struct cmd_results *bar_colors_cmd_focused_background(int argc, char **argv) { | ||
76 | return parse_single_color(&(config->current_bar->colors.focused_background), "focused_background", argc, argv); | ||
77 | } | ||
78 | |||
79 | struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) { | ||
80 | char **colors[3] = { | ||
81 | &(config->current_bar->colors.binding_mode_border), | ||
82 | &(config->current_bar->colors.binding_mode_bg), | ||
83 | &(config->current_bar->colors.binding_mode_text) | ||
84 | }; | ||
85 | return parse_three_colors(colors, "binding_mode", argc, argv); | ||
86 | } | ||
87 | |||
88 | struct cmd_results *bar_colors_cmd_focused_workspace(int argc, char **argv) { | ||
89 | char **colors[3] = { | ||
90 | &(config->current_bar->colors.focused_workspace_border), | ||
91 | &(config->current_bar->colors.focused_workspace_bg), | ||
92 | &(config->current_bar->colors.focused_workspace_text) | ||
93 | }; | ||
94 | return parse_three_colors(colors, "focused_workspace", argc, argv); | ||
95 | } | ||
96 | |||
97 | struct cmd_results *bar_colors_cmd_inactive_workspace(int argc, char **argv) { | ||
98 | char **colors[3] = { | ||
99 | &(config->current_bar->colors.inactive_workspace_border), | ||
100 | &(config->current_bar->colors.inactive_workspace_bg), | ||
101 | &(config->current_bar->colors.inactive_workspace_text) | ||
102 | }; | ||
103 | return parse_three_colors(colors, "inactive_workspace", argc, argv); | ||
104 | } | ||
105 | |||
106 | struct cmd_results *bar_colors_cmd_separator(int argc, char **argv) { | ||
107 | return parse_single_color(&(config->current_bar->colors.separator), "separator", argc, argv); | ||
108 | } | ||
109 | |||
110 | struct cmd_results *bar_colors_cmd_focused_separator(int argc, char **argv) { | ||
111 | return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv); | ||
112 | } | ||
113 | |||
114 | struct cmd_results *bar_colors_cmd_statusline(int argc, char **argv) { | ||
115 | return parse_single_color(&(config->current_bar->colors.statusline), "statusline", argc, argv); | ||
116 | } | ||
117 | |||
118 | struct cmd_results *bar_colors_cmd_focused_statusline(int argc, char **argv) { | ||
119 | return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv); | ||
120 | } | ||
121 | |||
122 | struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) { | ||
123 | char **colors[3] = { | ||
124 | &(config->current_bar->colors.urgent_workspace_border), | ||
125 | &(config->current_bar->colors.urgent_workspace_bg), | ||
126 | &(config->current_bar->colors.urgent_workspace_text) | ||
127 | }; | ||
128 | return parse_three_colors(colors, "urgent_workspace", argc, argv); | ||
129 | } | ||
diff --git a/sway/commands/bar/context_button.c b/sway/commands/bar/context_button.c deleted file mode 100644 index 6d7d7aec..00000000 --- a/sway/commands/bar/context_button.c +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | |||
5 | struct cmd_results *bar_cmd_context_button(int argc, char **argv) { | ||
6 | const char *cmd_name = "context_button"; | ||
7 | #ifndef ENABLE_TRAY | ||
8 | return cmd_results_new(CMD_INVALID, cmd_name, "Invalid %s command " | ||
9 | "%s called, but sway was compiled without tray support", | ||
10 | cmd_name, cmd_name); | ||
11 | #else | ||
12 | struct cmd_results *error = NULL; | ||
13 | if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 1))) { | ||
14 | return error; | ||
15 | } | ||
16 | |||
17 | if (!config->current_bar) { | ||
18 | return cmd_results_new(CMD_FAILURE, cmd_name, "No bar defined."); | ||
19 | } | ||
20 | |||
21 | // User should be able to prefix with 0x or whatever they want | ||
22 | config->current_bar->context_button = strtoul(argv[0], NULL, 0); | ||
23 | |||
24 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
25 | #endif | ||
26 | } | ||
diff --git a/sway/commands/bar/font.c b/sway/commands/bar/font.c deleted file mode 100644 index c586c5bc..00000000 --- a/sway/commands/bar/font.c +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | #include "stringop.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_font(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "font", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "font", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | char *font = join_args(argv, argc); | ||
17 | free(config->current_bar->font); | ||
18 | if (strlen(font) > 6 && strncmp("pango:", font, 6) == 0) { | ||
19 | config->current_bar->font = font; | ||
20 | } else { | ||
21 | config->current_bar->font = font; | ||
22 | } | ||
23 | |||
24 | sway_log(L_DEBUG, "Settings font '%s' for bar: %s", config->current_bar->font, config->current_bar->id); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/bar/height.c b/sway/commands/bar/height.c deleted file mode 100644 index eb576ab3..00000000 --- a/sway/commands/bar/height.c +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_height(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "height", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | int height = atoi(argv[0]); | ||
13 | if (height < 0) { | ||
14 | return cmd_results_new(CMD_INVALID, "height", | ||
15 | "Invalid height value: %s", argv[0]); | ||
16 | } | ||
17 | |||
18 | config->current_bar->height = height; | ||
19 | sway_log(L_DEBUG, "Setting bar height to %d on bar: %s", height, config->current_bar->id); | ||
20 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
21 | } | ||
diff --git a/sway/commands/bar/hidden_state.c b/sway/commands/bar/hidden_state.c deleted file mode 100644 index 0b49aa6b..00000000 --- a/sway/commands/bar/hidden_state.c +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/config.h" | ||
6 | #include "sway/ipc-server.h" | ||
7 | #include "log.h" | ||
8 | |||
9 | static struct cmd_results *bar_set_hidden_state(struct bar_config *bar, const char *hidden_state) { | ||
10 | char *old_state = bar->hidden_state; | ||
11 | if (strcasecmp("toggle", hidden_state) == 0 && !config->reading) { | ||
12 | if (strcasecmp("hide", bar->hidden_state) == 0) { | ||
13 | bar->hidden_state = strdup("show"); | ||
14 | } else if (strcasecmp("show", bar->hidden_state) == 0) { | ||
15 | bar->hidden_state = strdup("hide"); | ||
16 | } | ||
17 | } else if (strcasecmp("hide", hidden_state) == 0) { | ||
18 | bar->hidden_state = strdup("hide"); | ||
19 | } else if (strcasecmp("show", hidden_state) == 0) { | ||
20 | bar->hidden_state = strdup("show"); | ||
21 | } else { | ||
22 | return cmd_results_new(CMD_INVALID, "hidden_state", "Invalid value %s", hidden_state); | ||
23 | } | ||
24 | |||
25 | if (strcmp(old_state, bar->hidden_state) != 0) { | ||
26 | if (!config->reading) { | ||
27 | ipc_event_barconfig_update(bar); | ||
28 | } | ||
29 | sway_log(L_DEBUG, "Setting hidden_state: '%s' for bar: %s", bar->hidden_state, bar->id); | ||
30 | } | ||
31 | |||
32 | // free old mode | ||
33 | free(old_state); | ||
34 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
35 | } | ||
36 | |||
37 | struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { | ||
38 | struct cmd_results *error = NULL; | ||
39 | if ((error = checkarg(argc, "hidden_state", EXPECTED_AT_LEAST, 1))) { | ||
40 | return error; | ||
41 | } | ||
42 | if ((error = checkarg(argc, "hidden_state", EXPECTED_LESS_THAN, 3))) { | ||
43 | return error; | ||
44 | } | ||
45 | |||
46 | if (config->reading && argc > 1) { | ||
47 | return cmd_results_new(CMD_INVALID, "hidden_state", "Unexpected value %s in config mode", argv[1]); | ||
48 | } | ||
49 | |||
50 | const char *state = argv[0]; | ||
51 | |||
52 | if (config->reading) { | ||
53 | return bar_set_hidden_state(config->current_bar, state); | ||
54 | } | ||
55 | |||
56 | const char *id = NULL; | ||
57 | if (argc == 2) { | ||
58 | id = argv[1]; | ||
59 | } | ||
60 | |||
61 | int i; | ||
62 | struct bar_config *bar; | ||
63 | for (i = 0; i < config->bars->length; ++i) { | ||
64 | bar = config->bars->items[i]; | ||
65 | if (id && strcmp(id, bar->id) == 0) { | ||
66 | return bar_set_hidden_state(bar, state); | ||
67 | } | ||
68 | |||
69 | error = bar_set_hidden_state(bar, state); | ||
70 | if (error) { | ||
71 | return error; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | // active bar modifiers might have changed. | ||
76 | update_active_bar_modifiers(); | ||
77 | |||
78 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
79 | } | ||
diff --git a/sway/commands/bar/icon_theme.c b/sway/commands/bar/icon_theme.c deleted file mode 100644 index cbfc0be5..00000000 --- a/sway/commands/bar/icon_theme.c +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *bar_cmd_icon_theme(int argc, char **argv) { | ||
6 | const char *cmd_name = "tray_output"; | ||
7 | #ifndef ENABLE_TRAY | ||
8 | return cmd_results_new(CMD_INVALID, cmd_name, "Invalid %s command " | ||
9 | "%s called, but sway was compiled without tray support", | ||
10 | cmd_name, cmd_name); | ||
11 | #else | ||
12 | struct cmd_results *error = NULL; | ||
13 | if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 1))) { | ||
14 | return error; | ||
15 | } | ||
16 | |||
17 | if (!config->current_bar) { | ||
18 | return cmd_results_new(CMD_FAILURE, cmd_name, "No bar defined."); | ||
19 | } | ||
20 | |||
21 | config->current_bar->icon_theme = strdup(argv[0]); | ||
22 | |||
23 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
24 | #endif | ||
25 | } | ||
diff --git a/sway/commands/bar/id.c b/sway/commands/bar/id.c deleted file mode 100644 index 1221ebf6..00000000 --- a/sway/commands/bar/id.c +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_id(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "id", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | const char *name = argv[0]; | ||
13 | const char *oldname = config->current_bar->id; | ||
14 | |||
15 | // check if id is used by a previously defined bar | ||
16 | int i; | ||
17 | for (i = 0; i < config->bars->length; ++i) { | ||
18 | struct bar_config *find = config->bars->items[i]; | ||
19 | if (strcmp(name, find->id) == 0 && config->current_bar != find) { | ||
20 | return cmd_results_new(CMD_FAILURE, "id", | ||
21 | "Id '%s' already defined for another bar. Id unchanged (%s).", | ||
22 | name, oldname); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | sway_log(L_DEBUG, "Renaming bar: '%s' to '%s'", oldname, name); | ||
27 | |||
28 | // free old bar id | ||
29 | free(config->current_bar->id); | ||
30 | |||
31 | config->current_bar->id = strdup(name); | ||
32 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
33 | } | ||
diff --git a/sway/commands/bar/mode.c b/sway/commands/bar/mode.c deleted file mode 100644 index 36816b93..00000000 --- a/sway/commands/bar/mode.c +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/config.h" | ||
6 | #include "sway/ipc-server.h" | ||
7 | #include "log.h" | ||
8 | |||
9 | static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode) { | ||
10 | char *old_mode = bar->mode; | ||
11 | if (strcasecmp("toggle", mode) == 0 && !config->reading) { | ||
12 | if (strcasecmp("dock", bar->mode) == 0) { | ||
13 | bar->mode = strdup("hide"); | ||
14 | } else if (strcasecmp("hide", bar->mode) == 0) { | ||
15 | bar->mode = strdup("dock"); | ||
16 | } | ||
17 | } else if (strcasecmp("dock", mode) == 0) { | ||
18 | bar->mode = strdup("dock"); | ||
19 | } else if (strcasecmp("hide", mode) == 0) { | ||
20 | bar->mode = strdup("hide"); | ||
21 | } else if (strcasecmp("invisible", mode) == 0) { | ||
22 | bar->mode = strdup("invisible"); | ||
23 | } else { | ||
24 | return cmd_results_new(CMD_INVALID, "mode", "Invalid value %s", mode); | ||
25 | } | ||
26 | |||
27 | if (strcmp(old_mode, bar->mode) != 0) { | ||
28 | if (!config->reading) { | ||
29 | ipc_event_barconfig_update(bar); | ||
30 | |||
31 | // active bar modifiers might have changed. | ||
32 | update_active_bar_modifiers(); | ||
33 | } | ||
34 | sway_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id); | ||
35 | } | ||
36 | |||
37 | // free old mode | ||
38 | free(old_mode); | ||
39 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
40 | } | ||
41 | |||
42 | struct cmd_results *bar_cmd_mode(int argc, char **argv) { | ||
43 | struct cmd_results *error = NULL; | ||
44 | if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) { | ||
45 | return error; | ||
46 | } | ||
47 | if ((error = checkarg(argc, "mode", EXPECTED_LESS_THAN, 3))) { | ||
48 | return error; | ||
49 | } | ||
50 | |||
51 | if (config->reading && argc > 1) { | ||
52 | return cmd_results_new(CMD_INVALID, "mode", "Unexpected value %s in config mode", argv[1]); | ||
53 | } | ||
54 | |||
55 | const char *mode = argv[0]; | ||
56 | |||
57 | if (config->reading) { | ||
58 | return bar_set_mode(config->current_bar, mode); | ||
59 | } | ||
60 | |||
61 | const char *id = NULL; | ||
62 | if (argc == 2) { | ||
63 | id = argv[1]; | ||
64 | } | ||
65 | |||
66 | int i; | ||
67 | struct bar_config *bar; | ||
68 | for (i = 0; i < config->bars->length; ++i) { | ||
69 | bar = config->bars->items[i]; | ||
70 | if (id && strcmp(id, bar->id) == 0) { | ||
71 | return bar_set_mode(bar, mode); | ||
72 | } | ||
73 | |||
74 | error = bar_set_mode(bar, mode); | ||
75 | if (error) { | ||
76 | return error; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
81 | } | ||
diff --git a/sway/commands/bar/modifier.c b/sway/commands/bar/modifier.c deleted file mode 100644 index 153d87e6..00000000 --- a/sway/commands/bar/modifier.c +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | #include "stringop.h" | ||
5 | #include "util.h" | ||
6 | |||
7 | struct cmd_results *bar_cmd_modifier(int argc, char **argv) { | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "modifier", EXPECTED_EQUAL_TO, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | |||
13 | if (!config->current_bar) { | ||
14 | return cmd_results_new(CMD_FAILURE, "modifier", "No bar defined."); | ||
15 | } | ||
16 | |||
17 | uint32_t mod = 0; | ||
18 | |||
19 | list_t *split = split_string(argv[0], "+"); | ||
20 | for (int i = 0; i < split->length; ++i) { | ||
21 | uint32_t tmp_mod; | ||
22 | if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) { | ||
23 | mod |= tmp_mod; | ||
24 | continue; | ||
25 | } else { | ||
26 | free_flat_list(split); | ||
27 | return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", split->items[i]); | ||
28 | } | ||
29 | } | ||
30 | free_flat_list(split); | ||
31 | |||
32 | config->current_bar->modifier = mod; | ||
33 | sway_log(L_DEBUG, "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]); | ||
34 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
35 | } | ||
diff --git a/sway/commands/bar/output.c b/sway/commands/bar/output.c deleted file mode 100644 index a5710bc0..00000000 --- a/sway/commands/bar/output.c +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "list.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *bar_cmd_output(int argc, char **argv) { | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | |||
13 | if (!config->current_bar) { | ||
14 | return cmd_results_new(CMD_FAILURE, "output", "No bar defined."); | ||
15 | } | ||
16 | |||
17 | const char *output = argv[0]; | ||
18 | list_t *outputs = config->current_bar->outputs; | ||
19 | if (!outputs) { | ||
20 | outputs = create_list(); | ||
21 | config->current_bar->outputs = outputs; | ||
22 | } | ||
23 | |||
24 | int i; | ||
25 | int add_output = 1; | ||
26 | if (strcmp("*", output) == 0) { | ||
27 | // remove all previous defined outputs and replace with '*' | ||
28 | for (i = 0; i < outputs->length; ++i) { | ||
29 | free(outputs->items[i]); | ||
30 | list_del(outputs, i); | ||
31 | } | ||
32 | } else { | ||
33 | // only add output if not already defined with either the same | ||
34 | // name or as '*' | ||
35 | for (i = 0; i < outputs->length; ++i) { | ||
36 | const char *find = outputs->items[i]; | ||
37 | if (strcmp("*", find) == 0 || strcmp(output, find) == 0) { | ||
38 | add_output = 0; | ||
39 | break; | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | |||
44 | if (add_output) { | ||
45 | list_add(outputs, strdup(output)); | ||
46 | sway_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output); | ||
47 | } | ||
48 | |||
49 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
50 | } | ||
diff --git a/sway/commands/bar/pango_markup.c b/sway/commands/bar/pango_markup.c deleted file mode 100644 index f69e882f..00000000 --- a/sway/commands/bar/pango_markup.c +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "pango_markup", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "pango_markup", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | if (strcasecmp("enabled", argv[0]) == 0) { | ||
17 | config->current_bar->pango_markup = true; | ||
18 | sway_log(L_DEBUG, "Enabling pango markup for bar: %s", config->current_bar->id); | ||
19 | } else if (strcasecmp("disabled", argv[0]) == 0) { | ||
20 | config->current_bar->pango_markup = false; | ||
21 | sway_log(L_DEBUG, "Disabling pango markup for bar: %s", config->current_bar->id); | ||
22 | } else { | ||
23 | error = cmd_results_new(CMD_INVALID, "pango_markup", "Invalid value %s", argv[0]); | ||
24 | return error; | ||
25 | } | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/bar/position.c b/sway/commands/bar/position.c deleted file mode 100644 index 50de58e2..00000000 --- a/sway/commands/bar/position.c +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_position(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "position", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | if (strcasecmp("top", argv[0]) == 0) { | ||
17 | config->current_bar->position = DESKTOP_SHELL_PANEL_POSITION_TOP; | ||
18 | } else if (strcasecmp("bottom", argv[0]) == 0) { | ||
19 | config->current_bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; | ||
20 | } else if (strcasecmp("left", argv[0]) == 0) { | ||
21 | sway_log(L_INFO, "Warning: swaybar currently only supports top and bottom positioning. YMMV"); | ||
22 | config->current_bar->position = DESKTOP_SHELL_PANEL_POSITION_LEFT; | ||
23 | } else if (strcasecmp("right", argv[0]) == 0) { | ||
24 | sway_log(L_INFO, "Warning: swaybar currently only supports top and bottom positioning. YMMV"); | ||
25 | config->current_bar->position = DESKTOP_SHELL_PANEL_POSITION_RIGHT; | ||
26 | } else { | ||
27 | error = cmd_results_new(CMD_INVALID, "position", "Invalid value %s", argv[0]); | ||
28 | return error; | ||
29 | } | ||
30 | |||
31 | sway_log(L_DEBUG, "Setting bar position '%s' for bar: %s", argv[0], config->current_bar->id); | ||
32 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
33 | } | ||
diff --git a/sway/commands/bar/secondary_button.c b/sway/commands/bar/secondary_button.c deleted file mode 100644 index 745045c5..00000000 --- a/sway/commands/bar/secondary_button.c +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | |||
5 | struct cmd_results *bar_cmd_secondary_button(int argc, char **argv) { | ||
6 | const char *cmd_name = "secondary_button"; | ||
7 | #ifndef ENABLE_TRAY | ||
8 | return cmd_results_new(CMD_INVALID, cmd_name, "Invalid %s command " | ||
9 | "%s called, but sway was compiled without tray support", | ||
10 | cmd_name, cmd_name); | ||
11 | #else | ||
12 | struct cmd_results *error = NULL; | ||
13 | if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 1))) { | ||
14 | return error; | ||
15 | } | ||
16 | |||
17 | if (!config->current_bar) { | ||
18 | return cmd_results_new(CMD_FAILURE, cmd_name, "No bar defined."); | ||
19 | } | ||
20 | |||
21 | // User should be able to prefix with 0x or whatever they want | ||
22 | config->current_bar->secondary_button = strtoul(argv[0], NULL, 0); | ||
23 | |||
24 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
25 | #endif | ||
26 | } | ||
diff --git a/sway/commands/bar/separator_symbol.c b/sway/commands/bar/separator_symbol.c deleted file mode 100644 index 2766d8a2..00000000 --- a/sway/commands/bar/separator_symbol.c +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_separator_symbol(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "separator_symbol", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "separator_symbol", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | free(config->current_bar->separator_symbol); | ||
17 | config->current_bar->separator_symbol = strdup(argv[0]); | ||
18 | sway_log(L_DEBUG, "Settings separator_symbol '%s' for bar: %s", config->current_bar->separator_symbol, config->current_bar->id); | ||
19 | |||
20 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
21 | } | ||
diff --git a/sway/commands/bar/status_command.c b/sway/commands/bar/status_command.c deleted file mode 100644 index b227ac47..00000000 --- a/sway/commands/bar/status_command.c +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | #include "stringop.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_status_command(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "status_command", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "status_command", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | free(config->current_bar->status_command); | ||
17 | config->current_bar->status_command = join_args(argv, argc); | ||
18 | sway_log(L_DEBUG, "Feeding bar with status command: %s", config->current_bar->status_command); | ||
19 | |||
20 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
21 | } | ||
diff --git a/sway/commands/bar/strip_workspace_numbers.c b/sway/commands/bar/strip_workspace_numbers.c deleted file mode 100644 index 9ac32482..00000000 --- a/sway/commands/bar/strip_workspace_numbers.c +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "strip_workspace_numbers", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "strip_workspace_numbers", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | if (strcasecmp("yes", argv[0]) == 0) { | ||
17 | config->current_bar->strip_workspace_numbers = true; | ||
18 | sway_log(L_DEBUG, "Stripping workspace numbers on bar: %s", config->current_bar->id); | ||
19 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
20 | config->current_bar->strip_workspace_numbers = false; | ||
21 | sway_log(L_DEBUG, "Enabling workspace numbers on bar: %s", config->current_bar->id); | ||
22 | } else { | ||
23 | error = cmd_results_new(CMD_INVALID, "strip_workspace_numbers", "Invalid value %s", argv[0]); | ||
24 | return error; | ||
25 | } | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/bar/swaybar_command.c b/sway/commands/bar/swaybar_command.c deleted file mode 100644 index 452e2df5..00000000 --- a/sway/commands/bar/swaybar_command.c +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | #include "stringop.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_swaybar_command(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "swaybar_command", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "swaybar_command", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | free(config->current_bar->swaybar_command); | ||
17 | config->current_bar->swaybar_command = join_args(argv, argc); | ||
18 | sway_log(L_DEBUG, "Using custom swaybar command: %s", config->current_bar->swaybar_command); | ||
19 | |||
20 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
21 | } | ||
diff --git a/sway/commands/bar/tray_output.c b/sway/commands/bar/tray_output.c deleted file mode 100644 index 012304a9..00000000 --- a/sway/commands/bar/tray_output.c +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *bar_cmd_tray_output(int argc, char **argv) { | ||
6 | const char *cmd_name = "tray_output"; | ||
7 | #ifndef ENABLE_TRAY | ||
8 | return cmd_results_new(CMD_INVALID, cmd_name, "Invalid %s command " | ||
9 | "%s called, but sway was compiled without tray support", | ||
10 | cmd_name, cmd_name); | ||
11 | #else | ||
12 | struct cmd_results *error = NULL; | ||
13 | if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 1))) { | ||
14 | return error; | ||
15 | } | ||
16 | |||
17 | if (!config->current_bar) { | ||
18 | return cmd_results_new(CMD_FAILURE, cmd_name, "No bar defined."); | ||
19 | } | ||
20 | |||
21 | if (strcmp(argv[0], "all") == 0) { | ||
22 | // Default behaviour | ||
23 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
24 | } | ||
25 | config->current_bar->tray_output = strdup(argv[0]); | ||
26 | |||
27 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
28 | #endif | ||
29 | } | ||
diff --git a/sway/commands/bar/tray_padding.c b/sway/commands/bar/tray_padding.c deleted file mode 100644 index ac0572ce..00000000 --- a/sway/commands/bar/tray_padding.c +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) { | ||
7 | const char *cmd_name = "tray_padding"; | ||
8 | #ifndef ENABLE_TRAY | ||
9 | return cmd_results_new(CMD_INVALID, cmd_name, "Invalid %s command" | ||
10 | "%s called, but sway was compiled without tray support", | ||
11 | cmd_name, cmd_name); | ||
12 | #else | ||
13 | struct cmd_results *error = NULL; | ||
14 | if ((error = checkarg(argc, cmd_name, EXPECTED_AT_LEAST, 1))) { | ||
15 | return error; | ||
16 | } | ||
17 | |||
18 | if (!config->current_bar) { | ||
19 | return cmd_results_new(CMD_FAILURE, cmd_name, "No bar defined."); | ||
20 | } | ||
21 | |||
22 | if (argc == 1 || (argc == 2 && strcasecmp("px", argv[1]) == 0)) { | ||
23 | char *inv; | ||
24 | uint32_t padding = strtoul(argv[0], &inv, 10); | ||
25 | if (*inv == '\0' || strcasecmp(inv, "px") == 0) { | ||
26 | config->current_bar->tray_padding = padding; | ||
27 | sway_log(L_DEBUG, "Enabling tray padding of %d px on bar: %s", padding, config->current_bar->id); | ||
28 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
29 | } | ||
30 | } | ||
31 | return cmd_results_new(CMD_FAILURE, cmd_name, | ||
32 | "Expected 'tray_padding <padding>[px]'"); | ||
33 | #endif | ||
34 | } | ||
diff --git a/sway/commands/bar/workspace_buttons.c b/sway/commands/bar/workspace_buttons.c deleted file mode 100644 index 67dd2d31..00000000 --- a/sway/commands/bar/workspace_buttons.c +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "workspace_buttons", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "workspace_buttons", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | if (strcasecmp("yes", argv[0]) == 0) { | ||
17 | config->current_bar->workspace_buttons = true; | ||
18 | sway_log(L_DEBUG, "Enabling workspace buttons on bar: %s", config->current_bar->id); | ||
19 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
20 | config->current_bar->workspace_buttons = false; | ||
21 | sway_log(L_DEBUG, "Disabling workspace buttons on bar: %s", config->current_bar->id); | ||
22 | } else { | ||
23 | error = cmd_results_new(CMD_INVALID, "workspace_buttons", "Invalid value %s", argv[0]); | ||
24 | return error; | ||
25 | } | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/bar/wrap_scroll.c b/sway/commands/bar/wrap_scroll.c deleted file mode 100644 index 4ed1f12a..00000000 --- a/sway/commands/bar/wrap_scroll.c +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "wrap_scroll", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "wrap_scroll", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | if (strcasecmp("yes", argv[0]) == 0) { | ||
17 | config->current_bar->wrap_scroll = true; | ||
18 | sway_log(L_DEBUG, "Enabling wrap scroll on bar: %s", config->current_bar->id); | ||
19 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
20 | config->current_bar->wrap_scroll = false; | ||
21 | sway_log(L_DEBUG, "Disabling wrap scroll on bar: %s", config->current_bar->id); | ||
22 | } else { | ||
23 | error = cmd_results_new(CMD_INVALID, "wrap_scroll", "Invalid value %s", argv[0]); | ||
24 | return error; | ||
25 | } | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/bind.c b/sway/commands/bind.c deleted file mode 100644 index d9ea37b7..00000000 --- a/sway/commands/bind.c +++ /dev/null | |||
@@ -1,170 +0,0 @@ | |||
1 | #include <xkbcommon/xkbcommon.h> | ||
2 | #include <xkbcommon/xkbcommon-names.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/config.h" | ||
6 | #include "sway/input_state.h" | ||
7 | #include "list.h" | ||
8 | #include "log.h" | ||
9 | #include "stringop.h" | ||
10 | #include "util.h" | ||
11 | |||
12 | int binding_order = 0; | ||
13 | |||
14 | struct cmd_results *cmd_bindsym(int argc, char **argv) { | ||
15 | struct cmd_results *error = NULL; | ||
16 | if ((error = checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1))) { | ||
17 | return error; | ||
18 | } | ||
19 | |||
20 | struct sway_binding *binding = malloc(sizeof(struct sway_binding)); | ||
21 | if (!binding) { | ||
22 | return cmd_results_new(CMD_FAILURE, "bindsym", | ||
23 | "Unable to allocate binding"); | ||
24 | } | ||
25 | binding->keys = create_list(); | ||
26 | binding->modifiers = 0; | ||
27 | binding->release = false; | ||
28 | binding->bindcode = false; | ||
29 | |||
30 | // Handle --release | ||
31 | if (strcmp("--release", argv[0]) == 0) { | ||
32 | if (argc >= 3) { | ||
33 | binding->release = true; | ||
34 | argv++; | ||
35 | argc--; | ||
36 | } else { | ||
37 | free_sway_binding(binding); | ||
38 | return cmd_results_new(CMD_FAILURE, "bindsym", | ||
39 | "Invalid bindsym command " | ||
40 | "(expected more than 2 arguments, got %d)", argc); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | binding->command = join_args(argv + 1, argc - 1); | ||
45 | |||
46 | list_t *split = split_string(argv[0], "+"); | ||
47 | for (int i = 0; i < split->length; ++i) { | ||
48 | // Check for a modifier key | ||
49 | uint32_t mod; | ||
50 | if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) { | ||
51 | binding->modifiers |= mod; | ||
52 | continue; | ||
53 | } | ||
54 | // Check for xkb key | ||
55 | xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], | ||
56 | XKB_KEYSYM_CASE_INSENSITIVE); | ||
57 | |||
58 | // Check for mouse binding | ||
59 | if (strncasecmp(split->items[i], "button", strlen("button")) == 0 && | ||
60 | strlen(split->items[i]) == strlen("button0")) { | ||
61 | sym = ((char *)split->items[i])[strlen("button")] - '1' + M_LEFT_CLICK; | ||
62 | } | ||
63 | if (!sym) { | ||
64 | struct cmd_results *ret = cmd_results_new(CMD_INVALID, "bindsym", | ||
65 | "Unknown key '%s'", (char *)split->items[i]); | ||
66 | free_sway_binding(binding); | ||
67 | free_flat_list(split); | ||
68 | return ret; | ||
69 | } | ||
70 | xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t)); | ||
71 | if (!key) { | ||
72 | free_sway_binding(binding); | ||
73 | free_flat_list(split); | ||
74 | return cmd_results_new(CMD_FAILURE, "bindsym", | ||
75 | "Unable to allocate binding"); | ||
76 | } | ||
77 | *key = sym; | ||
78 | list_add(binding->keys, key); | ||
79 | } | ||
80 | free_flat_list(split); | ||
81 | |||
82 | struct sway_mode *mode = config->current_mode; | ||
83 | int i = list_seq_find(mode->bindings, sway_binding_cmp_keys, binding); | ||
84 | if (i > -1) { | ||
85 | sway_log(L_DEBUG, "bindsym - '%s' already exists, overwriting", argv[0]); | ||
86 | struct sway_binding *dup = mode->bindings->items[i]; | ||
87 | free_sway_binding(dup); | ||
88 | list_del(mode->bindings, i); | ||
89 | } | ||
90 | binding->order = binding_order++; | ||
91 | list_add(mode->bindings, binding); | ||
92 | list_qsort(mode->bindings, sway_binding_cmp_qsort); | ||
93 | |||
94 | sway_log(L_DEBUG, "bindsym - Bound %s to command %s", argv[0], binding->command); | ||
95 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
96 | } | ||
97 | |||
98 | struct cmd_results *cmd_bindcode(int argc, char **argv) { | ||
99 | struct cmd_results *error = NULL; | ||
100 | if ((error = checkarg(argc, "bindcode", EXPECTED_MORE_THAN, 1))) { | ||
101 | return error; | ||
102 | } | ||
103 | |||
104 | struct sway_binding *binding = malloc(sizeof(struct sway_binding)); | ||
105 | if (!binding) { | ||
106 | return cmd_results_new(CMD_FAILURE, "bindsym", | ||
107 | "Unable to allocate binding"); | ||
108 | } | ||
109 | binding->keys = create_list(); | ||
110 | binding->modifiers = 0; | ||
111 | binding->release = false; | ||
112 | binding->bindcode = true; | ||
113 | |||
114 | // Handle --release | ||
115 | if (strcmp("--release", argv[0]) == 0) { | ||
116 | if (argc >= 3) { | ||
117 | binding->release = true; | ||
118 | argv++; | ||
119 | argc--; | ||
120 | } else { | ||
121 | free_sway_binding(binding); | ||
122 | return cmd_results_new(CMD_FAILURE, "bindcode", | ||
123 | "Invalid bindcode command " | ||
124 | "(expected more than 2 arguments, got %d)", argc); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | binding->command = join_args(argv + 1, argc - 1); | ||
129 | |||
130 | list_t *split = split_string(argv[0], "+"); | ||
131 | for (int i = 0; i < split->length; ++i) { | ||
132 | // Check for a modifier key | ||
133 | uint32_t mod; | ||
134 | if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) { | ||
135 | binding->modifiers |= mod; | ||
136 | continue; | ||
137 | } | ||
138 | // parse keycode | ||
139 | xkb_keycode_t keycode = (int)strtol(split->items[i], NULL, 10); | ||
140 | if (!xkb_keycode_is_legal_ext(keycode)) { | ||
141 | error = cmd_results_new(CMD_INVALID, "bindcode", "Invalid keycode '%s'", (char *)split->items[i]); | ||
142 | free_sway_binding(binding); | ||
143 | list_free(split); | ||
144 | return error; | ||
145 | } | ||
146 | xkb_keycode_t *key = malloc(sizeof(xkb_keycode_t)); | ||
147 | *key = keycode - 8; | ||
148 | list_add(binding->keys, key); | ||
149 | } | ||
150 | free_flat_list(split); | ||
151 | |||
152 | struct sway_mode *mode = config->current_mode; | ||
153 | int i = list_seq_find(mode->bindings, sway_binding_cmp_keys, binding); | ||
154 | if (i > -1) { | ||
155 | struct sway_binding *dup = mode->bindings->items[i]; | ||
156 | if (dup->bindcode) { | ||
157 | sway_log(L_DEBUG, "bindcode - '%s' already exists, overwriting", argv[0]); | ||
158 | } else { | ||
159 | sway_log(L_DEBUG, "bindcode - '%s' already exists as bindsym, overwriting", argv[0]); | ||
160 | } | ||
161 | free_sway_binding(dup); | ||
162 | list_del(mode->bindings, i); | ||
163 | } | ||
164 | binding->order = binding_order++; | ||
165 | list_add(mode->bindings, binding); | ||
166 | list_qsort(mode->bindings, sway_binding_cmp_qsort); | ||
167 | |||
168 | sway_log(L_DEBUG, "bindcode - Bound %s to command %s", argv[0], binding->command); | ||
169 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
170 | } | ||
diff --git a/sway/commands/border.c b/sway/commands/border.c deleted file mode 100644 index c888622e..00000000 --- a/sway/commands/border.c +++ /dev/null | |||
@@ -1,65 +0,0 @@ | |||
1 | #include <errno.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include <strings.h> | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/container.h" | ||
7 | #include "sway/focus.h" | ||
8 | |||
9 | struct cmd_results *cmd_border(int argc, char **argv) { | ||
10 | struct cmd_results *error = NULL; | ||
11 | if (!config->active) { | ||
12 | return cmd_results_new(CMD_FAILURE, "border", "Can only be used when sway is running."); | ||
13 | } | ||
14 | if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) { | ||
15 | return error; | ||
16 | } | ||
17 | |||
18 | if (argc > 2) { | ||
19 | return cmd_results_new(CMD_INVALID, "border", | ||
20 | "Expected 'border <normal|pixel|none|toggle> [<n>]"); | ||
21 | } | ||
22 | |||
23 | swayc_t *view = current_container; | ||
24 | enum swayc_border_types border = view->border_type; | ||
25 | int thickness = view->border_thickness; | ||
26 | |||
27 | if (strcasecmp(argv[0], "none") == 0) { | ||
28 | border = B_NONE; | ||
29 | } else if (strcasecmp(argv[0], "normal") == 0) { | ||
30 | border = B_NORMAL; | ||
31 | } else if (strcasecmp(argv[0], "pixel") == 0) { | ||
32 | border = B_PIXEL; | ||
33 | } else if (strcasecmp(argv[0], "toggle") == 0) { | ||
34 | switch (border) { | ||
35 | case B_NONE: | ||
36 | border = B_PIXEL; | ||
37 | break; | ||
38 | case B_NORMAL: | ||
39 | border = B_NONE; | ||
40 | break; | ||
41 | case B_PIXEL: | ||
42 | border = B_NORMAL; | ||
43 | break; | ||
44 | } | ||
45 | } else { | ||
46 | return cmd_results_new(CMD_INVALID, "border", | ||
47 | "Expected 'border <normal|pixel|none|toggle>"); | ||
48 | } | ||
49 | |||
50 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { | ||
51 | thickness = (int)strtol(argv[1], NULL, 10); | ||
52 | if (errno == ERANGE || thickness < 0) { | ||
53 | errno = 0; | ||
54 | return cmd_results_new(CMD_INVALID, "border", "Number is out of range."); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | if (view) { | ||
59 | view->border_type = border; | ||
60 | view->border_thickness = thickness; | ||
61 | update_geometry(view); | ||
62 | } | ||
63 | |||
64 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
65 | } | ||
diff --git a/sway/commands/client.c b/sway/commands/client.c deleted file mode 100644 index f3d879cd..00000000 --- a/sway/commands/client.c +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | static struct cmd_results *parse_border_color(struct border_colors *border_colors, const char *cmd_name, int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if (argc < 3 || argc > 5) { | ||
8 | return cmd_results_new(CMD_INVALID, cmd_name, "Requires between three and five color values"); | ||
9 | } | ||
10 | |||
11 | uint32_t *colors[5] = { | ||
12 | &border_colors->border, | ||
13 | &border_colors->background, | ||
14 | &border_colors->text, | ||
15 | &border_colors->indicator, | ||
16 | &border_colors->child_border | ||
17 | }; | ||
18 | int i; | ||
19 | for (i = 0; i < argc; i++) { | ||
20 | char buffer[10]; | ||
21 | error = add_color(cmd_name, buffer, argv[i]); | ||
22 | if (error) { | ||
23 | return error; | ||
24 | } | ||
25 | *colors[i] = strtoul(buffer + 1, NULL, 16); | ||
26 | } | ||
27 | |||
28 | if (argc < 5) { | ||
29 | border_colors->child_border = border_colors->background; | ||
30 | } | ||
31 | |||
32 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
33 | } | ||
34 | |||
35 | struct cmd_results *cmd_client_focused(int argc, char **argv) { | ||
36 | return parse_border_color(&config->border_colors.focused, "client.focused", argc, argv); | ||
37 | } | ||
38 | |||
39 | struct cmd_results *cmd_client_focused_inactive(int argc, char **argv) { | ||
40 | return parse_border_color(&config->border_colors.focused_inactive, "client.focused_inactive", argc, argv); | ||
41 | } | ||
42 | |||
43 | struct cmd_results *cmd_client_unfocused(int argc, char **argv) { | ||
44 | return parse_border_color(&config->border_colors.unfocused, "client.unfocused", argc, argv); | ||
45 | } | ||
46 | |||
47 | struct cmd_results *cmd_client_urgent(int argc, char **argv) { | ||
48 | return parse_border_color(&config->border_colors.urgent, "client.urgent", argc, argv); | ||
49 | } | ||
50 | |||
51 | struct cmd_results *cmd_client_placeholder(int argc, char **argv) { | ||
52 | return parse_border_color(&config->border_colors.placeholder, "client.placeholder", argc, argv); | ||
53 | } | ||
54 | |||
55 | struct cmd_results *cmd_client_background(int argc, char **argv) { | ||
56 | char buffer[10]; | ||
57 | struct cmd_results *error = NULL; | ||
58 | uint32_t background; | ||
59 | |||
60 | if (argc != 1) { | ||
61 | return cmd_results_new(CMD_INVALID, "client.background", "Requires exactly one color value"); | ||
62 | } | ||
63 | |||
64 | error = add_color("client.background", buffer, argv[0]); | ||
65 | if (error) { | ||
66 | return error; | ||
67 | } | ||
68 | |||
69 | background = strtoul(buffer+1, NULL, 16); | ||
70 | config->border_colors.background = background; | ||
71 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
72 | } | ||
diff --git a/sway/commands/clipboard.c b/sway/commands/clipboard.c deleted file mode 100644 index 95514e78..00000000 --- a/sway/commands/clipboard.c +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | #include <wlc/wlc.h> | ||
2 | #include <unistd.h> | ||
3 | #include <string.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "stringop.h" | ||
6 | |||
7 | static void send_clipboard(void *data, const char *type, int fd) { | ||
8 | if (strcmp(type, "text/plain") != 0 | ||
9 | && strcmp(type, "text/plain;charset=utf-8") != 0) { | ||
10 | close(fd); | ||
11 | return; | ||
12 | } | ||
13 | |||
14 | const char *str = data; | ||
15 | write(fd, str, strlen(str)); | ||
16 | close(fd); | ||
17 | } | ||
18 | |||
19 | struct cmd_results *cmd_clipboard(int argc, char **argv) { | ||
20 | static char *current_data = NULL; | ||
21 | |||
22 | struct cmd_results *error = NULL; | ||
23 | if ((error = checkarg(argc, "clipboard", EXPECTED_AT_LEAST, 1))) { | ||
24 | return error; | ||
25 | } | ||
26 | |||
27 | static const char *types[2] = { | ||
28 | "text/plain", | ||
29 | "text/plain;charset=utf-8" | ||
30 | }; | ||
31 | |||
32 | char *str = join_args(argv, argc); | ||
33 | wlc_set_selection(str, types, 2, &send_clipboard); | ||
34 | |||
35 | free(current_data); | ||
36 | current_data = str; | ||
37 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
38 | } | ||
diff --git a/sway/commands/commands.c b/sway/commands/commands.c deleted file mode 100644 index 0c64970c..00000000 --- a/sway/commands/commands.c +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | #include <stdbool.h> | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/config.h" | ||
5 | #include "list.h" | ||
6 | #include "log.h" | ||
7 | |||
8 | struct cmd_results *cmd_commands(int argc, char **argv) { | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "commands", EXPECTED_EQUAL_TO, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | if ((error = check_security_config())) { | ||
14 | return error; | ||
15 | } | ||
16 | |||
17 | if (strcmp(argv[0], "{") != 0) { | ||
18 | return cmd_results_new(CMD_FAILURE, "commands", "Expected block declaration"); | ||
19 | } | ||
20 | |||
21 | if (!config->reading) { | ||
22 | return cmd_results_new(CMD_FAILURE, "commands", "Can only be used in config file."); | ||
23 | } | ||
24 | |||
25 | return cmd_results_new(CMD_BLOCK_COMMANDS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/debuglog.c b/sway/commands/debuglog.c deleted file mode 100644 index 658d6165..00000000 --- a/sway/commands/debuglog.c +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *cmd_debuglog(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "debuglog", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } else if (strcasecmp(argv[0], "toggle") == 0) { | ||
11 | if (config->reading) { | ||
12 | return cmd_results_new(CMD_FAILURE, "debuglog toggle", "Can't be used in config file."); | ||
13 | } | ||
14 | if (toggle_debug_logging()) { | ||
15 | sway_log(L_DEBUG, "Debuglog turned on."); | ||
16 | } | ||
17 | } else if (strcasecmp(argv[0], "on") == 0) { | ||
18 | set_log_level(L_DEBUG); | ||
19 | sway_log(L_DEBUG, "Debuglog turned on."); | ||
20 | } else if (strcasecmp(argv[0], "off") == 0) { | ||
21 | reset_log_level(); | ||
22 | } else { | ||
23 | return cmd_results_new(CMD_FAILURE, "debuglog", "Expected 'debuglog on|off|toggle'"); | ||
24 | } | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
27 | |||
diff --git a/sway/commands/default_border.c b/sway/commands/default_border.c deleted file mode 100644 index 8fbe8d19..00000000 --- a/sway/commands/default_border.c +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | #include <errno.h> | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/container.h" | ||
6 | |||
7 | struct cmd_results *cmd_default_border(int argc, char **argv) { | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "default_border", EXPECTED_AT_LEAST, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | |||
13 | if (argc > 2) { | ||
14 | return cmd_results_new(CMD_INVALID, "default_border", | ||
15 | "Expected 'default_border <normal|none|pixel> [<n>]"); | ||
16 | } | ||
17 | |||
18 | enum swayc_border_types border = config->border; | ||
19 | int thickness = config->border_thickness; | ||
20 | |||
21 | if (strcasecmp(argv[0], "none") == 0) { | ||
22 | border = B_NONE; | ||
23 | } else if (strcasecmp(argv[0], "normal") == 0) { | ||
24 | border = B_NORMAL; | ||
25 | } else if (strcasecmp(argv[0], "pixel") == 0) { | ||
26 | border = B_PIXEL; | ||
27 | } else { | ||
28 | return cmd_results_new(CMD_INVALID, "default_border", | ||
29 | "Expected 'default_border <normal|none|pixel> [<n>]"); | ||
30 | } | ||
31 | |||
32 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { | ||
33 | thickness = (int)strtol(argv[1], NULL, 10); | ||
34 | if (errno == ERANGE || thickness < 0) { | ||
35 | errno = 0; | ||
36 | return cmd_results_new(CMD_INVALID, "default_border", "Number is out out of range."); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | config->border = border; | ||
41 | config->border_thickness = thickness; | ||
42 | |||
43 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
44 | } | ||
diff --git a/sway/commands/default_floating_border.c b/sway/commands/default_floating_border.c deleted file mode 100644 index fb48c1c0..00000000 --- a/sway/commands/default_floating_border.c +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | #include <errno.h> | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/container.h" | ||
6 | |||
7 | struct cmd_results *cmd_default_floating_border(int argc, char **argv) { | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "default_floating_border", EXPECTED_AT_LEAST, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | |||
13 | if (argc > 2) { | ||
14 | return cmd_results_new(CMD_INVALID, "default_floating_border", | ||
15 | "Expected 'default_floating_border <normal|none|pixel> [<n>]"); | ||
16 | } | ||
17 | |||
18 | enum swayc_border_types border = config->floating_border; | ||
19 | int thickness = config->floating_border_thickness; | ||
20 | |||
21 | if (strcasecmp(argv[0], "none") == 0) { | ||
22 | border = B_NONE; | ||
23 | } else if (strcasecmp(argv[0], "normal") == 0) { | ||
24 | border = B_NORMAL; | ||
25 | } else if (strcasecmp(argv[0], "pixel") == 0) { | ||
26 | border = B_PIXEL; | ||
27 | } else { | ||
28 | return cmd_results_new(CMD_INVALID, "default_floating_border", | ||
29 | "Expected 'default_floating_border <normal|none|pixel> [<n>]"); | ||
30 | } | ||
31 | |||
32 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { | ||
33 | thickness = (int)strtol(argv[1], NULL, 10); | ||
34 | if (errno == ERANGE || thickness < 0) { | ||
35 | errno = 0; | ||
36 | return cmd_results_new(CMD_INVALID, "default_floating_border", | ||
37 | "Number is out out of range."); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | config->floating_border = border; | ||
42 | config->floating_border_thickness = thickness; | ||
43 | |||
44 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
45 | } | ||
diff --git a/sway/commands/exec.c b/sway/commands/exec.c deleted file mode 100644 index 58ef5f94..00000000 --- a/sway/commands/exec.c +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | #include "stringop.h" | ||
5 | |||
6 | struct cmd_results *cmd_exec(int argc, char **argv) { | ||
7 | if (!config->active) return cmd_results_new(CMD_DEFER, "exec", NULL); | ||
8 | if (config->reloading) { | ||
9 | char *args = join_args(argv, argc); | ||
10 | sway_log(L_DEBUG, "Ignoring 'exec %s' due to reload", args); | ||
11 | free(args); | ||
12 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
13 | } | ||
14 | return cmd_exec_always(argc, argv); | ||
15 | } | ||
16 | |||
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c deleted file mode 100644 index ab2d8622..00000000 --- a/sway/commands/exec_always.c +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include <sys/wait.h> | ||
4 | #include <unistd.h> | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/config.h" | ||
7 | #include "log.h" | ||
8 | #include "stringop.h" | ||
9 | |||
10 | struct cmd_results *cmd_exec_always(int argc, char **argv) { | ||
11 | struct cmd_results *error = NULL; | ||
12 | if (!config->active) return cmd_results_new(CMD_DEFER, NULL, NULL); | ||
13 | if ((error = checkarg(argc, "exec_always", EXPECTED_MORE_THAN, 0))) { | ||
14 | return error; | ||
15 | } | ||
16 | |||
17 | char *tmp = NULL; | ||
18 | if (strcmp((char*)*argv, "--no-startup-id") == 0) { | ||
19 | sway_log(L_INFO, "exec switch '--no-startup-id' not supported, ignored."); | ||
20 | if ((error = checkarg(argc - 1, "exec_always", EXPECTED_MORE_THAN, 0))) { | ||
21 | return error; | ||
22 | } | ||
23 | |||
24 | tmp = join_args(argv + 1, argc - 1); | ||
25 | } else { | ||
26 | tmp = join_args(argv, argc); | ||
27 | } | ||
28 | |||
29 | // Put argument into cmd array | ||
30 | char cmd[4096]; | ||
31 | strncpy(cmd, tmp, sizeof(cmd)); | ||
32 | cmd[sizeof(cmd) - 1] = 0; | ||
33 | free(tmp); | ||
34 | sway_log(L_DEBUG, "Executing %s", cmd); | ||
35 | |||
36 | int fd[2]; | ||
37 | if (pipe(fd) != 0) { | ||
38 | sway_log(L_ERROR, "Unable to create pipe for fork"); | ||
39 | } | ||
40 | |||
41 | pid_t pid; | ||
42 | pid_t *child = malloc(sizeof(pid_t)); // malloc'd so that Linux can avoid copying the process space | ||
43 | if (!child) { | ||
44 | return cmd_results_new(CMD_FAILURE, "exec_always", "Unable to allocate child pid"); | ||
45 | } | ||
46 | // Fork process | ||
47 | if ((pid = fork()) == 0) { | ||
48 | // Fork child process again | ||
49 | setsid(); | ||
50 | if ((*child = fork()) == 0) { | ||
51 | execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL); | ||
52 | /* Not reached */ | ||
53 | } | ||
54 | close(fd[0]); | ||
55 | ssize_t s = 0; | ||
56 | while ((size_t)s < sizeof(pid_t)) { | ||
57 | s += write(fd[1], ((uint8_t *)child) + s, sizeof(pid_t) - s); | ||
58 | } | ||
59 | close(fd[1]); | ||
60 | _exit(0); // Close child process | ||
61 | } else if (pid < 0) { | ||
62 | free(child); | ||
63 | return cmd_results_new(CMD_FAILURE, "exec_always", "fork() failed"); | ||
64 | } | ||
65 | close(fd[1]); // close write | ||
66 | ssize_t s = 0; | ||
67 | while ((size_t)s < sizeof(pid_t)) { | ||
68 | s += read(fd[0], ((uint8_t *)child) + s, sizeof(pid_t) - s); | ||
69 | } | ||
70 | close(fd[0]); | ||
71 | // cleanup child process | ||
72 | wait(0); | ||
73 | swayc_t *ws = swayc_active_workspace(); | ||
74 | if (*child > 0 && ws) { | ||
75 | sway_log(L_DEBUG, "Child process created with pid %d for workspace %s", *child, ws->name); | ||
76 | struct pid_workspace *pw = malloc(sizeof(struct pid_workspace)); | ||
77 | pw->pid = child; | ||
78 | pw->workspace = strdup(ws->name); | ||
79 | pid_workspace_add(pw); | ||
80 | } else { | ||
81 | free(child); | ||
82 | } | ||
83 | |||
84 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
85 | } | ||
diff --git a/sway/commands/exit.c b/sway/commands/exit.c deleted file mode 100644 index f192f86a..00000000 --- a/sway/commands/exit.c +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | #include "sway/commands.h" | ||
2 | #include "sway/container.h" | ||
3 | |||
4 | void sway_terminate(int exit_code); | ||
5 | |||
6 | struct cmd_results *cmd_exit(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if (config->reading) return cmd_results_new(CMD_FAILURE, "exit", "Can't be used in config file."); | ||
9 | if ((error = checkarg(argc, "exit", EXPECTED_EQUAL_TO, 0))) { | ||
10 | return error; | ||
11 | } | ||
12 | // Close all views | ||
13 | close_views(&root_container); | ||
14 | sway_terminate(EXIT_SUCCESS); | ||
15 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
16 | } | ||
17 | |||
diff --git a/sway/commands/floating.c b/sway/commands/floating.c deleted file mode 100644 index ccfde532..00000000 --- a/sway/commands/floating.c +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/container.h" | ||
5 | #include "sway/ipc-server.h" | ||
6 | #include "sway/layout.h" | ||
7 | #include "list.h" | ||
8 | #include "log.h" | ||
9 | |||
10 | struct cmd_results *cmd_floating(int argc, char **argv) { | ||
11 | struct cmd_results *error = NULL; | ||
12 | if (config->reading) return cmd_results_new(CMD_FAILURE, "floating", "Can't be used in config file."); | ||
13 | if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) { | ||
14 | return error; | ||
15 | } | ||
16 | swayc_t *view = current_container; | ||
17 | bool wants_floating; | ||
18 | if (strcasecmp(argv[0], "enable") == 0) { | ||
19 | wants_floating = true; | ||
20 | } else if (strcasecmp(argv[0], "disable") == 0) { | ||
21 | wants_floating = false; | ||
22 | } else if (strcasecmp(argv[0], "toggle") == 0) { | ||
23 | wants_floating = !view->is_floating; | ||
24 | } else { | ||
25 | return cmd_results_new(CMD_FAILURE, "floating", | ||
26 | "Expected 'floating <enable|disable|toggle>"); | ||
27 | } | ||
28 | |||
29 | // Prevent running floating commands on things like workspaces | ||
30 | if (view->type != C_VIEW) { | ||
31 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
32 | } | ||
33 | |||
34 | // Change from nonfloating to floating | ||
35 | if (!view->is_floating && wants_floating) { | ||
36 | // Remove view from its current location | ||
37 | destroy_container(remove_child(view)); | ||
38 | |||
39 | // and move it into workspace floating | ||
40 | add_floating(swayc_active_workspace(), view); | ||
41 | view->x = (swayc_active_workspace()->width - view->width)/2; | ||
42 | view->y = (swayc_active_workspace()->height - view->height)/2; | ||
43 | if (view->desired_width != -1) { | ||
44 | view->width = view->desired_width; | ||
45 | } | ||
46 | if (view->desired_height != -1) { | ||
47 | view->height = view->desired_height; | ||
48 | } | ||
49 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
50 | |||
51 | } else if (view->is_floating && !wants_floating) { | ||
52 | // Delete the view from the floating list and unset its is_floating flag | ||
53 | remove_child(view); | ||
54 | view->is_floating = false; | ||
55 | // Get the properly focused container, and add in the view there | ||
56 | swayc_t *focused = container_under_pointer(); | ||
57 | // If focused is null, it's because the currently focused container is a workspace | ||
58 | if (focused == NULL || focused->is_floating) { | ||
59 | focused = swayc_active_workspace(); | ||
60 | } | ||
61 | set_focused_container(focused); | ||
62 | |||
63 | sway_log(L_DEBUG, "Non-floating focused container is %p", focused); | ||
64 | |||
65 | // Case of focused workspace, just create as child of it | ||
66 | if (focused->type == C_WORKSPACE) { | ||
67 | add_child(focused, view); | ||
68 | } | ||
69 | // Regular case, create as sibling of current container | ||
70 | else { | ||
71 | add_sibling(focused, view); | ||
72 | } | ||
73 | // Refocus on the view once its been put back into the layout | ||
74 | view->width = view->height = 0; | ||
75 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
76 | remove_view_from_scratchpad(view); | ||
77 | ipc_event_window(view, "floating"); | ||
78 | } | ||
79 | set_focused_container(view); | ||
80 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
81 | } | ||
diff --git a/sway/commands/floating_maximum_size.c b/sway/commands/floating_maximum_size.c deleted file mode 100644 index 5bca4d7c..00000000 --- a/sway/commands/floating_maximum_size.c +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *cmd_floating_maximum_size(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | int32_t width; | ||
9 | int32_t height; | ||
10 | char *ptr; | ||
11 | |||
12 | if ((error = checkarg(argc, "floating_maximum_size", EXPECTED_EQUAL_TO, 3))) { | ||
13 | return error; | ||
14 | } | ||
15 | width = strtol(argv[0], &ptr, 10); | ||
16 | height = strtol(argv[2], &ptr, 10); | ||
17 | |||
18 | if (width < -1) { | ||
19 | sway_log(L_DEBUG, "floating_maximum_size invalid width value: '%s'", argv[0]); | ||
20 | |||
21 | } else { | ||
22 | config->floating_maximum_width = width; | ||
23 | |||
24 | } | ||
25 | |||
26 | if (height < -1) { | ||
27 | sway_log(L_DEBUG, "floating_maximum_size invalid height value: '%s'", argv[2]); | ||
28 | } | ||
29 | else { | ||
30 | config->floating_maximum_height = height; | ||
31 | |||
32 | } | ||
33 | |||
34 | sway_log(L_DEBUG, "New floating_maximum_size: '%d' x '%d'", config->floating_maximum_width, | ||
35 | config->floating_maximum_height); | ||
36 | |||
37 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
38 | } | ||
diff --git a/sway/commands/floating_minimum_size.c b/sway/commands/floating_minimum_size.c deleted file mode 100644 index ba72454c..00000000 --- a/sway/commands/floating_minimum_size.c +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *cmd_floating_minimum_size(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | int32_t width; | ||
9 | int32_t height; | ||
10 | char *ptr; | ||
11 | |||
12 | if ((error = checkarg(argc, "floating_minimum_size", EXPECTED_EQUAL_TO, 3))) { | ||
13 | return error; | ||
14 | } | ||
15 | width = strtol(argv[0], &ptr, 10); | ||
16 | height = strtol(argv[2], &ptr, 10); | ||
17 | |||
18 | if (width <= 0) { | ||
19 | sway_log(L_DEBUG, "floating_minimum_size invalid width value: '%s'", argv[0]); | ||
20 | |||
21 | } else { | ||
22 | config->floating_minimum_width = width; | ||
23 | |||
24 | } | ||
25 | |||
26 | if (height <= 0) { | ||
27 | sway_log(L_DEBUG, "floating_minimum_size invalid height value: '%s'", argv[2]); | ||
28 | } | ||
29 | else { | ||
30 | config->floating_minimum_height = height; | ||
31 | |||
32 | } | ||
33 | |||
34 | sway_log(L_DEBUG, "New floating_minimum_size: '%d' x '%d'", config->floating_minimum_width, | ||
35 | config->floating_minimum_height); | ||
36 | |||
37 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
38 | } | ||
diff --git a/sway/commands/floating_mod.c b/sway/commands/floating_mod.c deleted file mode 100644 index b8e81ab9..00000000 --- a/sway/commands/floating_mod.c +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input_state.h" | ||
5 | #include "list.h" | ||
6 | #include "log.h" | ||
7 | #include "stringop.h" | ||
8 | #include "util.h" | ||
9 | |||
10 | struct cmd_results *cmd_floating_mod(int argc, char **argv) { | ||
11 | struct cmd_results *error = NULL; | ||
12 | if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) { | ||
13 | return error; | ||
14 | } | ||
15 | int i; | ||
16 | list_t *split = split_string(argv[0], "+"); | ||
17 | config->floating_mod = 0; | ||
18 | |||
19 | // set modifier keys | ||
20 | for (i = 0; i < split->length; ++i) { | ||
21 | config->floating_mod |= get_modifier_mask_by_name(split->items[i]); | ||
22 | } | ||
23 | free_flat_list(split); | ||
24 | if (!config->floating_mod) { | ||
25 | error = cmd_results_new(CMD_INVALID, "floating_modifier", "Unknown keys %s", argv[0]); | ||
26 | return error; | ||
27 | } | ||
28 | |||
29 | if (argc >= 2) { | ||
30 | if (strcasecmp("inverse", argv[1]) == 0) { | ||
31 | config->dragging_key = M_RIGHT_CLICK; | ||
32 | config->resizing_key = M_LEFT_CLICK; | ||
33 | } else if (strcasecmp("normal", argv[1]) == 0) { | ||
34 | config->dragging_key = M_LEFT_CLICK; | ||
35 | config->resizing_key = M_RIGHT_CLICK; | ||
36 | } else { | ||
37 | error = cmd_results_new(CMD_INVALID, "floating_modifier", "Invalid definition %s", argv[1]); | ||
38 | return error; | ||
39 | } | ||
40 | } | ||
41 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
42 | } | ||
diff --git a/sway/commands/floating_scroll.c b/sway/commands/floating_scroll.c deleted file mode 100644 index 8c50c5bd..00000000 --- a/sway/commands/floating_scroll.c +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "log.h" | ||
6 | #include "stringop.h" | ||
7 | |||
8 | struct cmd_results *cmd_floating_scroll(int argc, char **argv) { | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "floating_scroll", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | if (!strcasecmp("up", argv[0])) { | ||
14 | free(config->floating_scroll_up_cmd); | ||
15 | if (argc < 2) { | ||
16 | config->floating_scroll_up_cmd = strdup(""); | ||
17 | } else { | ||
18 | config->floating_scroll_up_cmd = join_args(argv + 1, argc - 1); | ||
19 | } | ||
20 | } else if (!strcasecmp("down", argv[0])) { | ||
21 | free(config->floating_scroll_down_cmd); | ||
22 | if (argc < 2) { | ||
23 | config->floating_scroll_down_cmd = strdup(""); | ||
24 | } else { | ||
25 | config->floating_scroll_down_cmd = join_args(argv + 1, argc - 1); | ||
26 | } | ||
27 | } else if (!strcasecmp("left", argv[0])) { | ||
28 | free(config->floating_scroll_left_cmd); | ||
29 | if (argc < 2) { | ||
30 | config->floating_scroll_left_cmd = strdup(""); | ||
31 | } else { | ||
32 | config->floating_scroll_left_cmd = join_args(argv + 1, argc - 1); | ||
33 | } | ||
34 | } else if (!strcasecmp("right", argv[0])) { | ||
35 | free(config->floating_scroll_right_cmd); | ||
36 | if (argc < 2) { | ||
37 | config->floating_scroll_right_cmd = strdup(""); | ||
38 | } else { | ||
39 | config->floating_scroll_right_cmd = join_args(argv + 1, argc - 1); | ||
40 | } | ||
41 | } else { | ||
42 | error = cmd_results_new(CMD_INVALID, "floating_scroll", "Unknown command: '%s'", argv[0]); | ||
43 | return error; | ||
44 | } | ||
45 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
46 | } | ||
diff --git a/sway/commands/focus.c b/sway/commands/focus.c deleted file mode 100644 index c83157b8..00000000 --- a/sway/commands/focus.c +++ /dev/null | |||
@@ -1,100 +0,0 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include <wlc/wlc.h> | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/container.h" | ||
7 | #include "sway/focus.h" | ||
8 | #include "sway/input_state.h" | ||
9 | #include "sway/output.h" | ||
10 | #include "sway/workspace.h" | ||
11 | |||
12 | struct cmd_results *cmd_focus(int argc, char **argv) { | ||
13 | if (config->reading) return cmd_results_new(CMD_FAILURE, "focus", "Can't be used in config file."); | ||
14 | struct cmd_results *error = NULL; | ||
15 | if (argc > 0 && strcasecmp(argv[0], "output") == 0) { | ||
16 | swayc_t *output = NULL; | ||
17 | struct wlc_point abs_pos; | ||
18 | get_absolute_center_position(get_focused_container(&root_container), &abs_pos); | ||
19 | if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 2))) { | ||
20 | return error; | ||
21 | } else if (!(output = output_by_name(argv[1], &abs_pos))) { | ||
22 | return cmd_results_new(CMD_FAILURE, "focus output", | ||
23 | "Can't find output with name/at direction '%s' @ (%i,%i)", argv[1], abs_pos.x, abs_pos.y); | ||
24 | } else if (!workspace_switch(swayc_active_workspace_for(output))) { | ||
25 | return cmd_results_new(CMD_FAILURE, "focus output", | ||
26 | "Switching to workspace on output '%s' was blocked", argv[1]); | ||
27 | } else if (config->mouse_warping) { | ||
28 | swayc_t *focused = get_focused_view(output); | ||
29 | if (focused && focused->type == C_VIEW) { | ||
30 | center_pointer_on(focused); | ||
31 | } | ||
32 | } | ||
33 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
34 | } else if (argc == 0) { | ||
35 | set_focused_container(current_container); | ||
36 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
37 | } else if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1))) { | ||
38 | return error; | ||
39 | } | ||
40 | static int floating_toggled_index = 0; | ||
41 | static int tiled_toggled_index = 0; | ||
42 | if (strcasecmp(argv[0], "left") == 0) { | ||
43 | move_focus(MOVE_LEFT); | ||
44 | } else if (strcasecmp(argv[0], "right") == 0) { | ||
45 | move_focus(MOVE_RIGHT); | ||
46 | } else if (strcasecmp(argv[0], "up") == 0) { | ||
47 | move_focus(MOVE_UP); | ||
48 | } else if (strcasecmp(argv[0], "down") == 0) { | ||
49 | move_focus(MOVE_DOWN); | ||
50 | } else if (strcasecmp(argv[0], "parent") == 0) { | ||
51 | move_focus(MOVE_PARENT); | ||
52 | } else if (strcasecmp(argv[0], "child") == 0) { | ||
53 | move_focus(MOVE_CHILD); | ||
54 | } else if (strcasecmp(argv[0], "next") == 0) { | ||
55 | move_focus(MOVE_NEXT); | ||
56 | } else if (strcasecmp(argv[0], "prev") == 0) { | ||
57 | move_focus(MOVE_PREV); | ||
58 | } else if (strcasecmp(argv[0], "mode_toggle") == 0) { | ||
59 | int i; | ||
60 | swayc_t *workspace = swayc_active_workspace(); | ||
61 | swayc_t *focused = get_focused_view(workspace); | ||
62 | if (focused->is_floating) { | ||
63 | if (workspace->children->length > 0) { | ||
64 | for (i = 0;i < workspace->floating->length; i++) { | ||
65 | if (workspace->floating->items[i] == focused) { | ||
66 | floating_toggled_index = i; | ||
67 | break; | ||
68 | } | ||
69 | } | ||
70 | if (workspace->children->length > tiled_toggled_index) { | ||
71 | set_focused_container(get_focused_view(workspace->children->items[tiled_toggled_index])); | ||
72 | } else { | ||
73 | set_focused_container(get_focused_view(workspace->children->items[0])); | ||
74 | tiled_toggled_index = 0; | ||
75 | } | ||
76 | } | ||
77 | } else { | ||
78 | if (workspace->floating->length > 0) { | ||
79 | for (i = 0;i < workspace->children->length; i++) { | ||
80 | if (workspace->children->items[i] == focused) { | ||
81 | tiled_toggled_index = i; | ||
82 | break; | ||
83 | } | ||
84 | } | ||
85 | if (workspace->floating->length > floating_toggled_index) { | ||
86 | swayc_t *floating = workspace->floating->items[floating_toggled_index]; | ||
87 | set_focused_container(get_focused_view(floating)); | ||
88 | } else { | ||
89 | swayc_t *floating = workspace->floating->items[workspace->floating->length - 1]; | ||
90 | set_focused_container(get_focused_view(floating)); | ||
91 | tiled_toggled_index = workspace->floating->length - 1; | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | } else { | ||
96 | return cmd_results_new(CMD_INVALID, "focus", | ||
97 | "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'"); | ||
98 | } | ||
99 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
100 | } | ||
diff --git a/sway/commands/focus_follows_mouse.c b/sway/commands/focus_follows_mouse.c deleted file mode 100644 index 7c9c2b13..00000000 --- a/sway/commands/focus_follows_mouse.c +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *cmd_focus_follows_mouse(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if ((error = checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1))) { | ||
8 | return error; | ||
9 | } | ||
10 | |||
11 | config->focus_follows_mouse = !strcasecmp(argv[0], "yes"); | ||
12 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
13 | } | ||
diff --git a/sway/commands/font.c b/sway/commands/font.c deleted file mode 100644 index 32994f8a..00000000 --- a/sway/commands/font.c +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/border.h" | ||
4 | #include "sway/commands.h" | ||
5 | #include "log.h" | ||
6 | #include "stringop.h" | ||
7 | |||
8 | struct cmd_results *cmd_font(int argc, char **argv) { | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "font", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | |||
14 | char *font = join_args(argv, argc); | ||
15 | free(config->font); | ||
16 | if (strlen(font) > 6 && strncmp("pango:", font, 6) == 0) { | ||
17 | config->font = strdup(font + 6); | ||
18 | free(font); | ||
19 | } else { | ||
20 | config->font = font; | ||
21 | } | ||
22 | |||
23 | config->font_height = get_font_text_height(config->font); | ||
24 | |||
25 | sway_log(L_DEBUG, "Settings font %s", config->font); | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/for_window.c b/sway/commands/for_window.c deleted file mode 100644 index d1fd1641..00000000 --- a/sway/commands/for_window.c +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/criteria.h" | ||
5 | #include "list.h" | ||
6 | #include "log.h" | ||
7 | #include "stringop.h" | ||
8 | |||
9 | struct cmd_results *cmd_for_window(int argc, char **argv) { | ||
10 | struct cmd_results *error = NULL; | ||
11 | if ((error = checkarg(argc, "for_window", EXPECTED_AT_LEAST, 2))) { | ||
12 | return error; | ||
13 | } | ||
14 | // add command to a criteria/command pair that is run against views when they appear. | ||
15 | char *criteria = argv[0], *cmdlist = join_args(argv + 1, argc - 1); | ||
16 | |||
17 | struct criteria *crit = malloc(sizeof(struct criteria)); | ||
18 | if (!crit) { | ||
19 | return cmd_results_new(CMD_FAILURE, "for_window", "Unable to allocate criteria"); | ||
20 | } | ||
21 | crit->crit_raw = strdup(criteria); | ||
22 | crit->cmdlist = cmdlist; | ||
23 | crit->tokens = create_list(); | ||
24 | char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw); | ||
25 | |||
26 | if (err_str) { | ||
27 | error = cmd_results_new(CMD_INVALID, "for_window", err_str); | ||
28 | free(err_str); | ||
29 | free_criteria(crit); | ||
30 | } else if (crit->tokens->length == 0) { | ||
31 | error = cmd_results_new(CMD_INVALID, "for_window", "Found no name/value pairs in criteria"); | ||
32 | free_criteria(crit); | ||
33 | } else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) { | ||
34 | sway_log(L_DEBUG, "for_window: Duplicate, skipping."); | ||
35 | free_criteria(crit); | ||
36 | } else { | ||
37 | sway_log(L_DEBUG, "for_window: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist); | ||
38 | list_add(config->criteria, crit); | ||
39 | } | ||
40 | return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
41 | } | ||
diff --git a/sway/commands/force_focus_wrapping.c b/sway/commands/force_focus_wrapping.c deleted file mode 100644 index f19dd163..00000000 --- a/sway/commands/force_focus_wrapping.c +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *cmd_force_focus_wrapping(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if ((error = checkarg(argc, "force_focus_wrapping", EXPECTED_EQUAL_TO, 1))) { | ||
8 | return error; | ||
9 | } | ||
10 | |||
11 | config->force_focus_wrapping = !strcasecmp(argv[0], "yes"); | ||
12 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
13 | } | ||
diff --git a/sway/commands/fullscreen.c b/sway/commands/fullscreen.c deleted file mode 100644 index bfff82f9..00000000 --- a/sway/commands/fullscreen.c +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | #include <stdbool.h> | ||
2 | #include <string.h> | ||
3 | #include <wlc/wlc.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/container.h" | ||
6 | #include "sway/focus.h" | ||
7 | #include "sway/ipc-server.h" | ||
8 | #include "sway/layout.h" | ||
9 | |||
10 | struct cmd_results *cmd_fullscreen(int argc, char **argv) { | ||
11 | struct cmd_results *error = NULL; | ||
12 | if (config->reading) return cmd_results_new(CMD_FAILURE, "fullscreen", "Can't be used in config file."); | ||
13 | if (!config->active) return cmd_results_new(CMD_FAILURE, "fullscreen", "Can only be used when sway is running."); | ||
14 | if ((error = checkarg(argc, "fullscreen", EXPECTED_AT_LEAST, 0))) { | ||
15 | return error; | ||
16 | } | ||
17 | swayc_t *container = current_container; | ||
18 | if(container->type != C_VIEW){ | ||
19 | return cmd_results_new(CMD_INVALID, "fullscreen", "Only views can fullscreen"); | ||
20 | } | ||
21 | swayc_t *workspace = swayc_parent_by_type(container, C_WORKSPACE); | ||
22 | bool current = swayc_is_fullscreen(container); | ||
23 | wlc_view_set_state(container->handle, WLC_BIT_FULLSCREEN, !current); | ||
24 | |||
25 | if (container->is_floating) { | ||
26 | if (current) { | ||
27 | // set dimensions back to what they were before we fullscreened this | ||
28 | container->x = container->cached_geometry.origin.x; | ||
29 | container->y = container->cached_geometry.origin.y; | ||
30 | container->width = container->cached_geometry.size.w; | ||
31 | container->height = container->cached_geometry.size.h; | ||
32 | } else { | ||
33 | // cache dimensions so we can reset them after we "unfullscreen" this | ||
34 | struct wlc_geometry geo = { | ||
35 | .origin = { | ||
36 | .x = container->x, | ||
37 | .y = container->y | ||
38 | }, | ||
39 | .size = { | ||
40 | .w = container->width, | ||
41 | .h = container->height | ||
42 | } | ||
43 | }; | ||
44 | container->cached_geometry = geo; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | // Resize workspace if going from fullscreen -> notfullscreen | ||
49 | // otherwise just resize container | ||
50 | if (!current) { | ||
51 | arrange_windows(workspace, -1, -1); | ||
52 | workspace->fullscreen = container; | ||
53 | } else { | ||
54 | arrange_windows(container, -1, -1); | ||
55 | workspace->fullscreen = NULL; | ||
56 | } | ||
57 | ipc_event_window(container, "fullscreen_mode"); | ||
58 | |||
59 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
60 | } | ||
diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c deleted file mode 100644 index 0a48592d..00000000 --- a/sway/commands/gaps.c +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | #include <ctype.h> | ||
2 | #include <errno.h> | ||
3 | #include <stdlib.h> | ||
4 | #include <string.h> | ||
5 | #include <strings.h> | ||
6 | #include "sway/commands.h" | ||
7 | #include "sway/container.h" | ||
8 | #include "sway/focus.h" | ||
9 | #include "sway/layout.h" | ||
10 | |||
11 | struct cmd_results *cmd_gaps(int argc, char **argv) { | ||
12 | struct cmd_results *error = NULL; | ||
13 | if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1))) { | ||
14 | return error; | ||
15 | } | ||
16 | const char *expected_syntax = | ||
17 | "Expected 'gaps edge_gaps <on|off|toggle>' or " | ||
18 | "'gaps <inner|outer> <current|all|workspace> <set|plus|minus n>'"; | ||
19 | const char *amount_str = argv[0]; | ||
20 | // gaps amount | ||
21 | if (argc >= 1 && isdigit(*amount_str)) { | ||
22 | int amount = (int)strtol(amount_str, NULL, 10); | ||
23 | if (errno == ERANGE) { | ||
24 | errno = 0; | ||
25 | return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); | ||
26 | } | ||
27 | config->gaps_inner = config->gaps_outer = amount; | ||
28 | arrange_windows(&root_container, -1, -1); | ||
29 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
30 | } | ||
31 | // gaps inner|outer n | ||
32 | else if (argc >= 2 && isdigit((amount_str = argv[1])[0])) { | ||
33 | int amount = (int)strtol(amount_str, NULL, 10); | ||
34 | if (errno == ERANGE) { | ||
35 | errno = 0; | ||
36 | return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); | ||
37 | } | ||
38 | const char *target_str = argv[0]; | ||
39 | if (strcasecmp(target_str, "inner") == 0) { | ||
40 | config->gaps_inner = amount; | ||
41 | } else if (strcasecmp(target_str, "outer") == 0) { | ||
42 | config->gaps_outer = amount; | ||
43 | } | ||
44 | arrange_windows(&root_container, -1, -1); | ||
45 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
46 | } else if (argc == 2 && strcasecmp(argv[0], "edge_gaps") == 0) { | ||
47 | // gaps edge_gaps <on|off|toggle> | ||
48 | if (strcasecmp(argv[1], "toggle") == 0) { | ||
49 | if (config->reading) { | ||
50 | return cmd_results_new(CMD_FAILURE, "gaps edge_gaps toggle", | ||
51 | "Can't be used in config file."); | ||
52 | } | ||
53 | config->edge_gaps = !config->edge_gaps; | ||
54 | } else { | ||
55 | config->edge_gaps = | ||
56 | (strcasecmp(argv[1], "yes") == 0 || strcasecmp(argv[1], "on") == 0); | ||
57 | } | ||
58 | arrange_windows(&root_container, -1, -1); | ||
59 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
60 | } | ||
61 | // gaps inner|outer current|all set|plus|minus n | ||
62 | if (argc < 4 || config->reading) { | ||
63 | return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); | ||
64 | } | ||
65 | // gaps inner|outer ... | ||
66 | const char *inout_str = argv[0]; | ||
67 | enum {INNER, OUTER} inout; | ||
68 | if (strcasecmp(inout_str, "inner") == 0) { | ||
69 | inout = INNER; | ||
70 | } else if (strcasecmp(inout_str, "outer") == 0) { | ||
71 | inout = OUTER; | ||
72 | } else { | ||
73 | return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); | ||
74 | } | ||
75 | |||
76 | // gaps ... current|all ... | ||
77 | const char *target_str = argv[1]; | ||
78 | enum {CURRENT, WORKSPACE, ALL} target; | ||
79 | if (strcasecmp(target_str, "current") == 0) { | ||
80 | target = CURRENT; | ||
81 | } else if (strcasecmp(target_str, "all") == 0) { | ||
82 | target = ALL; | ||
83 | } else if (strcasecmp(target_str, "workspace") == 0) { | ||
84 | if (inout == OUTER) { | ||
85 | target = CURRENT; | ||
86 | } else { | ||
87 | // Set gap for views in workspace | ||
88 | target = WORKSPACE; | ||
89 | } | ||
90 | } else { | ||
91 | return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); | ||
92 | } | ||
93 | |||
94 | // gaps ... n | ||
95 | amount_str = argv[3]; | ||
96 | int amount = (int)strtol(amount_str, NULL, 10); | ||
97 | if (errno == ERANGE) { | ||
98 | errno = 0; | ||
99 | return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); | ||
100 | } | ||
101 | |||
102 | // gaps ... set|plus|minus ... | ||
103 | const char *method_str = argv[2]; | ||
104 | enum {SET, ADD} method; | ||
105 | if (strcasecmp(method_str, "set") == 0) { | ||
106 | method = SET; | ||
107 | } else if (strcasecmp(method_str, "plus") == 0) { | ||
108 | method = ADD; | ||
109 | } else if (strcasecmp(method_str, "minus") == 0) { | ||
110 | method = ADD; | ||
111 | amount *= -1; | ||
112 | } else { | ||
113 | return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); | ||
114 | } | ||
115 | |||
116 | if (target == CURRENT) { | ||
117 | swayc_t *cont; | ||
118 | if (inout == OUTER) { | ||
119 | if ((cont = swayc_active_workspace()) == NULL) { | ||
120 | return cmd_results_new(CMD_FAILURE, "gaps", "There's no active workspace."); | ||
121 | } | ||
122 | } else { | ||
123 | if ((cont = get_focused_view(&root_container))->type != C_VIEW) { | ||
124 | return cmd_results_new(CMD_FAILURE, "gaps", "Currently focused item is not a view."); | ||
125 | } | ||
126 | } | ||
127 | cont->gaps = swayc_gap(cont); | ||
128 | if (method == SET) { | ||
129 | cont->gaps = amount; | ||
130 | } else if ((cont->gaps += amount) < 0) { | ||
131 | cont->gaps = 0; | ||
132 | } | ||
133 | arrange_windows(cont->parent, -1, -1); | ||
134 | } else if (inout == OUTER) { | ||
135 | //resize all workspace. | ||
136 | int i,j; | ||
137 | for (i = 0; i < root_container.children->length; ++i) { | ||
138 | swayc_t *op = root_container.children->items[i]; | ||
139 | for (j = 0; j < op->children->length; ++j) { | ||
140 | swayc_t *ws = op->children->items[j]; | ||
141 | if (method == SET) { | ||
142 | ws->gaps = amount; | ||
143 | } else if ((ws->gaps += amount) < 0) { | ||
144 | ws->gaps = 0; | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | arrange_windows(&root_container, -1, -1); | ||
149 | } else { | ||
150 | // Resize gaps for all views in workspace | ||
151 | swayc_t *top; | ||
152 | if (target == WORKSPACE) { | ||
153 | if ((top = swayc_active_workspace()) == NULL) { | ||
154 | return cmd_results_new(CMD_FAILURE, "gaps", "There's currently no active workspace."); | ||
155 | } | ||
156 | } else { | ||
157 | top = &root_container; | ||
158 | } | ||
159 | int top_gap = top->gaps; | ||
160 | container_map(top, method == SET ? set_gaps : add_gaps, &amount); | ||
161 | top->gaps = top_gap; | ||
162 | arrange_windows(top, -1, -1); | ||
163 | } | ||
164 | |||
165 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
166 | } | ||
diff --git a/sway/commands/hide_edge_borders.c b/sway/commands/hide_edge_borders.c deleted file mode 100644 index ee2a2644..00000000 --- a/sway/commands/hide_edge_borders.c +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if ((error = checkarg(argc, "hide_edge_borders", EXPECTED_EQUAL_TO, 1))) { | ||
8 | return error; | ||
9 | } | ||
10 | |||
11 | if (strcasecmp(argv[0], "none") == 0) { | ||
12 | config->hide_edge_borders = E_NONE; | ||
13 | } else if (strcasecmp(argv[0], "vertical") == 0) { | ||
14 | config->hide_edge_borders = E_VERTICAL; | ||
15 | } else if (strcasecmp(argv[0], "horizontal") == 0) { | ||
16 | config->hide_edge_borders = E_HORIZONTAL; | ||
17 | } else if (strcasecmp(argv[0], "both") == 0) { | ||
18 | config->hide_edge_borders = E_BOTH; | ||
19 | } else if (strcasecmp(argv[0], "smart") == 0) { | ||
20 | config->hide_edge_borders = E_SMART; | ||
21 | } else { | ||
22 | return cmd_results_new(CMD_INVALID, "hide_edge_borders", | ||
23 | "Expected 'hide_edge_borders <none|vertical|horizontal|both>'"); | ||
24 | } | ||
25 | |||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/include.c b/sway/commands/include.c deleted file mode 100644 index 1ba9a10d..00000000 --- a/sway/commands/include.c +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | #include "sway/commands.h" | ||
2 | #include "sway/config.h" | ||
3 | |||
4 | struct cmd_results *cmd_include(int argc, char **argv) { | ||
5 | struct cmd_results *error = NULL; | ||
6 | if ((error = checkarg(argc, "include", EXPECTED_EQUAL_TO, 1))) { | ||
7 | return error; | ||
8 | } | ||
9 | |||
10 | if (!load_include_configs(argv[0], config)) { | ||
11 | return cmd_results_new(CMD_INVALID, "include", "Failed to include sub configuration file: %s", argv[0]); | ||
12 | } | ||
13 | |||
14 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
15 | } | ||
diff --git a/sway/commands/input.c b/sway/commands/input.c deleted file mode 100644 index ad53d272..00000000 --- a/sway/commands/input.c +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *cmd_input(int argc, char **argv) { | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 2))) { | ||
10 | return error; | ||
11 | } | ||
12 | |||
13 | if (config->reading && strcmp("{", argv[1]) == 0) { | ||
14 | current_input_config = new_input_config(argv[0]); | ||
15 | sway_log(L_DEBUG, "entering input block: %s", current_input_config->identifier); | ||
16 | return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL); | ||
17 | } | ||
18 | |||
19 | if (argc > 2) { | ||
20 | int argc_new = argc-2; | ||
21 | char **argv_new = argv+2; | ||
22 | |||
23 | struct cmd_results *res; | ||
24 | current_input_config = new_input_config(argv[0]); | ||
25 | if (strcasecmp("accel_profile", argv[1]) == 0) { | ||
26 | res = input_cmd_accel_profile(argc_new, argv_new); | ||
27 | } else if (strcasecmp("click_method", argv[1]) == 0) { | ||
28 | res = input_cmd_click_method(argc_new, argv_new); | ||
29 | } else if (strcasecmp("drag_lock", argv[1]) == 0) { | ||
30 | res = input_cmd_drag_lock(argc_new, argv_new); | ||
31 | } else if (strcasecmp("dwt", argv[1]) == 0) { | ||
32 | res = input_cmd_dwt(argc_new, argv_new); | ||
33 | } else if (strcasecmp("events", argv[1]) == 0) { | ||
34 | res = input_cmd_events(argc_new, argv_new); | ||
35 | } else if (strcasecmp("left_handed", argv[1]) == 0) { | ||
36 | res = input_cmd_left_handed(argc_new, argv_new); | ||
37 | } else if (strcasecmp("middle_emulation", argv[1]) == 0) { | ||
38 | res = input_cmd_middle_emulation(argc_new, argv_new); | ||
39 | } else if (strcasecmp("natural_scroll", argv[1]) == 0) { | ||
40 | res = input_cmd_natural_scroll(argc_new, argv_new); | ||
41 | } else if (strcasecmp("pointer_accel", argv[1]) == 0) { | ||
42 | res = input_cmd_pointer_accel(argc_new, argv_new); | ||
43 | } else if (strcasecmp("scroll_method", argv[1]) == 0) { | ||
44 | res = input_cmd_scroll_method(argc_new, argv_new); | ||
45 | } else if (strcasecmp("tap", argv[1]) == 0) { | ||
46 | res = input_cmd_tap(argc_new, argv_new); | ||
47 | } else { | ||
48 | res = cmd_results_new(CMD_INVALID, "input <device>", "Unknown command %s", argv[1]); | ||
49 | } | ||
50 | current_input_config = NULL; | ||
51 | return res; | ||
52 | } | ||
53 | |||
54 | return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL); | ||
55 | } | ||
diff --git a/sway/commands/input/accel_profile.c b/sway/commands/input/accel_profile.c deleted file mode 100644 index 8288c1ad..00000000 --- a/sway/commands/input/accel_profile.c +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_accel_profile(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "accel_profile", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "accel_profile", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "adaptive") == 0) { | ||
17 | new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; | ||
18 | } else if (strcasecmp(argv[0], "flat") == 0) { | ||
19 | new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_INVALID, "accel_profile", | ||
22 | "Expected 'accel_profile <adaptive|flat>'"); | ||
23 | } | ||
24 | |||
25 | input_cmd_apply(new_config); | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/input/click_method.c b/sway/commands/input/click_method.c deleted file mode 100644 index 5e9d3dcb..00000000 --- a/sway/commands/input/click_method.c +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *input_cmd_click_method(int argc, char **argv) { | ||
8 | sway_log(L_DEBUG, "click_method for device: %d %s", current_input_config==NULL, current_input_config->identifier); | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "click_method", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | if (!current_input_config) { | ||
14 | return cmd_results_new(CMD_FAILURE, "click_method", "No input device defined."); | ||
15 | } | ||
16 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
17 | |||
18 | if (strcasecmp(argv[0], "none") == 0) { | ||
19 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE; | ||
20 | } else if (strcasecmp(argv[0], "button_areas") == 0) { | ||
21 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; | ||
22 | } else if (strcasecmp(argv[0], "clickfinger") == 0) { | ||
23 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; | ||
24 | } else { | ||
25 | return cmd_results_new(CMD_INVALID, "click_method", "Expected 'click_method <none|button_areas|clickfinger'"); | ||
26 | } | ||
27 | |||
28 | input_cmd_apply(new_config); | ||
29 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
30 | } | ||
diff --git a/sway/commands/input/drag_lock.c b/sway/commands/input/drag_lock.c deleted file mode 100644 index f5a7beb4..00000000 --- a/sway/commands/input/drag_lock.c +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_drag_lock(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "drag_lock", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "drag_lock", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
17 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; | ||
18 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
19 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_INVALID, "drag_lock", "Expected 'drag_lock <enabled|disabled>'"); | ||
22 | } | ||
23 | |||
24 | input_cmd_apply(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/input/dwt.c b/sway/commands/input/dwt.c deleted file mode 100644 index 557b2207..00000000 --- a/sway/commands/input/dwt.c +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_dwt(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "dwt", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "dwt", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
17 | new_config->dwt = LIBINPUT_CONFIG_DWT_ENABLED; | ||
18 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
19 | new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_INVALID, "dwt", "Expected 'dwt <enabled|disabled>'"); | ||
22 | } | ||
23 | |||
24 | input_cmd_apply(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c deleted file mode 100644 index 9d54287a..00000000 --- a/sway/commands/input/events.c +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *input_cmd_events(int argc, char **argv) { | ||
8 | sway_log(L_DEBUG, "events for device: %s", current_input_config->identifier); | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | if (!current_input_config) { | ||
14 | return cmd_results_new(CMD_FAILURE, "events", "No input device defined."); | ||
15 | } | ||
16 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
17 | |||
18 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
19 | new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; | ||
20 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
21 | new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; | ||
22 | } else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) { | ||
23 | new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; | ||
24 | } else { | ||
25 | return cmd_results_new(CMD_INVALID, "events", "Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); | ||
26 | } | ||
27 | |||
28 | input_cmd_apply(new_config); | ||
29 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
30 | } | ||
diff --git a/sway/commands/input/left_handed.c b/sway/commands/input/left_handed.c deleted file mode 100644 index 6c913e70..00000000 --- a/sway/commands/input/left_handed.c +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_left_handed(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "left_handed", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "left_handed", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
17 | new_config->left_handed = 1; | ||
18 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
19 | new_config->left_handed = 0; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_INVALID, "left_handed", "Expected 'left_handed <enabled|disabled>'"); | ||
22 | } | ||
23 | |||
24 | input_cmd_apply(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/input/middle_emulation.c b/sway/commands/input/middle_emulation.c deleted file mode 100644 index 33cdd7d6..00000000 --- a/sway/commands/input/middle_emulation.c +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "middle_emulation", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "middle_emulation", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
17 | new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; | ||
18 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
19 | new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_INVALID, "middle_emulation", "Expected 'middle_emulation <enabled|disabled>'"); | ||
22 | } | ||
23 | |||
24 | input_cmd_apply(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/input/natural_scroll.c b/sway/commands/input/natural_scroll.c deleted file mode 100644 index 7bc8b8d0..00000000 --- a/sway/commands/input/natural_scroll.c +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "natural_scoll", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
17 | new_config->natural_scroll = 1; | ||
18 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
19 | new_config->natural_scroll = 0; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_INVALID, "natural_scroll", "Expected 'natural_scroll <enabled|disabled>'"); | ||
22 | } | ||
23 | |||
24 | input_cmd_apply(new_config); | ||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/input/pointer_accel.c b/sway/commands/input/pointer_accel.c deleted file mode 100644 index 94f595d1..00000000 --- a/sway/commands/input/pointer_accel.c +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "pointer_accel", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "pointer_accel", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | float pointer_accel = atof(argv[0]); | ||
17 | if (pointer_accel < -1 || pointer_accel > 1) { | ||
18 | return cmd_results_new(CMD_INVALID, "pointer_accel", "Input out of range [-1, 1]"); | ||
19 | } | ||
20 | new_config->pointer_accel = pointer_accel; | ||
21 | |||
22 | input_cmd_apply(new_config); | ||
23 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
24 | } | ||
diff --git a/sway/commands/input/scroll_method.c b/sway/commands/input/scroll_method.c deleted file mode 100644 index 5c6c3d7a..00000000 --- a/sway/commands/input/scroll_method.c +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input.h" | ||
5 | |||
6 | struct cmd_results *input_cmd_scroll_method(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "scroll_method", EXPECTED_AT_LEAST, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!current_input_config) { | ||
12 | return cmd_results_new(CMD_FAILURE, "scroll_method", "No input device defined."); | ||
13 | } | ||
14 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
15 | |||
16 | if (strcasecmp(argv[0], "none") == 0) { | ||
17 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; | ||
18 | } else if (strcasecmp(argv[0], "two_finger") == 0) { | ||
19 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG; | ||
20 | } else if (strcasecmp(argv[0], "edge") == 0) { | ||
21 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE; | ||
22 | } else if (strcasecmp(argv[0], "on_button_down") == 0) { | ||
23 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; | ||
24 | } else { | ||
25 | return cmd_results_new(CMD_INVALID, "scroll_method", "Expected 'scroll_method <none|two_finger|edge|on_button_down>'"); | ||
26 | } | ||
27 | |||
28 | input_cmd_apply(new_config); | ||
29 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
30 | } | ||
diff --git a/sway/commands/input/tap.c b/sway/commands/input/tap.c deleted file mode 100644 index 9e3ca2af..00000000 --- a/sway/commands/input/tap.c +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *input_cmd_tap(int argc, char **argv) { | ||
8 | sway_log(L_DEBUG, "tap for device: %s", current_input_config->identifier); | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "tap", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | if (!current_input_config) { | ||
14 | return cmd_results_new(CMD_FAILURE, "tap", "No input device defined."); | ||
15 | } | ||
16 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
17 | |||
18 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
19 | new_config->tap = LIBINPUT_CONFIG_TAP_ENABLED; | ||
20 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
21 | new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED; | ||
22 | } else { | ||
23 | return cmd_results_new(CMD_INVALID, "tap", "Expected 'tap <enabled|disabled>'"); | ||
24 | } | ||
25 | |||
26 | sway_log(L_DEBUG, "apply-tap for device: %s", current_input_config->identifier); | ||
27 | input_cmd_apply(new_config); | ||
28 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
29 | } | ||
diff --git a/sway/commands/ipc.c b/sway/commands/ipc.c deleted file mode 100644 index 0c678961..00000000 --- a/sway/commands/ipc.c +++ /dev/null | |||
@@ -1,162 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <stdio.h> | ||
3 | #include <string.h> | ||
4 | #include "sway/security.h" | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/config.h" | ||
7 | #include "ipc.h" | ||
8 | #include "log.h" | ||
9 | #include "util.h" | ||
10 | |||
11 | static struct ipc_policy *current_policy = NULL; | ||
12 | |||
13 | struct cmd_results *cmd_ipc(int argc, char **argv) { | ||
14 | struct cmd_results *error = NULL; | ||
15 | if ((error = checkarg(argc, "ipc", EXPECTED_EQUAL_TO, 2))) { | ||
16 | return error; | ||
17 | } | ||
18 | if ((error = check_security_config())) { | ||
19 | return error; | ||
20 | } | ||
21 | |||
22 | char *program = NULL; | ||
23 | |||
24 | if (!strcmp(argv[0], "*")) { | ||
25 | program = strdup(argv[0]); | ||
26 | } else if (!(program = resolve_path(argv[0]))) { | ||
27 | return cmd_results_new( | ||
28 | CMD_INVALID, "ipc", "Unable to resolve IPC Policy target."); | ||
29 | } | ||
30 | if (config->reading && strcmp("{", argv[1]) != 0) { | ||
31 | return cmd_results_new(CMD_INVALID, "ipc", | ||
32 | "Expected '{' at start of IPC config definition."); | ||
33 | } | ||
34 | |||
35 | if (!config->reading) { | ||
36 | return cmd_results_new(CMD_FAILURE, "ipc", "Can only be used in config file."); | ||
37 | } | ||
38 | |||
39 | current_policy = alloc_ipc_policy(program); | ||
40 | list_add(config->ipc_policies, current_policy); | ||
41 | |||
42 | free(program); | ||
43 | return cmd_results_new(CMD_BLOCK_IPC, NULL, NULL); | ||
44 | } | ||
45 | |||
46 | struct cmd_results *cmd_ipc_events(int argc, char **argv) { | ||
47 | struct cmd_results *error = NULL; | ||
48 | if ((error = checkarg(argc, "events", EXPECTED_EQUAL_TO, 1))) { | ||
49 | return error; | ||
50 | } | ||
51 | |||
52 | if (config->reading && strcmp("{", argv[0]) != 0) { | ||
53 | return cmd_results_new(CMD_INVALID, "events", | ||
54 | "Expected '{' at start of IPC event config definition."); | ||
55 | } | ||
56 | |||
57 | if (!config->reading) { | ||
58 | return cmd_results_new(CMD_FAILURE, "events", "Can only be used in config file."); | ||
59 | } | ||
60 | |||
61 | return cmd_results_new(CMD_BLOCK_IPC_EVENTS, NULL, NULL); | ||
62 | } | ||
63 | |||
64 | struct cmd_results *cmd_ipc_cmd(int argc, char **argv) { | ||
65 | struct cmd_results *error = NULL; | ||
66 | if ((error = checkarg(argc, "ipc", EXPECTED_EQUAL_TO, 1))) { | ||
67 | return error; | ||
68 | } | ||
69 | |||
70 | bool enabled; | ||
71 | if (strcmp(argv[0], "enabled") == 0) { | ||
72 | enabled = true; | ||
73 | } else if (strcmp(argv[0], "disabled") == 0) { | ||
74 | enabled = false; | ||
75 | } else { | ||
76 | return cmd_results_new(CMD_INVALID, argv[-1], | ||
77 | "Argument must be one of 'enabled' or 'disabled'"); | ||
78 | } | ||
79 | |||
80 | struct { | ||
81 | char *name; | ||
82 | enum ipc_feature type; | ||
83 | } types[] = { | ||
84 | { "*", IPC_FEATURE_ALL_COMMANDS }, | ||
85 | { "command", IPC_FEATURE_COMMAND }, | ||
86 | { "workspaces", IPC_FEATURE_GET_WORKSPACES }, | ||
87 | { "outputs", IPC_FEATURE_GET_OUTPUTS }, | ||
88 | { "tree", IPC_FEATURE_GET_TREE }, | ||
89 | { "marks", IPC_FEATURE_GET_MARKS }, | ||
90 | { "bar-config", IPC_FEATURE_GET_BAR_CONFIG }, | ||
91 | { "inputs", IPC_FEATURE_GET_INPUTS }, | ||
92 | { "clipboard", IPC_FEATURE_GET_CLIPBOARD }, | ||
93 | }; | ||
94 | |||
95 | uint32_t type = 0; | ||
96 | |||
97 | for (size_t i = 0; i < sizeof(types) / sizeof(types[0]); ++i) { | ||
98 | if (strcmp(types[i].name, argv[-1]) == 0) { | ||
99 | type = types[i].type; | ||
100 | break; | ||
101 | } | ||
102 | } | ||
103 | |||
104 | if (enabled) { | ||
105 | current_policy->features |= type; | ||
106 | sway_log(L_DEBUG, "Enabled IPC %s feature", argv[-1]); | ||
107 | } else { | ||
108 | current_policy->features &= ~type; | ||
109 | sway_log(L_DEBUG, "Disabled IPC %s feature", argv[-1]); | ||
110 | } | ||
111 | |||
112 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
113 | } | ||
114 | |||
115 | struct cmd_results *cmd_ipc_event_cmd(int argc, char **argv) { | ||
116 | struct cmd_results *error = NULL; | ||
117 | if ((error = checkarg(argc, "ipc", EXPECTED_EQUAL_TO, 1))) { | ||
118 | return error; | ||
119 | } | ||
120 | |||
121 | bool enabled; | ||
122 | if (strcmp(argv[0], "enabled") == 0) { | ||
123 | enabled = true; | ||
124 | } else if (strcmp(argv[0], "disabled") == 0) { | ||
125 | enabled = false; | ||
126 | } else { | ||
127 | return cmd_results_new(CMD_INVALID, argv[-1], | ||
128 | "Argument must be one of 'enabled' or 'disabled'"); | ||
129 | } | ||
130 | |||
131 | struct { | ||
132 | char *name; | ||
133 | enum ipc_feature type; | ||
134 | } types[] = { | ||
135 | { "*", IPC_FEATURE_ALL_EVENTS }, | ||
136 | { "workspace", IPC_FEATURE_EVENT_WORKSPACE }, | ||
137 | { "output", IPC_FEATURE_EVENT_OUTPUT }, | ||
138 | { "mode", IPC_FEATURE_EVENT_MODE }, | ||
139 | { "window", IPC_FEATURE_EVENT_WINDOW }, | ||
140 | { "binding", IPC_FEATURE_EVENT_BINDING }, | ||
141 | { "input", IPC_FEATURE_EVENT_INPUT }, | ||
142 | }; | ||
143 | |||
144 | uint32_t type = 0; | ||
145 | |||
146 | for (size_t i = 0; i < sizeof(types) / sizeof(types[0]); ++i) { | ||
147 | if (strcmp(types[i].name, argv[-1]) == 0) { | ||
148 | type = types[i].type; | ||
149 | break; | ||
150 | } | ||
151 | } | ||
152 | |||
153 | if (enabled) { | ||
154 | current_policy->features |= type; | ||
155 | sway_log(L_DEBUG, "Enabled IPC %s event", argv[-1]); | ||
156 | } else { | ||
157 | current_policy->features &= ~type; | ||
158 | sway_log(L_DEBUG, "Disabled IPC %s event", argv[-1]); | ||
159 | } | ||
160 | |||
161 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
162 | } | ||
diff --git a/sway/commands/kill.c b/sway/commands/kill.c deleted file mode 100644 index 742e2b86..00000000 --- a/sway/commands/kill.c +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | #include "sway/commands.h" | ||
2 | #include "sway/container.h" | ||
3 | #include "sway/focus.h" | ||
4 | |||
5 | struct cmd_results *cmd_kill(int argc, char **argv) { | ||
6 | if (config->reading) return cmd_results_new(CMD_FAILURE, "kill", "Can't be used in config file."); | ||
7 | if (!config->active) return cmd_results_new(CMD_FAILURE, "kill", "Can only be used when sway is running."); | ||
8 | |||
9 | swayc_t *container = current_container; | ||
10 | close_views(container); | ||
11 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
12 | } | ||
diff --git a/sway/commands/layout.c b/sway/commands/layout.c deleted file mode 100644 index 57a86565..00000000 --- a/sway/commands/layout.c +++ /dev/null | |||
@@ -1,196 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/container.h" | ||
5 | #include "sway/layout.h" | ||
6 | |||
7 | /** | ||
8 | * handle "layout auto" command group | ||
9 | */ | ||
10 | static struct cmd_results *cmd_layout_auto(swayc_t *container, int argc, char **argv); | ||
11 | |||
12 | struct cmd_results *cmd_layout(int argc, char **argv) { | ||
13 | struct cmd_results *error = NULL; | ||
14 | if (config->reading) return cmd_results_new(CMD_FAILURE, "layout", "Can't be used in config file."); | ||
15 | if (!config->active) return cmd_results_new(CMD_FAILURE, "layout", "Can only be used when sway is running."); | ||
16 | if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) { | ||
17 | return error; | ||
18 | } | ||
19 | swayc_t *parent = current_container; | ||
20 | if (parent->is_floating) { | ||
21 | return cmd_results_new(CMD_FAILURE, "layout", "Unable to change layout of floating windows"); | ||
22 | } | ||
23 | |||
24 | while (parent->type == C_VIEW) { | ||
25 | parent = parent->parent; | ||
26 | } | ||
27 | |||
28 | enum swayc_layouts old_layout = parent->layout; | ||
29 | |||
30 | if (strcasecmp(argv[0], "default") == 0) { | ||
31 | swayc_change_layout(parent, parent->prev_layout); | ||
32 | if (parent->layout == L_NONE) { | ||
33 | swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT); | ||
34 | swayc_change_layout(parent, default_layout(output)); | ||
35 | } | ||
36 | } else { | ||
37 | if (parent->layout != L_TABBED && parent->layout != L_STACKED) { | ||
38 | parent->prev_layout = parent->layout; | ||
39 | } | ||
40 | |||
41 | if (strcasecmp(argv[0], "tabbed") == 0) { | ||
42 | if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)){ | ||
43 | parent = new_container(parent, L_TABBED); | ||
44 | } | ||
45 | |||
46 | swayc_change_layout(parent, L_TABBED); | ||
47 | } else if (strcasecmp(argv[0], "stacking") == 0) { | ||
48 | if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)) { | ||
49 | parent = new_container(parent, L_STACKED); | ||
50 | } | ||
51 | |||
52 | swayc_change_layout(parent, L_STACKED); | ||
53 | } else if (strcasecmp(argv[0], "splith") == 0) { | ||
54 | swayc_change_layout(parent, L_HORIZ); | ||
55 | } else if (strcasecmp(argv[0], "splitv") == 0) { | ||
56 | swayc_change_layout(parent, L_VERT); | ||
57 | } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { | ||
58 | if (parent->layout == L_HORIZ && (parent->workspace_layout == L_NONE | ||
59 | || parent->workspace_layout == L_HORIZ)) { | ||
60 | swayc_change_layout(parent, L_VERT); | ||
61 | } else { | ||
62 | swayc_change_layout(parent, L_HORIZ); | ||
63 | } | ||
64 | } else if (strcasecmp(argv[0], "auto") == 0) { | ||
65 | return cmd_layout_auto(parent, argc, argv); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | update_layout_geometry(parent, old_layout); | ||
70 | update_geometry(parent); | ||
71 | |||
72 | arrange_windows(parent, parent->width, parent->height); | ||
73 | |||
74 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
75 | } | ||
76 | |||
77 | static struct cmd_results *cmd_layout_auto(swayc_t *container, int argc, char **argv) { | ||
78 | // called after checking that argv[0] is auto, so just continue parsing from there | ||
79 | struct cmd_results *error = NULL; | ||
80 | const char *cmd_name = "layout auto"; | ||
81 | const char *set_inc_cmd_name = "layout auto [master|ncol] [set|inc]"; | ||
82 | const char *err_msg = "Allowed arguments are <right|left|top|bottom|next|prev|master|ncol>"; | ||
83 | |||
84 | bool need_layout_update = false; | ||
85 | enum swayc_layouts old_layout = container->layout; | ||
86 | enum swayc_layouts layout = old_layout; | ||
87 | |||
88 | if ((error = checkarg(argc, "layout auto", EXPECTED_MORE_THAN, 1))) { | ||
89 | return error; | ||
90 | } | ||
91 | |||
92 | if (strcasecmp(argv[1], "left") == 0) { | ||
93 | layout = L_AUTO_LEFT; | ||
94 | } else if (strcasecmp(argv[1], "right") == 0) { | ||
95 | layout = L_AUTO_RIGHT; | ||
96 | } else if (strcasecmp(argv[1], "top") == 0) { | ||
97 | layout = L_AUTO_TOP; | ||
98 | } else if (strcasecmp(argv[1], "bottom") == 0) { | ||
99 | layout = L_AUTO_BOTTOM; | ||
100 | } else if (strcasecmp(argv[1], "next") == 0) { | ||
101 | if (is_auto_layout(container->layout) && container->layout < L_AUTO_LAST) { | ||
102 | layout = container->layout + 1; | ||
103 | } else { | ||
104 | layout = L_AUTO_FIRST; | ||
105 | } | ||
106 | } else if (strcasecmp(argv[1], "prev") == 0) { | ||
107 | if (is_auto_layout(container->layout) && container->layout > L_AUTO_FIRST) { | ||
108 | layout = container->layout - 1; | ||
109 | } else { | ||
110 | layout = L_AUTO_LAST; | ||
111 | } | ||
112 | } else { | ||
113 | bool is_nmaster; | ||
114 | bool is_set; | ||
115 | if (strcasecmp(argv[1], "master") == 0) { | ||
116 | is_nmaster = true; | ||
117 | } else if (strcasecmp(argv[1], "ncol") == 0) { | ||
118 | is_nmaster = false; | ||
119 | } else { | ||
120 | return cmd_results_new(CMD_INVALID, cmd_name, "Invalid %s command. %s", | ||
121 | cmd_name, err_msg); | ||
122 | } | ||
123 | if ((error = checkarg(argc, "auto <master|ncol>", EXPECTED_EQUAL_TO, 4))) { | ||
124 | return error; | ||
125 | } | ||
126 | if (strcasecmp(argv[2], "set") == 0) { | ||
127 | is_set = true; | ||
128 | } else if (strcasecmp(argv[2], "inc") == 0) { | ||
129 | is_set = false; | ||
130 | } else { | ||
131 | return cmd_results_new(CMD_INVALID, set_inc_cmd_name, "Invalid %s command. %s, " | ||
132 | "Argument must be on of <set|inc>", | ||
133 | set_inc_cmd_name); | ||
134 | } | ||
135 | char *end; | ||
136 | int n = (int)strtol(argv[3], &end, 10); | ||
137 | if (*end) { | ||
138 | return cmd_results_new(CMD_INVALID, set_inc_cmd_name, "Invalid %s command " | ||
139 | "(argument must be an integer)", set_inc_cmd_name); | ||
140 | } | ||
141 | if (is_auto_layout(container->layout)) { | ||
142 | int inc = 0; /* difference between current master/ncol and requested value */ | ||
143 | if (is_nmaster) { | ||
144 | if (is_set) { | ||
145 | if (n < 0) { | ||
146 | return cmd_results_new(CMD_INVALID, set_inc_cmd_name, "Invalid %s command " | ||
147 | "(master must be >= 0)", set_inc_cmd_name); | ||
148 | } | ||
149 | inc = n - (int)container->nb_master; | ||
150 | } else { /* inc command */ | ||
151 | if ((int)container->nb_master + n >= 0) { | ||
152 | inc = n; | ||
153 | } | ||
154 | } | ||
155 | if (inc) { | ||
156 | for (int i = container->nb_master; | ||
157 | i >= 0 && i < container->children->length | ||
158 | && i != (int)container->nb_master + inc;) { | ||
159 | ((swayc_t *)container->children->items[i])->height = -1; | ||
160 | ((swayc_t *)container->children->items[i])->width = -1; | ||
161 | i += inc > 0 ? 1 : -1; | ||
162 | } | ||
163 | container->nb_master += inc; | ||
164 | need_layout_update = true; | ||
165 | } | ||
166 | } else { /* ncol modification */ | ||
167 | if (is_set) { | ||
168 | if (n <= 0) { | ||
169 | return cmd_results_new(CMD_INVALID, set_inc_cmd_name, "Invalid %s command " | ||
170 | "(ncol must be > 0)", set_inc_cmd_name); | ||
171 | } | ||
172 | inc = n - (int)container->nb_slave_groups; | ||
173 | } else { /* inc command */ | ||
174 | if ((int)container->nb_slave_groups + n > 0) { | ||
175 | inc = n; | ||
176 | } | ||
177 | } | ||
178 | if (inc) { | ||
179 | container->nb_slave_groups += inc; | ||
180 | need_layout_update = true; | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | } | ||
185 | |||
186 | if (layout != old_layout) { | ||
187 | swayc_change_layout(container, layout); | ||
188 | update_layout_geometry(container, old_layout); | ||
189 | need_layout_update = true; | ||
190 | } | ||
191 | if (need_layout_update) { | ||
192 | update_geometry(container); | ||
193 | arrange_windows(container, container->width, container->height); | ||
194 | } | ||
195 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
196 | } | ||
diff --git a/sway/commands/log_colors.c b/sway/commands/log_colors.c deleted file mode 100644 index 815d1942..00000000 --- a/sway/commands/log_colors.c +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *cmd_log_colors(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if (!config->reading) return cmd_results_new(CMD_FAILURE, "log_colors", "Can only be used in config file."); | ||
9 | if ((error = checkarg(argc, "log_colors", EXPECTED_EQUAL_TO, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | if (strcasecmp(argv[0], "no") == 0) { | ||
13 | sway_log_colors(0); | ||
14 | } else if (strcasecmp(argv[0], "yes") == 0) { | ||
15 | sway_log_colors(1); | ||
16 | } else { | ||
17 | error = cmd_results_new(CMD_FAILURE, "log_colors", | ||
18 | "Invalid log_colors command (expected `yes` or `no`, got '%s')", argv[0]); | ||
19 | return error; | ||
20 | } | ||
21 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
22 | } | ||
diff --git a/sway/commands/mark.c b/sway/commands/mark.c deleted file mode 100644 index c1d959df..00000000 --- a/sway/commands/mark.c +++ /dev/null | |||
@@ -1,87 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include <stdbool.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "list.h" | ||
6 | #include "stringop.h" | ||
7 | |||
8 | static void find_marks_callback(swayc_t *container, void *_mark) { | ||
9 | char *mark = (char *)_mark; | ||
10 | |||
11 | int index; | ||
12 | if (container->marks && ((index = list_seq_find(container->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1)) { | ||
13 | list_del(container->marks, index); | ||
14 | } | ||
15 | } | ||
16 | |||
17 | struct cmd_results *cmd_mark(int argc, char **argv) { | ||
18 | struct cmd_results *error = NULL; | ||
19 | if (config->reading) return cmd_results_new(CMD_FAILURE, "mark", "Can't be used in config file."); | ||
20 | if ((error = checkarg(argc, "mark", EXPECTED_AT_LEAST, 1))) { | ||
21 | return error; | ||
22 | } | ||
23 | |||
24 | swayc_t *view = current_container; | ||
25 | bool add = false; | ||
26 | bool toggle = false; | ||
27 | |||
28 | if (strcmp(argv[0], "--add") == 0) { | ||
29 | --argc; ++argv; | ||
30 | add = true; | ||
31 | } else if (strcmp(argv[0], "--replace") == 0) { | ||
32 | --argc; ++argv; | ||
33 | } | ||
34 | |||
35 | if (argc && strcmp(argv[0], "--toggle") == 0) { | ||
36 | --argc; ++argv; | ||
37 | toggle = true; | ||
38 | } | ||
39 | |||
40 | if (argc) { | ||
41 | char *mark = join_args(argv, argc); | ||
42 | |||
43 | // Remove all existing marks of this type | ||
44 | container_map(&root_container, find_marks_callback, mark); | ||
45 | |||
46 | if (view->marks) { | ||
47 | if (add) { | ||
48 | int index; | ||
49 | if ((index = list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1) { | ||
50 | if (toggle) { | ||
51 | free(view->marks->items[index]); | ||
52 | list_del(view->marks, index); | ||
53 | |||
54 | if (0 == view->marks->length) { | ||
55 | list_free(view->marks); | ||
56 | view->marks = NULL; | ||
57 | } | ||
58 | } | ||
59 | free(mark); | ||
60 | } else { | ||
61 | list_add(view->marks, mark); | ||
62 | } | ||
63 | } else { | ||
64 | if (toggle && list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark) != -1) { | ||
65 | // Delete the list | ||
66 | list_foreach(view->marks, free); | ||
67 | list_free(view->marks); | ||
68 | view->marks = NULL; | ||
69 | } else { | ||
70 | // Delete and replace with a new list | ||
71 | list_foreach(view->marks, free); | ||
72 | list_free(view->marks); | ||
73 | |||
74 | view->marks = create_list(); | ||
75 | list_add(view->marks, mark); | ||
76 | } | ||
77 | } | ||
78 | } else { | ||
79 | view->marks = create_list(); | ||
80 | list_add(view->marks, mark); | ||
81 | } | ||
82 | } else { | ||
83 | return cmd_results_new(CMD_FAILURE, "mark", | ||
84 | "Expected 'mark [--add|--replace] [--toggle] <mark>'"); | ||
85 | } | ||
86 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
87 | } | ||
diff --git a/sway/commands/mode.c b/sway/commands/mode.c deleted file mode 100644 index d2985c54..00000000 --- a/sway/commands/mode.c +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <stdbool.h> | ||
3 | #include <string.h> | ||
4 | #include <strings.h> | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/config.h" | ||
7 | #include "sway/ipc-server.h" | ||
8 | #include "list.h" | ||
9 | #include "log.h" | ||
10 | |||
11 | struct cmd_results *cmd_mode(int argc, char **argv) { | ||
12 | struct cmd_results *error = NULL; | ||
13 | if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) { | ||
14 | return error; | ||
15 | } | ||
16 | |||
17 | const char *mode_name = argv[0]; | ||
18 | bool mode_make = (argc == 2 && strcmp(argv[1], "{") == 0); | ||
19 | if (mode_make) { | ||
20 | if (!config->reading) | ||
21 | return cmd_results_new(CMD_FAILURE, "mode", "Can only be used in config file."); | ||
22 | } | ||
23 | struct sway_mode *mode = NULL; | ||
24 | // Find mode | ||
25 | int i, len = config->modes->length; | ||
26 | for (i = 0; i < len; ++i) { | ||
27 | struct sway_mode *find = config->modes->items[i]; | ||
28 | if (strcasecmp(find->name, mode_name) == 0) { | ||
29 | mode = find; | ||
30 | break; | ||
31 | } | ||
32 | } | ||
33 | // Create mode if it doesn't exist | ||
34 | if (!mode && mode_make) { | ||
35 | mode = malloc(sizeof(struct sway_mode)); | ||
36 | if (!mode) { | ||
37 | return cmd_results_new(CMD_FAILURE, "mode", "Unable to allocate mode"); | ||
38 | } | ||
39 | mode->name = strdup(mode_name); | ||
40 | mode->bindings = create_list(); | ||
41 | list_add(config->modes, mode); | ||
42 | } | ||
43 | if (!mode) { | ||
44 | error = cmd_results_new(CMD_INVALID, "mode", "Unknown mode `%s'", mode_name); | ||
45 | return error; | ||
46 | } | ||
47 | if ((config->reading && mode_make) || (!config->reading && !mode_make)) { | ||
48 | sway_log(L_DEBUG, "Switching to mode `%s'",mode->name); | ||
49 | } | ||
50 | // Set current mode | ||
51 | config->current_mode = mode; | ||
52 | if (!mode_make) { | ||
53 | // trigger IPC mode event | ||
54 | ipc_event_mode(config->current_mode->name); | ||
55 | } | ||
56 | return cmd_results_new(mode_make ? CMD_BLOCK_MODE : CMD_SUCCESS, NULL, NULL); | ||
57 | } | ||
diff --git a/sway/commands/mouse_warping.c b/sway/commands/mouse_warping.c deleted file mode 100644 index 5596d483..00000000 --- a/sway/commands/mouse_warping.c +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *cmd_mouse_warping(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) { | ||
8 | return error; | ||
9 | } else if (strcasecmp(argv[0], "output") == 0) { | ||
10 | config->mouse_warping = true; | ||
11 | } else if (strcasecmp(argv[0], "none") == 0) { | ||
12 | config->mouse_warping = false; | ||
13 | } else { | ||
14 | return cmd_results_new(CMD_FAILURE, "mouse_warping", "Expected 'mouse_warping output|none'"); | ||
15 | } | ||
16 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
17 | } | ||
diff --git a/sway/commands/move.c b/sway/commands/move.c deleted file mode 100644 index 52c73e22..00000000 --- a/sway/commands/move.c +++ /dev/null | |||
@@ -1,189 +0,0 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include <wlc/wlc.h> | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/container.h" | ||
7 | #include "sway/layout.h" | ||
8 | #include "sway/output.h" | ||
9 | #include "sway/workspace.h" | ||
10 | #include "list.h" | ||
11 | #include "stringop.h" | ||
12 | |||
13 | struct cmd_results *cmd_move(int argc, char **argv) { | ||
14 | struct cmd_results *error = NULL; | ||
15 | int move_amt = 10; | ||
16 | |||
17 | if (config->reading) return cmd_results_new(CMD_FAILURE, "move", "Can't be used in config file."); | ||
18 | if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { | ||
19 | return error; | ||
20 | } | ||
21 | const char* expected_syntax = "Expected 'move <left|right|up|down|next|prev|first> <[px] px>' or " | ||
22 | "'move <container|window> to workspace <name>' or " | ||
23 | "'move <container|window|workspace> to output <name|direction>' or " | ||
24 | "'move position mouse'"; | ||
25 | swayc_t *view = current_container; | ||
26 | |||
27 | if (argc == 2 || (argc == 3 && strcasecmp(argv[2], "px") == 0 )) { | ||
28 | char *inv; | ||
29 | move_amt = (int)strtol(argv[1], &inv, 10); | ||
30 | if (*inv != '\0' && strcasecmp(inv, "px") != 0) { | ||
31 | move_amt = 10; | ||
32 | } | ||
33 | } | ||
34 | |||
35 | if (strcasecmp(argv[0], "left") == 0) { | ||
36 | move_container(view, MOVE_LEFT, move_amt); | ||
37 | } else if (strcasecmp(argv[0], "right") == 0) { | ||
38 | move_container(view, MOVE_RIGHT, move_amt); | ||
39 | } else if (strcasecmp(argv[0], "up") == 0) { | ||
40 | move_container(view, MOVE_UP, move_amt); | ||
41 | } else if (strcasecmp(argv[0], "down") == 0) { | ||
42 | move_container(view, MOVE_DOWN, move_amt); | ||
43 | } else if (strcasecmp(argv[0], "next") == 0) { | ||
44 | move_container(view, MOVE_NEXT, move_amt); | ||
45 | } else if (strcasecmp(argv[0], "prev") == 0) { | ||
46 | move_container(view, MOVE_PREV, move_amt); | ||
47 | } else if (strcasecmp(argv[0], "first") == 0) { | ||
48 | move_container(view, MOVE_FIRST, move_amt); | ||
49 | } else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) { | ||
50 | // "move container ... | ||
51 | if ((error = checkarg(argc, "move container/window", EXPECTED_AT_LEAST, 4))) { | ||
52 | return error; | ||
53 | } else if (strcasecmp(argv[1], "to") == 0 && strcasecmp(argv[2], "workspace") == 0) { | ||
54 | // move container to workspace x | ||
55 | if (view->type == C_WORKSPACE) { | ||
56 | if (!view->children || view->children->length == 0) { | ||
57 | return cmd_results_new(CMD_FAILURE, "move", "Cannot move an empty workspace"); | ||
58 | } | ||
59 | view = new_container(view, view->workspace_layout); | ||
60 | } if (view->type != C_CONTAINER && view->type != C_VIEW) { | ||
61 | return cmd_results_new(CMD_FAILURE, "move", "Can only move containers and views."); | ||
62 | } | ||
63 | |||
64 | swayc_t *ws; | ||
65 | const char *num_name = NULL; | ||
66 | char *ws_name = NULL; | ||
67 | if (argc == 5 && strcasecmp(argv[3], "number") == 0) { | ||
68 | // move "container to workspace number x" | ||
69 | num_name = argv[4]; | ||
70 | ws = workspace_by_number(num_name); | ||
71 | } else { | ||
72 | ws_name = join_args(argv + 3, argc - 3); | ||
73 | ws = workspace_by_name(ws_name); | ||
74 | } | ||
75 | |||
76 | if (ws == NULL) { | ||
77 | ws = workspace_create(ws_name ? ws_name : num_name); | ||
78 | } | ||
79 | if (ws_name) { | ||
80 | free(ws_name); | ||
81 | } | ||
82 | move_container_to(view, get_focused_container(ws)); | ||
83 | } else if (strcasecmp(argv[1], "to") == 0 && strcasecmp(argv[2], "output") == 0) { | ||
84 | // move container to output x | ||
85 | swayc_t *output = NULL; | ||
86 | struct wlc_point abs_pos; | ||
87 | get_absolute_center_position(view, &abs_pos); | ||
88 | if (view->type == C_WORKSPACE) { | ||
89 | if (!view->children || view->children->length == 0) { | ||
90 | return cmd_results_new(CMD_FAILURE, "move", "Cannot move an empty workspace"); | ||
91 | } | ||
92 | view = new_container(view, view->workspace_layout); | ||
93 | } else if (view->type != C_CONTAINER && view->type != C_VIEW) { | ||
94 | return cmd_results_new(CMD_FAILURE, "move", "Can only move containers and views."); | ||
95 | } else if (!(output = output_by_name(argv[3], &abs_pos))) { | ||
96 | return cmd_results_new(CMD_FAILURE, "move", | ||
97 | "Can't find output with name/direction '%s' @ (%i,%i)", argv[3], abs_pos.x, abs_pos.y); | ||
98 | } | ||
99 | |||
100 | swayc_t *container = get_focused_container(output); | ||
101 | if (container->is_floating) { | ||
102 | move_container_to(view, container->parent); | ||
103 | } else { | ||
104 | move_container_to(view, container); | ||
105 | } | ||
106 | } else { | ||
107 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
108 | } | ||
109 | } else if (strcasecmp(argv[0], "workspace") == 0) { | ||
110 | // move workspace (to output x) | ||
111 | swayc_t *output = NULL; | ||
112 | struct wlc_point abs_pos; | ||
113 | get_absolute_center_position(view, &abs_pos); | ||
114 | if ((error = checkarg(argc, "move workspace", EXPECTED_EQUAL_TO, 4))) { | ||
115 | return error; | ||
116 | } else if (strcasecmp(argv[1], "to") != 0 || strcasecmp(argv[2], "output") != 0) { | ||
117 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
118 | } else if (!(output = output_by_name(argv[3], &abs_pos))) { | ||
119 | return cmd_results_new(CMD_FAILURE, "move workspace", | ||
120 | "Can't find output with name/direction '%s' @ (%i,%i)", argv[3], abs_pos.x, abs_pos.y); | ||
121 | } | ||
122 | if (view->type == C_WORKSPACE) { | ||
123 | // This probably means we're moving an empty workspace, but | ||
124 | // that's fine. | ||
125 | move_workspace_to(view, output); | ||
126 | } else { | ||
127 | swayc_t *workspace = swayc_parent_by_type(view, C_WORKSPACE); | ||
128 | move_workspace_to(workspace, output); | ||
129 | } | ||
130 | } else if (strcasecmp(argv[0], "scratchpad") == 0 || (strcasecmp(argv[0], "to") == 0 && strcasecmp(argv[1], "scratchpad") == 0)) { | ||
131 | // move scratchpad ... | ||
132 | if (view->type != C_CONTAINER && view->type != C_VIEW) { | ||
133 | return cmd_results_new(CMD_FAILURE, "move scratchpad", "Can only move containers and views."); | ||
134 | } | ||
135 | swayc_t *view = current_container; | ||
136 | int i; | ||
137 | for (i = 0; i < scratchpad->length; i++) { | ||
138 | if (scratchpad->items[i] == view) { | ||
139 | hide_view_in_scratchpad(view); | ||
140 | sp_view = NULL; | ||
141 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
142 | } | ||
143 | } | ||
144 | list_add(scratchpad, view); | ||
145 | if (!view->is_floating) { | ||
146 | destroy_container(remove_child(view)); | ||
147 | } else { | ||
148 | remove_child(view); | ||
149 | } | ||
150 | wlc_view_set_mask(view->handle, 0); | ||
151 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
152 | swayc_t *focused = container_under_pointer(); | ||
153 | if (focused == NULL) { | ||
154 | focused = swayc_active_workspace(); | ||
155 | } | ||
156 | set_focused_container(focused); | ||
157 | } else if (strcasecmp(argv[0], "position") == 0) { | ||
158 | if ((error = checkarg(argc, "move workspace", EXPECTED_EQUAL_TO, 2))) { | ||
159 | return error; | ||
160 | } | ||
161 | if (strcasecmp(argv[1], "mouse")) { | ||
162 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
163 | } | ||
164 | |||
165 | if (view->is_floating) { | ||
166 | swayc_t *output = swayc_parent_by_type(view, C_OUTPUT); | ||
167 | struct wlc_geometry g; | ||
168 | wlc_view_get_visible_geometry(view->handle, &g); | ||
169 | const struct wlc_size *size = wlc_output_get_resolution(output->handle); | ||
170 | |||
171 | double x_pos, y_pos; | ||
172 | wlc_pointer_get_position_v2(&x_pos, &y_pos); | ||
173 | |||
174 | int32_t x = x_pos - g.size.w / 2; | ||
175 | int32_t y = y_pos - g.size.h / 2; | ||
176 | |||
177 | uint32_t w = size->w - g.size.w; | ||
178 | uint32_t h = size->h - g.size.h; | ||
179 | |||
180 | view->x = g.origin.x = MIN((int32_t)w, MAX(x, 0)); | ||
181 | view->y = g.origin.y = MIN((int32_t)h, MAX(y, 0)); | ||
182 | |||
183 | wlc_view_set_geometry(view->handle, 0, &g); | ||
184 | } | ||
185 | } else { | ||
186 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
187 | } | ||
188 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
189 | } | ||
diff --git a/sway/commands/new_float.c b/sway/commands/new_float.c deleted file mode 100644 index d0f96093..00000000 --- a/sway/commands/new_float.c +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | #include "log.h" | ||
2 | #include "sway/commands.h" | ||
3 | |||
4 | struct cmd_results *cmd_new_float(int argc, char **argv) { | ||
5 | sway_log(L_INFO, "`new_float` is deprecated and will be removed in the future. " | ||
6 | "Please use `default_floating_border` instead."); | ||
7 | return cmd_default_floating_border(argc, argv); | ||
8 | } | ||
diff --git a/sway/commands/new_window.c b/sway/commands/new_window.c deleted file mode 100644 index 574a4527..00000000 --- a/sway/commands/new_window.c +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | #include "log.h" | ||
2 | #include "sway/commands.h" | ||
3 | |||
4 | struct cmd_results *cmd_new_window(int argc, char **argv) { | ||
5 | sway_log(L_INFO, "`new_window` is deprecated and will be removed in the future. " | ||
6 | "Please use `default_border` instead."); | ||
7 | return cmd_default_border(argc, argv); | ||
8 | } | ||
diff --git a/sway/commands/no_focus.c b/sway/commands/no_focus.c deleted file mode 100644 index b3b88e5a..00000000 --- a/sway/commands/no_focus.c +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/criteria.h" | ||
5 | #include "list.h" | ||
6 | #include "log.h" | ||
7 | #include "stringop.h" | ||
8 | |||
9 | struct cmd_results *cmd_no_focus(int argc, char **argv) { | ||
10 | struct cmd_results *error = NULL; | ||
11 | if ((error = checkarg(argc, "no_focus", EXPECTED_EQUAL_TO, 1))) { | ||
12 | return error; | ||
13 | } | ||
14 | // add command to a criteria/command pair that is run against views when they appear. | ||
15 | char *criteria = argv[0]; | ||
16 | |||
17 | struct criteria *crit = malloc(sizeof(struct criteria)); | ||
18 | if (!crit) { | ||
19 | return cmd_results_new(CMD_FAILURE, "no_focus", "Unable to allocate criteria"); | ||
20 | } | ||
21 | crit->crit_raw = strdup(criteria); | ||
22 | crit->tokens = create_list(); | ||
23 | crit->cmdlist = NULL; | ||
24 | char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw); | ||
25 | |||
26 | if (err_str) { | ||
27 | error = cmd_results_new(CMD_INVALID, "no_focus", err_str); | ||
28 | free(err_str); | ||
29 | free_criteria(crit); | ||
30 | } else if (crit->tokens->length == 0) { | ||
31 | error = cmd_results_new(CMD_INVALID, "no_focus", "Found no name/value pairs in criteria"); | ||
32 | free_criteria(crit); | ||
33 | } else if (list_seq_find(config->no_focus, criteria_cmp, crit) != -1) { | ||
34 | sway_log(L_DEBUG, "no_focus: Duplicate, skipping."); | ||
35 | free_criteria(crit); | ||
36 | } else { | ||
37 | sway_log(L_DEBUG, "no_focus: '%s' added", crit->crit_raw); | ||
38 | list_add(config->no_focus, crit); | ||
39 | } | ||
40 | return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
41 | } | ||
diff --git a/sway/commands/orientation.c b/sway/commands/orientation.c deleted file mode 100644 index e54b60ee..00000000 --- a/sway/commands/orientation.c +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *cmd_orientation(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if (!config->reading) return cmd_results_new(CMD_FAILURE, "orientation", "Can only be used in config file."); | ||
8 | if ((error = checkarg(argc, "orientation", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (strcasecmp(argv[0], "horizontal") == 0) { | ||
12 | config->default_orientation = L_HORIZ; | ||
13 | } else if (strcasecmp(argv[0], "vertical") == 0) { | ||
14 | config->default_orientation = L_VERT; | ||
15 | } else if (strcasecmp(argv[0], "auto") == 0) { | ||
16 | // Do nothing | ||
17 | } else { | ||
18 | return cmd_results_new(CMD_INVALID, "orientation", "Expected 'orientation <horizontal|vertical|auto>'"); | ||
19 | } | ||
20 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
21 | } | ||
diff --git a/sway/commands/output.c b/sway/commands/output.c deleted file mode 100644 index 911391d2..00000000 --- a/sway/commands/output.c +++ /dev/null | |||
@@ -1,219 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <ctype.h> | ||
3 | #include <libgen.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <string.h> | ||
6 | #include <strings.h> | ||
7 | #include <unistd.h> | ||
8 | #include <wordexp.h> | ||
9 | #include "sway/commands.h" | ||
10 | #include "sway/config.h" | ||
11 | #include "list.h" | ||
12 | #include "log.h" | ||
13 | #include "stringop.h" | ||
14 | |||
15 | static char *bg_options[] = { | ||
16 | "stretch", | ||
17 | "center", | ||
18 | "fill", | ||
19 | "fit", | ||
20 | "tile" | ||
21 | }; | ||
22 | |||
23 | struct cmd_results *cmd_output(int argc, char **argv) { | ||
24 | struct cmd_results *error = NULL; | ||
25 | if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) { | ||
26 | return error; | ||
27 | } | ||
28 | const char *name = argv[0]; | ||
29 | |||
30 | struct output_config *output = calloc(1, sizeof(struct output_config)); | ||
31 | if (!output) { | ||
32 | return cmd_results_new(CMD_FAILURE, "output", "Unable to allocate output config"); | ||
33 | } | ||
34 | output->x = output->y = output->width = output->height = -1; | ||
35 | output->name = strdup(name); | ||
36 | output->enabled = -1; | ||
37 | output->scale = 1; | ||
38 | |||
39 | // TODO: atoi doesn't handle invalid numbers | ||
40 | |||
41 | int i; | ||
42 | for (i = 1; i < argc; ++i) { | ||
43 | const char *command = argv[i]; | ||
44 | |||
45 | if (strcasecmp(command, "disable") == 0) { | ||
46 | output->enabled = 0; | ||
47 | } else if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) { | ||
48 | if (++i >= argc) { | ||
49 | error = cmd_results_new(CMD_INVALID, "output", "Missing resolution argument."); | ||
50 | goto fail; | ||
51 | } | ||
52 | char *res = argv[i]; | ||
53 | char *x = strchr(res, 'x'); | ||
54 | int width = -1, height = -1; | ||
55 | if (x != NULL) { | ||
56 | // Format is 1234x4321 | ||
57 | *x = '\0'; | ||
58 | width = atoi(res); | ||
59 | height = atoi(x + 1); | ||
60 | *x = 'x'; | ||
61 | } else { | ||
62 | // Format is 1234 4321 | ||
63 | width = atoi(res); | ||
64 | if (++i >= argc) { | ||
65 | error = cmd_results_new(CMD_INVALID, "output", "Missing resolution argument (height)."); | ||
66 | goto fail; | ||
67 | } | ||
68 | res = argv[i]; | ||
69 | height = atoi(res); | ||
70 | } | ||
71 | output->width = width; | ||
72 | output->height = height; | ||
73 | } else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) { | ||
74 | if (++i >= argc) { | ||
75 | error = cmd_results_new(CMD_INVALID, "output", "Missing position argument."); | ||
76 | goto fail; | ||
77 | } | ||
78 | char *res = argv[i]; | ||
79 | char *c = strchr(res, ','); | ||
80 | int x = -1, y = -1; | ||
81 | if (c != NULL) { | ||
82 | // Format is 1234,4321 | ||
83 | *c = '\0'; | ||
84 | x = atoi(res); | ||
85 | y = atoi(c + 1); | ||
86 | *c = ','; | ||
87 | } else { | ||
88 | // Format is 1234 4321 | ||
89 | x = atoi(res); | ||
90 | if (++i >= argc) { | ||
91 | error = cmd_results_new(CMD_INVALID, "output", "Missing position argument (y)."); | ||
92 | goto fail; | ||
93 | } | ||
94 | res = argv[i]; | ||
95 | y = atoi(res); | ||
96 | } | ||
97 | output->x = x; | ||
98 | output->y = y; | ||
99 | } else if (strcasecmp(command, "scale") == 0) { | ||
100 | if (++i >= argc) { | ||
101 | error = cmd_results_new(CMD_INVALID, "output", "Missing scale parameter."); | ||
102 | goto fail; | ||
103 | } | ||
104 | output->scale = atoi(argv[i]); | ||
105 | } else if (strcasecmp(command, "background") == 0 || strcasecmp(command, "bg") == 0) { | ||
106 | wordexp_t p; | ||
107 | if (++i >= argc) { | ||
108 | error = cmd_results_new(CMD_INVALID, "output", "Missing background file or color specification."); | ||
109 | goto fail; | ||
110 | } | ||
111 | if (i + 1 >= argc) { | ||
112 | error = cmd_results_new(CMD_INVALID, "output", "Missing background scaling mode or `solid_color`."); | ||
113 | goto fail; | ||
114 | } | ||
115 | if (strcasecmp(argv[i + 1], "solid_color") == 0) { | ||
116 | output->background = strdup(argv[argc - 2]); | ||
117 | output->background_option = strdup("solid_color"); | ||
118 | } else { | ||
119 | // argv[i+j]=bg_option | ||
120 | bool valid = false; | ||
121 | char *mode; | ||
122 | size_t j; | ||
123 | for (j = 0; j < (size_t) (argc - i); ++j) { | ||
124 | mode = argv[i + j]; | ||
125 | for (size_t k = 0; k < sizeof(bg_options) / sizeof(char *); ++k) { | ||
126 | if (strcasecmp(mode, bg_options[k]) == 0) { | ||
127 | valid = true; | ||
128 | break; | ||
129 | } | ||
130 | } | ||
131 | if (valid) { | ||
132 | break; | ||
133 | } | ||
134 | } | ||
135 | if (!valid) { | ||
136 | error = cmd_results_new(CMD_INVALID, "output", "Missing background scaling mode."); | ||
137 | goto fail; | ||
138 | } | ||
139 | |||
140 | char *src = join_args(argv + i, j); | ||
141 | if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) { | ||
142 | error = cmd_results_new(CMD_INVALID, "output", "Invalid syntax (%s)", src); | ||
143 | goto fail; | ||
144 | } | ||
145 | free(src); | ||
146 | src = p.we_wordv[0]; | ||
147 | if (config->reading && *src != '/') { | ||
148 | char *conf = strdup(config->current_config); | ||
149 | if (conf) { | ||
150 | char *conf_path = dirname(conf); | ||
151 | src = malloc(strlen(conf_path) + strlen(src) + 2); | ||
152 | if (src) { | ||
153 | sprintf(src, "%s/%s", conf_path, p.we_wordv[0]); | ||
154 | } else { | ||
155 | sway_log(L_ERROR, "Unable to allocate background source"); | ||
156 | } | ||
157 | free(conf); | ||
158 | } else { | ||
159 | sway_log(L_ERROR, "Unable to allocate background source"); | ||
160 | } | ||
161 | } | ||
162 | if (!src || access(src, F_OK) == -1) { | ||
163 | error = cmd_results_new(CMD_INVALID, "output", "Background file unreadable (%s)", src); | ||
164 | wordfree(&p); | ||
165 | goto fail; | ||
166 | } | ||
167 | |||
168 | output->background = strdup(src); | ||
169 | output->background_option = strdup(mode); | ||
170 | if (src != p.we_wordv[0]) { | ||
171 | free(src); | ||
172 | } | ||
173 | wordfree(&p); | ||
174 | |||
175 | i += j; | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | |||
180 | i = list_seq_find(config->output_configs, output_name_cmp, name); | ||
181 | if (i >= 0) { | ||
182 | // merge existing config | ||
183 | struct output_config *oc = config->output_configs->items[i]; | ||
184 | merge_output_config(oc, output); | ||
185 | free_output_config(output); | ||
186 | output = oc; | ||
187 | } else { | ||
188 | list_add(config->output_configs, output); | ||
189 | } | ||
190 | |||
191 | sway_log(L_DEBUG, "Config stored for output %s (enabled:%d) (%d x %d @ %d, %d scale %d) (bg %s %s)", | ||
192 | output->name, output->enabled, output->width, | ||
193 | output->height, output->x, output->y, output->scale, | ||
194 | output->background, output->background_option); | ||
195 | |||
196 | if (output->name) { | ||
197 | // Try to find the output container and apply configuration now. If | ||
198 | // this is during startup then there will be no container and config | ||
199 | // will be applied during normal "new output" event from wlc. | ||
200 | swayc_t *cont = NULL; | ||
201 | for (int i = 0; i < root_container.children->length; ++i) { | ||
202 | cont = root_container.children->items[i]; | ||
203 | if (cont->name && ((strcmp(cont->name, output->name) == 0) || (strcmp(output->name, "*") == 0))) { | ||
204 | apply_output_config(output, cont); | ||
205 | |||
206 | if (strcmp(output->name, "*") != 0) { | ||
207 | // stop looking if the output config isn't applicable to all outputs | ||
208 | break; | ||
209 | } | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | |||
214 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
215 | |||
216 | fail: | ||
217 | free_output_config(output); | ||
218 | return error; | ||
219 | } | ||
diff --git a/sway/commands/permit.c b/sway/commands/permit.c deleted file mode 100644 index 7a5e06f7..00000000 --- a/sway/commands/permit.c +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/config.h" | ||
5 | #include "sway/security.h" | ||
6 | #include "util.h" | ||
7 | #include "log.h" | ||
8 | |||
9 | static enum secure_feature get_features(int argc, char **argv, | ||
10 | struct cmd_results **error) { | ||
11 | enum secure_feature features = 0; | ||
12 | |||
13 | struct { | ||
14 | char *name; | ||
15 | enum secure_feature feature; | ||
16 | } feature_names[] = { | ||
17 | { "lock", FEATURE_LOCK }, | ||
18 | { "panel", FEATURE_PANEL }, | ||
19 | { "background", FEATURE_BACKGROUND }, | ||
20 | { "screenshot", FEATURE_SCREENSHOT }, | ||
21 | { "fullscreen", FEATURE_FULLSCREEN }, | ||
22 | { "keyboard", FEATURE_KEYBOARD }, | ||
23 | { "mouse", FEATURE_MOUSE }, | ||
24 | }; | ||
25 | |||
26 | for (int i = 1; i < argc; ++i) { | ||
27 | size_t j; | ||
28 | for (j = 0; j < sizeof(feature_names) / sizeof(feature_names[0]); ++j) { | ||
29 | if (strcmp(feature_names[j].name, argv[i]) == 0) { | ||
30 | break; | ||
31 | } | ||
32 | } | ||
33 | if (j == sizeof(feature_names) / sizeof(feature_names[0])) { | ||
34 | *error = cmd_results_new(CMD_INVALID, | ||
35 | "permit", "Invalid feature grant %s", argv[i]); | ||
36 | return 0; | ||
37 | } | ||
38 | features |= feature_names[j].feature; | ||
39 | } | ||
40 | return features; | ||
41 | } | ||
42 | |||
43 | struct cmd_results *cmd_permit(int argc, char **argv) { | ||
44 | struct cmd_results *error = NULL; | ||
45 | if ((error = checkarg(argc, "permit", EXPECTED_MORE_THAN, 1))) { | ||
46 | return error; | ||
47 | } | ||
48 | if ((error = check_security_config())) { | ||
49 | return error; | ||
50 | } | ||
51 | |||
52 | bool assign_perms = true; | ||
53 | char *program = NULL; | ||
54 | |||
55 | if (!strcmp(argv[0], "*")) { | ||
56 | program = strdup(argv[0]); | ||
57 | } else { | ||
58 | program = resolve_path(argv[0]); | ||
59 | } | ||
60 | if (!program) { | ||
61 | sway_assert(program, "Unable to resolve IPC permit target '%s'." | ||
62 | " will issue empty policy", argv[0]); | ||
63 | assign_perms = false; | ||
64 | program = strdup(argv[0]); | ||
65 | } | ||
66 | |||
67 | struct feature_policy *policy = get_feature_policy(program); | ||
68 | if (policy && assign_perms) { | ||
69 | policy->features |= get_features(argc, argv, &error); | ||
70 | sway_log(L_DEBUG, "Permissions granted to %s for features %d", | ||
71 | policy->program, policy->features); | ||
72 | } | ||
73 | |||
74 | free(program); | ||
75 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
76 | } | ||
77 | |||
78 | struct cmd_results *cmd_reject(int argc, char **argv) { | ||
79 | struct cmd_results *error = NULL; | ||
80 | if ((error = checkarg(argc, "reject", EXPECTED_MORE_THAN, 1))) { | ||
81 | return error; | ||
82 | } | ||
83 | if ((error = check_security_config())) { | ||
84 | return error; | ||
85 | } | ||
86 | |||
87 | char *program = NULL; | ||
88 | if (!strcmp(argv[0], "*")) { | ||
89 | program = strdup(argv[0]); | ||
90 | } else { | ||
91 | program = resolve_path(argv[0]); | ||
92 | } | ||
93 | if (!program) { | ||
94 | // Punt | ||
95 | sway_log(L_INFO, "Unable to resolve IPC reject target '%s'." | ||
96 | " Will use provided path", argv[0]); | ||
97 | program = strdup(argv[0]); | ||
98 | } | ||
99 | |||
100 | struct feature_policy *policy = get_feature_policy(program); | ||
101 | policy->features &= ~get_features(argc, argv, &error); | ||
102 | |||
103 | sway_log(L_DEBUG, "Permissions granted to %s for features %d", | ||
104 | policy->program, policy->features); | ||
105 | |||
106 | free(program); | ||
107 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
108 | } | ||
diff --git a/sway/commands/reload.c b/sway/commands/reload.c deleted file mode 100644 index 01fcc5ba..00000000 --- a/sway/commands/reload.c +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | #include "sway/commands.h" | ||
2 | #include "sway/config.h" | ||
3 | #include "sway/layout.h" | ||
4 | |||
5 | struct cmd_results *cmd_reload(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if (config->reading) return cmd_results_new(CMD_FAILURE, "reload", "Can't be used in config file."); | ||
8 | if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) { | ||
9 | return error; | ||
10 | } | ||
11 | if (!load_main_config(config->current_config, true)) { | ||
12 | return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config."); | ||
13 | } | ||
14 | |||
15 | load_swaybars(); | ||
16 | |||
17 | arrange_windows(&root_container, -1, -1); | ||
18 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
19 | } | ||
diff --git a/sway/commands/resize.c b/sway/commands/resize.c deleted file mode 100644 index ef52bb07..00000000 --- a/sway/commands/resize.c +++ /dev/null | |||
@@ -1,375 +0,0 @@ | |||
1 | #include <errno.h> | ||
2 | #include <math.h> | ||
3 | #include <stdbool.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <string.h> | ||
6 | #include <strings.h> | ||
7 | #include <wlc/wlc.h> | ||
8 | #include "sway/commands.h" | ||
9 | #include "sway/layout.h" | ||
10 | #include "sway/focus.h" | ||
11 | #include "sway/input_state.h" | ||
12 | #include "sway/handlers.h" | ||
13 | #include "log.h" | ||
14 | |||
15 | enum resize_dim_types { | ||
16 | RESIZE_DIM_PX, | ||
17 | RESIZE_DIM_PPT, | ||
18 | RESIZE_DIM_DEFAULT, | ||
19 | }; | ||
20 | |||
21 | static bool set_size_floating(int new_dimension, bool use_width) { | ||
22 | swayc_t *view = current_container; | ||
23 | if (view) { | ||
24 | if (use_width) { | ||
25 | int current_width = view->width; | ||
26 | view->desired_width = new_dimension; | ||
27 | floating_view_sane_size(view); | ||
28 | |||
29 | int new_x = view->x + (int)(((view->desired_width - current_width) / 2) * -1); | ||
30 | view->width = view->desired_width; | ||
31 | view->x = new_x; | ||
32 | |||
33 | update_geometry(view); | ||
34 | } else { | ||
35 | int current_height = view->height; | ||
36 | view->desired_height = new_dimension; | ||
37 | floating_view_sane_size(view); | ||
38 | |||
39 | int new_y = view->y + (int)(((view->desired_height - current_height) / 2) * -1); | ||
40 | view->height = view->desired_height; | ||
41 | view->y = new_y; | ||
42 | |||
43 | update_geometry(view); | ||
44 | } | ||
45 | |||
46 | return true; | ||
47 | } | ||
48 | |||
49 | return false; | ||
50 | } | ||
51 | |||
52 | static bool resize_floating(int amount, bool use_width) { | ||
53 | swayc_t *view = current_container; | ||
54 | |||
55 | if (view) { | ||
56 | if (use_width) { | ||
57 | return set_size_floating(view->width + amount, true); | ||
58 | } else { | ||
59 | return set_size_floating(view->height + amount, false); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | return false; | ||
64 | } | ||
65 | |||
66 | static bool resize_tiled(int amount, bool use_width) { | ||
67 | swayc_t *container = current_container; | ||
68 | swayc_t *parent = container->parent; | ||
69 | int idx_focused = 0; | ||
70 | bool use_major = false; | ||
71 | size_t nb_before = 0; | ||
72 | size_t nb_after = 0; | ||
73 | |||
74 | // 1. Identify a container ancestor that will allow the focused child to grow in the requested | ||
75 | // direction. | ||
76 | while (container->parent) { | ||
77 | parent = container->parent; | ||
78 | if ((parent->children && parent->children->length > 1) | ||
79 | && (is_auto_layout(parent->layout) | ||
80 | || (use_width ? parent->layout == L_HORIZ : parent->layout == L_VERT))) { | ||
81 | // check if container has siblings that can provide/absorb the space needed for | ||
82 | // the resize operation. | ||
83 | use_major = use_width | ||
84 | ? parent->layout == L_AUTO_LEFT || parent->layout == L_AUTO_RIGHT | ||
85 | : parent->layout == L_AUTO_TOP || parent->layout == L_AUTO_BOTTOM; | ||
86 | // Note: use_major will be false for L_HORIZ and L_VERT | ||
87 | |||
88 | idx_focused = index_child(container); | ||
89 | if (idx_focused < 0) { | ||
90 | sway_log(L_ERROR, "Something weird is happening, child container not " | ||
91 | "present in its parent's children list."); | ||
92 | continue; | ||
93 | } | ||
94 | if (use_major) { | ||
95 | nb_before = auto_group_index(parent, idx_focused); | ||
96 | nb_after = auto_group_count(parent) - nb_before - 1; | ||
97 | } else { | ||
98 | nb_before = idx_focused - auto_group_start_index(parent, idx_focused); | ||
99 | nb_after = auto_group_end_index(parent, idx_focused) - idx_focused - 1; | ||
100 | sway_log(L_DEBUG, "+++ focused: %d, start: %d, end: %d, before: %d, after: %d", | ||
101 | idx_focused, | ||
102 | (int)auto_group_start_index(parent, idx_focused), | ||
103 | (int)auto_group_end_index(parent, idx_focused), | ||
104 | (int)nb_before, (int)nb_after); | ||
105 | |||
106 | } | ||
107 | if (nb_before || nb_after) { | ||
108 | break; | ||
109 | } | ||
110 | } | ||
111 | container = parent; /* continue up the tree to the next ancestor */ | ||
112 | } | ||
113 | if (parent == &root_container) { | ||
114 | return true; | ||
115 | } | ||
116 | sway_log(L_DEBUG, "Found the proper parent: %p. It has %zu before conts, " | ||
117 | "and %zu after conts", parent, nb_before, nb_after); | ||
118 | // 2. Ensure that the resize operation will not make one of the resized containers drop | ||
119 | // below the "sane" size threshold. | ||
120 | bool valid = true; | ||
121 | swayc_t *focused = parent->children->items[idx_focused]; | ||
122 | int start = use_major ? 0 : auto_group_start_index(parent, idx_focused); | ||
123 | int end = use_major ? parent->children->length : auto_group_end_index(parent, idx_focused); | ||
124 | sway_log(L_DEBUG, "Check children of container %p [%d,%d[", container, start, end); | ||
125 | for (int i = start; i < end; ) { | ||
126 | swayc_t *sibling = parent->children->items[i]; | ||
127 | double pixels = amount; | ||
128 | bool is_before = use_width ? sibling->x < focused->x : sibling->y < focused->y; | ||
129 | bool is_after = use_width ? sibling->x > focused->x : sibling->y > focused->y; | ||
130 | if (is_before || is_after) { | ||
131 | pixels = -pixels; | ||
132 | pixels /= is_before ? nb_before : nb_after; | ||
133 | if (nb_after != 0 && nb_before != 0) { | ||
134 | pixels /= 2; | ||
135 | } | ||
136 | } | ||
137 | sway_log(L_DEBUG, "Check container %p: width %g vs %d, height %g vs %d", sibling, sibling->width + pixels, min_sane_w, sibling->height + pixels, min_sane_h); | ||
138 | if (use_width ? | ||
139 | sibling->width + pixels < min_sane_w : | ||
140 | sibling->height + pixels < min_sane_h) { | ||
141 | valid = false; | ||
142 | sway_log(L_DEBUG, "Container size no longer sane"); | ||
143 | break; | ||
144 | } | ||
145 | i = use_major ? auto_group_end_index(parent, i) : (i + 1); | ||
146 | sway_log(L_DEBUG, "+++++ check %i", i); | ||
147 | } | ||
148 | // 3. Apply the size change | ||
149 | if (valid) { | ||
150 | for (int i = start; i < end; ) { | ||
151 | int next_i = use_major ? auto_group_end_index(parent, i) : (i + 1); | ||
152 | swayc_t *sibling = parent->children->items[i]; | ||
153 | double pixels = amount; | ||
154 | bool is_before = use_width ? sibling->x < focused->x : sibling->y < focused->y; | ||
155 | bool is_after = use_width ? sibling->x > focused->x : sibling->y > focused->y; | ||
156 | if (is_before || is_after) { | ||
157 | pixels = -pixels; | ||
158 | pixels /= is_before ? nb_before : nb_after; | ||
159 | if (nb_after != 0 && nb_before != 0) { | ||
160 | pixels /= 2; | ||
161 | } | ||
162 | sway_log(L_DEBUG, "%p: %s", sibling, is_before ? "before" : "after"); | ||
163 | if (use_major) { | ||
164 | for (int j = i; j < next_i; ++j) { | ||
165 | recursive_resize(parent->children->items[j], pixels, | ||
166 | use_width ? | ||
167 | (is_before ? WLC_RESIZE_EDGE_RIGHT : WLC_RESIZE_EDGE_LEFT) : | ||
168 | (is_before ? WLC_RESIZE_EDGE_BOTTOM : WLC_RESIZE_EDGE_TOP)); | ||
169 | } | ||
170 | } else { | ||
171 | recursive_resize(sibling, pixels, | ||
172 | use_width ? | ||
173 | (is_before ? WLC_RESIZE_EDGE_RIGHT : WLC_RESIZE_EDGE_LEFT) : | ||
174 | (is_before ? WLC_RESIZE_EDGE_BOTTOM : WLC_RESIZE_EDGE_TOP)); | ||
175 | } | ||
176 | } else { | ||
177 | if (use_major) { | ||
178 | for (int j = i; j < next_i; ++j) { | ||
179 | recursive_resize(parent->children->items[j], pixels / 2, | ||
180 | use_width ? WLC_RESIZE_EDGE_LEFT : WLC_RESIZE_EDGE_TOP); | ||
181 | recursive_resize(parent->children->items[j], pixels / 2, | ||
182 | use_width ? WLC_RESIZE_EDGE_RIGHT : WLC_RESIZE_EDGE_BOTTOM); | ||
183 | } | ||
184 | } else { | ||
185 | recursive_resize(sibling, pixels / 2, | ||
186 | use_width ? WLC_RESIZE_EDGE_LEFT : WLC_RESIZE_EDGE_TOP); | ||
187 | recursive_resize(sibling, pixels / 2, | ||
188 | use_width ? WLC_RESIZE_EDGE_RIGHT : WLC_RESIZE_EDGE_BOTTOM); | ||
189 | } | ||
190 | } | ||
191 | i = next_i; | ||
192 | } | ||
193 | // Recursive resize does not handle positions, let arrange_windows | ||
194 | // take care of that. | ||
195 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
196 | } | ||
197 | return true; | ||
198 | } | ||
199 | |||
200 | static bool set_size_tiled(int amount, bool use_width) { | ||
201 | int desired; | ||
202 | swayc_t *focused = current_container; | ||
203 | |||
204 | if (use_width) { | ||
205 | desired = amount - focused->width; | ||
206 | } else { | ||
207 | desired = amount - focused->height; | ||
208 | } | ||
209 | |||
210 | return resize_tiled(desired, use_width); | ||
211 | } | ||
212 | |||
213 | static bool set_size(int dimension, bool use_width) { | ||
214 | swayc_t *focused = current_container; | ||
215 | |||
216 | if (focused) { | ||
217 | if (focused->is_floating) { | ||
218 | return set_size_floating(dimension, use_width); | ||
219 | } else { | ||
220 | return set_size_tiled(dimension, use_width); | ||
221 | } | ||
222 | } | ||
223 | |||
224 | return false; | ||
225 | } | ||
226 | |||
227 | static bool resize(int dimension, bool use_width, enum resize_dim_types dim_type) { | ||
228 | swayc_t *focused = current_container; | ||
229 | |||
230 | // translate "10 ppt" (10%) to appropriate # of pixels in case we need it | ||
231 | float ppt_dim = (float)dimension / 100; | ||
232 | |||
233 | if (use_width) { | ||
234 | ppt_dim = focused->width * ppt_dim; | ||
235 | } else { | ||
236 | ppt_dim = focused->height * ppt_dim; | ||
237 | } | ||
238 | |||
239 | if (focused) { | ||
240 | if (focused->is_floating) { | ||
241 | // floating view resize dimensions should default to px, so only | ||
242 | // use ppt if specified | ||
243 | if (dim_type == RESIZE_DIM_PPT) { | ||
244 | dimension = (int)ppt_dim; | ||
245 | } | ||
246 | |||
247 | return resize_floating(dimension, use_width); | ||
248 | } else { | ||
249 | // tiled view resize dimensions should default to ppt, so only use | ||
250 | // px if specified | ||
251 | if (dim_type != RESIZE_DIM_PX) { | ||
252 | dimension = (int)ppt_dim; | ||
253 | } | ||
254 | |||
255 | return resize_tiled(dimension, use_width); | ||
256 | } | ||
257 | } | ||
258 | |||
259 | return false; | ||
260 | } | ||
261 | |||
262 | static struct cmd_results *cmd_resize_set(int argc, char **argv) { | ||
263 | struct cmd_results *error = NULL; | ||
264 | if ((error = checkarg(argc, "resize set", EXPECTED_AT_LEAST, 2))) { | ||
265 | return error; | ||
266 | } | ||
267 | |||
268 | if (strcasecmp(argv[0], "width") == 0 || strcasecmp(argv[0], "height") == 0) { | ||
269 | // handle `reset set width 100 px height 100 px` syntax, also allows | ||
270 | // specifying only one dimension for a `resize set` | ||
271 | int cmd_num = 0; | ||
272 | int dim; | ||
273 | |||
274 | while ((cmd_num + 1) < argc) { | ||
275 | dim = (int)strtol(argv[cmd_num + 1], NULL, 10); | ||
276 | if (errno == ERANGE || dim == 0) { | ||
277 | errno = 0; | ||
278 | return cmd_results_new(CMD_INVALID, "resize set", | ||
279 | "Expected 'resize set <width|height> <amount> [px] [<width|height> <amount> [px]]'"); | ||
280 | } | ||
281 | |||
282 | if (strcasecmp(argv[cmd_num], "width") == 0) { | ||
283 | set_size(dim, true); | ||
284 | } else if (strcasecmp(argv[cmd_num], "height") == 0) { | ||
285 | set_size(dim, false); | ||
286 | } else { | ||
287 | return cmd_results_new(CMD_INVALID, "resize set", | ||
288 | "Expected 'resize set <width|height> <amount> [px] [<width|height> <amount> [px]]'"); | ||
289 | } | ||
290 | |||
291 | cmd_num += 2; | ||
292 | |||
293 | if (cmd_num < argc && strcasecmp(argv[cmd_num], "px") == 0) { | ||
294 | // if this was `resize set width 400 px height 300 px`, disregard the `px` arg | ||
295 | cmd_num++; | ||
296 | } | ||
297 | } | ||
298 | } else { | ||
299 | // handle `reset set 100 px 100 px` syntax | ||
300 | int width = (int)strtol(argv[0], NULL, 10); | ||
301 | if (errno == ERANGE || width == 0) { | ||
302 | errno = 0; | ||
303 | return cmd_results_new(CMD_INVALID, "resize set", | ||
304 | "Expected 'resize set <width> [px] <height> [px]'"); | ||
305 | } | ||
306 | |||
307 | int height_arg = 1; | ||
308 | if (strcasecmp(argv[1], "px") == 0) { | ||
309 | height_arg = 2; | ||
310 | } | ||
311 | |||
312 | int height = (int)strtol(argv[height_arg], NULL, 10); | ||
313 | if (errno == ERANGE || height == 0) { | ||
314 | errno = 0; | ||
315 | return cmd_results_new(CMD_INVALID, "resize set", | ||
316 | "Expected 'resize set <width> [px] <height> [px]'"); | ||
317 | } | ||
318 | |||
319 | set_size(width, true); | ||
320 | set_size(height, false); | ||
321 | } | ||
322 | |||
323 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
324 | } | ||
325 | |||
326 | struct cmd_results *cmd_resize(int argc, char **argv) { | ||
327 | struct cmd_results *error = NULL; | ||
328 | if (config->reading) return cmd_results_new(CMD_FAILURE, "resize", "Can't be used in config file."); | ||
329 | if (!config->active) return cmd_results_new(CMD_FAILURE, "resize", "Can only be used when sway is running."); | ||
330 | |||
331 | if (strcasecmp(argv[0], "set") == 0) { | ||
332 | return cmd_resize_set(argc - 1, &argv[1]); | ||
333 | } | ||
334 | |||
335 | if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) { | ||
336 | return error; | ||
337 | } | ||
338 | |||
339 | int dim_arg = argc - 1; | ||
340 | |||
341 | enum resize_dim_types dim_type = RESIZE_DIM_DEFAULT; | ||
342 | if (strcasecmp(argv[dim_arg], "ppt") == 0) { | ||
343 | dim_type = RESIZE_DIM_PPT; | ||
344 | dim_arg--; | ||
345 | } else if (strcasecmp(argv[dim_arg], "px") == 0) { | ||
346 | dim_type = RESIZE_DIM_PX; | ||
347 | dim_arg--; | ||
348 | } | ||
349 | |||
350 | int amount = (int)strtol(argv[dim_arg], NULL, 10); | ||
351 | if (errno == ERANGE || amount == 0) { | ||
352 | errno = 0; | ||
353 | amount = 10; // this is the default resize dimension used by i3 for both px and ppt | ||
354 | sway_log(L_DEBUG, "Tried to get resize dimension out of '%s' but failed; setting dimension to default %d", | ||
355 | argv[dim_arg], amount); | ||
356 | } | ||
357 | |||
358 | bool use_width = false; | ||
359 | if (strcasecmp(argv[1], "width") == 0) { | ||
360 | use_width = true; | ||
361 | } else if (strcasecmp(argv[1], "height") != 0) { | ||
362 | return cmd_results_new(CMD_INVALID, "resize", | ||
363 | "Expected 'resize <shrink|grow> <width|height> [<amount>] [px|ppt]'"); | ||
364 | } | ||
365 | |||
366 | if (strcasecmp(argv[0], "shrink") == 0) { | ||
367 | amount *= -1; | ||
368 | } else if (strcasecmp(argv[0], "grow") != 0) { | ||
369 | return cmd_results_new(CMD_INVALID, "resize", | ||
370 | "Expected 'resize <shrink|grow> <width|height> [<amount>] [px|ppt]'"); | ||
371 | } | ||
372 | |||
373 | resize(amount, use_width, dim_type); | ||
374 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
375 | } | ||
diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c deleted file mode 100644 index 6c5c92df..00000000 --- a/sway/commands/scratchpad.c +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include <wlc/wlc.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/container.h" | ||
6 | #include "sway/focus.h" | ||
7 | #include "sway/layout.h" | ||
8 | |||
9 | static swayc_t *fetch_view_from_scratchpad() { | ||
10 | sp_index = (sp_index + 1) % scratchpad->length; | ||
11 | swayc_t *view = scratchpad->items[sp_index]; | ||
12 | |||
13 | if (wlc_view_get_output(view->handle) != swayc_active_output()->handle) { | ||
14 | wlc_view_set_output(view->handle, swayc_active_output()->handle); | ||
15 | } | ||
16 | if (!view->is_floating) { | ||
17 | view->width = swayc_active_workspace()->width * 0.5; | ||
18 | view->height = swayc_active_workspace()->height * 0.75; | ||
19 | view->x = (swayc_active_workspace()->width - view->width)/2; | ||
20 | view->y = (swayc_active_workspace()->height - view->height)/2; | ||
21 | } | ||
22 | if (swayc_active_workspace()->width < view->x + 20 || view->x + view->width < 20) { | ||
23 | view->x = (swayc_active_workspace()->width - view->width)/2; | ||
24 | } | ||
25 | if (swayc_active_workspace()->height < view->y + 20 || view->y + view->height < 20) { | ||
26 | view->y = (swayc_active_workspace()->height - view->height)/2; | ||
27 | } | ||
28 | |||
29 | add_floating(swayc_active_workspace(), view); | ||
30 | wlc_view_set_mask(view->handle, VISIBLE); | ||
31 | view->visible = true; | ||
32 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
33 | set_focused_container(view); | ||
34 | return view; | ||
35 | } | ||
36 | |||
37 | struct cmd_results *cmd_scratchpad(int argc, char **argv) { | ||
38 | struct cmd_results *error = NULL; | ||
39 | if (config->reading) return cmd_results_new(CMD_FAILURE, "scratchpad", "Can't be used in config file."); | ||
40 | if (!config->active) return cmd_results_new(CMD_FAILURE, "scratchpad", "Can only be used when sway is running."); | ||
41 | if ((error = checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1))) { | ||
42 | return error; | ||
43 | } | ||
44 | |||
45 | if (strcasecmp(argv[0], "show") == 0 && scratchpad->length > 0) { | ||
46 | if (!sp_view) { | ||
47 | if (current_container) { | ||
48 | // Haxor the scratchpad index if criteria'd | ||
49 | for (int i = 0; i < scratchpad->length; ++i) { | ||
50 | if (scratchpad->items[i] == current_container) { | ||
51 | sp_index = (i - 1) % scratchpad->length; | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | sp_view = fetch_view_from_scratchpad(); | ||
56 | } else { | ||
57 | if (swayc_active_workspace() != sp_view->parent) { | ||
58 | hide_view_in_scratchpad(sp_view); | ||
59 | if (sp_index == 0) { | ||
60 | sp_index = scratchpad->length; | ||
61 | } | ||
62 | sp_index--; | ||
63 | sp_view = fetch_view_from_scratchpad(); | ||
64 | } else { | ||
65 | hide_view_in_scratchpad(sp_view); | ||
66 | sp_view = NULL; | ||
67 | } | ||
68 | } | ||
69 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
70 | } | ||
71 | return cmd_results_new(CMD_FAILURE, "scratchpad", "Expected 'scratchpad show' when scratchpad is not empty."); | ||
72 | } | ||
diff --git a/sway/commands/seamless_mouse.c b/sway/commands/seamless_mouse.c deleted file mode 100644 index 7760e88d..00000000 --- a/sway/commands/seamless_mouse.c +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *cmd_seamless_mouse(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if ((error = checkarg(argc, "seamless_mouse", EXPECTED_EQUAL_TO, 1))) { | ||
8 | return error; | ||
9 | } | ||
10 | |||
11 | config->seamless_mouse = (strcasecmp(argv[0], "on") == 0 || strcasecmp(argv[0], "yes") == 0); | ||
12 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
13 | } | ||
diff --git a/sway/commands/set.c b/sway/commands/set.c deleted file mode 100644 index 46fc6d38..00000000 --- a/sway/commands/set.c +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include <stdio.h> | ||
3 | #include <string.h> | ||
4 | #include <strings.h> | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/config.h" | ||
7 | #include "list.h" | ||
8 | #include "stringop.h" | ||
9 | |||
10 | // sort in order of longest->shortest | ||
11 | static int compare_set_qsort(const void *_l, const void *_r) { | ||
12 | struct sway_variable const *l = *(void **)_l; | ||
13 | struct sway_variable const *r = *(void **)_r; | ||
14 | return strlen(r->name) - strlen(l->name); | ||
15 | } | ||
16 | |||
17 | struct cmd_results *cmd_set(int argc, char **argv) { | ||
18 | char *tmp; | ||
19 | struct cmd_results *error = NULL; | ||
20 | if (!config->reading) return cmd_results_new(CMD_FAILURE, "set", "Can only be used in config file."); | ||
21 | if ((error = checkarg(argc, "set", EXPECTED_AT_LEAST, 2))) { | ||
22 | return error; | ||
23 | } | ||
24 | |||
25 | if (argv[0][0] != '$') { | ||
26 | sway_log(L_INFO, "Warning: variable '%s' doesn't start with $", argv[0]); | ||
27 | |||
28 | size_t size = snprintf(NULL, 0, "$%s", argv[0]); | ||
29 | tmp = malloc(size + 1); | ||
30 | if (!tmp) { | ||
31 | return cmd_results_new(CMD_FAILURE, "set", "Not possible to create variable $'%s'", argv[0]); | ||
32 | } | ||
33 | snprintf(tmp, size+1, "$%s", argv[0]); | ||
34 | |||
35 | argv[0] = tmp; | ||
36 | } | ||
37 | |||
38 | struct sway_variable *var = NULL; | ||
39 | // Find old variable if it exists | ||
40 | int i; | ||
41 | for (i = 0; i < config->symbols->length; ++i) { | ||
42 | var = config->symbols->items[i]; | ||
43 | if (strcmp(var->name, argv[0]) == 0) { | ||
44 | break; | ||
45 | } | ||
46 | var = NULL; | ||
47 | } | ||
48 | if (var) { | ||
49 | free(var->value); | ||
50 | } else { | ||
51 | var = malloc(sizeof(struct sway_variable)); | ||
52 | if (!var) { | ||
53 | return cmd_results_new(CMD_FAILURE, "set", "Unable to allocate variable"); | ||
54 | } | ||
55 | var->name = strdup(argv[0]); | ||
56 | list_add(config->symbols, var); | ||
57 | list_qsort(config->symbols, compare_set_qsort); | ||
58 | } | ||
59 | var->value = join_args(argv + 1, argc - 1); | ||
60 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
61 | } | ||
diff --git a/sway/commands/show_marks.c b/sway/commands/show_marks.c deleted file mode 100644 index ed56d9e5..00000000 --- a/sway/commands/show_marks.c +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *cmd_show_marks(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if ((error = checkarg(argc, "show_marks", EXPECTED_EQUAL_TO, 1))) { | ||
8 | return error; | ||
9 | } | ||
10 | |||
11 | config->show_marks = !strcasecmp(argv[0], "on"); | ||
12 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
13 | } | ||
diff --git a/sway/commands/smart_gaps.c b/sway/commands/smart_gaps.c deleted file mode 100644 index 815fc501..00000000 --- a/sway/commands/smart_gaps.c +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *cmd_smart_gaps(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if ((error = checkarg(argc, "smart_gaps", EXPECTED_EQUAL_TO, 1))) { | ||
8 | return error; | ||
9 | } | ||
10 | |||
11 | if (strcasecmp(argv[0], "on") == 0) { | ||
12 | config->smart_gaps = true; | ||
13 | } else if (strcasecmp(argv[0], "off") == 0) { | ||
14 | config->smart_gaps = false; | ||
15 | } else { | ||
16 | return cmd_results_new(CMD_INVALID, "smart_gaps", "Expected 'smart_gaps <on|off>'"); | ||
17 | } | ||
18 | |||
19 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
20 | } | ||
diff --git a/sway/commands/split.c b/sway/commands/split.c deleted file mode 100644 index e3045a4f..00000000 --- a/sway/commands/split.c +++ /dev/null | |||
@@ -1,98 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include <wlc/wlc-render.h> | ||
4 | #include "sway/border.h" | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/container.h" | ||
7 | #include "sway/focus.h" | ||
8 | #include "sway/layout.h" | ||
9 | #include "log.h" | ||
10 | |||
11 | static struct cmd_results *_do_split(int argc, char **argv, int layout) { | ||
12 | char *name = layout == L_VERT ? "splitv" : | ||
13 | layout == L_HORIZ ? "splith" : "split"; | ||
14 | struct cmd_results *error = NULL; | ||
15 | if (config->reading) return cmd_results_new(CMD_FAILURE, name, "Can't be used in config file."); | ||
16 | if (!config->active) return cmd_results_new(CMD_FAILURE, name, "Can only be used when sway is running."); | ||
17 | if ((error = checkarg(argc, name, EXPECTED_EQUAL_TO, 0))) { | ||
18 | return error; | ||
19 | } | ||
20 | swayc_t *focused = current_container; | ||
21 | |||
22 | // Case of floating window, don't split | ||
23 | if (focused->is_floating) { | ||
24 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
25 | } | ||
26 | /* Case that focus is on an workspace with 0/1 children.change its layout */ | ||
27 | if (focused->type == C_WORKSPACE && focused->children->length <= 1) { | ||
28 | sway_log(L_DEBUG, "changing workspace layout"); | ||
29 | swayc_change_layout(focused, layout); | ||
30 | } else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) { | ||
31 | /* Case of no siblings. change parent layout */ | ||
32 | sway_log(L_DEBUG, "changing container layout"); | ||
33 | swayc_change_layout(focused->parent, layout); | ||
34 | } else { | ||
35 | /* regular case where new split container is build around focused container | ||
36 | * or in case of workspace, container inherits its children */ | ||
37 | sway_log(L_DEBUG, "Adding new container around current focused container"); | ||
38 | sway_log(L_INFO, "FOCUSED SIZE: %.f %.f", focused->width, focused->height); | ||
39 | swayc_t *parent = new_container(focused, layout); | ||
40 | set_focused_container(focused); | ||
41 | arrange_windows(parent, -1, -1); | ||
42 | } | ||
43 | |||
44 | // update container every time | ||
45 | // if it is tabbed/stacked then the title must change | ||
46 | // if the indicator color is different then the border must change | ||
47 | update_container_border(focused); | ||
48 | swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT); | ||
49 | // schedule render to make changes take effect right away, | ||
50 | // otherwise we would have to wait for the view to render, | ||
51 | // which is unpredictable. | ||
52 | wlc_output_schedule_render(output->handle); | ||
53 | |||
54 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
55 | } | ||
56 | |||
57 | struct cmd_results *cmd_split(int argc, char **argv) { | ||
58 | struct cmd_results *error = NULL; | ||
59 | if (config->reading) return cmd_results_new(CMD_FAILURE, "split", "Can't be used in config file."); | ||
60 | if (!config->active) return cmd_results_new(CMD_FAILURE, "split", "Can only be used when sway is running."); | ||
61 | if ((error = checkarg(argc, "split", EXPECTED_EQUAL_TO, 1))) { | ||
62 | return error; | ||
63 | } | ||
64 | if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { | ||
65 | _do_split(argc - 1, argv + 1, L_VERT); | ||
66 | } else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) { | ||
67 | _do_split(argc - 1, argv + 1, L_HORIZ); | ||
68 | } else if (strcasecmp(argv[0], "t") == 0 || strcasecmp(argv[0], "toggle") == 0) { | ||
69 | swayc_t *focused = current_container; | ||
70 | if (focused->parent->layout == L_VERT) { | ||
71 | _do_split(argc - 1, argv + 1, L_HORIZ); | ||
72 | } else { | ||
73 | _do_split(argc - 1, argv + 1, L_VERT); | ||
74 | } | ||
75 | } else { | ||
76 | error = cmd_results_new(CMD_FAILURE, "split", | ||
77 | "Invalid split command (expected either horizontal or vertical)."); | ||
78 | return error; | ||
79 | } | ||
80 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
81 | } | ||
82 | |||
83 | struct cmd_results *cmd_splitv(int argc, char **argv) { | ||
84 | return _do_split(argc, argv, L_VERT); | ||
85 | } | ||
86 | |||
87 | struct cmd_results *cmd_splith(int argc, char **argv) { | ||
88 | return _do_split(argc, argv, L_HORIZ); | ||
89 | } | ||
90 | |||
91 | struct cmd_results *cmd_splitt(int argc, char **argv) { | ||
92 | swayc_t *focused = current_container; | ||
93 | if (focused->parent->layout == L_VERT) { | ||
94 | return _do_split(argc, argv, L_HORIZ); | ||
95 | } else { | ||
96 | return _do_split(argc, argv, L_VERT); | ||
97 | } | ||
98 | } | ||
diff --git a/sway/commands/sticky.c b/sway/commands/sticky.c deleted file mode 100644 index 4899e061..00000000 --- a/sway/commands/sticky.c +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "sway/focus.h" | ||
4 | |||
5 | struct cmd_results *cmd_sticky(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if (config->reading) return cmd_results_new(CMD_FAILURE, "sticky", "Can't be used in config file."); | ||
8 | if (!config->active) return cmd_results_new(CMD_FAILURE, "sticky", "Can only be used when sway is running."); | ||
9 | if ((error = checkarg(argc, "sticky", EXPECTED_EQUAL_TO, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | char *action = argv[0]; | ||
13 | swayc_t *cont = get_focused_view(&root_container); | ||
14 | if (strcmp(action, "toggle") == 0) { | ||
15 | cont->sticky = !cont->sticky; | ||
16 | } else if (strcmp(action, "enable") == 0) { | ||
17 | cont->sticky = true; | ||
18 | } else if (strcmp(action, "disable") == 0) { | ||
19 | cont->sticky = false; | ||
20 | } else { | ||
21 | return cmd_results_new(CMD_FAILURE, "sticky", | ||
22 | "Expected 'sticky enable|disable|toggle'"); | ||
23 | } | ||
24 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
25 | } | ||
diff --git a/sway/commands/unmark.c b/sway/commands/unmark.c deleted file mode 100644 index ac213261..00000000 --- a/sway/commands/unmark.c +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "list.h" | ||
5 | #include "stringop.h" | ||
6 | |||
7 | struct cmd_results *cmd_unmark(int argc, char **argv) { | ||
8 | swayc_t *view = current_container; | ||
9 | |||
10 | if (view->marks) { | ||
11 | if (argc) { | ||
12 | char *mark = join_args(argv, argc); | ||
13 | int index; | ||
14 | if ((index = list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1) { | ||
15 | free(view->marks->items[index]); | ||
16 | list_del(view->marks, index); | ||
17 | |||
18 | if (view->marks->length == 0) { | ||
19 | list_free(view->marks); | ||
20 | view->marks = NULL; | ||
21 | } | ||
22 | } | ||
23 | free(mark); | ||
24 | } else { | ||
25 | list_foreach(view->marks, free); | ||
26 | list_free(view->marks); | ||
27 | view->marks = NULL; | ||
28 | } | ||
29 | } | ||
30 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
31 | } | ||
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c deleted file mode 100644 index a7839746..00000000 --- a/sway/commands/workspace.c +++ /dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/config.h" | ||
6 | #include "sway/input_state.h" | ||
7 | #include "sway/workspace.h" | ||
8 | #include "list.h" | ||
9 | #include "log.h" | ||
10 | #include "stringop.h" | ||
11 | |||
12 | struct cmd_results *cmd_workspace(int argc, char **argv) { | ||
13 | struct cmd_results *error = NULL; | ||
14 | if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { | ||
15 | return error; | ||
16 | } | ||
17 | |||
18 | int output_location = -1; | ||
19 | |||
20 | for (int i = 0; i < argc; ++i) { | ||
21 | if (strcasecmp(argv[i], "output") == 0) { | ||
22 | output_location = i; | ||
23 | break; | ||
24 | } | ||
25 | } | ||
26 | if (output_location >= 0) { | ||
27 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) { | ||
28 | return error; | ||
29 | } | ||
30 | struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); | ||
31 | if (!wso) { | ||
32 | return cmd_results_new(CMD_FAILURE, "workspace output", | ||
33 | "Unable to allocate workspace output"); | ||
34 | } | ||
35 | wso->workspace = join_args(argv, argc - 2); | ||
36 | wso->output = strdup(argv[output_location + 1]); | ||
37 | int i = -1; | ||
38 | if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) { | ||
39 | struct workspace_output *old = config->workspace_outputs->items[i]; | ||
40 | free(old); // workspaces can only be assigned to a single output | ||
41 | list_del(config->workspace_outputs, i); | ||
42 | } | ||
43 | sway_log(L_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output); | ||
44 | list_add(config->workspace_outputs, wso); | ||
45 | } else { | ||
46 | if (config->reading || !config->active) { | ||
47 | return cmd_results_new(CMD_DEFER, "workspace", NULL); | ||
48 | } | ||
49 | swayc_t *ws = NULL; | ||
50 | if (strcasecmp(argv[0], "number") == 0) { | ||
51 | if (!(ws = workspace_by_number(argv[1]))) { | ||
52 | char *name = join_args(argv + 1, argc - 1); | ||
53 | ws = workspace_create(name); | ||
54 | free(name); | ||
55 | } | ||
56 | } else if (strcasecmp(argv[0], "next") == 0) { | ||
57 | ws = workspace_next(); | ||
58 | } else if (strcasecmp(argv[0], "prev") == 0) { | ||
59 | ws = workspace_prev(); | ||
60 | } else if (strcasecmp(argv[0], "next_on_output") == 0) { | ||
61 | ws = workspace_output_next(); | ||
62 | } else if (strcasecmp(argv[0], "prev_on_output") == 0) { | ||
63 | ws = workspace_output_prev(); | ||
64 | } else if (strcasecmp(argv[0], "back_and_forth") == 0) { | ||
65 | // if auto_back_and_forth is enabled, workspace_switch will swap | ||
66 | // the workspaces. If we created prev_workspace here, workspace_switch | ||
67 | // would put us back on original workspace. | ||
68 | if (config->auto_back_and_forth) { | ||
69 | ws = swayc_active_workspace(); | ||
70 | } else if (prev_workspace_name && !(ws = workspace_by_name(prev_workspace_name))) { | ||
71 | ws = workspace_create(prev_workspace_name); | ||
72 | } | ||
73 | } else { | ||
74 | char *name = join_args(argv, argc); | ||
75 | if (!(ws = workspace_by_name(name))) { | ||
76 | ws = workspace_create(name); | ||
77 | } | ||
78 | free(name); | ||
79 | } | ||
80 | swayc_t *old_output = swayc_active_output(); | ||
81 | workspace_switch(ws); | ||
82 | swayc_t *new_output = swayc_active_output(); | ||
83 | |||
84 | if (config->mouse_warping && old_output != new_output) { | ||
85 | swayc_t *focused = get_focused_view(ws); | ||
86 | if (focused && focused->type == C_VIEW) { | ||
87 | center_pointer_on(focused); | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
92 | } | ||
diff --git a/sway/commands/workspace_auto_back_and_forth.c b/sway/commands/workspace_auto_back_and_forth.c deleted file mode 100644 index d58ae5c8..00000000 --- a/sway/commands/workspace_auto_back_and_forth.c +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *cmd_ws_auto_back_and_forth(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if ((error = checkarg(argc, "workspace_auto_back_and_forth", EXPECTED_EQUAL_TO, 1))) { | ||
8 | return error; | ||
9 | } | ||
10 | if (strcasecmp(argv[0], "yes") == 0) { | ||
11 | config->auto_back_and_forth = true; | ||
12 | } else if (strcasecmp(argv[0], "no") == 0) { | ||
13 | config->auto_back_and_forth = false; | ||
14 | } else { | ||
15 | return cmd_results_new(CMD_INVALID, "workspace_auto_back_and_forth", "Expected 'workspace_auto_back_and_forth <yes|no>'"); | ||
16 | } | ||
17 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
18 | } | ||
diff --git a/sway/commands/workspace_layout.c b/sway/commands/workspace_layout.c deleted file mode 100644 index 9ac84be2..00000000 --- a/sway/commands/workspace_layout.c +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *cmd_workspace_layout(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if ((error = checkarg(argc, "workspace_layout", EXPECTED_AT_LEAST, 1))) { | ||
8 | return error; | ||
9 | } | ||
10 | |||
11 | if (strcasecmp(argv[0], "default") == 0) { | ||
12 | config->default_layout = L_NONE; | ||
13 | } else if (strcasecmp(argv[0], "stacking") == 0) { | ||
14 | config->default_layout = L_STACKED; | ||
15 | } else if (strcasecmp(argv[0], "tabbed") == 0) { | ||
16 | config->default_layout = L_TABBED; | ||
17 | } else if (strcasecmp(argv[0], "auto") == 0) { | ||
18 | if (argc == 1) { | ||
19 | config->default_layout = L_AUTO_FIRST; | ||
20 | } else { | ||
21 | if ((error = checkarg(argc, "workspace_layout auto", EXPECTED_EQUAL_TO, 2))) { | ||
22 | return error; | ||
23 | } | ||
24 | if (strcasecmp(argv[1], "left") == 0) { | ||
25 | config->default_layout = L_AUTO_LEFT; | ||
26 | } else if (strcasecmp(argv[1], "right") == 0) { | ||
27 | config->default_layout = L_AUTO_RIGHT; | ||
28 | } else if (strcasecmp(argv[1], "top") == 0) { | ||
29 | config->default_layout = L_AUTO_TOP; | ||
30 | } else if (strcasecmp(argv[1], "bottom") == 0) { | ||
31 | config->default_layout = L_AUTO_BOTTOM; | ||
32 | } else { | ||
33 | return cmd_results_new(CMD_INVALID, "workspace_layout auto", "Expected 'workspace_layout auto <left|right|top|bottom>'"); | ||
34 | } | ||
35 | } | ||
36 | } else { | ||
37 | return cmd_results_new(CMD_INVALID, "workspace_layout", "Expected 'workspace_layout <default|stacking|tabbed|auto|auto left|auto right|auto top|auto bottom>'"); | ||
38 | } | ||
39 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
40 | } | ||