aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-15 11:24:16 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-15 11:24:16 +1000
commit4d1edfcba90854bd7f37ecb1b36fe4f05c37dda3 (patch)
treedf558830f4c0f5bc9e8943cfbf60532f2293aeda
parentImplement marks (diff)
downloadsway-4d1edfcba90854bd7f37ecb1b36fe4f05c37dda3.tar.gz
sway-4d1edfcba90854bd7f37ecb1b36fe4f05c37dda3.tar.zst
sway-4d1edfcba90854bd7f37ecb1b36fe4f05c37dda3.zip
Change unmark implemention to match i3's
-rw-r--r--include/sway/config.h1
-rw-r--r--sway/commands.c6
-rw-r--r--sway/commands/mark.c2
-rw-r--r--sway/commands/unmark.c49
4 files changed, 43 insertions, 15 deletions
diff --git a/include/sway/config.h b/include/sway/config.h
index f77c3b50..33f52156 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -368,6 +368,7 @@ struct sway_config {
368 struct seat_config *seat_config; 368 struct seat_config *seat_config;
369 struct sway_seat *seat; 369 struct sway_seat *seat;
370 struct sway_container *current_container; 370 struct sway_container *current_container;
371 bool using_criteria;
371 } handler_context; 372 } handler_context;
372}; 373};
373 374
diff --git a/sway/commands.c b/sway/commands.c
index 31d241a8..9b6d6459 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -302,7 +302,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
302 head = exec; 302 head = exec;
303 do { 303 do {
304 // Extract criteria (valid for this command list only). 304 // Extract criteria (valid for this command list only).
305 bool has_criteria = false; 305 config->handler_context.using_criteria = false;
306 if (*head == '[') { 306 if (*head == '[') {
307 char *error = NULL; 307 char *error = NULL;
308 struct criteria *criteria = criteria_parse(head, &error); 308 struct criteria *criteria = criteria_parse(head, &error);
@@ -315,7 +315,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
315 views = criteria_get_views(criteria); 315 views = criteria_get_views(criteria);
316 head += strlen(criteria->raw); 316 head += strlen(criteria->raw);
317 criteria_destroy(criteria); 317 criteria_destroy(criteria);
318 has_criteria = true; 318 config->handler_context.using_criteria = true;
319 // Skip leading whitespace 319 // Skip leading whitespace
320 head += strspn(head, whitespace); 320 head += strspn(head, whitespace);
321 } 321 }
@@ -352,7 +352,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
352 goto cleanup; 352 goto cleanup;
353 } 353 }
354 354
355 if (!has_criteria) { 355 if (!config->handler_context.using_criteria) {
356 // without criteria, the command acts upon the focused 356 // without criteria, the command acts upon the focused
357 // container 357 // container
358 config->handler_context.current_container = 358 config->handler_context.current_container =
diff --git a/sway/commands/mark.c b/sway/commands/mark.c
index 782e8ab9..b131f2f3 100644
--- a/sway/commands/mark.c
+++ b/sway/commands/mark.c
@@ -57,7 +57,7 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
57 57
58 view_find_and_unmark(mark); 58 view_find_and_unmark(mark);
59 59
60 if (!toggle || (toggle && !had_mark)) { 60 if (!toggle || !had_mark) {
61 list_add(view->marks, strdup(mark)); 61 list_add(view->marks, strdup(mark));
62 } 62 }
63 63
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
10static 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
10struct cmd_results *cmd_unmark(int argc, char **argv) { 21struct 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}