Subject: TrueColor bug in FvwmForm (patch included).

From: Chris Laas <[email-masked]>
Date: Sat, 20 Jul 1996 04:18:59 -0400

Hi, I'm new to this list, so if I'm really off-topic, just send me to /dev/null.

I noticed a very annoying bug in FvwmForm where it only comes up in monochrome
on any static-colormap visuals (i.e. TrueColor, StaticColor, and StaticGray).
The bug was trivial to locate and fix; FvwmForm used to assume a read-write
colormap.  I have included a patch after my signature to fix this.

Is there someone else I should mail this patch to in order to get it in the next
fvwm beta?

--Chris Laas

-- 
"If A equals success, then the formula is A = X + Y + Z.  X is work.  Y is
play.  Z is keep your mouth shut." -- Albert Einstein

"I'm not like John Lennon, who thought he was the Almighty.  I just think I'm
John Lennon." -- Noel Gallagher, lead singer, guitarist, and songwriter of
Oasis, on the importance of remaining humble despite great fame.

Chris "Xris" Laas (that's me!) can be found lurking at [email-masked] or
[email-masked].  If I say something wrong, don't hold Dream Communications
responsible; however, if I have an idea inspired by genius, Dreamcom owns it.

-------patch.FvwmForm.c begin---------------cut here--------------------------
603a604
>   Visual* visual = DefaultVisual(dpy, screen);
610,611c611,671
<   } else if (!XAllocColorCells(dpy, d_cmap, 0,
<                              NULL, 0, colors, 6)) {
---
>   } else if (visual->class == TrueColor ||
>                        visual->class == StaticColor ||
>                        visual->class == StaticGray) {
>     if (XParseColor(dpy, d_cmap, color_names[c_fore], &xc_item) &&
>               XAllocColor(dpy, d_cmap, &xc_item))
>         colors[c_fore] = xc_item.pixel;
>       else
>         colors[c_fore] = BlackPixel(dpy, screen);
> 
>     if (XParseColor(dpy, d_cmap, color_names[c_back], &xc_item) &&
>               XAllocColor(dpy, d_cmap, &xc_item))
>         colors[c_back] = xc_item.pixel;
>       else
>         colors[c_back] = WhitePixel(dpy, screen);
> 
>     if (XParseColor(dpy, d_cmap, color_names[c_itemfore], &xc_item) &&
>               XAllocColor(dpy, d_cmap, &xc_item))
>         colors[c_itemfore] = xc_item.pixel;
>       else
>         colors[c_itemfore] = BlackPixel(dpy, screen);
> 
>     if (XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item) &&
>               XAllocColor(dpy, d_cmap, &xc_item))
>         colors[c_itemback] = xc_item.pixel;
>       else
>         colors[c_itemback] = WhitePixel(dpy, screen);
> 
>     if (XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item)) {
>         red = (int) xc_item.red ;
>         green = (int) xc_item.green ;
>         blue = (int) xc_item.blue ;
>         xc_item.red = (60 * red) / 100 ;
>         xc_item.green = (60 * green) / 100 ;
>         xc_item.blue = (60 * blue) / 100 ;
>         if (XAllocColor(dpy, d_cmap, &xc_item))
>               colors[c_itemlo] = xc_item.pixel;
>         else
>               colors[c_itemlo] = BlackPixel(dpy, screen);
>       } else
>         colors[c_itemlo] = BlackPixel(dpy, screen);
> 
>     if (XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item)) {
>         tmp1 = (14 * red) / 10 ;
>         if (tmp1 > MAX_INTENSITY) tmp1 = MAX_INTENSITY ;
>         tmp2 = (MAX_INTENSITY + red) / 2 ;
>         xc_item.red = (tmp1 > tmp2) ? tmp1 : tmp2 ;
>         tmp1 = (14 * green) / 10 ;
>         if (tmp1 > MAX_INTENSITY) tmp1 = MAX_INTENSITY ;
>         tmp2 = (MAX_INTENSITY + green) / 2 ;
>         xc_item.green = (tmp1 > tmp2) ? tmp1 : tmp2 ;
>         tmp1 = (14 * blue) / 10 ;
>         if (tmp1 > MAX_INTENSITY) tmp1 = MAX_INTENSITY ;
>         tmp2 = (MAX_INTENSITY + blue) / 2 ;
>         xc_item.blue = (tmp1 > tmp2) ? tmp1 : tmp2 ;
>         if (XAllocColor(dpy, d_cmap, &xc_item))
>               colors[c_itemhi] = xc_item.pixel;
>         else
>               colors[c_itemhi] = BlackPixel(dpy, screen);
>       } else
>         colors[c_itemhi] = BlackPixel(dpy, screen);
>   } else if (!XAllocColorCells(dpy, d_cmap, 0, NULL, 0, colors, 6)) {
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Jason L Tibbitts III <[email-masked]>
Date: 21 Jul 1996 10:56:06 -0500

>>>>> "CL" == Chris Laas <[email-masked]> writes:

CL> Is there someone else I should mail this patch to in order to get it in
CL> the next fvwm beta?

This should do it, but when you submit a patch, please use either a context
diff or a unified diff (diff -c or diff -u).  Your patch as submitted will
probably not apply if the line numbers don't match up.  Context and unified
diffs include a few lines before and after each changed blocks so that
patch can locate the modified section even if the line numbers have changed.
-- 
      Jason L. Tibbitts III - [email-masked] - 713/743-8684 - 221SR1
System Manager:  University of Houston High Performance Computing Center
                1994 PC800 "Kuroneko"      DoD# 1723
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Chris Laas <[email-masked]>
Date: Mon, 22 Jul 1996 17:40:54 -0400

Jason L Tibbitts III wrote:
> diff or a unified diff (diff -c or diff -u).

Thanks for correcting that bit of stupidity on my part.  That is especially true
in light of the fact that I was patching 2.0.42, while the current is 2.0.43.
In case it's necessary, I have attached a unified patch after my signature.

--Xris

---------begin patch.FvwmForm.c-----------cut here---------------------------
--- FvwmForm.c.orig     Fri Jul 19 02:50:26 1996
+++ FvwmForm.c  Mon Jul 22 17:29:08 1996
@@ -601,14 +601,74 @@
 /* allocate color cells */
 void GetColors ()
 {
+  Visual* visual = DefaultVisual(dpy, screen);
   XColor xc_item;
   int red, green, blue, tmp1, tmp2 ;
   if (scr_depth < 8) {
     colors[c_back] = colors[c_itemback] = WhitePixel(dpy, screen);
     colors[c_fore] = colors[c_itemfore] = colors[c_itemlo] = colors[c_itemhi]
       = BlackPixel(dpy, screen);
-  } else if (!XAllocColorCells(dpy, d_cmap, 0,
-                              NULL, 0, colors, 6)) {
+  } else if (visual->class == TrueColor ||
+                        visual->class == StaticColor ||
+                        visual->class == StaticGray) {
+    if (XParseColor(dpy, d_cmap, color_names[c_fore], &xc_item) &&
+               XAllocColor(dpy, d_cmap, &xc_item))
+         colors[c_fore] = xc_item.pixel;
+       else
+         colors[c_fore] = BlackPixel(dpy, screen);
+
+    if (XParseColor(dpy, d_cmap, color_names[c_back], &xc_item) &&
+               XAllocColor(dpy, d_cmap, &xc_item))
+         colors[c_back] = xc_item.pixel;
+       else
+         colors[c_back] = WhitePixel(dpy, screen);
+
+    if (XParseColor(dpy, d_cmap, color_names[c_itemfore], &xc_item) &&
+               XAllocColor(dpy, d_cmap, &xc_item))
+         colors[c_itemfore] = xc_item.pixel;
+       else
+         colors[c_itemfore] = BlackPixel(dpy, screen);
+
+    if (XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item) &&
+               XAllocColor(dpy, d_cmap, &xc_item))
+         colors[c_itemback] = xc_item.pixel;
+       else
+         colors[c_itemback] = WhitePixel(dpy, screen);
+
+    if (XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item)) {
+         red = (int) xc_item.red ;
+         green = (int) xc_item.green ;
+         blue = (int) xc_item.blue ;
+         xc_item.red = (60 * red) / 100 ;
+         xc_item.green = (60 * green) / 100 ;
+         xc_item.blue = (60 * blue) / 100 ;
+         if (XAllocColor(dpy, d_cmap, &xc_item))
+               colors[c_itemlo] = xc_item.pixel;
+         else
+               colors[c_itemlo] = BlackPixel(dpy, screen);
+       } else
+         colors[c_itemlo] = BlackPixel(dpy, screen);
+
+    if (XParseColor(dpy, d_cmap, color_names[c_itemback], &xc_item)) {
+         tmp1 = (14 * red) / 10 ;
+         if (tmp1 > MAX_INTENSITY) tmp1 = MAX_INTENSITY ;
+         tmp2 = (MAX_INTENSITY + red) / 2 ;
+         xc_item.red = (tmp1 > tmp2) ? tmp1 : tmp2 ;
+         tmp1 = (14 * green) / 10 ;
+         if (tmp1 > MAX_INTENSITY) tmp1 = MAX_INTENSITY ;
+         tmp2 = (MAX_INTENSITY + green) / 2 ;
+         xc_item.green = (tmp1 > tmp2) ? tmp1 : tmp2 ;
+         tmp1 = (14 * blue) / 10 ;
+         if (tmp1 > MAX_INTENSITY) tmp1 = MAX_INTENSITY ;
+         tmp2 = (MAX_INTENSITY + blue) / 2 ;
+         xc_item.blue = (tmp1 > tmp2) ? tmp1 : tmp2 ;
+         if (XAllocColor(dpy, d_cmap, &xc_item))
+               colors[c_itemhi] = xc_item.pixel;
+         else
+               colors[c_itemhi] = BlackPixel(dpy, screen);
+       } else
+         colors[c_itemhi] = BlackPixel(dpy, screen);
+  } else if (!XAllocColorCells(dpy, d_cmap, 0, NULL, 0, colors, 6)) {
     colors[c_back] = colors[c_itemback] = WhitePixel(dpy, screen);
     colors[c_fore] = colors[c_itemfore] = colors[c_itemlo] = colors[c_itemhi]
       = BlackPixel(dpy, screen);
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].