static void draw_text (struct widget_xft_data *data, char *lbl, int inverse) { Screen *sc = XtScreen (data->widget); int screen = XScreenNumberOfScreen (sc); int y = data->xft_font->ascent; int x = inverse ? 0 : 2; char *bp = lbl; data->xft_draw = XftDrawCreate (XtDisplay (data->widget), data->p, DefaultVisual (XtDisplay (data->widget), screen), DefaultColormapOfScreen (sc)); XftDrawRect (data->xft_draw, inverse ? &data->xft_fg : &data->xft_bg, 0, 0, data->p_width, data->p_height); if (!inverse) y += 2; while (bp && *bp != '\0') { char *cp = strchr (bp, '\n'); XftDrawStringUtf8 (data->xft_draw, inverse ? &data->xft_bg : &data->xft_fg, data->xft_font, x, y, (FcChar8 *) bp, cp ? cp - bp : strlen (bp)); bp = cp ? cp + 1 : NULL; /* 1.2 gives reasonable line spacing. */ y += data->xft_font->height * 1.2; } }
static Cursor XbrCursorCreate(Display *display, Screen *screen, char *bits, int xhot, int yhot, int width, int height) { Cursor cursor; XColor colours[2]; Pixmap pixmap; Colormap colourmap = DefaultColormapOfScreen(screen); Window root = RootWindowOfScreen(screen); /* Find out the black & white pixel values */ XbrGfxBWPixels(display, screen, colourmap, &colours[0], &colours[1]); /* Convert the bitmap to a pixmap - we could use XbrReadBitmap but that requires a GC, so we use the normal X routine. */ pixmap = XCreatePixmapFromBitmapData(display, root, bits, width, height, colours[1].pixel, colours[0].pixel, 1); /* Create a cursor from the pixmap */ cursor = XCreatePixmapCursor(display, pixmap, pixmap, &colours[0], &colours[1], xhot, yhot); /* Free the pixmap now */ XFreePixmap(display, pixmap); return(cursor); }
static void fill_xft_data (struct widget_xft_data *data, Widget widget, XftFont *font) { Pixel bg, fg; XColor colors[2]; data->widget = widget; data->xft_font = font; XtVaGetValues (widget, XtNbackground, &bg, XtNforeground, &fg, NULL); colors[0].pixel = data->xft_fg.pixel = fg; colors[1].pixel = data->xft_bg.pixel = bg; XQueryColors (XtDisplay (widget), DefaultColormapOfScreen (XtScreen (widget)), colors, 2); data->xft_fg.color.alpha = 0xFFFF; data->xft_fg.color.red = colors[0].red; data->xft_fg.color.green = colors[0].green; data->xft_fg.color.blue = colors[0].blue; data->xft_bg.color.alpha = 0xFFFF; data->xft_bg.color.red = colors[1].red; data->xft_bg.color.green = colors[1].green; data->xft_bg.color.blue = colors[1].blue; data->p = None; data->xft_draw = 0; data->p_width = data->p_height = 0; }
void x11_draw_glyphs( Drawable drawable, GC gc, PangoFont *font, int x, int y, PangoGlyphString *glyphs, wxColour &colour ) { if (PANGO_XFT_IS_FONT (font)) { Display* xdisplay = wxGlobalDisplay(); int xscreen = DefaultScreen( xdisplay ); Visual* xvisual = DefaultVisual( xdisplay, xscreen ); Colormap xcolormap = DefaultColormapOfScreen( XScreenOfDisplay( xdisplay, xscreen ) ); XftDraw *draw = XftDrawCreate( xdisplay, drawable, xvisual, xcolormap ); XftColor color; color.pixel = 0; color.color.red = colour.Red() << 8; color.color.green = colour.Green() << 8; color.color.blue = colour.Blue() << 8; color.color.alpha = 65000; pango_xft_render( draw, &color, font, glyphs, x, y ); XftDrawDestroy( draw ); } }
static int module_init(Display *dpy) { int i; data.display = dpy; data.windows = (Window *)malloc(sizeof(Window) * ScreenCount(dpy)); for (i = 0; i < ScreenCount(dpy); i++) { Screen *screen = ScreenOfDisplay(dpy, i); Colormap colormap = DefaultColormapOfScreen(screen); XSetWindowAttributes xswa; XColor color; alock_alloc_color(dpy, colormap, data.colorname, "black", &color); xswa.override_redirect = True; xswa.colormap = colormap; xswa.background_pixel = color.pixel; data.windows[i] = XCreateWindow(dpy, RootWindowOfScreen(screen), 0, 0, WidthOfScreen(screen), HeightOfScreen(screen), 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect | CWColormap | CWBackPixel, &xswa); } return 0; }
Pixmap XcodaCreatePixmapFromXpm(Widget parent, const char** data, int type) { Display *dpy = XtDisplay(parent); Window win = XDefaultRootWindow(dpy); Screen *scr = XDefaultScreenOfDisplay(dpy); int depth = DefaultDepthOfScreen(scr); Colormap cmap = DefaultColormapOfScreen(scr); XpmAttributes attr; unsigned int valuemask = 0; int err; /*unsigned int pixmap_ret, pixmap_mask;*/ Pixmap pixmap_ret, pixmap_mask; XpmColorSymbol col_symbol[1]; Arg arg[5]; int ac = 0; Pixel parent_bg; if(type){ /* normal background for pixmap */ XtSetArg (arg[ac], XmNbackground, &parent_bg); ac++; XtGetValues (parent, arg, ac); ac = 0; } else{ /* inverted or highlighted pixmap */ XtSetArg (arg[ac], XmNforeground, &parent_bg); ac++; XtGetValues (parent, arg, ac); ac = 0; } col_symbol[0].name = (char *)NULL; col_symbol[0].value = (char *)malloc((strlen("LightBlue")+1)*sizeof(char)); strcpy(col_symbol[0].value,"LightBlue"); col_symbol[0].pixel = parent_bg; attr.colormap = cmap; attr.depth = depth; attr.colorsymbols = col_symbol; attr.valuemask = valuemask; attr.numsymbols = 1; attr.closeness = 65536; attr.valuemask |= XpmReturnPixels; attr.valuemask |= XpmColormap; attr.valuemask |= XpmColorSymbols; attr.valuemask |= XpmDepth; attr.valuemask |= XpmCloseness; /* printf("Calling XpmCreatePixmapFromData ...\n"); */ err = XpmCreatePixmapFromData(dpy, win, (char **)data, &pixmap_ret, &pixmap_mask, &attr); free (col_symbol[0].value); if(err != XpmSuccess){ pixmap_ret = 0; } return pixmap_ret; }
/* ** BeginWait/EndWait ** ** Display/Remove a watch cursor over topCursorWidget and its descendents */ void BeginWait(Widget topCursorWidget) { Display *display = XtDisplay(topCursorWidget); Pixmap pixmap; Pixmap maskPixmap; XColor xcolors[2]; static Cursor waitCursor = 0; /* if the watch cursor hasn't been created yet, create it */ if (!waitCursor) { pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display), (char *)watch_bits, watch_width, watch_height); maskPixmap = XCreateBitmapFromData(display, DefaultRootWindow(display), (char *)watch_mask_bits, watch_width, watch_height); xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(display)); xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(display)); XQueryColors(display, DefaultColormapOfScreen( DefaultScreenOfDisplay(display)), xcolors, 2); waitCursor = XCreatePixmapCursor(display, pixmap, maskPixmap, &xcolors[0], &xcolors[1], watch_x_hot, watch_y_hot); XFreePixmap(display, pixmap); XFreePixmap(display, maskPixmap); } /* display the cursor */ XDefineCursor(display, XtWindow(topCursorWidget), waitCursor); }
Cursor _Delay::hourglass_cursor() { if (hourglass_cache != 0) return hourglass_cache; Display *display = XtDisplay(widget); #if SMALL_HOURGLASS_CURSOR || LARGE_HORGLASS_CURSOR Screen *screen = XtScreen(widget); Window rootWindow = RootWindowOfScreen(screen); unsigned char *cursor_bits = time16_bits; unsigned char *cursor_mask_bits = time16m_bits; unsigned int cursor_width = time16_width; unsigned int cursor_height = time16_height; unsigned int cursor_x_hot = time16_x_hot; unsigned int cursor_y_hot = time16_y_hot; #if LARGE_HOURGLASS_CURSOR // Fetch cursor shape unsigned int width, height; XQueryBestCursor(display, rootWindow, 32, 32, &width, &height); Boolean largeCursors = (width >= 32 && height >= 32); if (largeCursors) { cursor_bits = time32_bits; cursor_mask_bits = time32m_bits; cursor_width = time32_width; cursor_height = time32_height; cursor_x_hot = time32_x_hot; cursor_y_hot = time32_y_hot; } #endif Pixmap cursor_pixmap = XCreateBitmapFromData(display, rootWindow, (char *)cursor_bits, cursor_width, cursor_height); Pixmap cursor_mask_pixmap = XCreateBitmapFromData(display, rootWindow, (char *)cursor_mask_bits, cursor_width, cursor_height); XColor cursor_colors[2]; cursor_colors[0].pixel = BlackPixelOfScreen(screen); cursor_colors[1].pixel = WhitePixelOfScreen(screen); XQueryColors(display, DefaultColormapOfScreen(screen), cursor_colors, 2); hourglass_cache = XCreatePixmapCursor(display, cursor_pixmap, cursor_mask_pixmap, cursor_colors, cursor_colors + 1, cursor_x_hot, cursor_y_hot); #else // Watch cursor hourglass_cache = XCreateFontCursor(display, XC_watch); #endif return hourglass_cache; }
// Set up a window. int initWindow( long width, long height ) { int defScreen; XSetWindowAttributes wAttr; XGCValues gcValues; char buffer[64] = "Graphics"; XTextProperty xtp = {(unsigned char *)buffer, 125, 8, strlen(buffer)}; /* * connect to the X server. uses the server specified in the * DISPLAY environment variable */ curDisplay = XOpenDisplay((char *) NULL); if ((Display *) NULL == curDisplay) { fprintf(stderr, "Fish School Stats Display: could not open display.\n"); exit(-1); } /* * begin to create a window */ defdepth = DefaultDepth(curDisplay,0); bytesPerPixel = defdepth/8; bytesPerPixel = bytesPerPixel == 3 ? 4 : bytesPerPixel; defScreen = DefaultScreen(curDisplay); curWindow = XCreateWindow(curDisplay, DefaultRootWindow(curDisplay), 10, 10, width, height, 0, defdepth, InputOutput, DefaultVisual(curDisplay, defScreen), 0, &wAttr); /* * request mouse button and keypress events */ wAttr.event_mask = ButtonPressMask | KeyPressMask | ExposureMask; XChangeWindowAttributes(curDisplay, curWindow, CWEventMask, &wAttr); /* * force it to appear on the screen */ XSetWMName(curDisplay, curWindow, &xtp); XMapWindow(curDisplay, curWindow); /* * create a graphics context. this stores a drawing state; stuff like * current color and line width. this gc is for drawing into our * window. */ curGC = XCreateGC(curDisplay, curWindow, 0, &gcValues); defaultFont = XQueryFont(curDisplay, XGContextFromGC(curGC)); XSetWindowColormap( curDisplay, curWindow, DefaultColormapOfScreen(DefaultScreenOfDisplay(curDisplay))); return(bytesPerPixel); }
unsigned long getColor( Display *dsp, unsigned short red, unsigned green, unsigned blue ) { XColor col; Colormap cmap = DefaultColormapOfScreen( ScreenOfDisplay( dsp, 0 ) ); col.red = (red + 1)*256 - 1; col.green = (green + 1)*256 - 1; col.blue = (blue + 1)*256 - 1; if (!XAllocColor( dsp, cmap, &col ) ) printf( "Can't alloc color\n" ); return col.pixel; }
Cursor MotifUI::InitHourGlassCursor() { unsigned int width; unsigned int height; unsigned int xHotspot; unsigned int yHotspot; Pixmap pixmap; Pixmap maskPixmap; XColor xcolors[2]; char * bits; char * maskBits; Cursor cursor = None; if (XQueryBestCursor(display, root, 32, 32, &width, &height)) { if ((width >= 32) && (height >= 32)) { width = time32_width; height = time32_height; bits = (char *)time32_bits; maskBits = (char *)time32m_bits; xHotspot = time32_x_hot; yHotspot = time32_y_hot; } else { width = time16_width; height = time16_height; bits = (char *)time16_bits; maskBits = (char *)time16m_bits; xHotspot = time16_x_hot; yHotspot = time16_y_hot; } pixmap = XCreateBitmapFromData(display, root, bits, width, height); maskPixmap = XCreateBitmapFromData(display, root, maskBits, width, height); xcolors[0].pixel = black; xcolors[1].pixel = white; XQueryColors(display, DefaultColormapOfScreen(DefaultScreenOfDisplay (display)), xcolors, 2); cursor = XCreatePixmapCursor(display, pixmap, maskPixmap, &(xcolors[0]), &(xcolors[1]), xHotspot, yHotspot); XFreePixmap(display, pixmap); XFreePixmap(display, maskPixmap); } return cursor; }
void XgraInitializeColors() { XColor ForgetIt; XColor GetIt; Window Root; int Counter; Colormap ColorMap; char Error; char *ColorName; autbegin(); ColorMap = DefaultColormapOfScreen ( XtScreen ( XgraGraphicWindow ) ); Error = False; for ( Counter = 0; Counter < XGRA_MAX_COLOR; Counter++ ) { if ( Counter < 5 ) { ColorName = *XgraColorName[ Counter ]; } else { ColorName = XGRA_LAYER_NAME_TABLE[ Counter - 5 ][ 1 ]; } if ( ColorName != (char *)NULL ) { if ( ! XAllocNamedColor( XgraGraphicDisplay, ColorMap, ColorName, &GetIt, &ForgetIt ) ) { fprintf ( stderr, "\nXmx100: Color name '%s' is not in X11 database !\n", ColorName ); Error = True; } XgraColor[ Counter ] = GetIt.pixel; } else { XgraColor[ Counter ] = XgraColor[ 0 ]; } } if ( Error == True ) exit( 1 ); autend(); }
void set_color (Widget widget, XtPointer client_data, XtPointer call_data) { String color = (String) client_data; Display *dpy = XtDisplay (widget); Colormap cmap = DefaultColormapOfScreen (XtScreen (widget)); XColor col, unused; if (!XAllocNamedColor (dpy, cmap, color, &col, &unused)) { printf ( "Can't alloc %s", color); return; } XSetForeground (dpy, gc, col.pixel); }
static Pixel allocRGB(Screen *screen, unsigned short red, unsigned short green, unsigned short blue) { Display *display = DisplayOfScreen(screen); XColor color; color.red = red; color.green = green; color.blue = blue; if (XAllocColor(display, DefaultColormapOfScreen(screen), &color)) return color.pixel; else return BlackPixelOfScreen(screen); }
WXColormap wxApp::GetMainColormap(WXDisplay* display) { if (!display) /* Must be called first with non-NULL display */ return m_mainColormap; int defaultScreen = DefaultScreen((Display*) display); Screen* screen = XScreenOfDisplay((Display*) display, defaultScreen); Colormap c = DefaultColormapOfScreen(screen); if (!m_mainColormap) m_mainColormap = (WXColormap) c; return (WXColormap) c; }
/*@ -usedef -compdef -mustfreefresh @*/ static void set_color(String color) { Display *dpy = XtDisplay(draww); Colormap cmap = DefaultColormapOfScreen(XtScreen(draww)); XColor col, unused; if (XAllocNamedColor(dpy, cmap, color, &col, &unused)==0) { char buf[32]; (void)snprintf(buf, sizeof(buf), "Can't alloc %s", color); XtWarning(buf); return; } (void)XSetForeground(dpy, drawGC, col.pixel); }
Cursor HelpAgent::create_help_cursor(Widget parent) { Display *display = XtDisplay(parent); Screen *retScr = XtScreen(parent); int screen = XScreenNumberOfScreen(retScr); char *bits; char *maskBits; unsigned int width; unsigned int height; unsigned int xHotspot; unsigned int yHotspot; Pixmap pixmap; Pixmap maskPixmap; XColor xcolors[2]; Cursor cursor; width = onitem32_width; height = onitem32_height; bits = (char *) onitem32_bits; maskBits = (char *) onitem32_m_bits; xHotspot = onitem32_x_hot; yHotspot = onitem32_y_hot; pixmap = XCreateBitmapFromData (display, RootWindowOfScreen(XtScreen(parent)), bits, width, height); maskPixmap = XCreateBitmapFromData (display, RootWindowOfScreen(XtScreen(parent)), maskBits, width, height); xcolors[0].pixel = BlackPixelOfScreen(ScreenOfDisplay(display, screen)); xcolors[1].pixel = WhitePixelOfScreen(ScreenOfDisplay(display, screen)); XQueryColors (display, DefaultColormapOfScreen(ScreenOfDisplay(display, screen)), xcolors, 2); cursor = XCreatePixmapCursor (display, pixmap, maskPixmap, &(xcolors[0]), &(xcolors[1]), xHotspot, yHotspot); XFreePixmap (display, pixmap); XFreePixmap (display, maskPixmap); return cursor; }
// Look for an existing Colormap that known to be associated with visual. static Colormap LookupColormapForVisual(const Screen* screen, const Visual* visual) { // common case if (visual == DefaultVisualOfScreen(screen)) return DefaultColormapOfScreen(screen); #ifdef MOZ_WIDGET_GTK2 // I wish there were a gdk_x11_display_lookup_screen. Display* dpy = DisplayOfScreen(screen); GdkDisplay* gdkDpy = gdk_x11_lookup_xdisplay(dpy); if (gdkDpy) { gint screen_num = 0; for (int s = 0; s < ScreenCount(dpy); ++s) { if (ScreenOfDisplay(dpy, s) == screen) { screen_num = s; break; } } GdkScreen* gdkScreen = gdk_display_get_screen(gdkDpy, screen_num); GdkColormap* gdkColormap = NULL; if (visual == GDK_VISUAL_XVISUAL(gdk_screen_get_rgb_visual(gdkScreen))) { // widget/src/gtk2/mozcontainer.c uses gdk_rgb_get_colormap() // which is inherited by child widgets, so this is the visual // expected when drawing directly to widget surfaces or surfaces // created using cairo_surface_create_similar with // CAIRO_CONTENT_COLOR. // gdk_screen_get_rgb_colormap is the generalization of // gdk_rgb_get_colormap for any screen. gdkColormap = gdk_screen_get_rgb_colormap(gdkScreen); } else if (visual == GDK_VISUAL_XVISUAL(gdk_screen_get_rgba_visual(gdkScreen))) { // This is the visual expected on displays with the Composite // extension enabled when the surface has been created using // cairo_surface_create_similar with CAIRO_CONTENT_COLOR_ALPHA, // as happens with non-unit opacity. gdkColormap = gdk_screen_get_rgba_colormap(gdkScreen); } if (gdkColormap != NULL) return GDK_COLORMAP_XCOLORMAP(gdkColormap); } #endif return None; }
void XfsmInitializeColorMap() { Display *ADisplay; Screen *AScreen; ADisplay = XtDisplay( XfsmTopLevel ); AScreen = XtScreen( XfsmTopLevel ); XfsmColorMap = DefaultColormapOfScreen( AScreen ); if ( XFSM_SWITCH_COLOR_MAP ) { XfsmColorMap = XCopyColormapAndFree( ADisplay, XfsmColorMap ); XInstallColormap( ADisplay, XfsmColorMap ); XtVaSetValues( XfsmTopLevel, XmNcolormap, XfsmColorMap, NULL ); } }
/*---------------------------------------------------------------------------- XbrGfxShadow() Get the shadow colours and set them for the given widget. Widget w The widget to wreck ----------------------------------------------------------------------------*/ void XbrGfxShadow(Widget w) { Pixel background, top_shadow, bottom_shadow; Screen *screen = XtScreen(w); /* Get the background pixel of the widget. */ XtVaGetValues(w, XmNbackground, &background, NULL); /* Generate the shadow colours */ XmGetColors(screen, DefaultColormapOfScreen(screen), background, NULL, &top_shadow, &bottom_shadow, NULL); /* Set shadow values. */ XtVaSetValues(w, XmNshadowThickness, 2, XmNtopShadowColor, top_shadow, XmNbottomShadowColor, bottom_shadow, NULL); }
/*@ -mustfreefresh -compdef +ignoresigns @*/ static Pixel get_pixel(Widget w, char *resource_value) { Colormap colormap; Boolean cstatus; XColor exact, color; colormap = DefaultColormapOfScreen( DefaultScreenOfDisplay(XtDisplay(w))); /*@i@*/cstatus = XAllocNamedColor(XtDisplay(w), colormap, resource_value, &color, &exact); if (cstatus == (Boolean)False) { (void)fprintf(stderr, "Unknown color: %s", resource_value); color.pixel = BlackPixelOfScreen( DefaultScreenOfDisplay(XtDisplay(w))); }; /*@i1@*/return (color.pixel); }
Color Color::getLighter() { Colormap cmap = DefaultColormapOfScreen(XtScreen(Application::getWidget())); XColor color; color.flags = DoRed|DoGreen|DoBlue; XAllocColor(XtDisplay(Application::getWidget()), cmap, &color); color.pixel = pixel; color.red += 50; color.green += 50; color.blue += 50; //XQueryColor(XtDisplay(Application::getWidget()), cmap, &color); //XStoreColor(XtDisplay(Application::getWidget()), cmap, &color); //XAllocColor(XtDisplay(Application::getWidget()), cmap, &color); return Color(color.pixel); }
int main(void) { Display *display; Window root; XWindowAttributes wa; GC g; char *colors[NCOLORS] = {"red", "green", "blue", "yellow"}; XColor xcolors[NCOLORS]; XColor xc, sc; int c; display = XOpenDisplay(getenv("Display")); root = DefaultRootWindow(display); g = XCreateGC(display, root, 0, NULL); //get root windows attributes XGetWindowAttributes(display, root, &wa); //allocate colors for(c=0; c<NCOLORS; c++) { XAllocNamedColor(display, DefaultColormapOfScreen(DefaultScreenOfDisplay(display)), colors[c], &sc, &xc); xcolors[c] = sc; } //draw while(1) { XSetForeground(display, g, xcolors[random()%NCOLORS].pixel); XFillRectangle(display, root, g, random()%(wa.width-50), random()%(wa.height-40), 50, 40); if(random()%500<1) XClearWindow(display, root); //flush and slepp XFlush(display); usleep(1*100000); } XCloseDisplay(display); return EXIT_SUCCESS; }
// CONSTRUCTOR fermi_view::fermi_view(Widget TopLevel) { char applresdir[1024]; char *trick_home; toplevel = TopLevel; display = XtDisplay(toplevel); screen = XtScreen(toplevel); colormap = DefaultColormapOfScreen(screen); xpos = 400; ypos = 50; width = 600; height = 700; trick_home = getenv("TRICK_HOME"); if (trick_home != NULL) { sprintf( applresdir,"%s/trick_source/data_products/DPX/APPS/FXPLOT",trick_home); setenv("XAPPLRESDIR", applresdir, 0); } else { std::cerr << "ERROR: $TRICK_HOME is not set." << std::endl; } }
static void SetWidgetColor( Widget w, char *color ) { Display *display; Colormap colormap; XColor newcolor; XColor unused; Arg Args[MAX_ARGS]; int n; display = XtDisplay(w); colormap = DefaultColormapOfScreen(XtScreen(w)); XAllocNamedColor( display, colormap, color, &newcolor, &unused ); n = 0; XtSetArg(Args[n], XmNbackground, newcolor.pixel ); n++; XtSetValues( w, Args, n ); return; }
unsigned long aX_get_color(Display *disp, int scr, unsigned long def_col, const char *color_name) { XColor color_def; Colormap def_map; Screen *scr_ptr; if(color_name == NULL) return def_col; scr_ptr = ScreenOfDisplay(disp, scr); def_map = DefaultColormapOfScreen(scr_ptr); if(XParseColor(disp, def_map, color_name, &color_def)) { if(XAllocColor(disp, def_map, &color_def)) return color_def.pixel; } else fprintf(stderr, "%s: aX_get_color: warning: Invalid color specification %s\n", prog_name, color_name); return def_col; }
Rgb2Pseudo* initRgb2Pseudo ( JNIEnv* env, jclass clazz, Toolkit* Tlk ) { Colormap dcm; int i, j, k; XColor xclr; Rgb2Pseudo *map; dcm = DefaultColormapOfScreen( DefaultScreenOfDisplay( Tlk->dsp)); map = (Rgb2Pseudo*) AWT_MALLOC( sizeof(Rgb2Pseudo)); xclr.flags = DoRed | DoGreen | DoBlue; for ( i=0; i<8; i++ ){ for ( j=0; j<8; j++ ) { for ( k=0; k<8; k++ ) map->pix[i][j][k] = 0; } } initColormap( env, Tlk, dcm, map); Tlk->colorMode = CM_PSEUDO_256; return map; }
static int ProcessUIParams(PluginInstance* This, Boolean trusted, Boolean use_fwp, Boolean use_lbx, RxParams *in, RxReturnParams *out, char **x_ui_auth_ret) { XSecurityAuthorization dum; int dummy; char *display_name; This->app_group = None; if (out->embedded != RxFalse) { /* default is embedded */ /* let's see whether the server supports AppGroups or not */ if (RxGlobal.has_appgroup == RxUndef) { if (XQueryExtension(RxGlobal.dpy, "XC-APPGROUP", &dummy, &dummy, &dummy) && XagQueryVersion (RxGlobal.dpy, &dummy, &dummy)) RxGlobal.has_appgroup = RxTrue; else RxGlobal.has_appgroup = RxFalse; } if (RxGlobal.has_appgroup == RxTrue) { Screen *scr; Colormap cmap; Arg arg; /* use plugin's colormap as the default colormap */ XtSetArg(arg, XtNcolormap, &cmap); XtGetValues(This->plugin_widget, &arg, 1); scr = XtScreen(This->plugin_widget); if (cmap == DefaultColormapOfScreen(scr)) { XagCreateEmbeddedApplicationGroup (RxGlobal.dpy, None, cmap, BlackPixelOfScreen(scr), WhitePixelOfScreen(scr), &This->app_group); } else { XColor black, white; Pixel pixels[2]; black.red = black.green = black.blue = 0; XAllocColor(RxGlobal.dpy, cmap, &black); white.red = white.green = white.blue = 65535; XAllocColor(RxGlobal.dpy, cmap, &white); XagCreateEmbeddedApplicationGroup (RxGlobal.dpy, None, cmap, pixels[0] = black.pixel, pixels[1] = white.pixel, &This->app_group); XFreeColors(RxGlobal.dpy, cmap, pixels, 2, 0); } SetupStructureNotify (This); RxpSetupPluginEventHandlers (This); } else { /* too bad */ out->embedded = RxFalse; fprintf(stderr, "Warning: Cannot perform embedding as \ requested, APPGROUP extension not supported\n"); } } if (in->x_ui_auth[0] != 0) { GetXAuth(RxGlobal.dpy, in->x_ui_auth[0], in->x_ui_auth_data[0], trusted, This->app_group, False, DEFAULT_TIMEOUT, x_ui_auth_ret, &This->x_ui_auth_id, &dummy); } else if (in->x_auth[0] != 0) GetXAuth(RxGlobal.dpy, in->x_auth[0], in->x_auth_data[0], trusted, This->app_group, False, DEFAULT_TIMEOUT, x_ui_auth_ret, &This->x_ui_auth_id, &dummy); /* make sure we use the server the user wants us to use */ if (RxGlobal.has_real_server == RxUndef) { Display *rdpy = RxGlobal.dpy; char *real_display = getenv("XREALDISPLAY"); RxGlobal.has_real_server = RxFalse; if (real_display != NULL) { rdpy = XOpenDisplay(real_display); if (rdpy == NULL) rdpy = RxGlobal.dpy; else RxGlobal.has_real_server = RxTrue; } /* let's see now whether the server supports LBX or not */ if (XQueryExtension(rdpy, "LBX", &dummy, &dummy, &dummy)) RxGlobal.has_ui_lbx = RxTrue; else RxGlobal.has_ui_lbx = RxFalse; if (rdpy != RxGlobal.dpy) XCloseDisplay(rdpy); } if (RxGlobal.has_real_server == RxTrue) display_name = getenv("XREALDISPLAY"); else display_name = DisplayString(RxGlobal.dpy); /* let's see whether we have a firewall proxy */ if (use_fwp == True && RxGlobal.has_ui_fwp == RxUndef) { RxGlobal.fwp_dpyname = GetXFwpDisplayName(display_name); if (RxGlobal.fwp_dpyname != NULL) RxGlobal.has_ui_fwp = RxTrue; else { /* * We were supposed to use the firewall proxy but we * couldn't get a connection. There is no need to * continue. */ return 1; } } if (use_fwp == True && RxGlobal.has_ui_fwp == RxTrue) out->ui = GetXUrl(RxGlobal.fwp_dpyname, *x_ui_auth_ret, in->action); else out->ui = GetXUrl(display_name, *x_ui_auth_ret, in->action); if (in->x_ui_lbx == RxTrue) { if (use_lbx == True) { if (RxGlobal.has_ui_lbx == RxTrue) { out->x_ui_lbx = RxTrue; /* let's get a key for the proxy now */ if (in->x_ui_lbx_auth[0] != 0) { GetXAuth(RxGlobal.dpy, in->x_ui_lbx_auth[0], in->x_ui_lbx_auth_data[0], trusted, None, False, DEFAULT_TIMEOUT, &out->x_ui_lbx_auth, &dum, &dummy); } else if (in->x_auth[0] != 0) GetXAuth(RxGlobal.dpy, in->x_auth[0], in->x_auth_data[0], trusted, None, False, DEFAULT_TIMEOUT, &out->x_ui_lbx_auth, &dum, &dummy); } else { out->x_ui_lbx = RxFalse; fprintf(stderr, "Warning: Cannot setup LBX as requested, \ LBX extension not supported\n"); } } else out->x_ui_lbx = RxFalse; } else /* it's either RxFalse or RxUndef */
void main(int argc, char *argv[]) { int i; #ifdef IRIX_5_1_MOTIF_BUG_WORKAROUND /* * XXX Unfortunately a bug in the IRIX 5.1 Motif shared library * causes a BadMatch X protocol error if the SGI look&feel * is enabled for this program. If we detect we are on an * IRIX 5.1 system, skip the first two fallback resources which * specify using the SGI look&feel. */ struct utsname versionInfo; if(uname(&versionInfo) >= 0) { if(!strcmp(versionInfo.sysname, "IRIX") && !strncmp(versionInfo.release, "5.1", 3)) { toplevel = XtAppInitialize(&app, "Textfun", NULL, 0, &argc, argv, &fallbackResources[2], NULL, 0); } } if(toplevel == NULL) { toplevel = XtAppInitialize(&app, "Textfun", NULL, 0, &argc, argv, fallbackResources, NULL, 0); } #else toplevel = XtAppInitialize(&app, "Textfun", NULL, 0, &argc, argv, fallbackResources, NULL, 0); #endif dpy = XtDisplay(toplevel); /* find an OpenGL-capable RGB visual with depth buffer */ vi = glXChooseVisual(dpy, DefaultScreen(dpy), dblBuf); if (vi == NULL) { vi = glXChooseVisual(dpy, DefaultScreen(dpy), snglBuf); if (vi == NULL) XtAppError(app, "no RGB visual with depth buffer"); doubleBuffer = GL_FALSE; } for (i = 0; i < NUM_FONT_ENTRIES; i++) { fontEntry[i].xfont = XLoadQueryFont(dpy, fontEntry[i].xlfd); if (i == 0 && !fontEntry[i].xfont) XtAppError(app, "could not get basic font"); } fontEntry[0].fontinfo = SuckGlyphsFromServer(dpy, fontEntry[0].xfont->fid); if (!fontEntry[0].fontinfo) XtAppError(app, "could not get font glyphs"); /* create an OpenGL rendering context */ cx = glXCreateContext(dpy, vi, /* no display list sharing */ None, /* favor direct */ GL_TRUE); if (cx == NULL) XtAppError(app, "could not create rendering context"); /* create an X colormap since probably not using default visual */ cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone); XtVaSetValues(toplevel, XtNvisual, vi->visual, XtNdepth, vi->depth, XtNcolormap, cmap, NULL); XtAddEventHandler(toplevel, StructureNotifyMask, False, map_state_changed, NULL); mainw = XmCreateMainWindow(toplevel, "mainw", NULL, 0); XtManageChild(mainw); /* create menu bar */ menubar = XmCreateMenuBar(mainw, "menubar", NULL, 0); XtManageChild(menubar); /* hack around Xt's ignorance of visuals */ XtSetArg(menuPaneArgs[0], XmNdepth, DefaultDepthOfScreen(XtScreen(mainw))); XtSetArg(menuPaneArgs[1], XmNcolormap, DefaultColormapOfScreen(XtScreen(mainw))); /* create File pulldown menu: Quit */ menupane = XmCreatePulldownMenu(menubar, "menupane", menuPaneArgs, 2); btn = XmCreatePushButton(menupane, "Quit", NULL, 0); XtAddCallback(btn, XmNactivateCallback, quit, NULL); XtManageChild(btn); XtSetArg(args[0], XmNsubMenuId, menupane); cascade = XmCreateCascadeButton(menubar, "File", args, 1); XtManageChild(cascade); /* create Options pulldown menu: Motion, Dolly, Rotate, Wobble */ menupane = XmCreatePulldownMenu(menubar, "menupane", menuPaneArgs, 2); btn = XmCreateToggleButton(menupane, "Motion", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) toggle, NULL); XtManageChild(btn); btn = XmCreateToggleButton(menupane, "Dolly", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) dolly, NULL); XtVaSetValues(btn, XmNset, True, NULL); XtManageChild(btn); btn = XmCreateToggleButton(menupane, "Rotate", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) rotate, NULL); XtManageChild(btn); btn = XmCreateToggleButton(menupane, "Wobble", NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) wobble, NULL); XtManageChild(btn); XtSetArg(args[0], XmNsubMenuId, menupane); cascade = XmCreateCascadeButton(menubar, "Options", args, 1); XtManageChild(cascade); XtSetArg(menuPaneArgs[2], XmNradioBehavior, True); XtSetArg(menuPaneArgs[3], XmNradioAlwaysOne, True); menupane = XmCreatePulldownMenu(menubar, "menupane", menuPaneArgs, 4); XtAddCallback(menupane, XmNentryCallback, (XtCallbackProc) fontSelect, NULL); for (i = 0; i < NUM_FONT_ENTRIES; i++) { btn = XmCreateToggleButton(menupane, fontEntry[i].name, NULL, 0); XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc) neverCalled, &fontEntry[i]); if (i == 0) XtVaSetValues(btn, XmNset, True, NULL); if (!fontEntry[i].xfont) XtSetSensitive(btn, False); XtManageChild(btn); } XtSetArg(args[0], XmNsubMenuId, menupane); cascade = XmCreateCascadeButton(menubar, "Font", args, 1); XtManageChild(cascade); /* create framed drawing area for OpenGL rendering */ frame = XmCreateFrame(mainw, "frame", NULL, 0); XtManageChild(frame); glxarea = XtCreateManagedWidget("glxarea", xmDrawingAreaWidgetClass, frame, NULL, 0); XtAddCallback(glxarea, XmNexposeCallback, (XtCallbackProc) draw, NULL); XtAddCallback(glxarea, XmNresizeCallback, resize, NULL); XtAddCallback(glxarea, XmNinputCallback, input, NULL); /* set up application's window layout */ XmMainWindowSetAreas(mainw, menubar, NULL, NULL, NULL, frame); XtRealizeWidget(toplevel); /* * Once widget is realized (ie, associated with a created X window), we * can bind the OpenGL rendering context to the window. */ glXMakeCurrent(dpy, XtWindow(glxarea), cx); made_current = GL_TRUE; /* setup OpenGL state */ glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glClearDepth(1.0); glMatrixMode(GL_PROJECTION); glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 80); glMatrixMode(GL_MODELVIEW); MakeCube(); if (argv[1] != NULL) { numMessages = argc - 1; messages = &argv[1]; } else { numMessages = NUM_DEFAULT_MESSAGES; messages = defaultMessage; } base = glGenLists(numMessages + 1); SetupMessageDisplayList(&fontEntry[0], numMessages, messages); tick(); /* start event processing */ XtAppMainLoop(app); }
/* static */ PRBool DisplayTable::GetColormapAndVisual(Screen* aScreen, XRenderPictFormat* aFormat, Visual* aVisual, Colormap* aColormap, Visual** aVisualForColormap) { Display* display = DisplayOfScreen(aScreen); // Use the default colormap if the default visual matches. Visual *defaultVisual = DefaultVisualOfScreen(aScreen); if (aVisual == defaultVisual || (aFormat && aFormat == XRenderFindVisualFormat(display, defaultVisual))) { *aColormap = DefaultColormapOfScreen(aScreen); *aVisualForColormap = defaultVisual; return PR_TRUE; } // Only supporting TrueColor non-default visuals if (!aVisual || aVisual->c_class != TrueColor) return PR_FALSE; if (!sDisplayTable) { sDisplayTable = new DisplayTable(); } nsTArray<DisplayInfo>* displays = &sDisplayTable->mDisplays; PRUint32 d = displays->IndexOf(display, 0, FindDisplay()); if (d == displays->NoIndex) { d = displays->Length(); // Register for notification of display closing, when this info // becomes invalid. XExtCodes *codes = XAddExtension(display); if (!codes) return PR_FALSE; XESetCloseDisplay(display, codes->extension, DisplayClosing); // Add a new DisplayInfo. displays->AppendElement(display); } nsTArray<ColormapEntry>* entries = &displays->ElementAt(d).mColormapEntries; // Only a small number of formats are expected to be used, so just do a // simple linear search. for (PRUint32 i = 0; i < entries->Length(); ++i) { const ColormapEntry& entry = entries->ElementAt(i); // Only the format and screen need to match. (The visual may differ.) // If there is no format (e.g. no RENDER extension) then just compare // the visual. if ((aFormat && entry.mFormat == aFormat && entry.mScreen == aScreen) || aVisual == entry.mVisual) { *aColormap = entry.mColormap; *aVisualForColormap = entry.mVisual; return PR_TRUE; } } // No existing entry. Create a colormap and add an entry. Colormap colormap = XCreateColormap(display, RootWindowOfScreen(aScreen), aVisual, AllocNone); ColormapEntry* newEntry = entries->AppendElement(); newEntry->mFormat = aFormat; newEntry->mScreen = aScreen; newEntry->mVisual = aVisual; newEntry->mColormap = colormap; *aColormap = colormap; *aVisualForColormap = aVisual; return PR_TRUE; }