wayland: Move toplevel-specific code into the toplevel
authorBenjamin Otte <otte@redhat.com>
Sun, 16 Apr 2023 23:26:16 +0000 (01:26 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 26 Apr 2023 19:03:34 +0000 (21:03 +0200)
The display->toplevels tracking belongs to GdkWAylandToplevel.

gdk/wayland/gdksurface-wayland.c
gdk/wayland/gdktoplevel-wayland.c

index 72e7fb63334b15f487ff7baf48556f2f07921c95..013cef0ad7ce08cccd36b7b21ad29ff07b6e6cc8 100644 (file)
@@ -854,7 +854,6 @@ gdk_wayland_display_create_surface (GdkDisplay     *display,
                               "frame-clock", frame_clock,
                               "title", get_default_title (),
                               NULL);
-      display_wayland->toplevels = g_list_prepend (display_wayland->toplevels, surface);
       break;
     case GDK_SURFACE_POPUP:
       g_warn_if_fail (parent != NULL);
@@ -1196,11 +1195,8 @@ static void
 gdk_wayland_surface_destroy (GdkSurface *surface,
                              gboolean    foreign_destroy)
 {
-  GdkWaylandDisplay *display;
   GdkFrameClock *frame_clock;
 
-  g_return_if_fail (GDK_IS_SURFACE (surface));
-
   /* Wayland surfaces can't be externally destroyed; we may possibly
    * eventually want to use this path at display close-down
    */
@@ -1213,9 +1209,6 @@ gdk_wayland_surface_destroy (GdkSurface *surface,
   frame_clock = gdk_surface_get_frame_clock (surface);
   g_signal_handlers_disconnect_by_func (frame_clock, on_frame_clock_before_paint, surface);
   g_signal_handlers_disconnect_by_func (frame_clock, on_frame_clock_after_paint, surface);
-
-  display = GDK_WAYLAND_DISPLAY (gdk_surface_get_display (surface));
-  display->toplevels = g_list_remove (display->toplevels, surface);
 }
 
 static void
index 416aab4840766b391b084496008ba9e24779c66d..c0d929b984afe9996ea15cbf7d28384fdac71cec 100644 (file)
@@ -1259,28 +1259,37 @@ gdk_wayland_toplevel_get_property (GObject    *object,
 static void
 gdk_wayland_toplevel_finalize (GObject *object)
 {
-  GdkWaylandToplevel *wayland_toplevel;
-
-  g_return_if_fail (GDK_IS_WAYLAND_TOPLEVEL (object));
+  GdkWaylandToplevel *self = GDK_WAYLAND_TOPLEVEL (object);
+  GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (gdk_surface_get_display (GDK_SURFACE (object)));
 
-  wayland_toplevel = GDK_WAYLAND_TOPLEVEL (object);
+  display_wayland->toplevels = g_list_remove (display_wayland->toplevels, self);
 
-  if (gdk_wayland_toplevel_is_exported (wayland_toplevel))
-    gdk_wayland_toplevel_unexport_handle (GDK_TOPLEVEL (wayland_toplevel));
+  if (gdk_wayland_toplevel_is_exported (self))
+    gdk_wayland_toplevel_unexport_handle (GDK_TOPLEVEL (self));
 
-  g_free (wayland_toplevel->application.application_id);
-  g_free (wayland_toplevel->application.app_menu_path);
-  g_free (wayland_toplevel->application.menubar_path);
-  g_free (wayland_toplevel->application.window_object_path);
-  g_free (wayland_toplevel->application.application_object_path);
-  g_free (wayland_toplevel->application.unique_bus_name);
+  g_free (self->application.application_id);
+  g_free (self->application.app_menu_path);
+  g_free (self->application.menubar_path);
+  g_free (self->application.window_object_path);
+  g_free (self->application.application_object_path);
+  g_free (self->application.unique_bus_name);
 
-  g_free (wayland_toplevel->title);
-  g_clear_pointer (&wayland_toplevel->shortcuts_inhibitors, g_hash_table_unref);
+  g_free (self->title);
+  g_clear_pointer (&self->shortcuts_inhibitors, g_hash_table_unref);
 
   G_OBJECT_CLASS (gdk_wayland_toplevel_parent_class)->finalize (object);
 }
 
+static void
+gdk_wayland_toplevel_constructed (GObject *object)
+{
+  GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (gdk_surface_get_display (GDK_SURFACE (object)));
+
+  display_wayland->toplevels = g_list_prepend (display_wayland->toplevels, object);
+
+  G_OBJECT_CLASS (gdk_wayland_toplevel_parent_class)->constructed (object);
+}
+
 static void
 gdk_wayland_toplevel_class_init (GdkWaylandToplevelClass *class)
 {
@@ -1291,6 +1300,7 @@ gdk_wayland_toplevel_class_init (GdkWaylandToplevelClass *class)
   object_class->get_property = gdk_wayland_toplevel_get_property;
   object_class->set_property = gdk_wayland_toplevel_set_property;
   object_class->finalize = gdk_wayland_toplevel_finalize;
+  object_class->constructed = gdk_wayland_toplevel_constructed;
 
   surface_class->compute_size = gdk_wayland_toplevel_compute_size;