[gtk/present-toplevel-2: 114/178] Add a GdkDragSurface interface



commit 50fc54aab8026ef60f6da8f383c88799aa6bfba7
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Mar 3 15:55:45 2020 -0800

    Add a GdkDragSurface interface
    
    This will provide functionality specific to drag icons.

 gdk/gdk.h                   |  1 +
 gdk/gdkdragsurface.c        | 75 +++++++++++++++++++++++++++++++++++++++++++++
 gdk/gdkdragsurface.h        | 43 ++++++++++++++++++++++++++
 gdk/gdkdragsurfaceprivate.h | 20 ++++++++++++
 gdk/meson.build             |  2 ++
 5 files changed, 141 insertions(+)
---
diff --git a/gdk/gdk.h b/gdk/gdk.h
index 5f6b03f3eb..995119440e 100644
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -71,6 +71,7 @@
 #include <gdk/gdkpopup.h>
 #include <gdk/gdktoplevellayout.h>
 #include <gdk/gdktoplevel.h>
+#include <gdk/gdkdragsurface.h>
 
 #include <gdk/gdk-autocleanup.h>
 
diff --git a/gdk/gdkdragsurface.c b/gdk/gdkdragsurface.c
new file mode 100644
index 0000000000..2bddb859d3
--- /dev/null
+++ b/gdk/gdkdragsurface.c
@@ -0,0 +1,75 @@
+/*
+ * 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 "gdkintl.h"
+#include "gdkdragsurfaceprivate.h"
+#include "gdk-private.h"
+
+/**
+ * SECTION:gdkdragsurface
+ * @Short_description: Interface for drag surface surfaces
+ * @Title: Drag surfaces
+ *
+ * A #GdkDragSurface is a surface that is used during a
+ * DND operation.
+ */
+
+
+/* FIXME: this can't have GdkSurface as a prerequisite
+ * as long as GdkSurface implements this interface itself
+ */
+G_DEFINE_INTERFACE (GdkDragSurface, gdk_drag_surface, G_TYPE_OBJECT)
+
+static gboolean
+gdk_drag_surface_default_present (GdkDragSurface *drag_surface,
+                                  int          width,
+                                  int          height)
+{
+  return FALSE;
+}
+
+static void
+gdk_drag_surface_default_init (GdkDragSurfaceInterface *iface)
+{
+  iface->present = gdk_drag_surface_default_present;
+}
+
+/**
+ * gdk_drag_surface_present:
+ * @drag_surface: the #GdkDragSurface to show
+ * @width: the unconstrained drag_surface width to layout
+ * @height: the unconstrained drag_surface height to layout
+ *
+ * Present @drag_surface.
+ *
+ * Returns: %FALSE if it failed to be presented, otherwise %TRUE.
+ */
+gboolean
+gdk_drag_surface_present (GdkDragSurface *drag_surface,
+                          int          width,
+                          int          height)
+{
+  g_return_val_if_fail (GDK_IS_DRAG_SURFACE (drag_surface), FALSE);
+  g_return_val_if_fail (width > 0, FALSE);
+  g_return_val_if_fail (height > 0, FALSE);
+
+  return GDK_DRAG_SURFACE_GET_IFACE (drag_surface)->present (drag_surface, width, height);
+}
diff --git a/gdk/gdkdragsurface.h b/gdk/gdkdragsurface.h
new file mode 100644
index 0000000000..b9772143ec
--- /dev/null
+++ b/gdk/gdkdragsurface.h
@@ -0,0 +1,43 @@
+/*
+ * 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_DRAG_SURFACE_H__
+#define __GDK_DRAG_SURFACE_H__
+
+#if !defined (__GDK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gdk/gdk.h> can be included directly."
+#endif
+
+#include <gdk/gdksurface.h>
+
+G_BEGIN_DECLS
+
+#define GDK_TYPE_DRAG_SURFACE               (gdk_drag_surface_get_type ())
+
+GDK_AVAILABLE_IN_ALL
+G_DECLARE_INTERFACE (GdkDragSurface, gdk_drag_surface, GDK, DRAG_SURFACE, GObject)
+
+GDK_AVAILABLE_IN_ALL
+gboolean        gdk_drag_surface_present        (GdkDragSurface *drag_icon,
+                                                 int             width,
+                                                 int             height);
+
+G_END_DECLS
+
+#endif /* __GDK_DRAG_SURFACE_H__ */
diff --git a/gdk/gdkdragsurfaceprivate.h b/gdk/gdkdragsurfaceprivate.h
new file mode 100644
index 0000000000..4301c7969b
--- /dev/null
+++ b/gdk/gdkdragsurfaceprivate.h
@@ -0,0 +1,20 @@
+#ifndef __GDK_DRAG_SURFACE_PRIVATE_H__
+#define __GDK_DRAG_SURFACE_PRIVATE_H__
+
+#include "gdkdragsurface.h"
+
+G_BEGIN_DECLS
+
+
+struct _GdkDragSurfaceInterface
+{
+  GTypeInterface g_iface;
+
+  gboolean      (* present)             (GdkDragSurface *drag_surface,
+                                         int             width,
+                                         int             height);
+};
+
+G_END_DECLS
+
+#endif /* __GDK_DRAG_SURFACE_PRIVATE_H__ */
diff --git a/gdk/meson.build b/gdk/meson.build
index 0c1a277549..ac14c3b6fe 100644
--- a/gdk/meson.build
+++ b/gdk/meson.build
@@ -48,6 +48,7 @@ gdk_public_sources = files([
   'gdkpopup.c',
   'gdktoplevellayout.c',
   'gdktoplevel.c',
+  'gdkdragsurface.c',
 ])
 
 gdk_public_headers = files([
@@ -95,6 +96,7 @@ gdk_public_headers = files([
   'gdkpopup.h',
   'gdktoplevellayout.h',
   'gdktoplevel.h',
+  'gdkdragsurface.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]