Unify WMCreateScreenWithRContext: single path, vtable dispatch

Eliminated the separate Wayland/X11 code paths. Now ONE path:
1. Backend selection (based on WMAKER_USE_WAYLAND)
2. Backend init
3. Common init (colors, fonts, antialiasedText)
4. viewBackend->platform_init() — X11 does GCs, atoms, cursors,
   cut buffers, modifier masks, pixmaps, IM, W_InitApplication.
   Wayland is NULL (no platform-specific late init needed).
5. rootView, balloon, return

All X11-specific screen setup moved to W_X11PlatformInit() called
through the view backend vtable. No if-guards, no early returns,
no separate paths.
This commit is contained in:
Levi Neely 2026-05-13 22:14:04 +02:00
parent 2e631eef15
commit ace0585ec3
3 changed files with 116 additions and 226 deletions

View File

@ -562,12 +562,12 @@ WMScreen *WMCreateScreen(Display * display, int screen)
return WMCreateScreenWithRContext(display, screen, RCreateContext(display, screen, NULL));
}
WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * context)
void W_X11PlatformInit(W_Screen *scrPtr)
{
W_Screen *scrPtr;
Display *display = scrPtr->display;
XGCValues gcv;
Pixmap stipple;
static int initialized = 0;
int i;
static char *atomNames[] = {
"_GNUSTEP_WM_ATTR",
"WM_DELETE_WINDOW",
@ -597,100 +597,6 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
"_NET_WM_ICON",
};
Atom atoms[wlengthof(atomNames)];
int i;
if (!initialized) {
initialized = 1;
W_ReadConfigurations();
assert(W_ApplicationInitialized());
}
scrPtr = malloc(sizeof(W_Screen));
if (!scrPtr)
return NULL;
memset(scrPtr, 0, sizeof(W_Screen));
scrPtr->aflags.hasAppIcon = 1;
scrPtr->display = display;
scrPtr->screen = screen;
scrPtr->rcontext = context;
/* --- Wayland path: no X11 calls --- */
if (getenv("WMAKER_USE_WAYLAND")) {
scrPtr->depth = context ? context->depth : 24;
scrPtr->visual = context ? context->visual : NULL;
scrPtr->colormap = context ? context->cmap : 0;
scrPtr->rootWin = None;
scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
scrPtr->fontBackend = &W_FontBackendWL;
scrPtr->fontBackendCtx = scrPtr->fontBackend->screen_init(scrPtr);
scrPtr->eventBackend = &W_EventBackendWL;
scrPtr->eventBackendCtx = scrPtr->eventBackend->screen_init(scrPtr);
scrPtr->renderBackend = &W_RenderBackendWL;
scrPtr->renderBackendCtx = scrPtr->renderBackend->screen_init(scrPtr);
scrPtr->viewBackend = &W_ViewBackendWL;
scrPtr->viewBackendCtx = scrPtr->viewBackend->screen_init(scrPtr);
scrPtr->colorBackend = &W_ColorBackendWL;
scrPtr->colorBackendCtx = scrPtr->colorBackend->screen_init(scrPtr);
scrPtr->antialiasedText = WINGsConfiguration.antialiasedText;
/* Allocate basic colors */
WMWhiteColor(scrPtr);
WMBlackColor(scrPtr);
WMGrayColor(scrPtr);
WMDarkGrayColor(scrPtr);
/* Load fonts */
scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 0);
scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 0);
if (!scrPtr->boldFont)
scrPtr->boldFont = scrPtr->normalFont;
if (!scrPtr->normalFont) {
wwarning(_("could not load any fonts."));
return NULL;
}
scrPtr->rootView = W_CreateRootView(scrPtr);
return scrPtr;
}
/* --- X11 path (unchanged) --- */
scrPtr->depth = context->depth;
scrPtr->visual = context->visual;
scrPtr->lastEventTime = 0;
scrPtr->colormap = context->cmap;
scrPtr->rootWin = RootWindow(display, screen);
scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
scrPtr->fontBackend = getenv("WMAKER_USE_WAYLAND") ? &W_FontBackendWL : &W_FontBackendX11;
scrPtr->fontBackendCtx = scrPtr->fontBackend->screen_init(scrPtr);
scrPtr->eventBackend = getenv("WMAKER_USE_WAYLAND") ? &W_EventBackendWL : &W_EventBackendX11;
scrPtr->eventBackendCtx = scrPtr->eventBackend->screen_init(scrPtr);
scrPtr->renderBackend = getenv("WMAKER_USE_WAYLAND") ? &W_RenderBackendWL : &W_RenderBackendX11;
scrPtr->renderBackendCtx = scrPtr->renderBackend->screen_init(scrPtr);
scrPtr->viewBackend = &W_ViewBackendX11;
scrPtr->viewBackendCtx = scrPtr->viewBackend->screen_init(scrPtr);
scrPtr->colorBackend = &W_ColorBackendX11;
scrPtr->colorBackendCtx = scrPtr->colorBackend->screen_init(scrPtr);
/* Create missing CUT_BUFFERs */
{
@ -701,47 +607,28 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
rootWinProps = XListProperties(display, scrPtr->rootWin, &count);
for (i = 0; i < count; i++) {
switch (rootWinProps[i]) {
case XA_CUT_BUFFER0:
exists[0] = 1;
break;
case XA_CUT_BUFFER1:
exists[1] = 1;
break;
case XA_CUT_BUFFER2:
exists[2] = 1;
break;
case XA_CUT_BUFFER3:
exists[3] = 1;
break;
case XA_CUT_BUFFER4:
exists[4] = 1;
break;
case XA_CUT_BUFFER5:
exists[5] = 1;
break;
case XA_CUT_BUFFER6:
exists[6] = 1;
break;
case XA_CUT_BUFFER7:
exists[7] = 1;
break;
default:
break;
case XA_CUT_BUFFER0: exists[0] = 1; break;
case XA_CUT_BUFFER1: exists[1] = 1; break;
case XA_CUT_BUFFER2: exists[2] = 1; break;
case XA_CUT_BUFFER3: exists[3] = 1; break;
case XA_CUT_BUFFER4: exists[4] = 1; break;
case XA_CUT_BUFFER5: exists[5] = 1; break;
case XA_CUT_BUFFER6: exists[6] = 1; break;
case XA_CUT_BUFFER7: exists[7] = 1; break;
default: break;
}
}
if (rootWinProps) {
if (rootWinProps)
XFree(rootWinProps);
}
for (i = 0; i < 8; i++) {
if (!exists[i]) {
if (!exists[i])
XStoreBuffer(display, "", 0, i);
}
}
}
/* Modifier mask detection */
scrPtr->ignoredModifierMask = 0;
{
int i;
XModifierKeymap *modmap;
KeyCode nlock, slock;
static int mask_table[8] = {
@ -752,13 +639,7 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
nlock = XKeysymToKeycode(display, XK_Num_Lock);
slock = XKeysymToKeycode(display, XK_Scroll_Lock);
/*
* Find out the masks for the NumLock and ScrollLock modifiers,
* so that we can bind the grabs for when they are enabled too.
*/
modmap = XGetModifierMapping(display);
if (modmap != NULL && modmap->max_keypermod > 0) {
for (i = 0; i < 8 * modmap->max_keypermod; i++) {
if (modmap->modifiermap[i] == nlock && nlock != 0)
@ -767,21 +648,13 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
scrollLockMask = mask_table[i / modmap->max_keypermod];
}
}
if (modmap)
XFreeModifiermap(modmap);
scrPtr->ignoredModifierMask = numLockMask | scrollLockMask | LockMask;
}
/* initially allocate some colors */
WMWhiteColor(scrPtr);
WMBlackColor(scrPtr);
WMGrayColor(scrPtr);
WMDarkGrayColor(scrPtr);
/* GCs */
gcv.graphics_exposures = False;
gcv.function = GXxor;
gcv.foreground = W_PIXEL(scrPtr->white);
if (gcv.foreground == 0)
@ -797,7 +670,6 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
gcv.function = GXcopy;
scrPtr->copyGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
scrPtr->clipGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCFunction | GCGraphicsExposures, &gcv);
stipple = XCreateBitmapFromData(display, W_DRAWABLE(scrPtr), STIPPLE_BITS, STIPPLE_WIDTH, STIPPLE_HEIGHT);
@ -808,130 +680,84 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
scrPtr->stippleGC = XCreateGC(display, W_DRAWABLE(scrPtr),
GCForeground | GCBackground | GCStipple
| GCFillStyle | GCGraphicsExposures, &gcv);
scrPtr->drawStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
scrPtr->drawImStringGC = XCreateGC(display, W_DRAWABLE(scrPtr), GCGraphicsExposures, &gcv);
/* we need a 1bpp drawable for the monoGC, so borrow this one */
scrPtr->monoGC = XCreateGC(display, stipple, 0, NULL);
scrPtr->stipple = stipple;
scrPtr->antialiasedText = WINGsConfiguration.antialiasedText;
scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 0);
scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 0);
if (!scrPtr->boldFont)
scrPtr->boldFont = scrPtr->normalFont;
if (!scrPtr->normalFont) {
wwarning(_("could not load any fonts. Make sure your font installation"
" and locale settings are correct."));
return NULL;
}
/* create input method stuff */
/* Input method */
W_InitIM(scrPtr);
/* Widget pixmaps */
scrPtr->checkButtonImageOn = makePixmap(scrPtr, CHECK_BUTTON_ON,
CHECK_BUTTON_ON_WIDTH, CHECK_BUTTON_ON_HEIGHT, False);
CHECK_BUTTON_ON_WIDTH, CHECK_BUTTON_ON_HEIGHT, False);
scrPtr->checkButtonImageOff = makePixmap(scrPtr, CHECK_BUTTON_OFF,
CHECK_BUTTON_OFF_WIDTH, CHECK_BUTTON_OFF_HEIGHT, False);
CHECK_BUTTON_OFF_WIDTH, CHECK_BUTTON_OFF_HEIGHT, False);
scrPtr->radioButtonImageOn = makePixmap(scrPtr, RADIO_BUTTON_ON,
RADIO_BUTTON_ON_WIDTH, RADIO_BUTTON_ON_HEIGHT, False);
RADIO_BUTTON_ON_WIDTH, RADIO_BUTTON_ON_HEIGHT, False);
scrPtr->radioButtonImageOff = makePixmap(scrPtr, RADIO_BUTTON_OFF,
RADIO_BUTTON_OFF_WIDTH, RADIO_BUTTON_OFF_HEIGHT, False);
RADIO_BUTTON_OFF_WIDTH, RADIO_BUTTON_OFF_HEIGHT, False);
scrPtr->tristateButtonImageOn = makePixmap(scrPtr, TRISTATE_BUTTON_ON,
TRISTATE_BUTTON_ON_WIDTH, TRISTATE_BUTTON_ON_HEIGHT, False);
TRISTATE_BUTTON_ON_WIDTH, TRISTATE_BUTTON_ON_HEIGHT, False);
scrPtr->tristateButtonImageOff = makePixmap(scrPtr, TRISTATE_BUTTON_OFF,
TRISTATE_BUTTON_OFF_WIDTH, TRISTATE_BUTTON_OFF_HEIGHT, False);
TRISTATE_BUTTON_OFF_WIDTH, TRISTATE_BUTTON_OFF_HEIGHT, False);
scrPtr->tristateButtonImageTri = makePixmap(scrPtr, TRISTATE_BUTTON_TRI,
TRISTATE_BUTTON_TRI_WIDTH, TRISTATE_BUTTON_TRI_HEIGHT, False);
scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW, BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT, False);
TRISTATE_BUTTON_TRI_WIDTH, TRISTATE_BUTTON_TRI_HEIGHT, False);
scrPtr->buttonArrow = makePixmap(scrPtr, BUTTON_ARROW,
BUTTON_ARROW_WIDTH, BUTTON_ARROW_HEIGHT, False);
scrPtr->pushedButtonArrow = makePixmap(scrPtr, BUTTON_ARROW2,
BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT, False);
BUTTON_ARROW2_WIDTH, BUTTON_ARROW2_HEIGHT, False);
scrPtr->scrollerDimple = makePixmap(scrPtr, SCROLLER_DIMPLE,
SCROLLER_DIMPLE_WIDTH, SCROLLER_DIMPLE_HEIGHT, False);
SCROLLER_DIMPLE_WIDTH, SCROLLER_DIMPLE_HEIGHT, False);
scrPtr->upArrow = makePixmap(scrPtr, SCROLLER_ARROW_UP,
SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
scrPtr->downArrow = makePixmap(scrPtr, SCROLLER_ARROW_DOWN,
SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
scrPtr->leftArrow = makePixmap(scrPtr, SCROLLER_ARROW_LEFT,
SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
scrPtr->rightArrow = makePixmap(scrPtr, SCROLLER_ARROW_RIGHT,
SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
scrPtr->hiUpArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_UP,
SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
SCROLLER_ARROW_UP_WIDTH, SCROLLER_ARROW_UP_HEIGHT, True);
scrPtr->hiDownArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_DOWN,
SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
SCROLLER_ARROW_DOWN_WIDTH, SCROLLER_ARROW_DOWN_HEIGHT, True);
scrPtr->hiLeftArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_LEFT,
SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
SCROLLER_ARROW_LEFT_WIDTH, SCROLLER_ARROW_LEFT_HEIGHT, True);
scrPtr->hiRightArrow = makePixmap(scrPtr, HI_SCROLLER_ARROW_RIGHT,
SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
SCROLLER_ARROW_RIGHT_WIDTH, SCROLLER_ARROW_RIGHT_HEIGHT, True);
scrPtr->popUpIndicator = makePixmap(scrPtr, POPUP_INDICATOR,
POPUP_INDICATOR_WIDTH, POPUP_INDICATOR_HEIGHT, True);
POPUP_INDICATOR_WIDTH, POPUP_INDICATOR_HEIGHT, True);
scrPtr->pullDownIndicator = makePixmap(scrPtr, PULLDOWN_INDICATOR,
PULLDOWN_INDICATOR_WIDTH, PULLDOWN_INDICATOR_HEIGHT, True);
scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK, CHECK_MARK_WIDTH, CHECK_MARK_HEIGHT, True);
PULLDOWN_INDICATOR_WIDTH, PULLDOWN_INDICATOR_HEIGHT, True);
scrPtr->checkMark = makePixmap(scrPtr, CHECK_MARK,
CHECK_MARK_WIDTH, CHECK_MARK_HEIGHT, True);
loadPixmaps(scrPtr);
/* Cursors */
scrPtr->defaultCursor = XCreateFontCursor(display, XC_left_ptr);
scrPtr->textCursor = XCreateFontCursor(display, XC_xterm);
{
XColor bla;
Pixmap blank;
blank = XCreatePixmap(display, scrPtr->stipple, 1, 1, 1);
XSetForeground(display, scrPtr->monoGC, 0);
XFillRectangle(display, blank, scrPtr->monoGC, 0, 0, 1, 1);
scrPtr->invisibleCursor = XCreatePixmapCursor(display, blank, blank, &bla, &bla, 0, 0);
XFreePixmap(display, blank);
}
/* Atoms */
#ifdef HAVE_XINTERNATOMS
XInternAtoms(display, atomNames, wlengthof(atomNames), False, atoms);
#else
for (i = 0; i < wlengthof(atomNames); i++) {
for (i = 0; i < wlengthof(atomNames); i++)
atoms[i] = XInternAtom(display, atomNames[i], False);
}
#endif
i = 0;
scrPtr->attribsAtom = atoms[i++];
scrPtr->deleteWindowAtom = atoms[i++];
scrPtr->protocolsAtom = atoms[i++];
scrPtr->clipboardAtom = atoms[i++];
scrPtr->xdndAwareAtom = atoms[i++];
scrPtr->xdndSelectionAtom = atoms[i++];
scrPtr->xdndEnterAtom = atoms[i++];
@ -943,27 +769,87 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
scrPtr->xdndActionListAtom = atoms[i++];
scrPtr->xdndActionDescriptionAtom = atoms[i++];
scrPtr->xdndStatusAtom = atoms[i++];
scrPtr->xdndActionCopy = atoms[i++];
scrPtr->xdndActionMove = atoms[i++];
scrPtr->xdndActionLink = atoms[i++];
scrPtr->xdndActionAsk = atoms[i++];
scrPtr->xdndActionPrivate = atoms[i++];
scrPtr->wmIconDragOffsetAtom = atoms[i++];
scrPtr->wmStateAtom = atoms[i++];
scrPtr->utf8String = atoms[i++];
scrPtr->netwmName = atoms[i++];
scrPtr->netwmIconName = atoms[i++];
scrPtr->netwmIcon = atoms[i++];
scrPtr->rootView = W_CreateRootView(scrPtr);
scrPtr->balloon = W_CreateBalloon(scrPtr);
/* Application group leader */
W_InitApplication(scrPtr);
}
WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * context)
{
W_Screen *scrPtr;
static int initialized = 0;
int wayland = (getenv("WMAKER_USE_WAYLAND") != NULL);
if (!initialized) {
initialized = 1;
W_ReadConfigurations();
assert(W_ApplicationInitialized());
}
scrPtr = malloc(sizeof(W_Screen));
if (!scrPtr)
return NULL;
memset(scrPtr, 0, sizeof(W_Screen));
scrPtr->aflags.hasAppIcon = 1;
scrPtr->display = display;
scrPtr->screen = screen;
scrPtr->rcontext = context;
/* --- Backend selection --- */
scrPtr->depth = context ? context->depth : 32;
scrPtr->visual = context ? context->visual : NULL;
scrPtr->colormap = context ? context->cmap : 0;
scrPtr->rootWin = display ? RootWindow(display, screen) : None;
scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
scrPtr->fontBackend = wayland ? &W_FontBackendWL : &W_FontBackendX11;
scrPtr->fontBackendCtx = scrPtr->fontBackend->screen_init(scrPtr);
scrPtr->eventBackend = wayland ? &W_EventBackendWL : &W_EventBackendX11;
scrPtr->eventBackendCtx = scrPtr->eventBackend->screen_init(scrPtr);
scrPtr->renderBackend = wayland ? &W_RenderBackendWL : &W_RenderBackendX11;
scrPtr->renderBackendCtx = scrPtr->renderBackend->screen_init(scrPtr);
scrPtr->viewBackend = wayland ? &W_ViewBackendWL : &W_ViewBackendX11;
scrPtr->viewBackendCtx = scrPtr->viewBackend->screen_init(scrPtr);
scrPtr->colorBackend = wayland ? &W_ColorBackendWL : &W_ColorBackendX11;
scrPtr->colorBackendCtx = scrPtr->colorBackend->screen_init(scrPtr);
/* --- Common init --- */
scrPtr->antialiasedText = WINGsConfiguration.antialiasedText;
WMWhiteColor(scrPtr);
WMBlackColor(scrPtr);
WMGrayColor(scrPtr);
WMDarkGrayColor(scrPtr);
scrPtr->normalFont = WMSystemFontOfSize(scrPtr, 0);
scrPtr->boldFont = WMBoldSystemFontOfSize(scrPtr, 0);
if (!scrPtr->boldFont)
scrPtr->boldFont = scrPtr->normalFont;
if (!scrPtr->normalFont) {
wwarning(_("could not load any fonts."));
return NULL;
}
/* --- Platform-specific late init (GCs, atoms, cursors, pixmaps, IM) --- */
if (scrPtr->viewBackend->platform_init)
scrPtr->viewBackend->platform_init(scrPtr);
/* --- Final common init --- */
scrPtr->rootView = W_CreateRootView(scrPtr);
scrPtr->balloon = W_CreateBalloon(scrPtr);
return scrPtr;
}

View File

@ -316,4 +316,5 @@ const W_ViewBackend W_ViewBackendWL = {
.get_screen_position = wl_get_screen_position,
.selection_acquire = wl_selection_acquire,
.selection_release = wl_selection_release,
.platform_init = NULL,
};

View File

@ -7,6 +7,8 @@
#include "WINGsP.h"
#include <X11/Xresource.h>
extern void W_X11PlatformInit(W_Screen *scr);
static XContext ViewContext = 0;
static void *x11_screen_init(W_Screen *scr)
@ -224,4 +226,5 @@ const W_ViewBackend W_ViewBackendX11 = {
.get_screen_position = x11_get_screen_position,
.selection_acquire = x11_selection_acquire,
.selection_release = x11_selection_release,
.platform_init = W_X11PlatformInit,
};