[gtk/wip/chergert/quartz4u] macos: implement transient-for for toplevel surface



commit 145ae27b198537b95ccf48e92cf715584a78b790
Author: Christian Hergert <chergert redhat com>
Date:   Mon May 4 15:24:23 2020 -0700

    macos: implement transient-for for toplevel surface

 gdk/macos/GdkMacosWindow.c                  | 23 ++++-------
 gdk/macos/gdkmacostoplevelsurface-private.h | 18 +++++----
 gdk/macos/gdkmacostoplevelsurface.c         | 59 ++++++++++++++++++++++++-----
 3 files changed, 67 insertions(+), 33 deletions(-)
---
diff --git a/gdk/macos/GdkMacosWindow.c b/gdk/macos/GdkMacosWindow.c
index 5fbeaef08f..0de37529d9 100644
--- a/gdk/macos/GdkMacosWindow.c
+++ b/gdk/macos/GdkMacosWindow.c
@@ -29,6 +29,7 @@
 
 #include "gdkmacosdisplay-private.h"
 #include "gdkmacossurface-private.h"
+#include "gdkmacostoplevelsurface-private.h"
 
 #include "gdksurfaceprivate.h"
 
@@ -69,33 +70,23 @@
 
 -(void)windowWillMiniaturize:(NSNotification *)aNotification
 {
-#if 0
-  GdkSurface *window = [[self contentView] gdkSurface];
-
-  _gdk_quartz_surface_detach_from_parent (window);
-#endif
+  if (GDK_IS_MACOS_TOPLEVEL_SURFACE (gdkSurface))
+    _gdk_macos_toplevel_surface_detach_from_parent (GDK_MACOS_TOPLEVEL_SURFACE (gdkSurface));
 }
 
 -(void)windowDidMiniaturize:(NSNotification *)aNotification
 {
-#if 0
-  GdkSurface *window = [[self contentView] gdkSurface];
-
-  gdk_synthesize_surface_state (window, 0, GDK_SURFACE_STATE_MINIMIZED);
-#endif
+  gdk_synthesize_surface_state (GDK_SURFACE (gdkSurface), 0, GDK_SURFACE_STATE_MINIMIZED);
 
   [self invalidateStacking];
 }
 
 -(void)windowDidDeminiaturize:(NSNotification *)aNotification
 {
-#if 0
-  GdkSurface *window = [[self contentView] gdkSurface];
-
-  _gdk_quartz_surface_attach_to_parent (window);
+  if (GDK_IS_MACOS_TOPLEVEL_SURFACE (gdkSurface))
+    _gdk_macos_toplevel_surface_attach_to_parent (GDK_MACOS_TOPLEVEL_SURFACE (gdkSurface));
 
-  gdk_synthesize_surface_state (window, GDK_SURFACE_STATE_MINIMIZED, 0);
-#endif
+  gdk_synthesize_surface_state (GDK_SURFACE (gdkSurface), GDK_SURFACE_STATE_MINIMIZED, 0);
 
   [self invalidateStacking];
 }
diff --git a/gdk/macos/gdkmacostoplevelsurface-private.h b/gdk/macos/gdkmacostoplevelsurface-private.h
index b62f0f2818..d7866601e5 100644
--- a/gdk/macos/gdkmacostoplevelsurface-private.h
+++ b/gdk/macos/gdkmacostoplevelsurface-private.h
@@ -31,14 +31,16 @@ typedef struct _GdkMacosToplevelSurfaceClass GdkMacosToplevelSurfaceClass;
 #define GDK_MACOS_TOPLEVEL_SURFACE(object)    (G_TYPE_CHECK_INSTANCE_CAST ((object), 
GDK_TYPE_MACOS_TOPLEVEL_SURFACE, GdkMacosToplevelSurface))
 #define GDK_IS_MACOS_TOPLEVEL_SURFACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), 
GDK_TYPE_MACOS_TOPLEVEL_SURFACE))
 
-GType            _gdk_macos_toplevel_surface_get_type (void);
-GdkMacosSurface *_gdk_macos_toplevel_surface_new      (GdkMacosDisplay *display,
-                                                       GdkSurface      *parent,
-                                                       GdkFrameClock   *frame_clock,
-                                                       int              x,
-                                                       int              y,
-                                                       int              width,
-                                                       int              height);
+GType            _gdk_macos_toplevel_surface_get_type           (void);
+GdkMacosSurface *_gdk_macos_toplevel_surface_new                (GdkMacosDisplay *display,
+                                                                 GdkSurface      *parent,
+                                                                 GdkFrameClock   *frame_clock,
+                                                                 int              x,
+                                                                 int              y,
+                                                                 int              width,
+                                                                 int              height);
+void             _gdk_macos_toplevel_surface_attach_to_parent   (GdkMacosToplevelSurface *self);
+void             _gdk_macos_toplevel_surface_detach_from_parent (GdkMacosToplevelSurface *self);
 
 G_END_DECLS
 
