[PATCH] Prevent XAllocColor() call on TrueColor display

2 views
Skip to first unread message

david.m...@gmail.com

unread,
Dec 25, 2025, 4:23:19 PM (7 days ago) 12/25/25
to Window Maker Development
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.
---
 src/framewin.c  | 12 ++++++------
 src/resources.c | 15 +++++++++++++--
 src/resources.h |  2 +-
 3 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/framewin.c b/src/framewin.c
index 3f03aa59..b11f414e 100644
--- a/src/framewin.c
+++ b/src/framewin.c
@@ -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)
diff --git a/src/resources.c b/src/resources.c
index 8a336008..ee427915 100644
--- a/src/resources.c
+++ b/src/resources.c
@@ -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];
 
diff --git a/src/resources.h b/src/resources.h
index a310c60b..7fe589f0 100644
--- a/src/resources.h
+++ b/src/resources.h
@@ -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);
 
--
2.43.0

0001-Prevent-XAllocColor-call-on-TrueColor-display.patch
Reply all
Reply to author
Forward
0 new messages