int main(int argc, char *argv[]) { Status rc; GC cont; dpy = XOpenDisplay(NULL); if( !dpy ) { fprintf(stderr, "Failed to open display"); return EXIT_FAILURE; } scr = DefaultScreen(dpy); scr_cmap = DefaultColormap(dpy, scr); rc = XAllocNamedColor(dpy, scr_cmap, "green", &green, &green); if( !rc ) { fprintf(stderr, "XAllocNamedColor: failed to allocate color"); return EXIT_FAILURE; } rc = XAllocNamedColor(dpy, scr_cmap, "blue", &blue, &blue); if ( !rc ) { fprintf(stderr, "XAllocNamedColor: failed to allocate color"); return EXIT_FAILURE; } win = XCreateSimpleWindow(dpy, RootWindow(dpy, scr), 0, 0, width, width, 0, blue.pixel, blue.pixel); XMapWindow(dpy, win); cont = XCreateGC(dpy, win, 0, NULL); XSetFillStyle(dpy, cont, FillSolid); int s; int t = 0, q = 1; while(1) { s = 0; while( s<width/2 ) { XSetForeground(dpy, cont, t ? (( (s% (2*step) )==0) ? green.pixel: blue.pixel) : (( (s% (2*step) )==0) ? blue.pixel: green.pixel) ); if(q) XFillRectangle(dpy, win, cont, s, s, width - 2*s, width - 2*s); else XFillRectangle(dpy, win, cont, width/2 - s, width/2 - s, 2*s, 2*s); s+=step; XFlush(dpy); // sleep(1); if( s!=step ) napms(500); } t=!t; q=!q; } XCloseDisplay(dpy); return EXIT_SUCCESS; }
//-------------------------------------------- void allocXResources() { XColor exactColor, screenColor; XAllocNamedColor(display, MainColormap, "red", &screenColor, &exactColor); RedXColor = screenColor.pixel; XAllocNamedColor(display, MainColormap, "blue", &screenColor, &exactColor); BlueXColor = screenColor.pixel; loadFont(&FontInfo); getGC(MainWindow, &MainGC, FontInfo); }
// chargement des parametre commun a toutes les fenetres void init_graphique(void){ XAllocNamedColor(dpy, DefaultColormap(dpy, DefaultScreen(dpy)), "grey", &color_fond, &color_fond); XAllocNamedColor(dpy, DefaultColormap(dpy, DefaultScreen(dpy)), "DimGrey", &color_focus, &color_focus); XAllocNamedColor(dpy, DefaultColormap(dpy, DefaultScreen(dpy)), "WhiteSmoke", &color_fond_de_fen , &color_fond_de_fen ); if ((font=XLoadQueryFont(dpy,"-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1"))==NULL){ fprintf(stderr," Sorry, having font problems.\n"); exit(-1); } cursor= XCreateFontCursor(dpy, CODE_CURS_XC_draft_large); }
void NodeViewInfo::comp_pixel_values_traverse(_DtCvSegment* seg, Display* dpy, Colormap &cmap) { if (seg == NULL) return; unsigned long seg_ptype = seg->type & _DtCvPRIMARY_MASK; if (seg_ptype == _DtCvSTRING && seg->client_use) { XColor screen, exact; SegClientData* pSCD = (SegClientData*)seg->client_use; assert( pSCD->type() == _DtCvSTRING ); if (pSCD->bg_color() && pSCD->bg_pixel() == (unsigned long)-1) { UAS_String bg_color = pSCD->bg_color(); unsigned long& bg_pixel = f_color_dict[bg_color]; if (bg_pixel == (unsigned long)-1) { if (XAllocNamedColor(dpy, cmap, pSCD->bg_color(), &screen, &exact)) pSCD->bg_pixel(bg_pixel = screen.pixel); } else pSCD->bg_pixel(bg_pixel); } if (pSCD->fg_color() && pSCD->fg_pixel() == (unsigned long)-1) { UAS_String fg_color = pSCD->fg_color(); unsigned long& fg_pixel = f_color_dict[fg_color]; if (fg_pixel == (unsigned long)-1) { if (XAllocNamedColor(dpy, cmap, pSCD->fg_color(), &screen, &exact)) pSCD->fg_pixel(fg_pixel = screen.pixel); } else pSCD->fg_pixel(fg_pixel); } } if (seg_ptype == _DtCvCONTAINER) { // traverse subordinates _DtCvSegment* subordinates; if ((subordinates = seg->handle.container.seg_list) != NULL) comp_pixel_values_traverse(subordinates, dpy, cmap); } // traverse siblings _DtCvSegment* siblings; if ((siblings = seg->next_seg) != NULL) comp_pixel_values_traverse(siblings, dpy, cmap); return; }
void initInterface(){ XAllocNamedColor (display, cmap, green, &color, &ignore); XtSetArg (greenwargs[0], XmNbackground, color.pixel); XAllocNamedColor (display, cmap, red, &color, &ignore); XtSetArg (redwargs[0], XmNbackground, color.pixel); XtVaSetValues (start, XmNsensitive, False, NULL); XtVaSetValues (end, XmNsensitive, False, NULL); XtVaSetValues (rec, XmNsensitive, False, NULL); XtVaSetValues (cir, XmNsensitive, False, NULL); XtVaSetValues (tri, XmNsensitive, False, NULL); }
unsigned long getColour(Display *dpy, XrmDatabase db, char *name, char *cl, char *def){ XrmValue v; XColor col1, col2; Colormap cmap = DefaultColormap(dpy, DefaultScreen(dpy)); char * type; if (XrmGetResource(db, name, cl, &type, &v) && XAllocNamedColor(dpy, cmap, v.addr, &col1, &col2)) { } else { XAllocNamedColor(dpy, cmap, def, &col1, &col2); } return col2.pixel; }
static void CanvasCB(Widget canvas, XtPointer client, XEvent *ev, Boolean *cont) { Display *dpy = XtDisplay(canvas) ; Window win = XtWindow(canvas) ; int x0,y0 ; if( !canvas_init ) { Colormap cmap ; XColor y,b, dummy ; XtVaGetValues(canvas, XtNcolormap, &cmap, 0) ; canvasGc = XCreateGC(dpy,win, 0,NULL) ; XSetLineAttributes(dpy, canvasGc, 8, LineSolid, CapButt, JoinRound); XSetGraphicsExposures(dpy, canvasGc, True) ; XAllocNamedColor(dpy, cmap, "yellow", &y, &dummy) ; yellow = y.pixel ; XAllocNamedColor(dpy, cmap, "black", &b, &dummy) ; black = b.pixel ; canvas_init = True ; } switch( ev->type ) { case GraphicsExpose: case Expose: x0 = MwRulerValue2Position(topRuler, 1.) ; y0 = MwRulerValue2Position(leftRuler, 1.) - 100 ; XSetForeground(dpy,canvasGc, yellow) ; XFillArc(dpy,win,canvasGc, x0,y0, 100,100, 0,360*64) ; XSetForeground(dpy,canvasGc, black) ; XDrawArc(dpy,win,canvasGc, x0,y0, 100,100, 0,360*64) ; XFillArc(dpy,win,canvasGc, x0+30,y0+30, 10,10, 0,360*64) ; XFillArc(dpy,win,canvasGc, x0+60,y0+30, 10,10, 0,360*64) ; XDrawArc(dpy,win,canvasGc, x0+20,y0+20, 60,60, 225*64,90*64) ; break ; case EnterNotify: MwRulerShowPointer(leftRuler, True) ; MwRulerShowPointer(topRuler, True) ; break ; case LeaveNotify: MwRulerShowPointer(leftRuler, False) ; MwRulerShowPointer(topRuler, False) ; break ; case MotionNotify: MwRulerSetIValue(leftRuler, ev->xmotion.y) ; MwRulerSetIValue(topRuler, ev->xmotion.x) ; break ; } }
static int InitX11ColorCells( Display *display ) { int i; Status status; Colormap colormap; XColor exactColor; gDisplay = display; colormap = DefaultColormap(display, DefaultScreen(display)); for (i=0; i<gFiTableSize; i++) { status = XAllocNamedColor(display, colormap, gFiTable[i].xColorName, &(gFiTable[i].xColor), &exactColor); if (status == 0) { if (gReportLevel == 1) { fprintf(stderr, "? Failed to allocate x11 color %s\n", gFiTable[i].xColorName); } break; } } if (status == 0) { FreeX11ColorCells(0, i); return FALSE; } return TRUE; }
void gl_mousepointer (int action) { if (action==2) hide_mouse ^= 1; else hide_mouse = action ? 1 : 0; if (hide_mouse) { /* hide */ Cursor no_ptr; Pixmap bm_no; XColor black, dummy; Colormap colormap; static char bm_no_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; colormap = DefaultColormap (_gl_display, _gl_screen); if (!XAllocNamedColor (_gl_display, colormap, "black", &black, &dummy) ) return; bm_no = XCreateBitmapFromData (_gl_display, _gl_win, bm_no_data, 8, 8); no_ptr = XCreatePixmapCursor (_gl_display, bm_no, bm_no, &black, &black, 0, 0); XDefineCursor (_gl_display, _gl_win, no_ptr); XFreeCursor (_gl_display, no_ptr); if (bm_no != None) XFreePixmap (_gl_display, bm_no); XFreeColors (_gl_display,colormap, &black.pixel, 1, 0); } else { /* show */ XDefineCursor(_gl_display, _gl_win, 0); } }
Lock * lockscreen(Display *dpy, int screen) { /* Thanks suckless - slock */ char curs[] = {0, 0, 0, 0, 0, 0, 0, 0}; Lock *lock; XColor black, dummy; XSetWindowAttributes wa; Cursor invisible; if (dpy == NULL || screen < 0) return NULL; lock = malloc(sizeof(Lock)); if (lock == NULL) return NULL; lock->screen = screen; lock->root = RootWindow(dpy, lock->screen); /* init */ wa.override_redirect = 1; wa.background_pixel = BlackPixel(dpy, lock->screen); lock->win = XCreateWindow(dpy, lock->root, 0, 0, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen), 0, DefaultDepth(dpy, lock->screen), CopyFromParent, DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa); XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen), "black", &black, &dummy); lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8); invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap, &black, &black, 0, 0); XDefineCursor(dpy, lock->win, invisible); XMapRaised(dpy, lock->win); return lock; }
static void QInitColors( void ) { XColor color,exact; Status result; int i; if( MAXCOLOR < 16 ) Error("xgraph: Error in dimension of color table"); MyColormap = XDefaultColormap(MyDisplay,MyScreen); for(i=0;i<16;i++) { result=XAllocNamedColor(MyDisplay,MyColormap,MyColorNames[i] ,&color,&exact); if(result) MyColors[i]=color; else { Error("QInitColors : Error allocating color"); } } MaxColors = 16; }
static void init_cursors(void) { static char zchar[1]; Pixmap pix; XColor black, dummy; create_cursor(CurNormal, XC_left_ptr); create_cursor(CurNECorner, XC_top_right_corner); create_cursor(CurNWCorner, XC_top_left_corner); create_cursor(CurSECorner, XC_bottom_right_corner); create_cursor(CurSWCorner, XC_bottom_left_corner); create_cursor(CurMove, XC_fleur); create_cursor(CurDHArrow, XC_sb_h_double_arrow); create_cursor(CurDVArrow, XC_sb_v_double_arrow); create_cursor(CurInput, XC_xterm); create_cursor(CurSizing, XC_sizing); create_cursor(CurIcon, XC_icon); create_cursor(CurTCross, XC_tcross); XAllocNamedColor(display, scr.colormap, "black", &black, &dummy); pix = XCreateBitmapFromData( display, scr.root.xid, zchar, 1, 1); cursor[CurNone] = XCreatePixmapCursor(display, pix, pix, &black, &black, 0, 0); XFreePixmap(display, pix); }
void XImlib2Caption::createFont() { XDesktopContainer * xContainer = dynamic_cast<XDesktopContainer *>(AbstractImage::container); DesktopIconConfig * dIconConfig = dynamic_cast<DesktopIconConfig *>(AbstractImage::iconConfig); font = XftFontOpen( xContainer->getDisplay(), DefaultScreen( xContainer->getDisplay()), XFT_FAMILY, XftTypeString, dIconConfig->getFont().c_str(), XFT_SIZE, XftTypeDouble, (double)dIconConfig->getFontSize(), XFT_WEIGHT, XftTypeInteger, boldVal, NULL ); XColor screen, exact; if (!XAllocNamedColor (xContainer->getDisplay(), cmap, (char*)dIconConfig->getFontColor().c_str(), &screen, &exact)) cout << "BAD COLORS!!!\n"; XftColorAllocName(xContainer->getDisplay(), visual, cmap, (char*)dIconConfig->getFontColor().c_str(), &fontColor ); if (shadowOn) XftColorAllocName(xContainer->getDisplay(), visual, cmap, (char*)shadowColor.c_str(), &shadowFontColor ); }
unsigned int color_get ( Display *display, const char *const name, const char * const defn ) { XColor color = { 0, 0, 0, 0, 0, 0 }; XColor def; // Special format. if ( strncmp ( name, "argb:", 5 ) == 0 ) { color.pixel = strtoul ( &name[5], NULL, 16 ); color.red = ( ( color.pixel & 0x00FF0000 ) >> 16 ) * 255; color.green = ( ( color.pixel & 0x0000FF00 ) >> 8 ) * 255; color.blue = ( ( color.pixel & 0x000000FF ) ) * 255; if ( !truecolor ) { // This will drop alpha part. Status st = XAllocColor ( display, map, &color ); if ( st == None ) { fprintf ( stderr, "Failed to parse color: '%s'\n", name ); st = XAllocNamedColor ( display, map, defn, &color, &def ); if ( st == None ) { fprintf ( stderr, "Failed to allocate fallback color\n" ); exit ( EXIT_FAILURE ); } } return color.pixel; } return color.pixel; }
void showCursor(Display *dpy, Window win, int show) { if(!show) { Pixmap bm_no; Colormap cmap; Cursor no_ptr; XColor black, dummy; char bm_no_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; cmap = DefaultColormap(dpy, DefaultScreen(dpy)); XAllocNamedColor(dpy, cmap, "black", &black, &dummy); bm_no = XCreateBitmapFromData(dpy, win, bm_no_data, 8, 8); no_ptr = XCreatePixmapCursor(dpy, bm_no, bm_no, &black, &black, 0, 0); XDefineCursor(dpy, win, no_ptr); XFreeCursor(dpy, no_ptr); XFreePixmap(dpy, bm_no); XFreeColors(dpy, cmap, &black.pixel, 1, 0); } else { XDefineCursor(dpy, win, 0); } }
void initscreen(void) { d1=XOpenDisplay(0); if (d1==NULL) { printf("Can't open display.\n"); exit(0); } /*Aufbau der XWindowsAttribStr*/ w0 = DefaultRootWindow(d1); winatt1.background_pixel = BlackPixel(d1,0); winatt1.backing_store = WhenMapped; winatt1.event_mask = KeyPressMask|StructureNotifyMask; w1 = XCreateWindow(d1,w0,w1_x,w1_y,w1_w,w1_h,w1_border,CopyFromParent,InputOutput, CopyFromParent,CWBackPixel|CWBackingStore|CWEventMask,&winatt1); XStoreName(d1,w1,w1_wname); XSetIconName(d1,w1,w1_iname); XMapWindow(d1,w1); cm1=DefaultColormap(d1,0); if (!XAllocNamedColor(d1,cm1,"blue",&xc1,&xc2)) printf("coudn't allocate blue color\n"); f1_str=XLoadQueryFont(d1,font1_name); if (f1_str==NULL) printf("could't load font\n"); gcval1.foreground = xc1.pixel; gcval1.font = f1_str -> fid; gcval1.line_style = LineSolid; gc1 = XCreateGC(d1,w1, GCForeground|GCLineStyle, &gcval1); gcval1.foreground = WhitePixel(d1,0); gc2 = XCreateGC(d1,w1, GCForeground|GCLineStyle|GCFont, &gcval1); }
ulng _getcolor(const char *colstr) { XColor color; if(!XAllocNamedColor(disp, wa.colormap, colstr, &color, &color)) { return 0; } return color.pixel; }
// Xft text box, optionally editable textbox* textbox_create(Window parent, unsigned long flags, short x, short y, short w, short h, char *font, char *fg, char *bg, char *text, char *prompt) { textbox *tb = calloc(1, sizeof(textbox)); tb->flags = flags; tb->parent = parent; tb->x = x; tb->y = y; tb->w = MAX(1, w); tb->h = MAX(1, h); XColor color; Colormap map = DefaultColormap(display, DefaultScreen(display)); unsigned int cp = XAllocNamedColor(display, map, bg, &color, &color) ? color.pixel: None; tb->window = XCreateSimpleWindow(display, tb->parent, tb->x, tb->y, tb->w, tb->h, 0, None, cp); // need to preload the font to calc line height textbox_font(tb, font, fg, bg); tb->prompt = strdup(prompt ? prompt: ""); textbox_text(tb, text ? text: ""); // auto height/width modes get handled here textbox_moveresize(tb, tb->x, tb->y, tb->w, tb->h); // edit mode controls if (tb->flags & TB_EDITABLE) { tb->xim = XOpenIM(display, NULL, NULL, NULL); tb->xic = XCreateIC(tb->xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, tb->window, XNFocusWindow, tb->window, NULL); } return tb; }
void DisplayX11::ASetBackground( char * color ) { XColor def, closest; XAllocNamedColor( disp, DefaultColormap( disp, 0 ), color, &def, &closest ); XSetBackground( disp, gc, closest.pixel ); }
void xsncolr ( char *cname, Pixel *pcolor, int *iret ) /************************************************************************ * xsncolr * * * * This subroutine allocates a named color for the X Windows device * * driver. * * * * xsncolr ( cname, pcolor, iret ) * * * * Input parameters: * * *cname char X Color name * * * * Output parameters: * * *pcolor Pixel Color pixel number * * *iret int Return code * * G_NORMAL = normal return * * G_NCLRAL = color allocation failure * ** * * Log: * * T. Piper/SAIC 05/03 Created * ***********************************************************************/ { XColor xcolor, xrgb; /*---------------------------------------------------------------------*/ if ( XAllocNamedColor(gemdisplay, gemmap, cname, &xcolor, &xrgb) ) { *pcolor = xcolor.pixel; *iret = G_NORMAL; } else { *pcolor = (Pixel)IMISSD; *iret = G_NCLRAL; } return; }
static unsigned int color_get ( Display *display, const char *const name ) { int screen_id = DefaultScreen ( display ); XColor color; Colormap map = DefaultColormap ( display, screen_id ); return XAllocNamedColor ( display, map, name, &color, &color ) ? color.pixel : None; }
// get a color from a string, and save it into the context unlong _getcolor(DC *dc, const char *colstr) { XColor color; if(!XAllocNamedColor(dc->dpy, dc->wa.colormap, colstr, &color, &color)) { printf("cannot allocate color '%s'\n", colstr); return 0; } return color.pixel; }
unsigned long ObtieneColor(Display* dis, char* color_name){ Colormap cmap; XColor color_cercano, color_verdadero; cmap = DefaultColormap(dis, 0); XAllocNamedColor(dis, cmap, color_name, &color_cercano, &color_verdadero); return(color_cercano.pixel); }
// allocate a pixel value for an X named color unsigned int color_get(const char *name) { XColor color; Colormap map = DefaultColormap(display, DefaultScreen(display)); return XAllocNamedColor(display, map, name, &color, &color) ? color.pixel : None; }
unsigned long GetColor(char *name, unsigned long def) { XColor col1, col2; if (hascolor && XAllocNamedColor(dpy, cmap, name, &col1, &col2)) { return col2.pixel; } else { return def; } }
unsigned long mycolor( Display *display , char *color ){ Colormap cmap; XColor c0,c1; cmap = DefaultColormap(display,0); XAllocNamedColor(display,cmap,color,&c1,&c0); return c1.pixel; }
int XuiInit(int n, int rectw, int border, int is_auto) { XGCValues gcv; Colormap cm; XColor c, ce; int winw = n * rectw + 2 * MARIN; Rectw = rectw; Border = border; Num = n; X0 = MARIN; Y0 = MARIN; IsAuto = is_auto; Dsp = XOpenDisplay(NULL); if (Dsp == NULL) fatal("open display failed\n"); Scr = DefaultScreen(Dsp); Win = XCreateSimpleWindow(Dsp, RootWindow(Dsp, Scr), 10, 10, winw, winw, 1, BlackPixel(Dsp, Scr), WhitePixel(Dsp, Scr)); cm = DefaultColormap(Dsp, Scr); XAllocNamedColor(Dsp, cm, BLOCK_COLOR, &c, &ce); gcv.foreground = c.pixel; gcv.background = WhitePixel(Dsp, Scr); Blockgc = XCreateGC(Dsp, Win, GCForeground | GCBackground, &gcv); XAllocNamedColor(Dsp, cm, FULL_COLOR, &c, &ce); gcv.foreground = c.pixel; Fullgc = XCreateGC(Dsp, Win, GCForeground | GCBackground, &gcv); XAllocNamedColor(Dsp, cm, EMPTY_COLOR, &c, &ce); gcv.foreground = c.pixel; Emptygc = XCreateGC(Dsp, Win, GCForeground | GCBackground, &gcv); gcv.foreground = BlackPixel(Dsp, Scr); Linegc = XCreateGC(Dsp, Win, GCForeground | GCBackground, &gcv); XSelectInput(Dsp, Win, ExposureMask | KeyPressMask | ButtonPressMask); XMapWindow(Dsp, Win); return 0; }
void str_color(char *str, XColor *c) { XColor newcolor, dummy; if(XAllocNamedColor(dpy, colormap, str, &newcolor, &dummy)) { if(!first) XFreeColors(dpy, colormap, &c->pixel, 1, 0); *c = newcolor; } }
NeoDrawColor *neo_draw_get_color_from_string(NeoDrawHandle *handle, char *color) { if(!handle) return NULL; NeoDrawColor *col = malloc(sizeof(*col)); XAllocNamedColor(handle->display, handle->colormap, color, &col->color, &col->exact); return col; }
int main (int argc, char *argv[]) { Display *dpy; Visual *visual; int depth; XSetWindowAttributes attributes; Window win; XFontStruct *fontinfo; XColor color, dummy; XGCValues gr_values; GC gc; XKeyEvent event; dpy = XOpenDisplay(NULL); visual = DefaultVisual(dpy, 0); depth = DefaultDepth(dpy, 0); attributes.background_pixel = XWhitePixel(dpy, 0); /* create the application window */ win = XCreateWindow(dpy, XRootWindow(dpy, 0), 50, 50, 400, 400, 5, depth, InputOutput, visual, CWBackPixel, &attributes); XSelectInput(dpy, win, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask); fontinfo = XLoadQueryFont(dpy, "6x10"); XAllocNamedColor(dpy, DefaultColormap(dpy, 0), "green", &color, &dummy); gr_values.font = fontinfo->fid; gr_values.foreground = color.pixel; gc = XCreateGC(dpy, win, GCFont+GCForeground, &gr_values); XMapWindow(dpy, win); /* run till key press */ while(1){ XNextEvent(dpy, (XEvent *)&event); switch(event.type) { case Expose: XDrawLine(dpy, win, gc, 0, 0, 100, 100); XDrawRectangle(dpy, win, gc, 140, 140, 50, 50); XDrawString(dpy, win, gc, 100, 100, "hello X world", 13); break; case ButtonPress: case KeyPress: XUnloadFont(dpy, fontinfo->fid); XFreeGC(dpy, gc); XCloseDisplay(dpy); exit(0); break; case ConfigureNotify: /* reconfigure size of window here */ break; default: break; } } return(0); }