[gnumeric] Clipboard: fix multihead issue.



commit d85eb8dcc2a31e8f5d5304545eb6090e49a3bfcb
Author: Morten Welinder <terra gnome org>
Date:   Fri Jan 4 18:16:18 2013 -0500

    Clipboard: fix multihead issue.

 ChangeLog           |    9 +++++++++
 NEWS                |    1 +
 src/application.c   |   12 +++---------
 src/gui-clipboard.c |   40 ++++++++++++++++++++++++++++++++++------
 src/gui-clipboard.h |    4 +++-
 src/wbc-gtk.c       |    4 +++-
 6 files changed, 53 insertions(+), 17 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b318df7..6c1d080 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2013-01-04  Morten Welinder  <terra gnome org>
+
+	* src/gui-clipboard.c (gnm_x_claim_clipboard): Take a GdkDisplay
+	as argument.  Keep track of displays.
+	(gnm_x_disown_clipboard): New function.
+
+	* src/application.c (gnm_app_clipboard_clear): Use
+	gnm_x_disown_clipboard to make things multi-head safe.
+
 2013-01-03  Morten Welinder  <terra gnome org>
 
 	* src/collect.c (collect_floats): Fix handling of
diff --git a/NEWS b/NEWS
index a78a8ab..a7ae8fe 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ Morten:
 	* Fix off-by-ones in sheet resize.  [#690929]
 	* Start working on warnings from newer gcc.
 	* Avoid using some deprecated symbols.
+	* Fix multihead issue with clipboard.
   
 --------------------------------------------------------------------------
 Gnumeric 1.12.0
diff --git a/src/application.c b/src/application.c
index 57c9f36..26d81f5 100644
--- a/src/application.c
+++ b/src/application.c
@@ -25,6 +25,7 @@
 #include "sheet-object.h"
 #include "pixmaps/gnumeric-stock-pixbufs.h"
 #include "commands.h"
+#include "gui-clipboard.h"
 
 #include <gnumeric-conf.h>
 #include <goffice/goffice.h>
@@ -177,15 +178,8 @@ gnm_app_clipboard_clear (gboolean drop_selection)
 		sv_weak_unref (&(app->clipboard_sheet_view));
 
 		/* Release the selection */
-		if (drop_selection) {
-#warning "FIXME: 1: this doesn't belong here.  2: it is not multihead safe."
-			gtk_selection_owner_set (NULL,
-						 GDK_SELECTION_PRIMARY,
-						 GDK_CURRENT_TIME);
-			gtk_selection_owner_set (NULL,
-						 GDK_SELECTION_CLIPBOARD,
-						 GDK_CURRENT_TIME);
-		}
+		if (drop_selection)
+			gnm_x_disown_clipboard ();
 	}
 }
 
diff --git a/src/gui-clipboard.c b/src/gui-clipboard.c
index f4dc794..6bb6a8e 100644
--- a/src/gui-clipboard.c
+++ b/src/gui-clipboard.c
@@ -47,6 +47,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#define APP_CLIP_DISP_KEY "clipboard-displays"
+
 static gboolean
 debug_clipboard (void)
 {
@@ -831,7 +833,7 @@ object_write (GnmCellRegion *cr, gchar const *mime_type, int *size)
  */
 static void
 x_clipboard_get_cb (GtkClipboard *gclipboard, GtkSelectionData *selection_data,
-		    guint info, GObject *obj)
+		    guint info, GObject *app)
 {
 	gboolean to_gnumeric = FALSE, content_needs_free = FALSE;
 	GnmCellRegion *clipboard = gnm_app_clipboard_contents_get ();
@@ -1061,14 +1063,14 @@ set_clipman_targets (GdkDisplay *disp, GtkTargetEntry *targets, guint n_targets)
 }
 
 gboolean
