+
+/* The documentation for the XSHM extension implies that if the server
+ supports XSHM but is not the local machine, the XShm calls will return
+ False; but this turns out not to be the case. Instead, the server
+ throws a BadAccess error. So, we need to catch X errors around all
+ of our XSHM calls, sigh.
+ */
+
+static Bool shm_got_x_error = False;
+XErrorHandler old_handler = 0;
+static int
+shm_ehandler (Display *dpy, XErrorEvent *error)
+{
+ shm_got_x_error = True;
+
+#ifdef DEBUG
+ fprintf (stderr, "\n%s: ignoring X error from XSHM:\n", progname);
+ XmuPrintDefaultErrorMessage (dpy, error, stderr);
+ fprintf (stderr, "\n");
+#endif
+
+ return 0;
+}
+
+
+#define CATCH_X_ERROR(DPY) do { \
+ XSync((DPY), False); \
+ shm_got_x_error = False; \
+ if (old_handler != shm_ehandler) \
+ old_handler = XSetErrorHandler (shm_ehandler); \
+} while(0)
+
+#define UNCATCH_X_ERROR(DPY) do { \
+ XSync((DPY), False); \
+ if (old_handler) \
+ XSetErrorHandler (old_handler); \
+ old_handler = 0; \
+} while(0)
+
+