aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/scratchpad.c
blob: ccc07c878489c43f9b81b77bd686f4b972460393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "log.h"
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/scratchpad.h"
#include "sway/tree/container.h"

struct cmd_results *cmd_scratchpad(int argc, char **argv) {
	struct cmd_results *error = NULL;
	if ((error = checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1))) {
		return error;
	}
	if (strcmp(argv[0], "show") != 0) {
		return cmd_results_new(CMD_INVALID, "scratchpad",
				"Expected 'scratchpad show'");
	}
	if (!root_container.sway_root->scratchpad->length) {
		return cmd_results_new(CMD_INVALID, "scratchpad",
				"Scratchpad is empty");
	}

	if (config->handler_context.using_criteria) {
		// If using criteria, this command is executed for every container which
		// matches the criteria. If this container isn't in the scratchpad,
		// we'll just silently return a success.
		struct sway_container *con = config->handler_context.current_container;
		wlr_log(WLR_INFO, "cmd_scratchpad(%s)", con->name);
		if (!con->scratchpad) {
			return cmd_results_new(CMD_SUCCESS, NULL, NULL);
		}
		scratchpad_toggle_container(con);
	} else {
		scratchpad_toggle_auto();
	}

	return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}