[gtk/present-toplevel-2: 1/59] Introduce GdkToplevelLayout
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/present-toplevel-2: 1/59] Introduce GdkToplevelLayout
- Date: Thu, 5 Mar 2020 18:16:42 +0000 (UTC)
commit 9c8b53ca8cd0fb5fc7a359835d9d31e2435e9805
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Feb 29 10:31:22 2020 -0500
Introduce GdkToplevelLayout
This will be used in a new GdkTopleve interface in
the near future.
gdk/gdk.h | 1 +
gdk/gdksurface.c | 43 ---------
gdk/gdktoplevellayout.c | 246 ++++++++++++++++++++++++++++++++++++++++++++++++
gdk/gdktoplevellayout.h | 104 ++++++++++++++++++++
gdk/meson.build | 2 +
5 files changed, 353 insertions(+), 43 deletions(-)
---
diff --git a/gdk/gdk.h b/gdk/gdk.h
index b466fe391a..a4f434511e 100644
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -69,6 +69,7 @@
#include <gdk/gdkvulkancontext.h>
#include <gdk/gdksurface.h>
#include <gdk/gdkpopup.h>
+#include <gdk/gdktoplevellayout.h>
#include <gdk/gdk-autocleanup.h>
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index ca06422030..2a0070197d 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -2013,49 +2013,6 @@ 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)
-{
- GdkGeometry geometry;
- GdkSurfaceHints mask;
-
- 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);
-
- 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_set_modal_hint (surface, gdk_toplevel_layout_get_modal (layout));
-
- gdk_surface_show (surface);
-
- return TRUE;
-}
-
static gboolean
gdk_popup_surface_present (GdkPopup *popup,
int width,
diff --git a/gdk/gdktoplevellayout.c b/gdk/gdktoplevellayout.c
new file mode 100644
index 0000000000..8cbb1a6bf5
--- /dev/null
+++ b/gdk/gdktoplevellayout.c
@@ -0,0 +1,246 @@
+/* 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;
+ guint resizable : 1;
+ guint maximized : 1;
+ guint fullscreen : 1;
+ guint modal : 1;
+ GdkSurfaceTypeHint type_hint;
+ 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)
+{
+ 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->resizable = TRUE;
+ layout->maximized = FALSE;
+ layout->fullscreen = FALSE;
+ layout->modal = FALSE;
+ layout->type_hint = GDK_SURFACE_TYPE_HINT_NORMAL;
+ layout->fullscreen_monitor = NULL;
+
+ 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->resizable = layout->resizable;
+ new_layout->maximized = layout->maximized;
+ new_layout->fullscreen = layout->fullscreen;
+ new_layout->modal = layout->modal;
+ new_layout->type_hint = layout->type_hint;
+ 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->resizable == other->resizable &&
+ layout->maximized == other->maximized &&
+ layout->fullscreen == other->fullscreen &&
+ layout->modal == other->modal &&
+ layout->type_hint == other->type_hint &&
+ layout->fullscreen_monitor == other->fullscreen_monitor;
+}
+
+int
+gdk_toplevel_layout_get_min_width (GdkToplevelLayout *layout)
+{
+ return layout->min_width;
+}
+
+int
+gdk_toplevel_layout_get_min_height (GdkToplevelLayout *layout)
+{
+ return layout->min_height;
+}
+
+void
+gdk_toplevel_layout_set_resizable (GdkToplevelLayout *layout,
+ gboolean resizable)
+{
+ layout->resizable = resizable;
+}
+
+gboolean
+gdk_toplevel_layout_get_resizable (GdkToplevelLayout *layout)
+{
+ return layout->resizable;
+}
+
+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;
+}
+
+void
+gdk_toplevel_layout_set_modal (GdkToplevelLayout *layout,
+ gboolean modal)
+{
+ layout->modal = modal;
+}
+
+
+gboolean
+gdk_toplevel_layout_get_modal (GdkToplevelLayout *layout)
+{
+ return layout->modal;
+}
+
+void
+gdk_toplevel_layout_set_type_hint (GdkToplevelLayout *layout,
+ GdkSurfaceTypeHint type_hint)
+{
+ layout->type_hint = type_hint;
+}
+
+
+GdkSurfaceTypeHint
+gdk_toplevel_layout_get_type_hint (GdkToplevelLayout *layout)
+{
+ return layout->type_hint;
+}
diff --git a/gdk/gdktoplevellayout.h b/gdk/gdktoplevellayout.h
new file mode 100644
index 0000000000..a05f03f472
--- /dev/null
+++ b/gdk/gdktoplevellayout.h
@@ -0,0 +1,104 @@
+/* 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);
+
+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
+int gdk_toplevel_layout_get_min_width (GdkToplevelLayout *layout);
+GDK_AVAILABLE_IN_ALL
+int gdk_toplevel_layout_get_min_height (GdkToplevelLayout *layout);
+
+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);
+
+GDK_AVAILABLE_IN_ALL
+void gdk_toplevel_layout_set_resizable (GdkToplevelLayout *layout,
+ gboolean resizable);
+
+GDK_AVAILABLE_IN_ALL
+gboolean gdk_toplevel_layout_get_resizable (GdkToplevelLayout *layout);
+
+GDK_AVAILABLE_IN_ALL
+void gdk_toplevel_layout_set_modal (GdkToplevelLayout *layout,
+ gboolean modal);
+
+GDK_AVAILABLE_IN_ALL
+gboolean gdk_toplevel_layout_get_modal (GdkToplevelLayout *layout);
+
+GDK_AVAILABLE_IN_ALL
+void gdk_toplevel_layout_set_type_hint (GdkToplevelLayout *layout,
+ GdkSurfaceTypeHint hint);
+
+GDK_AVAILABLE_IN_ALL
+GdkSurfaceTypeHint gdk_toplevel_layout_get_type_hint (GdkToplevelLayout *layout);
+
+G_END_DECLS
+
+#endif /* __GDK_TOPLEVEL_LAYOUT_H__ */
diff --git a/gdk/meson.build b/gdk/meson.build
index 71d8393f92..27d1bc3cda 100644
--- a/gdk/meson.build
+++ b/gdk/meson.build
@@ -46,6 +46,7 @@ gdk_public_sources = files([
'gdkpopuplayout.c',
'gdkprofiler.c',
'gdkpopup.c',
+ 'gdktoplevellayout.c',
])
gdk_public_headers = files([
@@ -91,6 +92,7 @@ gdk_public_headers = files([
'gdksurface.h',
'gdkpopuplayout.h',
'gdkpopup.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]