changeset 746:b13b1b7b11f1

[xemacs-hg @ 2002-02-08 13:04:18 by wmperry] GTK selection fixes from Eric Gillespie, Jr. <epg@pretzelnet.org>
author wmperry
date Fri, 08 Feb 2002 13:04:21 +0000
parents 4aa6e26cd8ba
children 9f953fdc1394
files src/ChangeLog src/device-gtk.c src/select-gtk.c
diffstat 3 files changed, 55 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Feb 06 16:27:06 2002 +0000
+++ b/src/ChangeLog	Fri Feb 08 13:04:21 2002 +0000
@@ -1,3 +1,15 @@
+2002-01-03  Eric Gillespie, Jr.  <epg@pretzelnet.org>
+
+	* device-gtk.c: Add prototype for
+	emacs_gtk_selection_clear_event_handle.
+	(gtk_init_device): Call gtk_selection_add_target for CLIPBOARD
+	selection.  Setup signal handler for "selection_clear_event"
+	(emacs_gtk_selection_clear_event_handle).
+
+	* select-gtk.c (emacs_gtk_selection_clear_event_handle): Handle
+	other applications owning the clipboard (based on
+	x_handle_selection_clear).
+
 2002-02-02  William M. Perry  <wmperry@gnu.org>
 
 	* winslots.h: New toolbar_shadow_thickness slot.
--- a/src/device-gtk.c	Wed Feb 06 16:27:06 2002 +0000
+++ b/src/device-gtk.c	Fri Feb 08 13:04:21 2002 +0000
@@ -126,6 +126,9 @@
 					guint info,
 					guint time_stamp,
 					gpointer data);
+extern void emacs_gtk_selection_clear_event_handle (GtkWidget *widget,
+                                                    GdkEventSelection *event,
+                                                    gpointer data);
 extern void emacs_gtk_selection_received (GtkWidget *widget,
 					  GtkSelectionData *selection_data,
 					  gpointer user_data);
@@ -284,9 +287,15 @@
   /* Need to set up some selection handlers */
   gtk_selection_add_target (GTK_WIDGET (app_shell), GDK_SELECTION_PRIMARY,
 			    GDK_SELECTION_TYPE_STRING, 0);
+  gtk_selection_add_target (GTK_WIDGET (app_shell),
+                            gdk_atom_intern("CLIPBOARD", FALSE),
+			    GDK_SELECTION_TYPE_STRING, 0);
   
   gtk_signal_connect (GTK_OBJECT (app_shell), "selection_get",
 		      GTK_SIGNAL_FUNC (emacs_gtk_selection_handle), NULL);
+  gtk_signal_connect (GTK_OBJECT (app_shell), "selection_clear_event",
+                      GTK_SIGNAL_FUNC (emacs_gtk_selection_clear_event_handle),
+                      NULL);
   gtk_signal_connect (GTK_OBJECT (app_shell), "selection_received",
 		      GTK_SIGNAL_FUNC (emacs_gtk_selection_received), NULL);
 
--- a/src/select-gtk.c	Wed Feb 06 16:27:06 2002 +0000
+++ b/src/select-gtk.c	Fri Feb 08 13:04:21 2002 +0000
@@ -235,6 +235,40 @@
 }
 
 
+void
+emacs_gtk_selection_clear_event_handle (GtkWidget *widget,
+                                        GdkEventSelection *event,
+                                        gpointer data)
+{
+  GdkAtom selection = event->selection;
+  guint32 changed_owner_time = event->time;
+  struct device *d = decode_gtk_device (Qnil);
+
+  Lisp_Object selection_symbol, local_selection_time_lisp;
+  guint32 local_selection_time;
+
+  selection_symbol = atom_to_symbol (d, selection);
+
+  local_selection_time_lisp = Fget_selection_timestamp (selection_symbol);
+
+  /* We don't own the selection, so that's fine. */
+  if (NILP (local_selection_time_lisp))
+    return;
+
+  local_selection_time = *(guint32 *) XOPAQUE_DATA (local_selection_time_lisp);
+
+  /* This SelectionClear is for a selection that we no longer own, so we can
+     disregard it.  (That is, we have reasserted the selection since this
+     request was generated.)
+   */
+  if (changed_owner_time != GDK_CURRENT_TIME &&
+      local_selection_time > changed_owner_time)
+    return;
+
+  handle_selection_clear (selection_symbol);
+}
+
+
 
 static GtkWidget *reading_selection_reply;
 static GdkAtom reading_which_selection;