diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-23 08:38:15 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-23 08:39:11 +1000 |
commit | cb66bbea42adeabd7bd87132a66589e14a46940f (patch) | |
tree | 43f409e1619b2deded320f0af7064e73e3969d30 /sway/commands.c | |
parent | Merge pull request #2677 from ggreer/pretty-fonts (diff) | |
download | sway-cb66bbea42adeabd7bd87132a66589e14a46940f.tar.gz sway-cb66bbea42adeabd7bd87132a66589e14a46940f.tar.zst sway-cb66bbea42adeabd7bd87132a66589e14a46940f.zip |
Allow running commands on containers without focusing them
This adds a `con` argument to `execute_command` which allows you to
specify the container to execute the command on. In most cases it leaves
it as `NULL` which makes it use the focused node. We only set it when
executing `for_window` criteria such as when a view maps. This means we
don't send unnecessary IPC focus events, and fixes a crash when the
criteria command is `move scratchpad` (because we can't give focus to a
hidden scratchpad container).
Each of the shell map handlers now check to see if the view has a
workspace. It won't have a workspace if criteria has moved it to the
scratchpad.
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/sway/commands.c b/sway/commands.c index 07169f1e..5b61f73a 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -237,7 +237,8 @@ static void set_config_node(struct sway_node *node) { | |||
237 | } | 237 | } |
238 | } | 238 | } |
239 | 239 | ||
240 | struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) { | 240 | struct cmd_results *execute_command(char *_exec, struct sway_seat *seat, |
241 | struct sway_container *con) { | ||
241 | // Even though this function will process multiple commands we will only | 242 | // Even though this function will process multiple commands we will only |
242 | // return the last error, if any (for now). (Since we have access to an | 243 | // return the last error, if any (for now). (Since we have access to an |
243 | // error string we could e.g. concatenate all errors there.) | 244 | // error string we could e.g. concatenate all errors there.) |
@@ -256,6 +257,15 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) { | |||
256 | } | 257 | } |
257 | } | 258 | } |
258 | 259 | ||
260 | // This is the container or workspace which this command will run on. | ||
261 | // Ignored if the command string contains criteria. | ||
262 | struct sway_node *node; | ||
263 | if (con) { | ||
264 | node = &con->node; | ||
265 | } else { | ||
266 | node = seat_get_focus_inactive(seat, &root->node); | ||
267 | } | ||
268 | |||
259 | config->handler_context.seat = seat; | 269 | config->handler_context.seat = seat; |
260 | 270 | ||
261 | head = exec; | 271 | head = exec; |
@@ -318,9 +328,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) { | |||
318 | } | 328 | } |
319 | 329 | ||
320 | if (!config->handler_context.using_criteria) { | 330 | if (!config->handler_context.using_criteria) { |
321 | // without criteria, the command acts upon the focused | 331 | set_config_node(node); |
322 | // container | ||
323 | set_config_node(seat_get_focus_inactive(seat, &root->node)); | ||
324 | struct cmd_results *res = handler->handle(argc-1, argv+1); | 332 | struct cmd_results *res = handler->handle(argc-1, argv+1); |
325 | if (res->status != CMD_SUCCESS) { | 333 | if (res->status != CMD_SUCCESS) { |
326 | free_argv(argc, argv); | 334 | free_argv(argc, argv); |