int Disp_DrawFilledCircles(Disp disp, GC gc, XArc * arcs, int n) { if (n > 0) { if (disp->direct_draw) XFillArcs(disp->display, disp->root_window, gc, arcs, n); else XFillArcs(disp->display, disp->pixmap, gc, arcs, n); } return (0); }
void genericarc_test(Boolean fill) { XArc *arcs; int num_arcs = 180; int i; long totaltime; char buf[80]; num_arcs *= X.percent; arcs = (XArc *) malloc(sizeof(XArc) * num_arcs); for (i=0;i<num_arcs;++i) { arcs[i].x = i; arcs[i].y = i; arcs[i].width = i; arcs[i].height = i; arcs[i].angle1 = i * 128; arcs[i].angle2 = i * 128; } XSync(X.dpy,0); start_timer(); if (fill) XFillArcs(X.dpy,X.win,X.gc,arcs,num_arcs); else XDrawArcs(X.dpy,X.win,X.gc,arcs,num_arcs); XSync(X.dpy,0); totaltime = end_timer(); snprintf(buf,sizeof buf,"An uncounted number of pixels in %.3f seconds.", (double)totaltime/1000000.); show_result(buf); free(arcs); }
void XSpadFillArcs(Display *dsply, Drawable drawable,XArc *arcs, int narcs, int hue, int theshade) { XFillArcs(dsply, drawable, SpadFillGC(dsply, hue, theshade, "XSpadFillArcs"), arcs, narcs); }
void XShadeArcs(Display *display, Drawable drawable, XArc *arcs, int narcs) { if (!INIT) { fprintf(stderr, "XShade Error: Tried to fill before INIT called\n"); exit(-1); } XFillArcs(display, drawable, TileGC, arcs, narcs); }
void redraw(void) { puts("redraw"); XSetForeground(dpy, gc, black_pixel); XFillArcs(dpy, pxm, gc, opnt, len); XSetForeground(dpy, gc, white_pixel); XFillArcs(dpy, pxm, gc, pnt, len); event.xexpose.x = 0; event.xexpose.y = 0; event.xexpose.width = w; event.xexpose.height = h; event.type = Expose; XSendEvent(dpy, win, True, ExposureMask, &event); }
static void fizzle (eraser_state *st) { #if 1 // hacked by katahiromz // NOTE: XDrawPoints is too slow in Win32 XArc *arcs; int chunk = 1000; int n = 4; int narcs = st->width * st->height / 8; narcs *= (st->ratio - st->prev_ratio); arcs = (XArc *) calloc (chunk, sizeof(*arcs)); if (! arcs) return; while (narcs > 0) { int remain = (chunk > narcs ? narcs : chunk); int i; for (i = 0; i < remain; i++) { int r = random(); arcs[i].x = r % st->width - 4; arcs[i].y = (r >> 16) % st->height - 4; arcs[i].width = arcs[i].height = n; } XFillArcs(st->dpy, st->window, st->bg_gc, arcs, remain); narcs -= remain; n++; } free (arcs); #else XPoint *points; int chunk = 20000; int npoints = st->width * st->height * 4; npoints *= (st->ratio - st->prev_ratio); points = (XPoint *) malloc (chunk * sizeof(*points)); if (! points) return; while (npoints > 0) { int remain = (chunk > npoints ? npoints : chunk); int i; for (i = 0; i < remain; i++) { int r = random(); points[i].x = r % st->width; points[i].y = (r >> 16) % st->height; } XDrawPoints (st->dpy, st->window, st->bg_gc, points, remain, CoordModeOrigin); npoints -= remain; } free (points); #endif }
void XDitherArcs(Display *display,Drawable drawable, GC gc, XArc *arcs,int narcs) { if (!DITHERINIT) { fprintf(stderr, "XDither Error: Tried to fill before INIT called\n"); exit(-1); } XFillArcs(display, drawable, gc, arcs, narcs); }
/** Render list of filled arcs, \a parcs in \a pDrawable on the back-end * server associated with \a pDrawable's screen. If the offscreen * optimization is enabled, only draw when \a pDrawable is at least * partially visible. */ void dmxPolyFillArc(DrawablePtr pDrawable, GCPtr pGC, int narcs, xArc *parcs) { DMXScreenInfo *dmxScreen = &dmxScreens[pDrawable->pScreen->myNum]; dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC); Drawable draw; if (DMX_GCOPS_OFFSCREEN(pDrawable)) return; DMX_GCOPS_SET_DRAWABLE(pDrawable, draw); XFillArcs(dmxScreen->beDisplay, draw, pGCPriv->gc, (XArc *)parcs, narcs); dmxSync(dmxScreen, FALSE); }
static PyObject * PaxGC_FillArcs(PaxGCObject * self, PyObject *args) { PyObject *arg1; XArc *arcs_arg1; int narcs_arg1; if (!PyArg_ParseTuple(args, "O", &arg1)) return NULL; if (!checkshortlist(6, arg1, (short**)&arcs_arg1, &narcs_arg1)) { if (!PyErr_Occurred()) PyErr_SetString(PyExc_TypeError, "arg1 should be XArc[]"); return NULL; } XFillArcs(self->display, self->drawable, self->gc, arcs_arg1, narcs_arg1); PyMem_Free(arcs_arg1); Py_INCREF(Py_None); return Py_None; }
void DoFilledArcs(XParms xp, Parms p, int reps) { int i; for (i = 0; i != reps; i++) { XFillArcs(xp->d, xp->w, pgc, arcs, p->objects); if (pgc == xp->ddbggc) pgc = xp->ddfggc; else if(pgc == xp->ddfggc) pgc = xp->ddbggc; else if (pgc == xp->bggc) pgc = xp->fggc; else pgc = xp->bggc; CheckAbort (); } }
void DisplayX11::fill_circlearcs( DisplayObject * d_obj, const RGBcolor & col, const int num, const CircleArc2d * vec ) { D_XArcs * myobj; if ( ! d_obj ) { if ( d_xarcs.aa.max_size < num ) { d_xarcs.aa.set_max_size( num ); } d_xarcs.aa.set_cur_size( num ); myobj = &d_xarcs; myobj->mark_col_change(); myobj->mark_pos_change(); } else { myobj = static_cast< D_XArcs * >( d_obj ); //dynamic_cast should also work, but it doesn't <- why? } //here we have the assumption num= myobj->pp.max_size; i.e. the it is not allowed to change the number of arcs if ( myobj->col_change ) { myobj->col_change = false; myobj->XColor_pixel = AGetColor( col ); } if ( myobj->area_number != area_number ) { myobj->area_number = area_number; copy_2_XArcs( myobj->aa.tab, num, vec ); } ASetForeground( myobj->XColor_pixel ); XFillArcs( disp, pixmap, gc, myobj->aa.tab, num ); }
void XmuFillRoundedRectangle(Display *dpy, Drawable draw, GC gc, int x, int y, int w, int h, int ew, int eh) { XArc arcs[4]; XRectangle rects[3]; XGCValues vals; int ew2, eh2; XGetGCValues(dpy, gc, GCArcMode, &vals); if (vals.arc_mode != ArcPieSlice) XSetArcMode(dpy, gc, ArcPieSlice); if ((ew2 = (ew << 1)) > w) ew2 = ew = 0; if ((eh2 = (eh << 1)) > h) eh2 = eh = 0; arcs[0].x = x; arcs[0].y = y; arcs[0].width = ew2; arcs[0].height = eh2; arcs[0].angle1 = 180 * 64; arcs[0].angle2 = -90 * 64; arcs[1].x = x + w - ew2 - 1; arcs[1].y = y; arcs[1].width = ew2; arcs[1].height = eh2; arcs[1].angle1 = 90 * 64; arcs[1].angle2 = -90 * 64; arcs[2].x = x + w - ew2 - 1; arcs[2].y = y + h - eh2 - 1; arcs[2].width = ew2; arcs[2].height = eh2; arcs[2].angle1 = 0; arcs[2].angle2 = -90 * 64; arcs[3].x = x; arcs[3].y = y + h - eh2 - 1; arcs[3].width = ew2; arcs[3].height = eh2; arcs[3].angle1 = 270 * 64; arcs[3].angle2 = -90 * 64; XFillArcs(dpy, draw, gc, arcs, 4); rects[0].x = x + ew; rects[0].y = y; rects[0].width = w - ew2; rects[0].height = h; rects[1].x = x; rects[1].y = y + eh; rects[1].width = ew; rects[1].height = h - eh2; rects[2].x = x + w - ew; rects[2].y = y + eh; rects[2].width = ew; rects[2].height = h - eh2; XFillRectangles(dpy, draw, gc, rects, 3); if (vals.arc_mode != ArcPieSlice) XSetArcMode(dpy, gc, vals.arc_mode); }
/* from Frederick Roeber <*****@*****.**> */ static void losira (eraser_state *st) { double mode1 = 0.55; double mode2 = mode1 + 0.30; double mode3 = 1.0; int radius = 10; if (st->ratio < mode1) /* squeeze from the sides */ { double ratio = st->ratio / mode1; double prev_ratio = st->prev_ratio / mode1; int max = st->width / 2; int step = (max * ratio) - (max * prev_ratio); if (step <= 0) step = 1; /* pull from left */ XCopyArea (st->dpy, st->window, st->window, st->fg_gc, 0, 0, max - step, st->height, step, 0); XFillRectangle (st->dpy, st->window, st->bg_gc, 0, 0, max * ratio, st->height); /* pull from right */ XCopyArea (st->dpy, st->window, st->window, st->fg_gc, max+step, 0, max - step, st->height, max, 0); XFillRectangle (st->dpy, st->window, st->bg_gc, max + max*(1-ratio), 0, max, st->height); /* expand white from center */ XFillRectangle (st->dpy, st->window, st->fg_gc, max - (radius * ratio), 0, radius * ratio * 2, st->height); } else if (st->ratio < mode2) /* squeeze from the top/bottom */ { double ratio = (st->ratio - mode1) / (mode2 - mode1); double prev_ratio = (st->prev_ratio - mode1) / (mode2 - mode1); int max = st->height / 2; int step = (max * ratio) - (max * prev_ratio); if (step <= 0) step = 1; /* fill middle */ XFillRectangle (st->dpy, st->window, st->fg_gc, st->width/2 - radius, max * ratio, radius*2, st->height * (1 - ratio)); /* fill left and right */ XFillRectangle (st->dpy, st->window, st->bg_gc, 0, 0, st->width/2 - radius, st->height); XFillRectangle (st->dpy, st->window, st->bg_gc, st->width/2 + radius, 0, st->width/2, st->height); /* fill top and bottom */ XFillRectangle (st->dpy, st->window, st->bg_gc, 0, 0, st->width, max * ratio); XFillRectangle (st->dpy, st->window, st->bg_gc, 0, st->height - (max * ratio), st->width, max); /* cap top */ XFillArc (st->dpy, st->window, st->fg_gc, st->width/2 - radius, max * ratio - radius, radius*2, radius*2, 0, 180*64); /* cap bottom */ XFillArc (st->dpy, st->window, st->fg_gc, st->width/2 - radius, st->height - (max * ratio + radius), radius*2, radius*2, 180*64, 180*64); } else /* starburst */ { double ratio = (st->ratio - mode2) / (mode3 - mode2); double r2 = ratio * radius * 4; XArc arc[9]; int i; int angle = 360*64/countof(arc); for (i = 0; i < countof(arc); i++) { double th; arc[i].angle1 = angle * i; arc[i].angle2 = angle; arc[i].width = radius*2 * (1 + ratio); arc[i].height = radius*2 * (1 + ratio); arc[i].x = st->width / 2 - radius; arc[i].y = st->height / 2 - radius; th = ((arc[i].angle1 + (arc[i].angle2 / 2)) / 64.0 / 180 * M_PI); arc[i].x += r2 * cos (th); arc[i].y -= r2 * sin (th); } XFillRectangle (st->dpy, st->window, st->bg_gc, 0, 0, st->width, st->height); XFillArcs (st->dpy, st->window, st->fg_gc, arc, countof(arc)); } }
void draw_bouboule(ModeInfo * mi) /****************/ { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); int i, diff = 0; double CX, CY, CZ, SX, SY, SZ; Star *star; XArc *arc, *arcleft = (XArc *) NULL; StarField *sp; #if (ADAPT_ERASE == 1) struct timeval tv1; struct timeval tv2; #endif #if ((USEOLDXARCS == 0) || (ADAPT_ERASE == 1)) short x_1, y_1, x_2, y_2; /* bounding rectangle around the old starfield, * for erasing with the smallest rectangle * instead of filling the whole screen */ int maxdiff = 0; /* maximal distance between left and right */ /* star in 3d mode, otherwise 0 */ #endif if (starfield == NULL) return; sp = &starfield[MI_SCREEN(mi)]; if (sp->star == NULL) return; MI_IS_DRAWN(mi) = True; #if ((USEOLDXARCS == 0) || (ADAPT_ERASE == 1)) if (MI_IS_USE3D(mi)) { maxdiff = (int) MAXDIFF; } x_1 = (int) sp->x.value - (int) sp->sizex.value - sp->max_star_size - maxdiff; y_1 = (int) sp->y.value - (int) sp->sizey.value - sp->max_star_size; x_2 = 2 * ((int) sp->sizex.value + sp->max_star_size + maxdiff); y_2 = 2 * ((int) sp->sizey.value + sp->max_star_size); #endif /* We make variables vary. */ sinvary(&sp->thetax); sinvary(&sp->thetay); sinvary(&sp->thetaz); sinvary(&sp->x); sinvary(&sp->y); if (MI_IS_USE3D(mi)) sinvary(&sp->z); /* A little trick to prevent the bouboule from being * bigger than the screen */ sp->sizex.maximum = MIN(((double) sp->width) - sp->x.value, sp->x.value); sp->sizex.minimum = sp->sizex.maximum / 3.0; /* Another trick to make the ball not too flat */ sp->sizey.minimum = MAX(sp->sizex.value / MAX_SIZEX_SIZEY, sp->sizey.maximum / 3.0); sp->sizey.maximum = MIN(sp->sizex.value * MAX_SIZEX_SIZEY, MIN(((double) sp->height) - sp->y.value, sp->y.value)); sinvary(&sp->sizex); sinvary(&sp->sizey); /* * We calculate the rotation matrix values. We just make the * rotation on the fly, without using a matrix. * Star positions are recorded as unit vectors pointing in various * directions. We just make them all rotate. */ CX = cos(sp->thetax.value); SX = sin(sp->thetax.value); CY = cos(sp->thetay.value); SY = sin(sp->thetay.value); CZ = cos(sp->thetaz.value); SZ = sin(sp->thetaz.value); for (i = 0; i < sp->NbStars; i++) { star = &(sp->star[i]); arc = &(sp->xarc[i]); if (MI_IS_USE3D(mi)) { arcleft = &(sp->xarcleft[i]); /* to help the eyes, the starfield is always as wide as */ /* deep, so .sizex.value can be used. */ diff = (int) GETZDIFF(sp->sizex.value * ((SY * CX) * star->x + (SX) * star->y + (CX * CY) * star->z) + sp->z.value); } arc->x = (short) ((sp->sizex.value * ((CY * CZ - SX * SY * SZ) * star->x + (-CX * SZ) * star->y + (SY * CZ + SZ * SX * CY) * star->z) + sp->x.value)); arc->y = (short) ((sp->sizey.value * ((CY * SZ + SX * SY * CZ) * star->x + (CX * CZ) * star->y + (SY * SZ - SX * CY * CZ) * star->z) + sp->y.value)); if (MI_IS_USE3D(mi)) { arcleft->x = (short) ((sp->sizex.value * ((CY * CZ - SX * SY * SZ) * star->x + (-CX * SZ) * star->y + (SY * CZ + SZ * SX * CY) * star->z) + sp->x.value)); arcleft->y = (short) ((sp->sizey.value * ((CY * SZ + SX * SY * CZ) * star->x + (CX * CZ) * star->y + (SY * SZ - SX * CY * CZ) * star->z) + sp->y.value)); arc->x += diff; arcleft->x -= diff; } if (star->size != 0) { arc->x -= star->size; arc->y -= star->size; if (MI_IS_USE3D(mi)) { arcleft->x -= star->size; arcleft->y -= star->size; } } } /* First, we erase the previous starfield */ if (MI_IS_INSTALL(mi) && MI_IS_USE3D(mi)) XSetForeground(display, gc, MI_NONE_COLOR(mi)); else XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); #if (ADAPT_ERASE == 1) if (sp->hasbeenchecked == 0) { /* We just calculate which method is the faster and eventually free * the oldxarc list */ if (sp->xarc_time > ADAPT_ARC_PREFERED * sp->rect_time) { sp->hasbeenchecked = -2; /* XFillRectangle mode */ free(sp->oldxarc); sp->oldxarc = (XArc *) NULL; if (MI_IS_USE3D(mi)) { free(sp->oldxarcleft); sp->oldxarcleft = (XArc *) NULL; } } else { sp->hasbeenchecked = -1; /* XFillArcs mode */ } } if (sp->hasbeenchecked == -2) { /* Erasing is done with XFillRectangle */ XFillRectangle(display, window, gc, x_1, y_1, x_2, y_2); } else if (sp->hasbeenchecked == -1) { /* Erasing is done with XFillArcs */ XFillArcs(display, window, gc, sp->oldxarc, sp->NbStars); if (MI_IS_USE3D(mi)) XFillArcs(display, window, gc, sp->oldxarcleft, sp->NbStars); } else { long usec; if (sp->hasbeenchecked > ADAPT_CHECKS) { GETTIMEOFDAY(&tv1); XFillRectangle(display, window, gc, x_1, y_1, x_2, y_2); GETTIMEOFDAY(&tv2); usec = (tv2.tv_sec - tv1.tv_sec) * 1000000; if (usec + tv2.tv_usec - tv1.tv_usec > 0) { sp->rect_time += usec + tv2.tv_usec - tv1.tv_usec; sp->hasbeenchecked--; } } else { GETTIMEOFDAY(&tv1); XFillArcs(display, window, gc, sp->oldxarc, sp->NbStars); if (MI_IS_USE3D(mi)) XFillArcs(display, window, gc, sp->oldxarcleft, sp->NbStars); GETTIMEOFDAY(&tv2); usec = (tv2.tv_sec - tv1.tv_sec) * 1000000; if (usec + tv2.tv_usec - tv1.tv_usec > 0) { sp->xarc_time += usec + tv2.tv_usec - tv1.tv_usec; sp->hasbeenchecked--; } } } #else #if (USEOLDXARCS == 1) XFillArcs(display, window, gc, sp->oldxarc, sp->NbStars); if (MI_IS_USE3D(mi)) XFillArcs(display, window, gc, sp->oldxarcleft, sp->NbStars); #else XFillRectangle(display, window, gc, x_1, y_1, x_2, y_2); #endif #endif /* Then we draw the new one */ if (MI_IS_USE3D(mi)) { if (MI_IS_INSTALL(mi)) XSetFunction(display, gc, GXor); XSetForeground(display, gc, MI_RIGHT_COLOR(mi)); XFillArcs(display, window, gc, sp->xarc, sp->NbStars); XSetForeground(display, gc, MI_LEFT_COLOR(mi)); XFillArcs(display, window, gc, sp->xarcleft, sp->NbStars); if (MI_IS_INSTALL(mi)) XSetFunction(display, gc, GXcopy); } else { XSetForeground(display, gc, sp->color); XFillArcs(display, window, gc, sp->xarc, sp->NbStars); } #if ((USEOLDXARCS == 1) || (ADAPT_ERASE == 1)) #if (ADAPT_ERASE == 1) if (sp->hasbeenchecked >= -1) { arc = sp->xarc; sp->xarc = sp->oldxarc; sp->oldxarc = arc; if (MI_IS_USE3D(mi)) { arcleft = sp->xarcleft; sp->xarcleft = sp->oldxarcleft; sp->oldxarcleft = arcleft; } } #else arc = sp->xarc; sp->xarc = sp->oldxarc; sp->oldxarc = arc; if (MI_IS_USE3D(mi)) { arcleft = sp->xarcleft; sp->xarcleft = sp->oldxarcleft; sp->oldxarcleft = arcleft; } #endif #endif /* We set up the color for the next drawing */ if (!MI_IS_USE3D(mi) && MI_NPIXELS(mi) > 2 && (++sp->colorchange >= COLOR_CHANGES)) { sp->colorchange = 0; if (++sp->colorp >= MI_NPIXELS(mi)) sp->colorp = 0; sp->color = MI_PIXEL(mi, sp->colorp); } }
main() { Window w2; Display *dpy = XOpenDisplay(NIL); assert(dpy); Screen *scr = DefaultScreenOfDisplay(dpy); // CreateWindow Window w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XDestroyWindow(dpy, w); // CreateWindow with arguments XSetWindowAttributes swa; swa.background_pixel = WhitePixelOfScreen(scr); swa.bit_gravity = NorthWestGravity; swa.border_pixel = BlackPixelOfScreen(scr); swa.colormap = DefaultColormapOfScreen(scr); swa.cursor = None; swa.win_gravity = NorthGravity; w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixel | CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWWinGravity, &swa); // CreateWindow with other arguments XDestroyWindow(dpy, w); Pixmap pixmap = XCreatePixmap(dpy, RootWindowOfScreen(scr), 45, 25, DefaultDepthOfScreen(scr)); assert(pixmap); swa.background_pixmap = pixmap; swa.border_pixmap = pixmap; w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixmap | CWBorderPixmap, &swa); // ChangeWindowAttributes swa.backing_planes = 0x1; swa.backing_pixel = WhitePixelOfScreen(scr); swa.save_under = True; swa.event_mask = KeyPressMask | KeyReleaseMask; swa.do_not_propagate_mask = ButtonPressMask | Button4MotionMask; swa.override_redirect = False; XChangeWindowAttributes(dpy, w, CWBackingPlanes | CWBackingPixel | CWSaveUnder | CWEventMask | CWDontPropagate | CWOverrideRedirect, &swa); // GetWindowAttributes XWindowAttributes wa; Status success = XGetWindowAttributes(dpy, w, &wa); // DestroyWindow (done) // DestroySubwindows w2 = XCreateWindow(dpy, w, 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XDestroySubwindows(dpy, w); // ChangeSaveSet // Display *dpy2 = XOpenDisplay(NIL); // assert(dpy2); // XAddToSaveSet(dpy2, w); // XCloseDisplay(dpy2); // ReparentWindow w2 = XCreateWindow(dpy, RootWindowOfScreen(scr), 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XReparentWindow(dpy, w2, w, 10, 5); // MapWindow XMapWindow(dpy, w); // MapSubwindows XMapSubwindows(dpy, w); // UnmapWindow XUnmapWindow(dpy, w); // UnmapSubwindows XMapWindow(dpy, w); XUnmapSubwindows(dpy, w2); XMapSubwindows(dpy, w); // ConfigureWindow Window w3 = XCreateWindow(dpy, w, 10, 50, 100, 10, 2, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XMapWindow(dpy, w3); XWindowChanges wc; wc.x = -5; wc.y = -10; wc.width = 50; wc.height = 40; wc.border_width = 7; wc.sibling = w2; wc.stack_mode = Opposite; XConfigureWindow(dpy, w3, CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWSibling | CWStackMode, &wc); // CirculateWindow XCirculateSubwindows(dpy, w, RaiseLowest); // GetGeometry Window root; int x, y; unsigned width, height, border_width, depth; XGetGeometry(dpy, w, &root, &x, &y, &width, &height, &border_width, &depth); // QueryTree Window parent; Window *children; unsigned nchildren; success = XQueryTree(dpy, w, &root, &parent, &children, &nchildren); XFree(children); // InternAtom Atom a = XInternAtom(dpy, "WM_PROTOCOLS", True); // GetAtomName char *string = XGetAtomName(dpy, XA_PRIMARY); XFree(string); // ChangeProperty XStoreName(dpy, w, "test window"); // DeleteProperty XDeleteProperty(dpy, w, XA_WM_NAME); // GetProperty // TODO // ListProperties int num_prop; Atom *list = XListProperties(dpy, w, &num_prop); XFree(list); // SetSelectionOwner XSetSelectionOwner(dpy, XA_PRIMARY, w, 12000); XSetSelectionOwner(dpy, XA_SECONDARY, w, CurrentTime); // GetSelectionOwner Window wx = XGetSelectionOwner(dpy, XA_PRIMARY); // ConvertSelection XConvertSelection(dpy, XA_SECONDARY, XA_CURSOR, XA_POINT, w, CurrentTime); // SendEvent // GrabPointer std::cerr << "Grabbing" << std::endl; int res = XGrabPointer(dpy, w, False, Button5MotionMask | PointerMotionHintMask, GrabModeSync, GrabModeAsync, w, None, CurrentTime); XSync(dpy, False); // sleep(5); // UngrabPointer std::cerr << "Ungrabbing" << std::endl; XUngrabPointer(dpy, CurrentTime); // GrabButton XGrabButton(dpy, 3, ShiftMask | ControlMask, w, False, PointerMotionHintMask | Button2MotionMask, GrabModeAsync, GrabModeSync, None, None); XGrabButton(dpy, 2, AnyModifier, w, False, PointerMotionHintMask | Button2MotionMask, GrabModeAsync, GrabModeSync, None, None); // UngrabButton XUngrabButton(dpy, 2, LockMask, w); // ChangeActivePointerGrab XChangeActivePointerGrab(dpy, ButtonPressMask, None, CurrentTime); // GrabKeyboard XGrabKeyboard(dpy, w, True, GrabModeSync, GrabModeSync, 12000); // UngrabKeyboard XUngrabKeyboard(dpy, 13000); // GrabKey XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Tab), ShiftMask | Mod3Mask, w, True, GrabModeSync, GrabModeSync); // UngrabKey XUngrabKey(dpy, AnyKey, AnyModifier, w); // AllowEvents XAllowEvents(dpy, AsyncPointer, 14000); // GrabServer XGrabServer(dpy); // UngrabServer XUngrabServer(dpy); // QueryPointer Window child; int root_x, root_y, win_x, win_y; unsigned mask; Bool bres = XQueryPointer(dpy, w, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask); // GetMotionEvents int nevents; XGetMotionEvents(dpy, w, 15000, 16000, &nevents); // TranslateCoordinates int dest_x, dest_y; XTranslateCoordinates(dpy, w, w2, 10, 20, &dest_x, &dest_y, &child); // WarpPointer XWarpPointer(dpy, w, w2, 0, 0, 100, 100, 20, 30); // SetInputFocus XSetInputFocus(dpy,w, RevertToPointerRoot, 17000); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, 17000); // GetInputFocus Window focus; int revert_to; XGetInputFocus(dpy, &focus, &revert_to); // QueryKeymap char keys_return[32]; XQueryKeymap(dpy, keys_return); // OpenFont Font fid = XLoadFont(dpy, "cursor"); // CloseFont XUnloadFont(dpy, fid); // QueryFont XFontStruct *fs = XLoadQueryFont(dpy, "cursor"); assert(fs); // QueryTextExtents int direction, font_ascent, font_descent; XCharStruct overall; XQueryTextExtents(dpy, fs -> fid, "toto", 4, &direction, &font_ascent, &font_descent, &overall); XQueryTextExtents(dpy, fs -> fid, "odd__length", 11, &direction, &font_ascent, &font_descent, &overall); XChar2b c2bs; c2bs.byte1 = '$'; c2bs.byte2 = 'B'; XQueryTextExtents16(dpy, fs -> fid, &c2bs, 1, &direction, &font_ascent, &font_descent, &overall); XQueryTextExtents(dpy, fs -> fid, longString, strlen(longString), &direction, &font_ascent, &font_descent, &overall); // ListFonts int actual_count; char **fontList = XListFonts(dpy, "*", 100, &actual_count); XFree((char *)fontList); // ListFontsWithInfo int count; XFontStruct *info; char **names = XListFontsWithInfo(dpy, "*", 100, &count, &info); XFreeFontInfo(names, info, count); // SetFontPath // GetFontPath int npaths; char **charList = XGetFontPath(dpy, &npaths); char **charList2 = new char *[npaths + 1]; memcpy(charList2, charList, npaths * sizeof(char *)); charList2[npaths] = charList2[0]; XSetFontPath(dpy, charList2, npaths + 1); XSetFontPath(dpy, charList, npaths); // Reset to some reasonnable value XFreeFontPath(charList); delete [] charList2; // CreatePixmap Pixmap pix2 = XCreatePixmap(dpy, w, 100, 200, DefaultDepthOfScreen(scr)); // FreePixmap XFreePixmap(dpy, pix2); // CreateGC Pixmap bitmap = XCreateBitmapFromData(dpy, RootWindowOfScreen(scr), "\000\000\001\000\000\001\000\000\001\377\377\377", 3, 4); XGCValues gcv; gcv.function = GXand; gcv.plane_mask = 0x1; gcv.foreground = WhitePixelOfScreen(scr); gcv.background = BlackPixelOfScreen(scr); gcv.line_width = 2; gcv.line_style = LineDoubleDash; gcv.cap_style = CapProjecting; gcv.join_style = JoinRound; gcv.fill_style = FillStippled; gcv.fill_rule = EvenOddRule; gcv.arc_mode = ArcPieSlice; gcv.tile = pixmap; gcv.stipple = bitmap; gcv.ts_x_origin = 3; gcv.ts_y_origin = 4; gcv.font = fs -> fid; gcv.subwindow_mode = ClipByChildren; gcv.graphics_exposures = True; gcv.clip_x_origin = 5; gcv.clip_y_origin = 6; gcv.clip_mask = bitmap; gcv.dash_offset = 1; gcv.dashes = 0xc2; GC gc = XCreateGC(dpy, w, GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule | GCTile | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCFont | GCSubwindowMode | GCGraphicsExposures | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCDashOffset | GCDashList | GCArcMode, &gcv); // ChangeGC gcv.function = GXandReverse; // Only a few of these should appear, since the values are cached on the client side by the Xlib. XChangeGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, &gcv); // CopyGC GC gc2 = XCreateGC(dpy, w, 0, NIL); XCopyGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, gc2); // SetDashes XSetDashes(dpy, gc, 3, "\001\377\001", 3); // SetClipRectangles XRectangle rectangles[] = { { 10, 20, 30, 40 }, { 100, 200, 5, 3 }, { -5, 1, 12, 24 } }; XSetClipRectangles(dpy, gc, 12, 9, rectangles, SIZEOF(rectangles), Unsorted); // FreeGC // done already // ClearArea XClearArea(dpy, w, 30, 10, 10, 100, False); // CopyArea XCopyArea(dpy, w, pixmap, gc, 0, 0, 100, 100, 10, 10); // CopyPlane // This won't work if the Screen doesn't have at least 3 planes XCopyPlane(dpy, pixmap, w, gc, 20, 10, 40, 30, 0, 0, 0x4); // PolyPoint XDrawPoint(dpy, w, gc, 1, 2); XPoint points[] = { { 3, 4 }, { 5, 6 } }; XDrawPoints(dpy, w, gc, points, SIZEOF(points), CoordModeOrigin); // PolyLine XDrawLines(dpy, w, gc, points, SIZEOF(points), CoordModePrevious); // PolySegment XSegment segments[] = { { 7, 8, 9, 10 }, { 11, 12, 13, 14 }, { 15, 16, 17, 18 } }; XDrawSegments(dpy, w, gc, segments, SIZEOF(segments)); // PolyRectangle XDrawRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles)); // PolyArc XArc arcs[] = { { 10, 20, 30, 40, 50, 60 }, { -70, 80, 90, 100, 110, 120 }, { 10, 20, 30, 40, 50, -30 } }; XDrawArcs(dpy, w, gc, arcs, SIZEOF(arcs)); // FillPoly XFillPolygon(dpy, w, gc, points, SIZEOF(points), Convex, CoordModePrevious); // PolyFillRectangle XFillRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles)); // PolyFillArc XFillArcs(dpy, w, gc, arcs, SIZEOF(arcs)); // PutImage // GetImage XImage *image = XGetImage(dpy, w, 10, 20, 40, 30, AllPlanes, ZPixmap); XPutImage(dpy, w, gc, image, 0, 0, 50, 60, 40, 30); XSync(dpy, False); // Make the next request starts at the beginning of a packet // PolyText8 XTextItem textItems[3]; textItems[0].chars = "toto"; textItems[0].nchars = strlen(textItems[0].chars); textItems[0].delta = -3; textItems[0].font = fs->fid; textItems[1].chars = "titi"; textItems[1].nchars = strlen(textItems[1].chars); textItems[1].delta = 3; textItems[1].font = None; textItems[2].chars = "tutu"; textItems[2].nchars = strlen(textItems[2].chars); textItems[2].delta = 0; textItems[2].font = fs->fid; XDrawText(dpy, w, gc, 10, 10, textItems, 3); XTextItem textItems2[3]; textItems2[0].chars = "totox"; textItems2[0].nchars = strlen(textItems2[0].chars); textItems2[0].delta = -3; textItems2[0].font = fs->fid; textItems2[1].chars = "titi"; textItems2[1].nchars = strlen(textItems2[1].chars); textItems2[1].delta = 3; textItems2[1].font = None; textItems2[2].chars = "tutu"; textItems2[2].nchars = strlen(textItems2[2].chars); textItems2[2].delta = 0; textItems2[2].font = fs->fid; XDrawText(dpy, w, gc, 10, 10, textItems2, 3); // PolyText16 XChar2b c2b2[] = { 0, 't', 0, 'x' }; XTextItem16 items16[] = { { &c2bs, 1, -5, None }, { NULL, 0, 0, None }, { c2b2, 2, 0, fs -> fid } }; XDrawText16(dpy, w, gc, 10, 0, items16, SIZEOF(items16)); // ImageText8 XDrawImageString(dpy, w, gc, 10, 10, "toto", 4); // ImageText16 XDrawImageString16(dpy, w, gc, 10, 10, &c2bs, 1); XDrawImageString16(dpy, w, gc, 10, 20, c2b2, 2); // CreateColormap // Don't forget to tell the kids how it was when we had only 8 bits per pixel. Colormap colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None); // FreeColormap XFreeColormap(dpy, colormap); colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None); // CopyColormapAndFree Colormap colormap2 = XCopyColormapAndFree(dpy, colormap); // InstallColormap XInstallColormap(dpy, colormap2); // UninstallColormap XUninstallColormap(dpy, colormap2); // ListInstalledColormaps int num; Colormap *colormapList = XListInstalledColormaps(dpy, w, &num); // AllocColor XColor screen; screen.red = 0; screen.green = 32767; screen.blue = 65535; screen.flags = DoRed | DoGreen | DoBlue; success = XAllocColor(dpy, colormap, &screen); // AllocNamedColor XColor screen2, exact; success = XAllocNamedColor(dpy, colormap, "Wheat", &screen2, &exact); // AllocColorCells unsigned long plane_masks, pixels; success = XAllocColorCells(dpy, colormap, False, &plane_masks, 1, &pixels, 1); // AllocColorPlanes unsigned long rmask, gmask, bmask; success = XAllocColorPlanes(dpy, colormap, False, &pixels, 1, 0, 0, 0, &rmask, &gmask, &bmask); // FreeColors unsigned long pixels2[2] = { screen.pixel, screen2.pixel }; XFreeColors(dpy, colormap, pixels2, 2, 0); // StoreColors success = XAllocColorCells(dpy, colormap, False, NIL, 0, pixels2, 2); // On many contemporary (that is, year 2000) video cards, you can't allocate read / write cells // I want my requests to be sent, however. if (!success) { XSetErrorHandler(errorHandler); } XColor colors[2]; colors[0] = screen; colors[0].pixel = pixels2[0]; colors[1] = screen2; colors[1].pixel = pixels2[1]; XStoreColors(dpy, colormap, colors, 2); // StoreNamedColor XStoreNamedColor(dpy, colormap, "Wheat", colors[0].pixel, DoBlue); XSync(dpy, False); XSetErrorHandler(NIL); // Restore the default handler // QueryColors screen2.pixel = WhitePixelOfScreen(scr); XQueryColor(dpy, colormap, &screen2); // LookupColor success = XLookupColor(dpy, colormap, "DarkCyan", &exact, &screen); // CreateCursor Cursor cursor = XCreatePixmapCursor(dpy, pixmap, None, &exact, colors, 10, 10); // CreateGlyphCursor Cursor cursor2 = XCreateGlyphCursor(dpy, fs -> fid, fs -> fid, 'X', 0, &exact, colors); // FreeCursor XFreeCursor(dpy, cursor2); // RecolorCursor XRecolorCursor(dpy, cursor, colors, &exact); // QueryBestSize success = XQueryBestSize(dpy, CursorShape, RootWindowOfScreen(scr), 100, 20, &width, &height); // QueryExtension int major_opcode, first_event, first_error; XQueryExtension(dpy, "toto", &major_opcode, &first_event, &first_error); // ListExtensions int nextensions; char **extensionList = XListExtensions(dpy, &nextensions); for(char **p = extensionList; nextensions; nextensions--, p++) std::cout << *p << std::endl; XFree(extensionList); // ChangeKeyboardMapping // GetKeyboardMapping int min_keycodes, max_keycodes; XDisplayKeycodes(dpy, &min_keycodes, &max_keycodes); int keysyms_per_keycode; KeySym *keysyms = XGetKeyboardMapping(dpy, min_keycodes, max_keycodes - min_keycodes + 1, &keysyms_per_keycode); XChangeKeyboardMapping(dpy, min_keycodes, keysyms_per_keycode, keysyms, max_keycodes - min_keycodes + 1); // ChangeKeyboardControl // GetKeyboardControl XKeyboardState keyboardState; XGetKeyboardControl(dpy, &keyboardState); XKeyboardControl keyboardValues; keyboardValues.key_click_percent = keyboardState.key_click_percent; keyboardValues.bell_percent = keyboardState.bell_percent; keyboardValues.bell_pitch = keyboardState.bell_pitch; keyboardValues.bell_duration = keyboardState.bell_duration; keyboardValues.led = 1; keyboardValues.led_mode = LedModeOn; keyboardValues.key = min_keycodes; keyboardValues.auto_repeat_mode = AutoRepeatModeDefault; XChangeKeyboardControl(dpy, KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration | KBLed | KBLedMode | KBKey | KBAutoRepeatMode, &keyboardValues); // Bell XBell(dpy, 90); // ChangePointerControl // GetPointerControl int accel_numerator, accel_denominator, threshold; XGetPointerControl(dpy, &accel_numerator, &accel_denominator, &threshold); XChangePointerControl(dpy, True, True, accel_numerator, accel_denominator, threshold); // SetScreenSaver // GetScreenSaver int timeout, interval, prefer_blanking, allow_exposures; XGetScreenSaver(dpy, &timeout, &interval, &prefer_blanking, &allow_exposures); XSetScreenSaver(dpy, timeout, interval, prefer_blanking, allow_exposures); // ChangeHosts // ListHosts int nhosts; Bool state; XHostAddress *hostList = XListHosts(dpy, &nhosts, &state); XHostAddress host; host.family = FamilyInternet; host.length = 4; host.address = "\001\002\003\004"; XAddHost(dpy, &host); // SetAccessControl XSetAccessControl(dpy, EnableAccess); // SetCloseDownMode XSetCloseDownMode(dpy, RetainTemporary); // KillClient XKillClient(dpy, AllTemporary); // RotateProperties Atom properties[] = { XInternAtom(dpy, "CUT_BUFFER0", False), XInternAtom(dpy, "CUT_BUFFER1", False), XInternAtom(dpy, "CUT_BUFFER2", False) }; XRotateWindowProperties(dpy, RootWindowOfScreen(scr), properties, SIZEOF(properties), -1); // ForceScreenSaver XForceScreenSaver(dpy, ScreenSaverReset); // SetPointerMapping // GetPointerMapping unsigned char map[64]; int map_length = XGetPointerMapping(dpy, map, 64); XSetPointerMapping(dpy, map, map_length); // SetModifierMapping // GetModifierMapping XModifierKeymap *modmap = XGetModifierMapping(dpy); XSetModifierMapping(dpy, modmap); // NoOperation XNoOp(dpy); for(;;) { XEvent e; XNextEvent(dpy, &e); std::cout << "Got an event of type " << e.type << std::endl; } }
int main( int argc, char *argv[] ) { Display *w_dis; Window w_win; XSetWindowAttributes w_att; GC w_gc; XEvent w_eve; XPoint p1[10], p2[10]; XSegment s1[10], s2[10]; XArc arc1[10], arc2[10]; XRectangle rect1[10], rect2[10]; char w_title[] = "kt-draw"; char w_icon_title[] = "ICON!"; int i; w_dis = XOpenDisplay( NULL ); w_win = XCreateSimpleWindow( w_dis, RootWindow( w_dis, 0 ),20 ,20 , 500, 400, 2, 0, 1); XSetStandardProperties( w_dis, w_win, w_title, w_icon_title, None, argv, argc, NULL ); w_att.override_redirect = True; XChangeWindowAttributes( w_dis, w_win, CWOverrideRedirect, &w_att ); XSelectInput( w_dis, w_win, ExposureMask ); XMapWindow( w_dis, w_win ); do{ XNextEvent( w_dis, &w_eve); }while( w_eve.type != Expose ); w_gc = XCreateGC( w_dis, w_win, 0, 0 ); XSetForeground( w_dis, w_gc, GetColor( w_dis, "green" )); // sample start XDrawLine( w_dis, w_win, w_gc, 50, 100, 450, 100 ); XDrawLine( w_dis, w_win, w_gc, 50, 100+50, 450, 100+50 ); for( i = 0; i < 10; i++ ) { s1[i].x1 = (i * 5) + 250; s1[i].y1 = 110; s1[i].x2 = (i * 5) + 250; s1[i].y2 = 130; } XDrawSegments( w_dis, w_win, w_gc, s1, 10 ); for( i = 0; i < 10; i++ ) { s2[i].x1 = 310; s2[i].y1 = (i * 4) + 110; s2[i].x2 = 350; s2[i].y2 = (i * 4) + 110; } XDrawSegments( w_dis, w_win, w_gc, s2, 10 ); for( i = 0; i < 10; i++ ) { p1[i].x = (i * 5) + 280; if (i==0 || i==2 || i==4 || i==6 || i==8 ) { p1[i].y = (i * 5) + 200; } else { p1[i].y = (i * (-5)) + 200; } } XDrawLines( w_dis, w_win, w_gc, p1, 10, CoordModeOrigin ); p2[0].x = 340; p2[0].y = 200; for( i = 1; i < 10; i++ ) { p2[i].x = 5; if (i==0 || i==2 || i==4 || i==6 || i==8 ) { p2[i].y = i * 5; } else { p2[i].y = i * (-5); } } XDrawLines( w_dis, w_win, w_gc, p2, 10, CoordModePrevious ); XDrawPoint( w_dis, w_win, w_gc, 55, 105 ); XDrawPoint( w_dis, w_win, w_gc, 55+10, 105+10 ); for( i = 0; i < 10; i++ ) { p1[i].x = (i * 5) + 100; p1[i].y = 300; } XDrawPoints( w_dis, w_win, w_gc, p1, 10, CoordModeOrigin ); p2[0].x = 100; p2[0].y = 310; for( i = 1; i < 10; i++ ) { p2[i].x = 5; p2[i].y = 0; } XDrawPoints( w_dis, w_win, w_gc, p2, 10, CoordModePrevious ); XDrawArc( w_dis, w_win, w_gc, 50, 50, 50, 50, 45*64, 135*64 ); XDrawArc( w_dis, w_win, w_gc, 50+100, 50, 50, 50, (45+30)*64, (135+30)*64 ); for( i = 0; i < 10; i++ ) { arc1[i].x = (i * 15) + 250; arc1[i].y = 50; arc1[i].width = 10; arc1[i].height = 10; arc1[i].angle1 = 0; arc1[i].angle2 = ((i + 1) * 36) * 64; } XDrawArcs( w_dis, w_win, w_gc, arc1, 10 ); for( i = 0; i < 10; i++ ) { arc2[i].x = (i * 15) + 250; arc2[i].y = 50 + 15; arc2[i].width = 10; arc2[i].height = 10; arc2[i].angle1 = 0; arc2[i].angle2 = ((10 - i) * 36) * 64; } XDrawArcs( w_dis, w_win, w_gc, arc2, 10 ); XFillArc( w_dis, w_win, w_gc, 100, 50, 50, 50, 45*64, 135*64 ); XFillArc( w_dis, w_win, w_gc, 100+100, 50, 50, 50, (45+30)*64, (135+30)*64 ); for( i = 0; i < 10; i++ ) { arc1[i].x = (i * 15) + 250; arc1[i].y = 50 + 25; arc1[i].width = 10; arc1[i].height = 10; arc1[i].angle1 = 0; arc1[i].angle2 = ((i + 1) * 36) * 64; } XFillArcs( w_dis, w_win, w_gc, arc1, 10 ); for( i = 0; i < 10; i++ ) { arc2[i].x = (i * 15) + 250; arc2[i].y = 50 + 37; arc2[i].width = 10; arc2[i].height = 10; arc2[i].angle1 = 0; arc2[i].angle2 = ((10 - i) * 36) * 64; } XFillArcs( w_dis, w_win, w_gc, arc2, 10 ); XDrawRectangle( w_dis, w_win, w_gc, 60, 110, 160, 210 ); XDrawRectangle( w_dis, w_win, w_gc, 60+30, 110+30, 160, 210 ); for( i = 0; i < 10; i++ ) { rect1[i].x = (i * 15) + 280; rect1[i].y = 300; rect1[i].width = 10; rect1[i].height = 10; } XDrawRectangles( w_dis, w_win, w_gc, rect1, 10 ); for( i = 0; i < 10; i++ ) { rect2[i].x = (i * 15) + 280; rect2[i].y = 300 + 20; rect2[i].width = 10; rect2[i].height = 10; } XDrawRectangles( w_dis, w_win, w_gc, rect2, 10 ); XFillRectangle( w_dis, w_win, w_gc, 70, 120, 100, 100 ); XFillRectangle( w_dis, w_win, w_gc, 70+100, 120+100, 100, 100 ); for( i = 0; i < 10; i++ ) { rect1[i].x = (i * 15) + 280; rect1[i].y = 300 + 40; rect1[i].width = 10; rect1[i].height = 10; } XFillRectangles( w_dis, w_win, w_gc, rect1, 10 ); for( i = 0; i < 10; i++ ) { rect2[i].x = (i * 15) + 280; rect2[i].y = 300 + 60; rect2[i].width = 10; rect2[i].height = 10; } XFillRectangles( w_dis, w_win, w_gc, rect2, 10 ); // sample end XFlush( w_dis ); printf( "Push return key." ); getchar( ); XDestroyWindow( w_dis , w_win ); XCloseDisplay( w_dis ); return( 0 ); }