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

wmaker: set the color pixel for TrueColor display

As mentioned in commit 67e2f5e1ca,
for TrueColor display it's not necessary to allocate a color but
it is required to set the pixel property of the XColor.
This commit is contained in:
David Maciejak
2026-02-18 21:26:56 -05:00
committed by Carlos R. Mafra
parent cc0a652ea8
commit 75a8299d18

View File

@@ -35,20 +35,41 @@
#include "resources.h"
#include "screen.h"
static unsigned long scale_color_component(unsigned short value, unsigned long mask)
{
unsigned long m = mask;
int shift = 0, bits = 0;
if (!m)
return 0;
while (!(m & 1)) {
shift++;
m >>= 1;
}
while (m) {
bits++;
m >>= 1;
}
return ((unsigned long)(value >> (16 - bits)) & ((1UL << bits) - 1)) << shift;
}
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;
}
if (scr->w_visual->class == TrueColor) {
/* Compute pixel directly from RGB components using the visual's channel masks */
color->pixel = scale_color_component(color->red, scr->w_visual->red_mask)
| scale_color_component(color->green, scr->w_visual->green_mask)
| scale_color_component(color->blue, scr->w_visual->blue_mask);
return True;
}
if (!XAllocColor(dpy, colormap, color)) {
wwarning(_("could not allocate color \"%s\""), color_name);
return False;