aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-02-24 12:50:24 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-02-24 12:50:24 -0500
commitac8269d536bf636bd0fbf8047cf6516912634864 (patch)
treed23376a0f745e113b3ddfb10573375c9d6ea587e /sway/commands.c
parentupdate log.h for latest wlr (diff)
downloadsway-ac8269d536bf636bd0fbf8047cf6516912634864.tar.gz
sway-ac8269d536bf636bd0fbf8047cf6516912634864.tar.zst
sway-ac8269d536bf636bd0fbf8047cf6516912634864.zip
take seat param for handle_command and rename
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c46
1 files changed, 27 insertions, 19 deletions
diff --git a/sway/commands.c b/sway/commands.c
index a7eb6b4a..66614058 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -198,7 +198,7 @@ static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
198 return res; 198 return res;
199} 199}
200 200
201struct cmd_results *handle_command(char *_exec) { 201struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
202 // Even though this function will process multiple commands we will only 202 // Even though this function will process multiple commands we will only
203 // return the last error, if any (for now). (Since we have access to an 203 // return the last error, if any (for now). (Since we have access to an
204 // error string we could e.g. concatenate all errors there.) 204 // error string we could e.g. concatenate all errors there.)
@@ -209,6 +209,16 @@ struct cmd_results *handle_command(char *_exec) {
209 char *cmd; 209 char *cmd;
210 list_t *containers = NULL; 210 list_t *containers = NULL;
211 211
212 if (seat == NULL) {
213 // passing a NULL seat means we just pick the default seat
214 seat = sway_input_manager_get_default_seat(input_manager);
215 if (!sway_assert(seat, "could not find a seat to run the command on")) {
216 return NULL;
217 }
218 }
219
220 config->handler_context.seat = seat;
221
212 head = exec; 222 head = exec;
213 do { 223 do {
214 // Extract criteria (valid for this command list only). 224 // Extract criteria (valid for this command list only).
@@ -278,24 +288,22 @@ struct cmd_results *handle_command(char *_exec) {
278 if (!has_criteria) { 288 if (!has_criteria) {
279 // without criteria, the command acts upon the focused 289 // without criteria, the command acts upon the focused
280 // container 290 // container
281 struct sway_seat *seat = config->handler_context.seat; 291 config->handler_context.current_container =
282 if (!seat) { 292 sway_seat_get_focus_inactive(seat, &root_container);
283 seat = sway_input_manager_get_default_seat(input_manager); 293 if (!sway_assert(config->handler_context.current_container,
294 "could not get focus-inactive for root container")) {
295 return NULL;
284 } 296 }
285 if (seat) { 297 struct cmd_results *res = handler->handle(argc-1, argv+1);
286 config->handler_context.current_container = 298 if (res->status != CMD_SUCCESS) {
287 sway_seat_get_focus(seat); 299 free_argv(argc, argv);
288 struct cmd_results *res = handler->handle(argc-1, argv+1); 300 if (results) {
289 if (res->status != CMD_SUCCESS) { 301 free_cmd_results(results);
290 free_argv(argc, argv);
291 if (results) {
292 free_cmd_results(results);
293 }
294 results = res;
295 goto cleanup;
296 } 302 }
297 free_cmd_results(res); 303 results = res;
304 goto cleanup;
298 } 305 }
306 free_cmd_results(res);
299 } else { 307 } else {
300 for (int i = 0; i < containers->length; ++i) { 308 for (int i = 0; i < containers->length; ++i) {
301 config->handler_context.current_container = containers->items[i]; 309 config->handler_context.current_container = containers->items[i];
@@ -322,13 +330,13 @@ cleanup:
322 return results; 330 return results;
323} 331}
324 332
325// this is like handle_command above, except: 333// this is like execute_command above, except:
326// 1) it ignores empty commands (empty lines) 334// 1) it ignores empty commands (empty lines)
327// 2) it does variable substitution 335// 2) it does variable substitution
328// 3) it doesn't split commands (because the multiple commands are supposed to 336// 3) it doesn't split commands (because the multiple commands are supposed to
329// be chained together) 337// be chained together)
330// 4) handle_command handles all state internally while config_command has some 338// 4) execute_command handles all state internally while config_command has
331// state handled outside (notably the block mode, in read_config) 339// some state handled outside (notably the block mode, in read_config)
332struct cmd_results *config_command(char *exec, enum cmd_status block) { 340struct cmd_results *config_command(char *exec, enum cmd_status block) {
333 struct cmd_results *results = NULL; 341 struct cmd_results *results = NULL;
334 int argc; 342 int argc;