[gtk/present-toplevel-2: 15/59] Add a GdkDragSurface interface



commit b25be8a42f4ca470ebc958034ae19391e0eb22e7
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        | 71 +++++++++++++++++++++++++++++++++++++++++++++
 gdk/gdkdragsurface.h        | 43 +++++++++++++++++++++++++++
 gdk/gdkdragsurfaceprivate.h | 20 +++++++++++++
 gdk/gdksurface.c            | 27 ++++++++++++++++-
 gdk/meson.build             |  2 ++
 6 files changed, 163 insertions(+), 1 deletion(-)
---
diff --git a/gdk/gdk.h b/gdk/gdk.h
index 30ab0d7590..d15dd7d922 100644
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -44,6 +44,7 @@
 #include <gdk/gdkdisplay.h>
 #include <gdk/gdkdisplaymanager.h>
 #include <gdk/gdkdrag.h>
+#include <gdk/gdkdragsurface.h>
 #include <gdk/gdkdrawcontext.h>
 #include <gdk/gdkdrop.h>
 #include <gdk/gdkenumtypes.h>
diff --git a/gdk/gdkdragsurface.c b/gdk/gdkdragsurface.c
new file mode 100644
index 0000000000..4eb3c9137f
--- /dev/null
+++ b/gdk/gdkdragsurface.c
@@ -0,0 +1,71 @@
+/*
+ * 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 "gdk-private.h"
+#include "gdkdragsurfaceprivate.h"
+#include "gdkintl.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.
+ */
+
+G_DEFINE_INTERFACE (GdkDragSurface, gdk_drag_surface, GDK_TYPE_SURFACE)
+
+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..61649bff76
--- /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..e32cfd780c
--- /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/gdksurface.c b/gdk/gdksurface.c
index 4e6cce46df..850826ea85 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -32,6 +32,7 @@
 #include "gdk-private.h"
 #include "gdkdeviceprivate.h"
 #include "gdkdisplayprivate.h"
+#include "gdkdragsurfaceprivate.h"
 #include "gdkeventsprivate.h"
 #include "gdkframeclockidleprivate.h"
 #include "gdkglcontextprivate.h"
@@ -113,12 +114,15 @@ static GParamSpec *properties[LAST_PROP] = { NULL, };
 
 static void gdk_surface_popup_init (GdkPopupInterface *iface);
 static void gdk_surface_toplevel_init (GdkToplevelInterface *iface);
+static void gdk_surface_drag_surface_init (GdkDragSurfaceInterface *iface);
 
 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkSurface, gdk_surface, G_TYPE_OBJECT,
                                   G_IMPLEMENT_INTERFACE (GDK_TYPE_POPUP,
                                                          gdk_surface_popup_init)
                                   G_IMPLEMENT_INTERFACE (GDK_TYPE_TOPLEVEL,
-                                                         gdk_surface_toplevel_init))
+                                                         gdk_surface_toplevel_init)
+                                  G_IMPLEMENT_INTERFACE (GDK_TYPE_DRAG_SURFACE,
+                                                         gdk_surface_drag_surface_init))
 
 static gboolean
 gdk_surface_real_beep (GdkSurface *surface)
@@ -2176,6 +2180,27 @@ gdk_surface_toplevel_init (GdkToplevelInterface *iface)
   iface->show_window_menu = gdk_toplevel_surface_show_window_menu;
 }
 
+static gboolean
+gdk_drag_surface_real_present (GdkDragSurface *drag_surface,
+                               int             width,
+                               int             height)
+{
+  GdkSurface *surface = GDK_SURFACE (drag_surface);
+
+  g_return_val_if_fail (surface->surface_type == GDK_SURFACE_TEMP, FALSE);
+
+  GDK_SURFACE_GET_CLASS (surface)->toplevel_resize (surface, width, height);
+  gdk_surface_show_internal (surface, TRUE);
+
+  return TRUE;
+}
+
+static void
+gdk_surface_drag_surface_init (GdkDragSurfaceInterface *iface)
+{
+  iface->present = gdk_drag_surface_real_present;
+}
+
 static void
 gdk_surface_set_cursor_internal (GdkSurface *surface,
                                  GdkDevice *device,
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]