[gtk/present-toplevel-2: 21/70] surface: Implement GdkToplevel



commit e856cc2dee21c4a59a1f990c8cea8464716b1968
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 29 10:31:47 2020 -0500

    surface: Implement GdkToplevel
    
    This is not quite right, and only temporary, since
    it makes GDK_IS_TOPLEVEL (surface) true for every surface.
    
    Eventually, the implementation will be moved to the
    backends.

 gdk/gdksurface.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 68 insertions(+), 1 deletion(-)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 85c81508c9..ba0e02ac9e 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -39,6 +39,7 @@
 #include "gdkmarshalers.h"
 #include "gdkglcontextprivate.h"
 #include "gdkpopupprivate.h"
+#include "gdktoplevelprivate.h"
 #include "gdk-private.h"
 
 #include <math.h>
@@ -112,10 +113,13 @@ static guint signals[LAST_SIGNAL] = { 0 };
 static GParamSpec *properties[LAST_PROP] = { NULL, };
 
 static void gdk_surface_popup_init (GdkPopupInterface *iface);
+static void gdk_surface_toplevel_init (GdkToplevelInterface *iface);
 
 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkSurface, gdk_surface, G_TYPE_OBJECT,
                                   G_IMPLEMENT_INTERFACE (GDK_TYPE_POPUP,
-                                                         gdk_surface_popup_init))
+                                                         gdk_surface_popup_init)
+                                  G_IMPLEMENT_INTERFACE (GDK_TYPE_TOPLEVEL,
+                                                         gdk_surface_toplevel_init))
 
 static gboolean
 gdk_surface_real_beep (GdkSurface *surface)
@@ -2070,6 +2074,69 @@ gdk_surface_popup_init (GdkPopupInterface *iface)
   iface->get_position = gdk_popup_surface_get_position;
 }
 
+static gboolean
+gdk_toplevel_surface_present (GdkToplevel       *toplevel,
+                              int                width,
+                              int                height,
+                              GdkToplevelLayout *layout)
+{
+  GdkSurface *surface = GDK_SURFACE (toplevel);
+  GdkGeometry geometry;
+  GdkSurfaceHints mask;
+
+  g_return_val_if_fail (surface->surface_type == GDK_SURFACE_TOPLEVEL, FALSE);
+  g_return_val_if_fail (!GDK_SURFACE_DESTROYED (surface), FALSE);
+
+  gdk_toplevel_layout_get_min_size (layout,
+                                    &geometry.min_width,
+                                    &geometry.min_height);
+  gdk_toplevel_layout_get_max_size (layout,
+                                    &geometry.max_width,
+                                    &geometry.max_height);
+  mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE;
+  gdk_surface_set_geometry_hints (surface, &geometry, mask); 
+  gdk_surface_constrain_size (&geometry, mask, width, height, &width, &height);
+  GDK_SURFACE_GET_CLASS (surface)->toplevel_resize (surface, width, height);
+
+  if (gdk_toplevel_layout_get_maximized (layout))
+    gdk_surface_maximize (surface);
+  else
+    gdk_surface_unmaximize (surface);
+
+  if (gdk_toplevel_layout_get_fullscreen (layout))
+    {
+      GdkMonitor *monitor = gdk_toplevel_layout_get_fullscreen_monitor (layout);
+      if (monitor)
+        gdk_surface_fullscreen_on_monitor (surface, monitor);
+      else
+        gdk_surface_fullscreen (surface);
+    }
+  else
+    gdk_surface_unfullscreen (surface);
+
+  gdk_surface_set_modal_hint (surface, gdk_toplevel_layout_get_modal (layout));
+  gdk_surface_set_type_hint (surface, gdk_toplevel_layout_get_type_hint (layout));
+
+  if (gdk_toplevel_layout_get_raise (layout))
+    {
+      gdk_surface_show_internal (surface, TRUE);
+    }
+  else
+    {
+      gdk_surface_show_internal (surface, FALSE);
+      if (gdk_toplevel_layout_get_lower (layout))
+        gdk_surface_lower_internal (surface);
+    }
+
+  return TRUE;
+}
+
+static void
+gdk_surface_toplevel_init (GdkToplevelInterface *iface)
+{
+  iface->present = gdk_toplevel_surface_present;
+}
+
 static void
 gdk_surface_set_cursor_internal (GdkSurface *surface,
                                  GdkDevice *device,


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