aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-11 15:36:19 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-11 15:36:19 +1000
commit31844bf42bc4b6549862ea4c4f077c1e19d9e7a1 (patch)
treef24bbab4a5a54936ddca9b823e4103ea630e993b
parentMerge pull request #2447 from ianyfan/swaynag-leak (diff)
downloadsway-31844bf42bc4b6549862ea4c4f077c1e19d9e7a1.tar.gz
sway-31844bf42bc4b6549862ea4c4f077c1e19d9e7a1.tar.zst
sway-31844bf42bc4b6549862ea4c4f077c1e19d9e7a1.zip
Remove container_has_child
In all cases you can use container_has_ancestor with the arguments swapped, which is faster than container_has_child.
-rw-r--r--include/sway/tree/container.h6
-rw-r--r--sway/input/seat.c6
-rw-r--r--sway/tree/container.c13
3 files changed, 3 insertions, 22 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 4d0e6003..799c017d 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -256,12 +256,6 @@ void container_for_each_descendant_dfs(struct sway_container *container,
256bool container_has_ancestor(struct sway_container *container, 256bool container_has_ancestor(struct sway_container *container,
257 struct sway_container *ancestor); 257 struct sway_container *ancestor);
258 258
259/**
260 * Returns true if the given container is a child descendant of this container.
261 */
262bool container_has_child(struct sway_container *con,
263 struct sway_container *child);
264
265int container_count_descendants_of_type(struct sway_container *con, 259int container_count_descendants_of_type(struct sway_container *con,
266 enum sway_container_type type); 260 enum sway_container_type type);
267 261
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 6dd7cf7d..3cd079f4 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -145,14 +145,14 @@ static struct sway_container *seat_get_focus_by_type(struct sway_seat *seat,
145 continue; 145 continue;
146 } 146 }
147 147
148 if (container_has_child(container, current->container)) { 148 if (container_has_ancestor(current->container, container)) {
149 if (only_tiling && 149 if (only_tiling &&
150 container_is_floating_or_child(current->container)) { 150 container_is_floating_or_child(current->container)) {
151 continue; 151 continue;
152 } 152 }
153 return current->container; 153 return current->container;
154 } 154 }
155 if (floating && container_has_child(floating, current->container)) { 155 if (floating && container_has_ancestor(current->container, floating)) {
156 return current->container; 156 return current->container;
157 } 157 }
158 } 158 }
@@ -190,7 +190,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
190 190
191 bool set_focus = 191 bool set_focus =
192 focus != NULL && 192 focus != NULL &&
193 (focus == con || container_has_child(con, focus)) && 193 (focus == con || container_has_ancestor(focus, con)) &&
194 con->type != C_WORKSPACE; 194 con->type != C_WORKSPACE;
195 195
196 seat_container_destroy(seat_con); 196 seat_container_destroy(seat_con);
diff --git a/sway/tree/container.c b/sway/tree/container.c
index aecb2ac6..cec51af4 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -817,19 +817,6 @@ bool container_has_ancestor(struct sway_container *descendant,
817 return false; 817 return false;
818} 818}
819 819
820static bool find_child_func(struct sway_container *con, void *data) {
821 struct sway_container *child = data;
822 return con == child;
823}
824
825bool container_has_child(struct sway_container *con,
826 struct sway_container *child) {
827 if (con == NULL || con->type == C_VIEW) {
828 return false;
829 }
830 return container_find(con, find_child_func, child);
831}
832
833int container_count_descendants_of_type(struct sway_container *con, 820int container_count_descendants_of_type(struct sway_container *con,
834 enum sway_container_type type) { 821 enum sway_container_type type) {
835 int children = 0; 822 int children = 0;