aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/tree/container.h4
-rw-r--r--sway/commands/swap.c4
-rw-r--r--sway/input/seat.c2
-rw-r--r--sway/tree/container.c6
-rw-r--r--sway/tree/layout.c8
-rw-r--r--sway/tree/view.c33
-rw-r--r--swaymsg/main.c21
7 files changed, 42 insertions, 36 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index a5f591ce..bb6c04a6 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -186,8 +186,8 @@ void container_for_each_descendant_dfs(struct sway_container *container,
186/** 186/**
187 * Returns true if the given container is an ancestor of this container. 187 * Returns true if the given container is an ancestor of this container.
188 */ 188 */
189bool container_has_anscestor(struct sway_container *container, 189bool container_has_ancestor(struct sway_container *container,
190 struct sway_container *anscestor); 190 struct sway_container *ancestor);
191 191
192/** 192/**
193 * Returns true if the given container is a child descendant of this container. 193 * Returns true if the given container is a child descendant of this container.
diff --git a/sway/commands/swap.c b/sway/commands/swap.c
index e925ad33..e8dfc57f 100644
--- a/sway/commands/swap.c
+++ b/sway/commands/swap.c
@@ -60,8 +60,8 @@ struct cmd_results *cmd_swap(int argc, char **argv) {
60 } else if (current->type < C_CONTAINER || other->type < C_CONTAINER) { 60 } else if (current->type < C_CONTAINER || other->type < C_CONTAINER) {
61 error = cmd_results_new(CMD_FAILURE, "swap", 61 error = cmd_results_new(CMD_FAILURE, "swap",
62 "Can only swap with containers and views"); 62 "Can only swap with containers and views");
63 } else if (container_has_anscestor(current, other) 63 } else if (container_has_ancestor(current, other)
64 || container_has_anscestor(other, current)) { 64 || container_has_ancestor(other, current)) {
65 error = cmd_results_new(CMD_FAILURE, "swap", 65 error = cmd_results_new(CMD_FAILURE, "swap",
66 "Cannot swap ancestor and descendant"); 66 "Cannot swap ancestor and descendant");
67 } else if (current->layout == L_FLOATING || other->layout == L_FLOATING) { 67 } else if (current->layout == L_FLOATING || other->layout == L_FLOATING) {
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 6cfbe8d4..0295212c 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -542,7 +542,7 @@ void seat_set_focus_warp(struct sway_seat *seat,
542 return; 542 return;
543 } 543 }
544 544
545 // put all the anscestors of this container on top of the focus stack 545 // put all the ancestors of this container on top of the focus stack
546 struct sway_seat_container *parent = 546 struct sway_seat_container *parent =
547 seat_container_from_container(seat, container->parent); 547 seat_container_from_container(seat, container->parent);
548 while (parent) { 548 while (parent) {
diff --git a/sway/tree/container.c b/sway/tree/container.c
index a4798c7e..59137d88 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -656,11 +656,11 @@ void container_for_each_descendant_bfs(struct sway_container *con,
656 } 656 }
657} 657}
658 658
659bool container_has_anscestor(struct sway_container *descendant, 659bool container_has_ancestor(struct sway_container *descendant,
660 struct sway_container *anscestor) { 660 struct sway_container *ancestor) {
661 while (descendant->type != C_ROOT) { 661 while (descendant->type != C_ROOT) {
662 descendant = descendant->parent; 662 descendant = descendant->parent;
663 if (descendant == anscestor) { 663 if (descendant == ancestor) {
664 return true; 664 return true;
665 } 665 }
666 } 666 }
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 6d76ae0f..1507eba9 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -157,7 +157,7 @@ struct sway_container *container_remove_child(struct sway_container *child) {
157void container_move_to(struct sway_container *container, 157void container_move_to(struct sway_container *container,
158 struct sway_container *destination) { 158 struct sway_container *destination) {
159 if (container == destination 159 if (container == destination
160 || container_has_anscestor(container, destination)) { 160 || container_has_ancestor(container, destination)) {
161 return; 161 return;
162 } 162 }
163 struct sway_container *old_parent = container_remove_child(container); 163 struct sway_container *old_parent = container_remove_child(container);
@@ -953,9 +953,9 @@ void container_swap(struct sway_container *con1, struct sway_container *con2) {
953 "Can only swap containers and views")) { 953 "Can only swap containers and views")) {
954 return; 954 return;
955 } 955 }
956 if (!sway_assert(!container_has_anscestor(con1, con2) 956 if (!sway_assert(!container_has_ancestor(con1, con2)
957 && !container_has_anscestor(con2, con1), 957 && !container_has_ancestor(con2, con1),
958 "Cannot swap anscestor and descendant")) { 958 "Cannot swap ancestor and descendant")) {
959 return; 959 return;
960 } 960 }
961 if (!sway_assert(con1->layout != L_FLOATING && con2->layout != L_FLOATING, 961 if (!sway_assert(con1->layout != L_FLOATING && con2->layout != L_FLOATING,
diff --git a/sway/tree/view.c b/sway/tree/view.c
index d91182ed..26ff1e8d 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -641,6 +641,14 @@ void view_child_destroy(struct sway_view_child *child) {
641 } 641 }
642} 642}
643 643
644static size_t append_prop(char *buffer, const char *value) {
645 if (!value) {
646 return 0;
647 }
648 lenient_strcat(buffer, value);
649 return strlen(value);
650}
651
644/** 652/**
645 * Calculate and return the length of the formatted title. 653 * Calculate and return the length of the formatted title.
646 * If buffer is not NULL, also populate the buffer with the formatted title. 654 * If buffer is not NULL, also populate the buffer with the formatted title.
@@ -653,16 +661,6 @@ static size_t parse_title_format(struct sway_view *view, char *buffer) {
653 } 661 }
654 return title ? strlen(title) : 0; 662 return title ? strlen(title) : 0;
655 } 663 }
656 const char *title = view_get_title(view);
657 const char *app_id = view_get_app_id(view);
658 const char *class = view_get_class(view);
659 const char *instance = view_get_instance(view);
660 const char *shell = view_get_shell(view);
661 size_t title_len = title ? strlen(title) : 0;
662 size_t app_id_len = app_id ? strlen(app_id) : 0;
663 size_t class_len = class ? strlen(class) : 0;
664 size_t instance_len = instance ? strlen(instance) : 0;
665 size_t shell_len = shell ? strlen(shell) : 0;
666 664
667 size_t len = 0; 665 size_t len = 0;
668 char *format = view->title_format; 666 char *format = view->title_format;
@@ -674,24 +672,19 @@ static size_t parse_title_format(struct sway_view *view, char *buffer) {
674 format = next; 672 format = next;
675 673
676 if (strncmp(next, "%title", 6) == 0) { 674 if (strncmp(next, "%title", 6) == 0) {
677 lenient_strcat(buffer, title); 675 len += append_prop(buffer, view_get_title(view));
678 len += title_len;
679 format += 6; 676 format += 6;
680 } else if (strncmp(next, "%app_id", 7) == 0) { 677 } else if (strncmp(next, "%app_id", 7) == 0) {
681 lenient_strcat(buffer, app_id); 678 len += append_prop(buffer, view_get_app_id(view));
682 len += app_id_len;
683 format += 7; 679 format += 7;
684 } else if (strncmp(next, "%class", 6) == 0) { 680 } else if (strncmp(next, "%class", 6) == 0) {
685 lenient_strcat(buffer, class); 681 len += append_prop(buffer, view_get_class(view));
686 len += class_len;
687 format += 6; 682 format += 6;
688 } else if (strncmp(next, "%instance", 9) == 0) { 683 } else if (strncmp(next, "%instance", 9) == 0) {
689 lenient_strcat(buffer, instance); 684 len += append_prop(buffer, view_get_instance(view));
690 len += instance_len;
691 format += 9; 685 format += 9;
692 } else if (strncmp(next, "%shell", 6) == 0) { 686 } else if (strncmp(next, "%shell", 6) == 0) {
693 lenient_strcat(buffer, shell); 687 len += append_prop(buffer, view_get_shell(view));
694 len += shell_len;
695 format += 6; 688 format += 6;
696 } else { 689 } else {
697 lenient_strcat(buffer, "%"); 690 lenient_strcat(buffer, "%");
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 89af7345..bf56b80d 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -19,13 +19,26 @@ void sway_terminate(int exit_code) {
19 exit(exit_code); 19 exit(exit_code);
20} 20}
21 21
22// Iterate results array and return false if any of them failed
22static bool success(json_object *r, bool fallback) { 23static bool success(json_object *r, bool fallback) {
23 json_object *success; 24 if (!json_object_is_type(r, json_type_array)) {
24 if (!json_object_object_get_ex(r, "success", &success)) {
25 return fallback; 25 return fallback;
26 } else {
27 return json_object_get_boolean(success);
28 } 26 }
27 size_t results_len = json_object_array_length(r);
28 if (!results_len) {
29 return fallback;
30 }
31 for (size_t i = 0; i < results_len; ++i) {
32 json_object *result = json_object_array_get_idx(r, i);
33 json_object *success;
34 if (!json_object_object_get_ex(result, "success", &success)) {
35 return false;
36 }
37 if (!json_object_get_boolean(success)) {
38 return false;
39 }
40 }
41 return true;
29} 42}
30 43
31static void pretty_print_cmd(json_object *r) { 44static void pretty_print_cmd(json_object *r) {