Phase 80g: clean X11 from motif.c, colormap.c, resources.c

- motif.c: wGetMWMHints moved entirely to x11_backend.c (inlined into
  x11_motif_get_hints)
- colormap.c: wColormapInstallForWindow inlined into x11_colormap_install;
  policy file now contains only vtable dispatch stubs
- resources.c: wGetColorForColormap and wFreeColor now dispatch through
  vtable; X11 implementation inlined into x11_backend.c
- xmodifier.c: wXModifierInitialize now called from x11_extensions_init
  (removed from main.c)

motif.o, colormap.o, resources.o verified X11-free with nm.
xmodifier.o retains X11 symbols (mechanism code, only reached through
X11 backend — candidate for physical move to backend/ directory).
This commit is contained in:
Levi Neely 2026-05-13 10:55:30 +02:00
parent e504141132
commit 90fc12c252
5 changed files with 92 additions and 118 deletions

View File

@ -67,6 +67,7 @@
#include "../../texture.h"
#include "../../menu.h"
#include "../../balloon.h"
#include "../../xmodifier.h"
#include "../backend.h"
#include "x11_compat.h"
#include "x11_backend.h"
@ -2238,6 +2239,7 @@ x11_extensions_init(void)
}
#endif
(void) j;
wXModifierInitialize();
}
/* -------------------------------------------------------------------- */
@ -2872,17 +2874,74 @@ static void x11_wipe_desktop(WScreen *scr)
static int x11_get_color_for_colormap(unsigned long colormap,
const char *color_name, XColor *color)
{
return wGetColorForColormap((Colormap)colormap, color_name, color);
if (!XParseColor(dpy, (Colormap)colormap, color_name, color)) {
wwarning(_("could not parse color \"%s\""), color_name);
return 0;
}
if (!XAllocColor(dpy, (Colormap)colormap, color)) {
wwarning(_("could not allocate color \"%s\""), color_name);
return 0;
}
return 1;
}
static void x11_free_color(WScreen *scr, unsigned long pixel)
{
wFreeColor(scr, pixel);
if (pixel != scr->white_pixel && pixel != scr->black_pixel) {
unsigned long colors[1];
colors[0] = pixel;
XFreeColors(dpy, scr->w_colormap, colors, 1, 0);
}
}
static void x11_colormap_install(WScreen *scr, WWindow *wwin)
{
wColormapInstallForWindow(scr, wwin);
int i;
XWindowAttributes attributes;
int done = 0;
Window xwin = None;
if (wwin)
xwin = wwin->client_win;
else
xwin = scr->root_win;
scr->cmap_window = wwin;
if (scr->root_colormap_install_count > 0) {
scr->original_cmap_window = wwin;
return;
}
if (wwin && wwin->cmap_window_no > 0 && wwin->cmap_windows) {
for (i = wwin->cmap_window_no - 1; i >= 0; i--) {
Window w = wwin->cmap_windows[i];
if (w == wwin->client_win)
done = 1;
XGetWindowAttributes(dpy, w, &attributes);
if (attributes.colormap == None)
attributes.colormap = scr->colormap;
if (scr->current_colormap != attributes.colormap) {
scr->current_colormap = attributes.colormap;
if (!scr->flags.colormap_stuff_blocked)
XInstallColormap(dpy, attributes.colormap);
}
}
}
if (!done) {
attributes.colormap = None;
if (xwin != None)
XGetWindowAttributes(dpy, xwin, &attributes);
if (attributes.colormap == None)
attributes.colormap = scr->colormap;
if (scr->current_colormap != attributes.colormap) {
scr->current_colormap = attributes.colormap;
if (!scr->flags.colormap_stuff_blocked)
XInstallColormap(dpy, attributes.colormap);
}
}
XSync(dpy, False);
}
/* -------------------------------------------------------------------- */
@ -2896,7 +2955,29 @@ static void x11_xdnd_init(void)
static int x11_motif_get_hints(WNativeWindow window, MWMHints *hints_out)
{
return wGetMWMHints((Window)window, hints_out);
static Atom _XA_MOTIF_WM_HINTS = 0;
unsigned long *data;
int count;
if (!_XA_MOTIF_WM_HINTS)
_XA_MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
data = (unsigned long *)PropGetCheckProperty((Window)window, _XA_MOTIF_WM_HINTS,
_XA_MOTIF_WM_HINTS, 32, 0, &count);
if (!data)
return 0;
hints_out->flags = 0;
if (count >= 4) {
hints_out->flags = data[0];
hints_out->functions = data[1];
hints_out->decorations = data[2];
hints_out->inputMode = data[3];
if (count > 5)
hints_out->status = data[4];
}
XFree(data);
return 1;
}
/* -------------------------------------------------------------------- */

View File

