[Xfce4-commits] <xfce4-clipman-plugin:master> [daemon] Rewrite the daemon using GTK+ functions
Mike Massonnet
noreply at xfce.org
Sun Nov 15 16:04:04 CET 2009
Updating branch refs/heads/master
to 7e931afafcec46b4ded033f609dfd53b44337168 (commit)
from 64d4ec055e60575506a95119daeed144a4b1a3ac (commit)
commit 7e931afafcec46b4ded033f609dfd53b44337168
Author: Mike Massonnet <mmassonnet at xfce.org>
Date: Sun Nov 15 17:02:22 2009 +0100
[daemon] Rewrite the daemon using GTK+ functions
The gsd-clipboard-manager has been rewritten using GTK+ functions. The
X11 manager showed bugs with text selections and images not converted
correctly. Also this new manager takes care about the primary clipboard.
ChangeLog | 16 +
daemon/Makefile.am | 2 -
daemon/gsd-clipboard-manager.c | 963 +++++++---------------------------------
daemon/list.c | 150 -------
daemon/list.h | 57 ---
daemon/xutils.c | 117 -----
daemon/xutils.h | 50 --
7 files changed, 178 insertions(+), 1177 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 00f5597..9ec9a17 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2009-11-15 Mike Massonnet
+[daemon] Rewrite the daemon using GTK+ functions
+
+ The gsd-clipboard-manager has been rewritten using GTK+ functions. The
+ X11 manager showed bugs with text selections and images not converted
+ correctly. Also this new manager takes care about the primary clipboard.
+
+2009-11-15 Mike Massonnet
+[tests/test-targets] Print format/length of targets
+
+2009-11-07 Mike Massonnet
+[tests] Add daemon test program
+
+ New test program for the daemon. The targets test program has a command
+ line flag to switch between the selections and the default clipboard.
+
2009-10-31 Mike Massonnet
Fix popup from keyboard shortcut not always working #bug 5909
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index ecbd1a5..2d1a10a 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -10,8 +10,6 @@ noinst_LTLIBRARIES = libdaemon.la
libdaemon_la_SOURCES = \
daemon.h \
gsd-clipboard-manager.c gsd-clipboard-manager.h \
- list.c list.h \
- xutils.c xutils.h \
$(NULL)
libdaemon_la_CFLAGS = \
diff --git a/daemon/gsd-clipboard-manager.c b/daemon/gsd-clipboard-manager.c
index 565a95b..20a6e8f 100644
--- a/daemon/gsd-clipboard-manager.c
+++ b/daemon/gsd-clipboard-manager.c
@@ -4,6 +4,7 @@
* Copyright (C) 2007 Anders Carlsson
* Copyright (C) 2007 Rodrigo Moya
* Copyright (C) 2007 William Jon McCann <mccann at jhu.edu>
+ * Copyright (C) 2009 Mike Massonnet <mmassonnet at xfce.org>
*
* 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
@@ -18,898 +19,253 @@
* 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 <sys/types.h>
-#include <sys/wait.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-#include <locale.h>
-
#include <glib.h>
-#include <glib/gi18n.h>
-#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
-#include "xutils.h"
-#include "list.h"
-
#include "gsd-clipboard-manager.h"
#define GSD_CLIPBOARD_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_CLIPBOARD_MANAGER, GsdClipboardManagerPrivate))
struct GsdClipboardManagerPrivate
{
- Display *display;
- Window window;
- Time timestamp;
+ GtkClipboard *default_clipboard;
+ GtkClipboard *primary_clipboard;
- List *contents;
- List *conversions;
+ GSList *default_cache;
+ gchar *primary_cache;
- Window requestor;
- Atom property;
- Time time;
-};
+ gboolean internal_change;
-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;
+ GtkWidget *window;
+};
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 clipboard_manager_watch_cb (GsdClipboardManager *manager,
- Window window,
- Bool is_start,
- long mask,
- void *cb_data);
-
G_DEFINE_TYPE (GsdClipboardManager, gsd_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 (GsdClipboardManager *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 ();
-}
+Atom XA_CLIPBOARD_MANAGER;
+Atom XA_MANAGER;
static void
-finish_selection_request (GsdClipboardManager *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)
+init_atoms (Display *display)
{
- switch (format) {
- case 8: return sizeof (char);
- case 16: return sizeof (short);
- case 32: return sizeof (long);
- default: ;
- }
-
- return 0;
-}
+ static int _init_atoms = 0;
-static void
-save_targets (GsdClipboardManager *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];
- }
+ if (_init_atoms > 0) {
+ return;
}
- 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;
-}
+ XA_CLIPBOARD_MANAGER = XInternAtom (display, "CLIPBOARD_MANAGER", False);
+ XA_MANAGER = XInternAtom (display, "MANAGER", False);
-static int
-find_content_type (TargetData *tdata,
- Atom type)
-{
- return tdata->type == type;
+ _init_atoms = 1;
}
-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,
- GsdClipboardManager *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 (GsdClipboardManager *manager,
- XEvent *xev)
+default_clipboard_store (GsdClipboardManager *manager)
{
- 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;
- }
+ GtkSelectionData *selection_data;
+ GdkAtom *atoms;
+ gint n_atoms;
+ gint i;
- 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);
- }
+ if (!gtk_clipboard_wait_for_targets (manager->priv->default_clipboard, &atoms, &n_atoms)) {
+ return;
}
- return True;
-}
-
-static Bool
-send_incrementally (GsdClipboardManager *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);
+ if (manager->priv->default_cache != NULL) {
+ g_slist_foreach (manager->priv->default_cache, (GFunc)gtk_selection_data_free, NULL);
+ g_slist_free (manager->priv->default_cache);
+ manager->priv->default_cache = NULL;
}
- return True;
-}
-
-static void
-convert_clipboard_manager (GsdClipboardManager *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,
- GsdClipboardManager *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;
+ for (i = 0; i < n_atoms; i++) {
+ if (atoms[i] == gdk_atom_intern_static_string ("TARGETS")
+ || atoms[i] == gdk_atom_intern_static_string ("MULTIPLE")
+ || atoms[i] == gdk_atom_intern_static_string ("DELETE")
+ || atoms[i] == gdk_atom_intern_static_string ("INSERT_PROPERTY")
+ || atoms[i] == gdk_atom_intern_static_string ("INSERT_SELECTION")
+ || atoms[i] == gdk_atom_intern_static_string ("PIXMAP")) {
+ continue;
}
- 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;
+ selection_data = gtk_clipboard_wait_for_contents (manager->priv->default_clipboard, atoms[i]);
+ if (selection_data == NULL) {
+ continue;
}
- 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 ();
- }
+ manager->priv->default_cache = g_slist_prepend (manager->priv->default_cache, selection_data);
}
}
static void
-collect_incremental (IncrConversion *rdata,
- GsdClipboardManager *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;
+default_clipboard_get_func (GtkClipboard *clipboard,
+ GtkSelectionData *selection_data,
+ guint info,
+ GsdClipboardManager *manager)
+{
+ GSList *list;
+ GtkSelectionData *selection_data_cache = NULL;
+
+ list = manager->priv->default_cache;
+ for (; list->next != NULL; list = list->next) {
+ selection_data_cache = list->data;
+ if (selection_data->target == selection_data_cache->target) {
+ break;
}
- free (rdata);
+ selection_data_cache = NULL;
}
+ if (selection_data_cache == NULL) {
+ return;
+ }
+ gtk_selection_data_set (selection_data, selection_data->target,
+ selection_data_cache->format,
+ selection_data_cache->data,
+ selection_data_cache->length);
}
static void
-convert_clipboard (GsdClipboardManager *manager,
- XEvent *xev)
+default_clipboard_clear_func (GtkClipboard *clipboard,
+ GsdClipboardManager *manager)
{
- 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)
- 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);
- }
+ return;
+}
- 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);
+static void
+default_clipboard_restore (GsdClipboardManager *manager)
+{
+ GtkTargetList *target_list;
+ GtkTargetEntry *targets;
+ gint n_targets;
+ GtkSelectionData *sdata;
+ GSList *list;
+
+ target_list = gtk_target_list_new (NULL, 0);
+ list = manager->priv->default_cache;
+ for (; list->next != NULL; list = list->next) {
+ sdata = list->data;
+ gtk_target_list_add (target_list, sdata->target, 0, 0);
}
+ targets = gtk_target_table_new_from_list (target_list, &n_targets);
- list_foreach (conversions, (Callback) collect_incremental, manager);
- list_free (conversions);
-
- if (multiple)
- free (multiple);
+ gtk_clipboard_set_with_data (manager->priv->default_clipboard,
+ targets, n_targets,
+ (GtkClipboardGetFunc)default_clipboard_get_func,
+ (GtkClipboardClearFunc)default_clipboard_clear_func,
+ manager);
}
-static Bool
-clipboard_manager_process_event (GsdClipboardManager *manager,
- XEvent *xev)
+static void
+default_clipboard_owner_change (GsdClipboardManager *manager,
+ GdkEventOwnerChange *event)
{
- 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 (event->send_event == TRUE) {
+ return;
+ }
- 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;
+ if (event->owner != 0) {
+ if (manager->priv->internal_change) {
+ manager->priv->internal_change = FALSE;
+ return;
}
- break;
-
- default: ;
+ default_clipboard_store (manager);
}
-
- return False;
-}
-
-static GdkFilterReturn
-clipboard_manager_event_filter (GdkXEvent *xevent,
- GdkEvent *event,
- GsdClipboardManager *manager)
-{
- if (clipboard_manager_process_event (manager, (XEvent *)xevent)) {
- return GDK_FILTER_REMOVE;
- } else {
- return GDK_FILTER_CONTINUE;
+ else {
+ manager->priv->internal_change = TRUE;
+ default_clipboard_restore (manager);
}
}
static void
-clipboard_manager_watch_cb (GsdClipboardManager *manager,
- Window window,
- Bool is_start,
- long mask,
- void *cb_data)
+primary_clipboard_owner_change (GsdClipboardManager *manager,
+ GdkEventOwnerChange *event)
{
- GdkWindow *gdkwin;
- GdkDisplay *display;
+ gchar *text;
- display = gdk_display_get_default ();
- gdkwin = gdk_window_lookup_for_display (display, window);
+ if (event->send_event == TRUE) {
+ return;
+ }
- if (is_start) {
- if (gdkwin == NULL) {
- gdkwin = gdk_window_foreign_new_for_display (display, window);
- } else {
- g_object_ref (gdkwin);
+ if (event->owner != 0) {
+ text = gtk_clipboard_wait_for_text (manager->priv->primary_clipboard);
+ if (text != NULL) {
+ g_free (manager->priv->primary_cache);
+ manager->priv->primary_cache = text;
}
-
- gdk_window_add_filter (gdkwin,
- (GdkFilterFunc)clipboard_manager_event_filter,
- manager);
- } else {
- if (gdkwin == NULL) {
- return;
+ }
+ else {
+ if (manager->priv->primary_cache != NULL) {
+ gtk_clipboard_set_text (manager->priv->primary_clipboard,
+ manager->priv->primary_cache,
+ -1);
}
- gdk_window_remove_filter (gdkwin,
- (GdkFilterFunc)clipboard_manager_event_filter,
- manager);
- g_object_unref (gdkwin);
}
}
static gboolean
start_clipboard_idle_cb (GsdClipboardManager *manager)
{
- XClientMessageEvent xev;
-
+ XClientMessageEvent xev;
+ gboolean ownership;
+ Display *display;
+ Window window;
+ Time timestamp;
- init_atoms (manager->priv->display);
+ display = GDK_DISPLAY ();
+ init_atoms (display);
- /* check if there is a clipboard manager running */
- if (XGetSelectionOwner (manager->priv->display, XA_CLIPBOARD_MANAGER)) {
+ /* Check if there is a clipboard manager running */
+ if (gdk_display_supports_clipboard_persistence (gdk_display_get_default ())) {
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);
+ manager->priv->window = gtk_invisible_new ();
+ gtk_widget_realize (manager->priv->window);
+
+ window = GDK_WINDOW_XID (manager->priv->window->window);
+ timestamp = GDK_CURRENT_TIME;
+
+ XSelectInput (display, window, PropertyChangeMask);
+ XSetSelectionOwner (display, XA_CLIPBOARD_MANAGER, window, timestamp);
+
+ g_signal_connect_swapped (manager->priv->default_clipboard, "owner-change",
+ G_CALLBACK (default_clipboard_owner_change), manager);
+ g_signal_connect_swapped (manager->priv->primary_clipboard, "owner-change",
+ G_CALLBACK (primary_clipboard_owner_change), manager);
/* 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) {
+ if (XGetSelectionOwner (display, XA_CLIPBOARD_MANAGER) == window) {
xev.type = ClientMessage;
- xev.window = DefaultRootWindow (manager->priv->display);
+ xev.window = DefaultRootWindow (display);
xev.message_type = XA_MANAGER;
xev.format = 32;
- xev.data.l[0] = manager->priv->timestamp;
+ xev.data.l[0] = timestamp;
xev.data.l[1] = XA_CLIPBOARD_MANAGER;
- xev.data.l[2] = manager->priv->window;
+ xev.data.l[2] = 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);
+ XSendEvent (display, DefaultRootWindow (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); */
+ gsd_clipboard_manager_stop (manager);
}
return FALSE;
@@ -928,18 +284,20 @@ gsd_clipboard_manager_stop (GsdClipboardManager *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);
+ g_signal_handlers_disconnect_by_func (manager->priv->default_clipboard,
+ default_clipboard_owner_change, manager);
+ g_signal_handlers_disconnect_by_func (manager->priv->primary_clipboard,
+ primary_clipboard_owner_change, manager);
+ gtk_widget_destroy (manager->priv->window);
- list_foreach (manager->priv->contents, (Callback) target_data_unref, NULL);
- list_free (manager->priv->contents);
+ if (manager->priv->default_cache != NULL) {
+ g_slist_foreach (manager->priv->default_cache, (GFunc)gtk_selection_data_free, NULL);
+ g_slist_free (manager->priv->default_cache);
+ manager->priv->default_cache = NULL;
+ }
+ if (manager->priv->primary_cache != NULL) {
+ g_free (manager->priv->primary_cache);
+ }
}
static void
@@ -1022,8 +380,11 @@ gsd_clipboard_manager_init (GsdClipboardManager *manager)
{
manager->priv = GSD_CLIPBOARD_MANAGER_GET_PRIVATE (manager);
- manager->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+ manager->priv->default_clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+ manager->priv->primary_clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
+ manager->priv->default_cache = NULL;
+ manager->priv->primary_cache = NULL;
}
static void
diff --git a/daemon/list.c b/daemon/list.c
deleted file mode 100644
index 477eead..0000000
--- a/daemon/list.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright © 2004 Red Hat, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Red Hat not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. Red Hat makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
- * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Matthias Clasen, Red Hat, Inc.
- */
-
-#include <stdlib.h>
-#include <list.h>
-
-
-void
-list_foreach (List *list,
- Callback func,
- void *user_data)
-{
- while (list)
- {
- func (list->data, user_data);
-
- list = list->next;
- }
-}
-
-List *
-list_prepend (List *list,
- void *data)
-{
- List *link;
-
- link = (List *) malloc (sizeof (List));
- link->next = list;
- link->data = data;
-
- return link;
-}
-
-void
-list_free (List *list)
-{
- while (list)
- {
- List *next = list->next;
-
- free (list);
-
- list = next;
- }
-}
-
-List *
-list_find (List *list,
- ListFindFunc func,
- void *user_data)
-{
- List *tmp;
-
- for (tmp = list; tmp; tmp = tmp->next)
- {
- if ((*func) (tmp->data, user_data))
- break;
- }
-
- return tmp;
-}
-
-List *
-list_remove (List *list,
- void *data)
-{
- List *tmp, *prev;
-
- prev = NULL;
- for (tmp = list; tmp; tmp = tmp->next)
- {
- if (tmp->data == data)
- {
- if (prev)
- prev->next = tmp->next;
- else
- list = tmp->next;
-
- free (tmp);
- break;
- }
-
- prev = tmp;
- }
-
- return list;
-}
-
-int
-list_length (List *list)
-{
- List *tmp;
- int length;
-
- length = 0;
- for (tmp = list; tmp; tmp = tmp->next)
- length++;
-
- return length;
-}
-
-List *
-list_copy (List *list)
-{
- List *new_list = NULL;
-
- if (list)
- {
- List *last;
-
- new_list = (List *) malloc (sizeof (List));
- new_list->data = list->data;
- new_list->next = NULL;
-
- last = new_list;
- list = list->next;
-
- while (list)
- {
- last->next = (List *) malloc (sizeof (List));
- last = last->next;
- last->data = list->data;
- list = list->next;
- }
-
- last->next = NULL;
- }
-
- return new_list;
-}
diff --git a/daemon/list.h b/daemon/list.h
deleted file mode 100644
index 158b779..0000000
--- a/daemon/list.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright © 2004 Red Hat, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Red Hat not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. Red Hat makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
- * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Matthias Clasen, Red Hat, Inc.
- */
-#ifndef LIST_H
-#define LIST_H
-
-
-typedef struct _List List;
-typedef void (*Callback) (void *data,
- void *user_data);
-
-
-struct _List
-{
- void *data;
-
- List *next;
-};
-
-typedef int (*ListFindFunc) (void *data,
- void *user_data);
-
-void list_foreach (List *list,
- Callback func,
- void *user_data);
-List *list_prepend (List *list,
- void *data);
-void list_free (List *list);
-List *list_find (List *list,
- ListFindFunc func,
- void *user_data);
-List *list_remove (List *list,
- void *data);
-int list_length (List *list);
-
-List *list_copy (List *list);
-
-#endif /* LIST_H */
diff --git a/daemon/xutils.c b/daemon/xutils.c
deleted file mode 100644
index 4e48b98..0000000
--- a/daemon/xutils.c
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright © 2004 Red Hat, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Red Hat not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. Red Hat makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
- * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Matthias Clasen, Red Hat, Inc.
- */
-
-#include <stdlib.h>
-
-#include "xutils.h"
-
-Atom XA_ATOM_PAIR;
-Atom XA_CLIPBOARD_MANAGER;
-Atom XA_CLIPBOARD;
-Atom XA_DELETE;
-Atom XA_INCR;
-Atom XA_INSERT_PROPERTY;
-Atom XA_INSERT_SELECTION;
-Atom XA_MANAGER;
-Atom XA_MULTIPLE;
-Atom XA_NULL;
-Atom XA_SAVE_TARGETS;
-Atom XA_TARGETS;
-Atom XA_TIMESTAMP;
-
-unsigned long SELECTION_MAX_SIZE = 0;
-
-
-void
-init_atoms (Display *display)
-{
- unsigned long max_request_size;
-
- if (SELECTION_MAX_SIZE > 0)
- return;
-
- XA_ATOM_PAIR = XInternAtom (display, "ATOM_PAIR", False);
- XA_CLIPBOARD_MANAGER = XInternAtom (display, "CLIPBOARD_MANAGER", False);
- XA_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
- XA_DELETE = XInternAtom (display, "DELETE", False);
- XA_INCR = XInternAtom (display, "INCR", False);
- XA_INSERT_PROPERTY = XInternAtom (display, "INSERT_PROPERTY", False);
- XA_INSERT_SELECTION = XInternAtom (display, "INSERT_SELECTION", False);
- XA_MANAGER = XInternAtom (display, "MANAGER", False);
- XA_MULTIPLE = XInternAtom (display, "MULTIPLE", False);
- XA_NULL = XInternAtom (display, "NULL", False);
- XA_SAVE_TARGETS = XInternAtom (display, "SAVE_TARGETS", False);
- XA_TARGETS = XInternAtom (display, "TARGETS", False);
- XA_TIMESTAMP = XInternAtom (display, "TIMESTAMP", False);
-
- max_request_size = XExtendedMaxRequestSize (display);
- if (max_request_size == 0)
- max_request_size = XMaxRequestSize (display);
-
- SELECTION_MAX_SIZE = max_request_size - 100;
- if (SELECTION_MAX_SIZE > 262144)
- SELECTION_MAX_SIZE = 262144;
-}
-
-typedef struct
-{
- Window window;
- Atom timestamp_prop_atom;
-} TimeStampInfo;
-
-static Bool
-timestamp_predicate (Display *display,
- XEvent *xevent,
- XPointer arg)
-{
- TimeStampInfo *info = (TimeStampInfo *)arg;
-
- if (xevent->type == PropertyNotify &&
- xevent->xproperty.window == info->window &&
- xevent->xproperty.atom == info->timestamp_prop_atom)
- return True;
-
- return False;
-}
-
-Time
-get_server_time (Display *display,
- Window window)
-{
- unsigned char c = 'a';
- XEvent xevent;
- TimeStampInfo info;
-
- info.timestamp_prop_atom = XInternAtom (display, "_TIMESTAMP_PROP", False);
- info.window = window;
-
- XChangeProperty (display, window,
- info.timestamp_prop_atom, info.timestamp_prop_atom,
- 8, PropModeReplace, &c, 1);
-
- XIfEvent (display, &xevent,
- timestamp_predicate, (XPointer)&info);
-
- return xevent.xproperty.time;
-}
-
diff --git a/daemon/xutils.h b/daemon/xutils.h
deleted file mode 100644
index 143fe44..0000000
--- a/daemon/xutils.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright © 2004 Red Hat, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Red Hat not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. Red Hat makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
- * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Matthias Clasen, Red Hat, Inc.
- */
-#ifndef X_UTILS_H
-#define X_UTILS_H
-
-#include <X11/Xlib.h>
-
-
-extern Atom XA_ATOM_PAIR;
-extern Atom XA_CLIPBOARD_MANAGER;
-extern Atom XA_CLIPBOARD;
-extern Atom XA_DELETE;
-extern Atom XA_INCR;
-extern Atom XA_INSERT_PROPERTY;
-extern Atom XA_INSERT_SELECTION;
-extern Atom XA_MANAGER;
-extern Atom XA_MULTIPLE;
-extern Atom XA_NULL;
-extern Atom XA_SAVE_TARGETS;
-extern Atom XA_TARGETS;
-extern Atom XA_TIMESTAMP;
-
-extern unsigned long SELECTION_MAX_SIZE;
-
-void init_atoms (Display *display);
-
-Time get_server_time (Display *display,
- Window window);
-
-#endif /* X_UTILS_H */
More information about the Xfce4-commits
mailing list