diff options
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/move.c | 19 | ||||
-rw-r--r-- | sway/commands/scratchpad.c | 37 |
2 files changed, 53 insertions, 3 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c index 6ec050a8..1940043d 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include "sway/input/cursor.h" | 9 | #include "sway/input/cursor.h" |
10 | #include "sway/input/seat.h" | 10 | #include "sway/input/seat.h" |
11 | #include "sway/output.h" | 11 | #include "sway/output.h" |
12 | #include "sway/scratchpad.h" | ||
12 | #include "sway/tree/arrange.h" | 13 | #include "sway/tree/arrange.h" |
13 | #include "sway/tree/container.h" | 14 | #include "sway/tree/container.h" |
14 | #include "sway/tree/layout.h" | 15 | #include "sway/tree/layout.h" |
@@ -296,6 +297,19 @@ static struct cmd_results *move_to_position(struct sway_container *container, | |||
296 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 297 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
297 | } | 298 | } |
298 | 299 | ||
300 | static struct cmd_results *move_to_scratchpad(struct sway_container *con) { | ||
301 | if (con->type != C_CONTAINER && con->type != C_VIEW) { | ||
302 | return cmd_results_new(CMD_INVALID, "move", | ||
303 | "Only views and containers can be moved to the scratchpad"); | ||
304 | } | ||
305 | if (con->scratchpad) { | ||
306 | return cmd_results_new(CMD_INVALID, "move", | ||
307 | "Container is already in the scratchpad"); | ||
308 | } | ||
309 | scratchpad_add_container(con); | ||
310 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
311 | } | ||
312 | |||
299 | struct cmd_results *cmd_move(int argc, char **argv) { | 313 | struct cmd_results *cmd_move(int argc, char **argv) { |
300 | struct cmd_results *error = NULL; | 314 | struct cmd_results *error = NULL; |
301 | if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { | 315 | if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { |
@@ -317,10 +331,9 @@ struct cmd_results *cmd_move(int argc, char **argv) { | |||
317 | } else if (strcasecmp(argv[0], "workspace") == 0) { | 331 | } else if (strcasecmp(argv[0], "workspace") == 0) { |
318 | return cmd_move_workspace(current, argc, argv); | 332 | return cmd_move_workspace(current, argc, argv); |
319 | } else if (strcasecmp(argv[0], "scratchpad") == 0 | 333 | } else if (strcasecmp(argv[0], "scratchpad") == 0 |
320 | || (strcasecmp(argv[0], "to") == 0 | 334 | || (strcasecmp(argv[0], "to") == 0 && argc == 2 |
321 | && strcasecmp(argv[1], "scratchpad") == 0)) { | 335 | && strcasecmp(argv[1], "scratchpad") == 0)) { |
322 | // TODO: scratchpad | 336 | return move_to_scratchpad(current); |
323 | return cmd_results_new(CMD_FAILURE, "move", "Unimplemented"); | ||
324 | } else if (strcasecmp(argv[0], "position") == 0) { | 337 | } else if (strcasecmp(argv[0], "position") == 0) { |
325 | return move_to_position(current, argc, argv); | 338 | return move_to_position(current, argc, argv); |
326 | } else if (strcasecmp(argv[0], "absolute") == 0) { | 339 | } else if (strcasecmp(argv[0], "absolute") == 0) { |
diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c new file mode 100644 index 00000000..8a529cb4 --- /dev/null +++ b/sway/commands/scratchpad.c | |||
@@ -0,0 +1,37 @@ | |||
1 | #include "log.h" | ||
2 | #include "sway/commands.h" | ||
3 | #include "sway/config.h" | ||
4 | #include "sway/scratchpad.h" | ||
5 | #include "sway/server.h" | ||
6 | #include "sway/tree/container.h" | ||
7 | |||
8 | struct cmd_results *cmd_scratchpad(int argc, char **argv) { | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | if (strcmp(argv[0], "show") != 0) { | ||
14 | return cmd_results_new(CMD_INVALID, "scratchpad", | ||
15 | "Expected 'scratchpad show'"); | ||
16 | } | ||
17 | if (!server.scratchpad->length) { | ||
18 | return cmd_results_new(CMD_INVALID, "scratchpad", | ||
19 | "Scratchpad is empty"); | ||
20 | } | ||
21 | |||
22 | if (config->handler_context.using_criteria) { | ||
23 | // If using criteria, this command is executed for every container which | ||
24 | // matches the criteria. If this container isn't in the scratchpad, | ||
25 | // we'll just silently return a success. | ||
26 | struct sway_container *con = config->handler_context.current_container; | ||
27 | wlr_log(WLR_INFO, "cmd_scratchpad(%s)", con->name); | ||
28 | if (!con->scratchpad) { | ||
29 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
30 | } | ||
31 | scratchpad_toggle_container(con); | ||
32 | } else { | ||
33 | scratchpad_toggle_auto(); | ||
34 | } | ||
35 | |||
36 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
37 | } | ||