gdk: A GdkClipboard API draft

This commit adds a GdkClipboard object which is intended to
replace GtkClipboard, eventually.
This commit is contained in:
Matthias Clasen 2014-05-28 23:55:53 -04:00 committed by Benjamin Otte
parent 174a36257f
commit e94b9b9a62
9 changed files with 386 additions and 0 deletions

View File

@ -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>

235
gdk/gdkclipboard.c Normal file
View File

@ -0,0 +1,235 @@
/* GDK - The GIMP Drawing Kit
*
* Copyright (C) 2017 Benjamin Otte <otte@gnome.org>
*
* 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);
}

48
gdk/gdkclipboard.h Normal file
View File

@ -0,0 +1,48 @@
/* GDK - The GIMP Drawing Kit
*
* Copyright (C) 2017 Benjamin Otte <otte@gnome.org>
*
* 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__ */

51
gdk/gdkclipboardprivate.h Normal file
View File

@ -0,0 +1,51 @@
/*
* Copyright (C) 2017 Benjamin Otte <otte@gnome.org>
*
* 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__ */

View File

@ -27,6 +27,7 @@
#include "gdkintl.h"
#include "gdk-private.h"
#include "gdkclipboardprivate.h"
#include "gdkdeviceprivate.h"
#include "gdkdisplaymanagerprivate.h"
#include "gdkevents.h"
@ -1187,6 +1188,46 @@ gdk_display_request_selection_notification (GdkDisplay *display,
return GDK_DISPLAY_GET_CLASS (display)->request_selection_notification (display, selection);
}
/**
* 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

View File

@ -99,6 +99,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

View File

@ -83,6 +83,9 @@ struct _GdkDisplay
GHashTable *device_grabs;
GdkClipboard *clipboard;
GdkClipboard *primary_clipboard;
GHashTable *pointers_info; /* GdkPointerWindowInfo for each device */
guint32 last_event_time; /* Last reported event time from server */

View File

@ -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 _GdkDisplay GdkDisplay;
typedef struct _GdkWindow GdkWindow;

View File

@ -2,6 +2,7 @@ gdk_public_sources = files([
'gdk.c',
'gdkapplaunchcontext.c',
'gdkcairo.c',
'gdkclipboard.c',
'gdkcontentformats.c',
'gdkcursor.c',
'gdkdevice.c',
@ -41,6 +42,7 @@ gdk_public_headers = files([
'gdk.h',
'gdkapplaunchcontext.h',
'gdkcairo.h',
'gdkclipboard.h',
'gdkcontentformats.h',
'gdkcursor.h',
'gdkdevice.h',