diff --git a/gdk/gdk.h b/gdk/gdk.h index b466fe391a..8bd2df4b42 100644 --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -69,6 +69,7 @@ #include #include #include +#include #include 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 . + * + * Authors: Matthias Clasen + */ + +#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 . + * + * Authors: Matthias Clasen + */ + +#ifndef __GDK_TOPLEVEL_H__ +#define __GDK_TOPLEVEL_H__ + +#if !defined (__GDK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include +#include + +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/')