mirror of
https://github.com/swaywm/sway.git
synced 2025-11-08 13:29:50 -05:00
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
This commit is contained in:
parent
89dc047ca9
commit
81e8f31cc6
13 changed files with 290 additions and 5 deletions
37
sway/commands/scratchpad.c
Normal file
37
sway/commands/scratchpad.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include "log.h"
|
||||
#include "sway/commands.h"
|
||||
#include "sway/config.h"
|
||||
#include "sway/scratchpad.h"
|
||||
#include "sway/server.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 (!server.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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue