waylandsurface: Introduce a few vfuncs
authorMatthias Clasen <mclasen@redhat.com>
Fri, 6 Jan 2023 21:35:16 +0000 (16:35 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 6 Jan 2023 22:00:45 +0000 (17:00 -0500)
gdk/wayland/gdkpopup-wayland-private.h
gdk/wayland/gdkpopup-wayland.c
gdk/wayland/gdksurface-wayland-private.h
gdk/wayland/gdksurface-wayland.c
gdk/wayland/gdktoplevel-wayland-private.h
gdk/wayland/gdktoplevel-wayland.c

index 396e841aef90b10bcda6f06d88af97be4511395f..de3310f6db9f87ec22fc9481bfe741b5043bde63 100644 (file)
@@ -16,9 +16,3 @@
  */
 
 #pragma once
-
-
-void gdk_wayland_surface_configure_popup          (GdkWaylandPopup *popup);
-void frame_callback_popup                         (GdkWaylandPopup *popup);
-void gdk_wayland_popup_hide_surface               (GdkWaylandPopup *popup);
-
index 378a82a6413e2ff1167ef25a6e94925af8b59fb1..48480216d27e30b7ed6ecc14a78bf76eaa95e14a 100644 (file)
@@ -280,9 +280,10 @@ thaw_popup_toplevel_state (GdkWaylandPopup *wayland_popup)
   gdk_wayland_surface_thaw_state (toplevel);
 }
 
-void
-gdk_wayland_popup_hide_surface (GdkWaylandPopup *popup)
+static void
+gdk_wayland_popup_hide_surface (GdkWaylandSurface *wayland_surface)
 {
+  GdkWaylandPopup *popup = GDK_WAYLAND_POPUP (wayland_surface);
   GdkSurface *surface = GDK_SURFACE (popup);
   GdkDisplay *display = gdk_surface_get_display (surface);
   GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
@@ -332,29 +333,23 @@ is_realized_popup (GdkWaylandSurface *impl)
 }
 
 static void
-finish_pending_relayout (GdkWaylandPopup *wayland_popup)
+gdk_wayland_popup_handle_frame (GdkWaylandSurface *surface)
 {
-  g_assert (wayland_popup->state == POPUP_STATE_WAITING_FOR_FRAME);
-  wayland_popup->state = POPUP_STATE_IDLE;
-
-  thaw_popup_toplevel_state (wayland_popup);
-}
+  GdkWaylandPopup *wayland_popup = GDK_WAYLAND_POPUP (surface);
 
-void
-frame_callback_popup (GdkWaylandPopup *wayland_popup)
-{
-      switch (wayland_popup->state)
-        {
-        case POPUP_STATE_IDLE:
-        case POPUP_STATE_WAITING_FOR_REPOSITIONED:
-        case POPUP_STATE_WAITING_FOR_CONFIGURE:
-          break;
-        case POPUP_STATE_WAITING_FOR_FRAME:
-          finish_pending_relayout (wayland_popup);
-          break;
-        default:
-          g_assert_not_reached ();
-        }
+  switch (wayland_popup->state)
+    {
+    case POPUP_STATE_IDLE:
+    case POPUP_STATE_WAITING_FOR_REPOSITIONED:
+    case POPUP_STATE_WAITING_FOR_CONFIGURE:
+      break;
+    case POPUP_STATE_WAITING_FOR_FRAME:
+      wayland_popup->state = POPUP_STATE_IDLE;
+      thaw_popup_toplevel_state (wayland_popup);
+      break;
+    default:
+      g_assert_not_reached ();
+    }
 }
 
 static gboolean
@@ -382,11 +377,11 @@ gdk_wayland_popup_compute_size (GdkSurface *surface)
   return FALSE;
 }
 
