XQueryExtension merely tells you whether the extension exists, it
doesn't tell you whether you're local enough for it to work.
XShmQueryVersion is not enough to discover this either, you need to
provoke the server to do actual work, and if it thinks you're remote it
will throw BadRequest at you. So send an invalid ShmDetach and use the
error code to distinguish local from remote.
[airlied: fixed bug not resetting xshm_error to 0 on success,
which made later stuff fail completely.]
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Adam Jackson <ajax@redhat.com>
(void) dpy;
assert(xshm_opcode != -1);
(void) dpy;
assert(xshm_opcode != -1);
- if (event->request_code != xshm_opcode ||
- event->minor_code != X_ShmAttach)
+ if (event->request_code != xshm_opcode)
+ xshm_error = event->error_code;
static int
check_xshm(Display *dpy)
{
static int
check_xshm(Display *dpy)
{
+ int (*old_handler)(Display *, XErrorEvent *);
+
+ XShmSegmentInfo info = { 0, };
+
+ if (!XQueryExtension(dpy, "MIT-SHM", &xshm_opcode, &ignore, &ignore))
+ return False;
+
+ old_handler = XSetErrorHandler(handle_xerror);
+ XShmDetach(dpy, &info);
+ XSync(dpy, False);
+ (void) XSetErrorHandler(old_handler);
- return XQueryExtension(dpy, "MIT-SHM", &xshm_opcode, &ignore, &ignore);
+ /* BadRequest means we're a remote client. If we were local we'd
+ * expect BadValue since 'info' has an invalid segment name.
+ */
+ if (xshm_error == BadRequest)
+ return False;
+
+ xshm_error = 0;
+ return True;
}
static struct glx_screen *
}
static struct glx_screen *