// 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;
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 |
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;
}
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;
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);
// //
// 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 //
// //
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/* 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 */
* 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);
#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
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);
+ }
}