Phase 80l: clean X11 from defaults.c

- XParseColor (9 calls) -> parse_color vtable slot
- XStringToKeysym -> keysym_from_name (existing slot)
- XReadBitmapFile/XQueryColor/XCreatePixmapCursor -> cursor_create_from_files
- XFreeCursor -> cursor_free
- XDefineCursor -> cursor_set
- XUngrabKey -> key_ungrab_all (existing slot)

New vtable slots: parse_color, cursor_create_from_files, cursor_free,
cursor_set.
defaults.o verified X11-free with nm.
This commit is contained in:
Levi Neely 2026-05-13 11:27:07 +02:00
parent 6f1c499b03
commit 40ac4f252b
4 changed files with 77 additions and 24 deletions

View File

@ -1719,6 +1719,12 @@ typedef struct WMBackend {
unsigned int *nchildren_out);
WScreen *(*screen_for_window)(WNativeWindow window);
int (*parse_color)(WScreen *scr, const char *name, XColor *color_out);
int (*cursor_create_from_files)(WScreen *scr, const char *bitmap_path,
const char *mask_path, Cursor *cursor_out);
void (*cursor_free)(Cursor cursor);
void (*cursor_set)(WNativeWindow window, Cursor cursor);
} WMBackend;
/*

View File

@ -6234,6 +6234,14 @@ static void wl_noop_query_tree(WNativeWindow root, WNativeWindow **children_out,
static WScreen *wl_noop_screen_for_window(WNativeWindow window)
{ (void)window; return wScreenWithNumber(0); }
static int wl_noop_parse_color(WScreen *scr, const char *name, XColor *color_out)
{ (void)scr; (void)name; (void)color_out; return 0; }
static int wl_noop_cursor_create_from_files(WScreen *scr, const char *bitmap_path,
const char *mask_path, Cursor *cursor_out)
{ (void)scr; (void)bitmap_path; (void)mask_path; (void)cursor_out; return 0; }
static void wl_noop_cursor_free(Cursor cursor) { (void)cursor; }
static void wl_noop_cursor_set(WNativeWindow window, Cursor cursor) { (void)window; (void)cursor; }
/* ------------------------------------------------------------------ */
/* vtable */
/* ------------------------------------------------------------------ */
@ -6461,4 +6469,8 @@ const WMBackend wl_backend = {
.context_init = wl_context_init,
.query_tree = wl_noop_query_tree,
.screen_for_window = wl_noop_screen_for_window,
.parse_color = wl_noop_parse_color,
.cursor_create_from_files = wl_noop_cursor_create_from_files,
.cursor_free = wl_noop_cursor_free,
.cursor_set = wl_noop_cursor_set,
};

View File

