diff --git a/src/backend/wayland/wl_backend.c b/src/backend/wayland/wl_backend.c index 818591a..d7ebe9d 100644 --- a/src/backend/wayland/wl_backend.c +++ b/src/backend/wayland/wl_backend.c @@ -1921,6 +1921,13 @@ wl_handle_x11_events(int fd, uint32_t mask, void *data) return 0; } +/* Public accessor for the XWayland Display* — used by screen.c to create + * an RContext for texture rendering without exposing wl_state globally. */ +Display *wl_get_x_display(void) +{ + return wl_state.x_display; +} + static void * wl_display_open(const char *name) { diff --git a/src/screen.c b/src/screen.c index deab403..cf51f93 100644 --- a/src/screen.c +++ b/src/screen.c @@ -163,17 +163,43 @@ WScreen *wScreenInit(int screen_number) * set, Path 1), fall through to the full X11 init so WINGs, RContext, * GCs, and menus work correctly on the XWayland display. */ if (wm_backend->is_wayland && !dpy) { - WWorkspace *wspace = wmalloc(sizeof(WWorkspace)); - wspace->name = wstrdup("Workspace 1"); - wspace->clip = NULL; - wspace->map = NULL; - scr->workspaces = wmalloc(sizeof(WWorkspace *)); - scr->workspaces[0] = wspace; - scr->workspace_count = 1; - /* Phase 62: run backend screen internals (sets no_focus_win, - * auto_focus, clears keyboard focus) before leaving the Wayland - * fast path — screen_create_internals is normally called at - * line 248 which the goto would skip. */ + extern Display *wl_get_x_display(void); + Display *xdpy = wl_get_x_display(); + + if (!xdpy) { + /* No XWayland — truly headless. Minimal workspace only. */ + WWorkspace *wspace = wmalloc(sizeof(WWorkspace)); + wspace->name = wstrdup("Workspace 1"); + wspace->clip = NULL; + wspace->map = NULL; + scr->workspaces = wmalloc(sizeof(WWorkspace *)); + scr->workspaces[0] = wspace; + scr->workspace_count = 1; + wm_backend->screen_create_internals(scr); + goto screen_done; + } + + /* XWayland available — create RContext on it for texture rendering. */ + rattr.flags = RC_RenderMode | RC_ColorsPerChannel | RC_StandardColormap; + rattr.render_mode = RBestMatchRendering; + rattr.colors_per_channel = 4; + rattr.standard_colormap_mode = RUseStdColormap; + + scr->rcontext = RCreateContext(xdpy, DefaultScreen(xdpy), &rattr); + if (!scr->rcontext) { + rattr.flags &= ~RC_StandardColormap; + scr->rcontext = RCreateContext(xdpy, DefaultScreen(xdpy), &rattr); + } + + if (scr->rcontext) { + scr->w_win = scr->rcontext->drawable; + scr->w_visual = scr->rcontext->visual; + scr->w_depth = scr->rcontext->depth; + scr->w_colormap = scr->rcontext->cmap; + + scr->wmscreen = WMCreateScreenWithRContext(xdpy, DefaultScreen(xdpy), scr->rcontext); + } + wm_backend->screen_create_internals(scr); goto screen_done; } diff --git a/src/startup.c b/src/startup.c index d2851ce..bbdd447 100644 --- a/src/startup.c +++ b/src/startup.c @@ -554,7 +554,6 @@ void StartUp(Bool defaultScreenOnly) InitializeSwitchMenu(); /* initialize/restore state for the screens */ - if (dpy) { for (j = 0; j < w_global.screen_count; j++) { int lastDesktop; @@ -613,7 +612,6 @@ void StartUp(Bool defaultScreenOnly) else wSessionRestoreLastWorkspace(wScreen[j]); } - } /* end if (dpy) */ if (w_global.screen_count == 0) { wfatal(_("could not manage any screen"));