[comp.windows.x] Need 8/24 bit colormap help

devin@samwise.Colorado.EDU (Yampalimardilor) (09/09/90)

I have a program that does a lot of 8-bit imaging stuff.

I need it to run on a 24-bit machine that does have an 8-bit visual.
Several visuals, in fact.

What should I do?

I get a BadMatch or something similar when I do XSetWindowColormap.

		-Devin

***********************************************************************
* Yampalimardilor          *     a.k.a Devin Hooker (RP90) DoD # 0034 *
* Mage School, Glantri     *           University of Colorado-Boulder *
* (Master of Movement)     *           (Undergrad Student)            *
***********************************************************************

thoth@reef.cis.ufl.edu (Gilligan) (09/10/90)

  Funny, I think I just solved this problem yesterday.  I doubt it is
your XSetWindowColormap call failing.  It's probably the XCreateWindow
call.  If you create the window WITHOUT SETTING the colormap field of
the XSetWindowAttributes structure the window will be created with its
parent's colormap which is a BadMatch (colormap from different
visual).  A subsequent attempt to set the colormap will fail because
the X server is already pissed off and there is no such window.  The
code on page 210 in Book 1 (purple or cyan) is BOGUS.

  Here's my code fragment that works on our R4 Sun 3/80s and 3/60s.
It won't do exactly what you want but I think it's a good example of
how to create window's under bizzarre visuals.


  xvi.class = StaticGray;
  vlist = XGetVisualInfo(dpy, (long)VisualClassMask, &xvi, &number);
  if (!number)
    {
      printf("No visuals. gbye\n");
      exit(1);
    }

  screen = vlist->screen;
  rwin = RootWindow(dpy,screen);

  cmap = XCreateColormap(dpy, rwin, vlist->visual, AllocNone);
  xswa.colormap = cmap;
  win = XCreateWindow(dpy, rwin, 0, 0, width, height, 1, vlist->depth,
		      InputOutput, vlist->visual, (long)CWColormap, &xswa);
#if 0
  /* this doesn't work because the creation of the window fails.
     You must create the window with the colormap set in the
     XSetWindowAttributes structure or it will BadMatch trying
     to use its parent's.
     */
  XSetWindowColormap(dpy, win, cmap);
#endif
--
#perl -ne
#/--------------------
print "a window is a terrible thing to paste -", $me;
#( My name's not really Gilligan, It's Robert Forsman, without an `e' )
s/Gilligan/Robert Foresman/g;
s/Foresman/Forsman/g;
#--------------------/