From ddaceb232c8b537a7d29a9708928d3a3671b98e5 Mon Sep 17 00:00:00 2001 From: haxar Date: Tue, 21 Feb 2012 20:13:04 -0800 Subject: gsd to msd complete rename patch by NiceandGently; code changes commit --- plugins/clipboard/Makefile.am | 12 ++-- plugins/clipboard/gsd-clipboard-manager.c | 114 +++++++++++++++--------------- plugins/clipboard/gsd-clipboard-manager.h | 34 ++++----- plugins/clipboard/gsd-clipboard-plugin.c | 42 +++++------ plugins/clipboard/gsd-clipboard-plugin.h | 28 ++++---- 5 files changed, 115 insertions(+), 115 deletions(-) (limited to 'plugins/clipboard') diff --git a/plugins/clipboard/Makefile.am b/plugins/clipboard/Makefile.am index f50a86e..4b1fdca 100644 --- a/plugins/clipboard/Makefile.am +++ b/plugins/clipboard/Makefile.am @@ -5,10 +5,10 @@ plugin_LTLIBRARIES = \ $(NULL) libclipboard_la_SOURCES = \ - gsd-clipboard-plugin.h \ - gsd-clipboard-plugin.c \ - gsd-clipboard-manager.h \ - gsd-clipboard-manager.c \ + msd-clipboard-plugin.h \ + msd-clipboard-plugin.c \ + msd-clipboard-manager.h \ + msd-clipboard-manager.c \ xutils.h \ xutils.c \ list.h \ @@ -25,7 +25,7 @@ libclipboard_la_CFLAGS = \ $(AM_CFLAGS) libclipboard_la_LDFLAGS = \ - $(GSD_PLUGIN_LDFLAGS) \ + $(MSD_PLUGIN_LDFLAGS) \ $(NULL) libclipboard_la_LIBADD = \ @@ -50,4 +50,4 @@ DISTCLEANFILES = \ $(plugin_DATA) \ $(NULL) -@GSD_INTLTOOL_PLUGIN_RULE@ +@MSD_INTLTOOL_PLUGIN_RULE@ diff --git a/plugins/clipboard/gsd-clipboard-manager.c b/plugins/clipboard/gsd-clipboard-manager.c index fcbc839..c6d5a57 100644 --- a/plugins/clipboard/gsd-clipboard-manager.c +++ b/plugins/clipboard/gsd-clipboard-manager.c @@ -45,11 +45,11 @@ #include "list.h" #include "mate-settings-profile.h" -#include "gsd-clipboard-manager.h" +#include "msd-clipboard-manager.h" -#define GSD_CLIPBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManagerPrivate)) +#define MSD_CLIPBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerPrivate)) -struct GsdClipboardManagerPrivate +struct MsdClipboardManagerPrivate { Display *display; Window window; @@ -82,17 +82,17 @@ typedef struct int offset; } IncrConversion; -static void gsd_clipboard_manager_class_init (GsdClipboardManagerClass *klass); -static void gsd_clipboard_manager_init (GsdClipboardManager *clipboard_manager); -static void gsd_clipboard_manager_finalize (GObject *object); +static void msd_clipboard_manager_class_init (MsdClipboardManagerClass *klass); +static void msd_clipboard_manager_init (MsdClipboardManager *clipboard_manager); +static void msd_clipboard_manager_finalize (GObject *object); -static void clipboard_manager_watch_cb (GsdClipboardManager *manager, +static void clipboard_manager_watch_cb (MsdClipboardManager *manager, Window window, Bool is_start, long mask, void *cb_data); -G_DEFINE_TYPE (GsdClipboardManager, gsd_clipboard_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (MsdClipboardManager, msd_clipboard_manager, G_TYPE_OBJECT) static gpointer manager_object = NULL; @@ -127,7 +127,7 @@ conversion_free (IncrConversion *rdata) } static void -send_selection_notify (GsdClipboardManager *manager, +send_selection_notify (MsdClipboardManager *manager, Bool success) { XSelectionEvent notify; @@ -155,7 +155,7 @@ send_selection_notify (GsdClipboardManager *manager, } static void -finish_selection_request (GsdClipboardManager *manager, +finish_selection_request (MsdClipboardManager *manager, XEvent *xev, Bool success) { @@ -195,7 +195,7 @@ clipboard_bytes_per_item (int format) } static void -save_targets (GsdClipboardManager *manager, +save_targets (MsdClipboardManager *manager, Atom *save_targets, int nitems) { @@ -263,7 +263,7 @@ find_conversion_requestor (IncrConversion *rdata, static void get_property (TargetData *tdata, - GsdClipboardManager *manager) + MsdClipboardManager *manager) { Atom type; int format; @@ -300,7 +300,7 @@ get_property (TargetData *tdata, } static Bool -receive_incrementally (GsdClipboardManager *manager, +receive_incrementally (MsdClipboardManager *manager, XEvent *xev) { List *list; @@ -359,7 +359,7 @@ receive_incrementally (GsdClipboardManager *manager, } static Bool -send_incrementally (GsdClipboardManager *manager, +send_incrementally (MsdClipboardManager *manager, XEvent *xev) { List *list; @@ -397,7 +397,7 @@ send_incrementally (GsdClipboardManager *manager, } static void -convert_clipboard_manager (GsdClipboardManager *manager, +convert_clipboard_manager (MsdClipboardManager *manager, XEvent *xev) { Atom type = None; @@ -486,7 +486,7 @@ convert_clipboard_manager (GsdClipboardManager *manager, static void convert_clipboard_target (IncrConversion *rdata, - GsdClipboardManager *manager) + MsdClipboardManager *manager) { TargetData *tdata; Atom *targets; @@ -561,7 +561,7 @@ convert_clipboard_target (IncrConversion *rdata, static void collect_incremental (IncrConversion *rdata, - GsdClipboardManager *manager) + MsdClipboardManager *manager) { if (rdata->offset >= 0) manager->priv->conversions = list_prepend (manager->priv->conversions, rdata); @@ -575,7 +575,7 @@ collect_incremental (IncrConversion *rdata, } static void -convert_clipboard (GsdClipboardManager *manager, +convert_clipboard (MsdClipboardManager *manager, XEvent *xev) { List *list; @@ -656,7 +656,7 @@ convert_clipboard (GsdClipboardManager *manager, } static Bool -clipboard_manager_process_event (GsdClipboardManager *manager, +clipboard_manager_process_event (MsdClipboardManager *manager, XEvent *xev) { Atom type; @@ -805,7 +805,7 @@ clipboard_manager_process_event (GsdClipboardManager *manager, static GdkFilterReturn clipboard_manager_event_filter (GdkXEvent *xevent, GdkEvent *event, - GsdClipboardManager *manager) + MsdClipboardManager *manager) { if (clipboard_manager_process_event (manager, (XEvent *)xevent)) { return GDK_FILTER_REMOVE; @@ -815,7 +815,7 @@ clipboard_manager_event_filter (GdkXEvent *xevent, } static void -clipboard_manager_watch_cb (GsdClipboardManager *manager, +clipboard_manager_watch_cb (MsdClipboardManager *manager, Window window, Bool is_start, long mask, @@ -849,7 +849,7 @@ clipboard_manager_watch_cb (GsdClipboardManager *manager, } static gboolean -start_clipboard_idle_cb (GsdClipboardManager *manager) +start_clipboard_idle_cb (MsdClipboardManager *manager) { XClientMessageEvent xev; @@ -924,7 +924,7 @@ start_clipboard_idle_cb (GsdClipboardManager *manager) } gboolean -gsd_clipboard_manager_start (GsdClipboardManager *manager, +msd_clipboard_manager_start (MsdClipboardManager *manager, GError **error) { mate_settings_profile_start (NULL); @@ -937,7 +937,7 @@ gsd_clipboard_manager_start (GsdClipboardManager *manager, } void -gsd_clipboard_manager_stop (GsdClipboardManager *manager) +msd_clipboard_manager_stop (MsdClipboardManager *manager) { g_debug ("Stopping clipboard manager"); @@ -956,14 +956,14 @@ gsd_clipboard_manager_stop (GsdClipboardManager *manager) } static void -gsd_clipboard_manager_set_property (GObject *object, +msd_clipboard_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GsdClipboardManager *self; + MsdClipboardManager *self; - self = GSD_CLIPBOARD_MANAGER (object); + self = MSD_CLIPBOARD_MANAGER (object); switch (prop_id) { default: @@ -973,14 +973,14 @@ gsd_clipboard_manager_set_property (GObject *object, } static void -gsd_clipboard_manager_get_property (GObject *object, +msd_clipboard_manager_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GsdClipboardManager *self; + MsdClipboardManager *self; - self = GSD_CLIPBOARD_MANAGER (object); + self = MSD_CLIPBOARD_MANAGER (object); switch (prop_id) { default: @@ -990,16 +990,16 @@ gsd_clipboard_manager_get_property (GObject *object, } static GObject * -gsd_clipboard_manager_constructor (GType type, +msd_clipboard_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - GsdClipboardManager *clipboard_manager; - GsdClipboardManagerClass *klass; + MsdClipboardManager *clipboard_manager; + MsdClipboardManagerClass *klass; - klass = GSD_CLIPBOARD_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_CLIPBOARD_MANAGER)); + klass = MSD_CLIPBOARD_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_CLIPBOARD_MANAGER)); - clipboard_manager = GSD_CLIPBOARD_MANAGER (G_OBJECT_CLASS (gsd_clipboard_manager_parent_class)->constructor (type, + clipboard_manager = MSD_CLIPBOARD_MANAGER (G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->constructor (type, n_construct_properties, construct_properties)); @@ -1007,63 +1007,63 @@ gsd_clipboard_manager_constructor (GType type, } static void -gsd_clipboard_manager_dispose (GObject *object) +msd_clipboard_manager_dispose (GObject *object) { - GsdClipboardManager *clipboard_manager; + MsdClipboardManager *clipboard_manager; - clipboard_manager = GSD_CLIPBOARD_MANAGER (object); + clipboard_manager = MSD_CLIPBOARD_MANAGER (object); - G_OBJECT_CLASS (gsd_clipboard_manager_parent_class)->dispose (object); + G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->dispose (object); } static void -gsd_clipboard_manager_class_init (GsdClipboardManagerClass *klass) +msd_clipboard_manager_class_init (MsdClipboardManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->get_property = gsd_clipboard_manager_get_property; - object_class->set_property = gsd_clipboard_manager_set_property; - object_class->constructor = gsd_clipboard_manager_constructor; - object_class->dispose = gsd_clipboard_manager_dispose; - object_class->finalize = gsd_clipboard_manager_finalize; + object_class->get_property = msd_clipboard_manager_get_property; + object_class->set_property = msd_clipboard_manager_set_property; + object_class->constructor = msd_clipboard_manager_constructor; + object_class->dispose = msd_clipboard_manager_dispose; + object_class->finalize = msd_clipboard_manager_finalize; - g_type_class_add_private (klass, sizeof (GsdClipboardManagerPrivate)); + g_type_class_add_private (klass, sizeof (MsdClipboardManagerPrivate)); } static void -gsd_clipboard_manager_init (GsdClipboardManager *manager) +msd_clipboard_manager_init (MsdClipboardManager *manager) { - manager->priv = GSD_CLIPBOARD_MANAGER_GET_PRIVATE (manager); + manager->priv = MSD_CLIPBOARD_MANAGER_GET_PRIVATE (manager); manager->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); } static void -gsd_clipboard_manager_finalize (GObject *object) +msd_clipboard_manager_finalize (GObject *object) { - GsdClipboardManager *clipboard_manager; + MsdClipboardManager *clipboard_manager; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_CLIPBOARD_MANAGER (object)); + g_return_if_fail (MSD_IS_CLIPBOARD_MANAGER (object)); - clipboard_manager = GSD_CLIPBOARD_MANAGER (object); + clipboard_manager = MSD_CLIPBOARD_MANAGER (object); g_return_if_fail (clipboard_manager->priv != NULL); - G_OBJECT_CLASS (gsd_clipboard_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->finalize (object); } -GsdClipboardManager * -gsd_clipboard_manager_new (void) +MsdClipboardManager * +msd_clipboard_manager_new (void) { if (manager_object != NULL) { g_object_ref (manager_object); } else { - manager_object = g_object_new (GSD_TYPE_CLIPBOARD_MANAGER, NULL); + manager_object = g_object_new (MSD_TYPE_CLIPBOARD_MANAGER, NULL); g_object_add_weak_pointer (manager_object, (gpointer *) &manager_object); } - return GSD_CLIPBOARD_MANAGER (manager_object); + return MSD_CLIPBOARD_MANAGER (manager_object); } diff --git a/plugins/clipboard/gsd-clipboard-manager.h b/plugins/clipboard/gsd-clipboard-manager.h index 0338799..e4af711 100644 --- a/plugins/clipboard/gsd-clipboard-manager.h +++ b/plugins/clipboard/gsd-clipboard-manager.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_CLIPBOARD_MANAGER_H -#define __GSD_CLIPBOARD_MANAGER_H +#ifndef __MSD_CLIPBOARD_MANAGER_H +#define __MSD_CLIPBOARD_MANAGER_H #include @@ -27,35 +27,35 @@ extern "C" { #endif -#define GSD_TYPE_CLIPBOARD_MANAGER (gsd_clipboard_manager_get_type ()) -#define GSD_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManager)) -#define GSD_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManagerClass)) -#define GSD_IS_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_CLIPBOARD_MANAGER)) -#define GSD_IS_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_CLIPBOARD_MANAGER)) -#define GSD_CLIPBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManagerClass)) +#define MSD_TYPE_CLIPBOARD_MANAGER (msd_clipboard_manager_get_type ()) +#define MSD_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManager)) +#define MSD_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerClass)) +#define MSD_IS_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_CLIPBOARD_MANAGER)) +#define MSD_IS_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_CLIPBOARD_MANAGER)) +#define MSD_CLIPBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerClass)) -typedef struct GsdClipboardManagerPrivate GsdClipboardManagerPrivate; +typedef struct MsdClipboardManagerPrivate MsdClipboardManagerPrivate; typedef struct { GObject parent; - GsdClipboardManagerPrivate *priv; -} GsdClipboardManager; + MsdClipboardManagerPrivate *priv; +} MsdClipboardManager; typedef struct { GObjectClass parent_class; -} GsdClipboardManagerClass; +} MsdClipboardManagerClass; -GType gsd_clipboard_manager_get_type (void); +GType msd_clipboard_manager_get_type (void); -GsdClipboardManager * gsd_clipboard_manager_new (void); -gboolean gsd_clipboard_manager_start (GsdClipboardManager *manager, +MsdClipboardManager * msd_clipboard_manager_new (void); +gboolean msd_clipboard_manager_start (MsdClipboardManager *manager, GError **error); -void gsd_clipboard_manager_stop (GsdClipboardManager *manager); +void msd_clipboard_manager_stop (MsdClipboardManager *manager); #ifdef __cplusplus } #endif -#endif /* __GSD_CLIPBOARD_MANAGER_H */ +#endif /* __MSD_CLIPBOARD_MANAGER_H */ diff --git a/plugins/clipboard/gsd-clipboard-plugin.c b/plugins/clipboard/gsd-clipboard-plugin.c index f384b52..6674265 100644 --- a/plugins/clipboard/gsd-clipboard-plugin.c +++ b/plugins/clipboard/gsd-clipboard-plugin.c @@ -24,38 +24,38 @@ #include #include "mate-settings-plugin.h" -#include "gsd-clipboard-plugin.h" -#include "gsd-clipboard-manager.h" +#include "msd-clipboard-plugin.h" +#include "msd-clipboard-manager.h" -struct GsdClipboardPluginPrivate { - GsdClipboardManager *manager; +struct MsdClipboardPluginPrivate { + MsdClipboardManager *manager; }; -#define GSD_CLIPBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_CLIPBOARD_PLUGIN, GsdClipboardPluginPrivate)) +#define MSD_CLIPBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginPrivate)) -MATE_SETTINGS_PLUGIN_REGISTER (GsdClipboardPlugin, gsd_clipboard_plugin) +MATE_SETTINGS_PLUGIN_REGISTER (MsdClipboardPlugin, msd_clipboard_plugin) static void -gsd_clipboard_plugin_init (GsdClipboardPlugin *plugin) +msd_clipboard_plugin_init (MsdClipboardPlugin *plugin) { - plugin->priv = GSD_CLIPBOARD_PLUGIN_GET_PRIVATE (plugin); + plugin->priv = MSD_CLIPBOARD_PLUGIN_GET_PRIVATE (plugin); - g_debug ("GsdClipboardPlugin initializing"); + g_debug ("MsdClipboardPlugin initializing"); - plugin->priv->manager = gsd_clipboard_manager_new (); + plugin->priv->manager = msd_clipboard_manager_new (); } static void -gsd_clipboard_plugin_finalize (GObject *object) +msd_clipboard_plugin_finalize (GObject *object) { - GsdClipboardPlugin *plugin; + MsdClipboardPlugin *plugin; g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_CLIPBOARD_PLUGIN (object)); + g_return_if_fail (MSD_IS_CLIPBOARD_PLUGIN (object)); - g_debug ("GsdClipboardPlugin finalizing"); + g_debug ("MsdClipboardPlugin finalizing"); - plugin = GSD_CLIPBOARD_PLUGIN (object); + plugin = MSD_CLIPBOARD_PLUGIN (object); g_return_if_fail (plugin->priv != NULL); @@ -63,7 +63,7 @@ gsd_clipboard_plugin_finalize (GObject *object) g_object_unref (plugin->priv->manager); } - G_OBJECT_CLASS (gsd_clipboard_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (msd_clipboard_plugin_parent_class)->finalize (object); } static void @@ -75,7 +75,7 @@ impl_activate (MateSettingsPlugin *plugin) g_debug ("Activating clipboard plugin"); error = NULL; - res = gsd_clipboard_manager_start (GSD_CLIPBOARD_PLUGIN (plugin)->priv->manager, &error); + res = msd_clipboard_manager_start (MSD_CLIPBOARD_PLUGIN (plugin)->priv->manager, &error); if (! res) { g_warning ("Unable to start clipboard manager: %s", error->message); g_error_free (error); @@ -86,19 +86,19 @@ static void impl_deactivate (MateSettingsPlugin *plugin) { g_debug ("Deactivating clipboard plugin"); - gsd_clipboard_manager_stop (GSD_CLIPBOARD_PLUGIN (plugin)->priv->manager); + msd_clipboard_manager_stop (MSD_CLIPBOARD_PLUGIN (plugin)->priv->manager); } static void -gsd_clipboard_plugin_class_init (GsdClipboardPluginClass *klass) +msd_clipboard_plugin_class_init (MsdClipboardPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - object_class->finalize = gsd_clipboard_plugin_finalize; + object_class->finalize = msd_clipboard_plugin_finalize; plugin_class->activate = impl_activate; plugin_class->deactivate = impl_deactivate; - g_type_class_add_private (klass, sizeof (GsdClipboardPluginPrivate)); + g_type_class_add_private (klass, sizeof (MsdClipboardPluginPrivate)); } diff --git a/plugins/clipboard/gsd-clipboard-plugin.h b/plugins/clipboard/gsd-clipboard-plugin.h index 4148c09..7b2ea1e 100644 --- a/plugins/clipboard/gsd-clipboard-plugin.h +++ b/plugins/clipboard/gsd-clipboard-plugin.h @@ -18,8 +18,8 @@ * */ -#ifndef __GSD_CLIPBOARD_PLUGIN_H__ -#define __GSD_CLIPBOARD_PLUGIN_H__ +#ifndef __MSD_CLIPBOARD_PLUGIN_H__ +#define __MSD_CLIPBOARD_PLUGIN_H__ #include #include @@ -31,27 +31,27 @@ extern "C" { #endif -#define GSD_TYPE_CLIPBOARD_PLUGIN (gsd_clipboard_plugin_get_type ()) -#define GSD_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_CLIPBOARD_PLUGIN, GsdClipboardPlugin)) -#define GSD_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_CLIPBOARD_PLUGIN, GsdClipboardPluginClass)) -#define GSD_IS_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_CLIPBOARD_PLUGIN)) -#define GSD_IS_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_CLIPBOARD_PLUGIN)) -#define GSD_CLIPBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_CLIPBOARD_PLUGIN, GsdClipboardPluginClass)) +#define MSD_TYPE_CLIPBOARD_PLUGIN (msd_clipboard_plugin_get_type ()) +#define MSD_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPlugin)) +#define MSD_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginClass)) +#define MSD_IS_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_CLIPBOARD_PLUGIN)) +#define MSD_IS_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_CLIPBOARD_PLUGIN)) +#define MSD_CLIPBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginClass)) -typedef struct GsdClipboardPluginPrivate GsdClipboardPluginPrivate; +typedef struct MsdClipboardPluginPrivate MsdClipboardPluginPrivate; typedef struct { MateSettingsPlugin parent; - GsdClipboardPluginPrivate *priv; -} GsdClipboardPlugin; + MsdClipboardPluginPrivate *priv; +} MsdClipboardPlugin; typedef struct { MateSettingsPluginClass parent_class; -} GsdClipboardPluginClass; +} MsdClipboardPluginClass; -GType gsd_clipboard_plugin_get_type (void) G_GNUC_CONST; +GType msd_clipboard_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); @@ -60,4 +60,4 @@ G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); } #endif -#endif /* __GSD_CLIPBOARD_PLUGIN_H__ */ +#endif /* __MSD_CLIPBOARD_PLUGIN_H__ */ -- cgit v1.2.1 From e46b4adef5c6c6805b3ca6dbfbe99a4299252514 Mon Sep 17 00:00:00 2001 From: haxar Date: Tue, 21 Feb 2012 20:14:01 -0800 Subject: gsd to msd complete rename patch by NiceandGently; file rename commit --- plugins/clipboard/gsd-clipboard-manager.c | 1069 ----------------------------- plugins/clipboard/gsd-clipboard-manager.h | 61 -- plugins/clipboard/gsd-clipboard-plugin.c | 104 --- plugins/clipboard/gsd-clipboard-plugin.h | 63 -- plugins/clipboard/msd-clipboard-manager.c | 1069 +++++++++++++++++++++++++++++ plugins/clipboard/msd-clipboard-manager.h | 61 ++ plugins/clipboard/msd-clipboard-plugin.c | 104 +++ plugins/clipboard/msd-clipboard-plugin.h | 63 ++ 8 files changed, 1297 insertions(+), 1297 deletions(-) delete mode 100644 plugins/clipboard/gsd-clipboard-manager.c delete mode 100644 plugins/clipboard/gsd-clipboard-manager.h delete mode 100644 plugins/clipboard/gsd-clipboard-plugin.c delete mode 100644 plugins/clipboard/gsd-clipboard-plugin.h create mode 100644 plugins/clipboard/msd-clipboard-manager.c create mode 100644 plugins/clipboard/msd-clipboard-manager.h create mode 100644 plugins/clipboard/msd-clipboard-plugin.c create mode 100644 plugins/clipboard/msd-clipboard-plugin.h (limited to 'plugins/clipboard') diff --git a/plugins/clipboard/gsd-clipboard-manager.c b/plugins/clipboard/gsd-clipboard-manager.c deleted file mode 100644 index c6d5a57..0000000 --- a/plugins/clipboard/gsd-clipboard-manager.c +++ /dev/null @@ -1,1069 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 Matthias Clasen - * Copyright (C) 2007 Anders Carlsson - * Copyright (C) 2007 Rodrigo Moya - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "xutils.h" -#include "list.h" - -#include "mate-settings-profile.h" -#include "msd-clipboard-manager.h" - -#define MSD_CLIPBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerPrivate)) - -struct MsdClipboardManagerPrivate -{ - Display *display; - Window window; - Time timestamp; - - List *contents; - List *conversions; - - Window requestor; - Atom property; - Time time; -}; - -typedef struct -{ - unsigned char *data; - int length; - Atom target; - Atom type; - int format; - int refcount; -} TargetData; - -typedef struct -{ - Atom target; - TargetData *data; - Atom property; - Window requestor; - int offset; -} IncrConversion; - -static void msd_clipboard_manager_class_init (MsdClipboardManagerClass *klass); -static void msd_clipboard_manager_init (MsdClipboardManager *clipboard_manager); -static void msd_clipboard_manager_finalize (GObject *object); - -static void clipboard_manager_watch_cb (MsdClipboardManager *manager, - Window window, - Bool is_start, - long mask, - void *cb_data); - -G_DEFINE_TYPE (MsdClipboardManager, msd_clipboard_manager, G_TYPE_OBJECT) - -static gpointer manager_object = NULL; - -/* We need to use reference counting for the target data, since we may - * need to keep the data around after loosing the CLIPBOARD ownership - * to complete incremental transfers. - */ -static TargetData * -target_data_ref (TargetData *data) -{ - data->refcount++; - return data; -} - -static void -target_data_unref (TargetData *data) -{ - data->refcount--; - if (data->refcount == 0) { - free (data->data); - free (data); - } -} - -static void -conversion_free (IncrConversion *rdata) -{ - if (rdata->data) { - target_data_unref (rdata->data); - } - free (rdata); -} - -static void -send_selection_notify (MsdClipboardManager *manager, - Bool success) -{ - XSelectionEvent notify; - - notify.type = SelectionNotify; - notify.serial = 0; - notify.send_event = True; - notify.display = manager->priv->display; - notify.requestor = manager->priv->requestor; - notify.selection = XA_CLIPBOARD_MANAGER; - notify.target = XA_SAVE_TARGETS; - notify.property = success ? manager->priv->property : None; - notify.time = manager->priv->time; - - gdk_error_trap_push (); - - XSendEvent (manager->priv->display, - manager->priv->requestor, - False, - NoEventMask, - (XEvent *)¬ify); - XSync (manager->priv->display, False); - - gdk_error_trap_pop (); -} - -static void -finish_selection_request (MsdClipboardManager *manager, - XEvent *xev, - Bool success) -{ - XSelectionEvent notify; - - notify.type = SelectionNotify; - notify.serial = 0; - notify.send_event = True; - notify.display = xev->xselectionrequest.display; - notify.requestor = xev->xselectionrequest.requestor; - notify.selection = xev->xselectionrequest.selection; - notify.target = xev->xselectionrequest.target; - notify.property = success ? xev->xselectionrequest.property : None; - notify.time = xev->xselectionrequest.time; - - gdk_error_trap_push (); - - XSendEvent (xev->xselectionrequest.display, - xev->xselectionrequest.requestor, - False, NoEventMask, (XEvent *) ¬ify); - XSync (manager->priv->display, False); - - gdk_error_trap_pop (); -} - -static int -clipboard_bytes_per_item (int format) -{ - switch (format) { - case 8: return sizeof (char); - case 16: return sizeof (short); - case 32: return sizeof (long); - default: ; - } - - return 0; -} - -static void -save_targets (MsdClipboardManager *manager, - Atom *save_targets, - int nitems) -{ - int nout, i; - Atom *multiple; - TargetData *tdata; - - multiple = (Atom *) malloc (2 * nitems * sizeof (Atom)); - - nout = 0; - for (i = 0; i < nitems; i++) { - if (save_targets[i] != XA_TARGETS && - save_targets[i] != XA_MULTIPLE && - save_targets[i] != XA_DELETE && - save_targets[i] != XA_INSERT_PROPERTY && - save_targets[i] != XA_INSERT_SELECTION && - save_targets[i] != XA_PIXMAP) { - tdata = (TargetData *) malloc (sizeof (TargetData)); - tdata->data = NULL; - tdata->length = 0; - tdata->target = save_targets[i]; - tdata->type = None; - tdata->format = 0; - tdata->refcount = 1; - manager->priv->contents = list_prepend (manager->priv->contents, tdata); - - multiple[nout++] = save_targets[i]; - multiple[nout++] = save_targets[i]; - } - } - - XFree (save_targets); - - XChangeProperty (manager->priv->display, manager->priv->window, - XA_MULTIPLE, XA_ATOM_PAIR, - 32, PropModeReplace, (const unsigned char *) multiple, nout); - free (multiple); - - XConvertSelection (manager->priv->display, XA_CLIPBOARD, - XA_MULTIPLE, XA_MULTIPLE, - manager->priv->window, manager->priv->time); -} - -static int -find_content_target (TargetData *tdata, - Atom target) -{ - return tdata->target == target; -} - -static int -find_content_type (TargetData *tdata, - Atom type) -{ - return tdata->type == type; -} - -static int -find_conversion_requestor (IncrConversion *rdata, - XEvent *xev) -{ - return (rdata->requestor == xev->xproperty.window && - rdata->property == xev->xproperty.atom); -} - -static void -get_property (TargetData *tdata, - MsdClipboardManager *manager) -{ - Atom type; - int format; - unsigned long length; - unsigned long remaining; - unsigned char *data; - - XGetWindowProperty (manager->priv->display, - manager->priv->window, - tdata->target, - 0, - 0x1FFFFFFF, - True, - AnyPropertyType, - &type, - &format, - &length, - &remaining, - &data); - - if (type == None) { - manager->priv->contents = list_remove (manager->priv->contents, tdata); - free (tdata); - } else if (type == XA_INCR) { - tdata->type = type; - tdata->length = 0; - XFree (data); - } else { - tdata->type = type; - tdata->data = data; - tdata->length = length * clipboard_bytes_per_item (format); - tdata->format = format; - } -} - -static Bool -receive_incrementally (MsdClipboardManager *manager, - XEvent *xev) -{ - List *list; - TargetData *tdata; - Atom type; - int format; - unsigned long length, nitems, remaining; - unsigned char *data; - - if (xev->xproperty.window != manager->priv->window) - return False; - - list = list_find (manager->priv->contents, - (ListFindFunc) find_content_target, (void *) xev->xproperty.atom); - - if (!list) - return False; - - tdata = (TargetData *) list->data; - - if (tdata->type != XA_INCR) - return False; - - XGetWindowProperty (xev->xproperty.display, - xev->xproperty.window, - xev->xproperty.atom, - 0, 0x1FFFFFFF, True, AnyPropertyType, - &type, &format, &nitems, &remaining, &data); - - length = nitems * clipboard_bytes_per_item (format); - if (length == 0) { - tdata->type = type; - tdata->format = format; - - if (!list_find (manager->priv->contents, - (ListFindFunc) find_content_type, (void *)XA_INCR)) { - /* all incremental transfers done */ - send_selection_notify (manager, True); - manager->priv->requestor = None; - } - - XFree (data); - } else { - if (!tdata->data) { - tdata->data = data; - tdata->length = length; - } else { - tdata->data = realloc (tdata->data, tdata->length + length + 1); - memcpy (tdata->data + tdata->length, data, length + 1); - tdata->length += length; - XFree (data); - } - } - - return True; -} - -static Bool -send_incrementally (MsdClipboardManager *manager, - XEvent *xev) -{ - List *list; - IncrConversion *rdata; - unsigned long length; - unsigned long items; - unsigned char *data; - - list = list_find (manager->priv->conversions, - (ListFindFunc) find_conversion_requestor, xev); - if (list == NULL) - return False; - - rdata = (IncrConversion *) list->data; - - data = rdata->data->data + rdata->offset; - length = rdata->data->length - rdata->offset; - if (length > SELECTION_MAX_SIZE) - length = SELECTION_MAX_SIZE; - - rdata->offset += length; - - items = length / clipboard_bytes_per_item (rdata->data->format); - XChangeProperty (manager->priv->display, rdata->requestor, - rdata->property, rdata->data->type, - rdata->data->format, PropModeAppend, - data, items); - - if (length == 0) { - manager->priv->conversions = list_remove (manager->priv->conversions, rdata); - conversion_free (rdata); - } - - return True; -} - -static void -convert_clipboard_manager (MsdClipboardManager *manager, - XEvent *xev) -{ - Atom type = None; - int format; - unsigned long nitems; - unsigned long remaining; - Atom *targets = NULL; - - if (xev->xselectionrequest.target == XA_SAVE_TARGETS) { - if (manager->priv->requestor != None || manager->priv->contents != NULL) { - /* We're in the middle of a conversion request, or own - * the CLIPBOARD already - */ - finish_selection_request (manager, xev, False); - } else { - gdk_error_trap_push (); - - clipboard_manager_watch_cb (manager, - xev->xselectionrequest.requestor, - True, - StructureNotifyMask, - NULL); - XSelectInput (manager->priv->display, - xev->xselectionrequest.requestor, - StructureNotifyMask); - XSync (manager->priv->display, False); - - if (gdk_error_trap_pop () != Success) - return; - - gdk_error_trap_push (); - - if (xev->xselectionrequest.property != None) { - XGetWindowProperty (manager->priv->display, - xev->xselectionrequest.requestor, - xev->xselectionrequest.property, - 0, 0x1FFFFFFF, False, XA_ATOM, - &type, &format, &nitems, &remaining, - (unsigned char **) &targets); - - if (gdk_error_trap_pop () != Success) { - if (targets) - XFree (targets); - - return; - } - } - - manager->priv->requestor = xev->xselectionrequest.requestor; - manager->priv->property = xev->xselectionrequest.property; - manager->priv->time = xev->xselectionrequest.time; - - if (type == None) - XConvertSelection (manager->priv->display, XA_CLIPBOARD, - XA_TARGETS, XA_TARGETS, - manager->priv->window, manager->priv->time); - else - save_targets (manager, targets, nitems); - } - } else if (xev->xselectionrequest.target == XA_TIMESTAMP) { - XChangeProperty (manager->priv->display, - xev->xselectionrequest.requestor, - xev->xselectionrequest.property, - XA_INTEGER, 32, PropModeReplace, - (unsigned char *) &manager->priv->timestamp, 1); - - finish_selection_request (manager, xev, True); - } else if (xev->xselectionrequest.target == XA_TARGETS) { - int n_targets = 0; - Atom targets[3]; - - targets[n_targets++] = XA_TARGETS; - targets[n_targets++] = XA_TIMESTAMP; - targets[n_targets++] = XA_SAVE_TARGETS; - - XChangeProperty (manager->priv->display, - xev->xselectionrequest.requestor, - xev->xselectionrequest.property, - XA_ATOM, 32, PropModeReplace, - (unsigned char *) targets, n_targets); - - finish_selection_request (manager, xev, True); - } else - finish_selection_request (manager, xev, False); -} - -static void -convert_clipboard_target (IncrConversion *rdata, - MsdClipboardManager *manager) -{ - TargetData *tdata; - Atom *targets; - int n_targets; - List *list; - unsigned long items; - XWindowAttributes atts; - - if (rdata->target == XA_TARGETS) { - n_targets = list_length (manager->priv->contents) + 2; - targets = (Atom *) malloc (n_targets * sizeof (Atom)); - - n_targets = 0; - - targets[n_targets++] = XA_TARGETS; - targets[n_targets++] = XA_MULTIPLE; - - for (list = manager->priv->contents; list; list = list->next) { - tdata = (TargetData *) list->data; - targets[n_targets++] = tdata->target; - } - - XChangeProperty (manager->priv->display, rdata->requestor, - rdata->property, - XA_ATOM, 32, PropModeReplace, - (unsigned char *) targets, n_targets); - free (targets); - } else { - /* Convert from stored CLIPBOARD data */ - list = list_find (manager->priv->contents, - (ListFindFunc) find_content_target, (void *) rdata->target); - - /* We got a target that we don't support */ - if (!list) - return; - - tdata = (TargetData *)list->data; - if (tdata->type == XA_INCR) { - /* we haven't completely received this target yet */ - rdata->property = None; - return; - } - - rdata->data = target_data_ref (tdata); - items = tdata->length / clipboard_bytes_per_item (tdata->format); - if (tdata->length <= SELECTION_MAX_SIZE) - XChangeProperty (manager->priv->display, rdata->requestor, - rdata->property, - tdata->type, tdata->format, PropModeReplace, - tdata->data, items); - else { - /* start incremental transfer */ - rdata->offset = 0; - - gdk_error_trap_push (); - - XGetWindowAttributes (manager->priv->display, rdata->requestor, &atts); - XSelectInput (manager->priv->display, rdata->requestor, - atts.your_event_mask | PropertyChangeMask); - - XChangeProperty (manager->priv->display, rdata->requestor, - rdata->property, - XA_INCR, 32, PropModeReplace, - (unsigned char *) &items, 1); - - XSync (manager->priv->display, False); - - gdk_error_trap_pop (); - } - } -} - -static void -collect_incremental (IncrConversion *rdata, - MsdClipboardManager *manager) -{ - if (rdata->offset >= 0) - manager->priv->conversions = list_prepend (manager->priv->conversions, rdata); - else { - if (rdata->data) { - target_data_unref (rdata->data); - rdata->data = NULL; - } - free (rdata); - } -} - -static void -convert_clipboard (MsdClipboardManager *manager, - XEvent *xev) -{ - List *list; - List *conversions; - IncrConversion *rdata; - Atom type; - int i; - int format; - unsigned long nitems; - unsigned long remaining; - Atom *multiple; - - conversions = NULL; - type = None; - - if (xev->xselectionrequest.target == XA_MULTIPLE) { - XGetWindowProperty (xev->xselectionrequest.display, - xev->xselectionrequest.requestor, - xev->xselectionrequest.property, - 0, 0x1FFFFFFF, False, XA_ATOM_PAIR, - &type, &format, &nitems, &remaining, - (unsigned char **) &multiple); - - if (type != XA_ATOM_PAIR || nitems == 0) { - if (multiple) - free (multiple); - return; - } - - for (i = 0; i < nitems; i += 2) { - rdata = (IncrConversion *) malloc (sizeof (IncrConversion)); - rdata->requestor = xev->xselectionrequest.requestor; - rdata->target = multiple[i]; - rdata->property = multiple[i+1]; - rdata->data = NULL; - rdata->offset = -1; - conversions = list_prepend (conversions, rdata); - } - } else { - multiple = NULL; - - rdata = (IncrConversion *) malloc (sizeof (IncrConversion)); - rdata->requestor = xev->xselectionrequest.requestor; - rdata->target = xev->xselectionrequest.target; - rdata->property = xev->xselectionrequest.property; - rdata->data = NULL; - rdata->offset = -1; - conversions = list_prepend (conversions, rdata); - } - - list_foreach (conversions, (Callback) convert_clipboard_target, manager); - - if (conversions->next == NULL && - ((IncrConversion *) conversions->data)->property == None) { - finish_selection_request (manager, xev, False); - } else { - if (multiple) { - i = 0; - for (list = conversions; list; list = list->next) { - rdata = (IncrConversion *)list->data; - multiple[i++] = rdata->target; - multiple[i++] = rdata->property; - } - XChangeProperty (xev->xselectionrequest.display, - xev->xselectionrequest.requestor, - xev->xselectionrequest.property, - XA_ATOM_PAIR, 32, PropModeReplace, - (unsigned char *) multiple, nitems); - } - finish_selection_request (manager, xev, True); - } - - list_foreach (conversions, (Callback) collect_incremental, manager); - list_free (conversions); - - if (multiple) - free (multiple); -} - -static Bool -clipboard_manager_process_event (MsdClipboardManager *manager, - XEvent *xev) -{ - Atom type; - int format; - unsigned long nitems; - unsigned long remaining; - Atom *targets; - - targets = NULL; - - switch (xev->xany.type) { - case DestroyNotify: - if (xev->xdestroywindow.window == manager->priv->requestor) { - list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); - list_free (manager->priv->contents); - manager->priv->contents = NULL; - - clipboard_manager_watch_cb (manager, - manager->priv->requestor, - False, - 0, - NULL); - manager->priv->requestor = None; - } - break; - case PropertyNotify: - if (xev->xproperty.state == PropertyNewValue) { - return receive_incrementally (manager, xev); - } else { - return send_incrementally (manager, xev); - } - - case SelectionClear: - if (xev->xany.window != manager->priv->window) - return False; - - if (xev->xselectionclear.selection == XA_CLIPBOARD_MANAGER) { - /* We lost the manager selection */ - if (manager->priv->contents) { - list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); - list_free (manager->priv->contents); - manager->priv->contents = NULL; - - XSetSelectionOwner (manager->priv->display, - XA_CLIPBOARD, - None, manager->priv->time); - } - - return True; - } - if (xev->xselectionclear.selection == XA_CLIPBOARD) { - /* We lost the clipboard selection */ - list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); - list_free (manager->priv->contents); - manager->priv->contents = NULL; - clipboard_manager_watch_cb (manager, - manager->priv->requestor, - False, - 0, - NULL); - manager->priv->requestor = None; - - return True; - } - break; - - case SelectionNotify: - if (xev->xany.window != manager->priv->window) - return False; - - if (xev->xselection.selection == XA_CLIPBOARD) { - /* a CLIPBOARD conversion is done */ - if (xev->xselection.property == XA_TARGETS) { - XGetWindowProperty (xev->xselection.display, - xev->xselection.requestor, - xev->xselection.property, - 0, 0x1FFFFFFF, True, XA_ATOM, - &type, &format, &nitems, &remaining, - (unsigned char **) &targets); - - save_targets (manager, targets, nitems); - } else if (xev->xselection.property == XA_MULTIPLE) { - List *tmp; - - tmp = list_copy (manager->priv->contents); - list_foreach (tmp, (Callback) get_property, manager); - list_free (tmp); - - manager->priv->time = xev->xselection.time; - XSetSelectionOwner (manager->priv->display, XA_CLIPBOARD, - manager->priv->window, manager->priv->time); - - if (manager->priv->property != None) - XChangeProperty (manager->priv->display, - manager->priv->requestor, - manager->priv->property, - XA_ATOM, 32, PropModeReplace, - (unsigned char *)&XA_NULL, 1); - - if (!list_find (manager->priv->contents, - (ListFindFunc)find_content_type, (void *)XA_INCR)) { - /* all transfers done */ - send_selection_notify (manager, True); - clipboard_manager_watch_cb (manager, - manager->priv->requestor, - False, - 0, - NULL); - manager->priv->requestor = None; - } - } - else if (xev->xselection.property == None) { - send_selection_notify (manager, False); - clipboard_manager_watch_cb (manager, - manager->priv->requestor, - False, - 0, - NULL); - manager->priv->requestor = None; - } - - return True; - } - break; - - case SelectionRequest: - if (xev->xany.window != manager->priv->window) { - return False; - } - - if (xev->xselectionrequest.selection == XA_CLIPBOARD_MANAGER) { - convert_clipboard_manager (manager, xev); - return True; - } else if (xev->xselectionrequest.selection == XA_CLIPBOARD) { - convert_clipboard (manager, xev); - return True; - } - break; - - default: ; - } - - return False; -} - -static GdkFilterReturn -clipboard_manager_event_filter (GdkXEvent *xevent, - GdkEvent *event, - MsdClipboardManager *manager) -{ - if (clipboard_manager_process_event (manager, (XEvent *)xevent)) { - return GDK_FILTER_REMOVE; - } else { - return GDK_FILTER_CONTINUE; - } -} - -static void -clipboard_manager_watch_cb (MsdClipboardManager *manager, - Window window, - Bool is_start, - long mask, - void *cb_data) -{ - GdkWindow *gdkwin; - GdkDisplay *display; - - display = gdk_display_get_default (); - gdkwin = gdk_window_lookup_for_display (display, window); - - if (is_start) { - if (gdkwin == NULL) { - gdkwin = gdk_window_foreign_new_for_display (display, window); - } else { - g_object_ref (gdkwin); - } - - gdk_window_add_filter (gdkwin, - (GdkFilterFunc)clipboard_manager_event_filter, - manager); - } else { - if (gdkwin == NULL) { - return; - } - gdk_window_remove_filter (gdkwin, - (GdkFilterFunc)clipboard_manager_event_filter, - manager); - g_object_unref (gdkwin); - } -} - -static gboolean -start_clipboard_idle_cb (MsdClipboardManager *manager) -{ - XClientMessageEvent xev; - - - mate_settings_profile_start (NULL); - - init_atoms (manager->priv->display); - - /* check if there is a clipboard manager running */ - if (XGetSelectionOwner (manager->priv->display, XA_CLIPBOARD_MANAGER)) { - g_warning ("Clipboard manager is already running."); - return FALSE; - } - - manager->priv->contents = NULL; - manager->priv->conversions = NULL; - manager->priv->requestor = None; - - manager->priv->window = XCreateSimpleWindow (manager->priv->display, - DefaultRootWindow (manager->priv->display), - 0, 0, 10, 10, 0, - WhitePixel (manager->priv->display, - DefaultScreen (manager->priv->display)), - WhitePixel (manager->priv->display, - DefaultScreen (manager->priv->display))); - clipboard_manager_watch_cb (manager, - manager->priv->window, - True, - PropertyChangeMask, - NULL); - XSelectInput (manager->priv->display, - manager->priv->window, - PropertyChangeMask); - manager->priv->timestamp = get_server_time (manager->priv->display, manager->priv->window); - - XSetSelectionOwner (manager->priv->display, - XA_CLIPBOARD_MANAGER, - manager->priv->window, - manager->priv->timestamp); - - /* Check to see if we managed to claim the selection. If not, - * we treat it as if we got it then immediately lost it - */ - if (XGetSelectionOwner (manager->priv->display, XA_CLIPBOARD_MANAGER) == manager->priv->window) { - xev.type = ClientMessage; - xev.window = DefaultRootWindow (manager->priv->display); - xev.message_type = XA_MANAGER; - xev.format = 32; - xev.data.l[0] = manager->priv->timestamp; - xev.data.l[1] = XA_CLIPBOARD_MANAGER; - xev.data.l[2] = manager->priv->window; - xev.data.l[3] = 0; /* manager specific data */ - xev.data.l[4] = 0; /* manager specific data */ - - XSendEvent (manager->priv->display, - DefaultRootWindow (manager->priv->display), - False, - StructureNotifyMask, - (XEvent *)&xev); - } else { - clipboard_manager_watch_cb (manager, - manager->priv->window, - False, - 0, - NULL); - /* FIXME: manager->priv->terminate (manager->priv->cb_data); */ - } - - mate_settings_profile_end (NULL); - - return FALSE; -} - -gboolean -msd_clipboard_manager_start (MsdClipboardManager *manager, - GError **error) -{ - mate_settings_profile_start (NULL); - - g_idle_add ((GSourceFunc) start_clipboard_idle_cb, manager); - - mate_settings_profile_end (NULL); - - return TRUE; -} - -void -msd_clipboard_manager_stop (MsdClipboardManager *manager) -{ - g_debug ("Stopping clipboard manager"); - - clipboard_manager_watch_cb (manager, - manager->priv->window, - FALSE, - 0, - NULL); - XDestroyWindow (manager->priv->display, manager->priv->window); - - list_foreach (manager->priv->conversions, (Callback) conversion_free, NULL); - list_free (manager->priv->conversions); - - list_foreach (manager->priv->contents, (Callback) target_data_unref, NULL); - list_free (manager->priv->contents); -} - -static void -msd_clipboard_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MsdClipboardManager *self; - - self = MSD_CLIPBOARD_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -msd_clipboard_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MsdClipboardManager *self; - - self = MSD_CLIPBOARD_MANAGER (object); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static GObject * -msd_clipboard_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - MsdClipboardManager *clipboard_manager; - MsdClipboardManagerClass *klass; - - klass = MSD_CLIPBOARD_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_CLIPBOARD_MANAGER)); - - clipboard_manager = MSD_CLIPBOARD_MANAGER (G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->constructor (type, - n_construct_properties, - construct_properties)); - - return G_OBJECT (clipboard_manager); -} - -static void -msd_clipboard_manager_dispose (GObject *object) -{ - MsdClipboardManager *clipboard_manager; - - clipboard_manager = MSD_CLIPBOARD_MANAGER (object); - - G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->dispose (object); -} - -static void -msd_clipboard_manager_class_init (MsdClipboardManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = msd_clipboard_manager_get_property; - object_class->set_property = msd_clipboard_manager_set_property; - object_class->constructor = msd_clipboard_manager_constructor; - object_class->dispose = msd_clipboard_manager_dispose; - object_class->finalize = msd_clipboard_manager_finalize; - - g_type_class_add_private (klass, sizeof (MsdClipboardManagerPrivate)); -} - -static void -msd_clipboard_manager_init (MsdClipboardManager *manager) -{ - manager->priv = MSD_CLIPBOARD_MANAGER_GET_PRIVATE (manager); - - manager->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); - -} - -static void -msd_clipboard_manager_finalize (GObject *object) -{ - MsdClipboardManager *clipboard_manager; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_CLIPBOARD_MANAGER (object)); - - clipboard_manager = MSD_CLIPBOARD_MANAGER (object); - - g_return_if_fail (clipboard_manager->priv != NULL); - - G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->finalize (object); -} - -MsdClipboardManager * -msd_clipboard_manager_new (void) -{ - if (manager_object != NULL) { - g_object_ref (manager_object); - } else { - manager_object = g_object_new (MSD_TYPE_CLIPBOARD_MANAGER, NULL); - g_object_add_weak_pointer (manager_object, - (gpointer *) &manager_object); - } - - return MSD_CLIPBOARD_MANAGER (manager_object); -} diff --git a/plugins/clipboard/gsd-clipboard-manager.h b/plugins/clipboard/gsd-clipboard-manager.h deleted file mode 100644 index e4af711..0000000 --- a/plugins/clipboard/gsd-clipboard-manager.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_CLIPBOARD_MANAGER_H -#define __MSD_CLIPBOARD_MANAGER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_CLIPBOARD_MANAGER (msd_clipboard_manager_get_type ()) -#define MSD_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManager)) -#define MSD_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerClass)) -#define MSD_IS_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_CLIPBOARD_MANAGER)) -#define MSD_IS_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_CLIPBOARD_MANAGER)) -#define MSD_CLIPBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerClass)) - -typedef struct MsdClipboardManagerPrivate MsdClipboardManagerPrivate; - -typedef struct -{ - GObject parent; - MsdClipboardManagerPrivate *priv; -} MsdClipboardManager; - -typedef struct -{ - GObjectClass parent_class; -} MsdClipboardManagerClass; - -GType msd_clipboard_manager_get_type (void); - -MsdClipboardManager * msd_clipboard_manager_new (void); -gboolean msd_clipboard_manager_start (MsdClipboardManager *manager, - GError **error); -void msd_clipboard_manager_stop (MsdClipboardManager *manager); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_CLIPBOARD_MANAGER_H */ diff --git a/plugins/clipboard/gsd-clipboard-plugin.c b/plugins/clipboard/gsd-clipboard-plugin.c deleted file mode 100644 index 6674265..0000000 --- a/plugins/clipboard/gsd-clipboard-plugin.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#include "config.h" - -#include -#include - -#include "mate-settings-plugin.h" -#include "msd-clipboard-plugin.h" -#include "msd-clipboard-manager.h" - -struct MsdClipboardPluginPrivate { - MsdClipboardManager *manager; -}; - -#define MSD_CLIPBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginPrivate)) - -MATE_SETTINGS_PLUGIN_REGISTER (MsdClipboardPlugin, msd_clipboard_plugin) - -static void -msd_clipboard_plugin_init (MsdClipboardPlugin *plugin) -{ - plugin->priv = MSD_CLIPBOARD_PLUGIN_GET_PRIVATE (plugin); - - g_debug ("MsdClipboardPlugin initializing"); - - plugin->priv->manager = msd_clipboard_manager_new (); -} - -static void -msd_clipboard_plugin_finalize (GObject *object) -{ - MsdClipboardPlugin *plugin; - - g_return_if_fail (object != NULL); - g_return_if_fail (MSD_IS_CLIPBOARD_PLUGIN (object)); - - g_debug ("MsdClipboardPlugin finalizing"); - - plugin = MSD_CLIPBOARD_PLUGIN (object); - - g_return_if_fail (plugin->priv != NULL); - - if (plugin->priv->manager != NULL) { - g_object_unref (plugin->priv->manager); - } - - G_OBJECT_CLASS (msd_clipboard_plugin_parent_class)->finalize (object); -} - -static void -impl_activate (MateSettingsPlugin *plugin) -{ - gboolean res; - GError *error; - - g_debug ("Activating clipboard plugin"); - - error = NULL; - res = msd_clipboard_manager_start (MSD_CLIPBOARD_PLUGIN (plugin)->priv->manager, &error); - if (! res) { - g_warning ("Unable to start clipboard manager: %s", error->message); - g_error_free (error); - } -} - -static void -impl_deactivate (MateSettingsPlugin *plugin) -{ - g_debug ("Deactivating clipboard plugin"); - msd_clipboard_manager_stop (MSD_CLIPBOARD_PLUGIN (plugin)->priv->manager); -} - -static void -msd_clipboard_plugin_class_init (MsdClipboardPluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); - - object_class->finalize = msd_clipboard_plugin_finalize; - - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - - g_type_class_add_private (klass, sizeof (MsdClipboardPluginPrivate)); -} diff --git a/plugins/clipboard/gsd-clipboard-plugin.h b/plugins/clipboard/gsd-clipboard-plugin.h deleted file mode 100644 index 7b2ea1e..0000000 --- a/plugins/clipboard/gsd-clipboard-plugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - -#ifndef __MSD_CLIPBOARD_PLUGIN_H__ -#define __MSD_CLIPBOARD_PLUGIN_H__ - -#include -#include -#include - -#include "mate-settings-plugin.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MSD_TYPE_CLIPBOARD_PLUGIN (msd_clipboard_plugin_get_type ()) -#define MSD_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPlugin)) -#define MSD_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginClass)) -#define MSD_IS_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_CLIPBOARD_PLUGIN)) -#define MSD_IS_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_CLIPBOARD_PLUGIN)) -#define MSD_CLIPBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginClass)) - -typedef struct MsdClipboardPluginPrivate MsdClipboardPluginPrivate; - -typedef struct -{ - MateSettingsPlugin parent; - MsdClipboardPluginPrivate *priv; -} MsdClipboardPlugin; - -typedef struct -{ - MateSettingsPluginClass parent_class; -} MsdClipboardPluginClass; - -GType msd_clipboard_plugin_get_type (void) G_GNUC_CONST; - -/* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); - -#ifdef __cplusplus -} -#endif - -#endif /* __MSD_CLIPBOARD_PLUGIN_H__ */ diff --git a/plugins/clipboard/msd-clipboard-manager.c b/plugins/clipboard/msd-clipboard-manager.c new file mode 100644 index 0000000..c6d5a57 --- /dev/null +++ b/plugins/clipboard/msd-clipboard-manager.c @@ -0,0 +1,1069 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 Matthias Clasen + * Copyright (C) 2007 Anders Carlsson + * Copyright (C) 2007 Rodrigo Moya + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "xutils.h" +#include "list.h" + +#include "mate-settings-profile.h" +#include "msd-clipboard-manager.h" + +#define MSD_CLIPBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerPrivate)) + +struct MsdClipboardManagerPrivate +{ + Display *display; + Window window; + Time timestamp; + + List *contents; + List *conversions; + + Window requestor; + Atom property; + Time time; +}; + +typedef struct +{ + unsigned char *data; + int length; + Atom target; + Atom type; + int format; + int refcount; +} TargetData; + +typedef struct +{ + Atom target; + TargetData *data; + Atom property; + Window requestor; + int offset; +} IncrConversion; + +static void msd_clipboard_manager_class_init (MsdClipboardManagerClass *klass); +static void msd_clipboard_manager_init (MsdClipboardManager *clipboard_manager); +static void msd_clipboard_manager_finalize (GObject *object); + +static void clipboard_manager_watch_cb (MsdClipboardManager *manager, + Window window, + Bool is_start, + long mask, + void *cb_data); + +G_DEFINE_TYPE (MsdClipboardManager, msd_clipboard_manager, G_TYPE_OBJECT) + +static gpointer manager_object = NULL; + +/* We need to use reference counting for the target data, since we may + * need to keep the data around after loosing the CLIPBOARD ownership + * to complete incremental transfers. + */ +static TargetData * +target_data_ref (TargetData *data) +{ + data->refcount++; + return data; +} + +static void +target_data_unref (TargetData *data) +{ + data->refcount--; + if (data->refcount == 0) { + free (data->data); + free (data); + } +} + +static void +conversion_free (IncrConversion *rdata) +{ + if (rdata->data) { + target_data_unref (rdata->data); + } + free (rdata); +} + +static void +send_selection_notify (MsdClipboardManager *manager, + Bool success) +{ + XSelectionEvent notify; + + notify.type = SelectionNotify; + notify.serial = 0; + notify.send_event = True; + notify.display = manager->priv->display; + notify.requestor = manager->priv->requestor; + notify.selection = XA_CLIPBOARD_MANAGER; + notify.target = XA_SAVE_TARGETS; + notify.property = success ? manager->priv->property : None; + notify.time = manager->priv->time; + + gdk_error_trap_push (); + + XSendEvent (manager->priv->display, + manager->priv->requestor, + False, + NoEventMask, + (XEvent *)¬ify); + XSync (manager->priv->display, False); + + gdk_error_trap_pop (); +} + +static void +finish_selection_request (MsdClipboardManager *manager, + XEvent *xev, + Bool success) +{ + XSelectionEvent notify; + + notify.type = SelectionNotify; + notify.serial = 0; + notify.send_event = True; + notify.display = xev->xselectionrequest.display; + notify.requestor = xev->xselectionrequest.requestor; + notify.selection = xev->xselectionrequest.selection; + notify.target = xev->xselectionrequest.target; + notify.property = success ? xev->xselectionrequest.property : None; + notify.time = xev->xselectionrequest.time; + + gdk_error_trap_push (); + + XSendEvent (xev->xselectionrequest.display, + xev->xselectionrequest.requestor, + False, NoEventMask, (XEvent *) ¬ify); + XSync (manager->priv->display, False); + + gdk_error_trap_pop (); +} + +static int +clipboard_bytes_per_item (int format) +{ + switch (format) { + case 8: return sizeof (char); + case 16: return sizeof (short); + case 32: return sizeof (long); + default: ; + } + + return 0; +} + +static void +save_targets (MsdClipboardManager *manager, + Atom *save_targets, + int nitems) +{ + int nout, i; + Atom *multiple; + TargetData *tdata; + + multiple = (Atom *) malloc (2 * nitems * sizeof (Atom)); + + nout = 0; + for (i = 0; i < nitems; i++) { + if (save_targets[i] != XA_TARGETS && + save_targets[i] != XA_MULTIPLE && + save_targets[i] != XA_DELETE && + save_targets[i] != XA_INSERT_PROPERTY && + save_targets[i] != XA_INSERT_SELECTION && + save_targets[i] != XA_PIXMAP) { + tdata = (TargetData *) malloc (sizeof (TargetData)); + tdata->data = NULL; + tdata->length = 0; + tdata->target = save_targets[i]; + tdata->type = None; + tdata->format = 0; + tdata->refcount = 1; + manager->priv->contents = list_prepend (manager->priv->contents, tdata); + + multiple[nout++] = save_targets[i]; + multiple[nout++] = save_targets[i]; + } + } + + XFree (save_targets); + + XChangeProperty (manager->priv->display, manager->priv->window, + XA_MULTIPLE, XA_ATOM_PAIR, + 32, PropModeReplace, (const unsigned char *) multiple, nout); + free (multiple); + + XConvertSelection (manager->priv->display, XA_CLIPBOARD, + XA_MULTIPLE, XA_MULTIPLE, + manager->priv->window, manager->priv->time); +} + +static int +find_content_target (TargetData *tdata, + Atom target) +{ + return tdata->target == target; +} + +static int +find_content_type (TargetData *tdata, + Atom type) +{ + return tdata->type == type; +} + +static int +find_conversion_requestor (IncrConversion *rdata, + XEvent *xev) +{ + return (rdata->requestor == xev->xproperty.window && + rdata->property == xev->xproperty.atom); +} + +static void +get_property (TargetData *tdata, + MsdClipboardManager *manager) +{ + Atom type; + int format; + unsigned long length; + unsigned long remaining; + unsigned char *data; + + XGetWindowProperty (manager->priv->display, + manager->priv->window, + tdata->target, + 0, + 0x1FFFFFFF, + True, + AnyPropertyType, + &type, + &format, + &length, + &remaining, + &data); + + if (type == None) { + manager->priv->contents = list_remove (manager->priv->contents, tdata); + free (tdata); + } else if (type == XA_INCR) { + tdata->type = type; + tdata->length = 0; + XFree (data); + } else { + tdata->type = type; + tdata->data = data; + tdata->length = length * clipboard_bytes_per_item (format); + tdata->format = format; + } +} + +static Bool +receive_incrementally (MsdClipboardManager *manager, + XEvent *xev) +{ + List *list; + TargetData *tdata; + Atom type; + int format; + unsigned long length, nitems, remaining; + unsigned char *data; + + if (xev->xproperty.window != manager->priv->window) + return False; + + list = list_find (manager->priv->contents, + (ListFindFunc) find_content_target, (void *) xev->xproperty.atom); + + if (!list) + return False; + + tdata = (TargetData *) list->data; + + if (tdata->type != XA_INCR) + return False; + + XGetWindowProperty (xev->xproperty.display, + xev->xproperty.window, + xev->xproperty.atom, + 0, 0x1FFFFFFF, True, AnyPropertyType, + &type, &format, &nitems, &remaining, &data); + + length = nitems * clipboard_bytes_per_item (format); + if (length == 0) { + tdata->type = type; + tdata->format = format; + + if (!list_find (manager->priv->contents, + (ListFindFunc) find_content_type, (void *)XA_INCR)) { + /* all incremental transfers done */ + send_selection_notify (manager, True); + manager->priv->requestor = None; + } + + XFree (data); + } else { + if (!tdata->data) { + tdata->data = data; + tdata->length = length; + } else { + tdata->data = realloc (tdata->data, tdata->length + length + 1); + memcpy (tdata->data + tdata->length, data, length + 1); + tdata->length += length; + XFree (data); + } + } + + return True; +} + +static Bool +send_incrementally (MsdClipboardManager *manager, + XEvent *xev) +{ + List *list; + IncrConversion *rdata; + unsigned long length; + unsigned long items; + unsigned char *data; + + list = list_find (manager->priv->conversions, + (ListFindFunc) find_conversion_requestor, xev); + if (list == NULL) + return False; + + rdata = (IncrConversion *) list->data; + + data = rdata->data->data + rdata->offset; + length = rdata->data->length - rdata->offset; + if (length > SELECTION_MAX_SIZE) + length = SELECTION_MAX_SIZE; + + rdata->offset += length; + + items = length / clipboard_bytes_per_item (rdata->data->format); + XChangeProperty (manager->priv->display, rdata->requestor, + rdata->property, rdata->data->type, + rdata->data->format, PropModeAppend, + data, items); + + if (length == 0) { + manager->priv->conversions = list_remove (manager->priv->conversions, rdata); + conversion_free (rdata); + } + + return True; +} + +static void +convert_clipboard_manager (MsdClipboardManager *manager, + XEvent *xev) +{ + Atom type = None; + int format; + unsigned long nitems; + unsigned long remaining; + Atom *targets = NULL; + + if (xev->xselectionrequest.target == XA_SAVE_TARGETS) { + if (manager->priv->requestor != None || manager->priv->contents != NULL) { + /* We're in the middle of a conversion request, or own + * the CLIPBOARD already + */ + finish_selection_request (manager, xev, False); + } else { + gdk_error_trap_push (); + + clipboard_manager_watch_cb (manager, + xev->xselectionrequest.requestor, + True, + StructureNotifyMask, + NULL); + XSelectInput (manager->priv->display, + xev->xselectionrequest.requestor, + StructureNotifyMask); + XSync (manager->priv->display, False); + + if (gdk_error_trap_pop () != Success) + return; + + gdk_error_trap_push (); + + if (xev->xselectionrequest.property != None) { + XGetWindowProperty (manager->priv->display, + xev->xselectionrequest.requestor, + xev->xselectionrequest.property, + 0, 0x1FFFFFFF, False, XA_ATOM, + &type, &format, &nitems, &remaining, + (unsigned char **) &targets); + + if (gdk_error_trap_pop () != Success) { + if (targets) + XFree (targets); + + return; + } + } + + manager->priv->requestor = xev->xselectionrequest.requestor; + manager->priv->property = xev->xselectionrequest.property; + manager->priv->time = xev->xselectionrequest.time; + + if (type == None) + XConvertSelection (manager->priv->display, XA_CLIPBOARD, + XA_TARGETS, XA_TARGETS, + manager->priv->window, manager->priv->time); + else + save_targets (manager, targets, nitems); + } + } else if (xev->xselectionrequest.target == XA_TIMESTAMP) { + XChangeProperty (manager->priv->display, + xev->xselectionrequest.requestor, + xev->xselectionrequest.property, + XA_INTEGER, 32, PropModeReplace, + (unsigned char *) &manager->priv->timestamp, 1); + + finish_selection_request (manager, xev, True); + } else if (xev->xselectionrequest.target == XA_TARGETS) { + int n_targets = 0; + Atom targets[3]; + + targets[n_targets++] = XA_TARGETS; + targets[n_targets++] = XA_TIMESTAMP; + targets[n_targets++] = XA_SAVE_TARGETS; + + XChangeProperty (manager->priv->display, + xev->xselectionrequest.requestor, + xev->xselectionrequest.property, + XA_ATOM, 32, PropModeReplace, + (unsigned char *) targets, n_targets); + + finish_selection_request (manager, xev, True); + } else + finish_selection_request (manager, xev, False); +} + +static void +convert_clipboard_target (IncrConversion *rdata, + MsdClipboardManager *manager) +{ + TargetData *tdata; + Atom *targets; + int n_targets; + List *list; + unsigned long items; + XWindowAttributes atts; + + if (rdata->target == XA_TARGETS) { + n_targets = list_length (manager->priv->contents) + 2; + targets = (Atom *) malloc (n_targets * sizeof (Atom)); + + n_targets = 0; + + targets[n_targets++] = XA_TARGETS; + targets[n_targets++] = XA_MULTIPLE; + + for (list = manager->priv->contents; list; list = list->next) { + tdata = (TargetData *) list->data; + targets[n_targets++] = tdata->target; + } + + XChangeProperty (manager->priv->display, rdata->requestor, + rdata->property, + XA_ATOM, 32, PropModeReplace, + (unsigned char *) targets, n_targets); + free (targets); + } else { + /* Convert from stored CLIPBOARD data */ + list = list_find (manager->priv->contents, + (ListFindFunc) find_content_target, (void *) rdata->target); + + /* We got a target that we don't support */ + if (!list) + return; + + tdata = (TargetData *)list->data; + if (tdata->type == XA_INCR) { + /* we haven't completely received this target yet */ + rdata->property = None; + return; + } + + rdata->data = target_data_ref (tdata); + items = tdata->length / clipboard_bytes_per_item (tdata->format); + if (tdata->length <= SELECTION_MAX_SIZE) + XChangeProperty (manager->priv->display, rdata->requestor, + rdata->property, + tdata->type, tdata->format, PropModeReplace, + tdata->data, items); + else { + /* start incremental transfer */ + rdata->offset = 0; + + gdk_error_trap_push (); + + XGetWindowAttributes (manager->priv->display, rdata->requestor, &atts); + XSelectInput (manager->priv->display, rdata->requestor, + atts.your_event_mask | PropertyChangeMask); + + XChangeProperty (manager->priv->display, rdata->requestor, + rdata->property, + XA_INCR, 32, PropModeReplace, + (unsigned char *) &items, 1); + + XSync (manager->priv->display, False); + + gdk_error_trap_pop (); + } + } +} + +static void +collect_incremental (IncrConversion *rdata, + MsdClipboardManager *manager) +{ + if (rdata->offset >= 0) + manager->priv->conversions = list_prepend (manager->priv->conversions, rdata); + else { + if (rdata->data) { + target_data_unref (rdata->data); + rdata->data = NULL; + } + free (rdata); + } +} + +static void +convert_clipboard (MsdClipboardManager *manager, + XEvent *xev) +{ + List *list; + List *conversions; + IncrConversion *rdata; + Atom type; + int i; + int format; + unsigned long nitems; + unsigned long remaining; + Atom *multiple; + + conversions = NULL; + type = None; + + if (xev->xselectionrequest.target == XA_MULTIPLE) { + XGetWindowProperty (xev->xselectionrequest.display, + xev->xselectionrequest.requestor, + xev->xselectionrequest.property, + 0, 0x1FFFFFFF, False, XA_ATOM_PAIR, + &type, &format, &nitems, &remaining, + (unsigned char **) &multiple); + + if (type != XA_ATOM_PAIR || nitems == 0) { + if (multiple) + free (multiple); + return; + } + + for (i = 0; i < nitems; i += 2) { + rdata = (IncrConversion *) malloc (sizeof (IncrConversion)); + rdata->requestor = xev->xselectionrequest.requestor; + rdata->target = multiple[i]; + rdata->property = multiple[i+1]; + rdata->data = NULL; + rdata->offset = -1; + conversions = list_prepend (conversions, rdata); + } + } else { + multiple = NULL; + + rdata = (IncrConversion *) malloc (sizeof (IncrConversion)); + rdata->requestor = xev->xselectionrequest.requestor; + rdata->target = xev->xselectionrequest.target; + rdata->property = xev->xselectionrequest.property; + rdata->data = NULL; + rdata->offset = -1; + conversions = list_prepend (conversions, rdata); + } + + list_foreach (conversions, (Callback) convert_clipboard_target, manager); + + if (conversions->next == NULL && + ((IncrConversion *) conversions->data)->property == None) { + finish_selection_request (manager, xev, False); + } else { + if (multiple) { + i = 0; + for (list = conversions; list; list = list->next) { + rdata = (IncrConversion *)list->data; + multiple[i++] = rdata->target; + multiple[i++] = rdata->property; + } + XChangeProperty (xev->xselectionrequest.display, + xev->xselectionrequest.requestor, + xev->xselectionrequest.property, + XA_ATOM_PAIR, 32, PropModeReplace, + (unsigned char *) multiple, nitems); + } + finish_selection_request (manager, xev, True); + } + + list_foreach (conversions, (Callback) collect_incremental, manager); + list_free (conversions); + + if (multiple) + free (multiple); +} + +static Bool +clipboard_manager_process_event (MsdClipboardManager *manager, + XEvent *xev) +{ + Atom type; + int format; + unsigned long nitems; + unsigned long remaining; + Atom *targets; + + targets = NULL; + + switch (xev->xany.type) { + case DestroyNotify: + if (xev->xdestroywindow.window == manager->priv->requestor) { + list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); + list_free (manager->priv->contents); + manager->priv->contents = NULL; + + clipboard_manager_watch_cb (manager, + manager->priv->requestor, + False, + 0, + NULL); + manager->priv->requestor = None; + } + break; + case PropertyNotify: + if (xev->xproperty.state == PropertyNewValue) { + return receive_incrementally (manager, xev); + } else { + return send_incrementally (manager, xev); + } + + case SelectionClear: + if (xev->xany.window != manager->priv->window) + return False; + + if (xev->xselectionclear.selection == XA_CLIPBOARD_MANAGER) { + /* We lost the manager selection */ + if (manager->priv->contents) { + list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); + list_free (manager->priv->contents); + manager->priv->contents = NULL; + + XSetSelectionOwner (manager->priv->display, + XA_CLIPBOARD, + None, manager->priv->time); + } + + return True; + } + if (xev->xselectionclear.selection == XA_CLIPBOARD) { + /* We lost the clipboard selection */ + list_foreach (manager->priv->contents, (Callback)target_data_unref, NULL); + list_free (manager->priv->contents); + manager->priv->contents = NULL; + clipboard_manager_watch_cb (manager, + manager->priv->requestor, + False, + 0, + NULL); + manager->priv->requestor = None; + + return True; + } + break; + + case SelectionNotify: + if (xev->xany.window != manager->priv->window) + return False; + + if (xev->xselection.selection == XA_CLIPBOARD) { + /* a CLIPBOARD conversion is done */ + if (xev->xselection.property == XA_TARGETS) { + XGetWindowProperty (xev->xselection.display, + xev->xselection.requestor, + xev->xselection.property, + 0, 0x1FFFFFFF, True, XA_ATOM, + &type, &format, &nitems, &remaining, + (unsigned char **) &targets); + + save_targets (manager, targets, nitems); + } else if (xev->xselection.property == XA_MULTIPLE) { + List *tmp; + + tmp = list_copy (manager->priv->contents); + list_foreach (tmp, (Callback) get_property, manager); + list_free (tmp); + + manager->priv->time = xev->xselection.time; + XSetSelectionOwner (manager->priv->display, XA_CLIPBOARD, + manager->priv->window, manager->priv->time); + + if (manager->priv->property != None) + XChangeProperty (manager->priv->display, + manager->priv->requestor, + manager->priv->property, + XA_ATOM, 32, PropModeReplace, + (unsigned char *)&XA_NULL, 1); + + if (!list_find (manager->priv->contents, + (ListFindFunc)find_content_type, (void *)XA_INCR)) { + /* all transfers done */ + send_selection_notify (manager, True); + clipboard_manager_watch_cb (manager, + manager->priv->requestor, + False, + 0, + NULL); + manager->priv->requestor = None; + } + } + else if (xev->xselection.property == None) { + send_selection_notify (manager, False); + clipboard_manager_watch_cb (manager, + manager->priv->requestor, + False, + 0, + NULL); + manager->priv->requestor = None; + } + + return True; + } + break; + + case SelectionRequest: + if (xev->xany.window != manager->priv->window) { + return False; + } + + if (xev->xselectionrequest.selection == XA_CLIPBOARD_MANAGER) { + convert_clipboard_manager (manager, xev); + return True; + } else if (xev->xselectionrequest.selection == XA_CLIPBOARD) { + convert_clipboard (manager, xev); + return True; + } + break; + + default: ; + } + + return False; +} + +static GdkFilterReturn +clipboard_manager_event_filter (GdkXEvent *xevent, + GdkEvent *event, + MsdClipboardManager *manager) +{ + if (clipboard_manager_process_event (manager, (XEvent *)xevent)) { + return GDK_FILTER_REMOVE; + } else { + return GDK_FILTER_CONTINUE; + } +} + +static void +clipboard_manager_watch_cb (MsdClipboardManager *manager, + Window window, + Bool is_start, + long mask, + void *cb_data) +{ + GdkWindow *gdkwin; + GdkDisplay *display; + + display = gdk_display_get_default (); + gdkwin = gdk_window_lookup_for_display (display, window); + + if (is_start) { + if (gdkwin == NULL) { + gdkwin = gdk_window_foreign_new_for_display (display, window); + } else { + g_object_ref (gdkwin); + } + + gdk_window_add_filter (gdkwin, + (GdkFilterFunc)clipboard_manager_event_filter, + manager); + } else { + if (gdkwin == NULL) { + return; + } + gdk_window_remove_filter (gdkwin, + (GdkFilterFunc)clipboard_manager_event_filter, + manager); + g_object_unref (gdkwin); + } +} + +static gboolean +start_clipboard_idle_cb (MsdClipboardManager *manager) +{ + XClientMessageEvent xev; + + + mate_settings_profile_start (NULL); + + init_atoms (manager->priv->display); + + /* check if there is a clipboard manager running */ + if (XGetSelectionOwner (manager->priv->display, XA_CLIPBOARD_MANAGER)) { + g_warning ("Clipboard manager is already running."); + return FALSE; + } + + manager->priv->contents = NULL; + manager->priv->conversions = NULL; + manager->priv->requestor = None; + + manager->priv->window = XCreateSimpleWindow (manager->priv->display, + DefaultRootWindow (manager->priv->display), + 0, 0, 10, 10, 0, + WhitePixel (manager->priv->display, + DefaultScreen (manager->priv->display)), + WhitePixel (manager->priv->display, + DefaultScreen (manager->priv->display))); + clipboard_manager_watch_cb (manager, + manager->priv->window, + True, + PropertyChangeMask, + NULL); + XSelectInput (manager->priv->display, + manager->priv->window, + PropertyChangeMask); + manager->priv->timestamp = get_server_time (manager->priv->display, manager->priv->window); + + XSetSelectionOwner (manager->priv->display, + XA_CLIPBOARD_MANAGER, + manager->priv->window, + manager->priv->timestamp); + + /* Check to see if we managed to claim the selection. If not, + * we treat it as if we got it then immediately lost it + */ + if (XGetSelectionOwner (manager->priv->display, XA_CLIPBOARD_MANAGER) == manager->priv->window) { + xev.type = ClientMessage; + xev.window = DefaultRootWindow (manager->priv->display); + xev.message_type = XA_MANAGER; + xev.format = 32; + xev.data.l[0] = manager->priv->timestamp; + xev.data.l[1] = XA_CLIPBOARD_MANAGER; + xev.data.l[2] = manager->priv->window; + xev.data.l[3] = 0; /* manager specific data */ + xev.data.l[4] = 0; /* manager specific data */ + + XSendEvent (manager->priv->display, + DefaultRootWindow (manager->priv->display), + False, + StructureNotifyMask, + (XEvent *)&xev); + } else { + clipboard_manager_watch_cb (manager, + manager->priv->window, + False, + 0, + NULL); + /* FIXME: manager->priv->terminate (manager->priv->cb_data); */ + } + + mate_settings_profile_end (NULL); + + return FALSE; +} + +gboolean +msd_clipboard_manager_start (MsdClipboardManager *manager, + GError **error) +{ + mate_settings_profile_start (NULL); + + g_idle_add ((GSourceFunc) start_clipboard_idle_cb, manager); + + mate_settings_profile_end (NULL); + + return TRUE; +} + +void +msd_clipboard_manager_stop (MsdClipboardManager *manager) +{ + g_debug ("Stopping clipboard manager"); + + clipboard_manager_watch_cb (manager, + manager->priv->window, + FALSE, + 0, + NULL); + XDestroyWindow (manager->priv->display, manager->priv->window); + + list_foreach (manager->priv->conversions, (Callback) conversion_free, NULL); + list_free (manager->priv->conversions); + + list_foreach (manager->priv->contents, (Callback) target_data_unref, NULL); + list_free (manager->priv->contents); +} + +static void +msd_clipboard_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MsdClipboardManager *self; + + self = MSD_CLIPBOARD_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +msd_clipboard_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MsdClipboardManager *self; + + self = MSD_CLIPBOARD_MANAGER (object); + + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GObject * +msd_clipboard_manager_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + MsdClipboardManager *clipboard_manager; + MsdClipboardManagerClass *klass; + + klass = MSD_CLIPBOARD_MANAGER_CLASS (g_type_class_peek (MSD_TYPE_CLIPBOARD_MANAGER)); + + clipboard_manager = MSD_CLIPBOARD_MANAGER (G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->constructor (type, + n_construct_properties, + construct_properties)); + + return G_OBJECT (clipboard_manager); +} + +static void +msd_clipboard_manager_dispose (GObject *object) +{ + MsdClipboardManager *clipboard_manager; + + clipboard_manager = MSD_CLIPBOARD_MANAGER (object); + + G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->dispose (object); +} + +static void +msd_clipboard_manager_class_init (MsdClipboardManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = msd_clipboard_manager_get_property; + object_class->set_property = msd_clipboard_manager_set_property; + object_class->constructor = msd_clipboard_manager_constructor; + object_class->dispose = msd_clipboard_manager_dispose; + object_class->finalize = msd_clipboard_manager_finalize; + + g_type_class_add_private (klass, sizeof (MsdClipboardManagerPrivate)); +} + +static void +msd_clipboard_manager_init (MsdClipboardManager *manager) +{ + manager->priv = MSD_CLIPBOARD_MANAGER_GET_PRIVATE (manager); + + manager->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + +} + +static void +msd_clipboard_manager_finalize (GObject *object) +{ + MsdClipboardManager *clipboard_manager; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_CLIPBOARD_MANAGER (object)); + + clipboard_manager = MSD_CLIPBOARD_MANAGER (object); + + g_return_if_fail (clipboard_manager->priv != NULL); + + G_OBJECT_CLASS (msd_clipboard_manager_parent_class)->finalize (object); +} + +MsdClipboardManager * +msd_clipboard_manager_new (void) +{ + if (manager_object != NULL) { + g_object_ref (manager_object); + } else { + manager_object = g_object_new (MSD_TYPE_CLIPBOARD_MANAGER, NULL); + g_object_add_weak_pointer (manager_object, + (gpointer *) &manager_object); + } + + return MSD_CLIPBOARD_MANAGER (manager_object); +} diff --git a/plugins/clipboard/msd-clipboard-manager.h b/plugins/clipboard/msd-clipboard-manager.h new file mode 100644 index 0000000..e4af711 --- /dev/null +++ b/plugins/clipboard/msd-clipboard-manager.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_CLIPBOARD_MANAGER_H +#define __MSD_CLIPBOARD_MANAGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_CLIPBOARD_MANAGER (msd_clipboard_manager_get_type ()) +#define MSD_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManager)) +#define MSD_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerClass)) +#define MSD_IS_CLIPBOARD_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_CLIPBOARD_MANAGER)) +#define MSD_IS_CLIPBOARD_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_CLIPBOARD_MANAGER)) +#define MSD_CLIPBOARD_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_CLIPBOARD_MANAGER, MsdClipboardManagerClass)) + +typedef struct MsdClipboardManagerPrivate MsdClipboardManagerPrivate; + +typedef struct +{ + GObject parent; + MsdClipboardManagerPrivate *priv; +} MsdClipboardManager; + +typedef struct +{ + GObjectClass parent_class; +} MsdClipboardManagerClass; + +GType msd_clipboard_manager_get_type (void); + +MsdClipboardManager * msd_clipboard_manager_new (void); +gboolean msd_clipboard_manager_start (MsdClipboardManager *manager, + GError **error); +void msd_clipboard_manager_stop (MsdClipboardManager *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_CLIPBOARD_MANAGER_H */ diff --git a/plugins/clipboard/msd-clipboard-plugin.c b/plugins/clipboard/msd-clipboard-plugin.c new file mode 100644 index 0000000..6674265 --- /dev/null +++ b/plugins/clipboard/msd-clipboard-plugin.c @@ -0,0 +1,104 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "config.h" + +#include +#include + +#include "mate-settings-plugin.h" +#include "msd-clipboard-plugin.h" +#include "msd-clipboard-manager.h" + +struct MsdClipboardPluginPrivate { + MsdClipboardManager *manager; +}; + +#define MSD_CLIPBOARD_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginPrivate)) + +MATE_SETTINGS_PLUGIN_REGISTER (MsdClipboardPlugin, msd_clipboard_plugin) + +static void +msd_clipboard_plugin_init (MsdClipboardPlugin *plugin) +{ + plugin->priv = MSD_CLIPBOARD_PLUGIN_GET_PRIVATE (plugin); + + g_debug ("MsdClipboardPlugin initializing"); + + plugin->priv->manager = msd_clipboard_manager_new (); +} + +static void +msd_clipboard_plugin_finalize (GObject *object) +{ + MsdClipboardPlugin *plugin; + + g_return_if_fail (object != NULL); + g_return_if_fail (MSD_IS_CLIPBOARD_PLUGIN (object)); + + g_debug ("MsdClipboardPlugin finalizing"); + + plugin = MSD_CLIPBOARD_PLUGIN (object); + + g_return_if_fail (plugin->priv != NULL); + + if (plugin->priv->manager != NULL) { + g_object_unref (plugin->priv->manager); + } + + G_OBJECT_CLASS (msd_clipboard_plugin_parent_class)->finalize (object); +} + +static void +impl_activate (MateSettingsPlugin *plugin) +{ + gboolean res; + GError *error; + + g_debug ("Activating clipboard plugin"); + + error = NULL; + res = msd_clipboard_manager_start (MSD_CLIPBOARD_PLUGIN (plugin)->priv->manager, &error); + if (! res) { + g_warning ("Unable to start clipboard manager: %s", error->message); + g_error_free (error); + } +} + +static void +impl_deactivate (MateSettingsPlugin *plugin) +{ + g_debug ("Deactivating clipboard plugin"); + msd_clipboard_manager_stop (MSD_CLIPBOARD_PLUGIN (plugin)->priv->manager); +} + +static void +msd_clipboard_plugin_class_init (MsdClipboardPluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + MateSettingsPluginClass *plugin_class = MATE_SETTINGS_PLUGIN_CLASS (klass); + + object_class->finalize = msd_clipboard_plugin_finalize; + + plugin_class->activate = impl_activate; + plugin_class->deactivate = impl_deactivate; + + g_type_class_add_private (klass, sizeof (MsdClipboardPluginPrivate)); +} diff --git a/plugins/clipboard/msd-clipboard-plugin.h b/plugins/clipboard/msd-clipboard-plugin.h new file mode 100644 index 0000000..7b2ea1e --- /dev/null +++ b/plugins/clipboard/msd-clipboard-plugin.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2007 William Jon McCann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef __MSD_CLIPBOARD_PLUGIN_H__ +#define __MSD_CLIPBOARD_PLUGIN_H__ + +#include +#include +#include + +#include "mate-settings-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MSD_TYPE_CLIPBOARD_PLUGIN (msd_clipboard_plugin_get_type ()) +#define MSD_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPlugin)) +#define MSD_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginClass)) +#define MSD_IS_CLIPBOARD_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MSD_TYPE_CLIPBOARD_PLUGIN)) +#define MSD_IS_CLIPBOARD_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MSD_TYPE_CLIPBOARD_PLUGIN)) +#define MSD_CLIPBOARD_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MSD_TYPE_CLIPBOARD_PLUGIN, MsdClipboardPluginClass)) + +typedef struct MsdClipboardPluginPrivate MsdClipboardPluginPrivate; + +typedef struct +{ + MateSettingsPlugin parent; + MsdClipboardPluginPrivate *priv; +} MsdClipboardPlugin; + +typedef struct +{ + MateSettingsPluginClass parent_class; +} MsdClipboardPluginClass; + +GType msd_clipboard_plugin_get_type (void) G_GNUC_CONST; + +/* All the plugins must implement this function */ +G_MODULE_EXPORT GType register_mate_settings_plugin (GTypeModule *module); + +#ifdef __cplusplus +} +#endif + +#endif /* __MSD_CLIPBOARD_PLUGIN_H__ */ -- cgit v1.2.1