[gtk+/wip/otte/clipboard: 1/11] gdk: A GdkClipboard API draft
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/clipboard: 1/11] gdk: A GdkClipboard API draft
- Date: Wed, 22 Nov 2017 11:24:14 +0000 (UTC)
commit 427eaed677431878ce81183e4f4e841ca12a083e
Author: Matthias Clasen <mclasen redhat com>
Date: Wed May 28 23:55:53 2014 -0400
gdk: A GdkClipboard API draft
This commit adds a GdkClipboard object which is intended to
replace GtkClipboard, eventually.
gdk/gdk.h | 1 +
gdk/gdkclipboard.c | 234 +++++++++++++++++++++++++++++++++++++++++++++
gdk/gdkclipboard.h | 47 +++++++++
gdk/gdkclipboardprivate.h | 51 ++++++++++
gdk/gdkdisplay.c | 41 ++++++++
gdk/gdkdisplay.h | 4 +
gdk/gdkdisplayprivate.h | 3 +
gdk/gdktypes.h | 1 +
gdk/meson.build | 2 +
9 files changed, 384 insertions(+), 0 deletions(-)
---
diff --git a/gdk/gdk.h b/gdk/gdk.h
index 296720c..ec280f6 100644
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -31,6 +31,7 @@
#include <gdk/gdkversionmacros.h>
#include <gdk/gdkapplaunchcontext.h>
#include <gdk/gdkcairo.h>
+#include <gdk/gdkclipboard.h>
#include <gdk/gdkcontentformats.h>
#include <gdk/gdkcursor.h>
#include <gdk/gdkdevice.h>
diff --git a/gdk/gdkclipboard.c b/gdk/gdkclipboard.c
new file mode 100644
index 0000000..da2f9db
--- /dev/null
+++ b/gdk/gdkclipboard.c
@@ -0,0 +1,234 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2014 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 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 "gdkclipboardprivate.h"
+
+#include "gdkcontentformats.h"
+#include "gdkdisplay.h"
+
+typedef struct _GdkClipboardPrivate GdkClipboardPrivate;
+
+struct _GdkClipboardPrivate
+{
+ GdkDisplay *display;
+ GdkContentFormats *formats;
+
+ guint local : 1;
+};
+
+enum {
+ PROP_0,
+ PROP_DISPLAY,
+ PROP_FORMATS,
+ PROP_LOCAL,
+ N_PROPERTIES
+};
+
+enum {
+ CHANGED,
+ N_SIGNALS
+};
+
+static GParamSpec *properties[N_PROPERTIES] = { NULL, };
+static guint signals[N_SIGNALS] = { 0 };
+
+G_DEFINE_TYPE_WITH_PRIVATE (GdkClipboard, gdk_clipboard, G_TYPE_OBJECT)
+
+static void
+gdk_clipboard_set_property (GObject *gobject,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GdkClipboard *clipboard = GDK_CLIPBOARD (gobject);
+ GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
+
+ switch (prop_id)
+ {
+ case PROP_DISPLAY:
+ priv->display = g_value_get_object (value);
+ g_assert (priv->display != NULL);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gdk_clipboard_get_property (GObject *gobject,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GdkClipboard *clipboard = GDK_CLIPBOARD (gobject);
+ GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
+
+ switch (prop_id)
+ {
+ case PROP_DISPLAY:
+ g_value_set_object (value, priv->display);
+ break;
+
+ case PROP_FORMATS:
+ g_value_set_boxed (value, priv->formats);
+ break;
+
+ case PROP_LOCAL:
+ g_value_set_boolean (value, priv->local);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gdk_clipboard_finalize (GObject *object)
+{
+ GdkClipboard *clipboard = GDK_CLIPBOARD (object);
+ GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
+
+ g_clear_pointer (&priv->formats, gdk_content_formats_unref);
+
+ G_OBJECT_CLASS (gdk_clipboard_parent_class)->finalize (object);
+}
+
+static void
+gdk_clipboard_class_init (GdkClipboardClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->get_property = gdk_clipboard_get_property;
+ object_class->set_property = gdk_clipboard_set_property;
+ object_class->finalize = gdk_clipboard_finalize;
+
+ /**
+ * GdkClipboard:display:
+ *
+ * The #GdkDisplay that the clipboard belongs to.
+ *
+ * Since: 3.94
+ */
+ properties[PROP_DISPLAY] =
+ g_param_spec_object ("display",
+ "Display",
+ "Display owning this clipboard",
+ GDK_TYPE_DISPLAY,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_EXPLICIT_NOTIFY);
+
+ /**
+ * GdkClipboard:formats:
+ *
+ * The possible formats that the clipboard can provide its data in.
+ *
+ * Since: 3.94
+ */
+ properties[PROP_FORMATS] =
+ g_param_spec_boxed ("formats",
+ "Formats",
+ "The possible formats for data",
+ GDK_TYPE_CONTENT_FORMATS,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_EXPLICIT_NOTIFY);
+
+ /**
+ * GdkClipboard:local:
+ *
+ * %TRUE if the contents of the clipboard are owned by this process.
+ *
+ * Since: 3.94
+ */
+ properties[PROP_LOCAL] =
+ g_param_spec_boolean ("local",
+ "Local",
+ "If the contents are owned by this process",
+ TRUE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_EXPLICIT_NOTIFY);
+
+ signals[CHANGED] =
+ g_signal_new ("changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GdkClipboardClass, changed),
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
+}
+
+static void
+gdk_clipboard_init (GdkClipboard *clipboard)
+{
+ GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
+
+ priv->formats = gdk_content_formats_new (NULL, 0);
+}
+
+/**
+ * gdk_clipboard_get_display:
+ * @clipboard: a #GdkClipboard
+ *
+ * Gets the #GdkDisplay that the clipboard was created for.
+ *
+ * Returns: (transfer none): a #GdkDisplay
+ **/
+GdkDisplay *
+gdk_clipboard_get_display (GdkClipboard *clipboard)
+{
+ GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
+
+ g_return_val_if_fail (GDK_IS_CLIPBOARD (clipboard), NULL);
+
+ return priv->display;
+}
+
+/**
+ * gdk_clipboard_get_formats:
+ * @clipboard: a #GdkClipboard
+ *
+ * Gets the formats that the clipboard can provide its current contents in.
+ *
+ * Returns: (transfer none): The formats of the clipboard
+ **/
+GdkContentFormats *
+gdk_clipboard_get_formats (GdkClipboard *clipboard)
+{
+ GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard);
+
+ g_return_val_if_fail (GDK_IS_CLIPBOARD (clipboard), NULL);
+
+ return priv->formats;
+}
+
+GdkClipboard *
+gdk_clipboard_new (GdkDisplay *display)
+{
+ return g_object_new (GDK_TYPE_CLIPBOARD,
+ "display", display,
+ NULL);
+}
diff --git a/gdk/gdkclipboard.h b/gdk/gdkclipboard.h
new file mode 100644
index 0000000..e997257
--- /dev/null
+++ b/gdk/gdkclipboard.h
@@ -0,0 +1,47 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2014 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 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_CLIPBOARD_H__
+#define __GDK_CLIPBOARD_H__
+
+#if !defined (__GDK_H_INSIDE__) && !defined (GDK_COMPILATION)
+#error "Only <gdk/gdk.h> can be included directly."
+#endif
+
+#include <gdk/gdkversionmacros.h>
+#include <gdk/gdktypes.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+
+G_BEGIN_DECLS
+
+#define GDK_TYPE_CLIPBOARD (gdk_clipboard_get_type ())
+#define GDK_CLIPBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDK_TYPE_CLIPBOARD, GdkClipboard))
+#define GDK_IS_CLIPBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDK_TYPE_CLIPBOARD))
+
+GDK_AVAILABLE_IN_3_94
+GType gdk_clipboard_get_type (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_3_94
+GdkDisplay * gdk_clipboard_get_display (GdkClipboard *clipboard);
+GDK_AVAILABLE_IN_3_94
+GdkContentFormats * gdk_clipboard_get_formats (GdkClipboard *clipboard);
+
+
+G_END_DECLS
+
+#endif /* __GDK_CLIPBOARD_H__ */
diff --git a/gdk/gdkclipboardprivate.h b/gdk/gdkclipboardprivate.h
new file mode 100644
index 0000000..317eb83
--- /dev/null
+++ b/gdk/gdkclipboardprivate.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2014 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 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_CLIPBOARD_PRIVATE_H__
+#define __GDK_CLIPBOARD_PRIVATE_H__
+
+#include <gdk/gdkclipboard.h>
+
+G_BEGIN_DECLS
+
+#define GDK_CLIPBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_CLIPBOARD,
GdkClipboardClass))
+#define GDK_IS_CLIPBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_CLIPBOARD))
+#define GDK_CLIPBOARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_CLIPBOARD,
GdkClipboardClass))
+
+typedef struct _GdkClipboardClass GdkClipboardClass;
+
+struct _GdkClipboard
+{
+ GObject parent;
+};
+
+struct _GdkClipboardClass
+{
+ GObjectClass parent_class;
+
+ /* signals */
+ void (* changed) (GdkClipboard *clipboard);
+
+ /* vfuncs */
+};
+
+GdkClipboard * gdk_clipboard_new (GdkDisplay *display);
+
+
+G_END_DECLS
+
+#endif /* __GDK_CLIPBOARD_PRIVATE_H__ */
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index 0d51b96..85a6f1a 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -27,6 +27,7 @@
#include "gdkintl.h"
#include "gdk-private.h"
+#include "gdkclipboardprivate.h"
#include "gdkdeviceprivate.h"
#include "gdkdisplaymanagerprivate.h"
#include "gdkevents.h"
@@ -1250,6 +1251,46 @@ gdk_display_request_selection_notification (GdkDisplay *display,
}
/**
+ * gdk_display_get_clipboard:
+ * @display: a #GdkDisplay
+ *
+ * Gets the clipboard used for copy/paste operations.
+ *
+ * Returns: the display's clipboard
+ **/
+GdkClipboard *
+gdk_display_get_clipboard (GdkDisplay *display)
+{
+ g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
+
+ if (display->clipboard == NULL)
+ display->clipboard = gdk_clipboard_new (display);
+
+ return display->clipboard;
+}
+
+/**
+ * gdk_display_get_primary_clipboard:
+ * @display: a #GdkDisplay
+ *
+ * Gets the clipboard used for the primary selection. On backends where the
+ * primary clipboard is not supported natively, GDK emulates this clipboard
+ * locally.
+ *
+ * Returns: the primary clipboard
+ **/
+GdkClipboard *
+gdk_display_get_primary_clipboard (GdkDisplay *display)
+{
+ g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
+
+ if (display->primary_clipboard == NULL)
+ display->primary_clipboard = gdk_clipboard_new (display);
+
+ return display->primary_clipboard;
+}
+
+/**
* gdk_display_supports_clipboard_persistence:
* @display: a #GdkDisplay
*
diff --git a/gdk/gdkdisplay.h b/gdk/gdkdisplay.h
index cf82ec2..443946f 100644
--- a/gdk/gdkdisplay.h
+++ b/gdk/gdkdisplay.h
@@ -100,6 +100,10 @@ GDK_AVAILABLE_IN_ALL
gboolean gdk_display_request_selection_notification (GdkDisplay *display,
GdkAtom selection);
+GDK_AVAILABLE_IN_3_94
+GdkClipboard * gdk_display_get_clipboard (GdkDisplay *display);
+GDK_AVAILABLE_IN_3_94
+GdkClipboard * gdk_display_get_primary_clipboard (GdkDisplay *display);
GDK_AVAILABLE_IN_ALL
gboolean gdk_display_supports_clipboard_persistence (GdkDisplay *display);
GDK_AVAILABLE_IN_ALL
diff --git a/gdk/gdkdisplayprivate.h b/gdk/gdkdisplayprivate.h
index 9c5dac2..f1e5869 100644
--- a/gdk/gdkdisplayprivate.h
+++ b/gdk/gdkdisplayprivate.h
@@ -84,6 +84,9 @@ struct _GdkDisplay
GHashTable *device_grabs;
GdkDeviceManager *device_manager;
+ GdkClipboard *clipboard;
+ GdkClipboard *primary_clipboard;
+
GHashTable *pointers_info; /* GdkPointerWindowInfo for each device */
guint32 last_event_time; /* Last reported event time from server */
diff --git a/gdk/gdktypes.h b/gdk/gdktypes.h
index 2105df5..7424576 100644
--- a/gdk/gdktypes.h
+++ b/gdk/gdktypes.h
@@ -126,6 +126,7 @@ typedef struct _GdkTexture GdkTexture;
typedef struct _GdkDevice GdkDevice;
typedef struct _GdkDragContext GdkDragContext;
+typedef struct _GdkClipboard GdkClipboard;
typedef struct _GdkDisplayManager GdkDisplayManager;
typedef struct _GdkDeviceManager GdkDeviceManager;
typedef struct _GdkDisplay GdkDisplay;
diff --git a/gdk/meson.build b/gdk/meson.build
index 9b34ee4..03b7758 100644
--- a/gdk/meson.build
+++ b/gdk/meson.build
@@ -2,6 +2,7 @@ gdk_public_sources = files([
'gdk.c',
'gdkapplaunchcontext.c',
'gdkcairo.c',
+ 'gdkclipboard.c',
'gdkcontentformats.c',
'gdkcursor.c',
'gdkdevice.c',
@@ -42,6 +43,7 @@ gdk_public_headers = files([
'gdk.h',
'gdkapplaunchcontext.h',
'gdkcairo.h',
+ 'gdkclipboard.h',
'gdkcontentformats.h',
'gdkcursor.h',
'gdkdevice.h',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]