diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-03-31 18:52:02 -0400 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-03-31 18:52:02 -0400 |
commit | eda425fdabb4050eb2ecc8741793d83e3a7bf154 (patch) | |
tree | 234918f83c38f0c494b8f0a04dff5704459bdbe6 | |
parent | clean up view destroy seat cleanup (diff) | |
download | sway-eda425fdabb4050eb2ecc8741793d83e3a7bf154.tar.gz sway-eda425fdabb4050eb2ecc8741793d83e3a7bf154.tar.zst sway-eda425fdabb4050eb2ecc8741793d83e3a7bf154.zip |
fix some segfaults
-rw-r--r-- | sway/input/seat.c | 7 | ||||
-rw-r--r-- | sway/tree/container.c | 19 | ||||
-rw-r--r-- | sway/tree/layout.c | 4 |
3 files changed, 19 insertions, 11 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c index adc4cb0a..a1b1caa8 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -94,6 +94,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener, | |||
94 | 94 | ||
95 | // TODO handle workspace switch in the seat? | 95 | // TODO handle workspace switch in the seat? |
96 | bool set_focus = | 96 | bool set_focus = |
97 | focus != NULL && | ||
97 | (focus == con || container_has_child(con, focus)) && | 98 | (focus == con || container_has_child(con, focus)) && |
98 | con->type != C_WORKSPACE; | 99 | con->type != C_WORKSPACE; |
99 | 100 | ||
@@ -103,12 +104,13 @@ static void handle_seat_container_destroy(struct wl_listener *listener, | |||
103 | struct sway_container *next_focus = NULL; | 104 | struct sway_container *next_focus = NULL; |
104 | while (next_focus == NULL) { | 105 | while (next_focus == NULL) { |
105 | next_focus = sway_seat_get_focus_by_type(seat, parent, C_VIEW); | 106 | next_focus = sway_seat_get_focus_by_type(seat, parent, C_VIEW); |
106 | parent = parent->parent; | ||
107 | 107 | ||
108 | if (next_focus == NULL && parent->type == C_WORKSPACE) { | 108 | if (next_focus == NULL && parent->type == C_WORKSPACE) { |
109 | next_focus = parent; | 109 | next_focus = parent; |
110 | break; | 110 | break; |
111 | } | 111 | } |
112 | |||
113 | parent = parent->parent; | ||
112 | } | 114 | } |
113 | 115 | ||
114 | // the structure change might have caused it to move up to the top of | 116 | // the structure change might have caused it to move up to the top of |
@@ -440,7 +442,8 @@ struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, | |||
440 | wl_list_for_each(current, &seat->focus_stack, link) { | 442 | wl_list_for_each(current, &seat->focus_stack, link) { |
441 | parent = current->container->parent; | 443 | parent = current->container->parent; |
442 | 444 | ||
443 | if (current->container == container) { | 445 | if (current->container == container && |
446 | (type == C_TYPES || container->type == type)) { | ||
444 | return current->container; | 447 | return current->container; |
445 | } | 448 | } |
446 | 449 | ||
diff --git a/sway/tree/container.c b/sway/tree/container.c index e2fe9e7c..b3c6d80f 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -69,11 +69,11 @@ static struct sway_container *_container_destroy(struct sway_container *cont) { | |||
69 | if (cont->children != NULL) { | 69 | if (cont->children != NULL) { |
70 | // remove children until there are no more, container_destroy calls | 70 | // remove children until there are no more, container_destroy calls |
71 | // container_remove_child, which removes child from this container | 71 | // container_remove_child, which removes child from this container |
72 | while (cont->children->length != 0) { | 72 | while (cont->children != NULL && cont->children->length != 0) { |
73 | container_destroy(cont->children->items[0]); | 73 | struct sway_container *child = cont->children->items[0]; |
74 | container_remove_child(child); | ||
75 | container_destroy(child); | ||
74 | } | 76 | } |
75 | list_free(cont->children); | ||
76 | cont->children = NULL; | ||
77 | } | 77 | } |
78 | if (cont->marks) { | 78 | if (cont->marks) { |
79 | list_foreach(cont->marks, free); | 79 | list_foreach(cont->marks, free); |
@@ -85,13 +85,17 @@ static struct sway_container *_container_destroy(struct sway_container *cont) { | |||
85 | if (cont->name) { | 85 | if (cont->name) { |
86 | free(cont->name); | 86 | free(cont->name); |
87 | } | 87 | } |
88 | list_free(cont->children); | ||
89 | cont->children = NULL; | ||
88 | free(cont); | 90 | free(cont); |
89 | return parent; | 91 | return parent; |
90 | } | 92 | } |
91 | 93 | ||
92 | struct sway_container *container_destroy(struct sway_container *cont) { | 94 | struct sway_container *container_destroy(struct sway_container *cont) { |
93 | cont = _container_destroy(cont); | 95 | struct sway_container *parent = _container_destroy(cont); |
94 | return container_reap_empty(cont->parent); | 96 | parent = container_reap_empty(parent); |
97 | arrange_windows(&root_container, -1, -1); | ||
98 | return parent; | ||
95 | } | 99 | } |
96 | 100 | ||
97 | struct sway_container *container_output_create( | 101 | struct sway_container *container_output_create( |
@@ -409,7 +413,8 @@ bool find_child_func(struct sway_container *con, void *data) { | |||
409 | 413 | ||
410 | bool container_has_child(struct sway_container *con, | 414 | bool container_has_child(struct sway_container *con, |
411 | struct sway_container *child) { | 415 | struct sway_container *child) { |
412 | if (child->type == C_VIEW || child->children->length == 0) { | 416 | if (child == NULL || child->type == C_VIEW || |
417 | child->children->length == 0) { | ||
413 | return false; | 418 | return false; |
414 | } | 419 | } |
415 | return container_find(con, find_child_func, child); | 420 | return container_find(con, find_child_func, child); |
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 62df19e9..5098c8d1 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -106,11 +106,11 @@ void container_add_child(struct sway_container *parent, | |||
106 | } | 106 | } |
107 | 107 | ||
108 | struct sway_container *container_reap_empty(struct sway_container *container) { | 108 | struct sway_container *container_reap_empty(struct sway_container *container) { |
109 | if (!sway_assert(container, "reaping null container")) { | 109 | if (container == NULL) { |
110 | return NULL; | 110 | return NULL; |
111 | } | 111 | } |
112 | wlr_log(L_DEBUG, "reaping %p %s", container, container->name); | 112 | wlr_log(L_DEBUG, "reaping %p %s", container, container->name); |
113 | while (container != &root_container && container->children->length == 0) { | 113 | while (container->type != C_VIEW && container != &root_container && container->children->length == 0) { |
114 | if (container->type == C_WORKSPACE) { | 114 | if (container->type == C_WORKSPACE) { |
115 | if (!workspace_is_visible(container)) { | 115 | if (!workspace_is_visible(container)) { |
116 | struct sway_container *parent = container->parent; | 116 | struct sway_container *parent = container->parent; |