void XmuDeleteStandardColormap(Display *dpy, int screen, Atom property) /* dpy; - specifies the X server to connect to * screen - specifies the screen of the display * property - specifies the standard colormap property */ { XStandardColormap *stdcmaps, *s; int count = 0; if (XGetRGBColormaps(dpy, RootWindow(dpy, screen), &stdcmaps, &count, property)) { for (s=stdcmaps; count > 0; count--, s++) { if ((s->killid == ReleaseByFreeingColormap) && (s->colormap != None) && (s->colormap != DefaultColormap(dpy, screen))) XFreeColormap(dpy, s->colormap); else if (s->killid != None) XKillClient(dpy, s->killid); } XDeleteProperty(dpy, RootWindow(dpy, screen), property); XFree((char *) stdcmaps); XSync(dpy, False); } }
Status XGetStandardColormap ( Display *dpy, Window w, XStandardColormap *cmap, Atom property) /* XA_RGB_BEST_MAP, etc. */ { Status stat; /* return value */ XStandardColormap *stdcmaps; /* will get malloced value */ int nstdcmaps; /* count of above */ stat = XGetRGBColormaps (dpy, w, &stdcmaps, &nstdcmaps, property); if (stat) { XStandardColormap *use; if (nstdcmaps > 1) { VisualID vid; Screen *sp = _XScreenOfWindow (dpy, w); int i; if (!sp) { if (stdcmaps) Xfree (stdcmaps); return False; } vid = sp->root_visual->visualid; for (i = 0; i < nstdcmaps; i++) { if (stdcmaps[i].visualid == vid) break; } if (i == nstdcmaps) { /* not found */ Xfree (stdcmaps); return False; } use = &stdcmaps[i]; } else { use = stdcmaps; } /* * assign only those fields which were in the pre-ICCCM version */ cmap->colormap = use->colormap; cmap->red_max = use->red_max; cmap->red_mult = use->red_mult; cmap->green_max = use->green_max; cmap->green_mult = use->green_mult; cmap->blue_max = use->blue_max; cmap->blue_mult = use->blue_mult; cmap->base_pixel = use->base_pixel; Xfree (stdcmaps); /* don't need alloced memory */ } return stat; }
/* Uses: dpy, scr, cmap. */ static XStandardColormap * x_get_std_cmap(gx_device_X * xdev, Atom prop) { int i; XStandardColormap *scmap, *sp; int nitems; if (XGetRGBColormaps(xdev->dpy, RootWindowOfScreen(xdev->scr), &scmap, &nitems, prop)) for (i = 0, sp = scmap; i < nitems; i++, sp++) if (xdev->cmap == sp->colormap) return sp; return NULL; }
void SoXtGLWidgetP::createVisual(void) { Display * const display = SoXt::getDisplay(); int trynum = 0; const int ARRAYSIZE = 256; int attrs[ARRAYSIZE]; int screen = DefaultScreen(display); while (this->normalvisual == NULL && trynum < 8) { int arraysize = this->buildGLAttrs(attrs, trynum); assert(arraysize < ARRAYSIZE); //this->normalvisual = glXChooseVisual(display, screen, attrs); trynum++; } if (this->normalvisual == NULL) { SoDebugError::post("SoXtGLWidget::buildWidget", "could not get satisfactory visual for GLX"); XtAppError(SoXt::getAppContext(), "SoXtGLWidget::buildWidget()"); } this->doublebuffer = ((trynum-1) & 0x02) ? FALSE : TRUE; if ((this->normalvisual->c_class != TrueColor) && (this->normalvisual->c_class != PseudoColor)) { SoDebugError::post("SoXtGLWidget::buildWidget", "Visual hasn't the necessary color capabilities"); XtAppError(SoXt::getAppContext(), "SoXtGLWidget::buildWidget()"); } #ifndef HAVE_LIBXMU SoDebugError::post("SoXtGLWidget::buildWidget", "SoXt does not support detecting best visual/colormap without the Xmu library (yet)"); exit(1); #else // HAVE_LIBXMU Colormap colors = (Colormap) NULL; XStandardColormap * cmaps = NULL; int nmaps = 0; if (XmuLookupStandardColormap(display, this->normalvisual->screen, this->normalvisual->visualid, this->normalvisual->depth, XA_RGB_DEFAULT_MAP, False, True) && XGetRGBColormaps(display, RootWindow(display, this->normalvisual->screen), &cmaps, &nmaps, XA_RGB_DEFAULT_MAP)) { SbBool found = FALSE; for (int i = 0; i < nmaps && ! found; i++) { if (cmaps[i].visualid == this->normalvisual->visualid) { #if SOXT_DEBUG && 0 SoDebugError::postInfo("SoXtGLWidget::buildWidget", "got shared color map"); #endif // SOXT_DEBUG colors = cmaps[i].colormap; XFree(cmaps); found = TRUE; } } if (! found) { colors = XCreateColormap(display, RootWindow(display, this->normalvisual->screen), this->normalvisual->visual, AllocNone); } } else { colors = XCreateColormap(display, RootWindow(display, this->normalvisual->screen), this->normalvisual->visual, AllocNone); } this->colormap = colors; #endif // HAVE_LIBXMU }
int main(int argc, char ** argv) { setbuf(stdout, NULL); setbuf(stderr, NULL); Display * display = XOpenDisplay(NULL); assert(display != NULL); XSynchronize(display, True); XtAppContext context = XtCreateApplicationContext(); Widget appshell = XtVaAppInitialize(&context, "SoXtTest", NULL, 0, &argc, argv, NULL, NULL); fprintf(stderr, "appshell: %p\n", appshell); #if WANT_VISUALID int i, numvisuals; unsigned int wanted = WANT_VISUALID; XVisualInfo templ; XVisualInfo * visuals = XGetVisualInfo(display, VisualNoMask, &templ, &numvisuals); for ( i = 0; i < numvisuals; i++ ) { if ( visuals[i].visualid == wanted ) goto selected; } assert(0 && "no visual selected"); selected: Visual * visual = visuals[i].visual; int visualid = visuals[i].visualid; int depth = visuals[i].depth; Colormap colormap = 0; fprintf(stderr, "visualid: %d, depth: %d, class: %s\n", visualid, depth, visuals[i].c_class == DirectColor ? "DirectColor" : "Other"); int numcmaps; XStandardColormap * stdcolormaps = NULL; if ( XmuLookupStandardColormap(display, visuals[i].screen, visuals[i].visualid, visuals[i].depth, XA_RGB_DEFAULT_MAP, False, True) && XGetRGBColormaps(display, RootWindow(display, visuals[i].screen), &stdcolormaps, &numcmaps, XA_RGB_DEFAULT_MAP) ) { for ( int j = 0; j < numcmaps; j++ ) { if (stdcolormaps[j].visualid == visuals[i].visualid) { colormap = stdcolormaps[j].colormap; goto cont; } } colormap = XCreateColormap(display, RootWindow(display, visuals[i].screen), visuals[i].visual, AllocNone); fprintf(stderr, "standard RGB colormaps did not work with visual - created own (%ld)", colormap); } else { assert(0); } cont: fprintf(stderr, "colormap: %ld\n", colormap); #else Visual * visual = NULL; int depth = 0; Colormap colormap = 0; int snum = XDefaultScreen(display); visual = XDefaultVisual(display, snum); depth = XDefaultDepth(display, snum); colormap = XDefaultColormap(display, snum); fprintf(stderr, "visual: %p, depth: %d\n", visual, depth); fprintf(stderr, "colormap: %ld\n", colormap); #endif XtVaSetValues(appshell, XmNwidth, 100, XmNheight, 100, XmNvisual, visual, XmNcolormap, colormap, XmNdepth, depth, NULL); Widget form = XtVaCreateManagedWidget( "form", xmFormWidgetClass, appshell, NULL); Widget button = XtVaCreateManagedWidget( "button", xmPushButtonWidgetClass, form, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL); Pixmap pixmap = createPixmapFromXpm(button, home_xpm); XtVaSetValues(button, XmNlabelType, XmPIXMAP, XmNlabelPixmap, pixmap, XmNlabelInsensitivePixmap, pixmap, XmNselectPixmap, pixmap, XmNselectInsensitivePixmap, pixmap, NULL); Widget list[] = { appshell, form, button, NULL }; XtSetWMColormapWindows(appshell, list, 3); XtRealizeWidget(appshell); XtAppMainLoop(context); }
static Colormap choose_cmap( Display *dpy, XVisualInfo *vi ) { if ( !cmap_dict ) { cmap_dict = new QIntDict<CMapEntry>; const char *v = glXQueryServerString( dpy, vi->screen, GLX_VERSION ); if ( v ) mesa_gl = strstr(v,"Mesa") != 0; qAddPostRoutine( cleanup_cmaps ); } CMapEntry *x = cmap_dict->find( (long) vi->visualid + ( vi->screen * 256 ) ); if ( x ) // found colormap for visual return x->cmap; x = new CMapEntry(); XStandardColormap *c; int n, i; // qDebug( "Choosing cmap for vID %0x", vi->visualid ); if ( vi->visualid == XVisualIDFromVisual( (Visual*)QPaintDevice::x11AppVisual( vi->screen ) ) ) { // qDebug( "Using x11AppColormap" ); return QPaintDevice::x11AppColormap( vi->screen ); } if ( mesa_gl ) { // we're using MesaGL Atom hp_cmaps = XInternAtom( dpy, "_HP_RGB_SMOOTH_MAP_LIST", TRUE ); if ( hp_cmaps && vi->visual->c_class == TrueColor && vi->depth == 8 ) { if ( XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n, hp_cmaps) ) { i = 0; while ( i < n && x->cmap == 0 ) { if ( c[i].visualid == vi->visual->visualid ) { x->cmap = c[i].colormap; x->scmap = c[i]; //qDebug( "Using HP_RGB scmap" ); } i++; } XFree( (char *)c ); } } } #if !defined(Q_OS_SOLARIS) if ( !x->cmap ) { #ifdef QT_DLOPEN_OPENGL typedef Status (*_XmuLookupStandardColormap)( Display *dpy, int screen, VisualID visualid, unsigned int depth, Atom property, Bool replace, Bool retain ); _XmuLookupStandardColormap qt_XmuLookupStandardColormap; qt_XmuLookupStandardColormap = (_XmuLookupStandardColormap) QLibrary::resolve("Xmu", "XmuLookupStandardColormap"); if (!qt_XmuLookupStandardColormap) qFatal("Unable to resolve Xmu symbols - please check your Xmu library installation."); #define XmuLookupStandardColormap qt_XmuLookupStandardColormap #endif if ( XmuLookupStandardColormap(dpy,vi->screen,vi->visualid,vi->depth, XA_RGB_DEFAULT_MAP,FALSE,TRUE) ) { if ( XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n, XA_RGB_DEFAULT_MAP) ) { i = 0; while ( i < n && x->cmap == 0 ) { if ( c[i].visualid == vi->visualid ) { x->cmap = c[i].colormap; x->scmap = c[i]; //qDebug( "Using RGB_DEFAULT scmap" ); } i++; } XFree( (char *)c ); } } } #endif if ( !x->cmap ) { // no shared cmap found x->cmap = XCreateColormap( dpy, RootWindow(dpy,vi->screen), vi->visual, AllocNone ); x->alloc = TRUE; // qDebug( "Allocating cmap" ); } // associate cmap with visualid cmap_dict->insert( (long) vi->visualid + ( vi->screen * 256 ), x ); return x->cmap; }
Colormap qt_gl_choose_cmap(Display *dpy, XVisualInfo *vi) { if (first_time) { const char *v = glXQueryServerString(dpy, vi->screen, GLX_VERSION); if (v) mesa_gl = (strstr(v, "Mesa") != 0); first_time = false; } CMapEntryHash *hash = cmap_handler()->cmap_hash; CMapEntryHash::ConstIterator it = hash->constFind((long) vi->visualid + (vi->screen * 256)); if (it != hash->constEnd()) return it.value()->cmap; // found colormap for visual if (vi->visualid == XVisualIDFromVisual((Visual *) QX11Info::appVisual(vi->screen))) { // qDebug("Using x11AppColormap"); return QX11Info::appColormap(vi->screen); } QCMapEntry *x = new QCMapEntry(); XStandardColormap *c; int n, i; // qDebug("Choosing cmap for vID %0x", vi->visualid); if (mesa_gl) { // we're using MesaGL Atom hp_cmaps = XInternAtom(dpy, "_HP_RGB_SMOOTH_MAP_LIST", true); if (hp_cmaps && vi->visual->c_class == TrueColor && vi->depth == 8) { if (XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n, hp_cmaps)) { i = 0; while (i < n && x->cmap == 0) { if (c[i].visualid == vi->visual->visualid) { x->cmap = c[i].colormap; x->scmap = c[i]; //qDebug("Using HP_RGB scmap"); } i++; } XFree((char *)c); } } } if (!x->cmap) { if (XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n, XA_RGB_DEFAULT_MAP)) { for (int i = 0; i < n && x->cmap == 0; ++i) { if (!c[i].red_max || !c[i].green_max || !c[i].blue_max || !c[i].red_mult || !c[i].green_mult || !c[i].blue_mult) continue; // invalid stdcmap if (c[i].visualid == vi->visualid) { x->cmap = c[i].colormap; x->scmap = c[i]; //qDebug("Using RGB_DEFAULT scmap"); } } XFree((char *)c); } } if (!x->cmap) { // no shared cmap found x->cmap = XCreateColormap(dpy, RootWindow(dpy,vi->screen), vi->visual, AllocNone); x->alloc = true; // qDebug("Allocating cmap"); } // colormap hash should be cleanup only when the QApplication dtor is called if (hash->isEmpty()) qAddPostRoutine(cleanup_cmaps); // associate cmap with visualid hash->insert((long) vi->visualid + (vi->screen * 256), x); return x->cmap; }
static Colormap getColormap(Display * dsp, XVisualInfo * vi, WINTYPE Req_Win_Type) { Status status; XStandardColormap *standardCmaps; int i, numCmaps; switch (vi->class) { case PseudoColor: if (Req_Win_Type >= 4) { if (MaxCmapsOfScreen(DefaultScreenOfDisplay(dsp)) == 1 && vi->visual == DefaultVisual(dsp, vi->screen)) { /* * Share the root colormap. */ return (DefaultColormap(dsp, vi->screen)); } else { /* * Get our own PseudoColor colormap. */ return (XCreateColormap(dsp, RootWindow(dsp, vi->screen), vi->visual, AllocNone)); } } else { /* * CI mode, real GLX never returns a PseudoColor visual * for RGB mode. */ return (XCreateColormap(dsp, RootWindow(dsp, vi->screen), vi->visual, AllocAll)); } break; case TrueColor: case DirectColor: status = XmuLookupStandardColormap(dsp, vi->screen, vi->visualid, vi->depth, XA_RGB_DEFAULT_MAP, /* * replace */ False, /* retain */ True); if (status == 1) { status = XGetRGBColormaps(dsp, RootWindow(dsp, vi->screen), &standardCmaps, &numCmaps, XA_RGB_DEFAULT_MAP); if (status == 1) for (i = 0; i < numCmaps; i++) if (standardCmaps[i].visualid == vi->visualid) { Colormap cmap; cmap = standardCmaps[i].colormap; XFree(standardCmaps); return (cmap); } } /* * If no standard colormap but TrueColor, just make a * private one. */ return (XCreateColormap(dsp, RootWindow(dsp, vi->screen), vi->visual, AllocNone)); break; case StaticColor: case StaticGray: case GrayScale: /* * Mesa supports these visuals */ return (XCreateColormap(dsp, RootWindow(dsp, vi->screen), vi->visual, AllocNone)); break; default: fprintf(stderr, "could not allocate colormap for visual type: %d.", vi->class); exit(-1); } return ((Colormap)NULL); }
int main(int argc, char *argv[]) { Display *dpy; int screen; register int i; XImage in_image_struct; XImage *in_image, *out_image; XSetWindowAttributes attributes; XVisualInfo vinfo, *vinfos; long mask; register char *buffer; unsigned long swaptest = 1; int count, stdcnt; unsigned buffer_size; int win_name_size; int ncolors; char *file_name = NULL; char *win_name; Bool inverse = False, rawbits = False, newmap = False; Bool onclick = True; Bool scale = False; int plane = -1; char *std = NULL; char *vis = NULL; char *display_name = NULL; char *fgname = NULL; char *bgname = NULL; char *geom = NULL; int gbits = 0; XSizeHints hints; XTextProperty textprop; XClassHint class_hint; XColor *colors = NULL, color, igncolor; Window image_win; Colormap colormap; XEvent event; register XExposeEvent *expose = (XExposeEvent *)&event; GC gc; XGCValues gc_val; XWDFileHeader header; XWDColor xwdcolor; FILE *in_file = stdin; char *map_name; Atom map_prop; XStandardColormap *stdmaps, *stdmap = NULL; char c; int win_width, win_height; progname = argv[0]; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-bg") == 0) { if (++i >= argc) usage(); bgname = argv[i]; continue; } if (strcmp(argv[i], "-display") == 0) { if (++i >= argc) usage(); display_name = argv[i]; continue; } if (strcmp(argv[i], "-fg") == 0) { if (++i >= argc) usage(); fgname = argv[i]; continue; } if (strcmp(argv[i], "-geometry") == 0) { if (++i >= argc) usage(); geom = argv[i]; continue; } if (strcmp(argv[i], "-help") == 0) { usage(); } if (strcmp(argv[i], "-in") == 0) { if (++i >= argc) usage(); file_name = argv[i]; continue; } if (strcmp(argv[i], "-inverse") == 0) { /* for compatibility */ inverse = True; continue; } if (strcmp(argv[i], "-new") == 0) { newmap = True; if (std) usage(); continue; } if (strcmp(argv[i], "-noclick") == 0) { onclick = False; continue; } if (strcmp(argv[i], "-plane") == 0) { if (++i >= argc) usage(); plane = atoi(argv[i]); continue; } if (strcmp(argv[i], "-raw") == 0) { rawbits = True; if (std) usage(); continue; } if (strcmp(argv[i], "-rv") == 0) { inverse = True; continue; } if (strcmp(argv[i], "-scale") == 0) { scale = True; continue; } if (strcmp(argv[i], "-split") == 0) { split = True; continue; } if (strcmp(argv[i], "-std") == 0) { if (++i >= argc) usage(); std = argv[i]; if (newmap || rawbits) usage(); continue; } if (strcmp(argv[i], "-vis") == 0) { if (++i >= argc) usage(); vis = argv[i]; continue; } usage(); } if (file_name) { in_file = fopen(file_name, "rb"); if (in_file == NULL) Error("Can't open input file as specified."); } #ifdef WIN32 else _setmode(fileno(in_file), _O_BINARY); #endif dpy = XOpenDisplay(display_name); if (dpy == NULL) { fprintf(stderr, "%s: unable to open display \"%s\"\n", progname, XDisplayName(display_name)); exit(1); } screen = DefaultScreen(dpy); /* * Read in header information. */ if(!Read((char *)&header, SIZEOF(XWDheader), 1, in_file)) Error("Unable to read dump file header."); if (*(char *) &swaptest) _swaplong((char *) &header, SIZEOF(XWDheader)); /* check to see if the dump file is in the proper format */ if (header.file_version != XWD_FILE_VERSION) { fprintf(stderr,"xwud: XWD file format version mismatch."); Error("exiting."); } if (header.header_size < SIZEOF(XWDheader)) { fprintf(stderr,"xwud: XWD header size is too small."); Error("exiting."); } /* alloc window name */ win_name_size = (header.header_size - SIZEOF(XWDheader)); if((win_name = malloc((unsigned) win_name_size + 6)) == NULL) Error("Can't malloc window name storage."); strcpy(win_name, "xwud: "); /* read in window name */ if(!Read(win_name + 6, sizeof(char), win_name_size, in_file)) Error("Unable to read window name from dump file."); /* initialize the input image */ in_image = &in_image_struct; in_image->depth = header.pixmap_depth; in_image->format = header.pixmap_format; in_image->xoffset = header.xoffset; in_image->data = NULL; in_image->width = header.pixmap_width; in_image->height = header.pixmap_height; in_image->bitmap_pad = header.bitmap_pad; in_image->bytes_per_line = header.bytes_per_line; in_image->byte_order = header.byte_order; in_image->bitmap_unit = header.bitmap_unit; in_image->bitmap_bit_order = header.bitmap_bit_order; in_image->bits_per_pixel = header.bits_per_pixel; in_image->red_mask = header.red_mask; in_image->green_mask = header.green_mask; in_image->blue_mask = header.blue_mask; if (!XInitImage(in_image)) Error("Invalid input image header data."); /* read in the color map buffer */ if((ncolors = header.ncolors)) { colors = (XColor *)malloc((unsigned) ncolors * sizeof(XColor)); if (!colors) Error("Can't malloc color table"); for (i = 0; i < ncolors; i++) { if(!Read((char *) &xwdcolor, SIZEOF(XWDColor), 1, in_file)) Error("Unable to read color map from dump file."); colors[i].pixel = xwdcolor.pixel; colors[i].red = xwdcolor.red; colors[i].green = xwdcolor.green; colors[i].blue = xwdcolor.blue; colors[i].flags = xwdcolor.flags; } if (*(char *) &swaptest) { for (i = 0; i < ncolors; i++) { _swaplong((char *) &colors[i].pixel, sizeof(long)); _swapshort((char *) &colors[i].red, 3 * sizeof(short)); } } } else /* no color map exists, turn on the raw option */ rawbits = True; /* alloc the pixel buffer */ buffer_size = Image_Size(in_image); if((buffer = malloc(buffer_size)) == NULL) Error("Can't malloc data buffer."); /* read in the image data */ if (!Read(buffer, sizeof(char), (int)buffer_size, in_file)) Error("Unable to read pixmap from dump file."); /* close the input file */ (void) fclose(in_file); if (plane >= in_image->depth) Error("plane number exceeds image depth"); if ((in_image->format == XYPixmap) && (plane >= 0)) { buffer += in_image->bytes_per_line * in_image->height * (in_image->depth - (plane + 1)); in_image->depth = 1; ncolors = 0; } if (in_image->bits_per_pixel == 1 && in_image->depth == 1) { in_image->format = XYBitmap; newmap = False; rawbits = True; } in_image->data = buffer; if (std) { map_name = malloc(strlen(std) + 9); strcpy(map_name, "RGB_"); strcat(map_name, std); strcat(map_name, "_MAP"); Latin1Upper(map_name); map_prop = XInternAtom(dpy, map_name, True); if (!map_prop || !XGetRGBColormaps(dpy, RootWindow(dpy, screen), &stdmaps, &stdcnt, map_prop)) Error("specified standard colormap does not exist"); } vinfo.screen = screen; mask = VisualScreenMask; if (vis) { char *vt; vt = malloc(strlen(vis) + 1); strcpy(vt, vis); Latin1Upper(vt); if (strcmp(vt, "STATICGRAY") == 0) { vinfo.class = StaticGray; mask |= VisualClassMask; } else if (strcmp(vt, "GRAYSCALE") == 0) {
static Status lookup(Display *dpy, int screen, VisualID visualid, Atom property, XStandardColormap *cnew, Bool replace) /* * dpy - specifies display connection * screen - specifies screen number * visualid - specifies visualid for std map * property - specifies colormap property name * cnew - specifies a standard colormap * replace - specifies whether to replace */ { register int i; int count; XStandardColormap *stdcmaps, *s; Window win = RootWindow(dpy, screen); /* The property does not already exist */ if (! XGetRGBColormaps(dpy, win, &stdcmaps, &count, property)) { if (cnew) XSetRGBColormaps(dpy, win, cnew, 1, property); return 0; } /* The property exists and is not describing the RGB_DEFAULT_MAP */ if (property != XA_RGB_DEFAULT_MAP) { if (replace) { XmuDeleteStandardColormap(dpy, screen, property); if (cnew) XSetRGBColormaps(dpy, win, cnew, 1, property); } XFree((char *)stdcmaps); return 1; } /* The property exists and is RGB_DEFAULT_MAP */ for (i=0, s=stdcmaps; (i < count) && (s->visualid != visualid); i++, s++) ; /* No RGB_DEFAULT_MAP property matches the given visualid */ if (i == count) { if (cnew) { XStandardColormap *m, *maps; s = (XStandardColormap *) malloc((unsigned) ((count+1) * sizeof (XStandardColormap))); for (i = 0, m = s, maps = stdcmaps; i < count; i++, m++, maps++) { m->colormap = maps->colormap; m->red_max = maps->red_max; m->red_mult = maps->red_mult; m->green_max = maps->green_max; m->green_mult = maps->green_mult; m->blue_max = maps->blue_max; m->blue_mult = maps->blue_mult; m->base_pixel = maps->base_pixel; m->visualid = maps->visualid; m->killid = maps->killid; } m->colormap = cnew->colormap; m->red_max = cnew->red_max; m->red_mult = cnew->red_mult; m->green_max = cnew->green_max; m->green_mult = cnew->green_mult; m->blue_max = cnew->blue_max; m->blue_mult = cnew->blue_mult; m->base_pixel = cnew->base_pixel; m->visualid = cnew->visualid; m->killid = cnew->killid; XSetRGBColormaps(dpy, win, s, ++count, property); free((char *) s); } XFree((char *) stdcmaps); return 0; } /* Found an RGB_DEFAULT_MAP property with a matching visualid */ if (replace) { /* Free old resources first - we may need them, particularly in * the default colormap of the screen. However, because of this, * it is possible that we will destroy the old resource and fail * to create a new one if XmuStandardColormap() fails. */ if (count == 1) { XmuDeleteStandardColormap(dpy, screen, property); if (cnew) XSetRGBColormaps(dpy, win, cnew, 1, property); } else { XStandardColormap *map; /* s still points to the matching standard colormap */ if (s->killid == ReleaseByFreeingColormap) { if ((s->colormap != None) && (s->colormap != DefaultColormap(dpy, screen))) XFreeColormap(dpy, s->colormap); } else if (s->killid != None) XKillClient(dpy, s->killid); map = (cnew) ? cnew : stdcmaps + --count; s->colormap = map->colormap; s->red_max = map->red_max; s->red_mult = map->red_mult; s->green_max = map->green_max; s->green_mult = map->green_mult; s->blue_max = map->blue_max; s->blue_mult = map->blue_mult; s->visualid = map->visualid; s->killid = map->killid; XSetRGBColormaps(dpy, win, stdcmaps, count, property); } } XFree((char *) stdcmaps); return 1; }
static Colormap choose_cmap( Display *dpy, XVisualInfo *vi ) { if ( !cmap_dict ) { cmap_dict = new QIntDict<CMapEntry>; const char *v = glXQueryServerString( dpy, vi->screen, GLX_VERSION ); if ( v ) mesa_gl = strstr(v,"Mesa") != 0; qAddPostRoutine( cleanup_cmaps ); } CMapEntry *x = cmap_dict->find( (long)vi->visualid ); if ( x ) // found colormap for visual return x->cmap; x = new CMapEntry(); XStandardColormap *c; int n, i; //qDebug( "Choosing cmap for vID %0x", vi->visualid ); if ( vi->visualid == XVisualIDFromVisual( (Visual*)QPaintDevice::x11AppVisual() ) ) { //qDebug( "Using x11AppColormap" ); return QPaintDevice::x11AppColormap(); } if ( mesa_gl ) { // we're using MesaGL Atom hp_cmaps = XInternAtom( dpy, "_HP_RGB_SMOOTH_MAP_LIST", TRUE ); if ( hp_cmaps && vi->visual->c_class == TrueColor && vi->depth == 8 ) { if ( XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n, hp_cmaps) ) { i = 0; while ( i < n && x->cmap == 0 ) { if ( c[i].visualid == vi->visual->visualid ) { x->cmap = c[i].colormap; x->scmap = c[i]; //qDebug( "Using HP_RGB scmap" ); } i++; } XFree( (char *)c ); } } } #if !defined(_OS_SOLARIS_) if ( !x->cmap ) { if ( XmuLookupStandardColormap(dpy,vi->screen,vi->visualid,vi->depth, XA_RGB_DEFAULT_MAP,FALSE,TRUE) ) { if ( XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n, XA_RGB_DEFAULT_MAP) ) { i = 0; while ( i < n && x->cmap == 0 ) { if ( c[i].visualid == vi->visualid ) { x->cmap = c[i].colormap; x->scmap = c[i]; //qDebug( "Using RGB_DEFAULT scmap" ); } i++; } XFree( (char *)c ); } } } #endif if ( !x->cmap ) { // no shared cmap found x->cmap = XCreateColormap( dpy, RootWindow(dpy,vi->screen), vi->visual, AllocNone ); x->alloc = TRUE; //qDebug( "Allocating cmap" ); } cmap_dict->insert( (long)vi->visualid, x ); // associate cmap with visualid return x->cmap; }