summaryrefslogtreecommitdiff
path: root/apps/unix/ximage.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2009-07-27 18:50:59 +0200
committerTor Andersson <tor@ghostscript.com>2009-07-27 18:50:59 +0200
commitcd3a744defafb4cd5484730a5cafeac976770dee (patch)
tree9eb4513ebdc4a0b235a0729198e04ca2dd0905a1 /apps/unix/ximage.c
parent6a4d7b3716b4ae58bd242b4a9b8029e92366aff1 (diff)
downloadmupdf-cd3a744defafb4cd5484730a5cafeac976770dee.tar.xz
Workaround to disable XShmPutImage if we get an error from the MIT-SHM extension. MIT-SHM is erroneously reported as available when tunneling X over ssh.
Diffstat (limited to 'apps/unix/ximage.c')
-rw-r--r--apps/unix/ximage.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/apps/unix/ximage.c b/apps/unix/ximage.c
index cb776e29..34221d0f 100644
--- a/apps/unix/ximage.c
+++ b/apps/unix/ximage.c
@@ -81,6 +81,7 @@ static struct
ximage_convert_func_t convert_func;
int useshm;
+ int shmcode;
XImage *pool[POOLSIZE];
/* MUST exist during the lifetime of the shared ximage according to the
xc/doc/hardcopy/Xext/mit-shm.PS.gz */
@@ -295,6 +296,23 @@ next_pool_image(void)
return info.pool[info.lastused ++];
}
+static int
+ximage_error_handler(Display *display, XErrorEvent *event)
+{
+ /* Turn off shared memory images if we get an error from the MIT-SHM extension */
+ if (event->request_code == info.shmcode)
+ {
+ char buf[80];
+ XGetErrorText(display, event->error_code, buf, sizeof buf);
+ printf("ximage: disabling shared memory extension: %s\n", buf);
+ info.useshm = 0;
+ return 0;
+ }
+
+ XSetErrorHandler(NULL);
+ return (XSetErrorHandler(ximage_error_handler))(display, event);
+}
+
int
ximage_init(Display *display, int screen, Visual *visual)
{
@@ -305,6 +323,9 @@ ximage_init(Display *display, int screen, Visual *visual)
int nformats;
int ok;
int i;
+ int major;
+ int event;
+ int error;
info.display = display;
info.screen = screen;
@@ -341,6 +362,14 @@ ximage_init(Display *display, int screen, Visual *visual)
/* prepare colormap */
make_colormap();
+ /* identify code for MIT-SHM extension */
+ if (XQueryExtension(display, "MIT-SHM", &major, &event, &error) &&
+ XShmQueryExtension(display))
+ info.shmcode = major;
+
+ /* intercept errors looking for SHM code */
+ XSetErrorHandler(ximage_error_handler);
+
/* prepare pool of XImages */
info.useshm = 1;
ok = create_pool();