]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Chase wlroots: add output to scene_output_layout explicitly
authorJohn Lindgren <john@jlindgren.net>
Fri, 22 Sep 2023 01:33:12 +0000 (21:33 -0400)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 27 Nov 2023 21:01:53 +0000 (21:01 +0000)
Chases: f5917f0247600b65edec1735234d00de57d577a8
scene_output_layout: make output adding explicit

include/labwc.h
src/output.c
subprojects/wlroots.wrap

index f3f0a2a72133c069c897b5869fb01d51162aeb1c..261883c5bfa97fc341fb1adf85b8a2393fe4f7a6 100644 (file)
@@ -229,6 +229,7 @@ struct server {
 
        struct seat seat;
        struct wlr_scene *scene;
+       struct wlr_scene_output_layout *scene_layout;
 
        /* cursor interactive */
        enum input_mode input_mode;
index f3e639c5f0550b73a34d542d865d818410e12f2a..b12c32fa4696623ff22f2d080d3315b053c45c01 100644 (file)
@@ -68,6 +68,10 @@ output_destroy_notify(struct wl_listener *listener, void *data)
                        view_on_output_destroy(view);
                }
        }
+       /*
+        * output->scene_output (if still around at this point) is
+        * destroyed automatically when the wlr_output is destroyed
+        */
        free(output);
 }
 
@@ -117,6 +121,30 @@ can_reuse_mode(struct wlr_output *wlr_output)
        return wlr_output->current_mode && wlr_output_test(wlr_output);
 }
 
+static void
+add_output_to_layout(struct server *server, struct output *output)
+{
+       struct wlr_output *wlr_output = output->wlr_output;
+       struct wlr_output_layout_output *layout_output =
+               wlr_output_layout_add_auto(server->output_layout, wlr_output);
+       if (!layout_output) {
+               wlr_log(WLR_ERROR, "unable to add output to layout");
+               return;
+       }
+
+       if (!output->scene_output) {
+               output->scene_output =
+                       wlr_scene_output_create(server->scene, wlr_output);
+               if (!output->scene_output) {
+                       wlr_log(WLR_ERROR, "unable to create scene output");
+                       return;
+               }
+       }
+
+       wlr_scene_output_layout_add_output(server->scene_layout, layout_output,
+               output->scene_output);
+}
+
 static void
 new_output_notify(struct wl_listener *listener, void *data)
 {
@@ -269,9 +297,7 @@ new_output_notify(struct wl_listener *listener, void *data)
         */
        server->pending_output_layout_change++;
 
-       wlr_output_layout_add_auto(server->output_layout, wlr_output);
-       output->scene_output = wlr_scene_get_scene_output(server->scene, wlr_output);
-       assert(output->scene_output);
+       add_output_to_layout(server, output);
 
        /* Create regions from config */
        regions_reconfigure_output(output);
@@ -299,7 +325,12 @@ output_init(struct server *server)
                wlr_log(WLR_ERROR, "unable to create output layout");
                exit(EXIT_FAILURE);
        }
-       wlr_scene_attach_output_layout(server->scene, server->output_layout);
+       server->scene_layout = wlr_scene_attach_output_layout(server->scene,
+               server->output_layout);
+       if (!server->scene_layout) {
+               wlr_log(WLR_ERROR, "unable to create scene layout");
+               exit(EXIT_FAILURE);
+       }
 
        /* Enable screen recording with wf-recorder */
        wlr_xdg_output_manager_v1_create(server->wl_display,
@@ -362,10 +393,7 @@ output_config_apply(struct server *server,
 
                /* Only do Layout specific actions if the commit went trough */
                if (need_to_add) {
-                       wlr_output_layout_add_auto(server->output_layout, o);
-                       output->scene_output =
-                               wlr_scene_get_scene_output(server->scene, o);
-                       assert(output->scene_output);
+                       add_output_to_layout(server, output);
                }
 
                if (output_enabled) {
@@ -384,6 +412,15 @@ output_config_apply(struct server *server,
 
                if (need_to_remove) {
                        regions_evacuate_output(output);
+                       /*
+                        * At time of writing, wlr_output_layout_remove()
+                        * indirectly destroys the wlr_scene_output, but
+                        * this behavior may change in future. To remove
+                        * doubt and avoid either a leak or double-free,
+                        * explicitly destroy the wlr_scene_output before
+                        * calling wlr_output_layout_remove().
+                        */
+                       wlr_scene_output_destroy(output->scene_output);
                        wlr_output_layout_remove(server->output_layout, o);
                        output->scene_output = NULL;
                }
index 1e80f2100f57836c68ba4e366c48b47902506c7f..74dd196e69bfac8c24b1a5162455305dd820a092 100644 (file)
@@ -1,6 +1,6 @@
 [wrap-git]
 url = https://gitlab.freedesktop.org/wlroots/wlroots.git
-revision = bdc34401ba8e4a59b3464c17fa5acf43ca417e57
+revision = f5917f0247600b65edec1735234d00de57d577a8
 
 [provide]
 dependency_names = wlroots