[gtk/present-toplevel-2: 64/178] Introduce GdkToplevel



commit a5fd330c755e5d81b0c92a8bc6f3690235f3317f
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 29 10:07:43 2020 -0500

    Introduce GdkToplevel
    
    This is a new interface for toplevel surfaces.

 gdk/gdk.h                |  1 +
 gdk/gdksurface.c         | 77 +++++++++++++++++++++++++++++++++++++++++++++-
 gdk/gdktoplevel.c        | 80 ++++++++++++++++++++++++++++++++++++++++++++++++
 gdk/gdktoplevel.h        | 45 +++++++++++++++++++++++++++
 gdk/gdktoplevelprivate.h | 21 +++++++++++++
 gdk/meson.build          |  2 ++
 6 files changed, 225 insertions(+), 1 deletion(-)
---
diff --git a/gdk/gdk.h b/gdk/gdk.h
index a4f434511e..5f6b03f3eb 100644
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -70,6 +70,7 @@
 #include <gdk/gdksurface.h>
 #include <gdk/gdkpopup.h>
 #include <gdk/gdktoplevellayout.h>
+#include <gdk/gdktoplevel.h>
 
 #include <gdk/gdk-autocleanup.h>
 
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 2a0070197d..365f90f937 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)
@@ -2078,6 +2082,77 @@ gdk_surface_popup_init (GdkPopupInterface *iface)
   iface->get_position_y = gdk_popup_surface_get_position_y;
 }
 
+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_SURFACE_GET_CLASS (surface)->unminimize (surface);
+
+  if (gdk_toplevel_layout_get_resizable (layout))
+    {
+      geometry.min_width = gdk_toplevel_layout_get_min_width (layout);
+      geometry.min_height = gdk_toplevel_layout_get_min_height (layout);
+      mask = GDK_HINT_MIN_SIZE;
+    }
+  else
+    {
+      geometry.max_width = geometry.min_width = width;
+      geometry.max_height = geometry.min_height = height;
+      mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE;
+    }
+
+  GDK_SURFACE_GET_CLASS (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,
diff --git a/gdk/gdktoplevel.c b/gdk/gdktoplevel.c
new file mode 100644
index 0000000000..c4155e860f
--- /dev/null
+++ b/gdk/gdktoplevel.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright © 2020 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Matthias Clasen <mclasen redhat com>
+ */
+
+#include "config.h"
+
+#include "gdktoplevelprivate.h"
+
+/**
+ * SECTION:gdktoplevel
+ * @Short_description: Interface for toplevel surfaces
+ * @Title: Toplevels
+ *
+ * A #GdkToplevel is a freestanding toplevel surface.
+ */
+
+
+/* FIXME: this can't have GdkSurface as a prerequisite
+ * as long as GdkSurface implements this interface itself
+ */
+G_DEFINE_INTERFACE (GdkToplevel, gdk_toplevel, G_TYPE_OBJECT)
+
+static gboolean
+gdk_toplevel_default_present (GdkToplevel       *toplevel,
+                              int                width,
+                              int                height,
+                              GdkToplevelLayout *layout)
+{
+  return FALSE;
+}
+
+static void
+gdk_toplevel_default_init (GdkToplevelInterface *iface)
+{
+  iface->present = gdk_toplevel_default_present;
+}
+
+/**
+ * gdk_toplevel_present:
+ * @toplevel: the #GdkToplevel to show
+ * @width: the unconstrained toplevel width to layout
+ * @height: the unconstrained toplevel height to layout
+ * @layout: the #GdkToplevelLayout object used to layout
+ *
+ * Present @toplevel after having processed the #GdkToplevelLayout rules.
+ * If the toplevel was previously now showing, it will be showed,
+ * otherwise it will change layout according to @layout.
+ *
+ * Presenting may fail.
+ *
+ * Returns: %FALSE if @toplevel failed to be presented, otherwise %TRUE.
+ */
+gboolean
+gdk_toplevel_present (GdkToplevel       *toplevel,
+                      int                width,
+                      int                height,
+                      GdkToplevelLayout *layout)
+{
+  g_return_val_if_fail (GDK_IS_TOPLEVEL (toplevel), FALSE);
+  g_return_val_if_fail (width > 0, FALSE);
+  g_return_val_if_fail (height > 0, FALSE);
+  g_return_val_if_fail (layout != NULL, FALSE);
+
+  return GDK_TOPLEVEL_GET_IFACE (toplevel)->present (toplevel, width, height, layout);
+}
diff --git a/gdk/gdktoplevel.h b/gdk/gdktoplevel.h
new file mode 100644
index 0000000000..eeb01582aa
--- /dev/null
+++ b/gdk/gdktoplevel.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2020 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Matthias Clasen <mclasen redhat com>
+ */
+
+#ifndef __GDK_TOPLEVEL_H__
+#define __GDK_TOPLEVEL_H__
+
+#if !defined (__GDK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gdk/gdk.h> can be included directly."
+#endif
+
+#include <gdk/gdksurface.h>
+#include <gdk/gdktoplevellayout.h>
+
+G_BEGIN_DECLS
+
+#define GDK_TYPE_TOPLEVEL               (gdk_toplevel_get_type ())
+
+GDK_AVAILABLE_IN_ALL
+G_DECLARE_INTERFACE (GdkToplevel, gdk_toplevel, GDK, TOPLEVEL, GObject)
+
+GDK_AVAILABLE_IN_ALL
+gboolean        gdk_toplevel_present            (GdkToplevel       *toplevel,
+                                                 int                width,
+                                                 int                height,
+                                                 GdkToplevelLayout *layout);
+
+G_END_DECLS
+
+#endif /* __GDK_TOPLEVEL_H__ */
diff --git a/gdk/gdktoplevelprivate.h b/gdk/gdktoplevelprivate.h
new file mode 100644
index 0000000000..bfa81c4282
--- /dev/null
+++ b/gdk/gdktoplevelprivate.h
@@ -0,0 +1,21 @@
+#ifndef __GDK_TOPLEVEL_PRIVATE_H__
+#define __GDK_TOPLEVEL_PRIVATE_H__
+
+#include "gdktoplevel.h"
+
+G_BEGIN_DECLS
+
+
+struct _GdkToplevelInterface
+{
+  GTypeInterface g_iface;
+
+  gboolean      (* present)             (GdkToplevel       *toplevel,
+                                         int                width,
+                                         int                height,
+                                         GdkToplevelLayout *layout);
+};
+
+G_END_DECLS
+
+#endif /* __GDK_TOPLEVEL_PRIVATE_H__ */
diff --git a/gdk/meson.build b/gdk/meson.build
index 27d1bc3cda..0c1a277549 100644
--- a/gdk/meson.build
+++ b/gdk/meson.build
@@ -47,6 +47,7 @@ gdk_public_sources = files([
   'gdkprofiler.c',
   'gdkpopup.c',
   'gdktoplevellayout.c',
+  'gdktoplevel.c',
 ])
 
 gdk_public_headers = files([
@@ -93,6 +94,7 @@ gdk_public_headers = files([
   'gdkpopuplayout.h',
   'gdkpopup.h',
   'gdktoplevellayout.h',
+  'gdktoplevel.h',
 ])
 install_headers(gdk_public_headers, subdir: 'gtk-4.0/gdk/')
 


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