diff options
author | 2015-08-10 13:53:43 -0500 | |
---|---|---|
committer | 2015-08-10 13:53:43 -0500 | |
commit | c0ee2a64065f3a9953e977e517a466361444c144 (patch) | |
tree | 505618d3711dcd48c5e7941abd7dfe1ae070752f | |
parent | Focus unmanaged windows when created (diff) | |
download | sway-c0ee2a64065f3a9953e977e517a466361444c144.tar.gz sway-c0ee2a64065f3a9953e977e517a466361444c144.tar.zst sway-c0ee2a64065f3a9953e977e517a466361444c144.zip |
Added in reload and exec_always handling
-rw-r--r-- | sway/commands.c | 51 | ||||
-rw-r--r-- | sway/config.c | 9 | ||||
-rw-r--r-- | sway/config.h | 4 | ||||
-rw-r--r-- | sway/main.c | 3 |
4 files changed, 63 insertions, 4 deletions
diff --git a/sway/commands.c b/sway/commands.c index 64130fdc..df394901 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -39,7 +39,7 @@ int cmd_bindsym(struct sway_config *config, int argc, char **argv) { | |||
39 | binding->keys = create_list(); | 39 | binding->keys = create_list(); |
40 | binding->modifiers = 0; | 40 | binding->modifiers = 0; |
41 | binding->command = join_args(argv + 1, argc - 1); | 41 | binding->command = join_args(argv + 1, argc - 1); |
42 | 42 | ||
43 | list_t *split = split_string(argv[0], "+"); | 43 | list_t *split = split_string(argv[0], "+"); |
44 | int i; | 44 | int i; |
45 | for (i = 0; i < split->length; ++i) { | 45 | for (i = 0; i < split->length; ++i) { |
@@ -78,6 +78,28 @@ int cmd_exec(struct sway_config *config, int argc, char **argv) { | |||
78 | sway_log(L_ERROR, "Invalid exec command (expected at least 1 argument, got %d)", argc); | 78 | sway_log(L_ERROR, "Invalid exec command (expected at least 1 argument, got %d)", argc); |
79 | return 1; | 79 | return 1; |
80 | } | 80 | } |
81 | |||
82 | if (config->reloading) { | ||
83 | sway_log(L_DEBUG, "Ignoring exec %s due to reload", join_args(argv, argc)); | ||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | if (fork() == 0) { | ||
88 | char *args = join_args(argv, argc); | ||
89 | sway_log(L_DEBUG, "Executing %s", args); | ||
90 | execl("/bin/sh", "sh", "-c", args, (char *)NULL); | ||
91 | free(args); | ||
92 | exit(0); | ||
93 | } | ||
94 | return 0; | ||
95 | } | ||
96 | |||
97 | int cmd_exec_always(struct sway_config *config, int argc, char **argv) { | ||
98 | if (argc < 1) { | ||
99 | sway_log(L_ERROR, "Invalid exec_always command (expected at least 1 argument, got %d)", argc); | ||
100 | return 1; | ||
101 | } | ||
102 | |||
81 | if (fork() == 0) { | 103 | if (fork() == 0) { |
82 | char *args = join_args(argv, argc); | 104 | char *args = join_args(argv, argc); |
83 | sway_log(L_DEBUG, "Executing %s", args); | 105 | sway_log(L_DEBUG, "Executing %s", args); |
@@ -152,6 +174,31 @@ int cmd_layout(struct sway_config *config, int argc, char **argv) { | |||
152 | return 0; | 174 | return 0; |
153 | } | 175 | } |
154 | 176 | ||
177 | int cmd_reload(struct sway_config *config, int argc, char **argv) { | ||
178 | if (argc != 0) { | ||
179 | sway_log(L_ERROR, "Invalid reload command (expected 1 arguments, got %d)", argc); | ||
180 | return 1; | ||
181 | } | ||
182 | |||
183 | // TODO: Allow use of more config file locations | ||
184 | const char *name = "/.sway/config"; | ||
185 | const char *home = getenv("HOME"); | ||
186 | char *temp = malloc(strlen(home) + strlen(name) + 1); | ||
187 | strcpy(temp, home); | ||
188 | strcat(temp, name); | ||
189 | FILE *f = fopen(temp, "r"); | ||
190 | if (!f) { | ||
191 | fprintf(stderr, "Unable to open %s for reading", temp); | ||
192 | free(temp); | ||
193 | exit(1); | ||
194 | } | ||
195 | free(temp); | ||
196 | config = read_config(f, true); | ||
197 | fclose(f); | ||
198 | |||
199 | return 0; | ||
200 | } | ||
201 | |||
155 | int cmd_set(struct sway_config *config, int argc, char **argv) { | 202 | int cmd_set(struct sway_config *config, int argc, char **argv) { |
156 | if (argc != 2) { | 203 | if (argc != 2) { |
157 | sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc); | 204 | sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc); |
@@ -232,12 +279,14 @@ int cmd_fullscreen(struct sway_config *config, int argc, char **argv) { | |||
232 | struct cmd_handler handlers[] = { | 279 | struct cmd_handler handlers[] = { |
233 | { "bindsym", cmd_bindsym }, | 280 | { "bindsym", cmd_bindsym }, |
234 | { "exec", cmd_exec }, | 281 | { "exec", cmd_exec }, |
282 | { "exec_always", cmd_exec_always }, | ||
235 | { "exit", cmd_exit }, | 283 | { "exit", cmd_exit }, |
236 | { "focus", cmd_focus }, | 284 | { "focus", cmd_focus }, |
237 | { "focus_follows_mouse", cmd_focus_follows_mouse }, | 285 | { "focus_follows_mouse", cmd_focus_follows_mouse }, |
238 | { "fullscreen", cmd_fullscreen }, | 286 | { "fullscreen", cmd_fullscreen }, |
239 | { "layout", cmd_layout }, | 287 | { "layout", cmd_layout }, |
240 | { "log_colors", cmd_log_colors }, | 288 | { "log_colors", cmd_log_colors }, |
289 | { "reload", cmd_reload }, | ||
241 | { "set", cmd_set }, | 290 | { "set", cmd_set }, |
242 | { "splith", cmd_splith }, | 291 | { "splith", cmd_splith }, |
243 | { "splitv", cmd_splitv } | 292 | { "splitv", cmd_splitv } |
diff --git a/sway/config.c b/sway/config.c index 26dc88cb..ee6c324c 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -18,12 +18,17 @@ void config_defaults(struct sway_config *config) { | |||
18 | // Flags | 18 | // Flags |
19 | config->focus_follows_mouse = true; | 19 | config->focus_follows_mouse = true; |
20 | config->mouse_warping = true; | 20 | config->mouse_warping = true; |
21 | config->reloading = false; | ||
21 | } | 22 | } |
22 | 23 | ||
23 | struct sway_config *read_config(FILE *file) { | 24 | struct sway_config *read_config(FILE *file, bool is_active) { |
24 | struct sway_config *config = malloc(sizeof(struct sway_config)); | 25 | struct sway_config *config = malloc(sizeof(struct sway_config)); |
25 | config_defaults(config); | 26 | config_defaults(config); |
26 | 27 | ||
28 | if (is_active) { | ||
29 | config->reloading = true; | ||
30 | } | ||
31 | |||
27 | bool success = true; | 32 | bool success = true; |
28 | 33 | ||
29 | int temp_depth = 0; // Temporary: skip all config sections with depth | 34 | int temp_depth = 0; // Temporary: skip all config sections with depth |
@@ -56,6 +61,8 @@ _continue: | |||
56 | exit(1); | 61 | exit(1); |
57 | } | 62 | } |
58 | 63 | ||
64 | config->reloading = false; | ||
65 | |||
59 | return config; | 66 | return config; |
60 | } | 67 | } |
61 | 68 | ||
diff --git a/sway/config.h b/sway/config.h index 6802a341..6a50c445 100644 --- a/sway/config.h +++ b/sway/config.h | |||
@@ -29,9 +29,11 @@ struct sway_config { | |||
29 | // Flags | 29 | // Flags |
30 | bool focus_follows_mouse; | 30 | bool focus_follows_mouse; |
31 | bool mouse_warping; | 31 | bool mouse_warping; |
32 | |||
33 | bool reloading; | ||
32 | }; | 34 | }; |
33 | 35 | ||
34 | struct sway_config *read_config(FILE *file); | 36 | struct sway_config *read_config(FILE *file, bool is_active); |
35 | char *do_var_replacement(struct sway_config *config, char *str); | 37 | char *do_var_replacement(struct sway_config *config, char *str); |
36 | 38 | ||
37 | extern struct sway_config *config; | 39 | extern struct sway_config *config; |
diff --git a/sway/main.c b/sway/main.c index 248beae7..298e530d 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -23,7 +23,7 @@ void load_config() { | |||
23 | exit(1); | 23 | exit(1); |
24 | } | 24 | } |
25 | free(temp); | 25 | free(temp); |
26 | config = read_config(f); | 26 | config = read_config(f, false); |
27 | fclose(f); | 27 | fclose(f); |
28 | } | 28 | } |
29 | 29 | ||
@@ -52,6 +52,7 @@ int main(int argc, char **argv) { | |||
52 | .motion = handle_pointer_motion, | 52 | .motion = handle_pointer_motion, |
53 | .button = handle_pointer_button | 53 | .button = handle_pointer_button |
54 | } | 54 | } |
55 | |||
55 | }; | 56 | }; |
56 | 57 | ||
57 | setenv("WLC_DIM", "0", 0); | 58 | setenv("WLC_DIM", "0", 0); |