This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch wl-clipboard-seam
in repository enlightenment.

View the commit online.

commit 58add1be7d88004d012c911850d34820ba4f96f1
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Dec 1 21:17:23 2026 -0600

    xwayland - paste the clipboard E saved from a Wayland client
    
    An X11 client pasting the clipboard crashed E when its owner was E's
    saved copy of a Wayland client's selection, which is what is left once
    that client destroys its source or exits. The request handler sent
    wl_data_source.send on source->resource, and the saved copy has none.
    Anyone running an X11 application next to Wayland ones who copies, then
    closes the application they copied from, hits it on the next paste.
    
    Go through source->send instead: every implementation it can reach
    (wl_data_source, the saved copy, xwayland's own) takes the fd and
    closes it or keeps it for its transfer, so the close after the call
    goes too. The saved copy writes without blocking E, so a large paste
    from X11 does not make E wait for itself.
    
    The test copies from a Wayland client, destroys the source and pastes
    from an X client. E crashes without the fix.
    
    Co-Authored-By: Claude Fable 5.2 <[email protected]>
---
 src/modules/xwayland/dnd.c        |  3 +-
 src/tests/wayland/meson.build     |  4 +-
 src/tests/wayland/test_xwayland.c | 83 ++++++++++++++++++++++++++++++++++++++-
 3 files changed, 84 insertions(+), 6 deletions(-)

diff --git a/src/modules/xwayland/dnd.c b/src/modules/xwayland/dnd.c
index 42f5f28bd..0469e7fbb 100644
--- a/src/modules/xwayland/dnd.c
+++ b/src/modules/xwayland/dnd.c
@@ -474,8 +474,7 @@ _xwl_selection_request(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_X_Event_Sel
                     p->fdh = ecore_main_fd_handler_add(fds[0], ECORE_FD_READ, _xwl_pipe_read, p, NULL, NULL);
                     p->win = ev->requestor;
                     p->source = source;
-                    wl_data_source_send_send(source->resource, type, fds[1]);
-                    close(fds[1]);
+                    source->send(source, type, fds[1]);
                     p->atom = ev->target;
                     p->selection = ev->selection;
                     p->property = ev->property;
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index afd4bf7f5..1ba335bba 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -186,9 +186,9 @@ endif
 if get_option('xwayland') and not config_h.has('HAVE_WAYLAND_ONLY')
   test_xwayland = executable('test_wl_xwayland',
     ['test_xwayland.c', tk_src, test_proto_src],
-    dependencies: [dependency('wayland-client'), dep_ecore_x],
+    dependencies: [dependency('wayland-client'), dep_ecore_x, dep_ecore],
   )
-  foreach scenario: ['close', 'restore', 'early-map']
+  foreach scenario: ['close', 'restore', 'early-map', 'paste-saved']
     test('wl-xwayland-' + scenario,
       run_nested,
       args: [test_xwayland, scenario],
diff --git a/src/tests/wayland/test_xwayland.c b/src/tests/wayland/test_xwayland.c
index eb0797789..02a4b5782 100644
--- a/src/tests/wayland/test_xwayland.c
+++ b/src/tests/wayland/test_xwayland.c
@@ -14,6 +14,10 @@
  *              Skipped when E manages the display before the test can map
  *              the window.
  *
+ *   paste-saved  A Wayland client copies and destroys its source. E keeps
+ *              the copy, which has no wl_data_source of its own, and an X
+ *              client pastes it.
+ *
  * Every scenario ends with the client closing, so each also checks that E
  * still finds the window from its X window id.
  *
@@ -23,9 +27,11 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
+#include <Ecore.h>
 #include <Ecore_X.h>
+#include <unistd.h>
 
-#include "e_wl_testkit.h"
+#include "e_wl_clipboardkit.h"
 
 #define PROG   "test-xwayland"
 #define APP_ID "E.test.xwayland"
@@ -187,6 +193,77 @@ _restore(Tk *tk)
      }
 }
 
+#define APP_WL "E.test.xwayland.wl"
+#define MIME "text/plain"
+#define COPY_TEXT "copied by a client"
+
+static char x_got[256];
+static int x_got_count;
+
+static Eina_Bool
+_x_selection_notify(void *d EINA_UNUSED, int t EINA_UNUSED, void *event)
+{
+   Ecore_X_Event_Selection_Notify *ev = event;
+   Ecore_X_Selection_Data *sd = ev->data;
+
+   x_got_count++;
+   if (sd && sd->data)
+     snprintf(x_got, sizeof(x_got), "%.*s", sd->length, (char *)sd->data);
+   return ECORE_CALLBACK_RENEW;
+}
+
+/* One pass for each side: E answers on the Wayland connection, the X client
+ * on its own. */
+static void
+_both_iterate(Tk *tk)
+{
+   tk_sync(tk);
+   ecore_main_loop_iterate();
+}
+
+static void
+_paste_saved(Tk *tk)
+{
+   static const char *const types[] = { MIME };
+   Cb_Peer a;
+   Cb_Source src;
+   Ecore_X_Window win;
+   double deadline;
+
+   _x_window_manager_wait(tk);
+   cb_peer_new(&a, PROG, APP_WL);
+   cb_copy(&a, &src, types, 1, COPY_TEXT, strlen(COPY_TEXT), 0);
+   /* The owner goes: E keeps what it had read from it. */
+   wl_data_source_destroy(src.source);
+   tk_settle(a.tk);
+
+   win = _x_window_show();
+   _x_window_wait_shown(tk);
+   tk_action(tk, tk_expect(tk, APP_ID)->id, "window_focus", NULL);
+   tk_wait_states(tk, APP_ID, CB_FOCUS, CB_FOCUS, "the X window has the focus");
+   tk_settle(tk);
+
+   /* E takes the X clipboard when the X window gets the focus. */
+   deadline = _now() + TK_WAIT_SECONDS;
+   while (!ecore_x_selection_owner_get(ECORE_X_ATOM_SELECTION_CLIPBOARD))
+     {
+        if (_now() > deadline) tk_fail(tk, "E never took the X clipboard");
+        _both_iterate(tk);
+     }
+   ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY, _x_selection_notify, NULL);
+   ecore_x_selection_clipboard_request(win, MIME);
+   ecore_x_sync();
+   deadline = _now() + TK_WAIT_SECONDS;
+   while (!x_got_count)
+     {
+        if (_now() > deadline) tk_fail(tk, "the X client got no answer: E is gone or stuck");
+        _both_iterate(tk);
+     }
+   if (strcmp(x_got, COPY_TEXT))
+     tk_fail(tk, "the X client pasted '%s', not '%s'", x_got, COPY_TEXT);
+   tk_disconnect(a.tk);
+}
+
 static void
 _early_map(Tk *tk)
 {
@@ -235,7 +312,7 @@ main(int argc, char **argv)
 
    if (argc != 2)
      {
-        fprintf(stderr, "usage: %s close|restore|early-map\n", argv[0]);
+        fprintf(stderr, "usage: %s close|restore|early-map|paste-saved\n", argv[0]);
         return 2;
      }
 
@@ -251,6 +328,8 @@ main(int argc, char **argv)
      _x_window_map_managed(tk);
    else if (!strcmp(argv[1], "restore"))
      _restore(tk);
+   else if (!strcmp(argv[1], "paste-saved"))
+     _paste_saved(tk);
    else if (!strcmp(argv[1], "early-map"))
      _early_map(tk);
    else

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to