2002/06/23 21:36:31
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 06:48:25 +0000 (06:48 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 06:48:25 +0000 (06:48 +0000)
darcs-hash:20040130064825-2ba56-f128d7981549fae04e59700fd517c7dc479310af.gz

CHANGES
src/org/xwt/plat/POSIX.cc

diff --git a/CHANGES b/CHANGES
index b4b926d..7c81e01 100644 (file)
--- a/CHANGES
+++ b/CHANGES
 23-Jun megacz Java12.java: removed wierd BufferedImage hackaround;
               jdk1.4 doesn't need it and it was causing wierd rendering glitches
 
+23-Jun megacz POSIX.cc: hackaround for wierd XFreeColormap() failure
+
index c07ec1c..1f6f4ea 100644 (file)
@@ -37,7 +37,7 @@
 
 // static (per-xserver) data
 static Visual* visual;
-static Colormap colormap;
+static Colormap s_colormap;
 static XStandardColormap* colormap_info;
 static XShmSegmentInfo shm_info;
 static Window selectionWindow;
@@ -403,7 +403,7 @@ void org::xwt::plat::POSIX$X11Surface::natInit() {
     XSetWindowAttributes xswa;
     window = (gnu::gcj::RawData*)malloc(sizeof(Window));
     xswa.bit_gravity = NorthWestGravity;
-    xswa.colormap = colormap;
+    xswa.colormap = s_colormap;
     xswa.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask |
         KeyPressMask | KeyReleaseMask | ButtonPressMask |
         ButtonReleaseMask | EnterWindowMask | LeaveWindowMask |
@@ -708,7 +708,6 @@ typedef int (X11ErrorHandler)(Display*, XErrorEvent*);
 int errorHandler(Display* d, XErrorEvent* e) {
     // this error handler is only installed during the initial
     // test to see if shm is present
-    java::lang::System::out->println(JvNewStringLatin1("here"));
     shm_supported = 0;
 }
 
@@ -768,13 +767,16 @@ void org::xwt::plat::POSIX::natInit() {
     selectionWindow = XCreateWindow(display, RootWindow(display, screen_num), 0, 0, 1, 1, 0, colorDepth, InputOutput, CopyFromParent, 0, NULL);
     visual = DefaultVisual(display, screen_num);
     char buf[255];
-    sprintf(buf, "X11 SHM:    %s", shm_supported ? "enabled" : "disabled");
+    sprintf(buf, "X11 DISPLAY: %s", JvNewStringLatin1(XDisplayString(display)));
     org::xwt::util::Log::log(this->getClass(), JvNewStringLatin1(buf));
-    sprintf(buf, "X11 Visual: %x %x %x bits: %i visualid: %i depth: %i",
+    sprintf(buf, "X11 SHM:     %s", shm_supported ? "enabled" : "disabled");
+    org::xwt::util::Log::log(this->getClass(), JvNewStringLatin1(buf));
+    sprintf(buf, "X11 Visual:  %x %x %x bits: %i visualid: %i depth: %i",
             visual->red_mask, visual->green_mask, visual->blue_mask, visual->bits_per_rgb, visual->visualid, colorDepth);
     org::xwt::util::Log::log(this->getClass(), JvNewStringLatin1(buf));
 
-    if(XmuLookupStandardColormap(display, screen_num, visual->visualid, colorDepth, XA_RGB_BEST_MAP, False, True) == 0)
+    // FIXME: don't know why (True, False) is the best solution...
+    if(XmuLookupStandardColormap(display, screen_num, visual->visualid, colorDepth, XA_RGB_BEST_MAP, True, False) == 0)
         org::xwt::Platform::criticalAbort(JvNewStringLatin1("ERROR: XmuLookupStandardColormap failed"));
     
     XStandardColormap* best_map_info = NULL;
@@ -785,7 +787,7 @@ void org::xwt::plat::POSIX::natInit() {
         org::xwt::Platform::criticalAbort(JvNewStringLatin1("ERROR: XmuLookupStandardColomap succeded, but no colormap was found on the root window"));
     if (best_map_info->red_max == 0)
         org::xwt::Platform::criticalAbort(JvNewStringLatin1("ERROR: standard colormap exists, but was improperly allocated"));
-    colormap = best_map_info->colormap;
+    s_colormap = best_map_info->colormap;
     colormap_info = best_map_info;
 
     sprintf(buf, "            red_max / red_mult: %x %x", colormap_info->red_max, colormap_info->red_mult);
@@ -835,7 +837,8 @@ jint org::xwt::plat::POSIX::_stringWidth(::java::lang::String* font, ::java::lan
 //                                                                          //
 // Everything below this point was taken, cut-and-paste, from the           //
 // source for libXmu. It implements the official 'standard colormap         //
-// creation algorithm.                                                      //
+// creation algorithm.  I made some small changes to                        //
+// XmuDeleteStandardColormap                                                //
 //                                                                          //
 //////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////
@@ -981,11 +984,11 @@ XmuLookupStandardColormap(Display *dpy, int screen, VisualID visualid,
     /* If retaining resources, open a new connection to the same server */
 
     if (retain) {
-       odpy = dpy;
-       if ((dpy = XOpenDisplay(XDisplayString(odpy))) == NULL) {
-           XFree((char *) vinfo);
-           return 0;
-       }
+        odpy = dpy;
+        if ((dpy = XOpenDisplay(XDisplayString(odpy))) == NULL) {
+            XFree((char *) vinfo);
+            return 0;
+        }
     }
 
     /* Create the standard colormap */
@@ -1006,9 +1009,8 @@ XmuLookupStandardColormap(Display *dpy, int screen, VisualID visualid,
             * when this connection closes.
             */
            if (colormap->killid == ReleaseByFreeingColormap)
-               XFreeColormap(dpy, colormap->colormap);
-       }
-       else if (retain) {
+            XFreeColormap(dpy, colormap->colormap);
+       } else if (retain) {
                XSetCloseDownMode(dpy, RetainPermanent);
        }
        XUngrabServer(dpy);
@@ -2319,6 +2321,8 @@ in this Software without prior written authorization from The Open Group.
 #include <X11/Xutil.h>
 #include <X11/Xmu/StdCmap.h>
 
+int ignoreErrorHandler(Display* d, XErrorEvent* e) { }
+
 /* To remove any standard colormap property, use XmuDeleteStandardColormap().
  * XmuDeleteStandardColormap() will remove the specified property from the
  * specified screen, releasing any resources used by the colormap(s) of the
@@ -2336,19 +2340,28 @@ XmuDeleteStandardColormap(Display *dpy, int screen, Atom property)
     int                        count = 0;
 
     if (XGetRGBColormaps(dpy, RootWindow(dpy, screen), &stdcmaps, &count,
-                        property))
-    {
-       for (s=stdcmaps; count > 0; count--, s++) {
-           if ((s->killid == ReleaseByFreeingColormap) &&
-               (s->colormap != None) &&
-               (s->colormap != DefaultColormap(dpy, screen)))
-               XFreeColormap(dpy, s->colormap);
-           else if (s->killid != None)
-               XKillClient(dpy, s->killid);
-       }
-       XDeleteProperty(dpy, RootWindow(dpy, screen), property);
-       XFree((char *) stdcmaps);
-       XSync(dpy, False);
-    }
+                         property))
+        {
+            for (s=stdcmaps; count > 0; count--, s++) {
+                if ((s->killid == ReleaseByFreeingColormap) &&
+                    (s->colormap != None) &&
+                    (s->colormap != DefaultColormap(dpy, screen))) {
+
+                    // UGLY HACK written in by Adam Megacz -- sometimes s->colormap isn't valid, so we do some shuffling
+                    X11ErrorHandler* oldHandler = XSetErrorHandler(ignoreErrorHandler);
+                    XSync(dpy, False);
+                    XFreeColormap(dpy, s->colormap);
+                    XSync(dpy, False);
+                    XSetErrorHandler(oldHandler);
+                    XSync(dpy, False);
+
+                } else if (s->killid != None) {
+                    XKillClient(dpy, s->killid);
+                }
+            }
+            XDeleteProperty(dpy, RootWindow(dpy, screen), property);
+            XFree((char *) stdcmaps);
+            XSync(dpy, False);
+        }
 }