-void
-gdk_wayland_surface_configure_popup (GdkWaylandPopup *wayland_popup)
+static void
+gdk_wayland_popup_handle_configure (GdkWaylandSurface *wayland_surface)
 {
-  GdkSurface *surface = GDK_SURFACE (wayland_popup);
-  GdkWaylandSurface *wayland_surface = GDK_WAYLAND_SURFACE (wayland_popup);
+  GdkSurface *surface = GDK_SURFACE (wayland_surface);
+  GdkWaylandPopup *wayland_popup = GDK_WAYLAND_POPUP (wayland_surface);
   GdkRectangle parent_geometry;
   int x, y, width, height;
 
@@ -1084,12 +1079,17 @@ gdk_wayland_popup_class_init (GdkWaylandPopupClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
   GdkSurfaceClass *surface_class = GDK_SURFACE_CLASS (class);
+  GdkWaylandSurfaceClass *wayland_surface_class = GDK_WAYLAND_SURFACE_CLASS (class);
 
   object_class->get_property = gdk_wayland_popup_get_property;
   object_class->set_property = gdk_wayland_popup_set_property;
 
   surface_class->compute_size = gdk_wayland_popup_compute_size;
 
+  wayland_surface_class->handle_configure = gdk_wayland_popup_handle_configure;
+  wayland_surface_class->handle_frame = gdk_wayland_popup_handle_frame;
+  wayland_surface_class->hide_surface = gdk_wayland_popup_hide_surface;
+
   gdk_popup_install_properties (object_class, 1);
 }
 
index 1a260704997c2db669b88b0abb5bd8e319179c61..2648972b33091659450aac80007889c02d24f174 100644 (file)
@@ -85,8 +85,18 @@ typedef struct _GdkWaylandSurfaceClass GdkWaylandSurfaceClass;
 struct _GdkWaylandSurfaceClass
 {
   GdkSurfaceClass parent_class;
+
+  void (* handle_configure) (GdkWaylandSurface *surface);
+
+  void (* handle_frame) (GdkWaylandSurface *surface);
+
+  void (* hide_surface) (GdkWaylandSurface *surface);
 };
 
+#define GDK_WAYLAND_SURFACE_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_WAYLAND_SURFACE, GdkWaylandSurfaceClass))
+
+#define GDK_WAYLAND_SURFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_WAYLAND_SURFACE, GdkWaylandSurfaceClass))
+
 void gdk_wayland_surface_create_wl_surface (GdkSurface *surface);
 void gdk_wayland_surface_update_size       (GdkSurface *surface,
                                             int32_t     width,
index 5f773e2e56b3744444c687bde3d5a87388903fd5..be6df5b36e261909cd556e29f1431ceb143f7751 100644 (file)
@@ -268,8 +268,7 @@ frame_callback (void               *data,
   if (!impl->awaiting_frame)
     return;
 
-  if (GDK_IS_WAYLAND_POPUP (surface))
-    frame_callback_popup (GDK_WAYLAND_POPUP (surface));
+  GDK_WAYLAND_SURFACE_GET_CLASS (impl)->handle_frame (impl);
 
   impl->awaiting_frame = FALSE;
   if (impl->awaiting_frame_frozen)
@@ -881,12 +880,7 @@ gdk_wayland_surface_configure (GdkSurface *surface)
 
   impl->has_uncommitted_ack_configure = TRUE;
 
-  if (GDK_IS_WAYLAND_POPUP (surface))
-    gdk_wayland_surface_configure_popup (GDK_WAYLAND_POPUP (surface));
-  else if (GDK_IS_WAYLAND_TOPLEVEL (surface))
-    gdk_wayland_surface_configure_toplevel (GDK_WAYLAND_TOPLEVEL (surface));
-  else
-    g_warn_if_reached ();
+  GDK_WAYLAND_SURFACE_GET_CLASS (impl)->handle_configure (impl);
 
   impl->last_configure_serial = impl->pending.serial;
 
@@ -1024,11 +1018,7 @@ gdk_wayland_surface_hide_surface (GdkSurface *surface)
           gdk_surface_thaw_updates (surface);
         }
 
-      if (GDK_IS_WAYLAND_TOPLEVEL (surface))
-        gdk_wayland_toplevel_hide_surface (GDK_WAYLAND_TOPLEVEL (surface));
-
-      if (GDK_IS_WAYLAND_POPUP (surface))
-        gdk_wayland_popup_hide_surface (GDK_WAYLAND_POPUP (surface));
+      GDK_WAYLAND_SURFACE_GET_CLASS (impl)->hide_surface (impl);
 
       g_clear_pointer (&impl->display_server.wl_surface, wl_surface_destroy);
 
@@ -1224,6 +1214,21 @@ gdk_wayland_surface_set_opaque_region (GdkSurface     *surface,
   impl->opaque_region_dirty = TRUE;
 }
 
+static void
+gdk_wayland_surface_default_handle_configure (GdkWaylandSurface *surface)
+{
+}
+
+static void
+gdk_wayland_surface_default_handle_frame (GdkWaylandSurface *surface)
+{
+}
+
+static void
+gdk_wayland_surface_default_hide_surface (GdkWaylandSurface *surface)
+{
+}
+
 static void
 gdk_wayland_surface_class_init (GdkWaylandSurfaceClass *klass)
 {
@@ -1247,6 +1252,10 @@ gdk_wayland_surface_class_init (GdkWaylandSurfaceClass *klass)
   surface_class->get_scale_factor = gdk_wayland_surface_get_scale_factor;
   surface_class->set_opaque_region = gdk_wayland_surface_set_opaque_region;
   surface_class->request_layout = gdk_wayland_surface_request_layout;
+
+  klass->handle_configure = gdk_wayland_surface_default_handle_configure;
+  klass->handle_frame = gdk_wayland_surface_default_handle_frame;
+  klass->hide_surface = gdk_wayland_surface_default_hide_surface;
 }
 
 /* }}} */
index d3f9a5132574abfdedceca21ea06d30971f39f9c..9b061013716d2dea702d4d0ceee27c38c7f6e550 100644 (file)
 #pragma once
 
 
-void gdk_wayland_surface_configure_toplevel       (GdkWaylandToplevel *toplevel);
 void gdk_wayland_toplevel_set_geometry_hints      (GdkWaylandToplevel *toplevel,
                                                    const GdkGeometry  *geometry,
                                                    GdkSurfaceHints     geom_mask);
-void gdk_wayland_toplevel_hide_surface            (GdkWaylandToplevel *toplevel);
 
 struct gtk_surface1 *
      gdk_wayland_toplevel_get_gtk_surface         (GdkWaylandToplevel *wayland_toplevel);
index ff086681129e7c5964adb6e675b829ef18af02a1..bdaca587f9645a84ff355ff9964c21a3a68da96a 100644 (file)
@@ -205,9 +205,10 @@ gdk_wayland_toplevel_clear_saved_size (GdkWaylandToplevel *toplevel)
 static void maybe_set_gtk_surface_dbus_properties (GdkWaylandToplevel *wayland_toplevel);
 static void maybe_set_gtk_surface_modal (GdkWaylandToplevel *wayland_toplevel);
 
-void
-gdk_wayland_toplevel_hide_surface (GdkWaylandToplevel *toplevel)
+static void
+gdk_wayland_toplevel_hide_surface (GdkWaylandSurface *wayland_surface)
 {
+  GdkWaylandToplevel *toplevel = GDK_WAYLAND_TOPLEVEL (wayland_surface);
   GdkDisplay *display = gdk_surface_get_display (GDK_SURFACE (toplevel));
   GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
 
@@ -459,11 +460,11 @@ gdk_wayland_toplevel_compute_size (GdkSurface *surface)
   return FALSE;
 }
 
-void
-gdk_wayland_surface_configure_toplevel (GdkWaylandToplevel *wayland_toplevel)
+static void
+gdk_wayland_toplevel_handle_configure (GdkWaylandSurface *wayland_surface)
 {
-  GdkSurface *surface = GDK_SURFACE (wayland_toplevel);
-  GdkWaylandSurface *wayland_surface = GDK_WAYLAND_SURFACE (wayland_toplevel);
+  GdkSurface *surface = GDK_SURFACE (wayland_surface);
+  GdkWaylandToplevel *wayland_toplevel = GDK_WAYLAND_TOPLEVEL (wayland_surface);
   GdkWaylandDisplay *display_wayland =
     GDK_WAYLAND_DISPLAY (gdk_surface_get_display (surface));
   GdkToplevelState new_state;
@@ -1285,6 +1286,7 @@ gdk_wayland_toplevel_class_init (GdkWaylandToplevelClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
   GdkSurfaceClass *surface_class = GDK_SURFACE_CLASS (class);
+  GdkWaylandSurfaceClass *wayland_surface_class = GDK_WAYLAND_SURFACE_CLASS (class);
 
   object_class->get_property = gdk_wayland_toplevel_get_property;
   object_class->set_property = gdk_wayland_toplevel_set_property;
@@ -1292,6 +1294,9 @@ gdk_wayland_toplevel_class_init (GdkWaylandToplevelClass *class)
 
   surface_class->compute_size = gdk_wayland_toplevel_compute_size;
 
+  wayland_surface_class->handle_configure = gdk_wayland_toplevel_handle_configure;
+  wayland_surface_class->hide_surface = gdk_wayland_toplevel_hide_surface;
+
   gdk_toplevel_install_properties (object_class, 1);
 }