diff --git a/gdk/macos/gdkmacostoplevelsurface.c b/gdk/macos/gdkmacostoplevelsurface.c
index 2132d91b63..08225410a0 100644
--- a/gdk/macos/gdkmacostoplevelsurface.c
+++ b/gdk/macos/gdkmacostoplevelsurface.c
@@ -140,6 +140,8 @@ _gdk_macos_toplevel_surface_present (GdkToplevel       *toplevel,
   /* Now present the window */
   [(GdkMacosWindow *)window showAndMakeKey:YES];
 
+  g_print ("Made window key\n");
+
   return TRUE;
 }
 
@@ -194,7 +196,11 @@ _gdk_macos_toplevel_surface_set_transient_for (GdkMacosToplevelSurface *self,
   g_assert (GDK_IS_MACOS_TOPLEVEL_SURFACE (self));
   g_assert (!parent || GDK_IS_MACOS_SURFACE (parent));
 
-  g_set_object (&self->transient_for, parent);
+  _gdk_macos_toplevel_surface_detach_from_parent (self);
+  g_clear_object (&self->transient_for);
+
+  if (g_set_object (&self->transient_for, parent))
+    _gdk_macos_toplevel_surface_attach_to_parent (self);
 }
 
 static void
@@ -214,23 +220,24 @@ _gdk_macos_toplevel_surface_set_decorated (GdkMacosToplevelSurface *self,
 }
 
 static void
-_gdk_macos_toplevel_surface_destroy (GdkSurface *surface,
-                                     gboolean    foreign_destroy)
+_gdk_macos_toplevel_surface_hide (GdkSurface *surface)
 {
   GdkMacosToplevelSurface *self = (GdkMacosToplevelSurface *)surface;
 
-  g_clear_object (&self->transient_for);
+  _gdk_macos_toplevel_surface_detach_from_parent (self);
 
-  GDK_SURFACE_CLASS (_gdk_macos_toplevel_surface_parent_class)->destroy (surface, foreign_destroy);
+  GDK_SURFACE_CLASS (_gdk_macos_toplevel_surface_parent_class)->hide (surface);
 }
 
 static void
-_gdk_macos_toplevel_surface_constructed (GObject *object)
+_gdk_macos_toplevel_surface_destroy (GdkSurface *surface,
+                                     gboolean    foreign_destroy)
 {
-  //GdkMacosToplevelSurface *self = (GdkMacosToplevelSurface *)object;
+  GdkMacosToplevelSurface *self = (GdkMacosToplevelSurface *)surface;
 
-  G_OBJECT_CLASS (_gdk_macos_toplevel_surface_parent_class)->constructed (object);
+  g_clear_object (&self->transient_for);
 
+  GDK_SURFACE_CLASS (_gdk_macos_toplevel_surface_parent_class)->destroy (surface, foreign_destroy);
 }
 
 static void
@@ -350,11 +357,11 @@ _gdk_macos_toplevel_surface_class_init (GdkMacosToplevelSurfaceClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GdkSurfaceClass *surface_class = GDK_SURFACE_CLASS (klass);
 
-  object_class->constructed = _gdk_macos_toplevel_surface_constructed;
   object_class->get_property = _gdk_macos_toplevel_surface_get_property;
   object_class->set_property = _gdk_macos_toplevel_surface_set_property;
 
   surface_class->destroy = _gdk_macos_toplevel_surface_destroy;
+  surface_class->hide = _gdk_macos_toplevel_surface_hide;
 
   gdk_toplevel_install_properties (object_class, LAST_PROP);
 }
@@ -418,3 +425,37 @@ _gdk_macos_toplevel_surface_new (GdkMacosDisplay *display,
 
   return g_steal_pointer (&self);
 }
+
+void
+_gdk_macos_toplevel_surface_attach_to_parent (GdkMacosToplevelSurface *self)
+{
+  g_return_if_fail (GDK_IS_MACOS_TOPLEVEL_SURFACE (self));
+
+  if (GDK_SURFACE_DESTROYED (self))
+    return;
+
+  if (self->transient_for != NULL && !GDK_SURFACE_DESTROYED (self->transient_for))
+    {
+      NSWindow *parent = _gdk_macos_surface_get_native (self->transient_for);
+      NSWindow *window = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (self));
+
+      [parent addChildWindow:window ordered:NSWindowAbove];
+    }
+}
+
+void
+_gdk_macos_toplevel_surface_detach_from_parent (GdkMacosToplevelSurface *self)
+{
+  g_return_if_fail (GDK_IS_MACOS_TOPLEVEL_SURFACE (self));
+
+  if (GDK_SURFACE_DESTROYED (self))
+    return;
+
+  if (self->transient_for != NULL && !GDK_SURFACE_DESTROYED (self->transient_for))
+    {
+      NSWindow *parent = _gdk_macos_surface_get_native (self->transient_for);
+      NSWindow *window = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (self));
+
+      [parent removeChildWindow:window];
+    }
+}


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