summaryrefslogtreecommitdiffstats
path: root/sway/commands/scratchpad.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/scratchpad.c')
-rw-r--r--sway/commands/scratchpad.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c
new file mode 100644
index 00000000..01a91d65
--- /dev/null
+++ b/sway/commands/scratchpad.c
@@ -0,0 +1,44 @@
1#include "log.h"
2#include "sway/commands.h"
3#include "sway/config.h"
4#include "sway/scratchpad.h"
5#include "sway/tree/container.h"
6
7struct cmd_results *cmd_scratchpad(int argc, char **argv) {
8 struct cmd_results *error = NULL;
9 if ((error = checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1))) {
10 return error;
11 }
12 if (strcmp(argv[0], "show") != 0) {
13 return cmd_results_new(CMD_INVALID, "scratchpad",
14 "Expected 'scratchpad show'");
15 }
16 if (!root_container.sway_root->scratchpad->length) {
17 return cmd_results_new(CMD_INVALID, "scratchpad",
18 "Scratchpad is empty");
19 }
20
21 if (config->handler_context.using_criteria) {
22 struct sway_container *con = config->handler_context.current_container;
23
24 // If the container is in a floating split container,
25 // operate on the split container instead of the child.
26 if (container_is_floating_or_child(con)) {
27 while (con->parent->layout != L_FLOATING) {
28 con = con->parent;
29 }
30 }
31
32 // If using criteria, this command is executed for every container which
33 // matches the criteria. If this container isn't in the scratchpad,
34 // we'll just silently return a success.
35 if (!con->scratchpad) {
36 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
37 }
38 scratchpad_toggle_container(con);
39 } else {
40 scratchpad_toggle_auto();
41 }
42
43 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
44}