int init_x (int X, int Y, int W, int H, int bpp, const char *Name) { XPixmapFormatValues *formatList; int formatCount; int i; int formatOk; int scanlineLength; XGCValues gcVal; unsigned long gcMask; dis = XOpenDisplay ( NULL ); if ( dis == NULL) { fprintf ( stderr , "Error :\n" ); fprintf ( stderr , " Cannot connect to Display.\n"); exit (1); } screen = DefaultScreen ( dis ); depth = DefaultDepth ( dis , screen ); width = DisplayWidth ( dis , screen ); height = DisplayHeight ( dis , screen );
winRoot = DefaultRootWindow ( dis ); winAttr.border_pixel = BlackPixel ( dis , screen ); winAttr.background_pixel = BlackPixel ( dis , screen ); winMask = CWBackPixel | CWBorderPixel;
formatList = XListPixmapFormats( dis, &formatCount); if (formatList == NULL){ fprintf ( stderr , " Cannot get pixmap list\n"); exit (1); } formatOk=-1; for (i=0; ibytes_per_line*xim->height, IPC_CREAT|0777); xim->data = SHMInfo.shmaddr = (char *)shmat(SHMInfo.shmid, 0, 0); SHMInfo.readOnly = False; XShmAttach(dis, &SHMInfo); XSync(dis, False); buffer=(unsigned char *)xim->data; #else buffer = (unsigned char *)calloc(W*H, pixmapFormat.bits_per_pixel/8); xim = XCreateImage ( dis , CopyFromParent , depth , ZPixmap , 0 , (char *) buffer , W , H , pixmapFormat.scanline_pad, scanlineLength); if (xim == NULL){ fprintf(stderr, " Couldnt create Ximage..\n"); exit(-1); } #endif gcVal.foreground = 0; gcVal.background = 0; gcMask = GCForeground | GCBackground; gc = XCreateGC ( dis , win , gcMask , &gcVal ); if (depth==24) depth = pixmapFormat.bits_per_pixel; return (depth); }
|