aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-02-24 13:20:34 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-02-24 13:20:34 -0500
commit5b219a15982b9626f85535c082ee2adb460ad11d (patch)
treee7cf000493871657311c1492ba314e82443b3551 /sway/commands.c
parenttake seat param for handle_command and rename (diff)
downloadsway-5b219a15982b9626f85535c082ee2adb460ad11d.tar.gz
sway-5b219a15982b9626f85535c082ee2adb460ad11d.tar.zst
sway-5b219a15982b9626f85535c082ee2adb460ad11d.zip
separate config directives and commands
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 66614058..ed8da3dc 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -125,25 +125,35 @@ struct cmd_results *add_color(const char *name, char *buffer, const char *color)
125 return NULL; 125 return NULL;
126} 126}
127 127
128/* Keep alphabetized */ 128/**
129 * handlers that can run in either config or command context
130 * Keep alphabetized
131 */
129static struct cmd_handler handlers[] = { 132static struct cmd_handler handlers[] = {
130 { "bindcode", cmd_bindcode }, 133 { "bindcode", cmd_bindcode },
131 { "bindsym", cmd_bindsym }, 134 { "bindsym", cmd_bindsym },
132 { "exec", cmd_exec }, 135 { "exec", cmd_exec },
133 { "exec_always", cmd_exec_always }, 136 { "exec_always", cmd_exec_always },
134 { "exit", cmd_exit },
135 { "focus", cmd_focus },
136 { "include", cmd_include }, 137 { "include", cmd_include },
137 { "input", cmd_input }, 138 { "input", cmd_input },
138 { "kill", cmd_kill },
139 { "layout", cmd_layout },
140 { "output", cmd_output }, 139 { "output", cmd_output },
141 { "reload", cmd_reload },
142 { "seat", cmd_seat }, 140 { "seat", cmd_seat },
143 { "set", cmd_set }, 141 { "set", cmd_set },
144 { "workspace", cmd_workspace }, 142 { "workspace", cmd_workspace },
145}; 143};
146 144
145/**
146 * Commands that can *not* run in the config loading context
147 * Keep alphabetized
148 */
149static struct cmd_handler command_handlers[] = {
150 { "exit", cmd_exit },
151 { "focus", cmd_focus },
152 { "kill", cmd_kill },
153 { "layout", cmd_layout },
154 { "reload", cmd_reload },
155};
156
147static int handler_compare(const void *_a, const void *_b) { 157static int handler_compare(const void *_a, const void *_b) {
148 const struct cmd_handler *a = _a; 158 const struct cmd_handler *a = _a;
149 const struct cmd_handler *b = _b; 159 const struct cmd_handler *b = _b;
@@ -181,20 +191,34 @@ static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
181 struct cmd_handler *res = NULL; 191 struct cmd_handler *res = NULL;
182 wlr_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_SEAT); 192 wlr_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_SEAT);
183 193
194 bool config_loading = config->reading || !config->active;
195
184 if (block == CMD_BLOCK_INPUT) { 196 if (block == CMD_BLOCK_INPUT) {
185 res = bsearch(&d, input_handlers, 197 // input commands can run in either context
198 return bsearch(&d, input_handlers,
186 sizeof(input_handlers) / sizeof(struct cmd_handler), 199 sizeof(input_handlers) / sizeof(struct cmd_handler),
187 sizeof(struct cmd_handler), handler_compare); 200 sizeof(struct cmd_handler), handler_compare);
188 } else if (block == CMD_BLOCK_SEAT) { 201 } else if (block == CMD_BLOCK_SEAT) {
189 res = bsearch(&d, seat_handlers, 202 // seat commands can run in either context
203 return bsearch(&d, seat_handlers,
190 sizeof(seat_handlers) / sizeof(struct cmd_handler), 204 sizeof(seat_handlers) / sizeof(struct cmd_handler),
191 sizeof(struct cmd_handler), handler_compare); 205 sizeof(struct cmd_handler), handler_compare);
192 } else { 206 }
193 res = bsearch(&d, handlers, 207
194 sizeof(handlers) / sizeof(struct cmd_handler), 208 if (!config_loading) {
209 res = bsearch(&d, command_handlers,
210 sizeof(command_handlers) / sizeof(struct cmd_handler),
195 sizeof(struct cmd_handler), handler_compare); 211 sizeof(struct cmd_handler), handler_compare);
212
213 if (res) {
214 return res;
215 }
196 } 216 }
197 217
218 res = bsearch(&d, handlers,
219 sizeof(handlers) / sizeof(struct cmd_handler),
220 sizeof(struct cmd_handler), handler_compare);
221
198 return res; 222 return res;
199} 223}
200 224