diff --git a/src/backend/wayland/wl_backend.c b/src/backend/wayland/wl_backend.c index ae6fd65..938c103 100644 --- a/src/backend/wayland/wl_backend.c +++ b/src/backend/wayland/wl_backend.c @@ -326,6 +326,14 @@ wl_display_open(const char *name) wl_state.is_nested = 1; /* explicit override: force nested */ else wl_state.is_nested = (wayland_display && wayland_display[0]) ? 1 : 0; + /* Save the host compositor's WAYLAND_DISPLAY before anything + * overwrites it, so restart (execvp) can restore it and the + * new instance can find the host compositor. */ + const char *_hwd = getenv("WAYLAND_DISPLAY"); + if (_hwd) + snprintf(wl_state.host_wayland_display, sizeof(wl_state.host_wayland_display), "%s", _hwd); + else + wl_state.host_wayland_display[0] = '\0'; } /* Always create a headless backend for the output in headless mode. */ @@ -894,13 +902,16 @@ wl_display_close(void) unlink(path); } } - unsetenv("WAYLAND_DISPLAY"); + if (wl_state.host_wayland_display[0]) + setenv("WAYLAND_DISPLAY", wl_state.host_wayland_display, 1); + else + unsetenv("WAYLAND_DISPLAY"); wl_state.renderer = NULL; wl_state.backend = NULL; wl_state.headless_inner = NULL; wl_state.wl_backend_inner = NULL; wl_state.display = NULL; - wl_state.output = NULL; + wl_state.output = NULL; wl_state.frame_timer = NULL; wl_state.output_layout = NULL; wl_state.scene_output = NULL; @@ -909,6 +920,7 @@ wl_display_close(void) wl_state.started = 0; } + void wl_display_post_open(const char *display_name, int *multi_head_out) { diff --git a/src/backend/wayland/wl_types.h b/src/backend/wayland/wl_types.h index cea2c5a..7cf2d75 100644 --- a/src/backend/wayland/wl_types.h +++ b/src/backend/wayland/wl_types.h @@ -213,7 +213,8 @@ struct wl_compositor_state { struct wlr_scene_output *scene_output; struct wl_listener backend_new_output_listener; struct wl_listener output_frame_listener; - char socket_name[64]; /* Phase 34: e.g. "wayland-0" */ + char socket_name[64]; + char host_wayland_display[64]; /* saved from env before overwrite */ int started; /* non-zero after successful display_open */ /* Self-pipe for async-signal-safe shutdown: signal handler writes to [1], * event loop reads [0] and calls wl_display_terminate(). */