aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/scratchpad.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-07-22 14:10:40 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-07-23 08:24:32 +1000
commit81e8f31cc6f284b54ab206e14af7ecbc1a9ed1bb (patch)
treeea124a94869d06edb3f98e85ecd649275e86ef91 /sway/commands/scratchpad.c
parentMerge pull request #2328 from emersion/xdg-shell-set-title (diff)
downloadsway-81e8f31cc6f284b54ab206e14af7ecbc1a9ed1bb.tar.gz
sway-81e8f31cc6f284b54ab206e14af7ecbc1a9ed1bb.tar.zst
sway-81e8f31cc6f284b54ab206e14af7ecbc1a9ed1bb.zip
Implement scratchpad
Implements the following commands: * move scratchpad * scratchpad show * [criteria] scratchpad show Also fixes these: * Fix memory leak when executing command with criteria (use `list_free(views)` instead of `free(views)`) * Fix crash when running `move to` with no further arguments
Diffstat (limited to 'sway/commands/scratchpad.c')
-rw-r--r--sway/commands/scratchpad.c37
1 files changed, 37 insertions, 0 deletions
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
8struct 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}