Exemple #1
0
static Bool
setupStandardColormap(RContext *ctx, Atom property)
{
    if (!XmuLookupStandardColormap(ctx->dpy, ctx->screen_number,
                                   ctx->visual->visualid,
                                   ctx->depth, property,
                                   True, True)) {
        RErrorCode = RERR_STDCMAPFAIL;

        return False;
    }
    return True;
}
Exemple #2
0
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
}
Exemple #3
0
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);
}
Exemple #4
0
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;
}
Exemple #5
0
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);

}
Exemple #6
0
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;
}