[gtk/wip/chergert/quartz4u: 88/120] macos: wire-up API to manually reposition popups



commit a18db213e2c37c452af9af08a9d499fb0d9eff60
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 20 17:13:46 2020 -0700

    macos: wire-up API to manually reposition popups

 gdk/macos/gdkmacospopupsurface-private.h |  1 +
 gdk/macos/gdkmacospopupsurface.c         | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)
---
diff --git a/gdk/macos/gdkmacospopupsurface-private.h b/gdk/macos/gdkmacospopupsurface-private.h
index c04c137cf7..8c63d4f6a0 100644
--- a/gdk/macos/gdkmacospopupsurface-private.h
+++ b/gdk/macos/gdkmacospopupsurface-private.h
@@ -41,6 +41,7 @@ GdkMacosSurface *_gdk_macos_popup_surface_new                (GdkMacosDisplay
                                                               int                   height);
 void             _gdk_macos_popup_surface_attach_to_parent   (GdkMacosPopupSurface *self);
 void             _gdk_macos_popup_surface_detach_from_parent (GdkMacosPopupSurface *self);
+void             _gdk_macos_popup_surface_reposition         (GdkMacosPopupSurface *self);
 
 G_END_DECLS
 
diff --git a/gdk/macos/gdkmacospopupsurface.c b/gdk/macos/gdkmacospopupsurface.c
index 5a42e87f67..d9b072a314 100644
--- a/gdk/macos/gdkmacospopupsurface.c
+++ b/gdk/macos/gdkmacospopupsurface.c
@@ -31,6 +31,7 @@
 struct _GdkMacosPopupSurface
 {
   GdkMacosSurface parent_instance;
+  GdkPopupLayout *layout;
 };
 
 struct _GdkMacosPopupSurfaceClass
@@ -51,6 +52,12 @@ gdk_macos_popup_surface_layout (GdkMacosPopupSurface *self,
   g_assert (layout != NULL);
   g_assert (GDK_SURFACE (self)->parent);
 
+  if (layout != self->layout)
+    {
+      g_clear_pointer (&self->layout, gdk_popup_layout_unref);
+      self->layout = gdk_popup_layout_ref (layout);
+    }
+
   gdk_surface_layout_popup_helper (GDK_SURFACE (self),
                                    width,
                                    height,
@@ -182,6 +189,7 @@ _gdk_macos_popup_surface_finalize (GObject *object)
   GdkMacosPopupSurface *self = (GdkMacosPopupSurface *)object;
 
   g_clear_object (&GDK_SURFACE (self)->parent);
+  g_clear_pointer (&self->layout, gdk_popup_layout_unref);
 
   G_OBJECT_CLASS (_gdk_macos_popup_surface_parent_class)->finalize (object);
 }
@@ -355,3 +363,19 @@ _gdk_macos_popup_surface_detach_from_parent (GdkMacosPopupSurface *self)
       _gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (surface->display));
     }
 }
+
+void
+_gdk_macos_popup_surface_reposition (GdkMacosPopupSurface *self)
+{
+  g_return_if_fail (GDK_IS_MACOS_POPUP_SURFACE (self));
+
+  if (self->layout == NULL ||
+      !gdk_surface_get_mapped (GDK_SURFACE (self)) ||
+      GDK_SURFACE (self)->parent == NULL)
+    return;
+
+  gdk_macos_popup_surface_layout (self,
+                                  GDK_SURFACE (self)->width,
+                                  GDK_SURFACE (self)->height,
+                                  self->layout);
+}


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