[mutter] wayland/output: Remove wl_output global when making it inert



commit c0bc821f628c851fbacdf8dea58f515712258a52
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Mon Mar 22 16:27:54 2021 +0100

    wayland/output: Remove wl_output global when making it inert
    
    This will make clients immediately aware of the output disappearing,
    while still allowing for a grace period of 10 seconds for attempting to
    bind to it before it turning into a protocol error. This API added as
    part of wayland 1.18.
    
    This requires us to not add the output resource to the output resource
    list, if the output was made inert. This effectively makes the resource
    useless, but that is harmless, since shortly after, the client will
    clean it up anyway.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1796>

 src/wayland/meta-wayland-outputs.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/src/wayland/meta-wayland-outputs.c b/src/wayland/meta-wayland-outputs.c
index f8069b6929..5631ef6164 100644
--- a/src/wayland/meta-wayland-outputs.c
+++ b/src/wayland/meta-wayland-outputs.c
@@ -312,15 +312,16 @@ bind_output (struct wl_client *client,
 #endif
 
   resource = wl_resource_create (client, &wl_output_interface, version, id);
-  wayland_output->resources = g_list_prepend (wayland_output->resources, resource);
-
-  wl_resource_set_user_data (resource, wayland_output);
-  wl_resource_set_destructor (resource, output_resource_destroy);
 
   monitor = wayland_output->monitor;
   if (!monitor)
     return;
 
+  wayland_output->resources = g_list_prepend (wayland_output->resources,
+                                              resource);
+  wl_resource_set_user_data (resource, wayland_output);
+  wl_resource_set_destructor (resource, output_resource_destroy);
+
 #ifdef WITH_VERBOSE_MODE
   logical_monitor = meta_monitor_get_logical_monitor (monitor);
   meta_verbose ("Binding monitor %p/%s (%u, %u, %u, %u) x %f",
@@ -430,6 +431,8 @@ make_output_resources_inert (MetaWaylandOutput *wayland_output)
 {
   GList *l;
 
+  wl_global_remove (wayland_output->global);
+
   for (l = wayland_output->resources; l; l = l->next)
     {
       struct wl_resource *output_resource = l->data;
@@ -531,12 +534,10 @@ meta_wayland_output_finalize (GObject *object)
 {
   MetaWaylandOutput *wayland_output = META_WAYLAND_OUTPUT (object);
 
-  wl_global_destroy (wayland_output->global);
+  g_warn_if_fail (!wayland_output->resources);
+  g_warn_if_fail (!wayland_output->xdg_output_resources);
 
-  /* Make sure the wl_output destructor doesn't try to access MetaWaylandOutput
-   * after we have freed it.
-   */
-  make_output_resources_inert (wayland_output);
+  wl_global_destroy (wayland_output->global);
 
   G_OBJECT_CLASS (meta_wayland_output_parent_class)->finalize (object);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]