[gtk+] x11: Make clipboard use translate-event signal



commit 2d86c1a869a94ab54bcab6fbb9ce87af3b684d0a
Author: Benjamin Otte <otte redhat com>
Date:   Wed Dec 13 00:56:05 2017 +0100

    x11: Make clipboard use translate-event signal

 gdk/x11/gdkclipboard-x11.c |   47 +++++++++++++++++++++----------------------
 1 files changed, 23 insertions(+), 24 deletions(-)
---
diff --git a/gdk/x11/gdkclipboard-x11.c b/gdk/x11/gdkclipboard-x11.c
index 78edb2a..ce905b8 100644
--- a/gdk/x11/gdkclipboard-x11.c
+++ b/gdk/x11/gdkclipboard-x11.c
@@ -372,55 +372,52 @@ gdk_x11_clipboard_claim_remote (GdkX11Clipboard *cb,
   gdk_x11_clipboard_request_targets (cb);
 }
 
-static GdkFilterReturn
-gdk_x11_clipboard_filter_event (GdkXEvent *xev,
-                                GdkEvent  *gdkevent,
-                                gpointer   data)
+static GdkEvent *
+gdk_x11_clipboard_translate_event (GdkDisplay   *display,
+                                   const XEvent *xevent,
+                                   gpointer   data)
 {
   GdkX11Clipboard *cb = GDK_X11_CLIPBOARD (data);
-  GdkDisplay *display;
-  XEvent *xevent = xev;
   Window xwindow;
 
-  display = gdk_clipboard_get_display (GDK_CLIPBOARD (cb));
   xwindow = GDK_X11_DISPLAY (display)->leader_window;
 
   if (xevent->xany.window != xwindow)
-    return GDK_FILTER_CONTINUE;
+    return NULL;
 
   switch (xevent->type)
   {
     case SelectionClear:
       if (xevent->xselectionclear.selection != cb->xselection)
-        return GDK_FILTER_CONTINUE;
+        return NULL;
 
       if (xevent->xselectionclear.time < cb->timestamp)
         {
           GDK_NOTE(CLIPBOARD, g_printerr ("%s: ignoring SelectionClear with too old timestamp (%lu vs 
%lu)\n",
                                           cb->selection, xevent->xselectionclear.time, cb->timestamp));
-          return GDK_FILTER_CONTINUE;
+          return NULL;
         }
 
       GDK_NOTE(CLIPBOARD, g_printerr ("%s: got SelectionClear\n", cb->selection));
       gdk_x11_clipboard_claim_remote (cb, xevent->xselectionclear.time);
-      return GDK_FILTER_REMOVE;
+      return gdk_event_new (GDK_NOTHING);
 
     case SelectionNotify:
       /* This code only checks clipboard manager replies, so... */
       if (!g_str_equal (cb->selection, "CLIPBOARD"))
-        return GDK_FILTER_CONTINUE;
+        return NULL;
 
       /* selection is not for us */
       if (xevent->xselection.selection != gdk_x11_get_xatom_by_name_for_display (display, 
"CLIPBOARD_MANAGER") ||
           xevent->xselection.target != gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS"))
-        return GDK_FILTER_CONTINUE;
+        return NULL;
 
       /* We already received a selectionNotify before */
       if (cb->store_task == NULL)
         {
           GDK_NOTE(CLIPBOARD, g_printerr ("%s: got SelectionNotify for nonexisting task?!\n",
                                           cb->selection));
-          return GDK_FILTER_CONTINUE;
+          return NULL;
         }
 
       GDK_NOTE(CLIPBOARD, g_printerr ("%s: got SelectionNotify for store task\n",
@@ -433,14 +430,14 @@ gdk_x11_clipboard_filter_event (GdkXEvent *xev,
                                  _("Clipboard manager could not store selection."));
       g_clear_object (&cb->store_task);
       
-      return GDK_FILTER_CONTINUE;
+      return NULL;
 
     case SelectionRequest:
       {
         const char *target, *property;
 
         if (xevent->xselectionrequest.selection != cb->xselection)
-          return GDK_FILTER_CONTINUE;
+          return NULL;
 
         target = gdk_x11_get_xatom_name_for_display (display, xevent->xselectionrequest.target);
         if (xevent->xselectionrequest.property == None)
@@ -452,13 +449,13 @@ gdk_x11_clipboard_filter_event (GdkXEvent *xev,
           {
             GDK_NOTE(CLIPBOARD, g_printerr ("%s: got SelectionRequest for %s @ %s even though we don't own 
the selection, huh?\n",
                                             cb->selection, target, property));
-            return GDK_FILTER_REMOVE;
+            return gdk_event_new (GDK_NOTHING);
           }
         if (xevent->xselectionrequest.requestor == None)
           {
             GDK_NOTE(CLIPBOARD, g_printerr ("%s: got SelectionRequest for %s @ %s with NULL window, 
ignoring\n",
                                             cb->selection, target, property));
-            return GDK_FILTER_REMOVE;
+            return gdk_event_new (GDK_NOTHING);
           }
         
         GDK_NOTE(CLIPBOARD, g_printerr ("%s: got SelectionRequest for %s @ %s\n",
@@ -474,7 +471,7 @@ gdk_x11_clipboard_filter_event (GdkXEvent *xev,
                                                  xevent->xselectionrequest.time,
                                                  gdk_x11_clipboard_default_output_handler,
                                                  cb);
-        return GDK_FILTER_REMOVE;
+        return gdk_event_new (GDK_NOTHING);
       }
 
     default:
@@ -484,13 +481,13 @@ gdk_x11_clipboard_filter_event (GdkXEvent *xev,
           XFixesSelectionNotifyEvent *sn = (XFixesSelectionNotifyEvent *) xevent;
 
           if (sn->selection != cb->xselection)
-            return GDK_FILTER_CONTINUE;
+            return NULL;
 
           if (sn->owner == GDK_X11_DISPLAY (display)->leader_window)
             {
               GDK_NOTE(CLIPBOARD, g_printerr ("%s: Ignoring XFixesSelectionNotify for ourselves\n",
                                               cb->selection));
-              return GDK_FILTER_CONTINUE;
+              return NULL;
             }
 
           GDK_NOTE(CLIPBOARD, g_printerr ("%s: Received XFixesSelectionNotify, claiming selection\n",
@@ -499,7 +496,7 @@ gdk_x11_clipboard_filter_event (GdkXEvent *xev,
           gdk_x11_clipboard_claim_remote (cb, sn->selection_timestamp);
         }
 #endif
-      return GDK_FILTER_CONTINUE;
+      return NULL;
   }
 }
 
@@ -508,7 +505,9 @@ gdk_x11_clipboard_finalize (GObject *object)
 {
   GdkX11Clipboard *cb = GDK_X11_CLIPBOARD (object);
 
-  gdk_window_remove_filter (NULL, gdk_x11_clipboard_filter_event, cb);
+  g_signal_handlers_disconnect_by_func (gdk_clipboard_get_display (GDK_CLIPBOARD (cb)),
+                                        gdk_x11_clipboard_translate_event,
+                                        cb);
   g_free (cb->selection);
 
   G_OBJECT_CLASS (gdk_x11_clipboard_parent_class)->finalize (object);
@@ -815,7 +814,7 @@ gdk_x11_clipboard_new (GdkDisplay  *display,
   cb->xselection = gdk_x11_get_xatom_by_name_for_display (display, selection);
 
   gdk_display_request_selection_notification (display, gdk_atom_intern (selection, FALSE));
-  gdk_window_add_filter (NULL, gdk_x11_clipboard_filter_event, cb);
+  g_signal_connect (display, "translate-event", G_CALLBACK (gdk_x11_clipboard_translate_event), cb);
   gdk_x11_clipboard_claim_remote (cb, CurrentTime);
 
   return GDK_CLIPBOARD (cb);


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