This is an automated email from the git hooks/post-receive script.
git pushed a commit to reference refs/pull/207/head
in repository enlightenment.
View the commit online.
commit b9769ae3595f659efeb59692a6f6e2fd4c5320a3
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Nov 24 09:10:16 2026 -0600
e_comp_x - keep an Xwayland window tied to its X window
When an X application running through Xwayland exits, its window stays
on screen with its last picture and never goes away. It shows with any
X client on the Wayland compositor, such as expedite, which uses its X11
engine by default.
Once Xwayland names the wl_surface of an X window, the window moves from
the E_Client E made for the X window to the one made for the surface,
and the first is deleted. The X window ids have to follow, because every
X event handler finds its client through them. Since 1eb64ce30 they were
added to the client being deleted instead, and freeing it took them out
of the hash altogether. The DestroyNotify of the exiting client then
found nothing, and its window was never deleted. The ids are now moved:
taken off the first client, or freeing it would remove them by id from
under the second, and put on the second.
Finding the window again exposes a crash. Xwayland gives an X window a
new wl_surface whenever it maps it again as a toplevel: when E restores
the frame of a minimised window, or when E reparents a window that was
mapped before E managed the display. The new surface id then names a
window whose client already went through that move, and the move
treated that client's Wayland data as X data: E crashed restoring any
minimised X window. Before the ids were fixed, the lookup missed
instead, and E adopted its own frame window as a new client.
The move now starts from either kind of client. One already moved hands
its X data and its X pixmap reference over, and leaves the queue of
windows waiting for their surface, where it can now be. The strings and
lists of icccm, netwm and e go to the new client as well, instead of
being shared and released when the old one is freed: a window moved
twice showed a freed title.
e_comp_x_xwayland_client_setup() has two callers, both on the Wayland
compositor only: the WL_SURFACE_ID client message in e_comp_x.c, and
wl_surface creation in e_comp_wl.c for a window whose message came
first. E as an X11 window manager does not reach it.
The new test runs an X client on E's own Xwayland. run-nested.sh now
gives it E's pid, which Xwayland's lock file names, to find that
display. It closes the client, minimises and restores the window
before closing it, and maps a window before E manages the display. The
last cannot always get ahead of E, and is skipped when it does not.
Tested with the default suite, wlcs included, and each new scenario 20
times. The x11 suite fails on this machine, 3 to 6 tests out of 6 from
run to run, the same ways with and without this change.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/bin/e_comp_wl.c | 12 +-
src/bin/e_comp_wl.h | 10 ++
src/bin/e_comp_x.c | 45 +++++--
src/tests/wayland/meson.build | 19 +++
src/tests/wayland/run-nested.sh | 5 +-
src/tests/wayland/test_xwayland.c | 263 ++++++++++++++++++++++++++++++++++++++
6 files changed, 336 insertions(+), 18 deletions(-)
diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index 9e78a0503..ffcf85633 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -2329,10 +2329,14 @@ _e_comp_wl_compositor_cb_surface_create(struct wl_client *client, struct wl_reso
#ifndef HAVE_WAYLAND_ONLY
EINA_LIST_FOREACH(e_comp_wl->xwl_pending, l, wc)
{
- if (!e_pixmap_is_x(wc->pixmap)) continue;
- if (wl_resource_get_id(res) !=
- ((E_Comp_X_Client_Data*)wc->comp_data)->surface_id) continue;
- // wc, ec is correct! first arg should be the x client, 2nd wl one
+ E_Comp_X_Client_Data *xcd;
+
+ if (e_pixmap_is_x(wc->pixmap))
+ xcd = (E_Comp_X_Client_Data*)wc->comp_data;
+ else
+ xcd = e_comp_wl_client_xwayland_data(wc);
+ if (wl_resource_get_id(res) != xcd->surface_id) continue;
+ // wc, ec is correct! first arg holds the x window, 2nd is the new wl one
e_comp_x_xwayland_client_setup(wc, ec);
break;
}
diff --git a/src/bin/e_comp_wl.h b/src/bin/e_comp_wl.h
index ea39955f0..af77523be 100644
--- a/src/bin/e_comp_wl.h
+++ b/src/bin/e_comp_wl.h
@@ -538,6 +538,16 @@ e_comp_wl_client_xwayland_setup(E_Client *ec, E_Comp_X_Client_Data *cd, E_Pixmap
if (e_comp_wl->xwl_pending)
e_comp_wl->xwl_pending = eina_list_remove(e_comp_wl->xwl_pending, ec);
}
+
+/* The X window of ec has moved to the client of a newer wl_surface: ec no
+ * longer owns its E_Comp_X_Client_Data nor its X pixmap reference. */
+static inline void
+e_comp_wl_client_xwayland_release(E_Client *ec)
+{
+ ((E_Comp_Wl_Client_Data*)ec->comp_data)->xwayland_data = NULL;
+ ((E_Comp_Wl_Client_Data*)ec->comp_data)->xwayland_pixmap = NULL;
+ e_comp_wl_client_xwayland_setup(ec, NULL, NULL);
+}
# endif
# endif
#endif
diff --git a/src/bin/e_comp_x.c b/src/bin/e_comp_x.c
index da7021090..00aabe0ae 100644
--- a/src/bin/e_comp_x.c
+++ b/src/bin/e_comp_x.c
@@ -2465,7 +2465,7 @@ _e_comp_x_message(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_X_Event_Cl
}
else
{
- ec->comp_data->surface_id = ev->data.l[0];
+ _e_comp_x_client_data_get(ec)->surface_id = ev->data.l[0];
e_comp_wl_xwayland_client_queue(ec);
}
}
@@ -5157,9 +5157,8 @@ _e_comp_x_hook_client_del(void *d EINA_UNUSED, E_Client *ec)
#ifdef HAVE_WAYLAND
if (e_comp->comp_type == E_PIXMAP_TYPE_WL)
{
- if (e_pixmap_is_x(ec->pixmap))
- e_comp_wl_client_xwayland_setup(ec, NULL, NULL);
- else
+ e_comp_wl_client_xwayland_setup(ec, NULL, NULL);
+ if (!e_pixmap_is_x(ec->pixmap))
{
e_pixmap_alias(NULL, E_PIXMAP_TYPE_X, win);
free(cd);
@@ -6237,13 +6236,24 @@ e_comp_x_xwayland_client_setup(E_Client *ec, E_Client *wc)
win = e_client_util_win_get(ec);
pwin = e_client_util_pwin_get(ec);
- cd = ec->comp_data;
- e_comp_wl_client_xwayland_setup(wc, cd, e_pixmap_ref(ec->pixmap));
- eina_hash_del(damages_hash, &cd->damage, ec);
- ecore_x_damage_free(cd->damage);
+ cd = _e_comp_x_client_data_get(ec);
+ if (e_pixmap_is_x(ec->pixmap))
+ {
+ e_comp_wl_client_xwayland_setup(wc, cd, e_pixmap_ref(ec->pixmap));
+ ec->comp_data = NULL;
+ }
+ else
+ {
+ e_comp_wl_client_xwayland_setup(wc, cd, e_comp_x_client_pixmap_get(ec));
+ e_comp_wl_client_xwayland_release(ec);
+ }
+ if (cd->damage)
+ {
+ eina_hash_del(damages_hash, &cd->damage, ec);
+ ecore_x_damage_free(cd->damage);
+ cd->damage = 0;
+ }
E_FREE_FUNC(cd->first_draw_delay, ecore_timer_del);
- cd->damage = 0;
- ec->comp_data = NULL;
cd->evas_init = 0;
_e_comp_x_client_evas_init(wc);
if (!e_comp_object_frame_exists(ec->frame))
@@ -6265,13 +6275,22 @@ e_comp_x_xwayland_client_setup(E_Client *ec, E_Client *wc)
memcpy(&wc->icccm, &ec->icccm, sizeof(ec->icccm));
memcpy(&wc->netwm, &ec->netwm, sizeof(ec->netwm));
memcpy(&wc->e, &ec->e, sizeof(ec->e));
+ /* The strings and lists in them belong to wc now: freeing ec, below,
+ * must not release them. */
+ memset(&ec->icccm, 0, sizeof(ec->icccm));
+ memset(&ec->netwm, 0, sizeof(ec->netwm));
+ memset(&ec->e, 0, sizeof(ec->e));
wc->new_client = !wc->override;
if (wc->new_client)
e_comp->new_clients++;
- _e_comp_x_hash_add(win, ec);
+ _e_comp_x_hash_del(win, ec);
+ _e_comp_x_hash_add(win, wc);
if (pwin)
- _e_comp_x_hash_add(pwin, ec);
+ {
+ _e_comp_x_hash_del(pwin, ec);
+ _e_comp_x_hash_add(pwin, wc);
+ }
// eina_hash_set(clients_win_hash, &win, wc);
// if (pwin)
// eina_hash_set(clients_win_hash, &pwin, wc);
@@ -6290,7 +6309,7 @@ e_comp_x_xwayland_client_setup(E_Client *ec, E_Client *wc)
evas_object_layer_set(wc->frame, evas_object_layer_get(ec->frame));
evas_object_geometry_set(wc->frame, ec->x, ec->y, ec->w, ec->h);
evas_object_show(wc->frame);
- e_pixmap_alias(wc->pixmap, E_PIXMAP_TYPE_X, e_pixmap_window_get(ec->pixmap));
+ e_pixmap_alias(wc->pixmap, E_PIXMAP_TYPE_X, win);
e_object_del(E_OBJECT(ec));
e_hints_window_visible_set(wc);
_e_comp_x_client_stack(wc);
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index 7a860e484..d969c9706 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -109,3 +109,22 @@ foreach t: wl_protocol_tests
timeout: 120,
)
endforeach
+
+# X clients of the compositor's own Xwayland, so the xwayland module is
+# loaded as well, and the client speaks X through ecore_x. One program, run
+# once per scenario.
+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],
+ )
+ foreach scenario: ['close', 'restore', 'early-map']
+ test('wl-xwayland-' + scenario,
+ run_nested,
+ args: [test_xwayland, scenario],
+ env: environment({'E_TEST_COMPOSITOR': e_test_compositor,
+ 'E_TEST_MODULE': 'wl_test,xwayland'}),
+ timeout: 120,
+ )
+ endforeach
+endif
diff --git a/src/tests/wayland/run-nested.sh b/src/tests/wayland/run-nested.sh
index 193e9af2b..590a9d098 100755
--- a/src/tests/wayland/run-nested.sh
+++ b/src/tests/wayland/run-nested.sh
@@ -11,6 +11,9 @@
# E_TEST_KEEP set to 1 to keep the temp dir and print E's log path
# WAYLAND_DEBUG passed through to the client
#
+# The client gets E_TEST_PID, the compositor's pid: Xwayland's lock file names
+# it, and that is how a test finds the X display of its own compositor.
+#
# Exits with the client's exit status, or 1 if the compositor never came up.
#
# The compositor gets a private XDG_RUNTIME_DIR, so it owns the only socket
@@ -140,7 +143,7 @@ if [ -z "$SOCKET" ]; then
fi
set +e
-XDG_RUNTIME_DIR="$RUNDIR" WAYLAND_DISPLAY="$SOCKET" "$@"
+XDG_RUNTIME_DIR="$RUNDIR" WAYLAND_DISPLAY="$SOCKET" E_TEST_PID="$E_PID" "$@"
client_status=$?
set -e
diff --git a/src/tests/wayland/test_xwayland.c b/src/tests/wayland/test_xwayland.c
new file mode 100644
index 000000000..eb0797789
--- /dev/null
+++ b/src/tests/wayland/test_xwayland.c
@@ -0,0 +1,263 @@
+/* X clients of E's own Xwayland. One scenario per run, named by the only
+ * argument:
+ *
+ * close The client closes its X connection, as an application does
+ * when it quits. E has to find the window it manages from the
+ * X window id in the DestroyNotify, and delete it.
+ * restore The window is minimised and restored. E unmaps the frame of
+ * a minimised window, and Xwayland gives it a new wl_surface
+ * when it is mapped again: E has to move the window to it.
+ * early-map A window mapped before E manages the display. E adopts it
+ * and reparents it into a frame, and Xwayland then gives the
+ * frame a wl_surface of its own, after the one it gave the
+ * window: E has to move the window to the newer surface.
+ * Skipped when E manages the display before the test can map
+ * the window.
+ *
+ * Every scenario ends with the client closing, so each also checks that E
+ * still finds the window from its X window id.
+ *
+ * The X display is the one E opened for its Xwayland: the lock file of an
+ * X display holds the pid of the server, and E writes its own pid there. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <Ecore_X.h>
+
+#include "e_wl_testkit.h"
+
+#define PROG "test-xwayland"
+#define APP_ID "E.test.xwayland"
+#define TITLE "xwayland under test"
+#define W 160
+#define H 120
+#define MAX_DISPLAYS 64
+
+static double
+_now(void)
+{
+ struct timespec ts;
+
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return ts.tv_sec + (ts.tv_nsec / 1e9);
+}
+
+static int
+_lock_owner(int disp)
+{
+ char path[64], buf[16];
+ FILE *f;
+ int pid = -1;
+
+ snprintf(path, sizeof(path), "/tmp/.X%d-lock", disp);
+ f = fopen(path, "r");
+ if (!f) return -1;
+ if (fgets(buf, sizeof(buf), f)) pid = atoi(buf);
+ fclose(f);
+ return pid;
+}
+
+/* The lock is taken when E loads the xwayland module, which may be after
+ * its Wayland socket is up. E locks a display before it binds its sockets
+ * and drops the lock again when another server has them, so a lock only
+ * counts once E has gone back to its main loop and still holds it. */
+static int
+_xwayland_display_find(Tk *tk, int e_pid)
+{
+ double deadline = _now() + TK_WAIT_SECONDS;
+ int i;
+
+ for (;;)
+ {
+ for (i = 0; i < MAX_DISPLAYS; i++)
+ {
+ if (_lock_owner(i) != e_pid) continue;
+ tk_sync(tk);
+ if (_lock_owner(i) == e_pid) return i;
+ }
+ if (_now() > deadline) break;
+ tk_sync(tk);
+ }
+ tk_fail(tk, "no X display locked by the compositor (pid %d) after %ds",
+ e_pid, TK_WAIT_SECONDS);
+}
+
+/* E sets _NET_SUPPORTING_WM_CHECK once it redirects the root's children. */
+static Eina_Bool
+_x_window_managed(void)
+{
+ Ecore_X_Window check;
+
+ return ecore_x_window_prop_window_get(ecore_x_window_root_first_get(),
+ ECORE_X_ATOM_NET_SUPPORTING_WM_CHECK,
+ &check, 1) == 1;
+}
+
+static Ecore_X_Window
+_x_window_show(void)
+{
+ Ecore_X_Window win;
+
+ win = ecore_x_window_new(0, 0, 0, W, H);
+ ecore_x_icccm_name_class_set(win, "xwayland", APP_ID);
+ ecore_x_icccm_title_set(win, TITLE);
+ ecore_x_window_background_color_set(win, 0xffff, 0x8000, 0);
+ ecore_x_window_show(win);
+ ecore_x_sync();
+ return win;
+}
+
+static void
+_x_window_wait_shown(Tk *tk)
+{
+ double deadline = _now() + TK_WAIT_SECONDS;
+
+ /* Before Xwayland names the window's wl_surface, the X window is not a
+ * window E shows: visible means E took it over through that surface. */
+ while (!tk_find(tk, APP_ID))
+ {
+ if (_now() > deadline)
+ tk_fail(tk, "the X window never became a window of the compositor");
+ tk_sync(tk);
+ }
+ tk_wait_states(tk, APP_ID, WL_TEST_CLIENT_STATE_VISIBLE,
+ WL_TEST_CLIENT_STATE_VISIBLE, "X window shown");
+}
+
+static void
+_x_window_manager_wait(Tk *tk)
+{
+ double deadline = _now() + TK_WAIT_SECONDS;
+
+ while (!_x_window_managed())
+ {
+ if (_now() > deadline)
+ tk_fail(tk, "the compositor did not manage its Xwayland display "
+ "after %ds", TK_WAIT_SECONDS);
+ tk_sync(tk);
+ }
+}
+
+static void
+_x_close_wait_gone(Tk *tk)
+{
+ double deadline;
+
+ ecore_x_shutdown();
+ deadline = _now() + TK_WAIT_SECONDS;
+ while (tk_find(tk, APP_ID))
+ {
+ if (_now() > deadline)
+ tk_fail(tk, "the window is still listed %ds after its X client "
+ "closed its connection", TK_WAIT_SECONDS);
+ tk_sync(tk);
+ }
+}
+
+static void
+_x_window_map_managed(Tk *tk)
+{
+ _x_window_manager_wait(tk);
+ _x_window_show();
+ _x_window_wait_shown(tk);
+}
+
+static void
+_restore(Tk *tk)
+{
+ const unsigned int mask = WL_TEST_CLIENT_STATE_VISIBLE |
+ WL_TEST_CLIENT_STATE_ICONIFIED;
+ Tk_Client *c;
+ int i;
+
+ _x_window_map_managed(tk);
+ /* Twice: the second time, the window is one E already moved. */
+ for (i = 0; i < 2; i++)
+ {
+ tk_action(tk, tk_expect(tk, APP_ID)->id, "window_iconic_toggle", NULL);
+ tk_wait_states(tk, APP_ID, mask, WL_TEST_CLIENT_STATE_ICONIFIED,
+ "minimised");
+ tk_action(tk, tk_expect(tk, APP_ID)->id, "window_iconic_toggle", NULL);
+ c = tk_wait_states(tk, APP_ID, mask, WL_TEST_CLIENT_STATE_VISIBLE,
+ "restored");
+ if (strcmp(c->title, TITLE))
+ tk_fail(tk, "restored window has title '%s', expected '%s'",
+ c->title, TITLE);
+ }
+}
+
+static void
+_early_map(Tk *tk)
+{
+ Ecore_X_Window win, frame;
+ double deadline;
+
+ /* Xwayland was started by this connection, and E becomes its window
+ * manager only once it is up. The grab keeps E from doing so before
+ * the window is mapped. */
+ ecore_x_grab();
+ if (_x_window_managed())
+ {
+ printf(PROG ": early-map skipped: the compositor manages its Xwayland "
+ "display already\n");
+ ecore_x_shutdown();
+ tk_disconnect(tk);
+ exit(77);
+ }
+ win = _x_window_show();
+ ecore_x_ungrab();
+ ecore_x_sync();
+
+ /* Xwayland names the frame's surface when E maps the frame. */
+ deadline = _now() + TK_WAIT_SECONDS;
+ for (;;)
+ {
+ frame = ecore_x_window_parent_get(win);
+ if ((frame != ecore_x_window_root_first_get()) &&
+ ecore_x_window_visible_get(frame))
+ break;
+ if (_now() > deadline)
+ tk_fail(tk, "the compositor did not map a frame around the window "
+ "after %ds", TK_WAIT_SECONDS);
+ tk_sync(tk);
+ }
+ tk_settle(tk);
+ _x_window_wait_shown(tk);
+}
+
+int
+main(int argc, char **argv)
+{
+ Tk *tk;
+ const char *e_pid;
+ char disp[16];
+
+ if (argc != 2)
+ {
+ fprintf(stderr, "usage: %s close|restore|early-map\n", argv[0]);
+ return 2;
+ }
+
+ tk = tk_connect(PROG);
+
+ e_pid = getenv("E_TEST_PID");
+ if (!e_pid) tk_fail(tk, "E_TEST_PID is not set; run this under run-nested.sh");
+ snprintf(disp, sizeof(disp), ":%d", _xwayland_display_find(tk, atoi(e_pid)));
+ if (!ecore_x_init(disp))
+ tk_fail(tk, "cannot connect to the compositor's Xwayland on %s", disp);
+
+ if (!strcmp(argv[1], "close"))
+ _x_window_map_managed(tk);
+ else if (!strcmp(argv[1], "restore"))
+ _restore(tk);
+ else if (!strcmp(argv[1], "early-map"))
+ _early_map(tk);
+ else
+ tk_fail(tk, "unknown scenario '%s'", argv[1]);
+ _x_close_wait_gone(tk);
+
+ printf(PROG ": %s ok (display %s)\n", argv[1], disp);
+ tk_disconnect(tk);
+ return 0;
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.