/* * Initialize graphics and open a window for the viewer */ Bool CreateXWindow(void) { int fd; GR_SIZE w, h; GR_SCREEN_INFO si; if ((fd = GrOpen()) < 0) return(False); nx_dpy.fd = fd; dpy = &nx_dpy; GrGetScreenInfo(&si); /* pass screen details to RFB handler */ myFormat.bitsPerPixel = si.bpp; myFormat.depth = si.bpp; /* is this right? */ myFormat.bigEndian = 0; /* how do I find this out? */ myFormat.trueColour = (myFormat.depth == 8 && !useBGR233) ? 0 : 1; if (myFormat.trueColour) { myFormat.redMax = myFormat.greenMax = 7; myFormat.blueMax = 3; myFormat.redShift = 0; myFormat.greenShift = 3; myFormat.blueShift = 6; } pixtype = si.pixtype; /* get the initial server palette */ GrGetSystemPalette(&srv_pal); #if 0 /* DEBUG */ for (i = 0; i < srv_pal.count; i++) { printf("0x%02x %03d %03d %03d\n", i, \ srv_pal.palette[i].r, srv_pal.palette[i].g, \ srv_pal.palette[i].b ); } #endif /* create the top-level window */ w = (VW_WIDTH > (si.cols - VW_X)) ? (si.cols - VW_X) : VW_WIDTH; h = (VW_HEIGHT > (si.rows - VW_Y)) ? (si.rows - VW_Y) : VW_HEIGHT; if ((wid = GrNewWindow(GR_ROOT_WINDOW_ID, VW_X, VW_Y, w, h, 2, LTGRAY, BLACK)) == 0) { fprintf(stderr, "Unable to create top-level window\n"); GrClose(); return False; } /* select events to receive */ GrSelectEvents(wid, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | GR_EVENT_MASK_MOUSE_POSITION); /* make thw window visible */ GrMapWindow(wid); canvas = wid; /* create the graphics contexts */ gc = GrNewGC(); srcGC = GrNewGC(); dstGC = GrNewGC(); return True; }
static void GrGetSystemPaletteWrapper(void *r) { GR_PALETTE pal; GrGetSystemPalette(&pal); GsWriteType(current_fd,GrNumGetSystemPalette); GsWrite(current_fd, &pal, sizeof(pal)); }
Colormap DefaultColormapOfScreen(Screen* screen) { if (!s_globalColormap) { s_globalColormap = (GR_PALETTE*) malloc(sizeof(GR_PALETTE)); GrGetSystemPalette(s_globalColormap); } return s_globalColormap; }