macos: add getter for NSWindow with macOS windowing
authorChristian Hergert <christian@hergert.me>
Tue, 22 Feb 2022 18:21:46 +0000 (10:21 -0800)
committerChristian Hergert <chergert@redhat.com>
Fri, 25 Feb 2022 19:36:39 +0000 (11:36 -0800)
There may be various reasons that an application could need access to the
underlying NSWindow that is being used to display the GdkMacosSurface
contents. This provides a minimal API to do that without exposing our
implementation details through public API.

As our rendering system is likely to change over time, we very much want
to keep GdkMacosView, GdkMacosLayer, GdkMacosTile, and GdkMacosWindow all
private implementation details which are subject to change.

As this is public API, we are a bit long-winded with the name so it is
clear what is being accessed without polluting symbol names with things
like "ns" as we used to.

gdk/macos/gdkmacossurface.c
gdk/macos/gdkmacossurface.h

index 0f9fd4d83335ed441b361acb930267c34f5b1954..ff4dcbf218620abf6e0934fbc5825e9cefcb735b 100644 (file)
@@ -528,6 +528,11 @@ gdk_macos_surface_class_init (GdkMacosSurfaceClass *klass)
   surface_class->set_input_region = gdk_macos_surface_set_input_region;
   surface_class->set_opaque_region = gdk_macos_surface_set_opaque_region;
 
+  /**
+   * GdkMacosSurface:native: (attributes org.gtk.Property.get=gdk_macos_surface_get_native_window)
+   *
+   * The "native" property contains the underlying NSWindow.
+   */
   properties [PROP_NATIVE] =
     g_param_spec_pointer ("native",
                           "Native",
@@ -688,6 +693,27 @@ _gdk_macos_surface_get_native (GdkMacosSurface *self)
   return (NSWindow *)self->window;
 }
 
+/**
+ * gdk_macos_surface_get_native_window: (attributes org.gtk.Method.get_property=native)
+ * @self: a #GdkMacosSurface
+ *
+ * Gets the underlying NSWindow used by the surface.
+ *
+ * The NSWindow's contentView is an implementation detail and may change
+ * between releases of GTK.
+ *
+ * Returns: (nullable): a #NSWindow or %NULL
+ *
+ * Since: 4.8
+ */
+gpointer
+gdk_macos_surface_get_native_window (GdkMacosSurface *self)
+{
+  g_return_val_if_fail (GDK_IS_MACOS_SURFACE (self), NULL);
+
+  return _gdk_macos_surface_get_native (self);
+}
+
 void
 _gdk_macos_surface_set_geometry_hints (GdkMacosSurface   *self,
                                        const GdkGeometry *geometry,
index 470287202eb23efb93692c4953549f66b00deb72..64ea4c733debc9128dbe65610bce3b1e80c43ce1 100644 (file)
@@ -36,7 +36,9 @@ typedef struct _GdkMacosSurfaceClass GdkMacosSurfaceClass;
 #define GDK_IS_MACOS_SURFACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_MACOS_SURFACE))
 
 GDK_AVAILABLE_IN_ALL
-GType gdk_macos_surface_get_type (void);
+GType    gdk_macos_surface_get_type          (void);
+GDK_AVAILABLE_IN_4_8
+gpointer gdk_macos_surface_get_native_window (GdkMacosSurface *self);
 
 G_END_DECLS