| Title: | "OSF/Motif" is a trademark |
| Notice: | MOTIF kit note in 7.* |
| Moderator: | GOOEY::GRASS |
| Created: | Mon Aug 07 1989 |
| Last Modified: | Thu Jun 05 1997 |
| Last Successful Update: | Fri Jun 06 1997 |
| Number of topics: | 5973 |
| Total number of notes: | 24620 |
Hello!
I have a X11 question rather than Motif:
How can I use a 256-entry r/w colormap in TrueColor? I know there are apps
that do this (SoftWindows and xv). I tried to use the following code, but
it keeps crashing with BadMatch:
Any help would be appreciated.
Amit
#include <malloc.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
void main(void)
{
Display *disp;
Colormap cmap;
Window win;
XVisualInfo vinfo[100];
XSetWindowAttributes attr;
Status stat;
disp = XOpenDisplay("doronx:0.0");
stat = XMatchVisualInfo(disp,0,8,PseudoColor,vinfo);
if(stat==0)
{
XCloseDisplay(disp);
exit(0);
}
XSync(disp,False);
win = XCreateWindow(disp,
DefaultRootWindow(disp),
0,0,100,76, /* x,y,w,h */
0, /* border */
8, /* depth */
InputOutput, /* input class */
vinfo[0].visual, /* pseudocolor visual */
0L,NULL); /* attribs */
XSync(disp,False);
if(win==0)
{
XCloseDisplay(disp);
exit(0);
}
cmap = XCreateColormap(disp,DefaultRootWindow(disp),
vinfo[0].visual,AllocAll);
if(cmap == 0)
{
XCloseDisplay(disp);
exit(0);
}
XSync(disp,False);
XSetWindowColormap(disp,win,cmap);
/* Main thing */
XSync(disp,False);
XDestroyWindow(disp,win);
XCloseDisplay(disp);
}
| T.R | Title | User | Personal Name | Date | Lines |
|---|---|---|---|---|---|
| 5961.1 | I figured it out, so I decided to put it here. | TAV02::AMIT | Amit Margalit | Mon May 05 1997 03:14 | 71 |
Hi!
Re: .0
I was getting BadMatch because when a window is a different depth than its
parent, it must be created with a matching colormap AND a border_pixel value.
I was creating the colormap after the window which is wrong. Here is a correct
version:
#include <malloc.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
void main(void)
{
Display *disp;
Colormap cmap;
Window win;
XVisualInfo vinfo[10];
XSetWindowAttributes attr;
Status stat;
int i;
XColor xclr[256];
disp = XOpenDisplay("doronx:0.0");
stat = XMatchVisualInfo(disp,0,8,PseudoColor,vinfo);
if(stat==0)
{
XCloseDisplay(disp);
exit(0);
}
cmap=XCreateColormap(disp,DefaultRootWindow(disp),vinfo[0].visual,AllocAll);
if(cmap == 0)
{
XCloseDisplay(disp);
exit(0);
}
for(i=0;i<256;i++)
{
xclr[i].red=i*256; xclr[i].green=i*128;
xclr[i].blue=~(i*256);
xclr[i].flags=DoRed|DoGreen|DoBlue;
xclr[i].pixel=i;
}
XStoreColors(disp,cmap,xclr,256);
attr.border_pixel=BlackPixel(disp,0);
attr.colormap=cmap;
win = XCreateWindow(disp,
DefaultRootWindow(disp),
0,0,100,76, /* x,y,w,h */
0,8, /* border,depth */
InputOutput, /* input class */
vinfo[0].visual, /* pseudocolor visual */
CWBorderPixel|CWColormap,&attr); /* attribs */
if(win==0)
{
XCloseDisplay(disp);
exit(0);
}
XMapWindow(disp,win); /* whop! we're on screen! */
XSync(disp,False);
scanf("%d",&i); /* just to wait until you press something */
XDestroyWindow(disp,win); /* that's all folks! */
XCloseDisplay(disp);
}
| |||||