diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-05-15 11:24:16 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-05-15 11:24:16 +1000 |
commit | 4d1edfcba90854bd7f37ecb1b36fe4f05c37dda3 (patch) | |
tree | df558830f4c0f5bc9e8943cfbf60532f2293aeda /sway/commands/unmark.c | |
parent | Implement marks (diff) | |
download | sway-4d1edfcba90854bd7f37ecb1b36fe4f05c37dda3.tar.gz sway-4d1edfcba90854bd7f37ecb1b36fe4f05c37dda3.tar.zst sway-4d1edfcba90854bd7f37ecb1b36fe4f05c37dda3.zip |
Change unmark implemention to match i3's
Diffstat (limited to 'sway/commands/unmark.c')
-rw-r--r-- | sway/commands/unmark.c | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/sway/commands/unmark.c b/sway/commands/unmark.c index a7d39432..ea2a5709 100644 --- a/sway/commands/unmark.c +++ b/sway/commands/unmark.c | |||
@@ -7,26 +7,53 @@ | |||
7 | #include "log.h" | 7 | #include "log.h" |
8 | #include "stringop.h" | 8 | #include "stringop.h" |
9 | 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 | |||
10 | struct cmd_results *cmd_unmark(int argc, char **argv) { | 21 | struct cmd_results *cmd_unmark(int argc, char **argv) { |
11 | if (argc == 0) { | 22 | // Determine the view |
12 | // Remove all marks from the current container | 23 | struct sway_view *view = NULL; |
24 | if (config->handler_context.using_criteria) { | ||
13 | struct sway_container *container = | 25 | struct sway_container *container = |
14 | config->handler_context.current_container; | 26 | config->handler_context.current_container; |
15 | if (container->type != C_VIEW) { | 27 | if (container->type != C_VIEW) { |
16 | return cmd_results_new(CMD_INVALID, "unmark", | 28 | return cmd_results_new(CMD_INVALID, "unmark", |
17 | "Only views can have marks"); | 29 | "Only views can have marks"); |
18 | } | 30 | } |
19 | view_clear_marks(container->sway_view); | 31 | view = container->sway_view; |
20 | } else { | 32 | } |
21 | // Remove a single mark from whichever container has it | 33 | |
22 | char *mark = join_args(argv, argc); | 34 | // Determine the mark |
23 | if (!view_find_and_unmark(mark)) { | 35 | char *mark = NULL; |
24 | free(mark); | 36 | if (argc > 0) { |
25 | return cmd_results_new(CMD_INVALID, "unmark", | 37 | mark = join_args(argv, argc); |
26 | "No view exists with that mark"); | 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); | ||
27 | } | 44 | } |
28 | free(mark); | 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); | ||
29 | } | 55 | } |
56 | free(mark); | ||
30 | 57 | ||
31 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 58 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
32 | } | 59 | } |