aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--include/sway/commands.h4
-rw-r--r--sway/commands.c46
-rw-r--r--sway/input/keyboard.c2
-rw-r--r--sway/ipc-server.c3
-rw-r--r--sway/server.c2
5 files changed, 32 insertions, 25 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index 4ee7af2a..9ff18823 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -46,9 +46,9 @@ struct cmd_results *checkarg(int argc, const char *name,
46 enum expected_args type, int val); 46 enum expected_args type, int val);
47 47
48/** 48/**
49 * Parse and handles a command. 49 * Parse and executes a command.
50 */ 50 */
51struct cmd_results *handle_command(char *command); 51struct cmd_results *execute_command(char *command, struct sway_seat *seat);
52/** 52/**
53 * Parse and handles a command during config file loading. 53 * Parse and handles a command during config file loading.
54 * 54 *
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;
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index 6dc57d46..99685052 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -95,7 +95,7 @@ static void keyboard_execute_command(struct sway_keyboard *keyboard,
95 binding->command); 95 binding->command);
96 config_clear_handler_context(config); 96 config_clear_handler_context(config);
97 config->handler_context.seat = keyboard->seat_device->sway_seat; 97 config->handler_context.seat = keyboard->seat_device->sway_seat;
98 struct cmd_results *results = handle_command(binding->command); 98 struct cmd_results *results = execute_command(binding->command, NULL);
99 if (results->status != CMD_SUCCESS) { 99 if (results->status != CMD_SUCCESS) {
100 wlr_log(L_DEBUG, "could not run command for binding: %s", 100 wlr_log(L_DEBUG, "could not run command for binding: %s",
101 binding->command); 101 binding->command);
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index ee259c99..4c0953e8 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -336,8 +336,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
336 case IPC_COMMAND: 336 case IPC_COMMAND:
337 { 337 {
338 config_clear_handler_context(config); 338 config_clear_handler_context(config);
339 config->handler_context.seat = input_manager_current_seat(input_manager); 339 struct cmd_results *results = execute_command(buf, NULL);
340 struct cmd_results *results = handle_command(buf);
341 const char *json = cmd_results_to_json(results); 340 const char *json = cmd_results_to_json(results);
342 char reply[256]; 341 char reply[256];
343 int length = snprintf(reply, sizeof(reply), "%s", json); 342 int length = snprintf(reply, sizeof(reply), "%s", json);
diff --git a/sway/server.c b/sway/server.c
index 0753d37e..495769ee 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -22,7 +22,7 @@ static void server_ready(struct wl_listener *listener, void *data) {
22 config->active = true; 22 config->active = true;
23 while (config->cmd_queue->length) { 23 while (config->cmd_queue->length) {
24 char *line = config->cmd_queue->items[0]; 24 char *line = config->cmd_queue->items[0];
25 struct cmd_results *res = handle_command(line); 25 struct cmd_results *res = execute_command(line, NULL);
26 if (res->status != CMD_SUCCESS) { 26 if (res->status != CMD_SUCCESS) {
27 wlr_log(L_ERROR, "Error on line '%s': %s", line, res->error); 27 wlr_log(L_ERROR, "Error on line '%s': %s", line, res->error);
28 } 28 }