@ -33,77 +33,12 @@
void wColormapInstallForWindow(WScreen * scr, WWindow * wwin)
{
int i;
XWindowAttributes attributes;
int done = 0;
Window xwin = None;
if (wwin) {
xwin = wwin->client_win;
} else {
xwin = scr->root_win;
}
scr->cmap_window = wwin;
if (scr->root_colormap_install_count > 0) {
scr->original_cmap_window = wwin;
return;
}
/* install colormap for all windows of the client */
if (wwin && wwin->cmap_window_no > 0 && wwin->cmap_windows) {
for (i = wwin->cmap_window_no - 1; i >= 0; i--) {
Window w;
w = wwin->cmap_windows[i];
if (w == wwin->client_win)
done = 1;
XGetWindowAttributes(dpy, w, &attributes);
if (attributes.colormap == None)
attributes.colormap = scr->colormap;
if (scr->current_colormap != attributes.colormap) {
scr->current_colormap = attributes.colormap;
/*
* ICCCM 2.0: some client requested permission
* to install colormaps by itself and we granted.
* So, we can't install any colormaps.
*/
if (!scr->flags.colormap_stuff_blocked)
XInstallColormap(dpy, attributes.colormap);
}
}
}
if (!done) {
attributes.colormap = None;
if (xwin != None)
XGetWindowAttributes(dpy, xwin, &attributes);
if (attributes.colormap == None)
attributes.colormap = scr->colormap;
if (scr->current_colormap != attributes.colormap) {
scr->current_colormap = attributes.colormap;
if (!scr->flags.colormap_stuff_blocked)
XInstallColormap(dpy, attributes.colormap);
}
}
XSync(dpy, False);
wm_backend->colormap_install(scr, wwin);
}
void wColormapAllowClientInstallation(WScreen * scr, Bool starting)
{
scr->flags.colormap_stuff_blocked = starting;
/*
* Client stopped managing the colormap stuff. Restore the colormap
* that would be installed if the client did not request colormap
* stuff.
*/
if (!starting) {
XInstallColormap(dpy, scr->current_colormap);
XSync(dpy, False);
}
if (!starting)
wm_backend->colormap_install(scr, scr->cmap_window);
}

View File

@ -816,8 +816,7 @@ static int real_main(int argc, char **argv)
* before EventLoop() would deadlock waiting for a reply that
* XWayland cannot deliver. Modifier masks are handled via XKB
* in wl_backend (wSetModifierMasks), so this call is not needed. */
if (!wm_backend->is_wayland)
wXModifierInitialize();
/* Modifier initialization handled by extensions_init in X11 backend */
}
StartUp(!multiHead);

View File

@ -54,7 +54,6 @@
#define MWM_DECOR_MINIMIZE (1L << 5)
#define MWM_DECOR_MAXIMIZE (1L << 6)
static Atom _XA_MOTIF_WM_HINTS;
static void setupMWMHints(WWindow *wwin, MWMHints *mwm_hints)
{
@ -148,34 +147,7 @@ static void setupMWMHints(WWindow *wwin, MWMHints *mwm_hints)
}
}
int wGetMWMHints(Window window, MWMHints *mwmhints)
{
unsigned long *data;
int count;
if (!_XA_MOTIF_WM_HINTS)
_XA_MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
data = (unsigned long *)PropGetCheckProperty(window, _XA_MOTIF_WM_HINTS,
_XA_MOTIF_WM_HINTS, 32, 0, &count);
if (!data)
return 0;
mwmhints->flags = 0;
if (count >= 4) {
mwmhints->flags = data[0];
mwmhints->functions = data[1];
mwmhints->decorations = data[2];
mwmhints->inputMode = data[3];
if (count > 5)
mwmhints->status = data[4];
}
XFree(data);
return 1;
}
/* wGetMWMHints moved to x11_backend.c — X11 mechanism code */
void wMWMCheckClientHints(WWindow *wwin)
{

View File

@ -35,15 +35,7 @@
int wGetColorForColormap(Colormap colormap, const char *color_name, XColor *color)
{
if (!XParseColor(dpy, colormap, color_name, color)) {
wwarning(_("could not parse color \"%s\""), color_name);
return False;
}
if (!XAllocColor(dpy, colormap, color)) {
wwarning(_("could not allocate color \"%s\""), color_name);
return False;
}
return True;
return wm_backend->get_color_for_colormap((unsigned long)colormap, color_name, color);
}
int wGetColor(WScreen *scr, const char *color_name, XColor *color)
@ -53,10 +45,5 @@ int wGetColor(WScreen *scr, const char *color_name, XColor *color)
void wFreeColor(WScreen * scr, unsigned long pixel)
{
if (pixel != scr->white_pixel && pixel != scr->black_pixel) {
unsigned long colors[1];
colors[0] = pixel;
XFreeColors(dpy, scr->w_colormap, colors, 1, 0);
}
wm_backend->free_color(scr, pixel);
}