+#ifdef XDBG_CLIENT
+Bool get_error_caught;
+
+static int
+_get_error_handle (Display *dpy, XErrorEvent *ev)
+{
+ if (!dpy)
+ return 0;
+
+ get_error_caught = True;
+ return 0;
+}
+#endif
+
+char* xDbgGetAtom(void *dpy, Atom atom, char *reply, int *len)
+{
+#ifdef XDBG_CLIENT
+ Display *d = NULL;
+ XErrorHandler old_handler = NULL;
+
+ RETURN_VAL_IF_FAIL(dpy != NULL, reply);
+
+ get_error_caught = False;
+ d = (Display*)dpy;
+
+ XSync (d, 0);
+ old_handler = XSetErrorHandler (_get_error_handle);
+
+ if(XGetAtomName(d, atom))
+ REPLY("(%s)", XGetAtomName(d, atom));
+ else
+ REPLY("(0x%lx)", atom);
+
+ get_error_caught = False;
+ XSetErrorHandler (old_handler);
+#else
+ if (NameForAtom(atom))
+ REPLY("(%s)", (char*)NameForAtom(atom));
+ else
+ REPLY("(0x%lx)", atom);
+#endif
+
+ return reply;
+}
+
+char* xDbgGetRegion(void* dpy, EvlogInfo *evinfo, XserverRegion region, char *reply, int *len)
+{
+#ifdef XDBG_CLIENT
+ int nrect, i;
+ XRectangle *rects;
+ Display *d = (Display*)dpy;
+ XErrorHandler old_handler = NULL;
+
+ RETURN_VAL_IF_FAIL(dpy != NULL, reply);
+
+ get_error_caught = False;
+ d = (Display*)dpy;
+
+ XSync (d, 0);
+ old_handler = XSetErrorHandler (_get_error_handle);
+
+ rects = XFixesFetchRegion(d, region, &nrect);
+ if (!get_error_caught)
+ {
+ REPLY ("(");
+ for (i = 0; i < nrect; i++)
+ {
+ REPLY ("[%d,%d %dx%d]",
+ rects[i].x,
+ rects[i].y,
+ rects[i].width,
+ rects[i].height);
+ if(i != nrect - 1)
+ REPLY (",");
+ }
+ REPLY (")");
+ }
+ else
+ REPLY ("(0x%lx)", region);
+
+ get_error_caught = False;
+ XSetErrorHandler (old_handler);
+#else
+ extern _X_EXPORT RESTYPE RegionResType;
+ RegionPtr pRegion;
+ BoxPtr rects;
+ int nrect, i;
+
+ int err = dixLookupResourceByType((pointer *) &pRegion, region,
+ RegionResType, (ClientPtr)evinfo->client.pClient,
+ DixReadAccess);
+ if (err != Success)
+ {
+ REPLY ("(0x%lx)", region);
+ return reply;
+ }
+
+ nrect = RegionNumRects(pRegion);
+ rects = RegionRects(pRegion);
+
+ REPLY ("(");
+ for (i = 0; i < nrect; i++)
+ {
+ REPLY ("[%d,%d %dx%d]",
+ rects[i].x1,
+ rects[i].y1,
+ rects[i].x2 - rects[i].x1,
+ rects[i].y2 - rects[i].y1);
+ if(i != nrect - 1)
+ REPLY (",");
+ }
+ REPLY (")");
+#endif
+
+ return reply;
+}