diff options
author | Kevin Hamacher <kevin.hamacher@rub.de> | 2015-12-14 11:43:17 +0100 |
---|---|---|
committer | Kevin Hamacher <kevin.hamacher@rub.de> | 2015-12-14 11:43:17 +0100 |
commit | 64a183b23d2a0b2e628f641345e33d7ea46c0d07 (patch) | |
tree | 6afaf5b52ea1542d5068d7cc6a12b63dc236a95c | |
parent | Fix rendering of borders on workspaces (swaybar) (diff) | |
download | sway-64a183b23d2a0b2e628f641345e33d7ea46c0d07.tar.gz sway-64a183b23d2a0b2e628f641345e33d7ea46c0d07.tar.zst sway-64a183b23d2a0b2e628f641345e33d7ea46c0d07.zip |
Fix dangling pointer on focus swap/describe WS
-rw-r--r-- | sway/focus.c | 6 | ||||
-rw-r--r-- | sway/ipc-server.c | 6 |
2 files changed, 11 insertions, 1 deletions
diff --git a/sway/focus.c b/sway/focus.c index 6911ac00..c60f410c 100644 --- a/sway/focus.c +++ b/sway/focus.c | |||
@@ -96,6 +96,7 @@ bool set_focused_container(swayc_t *c) { | |||
96 | return false; | 96 | return false; |
97 | } | 97 | } |
98 | swayc_t *active_ws = swayc_active_workspace(); | 98 | swayc_t *active_ws = swayc_active_workspace(); |
99 | int active_ws_child_count = active_ws->children->length + active_ws->floating->length; | ||
99 | 100 | ||
100 | swayc_log(L_DEBUG, c, "Setting focus to %p:%ld", c, c->handle); | 101 | swayc_log(L_DEBUG, c, "Setting focus to %p:%ld", c, c->handle); |
101 | 102 | ||
@@ -118,6 +119,11 @@ bool set_focused_container(swayc_t *c) { | |||
118 | p = p->parent; | 119 | p = p->parent; |
119 | p->is_focused = false; | 120 | p->is_focused = false; |
120 | } | 121 | } |
122 | // active_ws might have been destroyed by now | ||
123 | // (focus swap away from empty ws = destroy ws) | ||
124 | if (active_ws_child_count == 0) { | ||
125 | active_ws = NULL; | ||
126 | } | ||
121 | 127 | ||
122 | // get new focused view and set focus to it. | 128 | // get new focused view and set focus to it. |
123 | p = get_focused_view(c); | 129 | p = get_focused_view(c); |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 7c737307..3f02812d 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -455,7 +455,11 @@ void ipc_get_outputs_callback(swayc_t *container, void *data) { | |||
455 | void ipc_event_workspace(swayc_t *old, swayc_t *new) { | 455 | void ipc_event_workspace(swayc_t *old, swayc_t *new) { |
456 | json_object *obj = json_object_new_object(); | 456 | json_object *obj = json_object_new_object(); |
457 | json_object_object_add(obj, "change", json_object_new_string("focus")); | 457 | json_object_object_add(obj, "change", json_object_new_string("focus")); |
458 | json_object_object_add(obj, "old", ipc_json_describe_workspace(old)); | 458 | if (old) { |
459 | json_object_object_add(obj, "old", ipc_json_describe_workspace(old)); | ||
460 | } else { | ||
461 | json_object_object_add(obj, "old", NULL); | ||
462 | } | ||
459 | json_object_object_add(obj, "current", ipc_json_describe_workspace(new)); | 463 | json_object_object_add(obj, "current", ipc_json_describe_workspace(new)); |
460 | const char *json_string = json_object_to_json_string(obj); | 464 | const char *json_string = json_object_to_json_string(obj); |
461 | 465 | ||