1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
Description: Check for XShm support before using it
Origin: other
Index: koules-1.4/xlib/init.c
===================================================================
--- koules-1.4.orig/xlib/init.c 2006-11-03 11:43:49.000000000 +0100
+++ koules-1.4/xlib/init.c 2006-11-03 11:56:04.000000000 +0100
@@ -91,6 +91,8 @@
#ifdef MITSHM
extern int XShmQueryExtension (Display * dpy);
+extern Bool XShmQueryVersion (Display* dpy, int * major, int * minor,
+ Bool * sharedpixmaps);
static int haderror;
static int (*origerrorhandler) (Display *, XErrorEvent *);
static int bpp;
@@ -107,6 +109,15 @@
return (0);
}
+static int
+badmatcherrorhandler (Display * d, XErrorEvent * e)
+{
+ haderror++;
+ if (e->error_code != BadMatch)
+ (*origerrorhandler) (d, e);
+ return (0);
+}
+
#define Width MAPWIDTH
#define Height (MAPHEIGHT+20)
XShmSegmentInfo shminfo;
@@ -186,16 +197,27 @@
fflush (stdout);
testpixmap = XCreatePixmap (dp, wi, MAPWIDTH, MAPHEIGHT + 20, DefaultDepth (dp, screen));
XSync (dp, 0);
+ haderror = False;
+ origerrorhandler = XSetErrorHandler (badmatcherrorhandler);
for (i = 0; i < 10 && wait > 0; i++)
{
- XPutImage (dp, testpixmap, gc, pixmap->ximage, 0, 0, 0, 0, MAPWIDTH, MAPHEIGHT + 20);
+ if (!XPutImage (dp, testpixmap, gc, pixmap->ximage, 0, 0, 0, 0,
+ MAPWIDTH, MAPHEIGHT + 20))
+ break;
XSync (dp, 0);
gettimeofday (&VnewClk, NULL);
if (VnewClk.tv_usec < VendSleep)
VendSleep -= 1000000;
wait = (VfTime - VnewClk.tv_usec + VendSleep);
}
+ XSync (dp, False);
+ XSetErrorHandler (origerrorhandler);
XFreePixmap (dp, testpixmap);
+ if (haderror)
+ {
+ printf (" XPutImage failed (remote server?)\n");
+ return 0;
+ }
if (i == 10)
{
printf ("OK\n");
@@ -258,6 +280,7 @@
pixmap->ximage->data = (char *) shared_mem;
/* Now try to attach it to the X Server */
+ XSync (dp, False);
haderror = False;
origerrorhandler = XSetErrorHandler (shmerrorhandler);
if (!XShmAttach (dp, &shminfo))
@@ -416,22 +439,25 @@
#ifdef MITSHM
/* Make sure all is destroyed if killed off */
- /* Make sure we can do PsuedoColor colormap stuff */
+ /* Make sure we can do PseudoColor colormap stuff */
if (!shm)
{
printf ("Shm support disabled\n");
}
else
- /* Check to see if the extensions are supported */
- if (!XShmQueryExtension (dp))
{
- fprintf (stderr, "X server doesn't support MITSHM extension.\n");
- shm = 0;
+ /* Check to see if the extensions are supported */
+ int major, minor;
+ Bool pixmaps;
+ if (XShmQueryVersion (dp, &major, &minor, &pixmaps) != 0
+ && (major > 1 || (major == 1 && minor >= 1)))
+ printf ("Shm mode seems to be possible\n");
+ else
+ {
+ fprintf (stderr, "X server doesn't support MITSHM extension.\n");
+ shm = 0;
+ }
}
- if (shm)
- printf ("Shm mode seems to be possible\n");
-
-
#endif
wi = physicalscreen.pixmap = XCreateSimpleWindow (dp, RootWindow (dp, screen), 50, 50, MAPWIDTH, MAPHEIGHT + 20,
0, 0, 0);
|