Commit 896ce28a0e425ac324aad6efc32bd0d349feb5d9 Parent: 3856c3b92f7d1a2b08e92eb173fd7ca58757d1f0 Author: mcol <mcol@posteo.net> Date: 2021-02-07 11:43:40 +0000 Committer: mcol <mcol@posteo.net> Committed: 2021-02-07 11:46:39 +0000 move output freeing into output.c
src/types.h Modified
@@ -132,6 +132,7 @@ struct wl_list layer_views[4]; struct wlr_output *wlr_output; struct wl_listener frame_listener; + struct wl_listener destroy_listener; }; struct layer_view {
src/output.c Modified
@@ -208,6 +208,27 @@ } +static void on_destroy(struct wl_listener *listener, void *data) { + struct output *output = wl_container_of(listener, output, destroy_listener); + + struct layer_view *lview, *tlview; + for (int i = 0; i < 4; i++ ) { + wl_list_for_each_safe(lview, tlview, &output->layer_views[i], link) { + wl_list_remove(&lview->link); + wl_list_remove(&lview->map_listener.link); + wl_list_remove(&lview->unmap_listener.link); + wl_list_remove(&lview->destroy_listener.link); + free(lview); + }; + } + + wl_list_remove(&output->frame_listener.link); + wl_list_remove(&output->destroy_listener.link); + wl_list_remove(&output->link); + free(output); +} + + static void on_new_output(struct wl_listener *listener, void *data) { struct wlr_output *wlr_output = data; @@ -225,7 +246,10 @@ wlr_output->data = output; output->frame_listener.notify = on_frame; + output->destroy_listener.notify = on_destroy; wl_signal_add(&wlr_output->events.frame, &output->frame_listener); + wl_signal_add(&wlr_output->events.destroy, &output->destroy_listener); + wl_list_insert(&wimp.outputs, &output->link); wlr_output_layout_add_auto(wimp.output_layout, wlr_output);
src/main.c Modified
@@ -103,23 +103,6 @@ free(desk); }; - struct output *output, *toutput; - struct layer_view *lview, *tlview; - wl_list_for_each_safe(output, toutput, &wimp.outputs, link) { - for (int i = 0; i < 4; i++ ) { - wl_list_for_each_safe(lview, tlview, &output->layer_views[i], link) { - wl_list_remove(&lview->link); - wl_list_remove(&lview->map_listener.link); - wl_list_remove(&lview->unmap_listener.link); - wl_list_remove(&lview->destroy_listener.link); - free(lview); - }; - } - wl_list_remove(&output->link); - wl_list_remove(&output->frame_listener.link); - free(output); - }; - struct mark *mark, *tmark; wl_list_for_each_safe(mark, tmark, &wimp.marks, link) { wl_list_remove(&mark->link);