1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-03-19 09:13:33 +01:00

Prevent XAllocColor() call on TrueColor display

As reported in bug https://github.com/window-maker/wmaker/issues/50
X11 XAllocColor() call from wGetColorForColormap() in src/resources.c is returning some errors
especially seen when running GZDoom.

TrueColor display has been the dominant standard for well over a decade, meaning almost all modern X servers default to a TrueColor visual.
The default colormap is predefined and read-only, making allocation with XAllocColor() unnecessary (and meaning no need to free it too).
The patch is checking the display visual, and in case the display is truecolor, it does not allocate or free the color, just looking up for it.
Once the patch applied, GZDoom is not reporting warnings anymore.
This commit is contained in:
David Maciejak
2025-12-25 16:19:05 -05:00
committed by Carlos R. Mafra
parent 3579c85af1
commit 67e2f5e1ca
3 changed files with 20 additions and 9 deletions

View File

@@ -58,14 +58,14 @@ static void paintButton(WCoreWindow * button, WTexture * texture,
static void updateTitlebar(WFrameWindow * fwin);
static void allocFrameBorderPixel(Colormap colormap, const char *color_name, unsigned long **pixel);
static void allocFrameBorderPixel(WFrameWindow *fwin, const char *color_name, unsigned long **pixel);
static void allocFrameBorderPixel(Colormap colormap, const char *color_name, unsigned long **pixel) {
static void allocFrameBorderPixel(WFrameWindow *fwin, const char *color_name, unsigned long **pixel) {
XColor xcol;
*pixel = NULL;
if (! wGetColorForColormap(colormap, color_name, &xcol))
if (! wGetColorForColormap(fwin->screen_ptr, fwin->colormap, color_name, &xcol))
return;
*pixel = wmalloc(sizeof(unsigned long));
@@ -412,9 +412,9 @@ void wFrameWindowUpdateBorders(WFrameWindow * fwin, int flags)
checkTitleSize(fwin);
allocFrameBorderPixel(fwin->colormap, WMGetColorRGBDescription(scr->frame_border_color), &fwin->border_pixel);
allocFrameBorderPixel(fwin->colormap, WMGetColorRGBDescription(scr->frame_focused_border_color), &fwin->focused_border_pixel);
allocFrameBorderPixel(fwin->colormap, WMGetColorRGBDescription(scr->frame_selected_border_color), &fwin->selected_border_pixel);
allocFrameBorderPixel(fwin, WMGetColorRGBDescription(scr->frame_border_color), &fwin->border_pixel);
allocFrameBorderPixel(fwin, WMGetColorRGBDescription(scr->frame_focused_border_color), &fwin->focused_border_pixel);
allocFrameBorderPixel(fwin, WMGetColorRGBDescription(scr->frame_selected_border_color), &fwin->selected_border_pixel);
if (flags & WFF_SELECTED) {
if (fwin->selected_border_pixel)

View File

@@ -35,8 +35,16 @@
#include "resources.h"
#include "screen.h"
int wGetColorForColormap(Colormap colormap, const char *color_name, XColor *color)
int wGetColorForColormap(WScreen *scr, Colormap colormap, const char *color_name, XColor *color)
{
if (scr->w_visual->class == TrueColor) {
XColor dummy_exact;
if (!XLookupColor(dpy, colormap, color_name, &dummy_exact, color)) {
wwarning(_("could not lookup color \"%s\""), color_name);
return False;
}
return True;
}
if (!XParseColor(dpy, colormap, color_name, color)) {
wwarning(_("could not parse color \"%s\""), color_name);
return False;
@@ -50,11 +58,14 @@ int wGetColorForColormap(Colormap colormap, const char *color_name, XColor *colo
int wGetColor(WScreen *scr, const char *color_name, XColor *color)
{
return wGetColorForColormap(scr->w_colormap, color_name, color);
return wGetColorForColormap(scr, scr->w_colormap, color_name, color);
}
void wFreeColor(WScreen * scr, unsigned long pixel)
{
if (scr->w_visual->class == TrueColor)
return;
if (pixel != scr->white_pixel && pixel != scr->black_pixel) {
unsigned long colors[1];

View File

@@ -21,7 +21,7 @@
#ifndef WMRESOURCES_H_
#define WMRESOURCES_H_
int wGetColorForColormap(Colormap colormap, const char *color_name, XColor *color);
int wGetColorForColormap(WScreen *scr, Colormap colormap, const char *color_name, XColor *color);
int wGetColor(WScreen *scr, const char *color_name, XColor *color);
void wFreeColor(WScreen *scr, unsigned long pixel);