[gtk/present-toplevel] Add gdk_surface_present_toplevel
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/present-toplevel] Add gdk_surface_present_toplevel
- Date: Sat, 29 Feb 2020 01:19:43 +0000 (UTC)
commit 1aec93529a45524ee66b5c0dd98ee36758ae86f4
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Feb 28 20:16:18 2020 -0500
Add gdk_surface_present_toplevel
Add a new api for presenting toplevel surfaces, and
a GdkToplevelLayout struct that collects all the relevant
parameters for it.
The implementation is currently just a fallback using
existing GdkSurface api.
gdk/gdksurface.c | 69 ++++++++++++++++
gdk/gdksurface.h | 6 ++
gdk/gdksurfaceprivate.h | 4 +
gdk/gdktoplevellayout.c | 208 ++++++++++++++++++++++++++++++++++++++++++++++++
gdk/gdktoplevellayout.h | 90 +++++++++++++++++++++
gdk/meson.build | 2 +
6 files changed, 379 insertions(+)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 8c9a23db10..596ee5fae8 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -396,6 +396,56 @@ gdk_surface_init (GdkSurface *surface)
NULL, g_object_unref);
}
+static void
+get_geometry_hints (GdkToplevelLayout *layout,
+ GdkGeometry *geometry,
+ GdkSurfaceHints *mask)
+{
+ 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;
+}
+
+static gboolean
+gdk_surface_real_present_toplevel (GdkSurface *surface,
+ int width,
+ int height,
+ GdkToplevelLayout *layout)
+{
+ GdkGeometry geometry;
+ GdkSurfaceHints mask;
+
+ get_geometry_hints (layout, &geometry, &mask);
+ gdk_surface_set_geometry_hints (surface, &geometry, mask);
+ gdk_surface_constrain_size (&geometry, mask, width, height, &width, &height);
+ gdk_surface_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_show (surface);
+
+ return TRUE;
+}
+
static void
gdk_surface_class_init (GdkSurfaceClass *klass)
{
@@ -406,6 +456,7 @@ gdk_surface_class_init (GdkSurfaceClass *klass)
object_class->get_property = gdk_surface_get_property;
klass->beep = gdk_surface_real_beep;
+ klass->present_toplevel = gdk_surface_real_present_toplevel;
/**
* GdkSurface:cursor:
@@ -2070,6 +2121,24 @@ gdk_surface_resize (GdkSurface *surface,
GDK_SURFACE_GET_CLASS (surface)->toplevel_resize (surface, width, height);
}
+gboolean
+gdk_surface_present_toplevel (GdkSurface *surface,
+ int width,
+ int height,
+ GdkToplevelLayout *layout)
+{
+ g_return_val_if_fail (GDK_IS_SURFACE (surface), FALSE);
+ g_return_val_if_fail (surface->parent == NULL, FALSE);
+ g_return_val_if_fail (layout, FALSE);
+ g_return_val_if_fail (!GDK_SURFACE_DESTROYED (surface), FALSE);
+ g_return_val_if_fail (width > 0 && height > 0, FALSE);
+
+ return GDK_SURFACE_GET_CLASS (surface)->present_toplevel (surface,
+ width,
+ height,
+ layout);
+}
+
/**
* gdk_surface_present_popup:
* @surface: the popup #GdkSurface to show
diff --git a/gdk/gdksurface.h b/gdk/gdksurface.h
index 67ba05b4ae..24ddec2edc 100644
--- a/gdk/gdksurface.h
+++ b/gdk/gdksurface.h
@@ -35,6 +35,7 @@
#include <gdk/gdkframeclock.h>
#include <gdk/gdkmonitor.h>
#include <gdk/gdkpopuplayout.h>
+#include <gdk/gdktoplevellayout.h>
G_BEGIN_DECLS
@@ -366,6 +367,11 @@ void gdk_surface_resize (GdkSurface *surface,
gint width,
gint height);
GDK_AVAILABLE_IN_ALL
+gboolean gdk_surface_present_toplevel (GdkSurface *surface,
+ int width,
+ int height,
+ GdkToplevelLayout *layout);
+GDK_AVAILABLE_IN_ALL
gboolean gdk_surface_present_popup (GdkSurface *surface,
int width,
int height,
diff --git a/gdk/gdksurfaceprivate.h b/gdk/gdksurfaceprivate.h
index e1e1f3687c..c06503f2e0 100644
--- a/gdk/gdksurfaceprivate.h
+++ b/gdk/gdksurfaceprivate.h
@@ -121,6 +121,10 @@ struct _GdkSurfaceClass
void (* toplevel_resize) (GdkSurface *surface,
gint width,
gint height);
+ gboolean (* present_toplevel) (GdkSurface *surface,
+ int width,
+ int height,
+ GdkToplevelLayout *layout);
gboolean (* present_popup) (GdkSurface *surface,
int width,
int height,
diff --git a/gdk/gdktoplevellayout.c b/gdk/gdktoplevellayout.c
new file mode 100644
index 0000000000..ef9b8dd3d5
--- /dev/null
+++ b/gdk/gdktoplevellayout.c
@@ -0,0 +1,208 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2020 Red Hat
+ *
+ * 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 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/>.
+ *
+ */
+
+#include "config.h"
+
+#include "gdktoplevellayout.h"
+
+#include "gdkmonitor.h"
+
+struct _GdkToplevelLayout
+{
+ /* < private >*/
+ grefcount ref_count;
+
+ int min_width;
+ int min_height;
+ int max_width;
+ int max_height;
+ gboolean maximized;
+ gboolean fullscreen;
+ GdkMonitor *fullscreen_monitor;
+};
+
+G_DEFINE_BOXED_TYPE (GdkToplevelLayout, gdk_toplevel_layout,
+ gdk_toplevel_layout_ref,
+ gdk_toplevel_layout_unref)
+
+/**
+ * gdk_toplevel_layout_new: (constructor)
+ *
+ * Create a toplevel layout description. Used together with
+ * gdk_surface_present_toplevel() to describe how a toplevel surface
+ * should be placed and behave on-screen.
+ *
+ * Returns: (transfer full): newly created instance of #GdkToplevelLayout
+ */
+GdkToplevelLayout *
+gdk_toplevel_layout_new (int min_width,
+ int min_height,
+ int max_width,
+ int max_height)
+{
+ GdkToplevelLayout *layout;
+
+ layout = g_new0 (GdkToplevelLayout, 1);
+ g_ref_count_init (&layout->ref_count);
+ layout->min_width = min_width;
+ layout->min_height = min_height;
+ layout->max_width = max_width;
+ layout->max_height = max_height;
+
+ return layout;
+}
+
+/**
+ * gdk_toplevel_layout_ref:
+ * @layout: a #GdkToplevelLayout
+ *
+ * Increases the reference count of @layout.
+ *
+ * Returns: the same @layout
+ */
+GdkToplevelLayout *
+gdk_toplevel_layout_ref (GdkToplevelLayout *layout)
+{
+ g_ref_count_inc (&layout->ref_count);
+ return layout;
+}
+
+/**
+ * gdk_toplevel_layout_unref:
+ * @layout: a #GdkToplevelLayout
+ *
+ * Decreases the reference count of @layout.
+ */
+void
+gdk_toplevel_layout_unref (GdkToplevelLayout *layout)
+{
+ if (g_ref_count_dec (&layout->ref_count))
+ {
+ g_clear_object (&layout->fullscreen_monitor);
+ g_free (layout);
+ }
+}
+
+/**
+ * gdk_toplevel_layout_copy:
+ * @layout: a #GdkToplevelLayout
+ *
+ * Create a new #GdkToplevelLayout and copy the contents of @layout into it.
+ *
+ * Returns: (transfer full): a copy of @layout.
+ */
+GdkToplevelLayout *
+gdk_toplevel_layout_copy (GdkToplevelLayout *layout)
+{
+ GdkToplevelLayout *new_layout;
+
+ new_layout = g_new0 (GdkToplevelLayout, 1);
+ g_ref_count_init (&new_layout->ref_count);
+
+ new_layout->min_width = layout->min_width;
+ new_layout->min_height = layout->min_height;
+ new_layout->max_width = layout->max_width;
+ new_layout->max_height = layout->max_height;
+ new_layout->maximized = layout->maximized;
+ new_layout->fullscreen = layout->fullscreen;
+ if (layout->fullscreen_monitor)
+ new_layout->fullscreen_monitor = g_object_ref (layout->fullscreen_monitor);
+
+ return new_layout;
+}
+
+/**
+ * gdk_toplevel_layout_equal:
+ * @layout: a #GdkToplevelLayout
+ * @other: another #GdkToplevelLayout
+ *
+ * Check whether @layout and @other has identical layout properties.
+ *
+ * Returns: %TRUE if @layout and @other have identical layout properties,
+ * otherwise %FALSE.
+ */
+gboolean
+gdk_toplevel_layout_equal (GdkToplevelLayout *layout,
+ GdkToplevelLayout *other)
+{
+ g_return_val_if_fail (layout, FALSE);
+ g_return_val_if_fail (other, FALSE);
+
+ return layout->min_width == other->min_width &&
+ layout->min_height == other->min_height &&
+ layout->max_width == other->max_width &&
+ layout->max_height == other->max_height &&
+ layout->maximized == other->maximized &&
+ layout->fullscreen == other->fullscreen &&
+ layout->fullscreen_monitor == other->fullscreen_monitor;
+}
+
+
+void
+gdk_toplevel_layout_get_min_size (GdkToplevelLayout *layout,
+ int *width,
+ int *height)
+{
+ *width = layout->min_width;
+ *height = layout->min_height;
+}
+
+void
+gdk_toplevel_layout_get_max_size (GdkToplevelLayout *layout,
+ int *width,
+ int *height)
+{
+ *width = layout->max_width;
+ *height = layout->max_height;
+}
+
+void
+gdk_toplevel_layout_set_maximized (GdkToplevelLayout *layout,
+ gboolean maximized)
+{
+ layout->maximized = maximized;
+}
+
+
+gboolean
+gdk_toplevel_layout_get_maximized (GdkToplevelLayout *layout)
+{
+ return layout->maximized;
+}
+
+void
+gdk_toplevel_layout_set_fullscreen (GdkToplevelLayout *layout,
+ gboolean fullscreen,
+ GdkMonitor *monitor)
+{
+ layout->fullscreen = fullscreen;
+ if (monitor)
+ layout->fullscreen_monitor = g_object_ref (monitor);
+}
+
+gboolean
+gdk_toplevel_layout_get_fullscreen (GdkToplevelLayout *layout)
+{
+ return layout->fullscreen;
+}
+
+GdkMonitor *
+gdk_toplevel_layout_get_fullscreen_monitor (GdkToplevelLayout *layout)
+{
+ return layout->fullscreen_monitor;
+}
diff --git a/gdk/gdktoplevellayout.h b/gdk/gdktoplevellayout.h
new file mode 100644
index 0000000000..5b4c8ccbb0
--- /dev/null
+++ b/gdk/gdktoplevellayout.h
@@ -0,0 +1,90 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2020 Red Hat
+ *
+ * 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 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/>.
+ *
+ */
+
+#ifndef __GDK_TOPLEVEL_LAYOUT_H__
+#define __GDK_TOPLEVEL_LAYOUT_H__
+
+#if !defined (__GDK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gdk/gdk.h> can be included directly."
+#endif
+
+#include <gdk/gdkversionmacros.h>
+#include <gdk/gdktypes.h>
+#include <gdk/gdkmonitor.h>
+
+G_BEGIN_DECLS
+
+/**
+ * GdkTopLevelLayout:
+ */
+typedef struct _GdkToplevelLayout GdkToplevelLayout;
+
+#define GDK_TYPE_TOPLEVEL_LAYOUT (gdk_toplevel_layout_get_type ())
+
+GDK_AVAILABLE_IN_ALL
+GType gdk_toplevel_layout_get_type (void);
+
+GDK_AVAILABLE_IN_ALL
+GdkToplevelLayout * gdk_toplevel_layout_new (int min_width,
+ int min_height,
+ int max_width,
+ int max_height);
+
+GDK_AVAILABLE_IN_ALL
+GdkToplevelLayout * gdk_toplevel_layout_ref (GdkToplevelLayout *layout);
+
+GDK_AVAILABLE_IN_ALL
+void gdk_toplevel_layout_unref (GdkToplevelLayout *layout);
+
+GDK_AVAILABLE_IN_ALL
+GdkToplevelLayout * gdk_toplevel_layout_copy (GdkToplevelLayout *layout);
+
+GDK_AVAILABLE_IN_ALL
+gboolean gdk_toplevel_layout_equal (GdkToplevelLayout *layout,
+ GdkToplevelLayout *other);
+
+GDK_AVAILABLE_IN_ALL
+void gdk_toplevel_layout_set_maximized (GdkToplevelLayout *layout,
+ gboolean maximized);
+GDK_AVAILABLE_IN_ALL
+void gdk_toplevel_layout_set_fullscreen (GdkToplevelLayout *layout,
+ gboolean fullscreen,
+ GdkMonitor *monitor);
+
+GDK_AVAILABLE_IN_ALL
+void gdk_toplevel_layout_get_min_size (GdkToplevelLayout *layout,
+ int *width,
+ int *height);
+
+GDK_AVAILABLE_IN_ALL
+void gdk_toplevel_layout_get_max_size (GdkToplevelLayout *layout,
+ int *width,
+ int *height);
+
+GDK_AVAILABLE_IN_ALL
+gboolean gdk_toplevel_layout_get_maximized (GdkToplevelLayout *layout);
+
+GDK_AVAILABLE_IN_ALL
+gboolean gdk_toplevel_layout_get_fullscreen (GdkToplevelLayout *layout);
+
+GDK_AVAILABLE_IN_ALL
+GdkMonitor * gdk_toplevel_layout_get_fullscreen_monitor (GdkToplevelLayout *layout);
+
+G_END_DECLS
+
+#endif /* __GDK_TOPLEVEL_LAYOUT_H__ */
diff --git a/gdk/meson.build b/gdk/meson.build
index 1df3b60e74..055325b42a 100644
--- a/gdk/meson.build
+++ b/gdk/meson.build
@@ -44,6 +44,7 @@ gdk_public_sources = files([
'gdkvulkancontext.c',
'gdksurface.c',
'gdkpopuplayout.c',
+ 'gdktoplevellayout.c',
'gdkprofiler.c'
])
@@ -89,6 +90,7 @@ gdk_public_headers = files([
'gdkvulkancontext.h',
'gdksurface.h',
'gdkpopuplayout.h',
+ 'gdktoplevellayout.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]