@ -3040,6 +3040,46 @@ static WScreen *x11_screen_for_window(WNativeWindow window)
return NULL;
}
static int x11_parse_color(WScreen *scr, const char *name, XColor *color_out)
{
return XParseColor(dpy, scr->w_colormap, name, color_out);
}
static int x11_cursor_create_from_files(WScreen *scr, const char *bitmap_path,
const char *mask_path, Cursor *cursor_out)
{
Pixmap bitmap = None, mask = None;
unsigned int w, h;
int x, y;
XColor fg, bg;
if (XReadBitmapFile(dpy, scr->w_win, bitmap_path, &w, &h, &bitmap, &x, &y) != BitmapSuccess)
return 0;
if (XReadBitmapFile(dpy, scr->w_win, mask_path, &w, &h, &mask, &x, &y) != BitmapSuccess) {
XFreePixmap(dpy, bitmap);
return 0;
}
fg.pixel = scr->black_pixel;
bg.pixel = scr->white_pixel;
XQueryColor(dpy, scr->w_colormap, &fg);
XQueryColor(dpy, scr->w_colormap, &bg);
*cursor_out = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
XFreePixmap(dpy, bitmap);
XFreePixmap(dpy, mask);
return 1;
}
static void x11_cursor_free(Cursor cursor)
{
if (cursor != None)
XFreeCursor(dpy, cursor);
}
static void x11_cursor_set(WNativeWindow window, Cursor cursor)
{
XDefineCursor(dpy, (Window)window, cursor);
}
/* -------------------------------------------------------------------- */
/* Client operations (Phase 80) */
/* -------------------------------------------------------------------- */
@ -3750,6 +3790,10 @@ const WMBackend x11_backend = {
.context_init = x11_context_init,
.query_tree = x11_query_tree,
.screen_for_window = x11_screen_for_window,
.parse_color = x11_parse_color,
.cursor_create_from_files = x11_cursor_create_from_files,
.cursor_free = x11_cursor_free,
.cursor_set = x11_cursor_set,
};
/*

View File

@ -1672,7 +1672,7 @@ static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
return NULL;
val = WMGetFromPLString(elem);
if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
if (!wm_backend->parse_color(scr, val, &color)) {
wwarning(_("\"%s\" is not a valid color name"), val);
return NULL;
}
@ -1702,7 +1702,7 @@ static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
return NULL;
val = WMGetFromPLString(elem);
if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
if (!wm_backend->parse_color(scr, val, &xcolor)) {
wwarning(_("\"%s\" is not a valid color name"), val);
return NULL;
}
@ -1718,7 +1718,7 @@ static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
}
val = WMGetFromPLString(elem);
if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
if (!wm_backend->parse_color(scr, val, &xcolor)) {
wwarning(_("\"%s\" is not a valid color name"), val);
return NULL;
}
@ -1747,7 +1747,7 @@ static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
return NULL;
val = WMGetFromPLString(elem);
if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
if (!wm_backend->parse_color(scr, val, &xcolor)) {
wwarning(_("\"%s\" is not a valid color name"), val);
return NULL;
}
@ -1769,7 +1769,7 @@ static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
return NULL;
val = WMGetFromPLString(elem);
if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
if (!wm_backend->parse_color(scr, val, &xcolor)) {
wwarning(_("\"%s\" is not a valid color name"), val);
return NULL;
}
@ -1820,7 +1820,7 @@ static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
}
val = WMGetFromPLString(elem);
if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
if (!wm_backend->parse_color(scr, val, &color)) {
wwarning(_("\"%s\" is not a valid color name"), val);
for (--i; i >= 0; --i) {
wfree(colors[i]);
@ -1859,7 +1859,7 @@ static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
}
val = WMGetFromPLString(elem);
if (!XParseColor(dpy, scr->w_colormap, val, &color)) {
if (!wm_backend->parse_color(scr, val, &color)) {
wwarning(_("\"%s\" is not a valid color name"), val);
return NULL;
}
@ -1896,7 +1896,7 @@ static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
return NULL;
val = WMGetFromPLString(elem);
if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
if (!wm_backend->parse_color(scr, val, &xcolor)) {
wwarning(_("\"%s\" is not a valid color name"), val);
return NULL;
}
@ -1912,7 +1912,7 @@ static WTexture *parse_texture(WScreen * scr, WMPropList * pl)
}
val = WMGetFromPLString(elem);
if (!XParseColor(dpy, scr->w_colormap, val, &xcolor)) {
if (!wm_backend->parse_color(scr, val, &xcolor)) {
wwarning(_("\"%s\" is not a valid color name"), val);
return NULL;
}
@ -2218,7 +2218,7 @@ static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value,
}
/* get key */
ksym = XStringToKeysym(b);
ksym = (KeySym)wm_backend->keysym_from_name(b);
if (ksym == NoSymbol) {
wwarning(_("%s:invalid kbd shortcut specification \"%s\""), entry->key, val);
@ -2366,18 +2366,9 @@ static int parse_cursor(WScreen * scr, WMPropList * pl, Cursor * cursor)
wwarning(_("could not find cursor bitmap file \"%s\""), val);
return (status);
}
mask_status = XReadBitmapFile(dpy, scr->w_win, mask_name, &w, &h, &mask, &x, &y);
bitmap_status = XReadBitmapFile(dpy, scr->w_win, bitmap_name, &w, &h, &bitmap, &x, &y);
if ((BitmapSuccess == bitmap_status) && (BitmapSuccess == mask_status)) {
fg.pixel = scr->black_pixel;
bg.pixel = scr->white_pixel;
XQueryColor(dpy, scr->w_colormap, &fg);
XQueryColor(dpy, scr->w_colormap, &bg);
*cursor = XCreatePixmapCursor(dpy, bitmap, mask, &fg, &bg, x, y);
mask_status = wm_backend->cursor_create_from_files(scr, bitmap_name, mask_name, cursor);
if (mask_status)
status = 1;
}
check_bitmap_status(bitmap_status, bitmap_name, bitmap);
check_bitmap_status(mask_status, mask_name, mask);
wfree(bitmap_name);
wfree(mask_name);
}
@ -3140,7 +3131,7 @@ static int setKeyGrab(WScreen * scr, WDefaultEntry * entry, void *tdata, void *e
wwin = scr->focused_window;
while (wwin != NULL) {
XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
wm_backend->key_ungrab_all((WNativeWindow)wwin->frame->core->window);
if (!WFLAGP(wwin, no_bind_keys)) {
wWindowSetKeyGrabs(wwin);
@ -3434,13 +3425,13 @@ static int setCursor(WScreen * scr, WDefaultEntry * entry, void *tdata, void *ex
(void) entry;
if (wPreferences.cursor[widx] != None) {
XFreeCursor(dpy, wPreferences.cursor[widx]);
wm_backend->cursor_free(wPreferences.cursor[widx]);
}
wPreferences.cursor[widx] = *cursor;
if (widx == WCUR_ROOT && *cursor != None) {
XDefineCursor(dpy, scr->root_win, *cursor);
wm_backend->cursor_set((WNativeWindow)scr->root_win, *cursor);
}
return 0;