diff options
Diffstat (limited to 'sway/commands/unmark.c')
-rw-r--r-- | sway/commands/unmark.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/sway/commands/unmark.c b/sway/commands/unmark.c new file mode 100644 index 00000000..ea2a5709 --- /dev/null +++ b/sway/commands/unmark.c | |||
@@ -0,0 +1,59 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/config.h" | ||
5 | #include "sway/tree/view.h" | ||
6 | #include "list.h" | ||
7 | #include "log.h" | ||
8 | #include "stringop.h" | ||
9 | |||
10 | static void remove_all_marks_iterator(struct sway_container *con, void *data) { | ||
11 | if (con->type == C_VIEW) { | ||
12 | view_clear_marks(con->sway_view); | ||
13 | } | ||
14 | } | ||
15 | |||
16 | // unmark Remove all marks from all views | ||
17 | // unmark foo Remove single mark from whichever view has it | ||
18 | // [criteria] unmark Remove all marks from matched view | ||
19 | // [criteria] unmark foo Remove single mark from matched view | ||
20 | |||
21 | struct cmd_results *cmd_unmark(int argc, char **argv) { | ||
22 | // Determine the view | ||
23 | struct sway_view *view = NULL; | ||
24 | if (config->handler_context.using_criteria) { | ||
25 | struct sway_container *container = | ||
26 | config->handler_context.current_container; | ||
27 | if (container->type != C_VIEW) { | ||
28 | return cmd_results_new(CMD_INVALID, "unmark", | ||
29 | "Only views can have marks"); | ||
30 | } | ||
31 | view = container->sway_view; | ||
32 | } | ||
33 | |||
34 | // Determine the mark | ||
35 | char *mark = NULL; | ||
36 | if (argc > 0) { | ||
37 | mark = join_args(argv, argc); | ||
38 | } | ||
39 | |||
40 | if (view && mark) { | ||
41 | // Remove the mark from the given view | ||
42 | if (view_has_mark(view, mark)) { | ||
43 | view_find_and_unmark(mark); | ||
44 | } | ||
45 | } else if (view && !mark) { | ||
46 | // Clear all marks from the given view | ||
47 | view_clear_marks(view); | ||
48 | } else if (!view && mark) { | ||
49 | // Remove mark from whichever view has it | ||
50 | view_find_and_unmark(mark); | ||
51 | } else { | ||
52 | // Remove all marks from all views | ||
53 | container_for_each_descendant_dfs(&root_container, | ||
54 | remove_all_marks_iterator, NULL); | ||
55 | } | ||
56 | free(mark); | ||
57 | |||
58 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
59 | } | ||