-gnm_x_claim_clipboard (WBCGtk *wbcg)
+gnm_x_claim_clipboard (GdkDisplay *display)
 {
-	GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET (wbcg_toplevel (wbcg)));
 	GnmCellRegion *content = gnm_app_clipboard_contents_get ();
 	SheetObject *imageable = NULL, *exportable = NULL;
 	GtkTargetEntry *targets = NULL;
 	int n_targets;
 	gboolean ret;
+	GObject *app = gnm_app_get_app ();
 
 	static GtkTargetEntry const table_targets[] = {
 		{ (char *) GNUMERIC_ATOM_NAME, 0, GNUMERIC_ATOM_INFO },
@@ -1117,18 +1119,25 @@ gnm_x_claim_clipboard (WBCGtk *wbcg)
 		targets, n_targets,
 		(GtkClipboardGetFunc) x_clipboard_get_cb,
 		(GtkClipboardClearFunc) x_clipboard_clear_cb,
-		gnm_app_get_app ());
+		app);
 	if (ret) {
 		if (debug_clipboard ())
 			g_printerr ("Clipboard successfully claimed.\n");
+
+		g_object_set_data_full (app, APP_CLIP_DISP_KEY,
+					g_slist_prepend (g_object_steal_data (app, APP_CLIP_DISP_KEY),
+							 display),
+					(GDestroyNotify)g_slist_free);
+
+
 		set_clipman_targets (display, targets, n_targets);
-		ret = gtk_clipboard_set_with_owner (
+		(void)gtk_clipboard_set_with_owner (
 			gtk_clipboard_get_for_display (display,
 						       GDK_SELECTION_PRIMARY),
 			targets, n_targets,
 			(GtkClipboardGetFunc) x_clipboard_get_cb,
 			NULL,
-			gnm_app_get_app ());
+			app);
 	} else {
 		if (debug_clipboard ())
 			g_printerr ("Failed to claim clipboard.\n");
@@ -1139,6 +1148,25 @@ gnm_x_claim_clipboard (WBCGtk *wbcg)
 	return ret;
 }
 
+void
+gnm_x_disown_clipboard (void)
+{
+	GObject *app = gnm_app_get_app ();
+	GSList *displays = g_object_steal_data (app, APP_CLIP_DISP_KEY);
+	GSList *l;
+
+	for (l = displays; l; l = l->next) {
+		GdkDisplay *display = l->data;
+		gtk_selection_owner_set_for_display (display, NULL,
+						     GDK_SELECTION_PRIMARY,
+						     GDK_CURRENT_TIME);
+		gtk_selection_owner_set_for_display (display, NULL,
+						     GDK_SELECTION_CLIPBOARD,
+						     GDK_CURRENT_TIME);
+	}
+	g_slist_free (displays);
+}
+
 /* Hand clipboard off to clipboard manager. To be called before workbook
  * object is destroyed.
  */
diff --git a/src/gui-clipboard.h b/src/gui-clipboard.h
index 7b253a2..85d4415 100644
--- a/src/gui-clipboard.h
+++ b/src/gui-clipboard.h
@@ -7,9 +7,11 @@
 G_BEGIN_DECLS
 
 void gnm_x_request_clipboard (WBCGtk *wbcg, GnmPasteTarget const *pt);
-gboolean gnm_x_claim_clipboard (WBCGtk *wbcg);
 void gnm_x_store_clipboard_if_needed (Workbook *wb);
 
+gboolean gnm_x_claim_clipboard (GdkDisplay *display);
+void gnm_x_disown_clipboard (void);
+
 G_END_DECLS
 
 #endif /* _GNM_GUI_CLIPBOARD_H_ */
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index 5e39b53..f276836 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -1678,7 +1678,9 @@ wbcg_paste_from_selection (WorkbookControl *wbc, GnmPasteTarget const *pt)
 static gboolean
 wbcg_claim_selection (WorkbookControl *wbc)
 {
-	return gnm_x_claim_clipboard ((WBCGtk *)wbc);
+	WBCGtk *wbcg = (WBCGtk *)wbc;
+	GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET (wbcg_toplevel (wbcg)));
+	return gnm_x_claim_clipboard (display);
 }
 
 static int



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]