wayland: Move surface initialization into constructed()
authorBenjamin Otte <otte@redhat.com>
Sun, 16 Apr 2023 23:26:45 +0000 (01:26 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 26 Apr 2023 19:03:34 +0000 (21:03 +0200)
That way, it doesn't ned a specific init function.

Also chain up last, so that the generic initialization code can access a
fully initialized wayland surface.

gdk/wayland/gdksurface-wayland.c

index 013cef0ad7ce08cccd36b7b21ad29ff07b6e6cc8..bb6f6135d90f6e35b04e46b4a3634e42306c4ac1 100644 (file)
@@ -525,21 +525,6 @@ gdk_wayland_surface_beep (GdkSurface *surface)
   return TRUE;
 }
 
-static void
-gdk_wayland_surface_constructed (GObject *object)
-{
-  GdkSurface *surface = GDK_SURFACE (object);
-  GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
-  GdkWaylandDisplay *display_wayland =
-    GDK_WAYLAND_DISPLAY (gdk_surface_get_display (surface));
-
-  G_OBJECT_CLASS (gdk_wayland_surface_parent_class)->constructed (object);
-
-  impl->event_queue = wl_display_create_queue (display_wayland->wl_display);
-  display_wayland->event_queues = g_list_prepend (display_wayland->event_queues,
-                                                  impl->event_queue);
-}
-
 static void
 gdk_wayland_surface_dispose (GObject *object)
 {
@@ -814,6 +799,45 @@ gdk_wayland_surface_create_wl_surface (GdkSurface *surface)
   self->display_server.wl_surface = wl_surface;
 }
 
+static void
+gdk_wayland_surface_constructed (GObject *object)
+{
+  GdkSurface *surface = GDK_SURFACE (object);
+  GdkWaylandSurface *self = GDK_WAYLAND_SURFACE (surface);
+  GdkDisplay *display = gdk_surface_get_display (surface);
+  GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
+  GdkFrameClock *frame_clock = gdk_surface_get_frame_clock (surface);
+
+  self->event_queue = wl_display_create_queue (display_wayland->wl_display);
+  display_wayland->event_queues = g_list_prepend (display_wayland->event_queues,
+                                                  self->event_queue);
+
+  /* More likely to be right than just assuming 1 */
+  if (wl_compositor_get_version (display_wayland->compositor) >= WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION)
+    {
+      GdkMonitor *monitor = g_list_model_get_item (gdk_display_get_monitors (display), 0);
+      if (monitor)
+        {
+          guint32 monitor_scale = gdk_monitor_get_scale_factor (monitor);
+
+          if (monitor_scale != 1)
+            {
+              self->scale = GDK_FRACTIONAL_SCALE_INIT_INT (monitor_scale);
+              self->buffer_scale_dirty = TRUE;
+            }
+
+          g_object_unref (monitor);
+        }
+    }
+
+  gdk_wayland_surface_create_wl_surface (surface);
+
+  g_signal_connect (frame_clock, "before-paint", G_CALLBACK (on_frame_clock_before_paint), surface);
+  g_signal_connect (frame_clock, "after-paint", G_CALLBACK (on_frame_clock_after_paint), surface);
+
+  G_OBJECT_CLASS (gdk_wayland_surface_parent_class)->constructed (object);
+}
+
 static void
 gdk_wayland_surface_destroy_wl_surface (GdkWaylandSurface *self)
 {
@@ -836,7 +860,6 @@ gdk_wayland_display_create_surface (GdkDisplay     *display,
                                     GdkSurfaceType  surface_type,
                                     GdkSurface     *parent)
 {
-  GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
   GdkSurface *surface;
   GdkFrameClock *frame_clock;
 
@@ -875,30 +898,6 @@ gdk_wayland_display_create_surface (GdkDisplay     *display,
       break;
     }
 
-  /* More likely to be right than just assuming 1 */
-  if (wl_compositor_get_version (display_wayland->compositor) >= WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION)
-    {
-      GdkMonitor *monitor = g_list_model_get_item (gdk_display_get_monitors (display), 0);
-      if (monitor)
-        {
-          GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
-          guint32 monitor_scale = gdk_monitor_get_scale_factor (monitor);
-
-          if (monitor_scale != 1)
-            {
-              impl->scale = GDK_FRACTIONAL_SCALE_INIT_INT (monitor_scale);
-              impl->buffer_scale_dirty = TRUE;
-            }
-
-          g_object_unref (monitor);
-        }
-    }
-
-  gdk_wayland_surface_create_wl_surface (surface);
-
-  g_signal_connect (frame_clock, "before-paint", G_CALLBACK (on_frame_clock_before_paint), surface);
-  g_signal_connect (frame_clock, "after-paint", G_CALLBACK (on_frame_clock_after_paint), surface);
-
   g_object_unref (frame_clock);
 
   return surface;