static PyObject * PaxGC_SetState(PaxGCObject *self, PyObject*args) { unsigned long arg1; unsigned long arg2; int arg3; unsigned long arg4; if (self->shared) { PyErr_SetString(PyExc_TypeError, "can't modify shared GC"); return NULL; } if (!PyArg_ParseTuple(args, "llil", &arg1, &arg2, &arg3, &arg4)) return NULL; XSetState(self->display, self->gc, arg1, arg2, arg3, arg4); Py_INCREF(Py_None); return Py_None; }
static void child_process(void) { union comdata d; unsigned char *bp; int i, j; /* * main loop */ for (;;) { /* * send synchronisation mark */ while (!do_x_select(cmdpipe[1], 1)); i = write(cmdpipe[1], "r", 1); if (i < 1) { perror("write"); exit(1); } /* * read data */ for (j = sizeof(d), bp = d.b; j > 0; ) { while (!do_x_select(datapipe[0], 0)); i = read(datapipe[0], bp, j); if (i < 1) { perror("read"); exit(1); } j -= i; bp += i; } /* * clear pixmap */ XSetState(display, gc, col_background, col_background, GXcopy, AllPlanes); XFillRectangle(display, pixmap, gc, 0, 0, WIDTH, HEIGHT); /* * draw zero line */ XSetForeground(display, gc, col_zeroline); XDrawLine(display, pixmap, gc, 0, YCOORD(0), WIDTH, YCOORD(0)); /* * draw input */ XSetForeground(display, gc, col_trace); for (i = 1; i < WIDTH; i++) XDrawLine(display, pixmap, gc, i-1, YCOORD(d.s[i-1]), i, YCOORD(d.s[i])); XCopyArea(display, pixmap, window, gc, 0, 0, WIDTH, HEIGHT, 0, 0); /* XSync(display, 0); */ } XDestroyWindow(display, window); XCloseDisplay(display); }
/* * The following function initializes a toplevel window. * It returns 0 if the initialization was successful, * or -1 if it couldn't initialize the double buffering routine. */ int Init_top(void) { int top_x, top_y; int i; int x, y; unsigned w, h; unsigned long values; int top_flags; XGCValues xgc; XSetWindowAttributes sattr; unsigned long mask; if (topWindow) fatal("Init_top called twice"); if (Colors_init() == -1) return -1; radarDrawRectanglePtr = XFillRectangle; /* * Get toplevel geometry. */ top_flags = 0; if (geometry != NULL && geometry[0] != '\0') mask = XParseGeometry(geometry, &x, &y, &w, &h); else mask = 0; if ((mask & WidthValue) != 0) { top_width = w; top_flags |= USSize; } else { top_width = DEF_TOP_WIDTH; top_flags |= PSize; } LIMIT(top_width, MIN_TOP_WIDTH, MAX_TOP_WIDTH); if ((mask & HeightValue) != 0) { top_height = h; top_flags |= USSize; } else { top_height = DEF_TOP_HEIGHT; top_flags |= PSize; } LIMIT(top_height, MIN_TOP_HEIGHT, MAX_TOP_HEIGHT); if ((mask & XValue) != 0) { if ((mask & XNegative) != 0) top_x = DisplayWidth(dpy, DefaultScreen(dpy)) - top_width + x; else top_x = x; top_flags |= USPosition; } else { top_x = (DisplayWidth(dpy, DefaultScreen(dpy)) - top_width) /2; top_flags |= PPosition; } if ((mask & YValue) != 0) { if ((mask & YNegative) != 0) top_y = DisplayHeight(dpy, DefaultScreen(dpy)) - top_height + y; else top_y = y; top_flags |= USPosition; } else { top_y = (DisplayHeight(dpy, DefaultScreen(dpy)) - top_height) /2; top_flags |= PPosition; } if (geometry != NULL) { free(geometry); geometry = NULL; } /* * Create toplevel window (we need this first so that we can create GCs) */ mask = 0; /*old debug: sattr.background_pixel = colors[WHITE].pixel;*/ sattr.background_pixel = colors[BLACK].pixel; mask |= CWBackPixel; sattr.border_pixel = colors[WHITE].pixel; mask |= CWBorderPixel; if (colormap != 0) { sattr.colormap = colormap; mask |= CWColormap; } if (ignoreWindowManager) { sattr.override_redirect = True; mask |= CWOverrideRedirect; } topWindow = XCreateWindow(dpy, DefaultRootWindow(dpy), top_x, top_y, top_width, top_height, 0, (int)dispDepth, InputOutput, visual, mask, &sattr); XSelectInput(dpy, topWindow, KeyPressMask | KeyReleaseMask | FocusChangeMask | StructureNotifyMask); Init_disp_prop(dpy, topWindow, top_width, top_height, top_x, top_y, top_flags); if (kdpy) { int scr = DefaultScreen(kdpy); keyboardWindow = XCreateSimpleWindow(kdpy, DefaultRootWindow(kdpy), top_x, top_y, top_width, top_height, 0, 0, BlackPixel(dpy, scr)); XSelectInput(kdpy, keyboardWindow, KeyPressMask | KeyReleaseMask | FocusChangeMask); Init_disp_prop(kdpy, keyboardWindow, top_width, top_height, top_x, top_y, top_flags); } /* * Create item bitmaps */ for (i = 0; i < NUM_ITEMS; i++) itemBitmaps[i] = XCreateBitmapFromData(dpy, topWindow, (char *)itemBitmapData[i].data, ITEM_SIZE, ITEM_SIZE); /* * Creates and initializes the graphic contexts. */ xgc.line_width = 0; xgc.line_style = LineSolid; xgc.cap_style = CapButt; xgc.join_style = JoinMiter; /* I think this is fastest, is it? */ xgc.graphics_exposures = False; values = GCLineWidth|GCLineStyle|GCCapStyle|GCJoinStyle|GCGraphicsExposures; messageGC = XCreateGC(dpy, topWindow, values, &xgc); radarGC = XCreateGC(dpy, topWindow, values, &xgc); buttonGC = XCreateGC(dpy, topWindow, values, &xgc); scoreListGC = XCreateGC(dpy, topWindow, values, &xgc); textGC = XCreateGC(dpy, topWindow, values, &xgc); talkGC = XCreateGC(dpy, topWindow, values, &xgc); motdGC = XCreateGC(dpy, topWindow, values, &xgc); gameGC = XCreateGC(dpy, topWindow, values, &xgc); XSetBackground(dpy, gameGC, colors[BLACK].pixel); /* * Set fonts */ gameFont = Set_font(dpy, gameGC, gameFontName, "gameFont"); messageFont = Set_font(dpy, messageGC, messageFontName, "messageFont"); scoreListFont = Set_font(dpy, scoreListGC, scoreListFontName, "scoreListFont"); buttonFont = Set_font(dpy, buttonGC, buttonFontName, "buttonFont"); textFont = Set_font(dpy, textGC, textFontName, "textFont"); talkFont = Set_font(dpy, talkGC, talkFontName, "talkFont"); motdFont = Set_font(dpy, motdGC, motdFontName, "motdFont"); XSetState(dpy, gameGC, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy)), GXcopy, AllPlanes); XSetState(dpy, radarGC, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy)), GXcopy, AllPlanes); XSetState(dpy, messageGC, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy)), GXcopy, AllPlanes); XSetState(dpy, buttonGC, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy)), GXcopy, AllPlanes); XSetState(dpy, scoreListGC, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy)), GXcopy, AllPlanes); if (dbuf_state->type == COLOR_SWITCH) XSetPlaneMask(dpy, gameGC, dbuf_state->drawing_planes); return 0; }
static int win_open (const GEN_PAR * pg, char *title, int x, int y, int w, int h) { char *DisplayName = NULL; char **argv; XSizeHints Hints; unsigned long ValueMask; XSetWindowAttributes WinAttr; XEvent Event; char colorname[13]; int i; /** ** Simulate command line arguments **/ argv = (char **) malloc (3 * sizeof (char *)); argv[0] = PROG_NAME; argv[1] = title; argv[2] = NULL; /** ** X11 server reachable ? **/ if ((XDisplay = (Display *) XOpenDisplay (DisplayName)) == NULL) { Eprintf ("No X11 server found !\n"); return NO_SERVER; } XScreen = DefaultScreen (XDisplay); XRoot = RootWindow (XDisplay, XScreen); XVisual = DefaultVisual (XDisplay, XScreen); XGcWin = DefaultGC (XDisplay, XScreen); scr_width = WidthOfScreen (ScreenOfDisplay (XDisplay, XScreen)); scr_height = HeightOfScreen (ScreenOfDisplay (XDisplay, XScreen)); if (x + w > scr_width || y + h > scr_height) { if (!pg->quiet) Eprintf ("Window exceeds screen limits, use mouse button 1 to pan\n"); w = MIN (w, scr_width); h = MIN (h, scr_height); oversized = 1; /* return SIZE;*/ } /** ** Set window attributes **/ WinAttr.background_pixel = WhitePixel (XDisplay, XScreen); WinAttr.border_pixel = WhitePixel (XDisplay, XScreen); WinAttr.backing_store = Always; ValueMask = CWBackPixel | CWBorderPixel | CWBackingStore; /** ** Create Window **/ XWin = XCreateWindow (XDisplay, XRoot, x, y, w, h, 1, 0, CopyFromParent, CopyFromParent, ValueMask, &WinAttr); /** ** Define window properties **/ Hints.flags = PSize | PMinSize | PMaxSize | USPosition; Hints.x = x; Hints.y = y; Hints.width = Hints.min_width = Hints.max_width = w; Hints.height = Hints.min_height = Hints.max_height = h; XSetStandardProperties (XDisplay, XWin, title, title, 0, argv, 2, &Hints); /** ** Define color table (compatible to SunView and Turbo-C usage) **/ def_clut = DefaultColormap (XDisplay, XScreen); if (DefaultDepth (XDisplay, XScreen) < 4) { col_table[BLACK] = WhitePixel (XDisplay, XScreen); col_table[WHITE] = BlackPixel (XDisplay, XScreen); col_table[GRAY] = col_table[WHITE]; col_table[RED] = col_table[WHITE]; col_table[GREEN] = col_table[WHITE]; col_table[BLUE] = col_table[WHITE]; col_table[CYAN] = col_table[WHITE]; col_table[MAGENTA] = col_table[WHITE]; col_table[YELLOW] = col_table[WHITE]; col_table[LIGHTGRAY] = col_table[WHITE]; col_table[LIGHTRED] = col_table[WHITE]; col_table[LIGHTGREEN] = col_table[WHITE]; col_table[LIGHTBLUE] = col_table[WHITE]; col_table[LIGHTCYAN] = col_table[WHITE]; col_table[LIGHTMAGENTA] = col_table[WHITE]; } else { XParseColor (XDisplay, def_clut, "gray10", &Xcol); XAllocColor (XDisplay, def_clut, &Xcol); col_table[GRAY] = Xcol.pixel; for (i = 1; i <= pg->maxpens; i++) { sprintf (colorname, "#%2.2X%2.2X%2.2X", pt.clut[i][0], pt.clut[i][1], pt.clut[i][2]); if (XParseColor (XDisplay, def_clut, colorname, &Xcol)==0) fprintf(stderr,"failed tp map color for pen %d\n",i); if (XAllocColor (XDisplay, def_clut, &Xcol)==0) { fprintf(stderr,"failed to alloc X color for pen %d\n",i); col_table[i] = col_table[GRAY]; }else col_table[i] = Xcol.pixel; } } /** ** Set foreground and background colors **/ XSetState (XDisplay, XGcWin, col_table[BLACK], col_table[WHITE], GXcopy, AllPlanes); /** ** Define permitted events for this window **/ XSelectInput (XDisplay, XWin, ExposureMask | KeyPressMask | VisibilityChangeMask | ButtonPressMask | ButtonReleaseMask); /** ** Display window **/ XMapWindow (XDisplay, XWin); do { XNextEvent (XDisplay, &Event); } while (Event.type != Expose && Event.type != VisibilityNotify ); width = w; height = h; bytes = (w + 7) / 8; free ((char *) argv); return (0); }