aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/move.c19
-rw-r--r--sway/commands/scratchpad.c36
2 files changed, 52 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 @@
#include "sway/input/cursor.h"
#include "sway/input/seat.h"
#include "sway/output.h"
+#include "sway/scratchpad.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/layout.h"
@@ -296,6 +297,19 @@ static struct cmd_results *move_to_position(struct sway_container *container,
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
+static struct cmd_results *move_to_scratchpad(struct sway_container *con) {
+ if (con->type != C_CONTAINER && con->type != C_VIEW) {
+ return cmd_results_new(CMD_INVALID, "move",
+ "Only views and containers can be moved to the scratchpad");
+ }
+ if (con->scratchpad) {
+ return cmd_results_new(CMD_INVALID, "move",
+ "Container is already in the scratchpad");
+ }
+ scratchpad_add_container(con);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
struct cmd_results *cmd_move(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) {
@@ -317,10 +331,9 @@ struct cmd_results *cmd_move(int argc, char **argv) {
} else if (strcasecmp(argv[0], "workspace") == 0) {
return cmd_move_workspace(current, argc, argv);
} else if (strcasecmp(argv[0], "scratchpad") == 0
- || (strcasecmp(argv[0], "to") == 0
+ || (strcasecmp(argv[0], "to") == 0 && argc == 2
&& strcasecmp(argv[1], "scratchpad") == 0)) {
- // TODO: scratchpad
- return cmd_results_new(CMD_FAILURE, "move", "Unimplemented");
+ return move_to_scratchpad(current);
} else if (strcasecmp(argv[0], "position") == 0) {
return move_to_position(current, argc, argv);
} 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..ccc07c87
--- /dev/null
+++ b/sway/commands/scratchpad.c
@@ -0,0 +1,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);
+}