2003/06/18 07:49:51
[org.ibex.core.git] / src / org / xwt / plat / X11.cc
index 9fd2ac3..73d1541 100644 (file)
@@ -1,8 +1,8 @@
 // Copyright 2002 Adam Megacz, see the COPYING file for licensing [LGPL]
 // see below for copyright information on the second portion of this file
 
-#include <sys/ipc.h>
-#include <sys/shm.h>
+#include "POSIX.cc"
+
 #include <X11/Xlib.h>
 #include <X11/extensions/XShm.h>
 #include <X11/keysymdef.h>
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
 #include <X11/Xmu/StdCmap.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <gcj/cni.h>
-#include <signal.h>
 
 #include <java/lang/String.h>
 #include <org/xwt/Surface.h>
@@ -41,7 +35,7 @@ static Colormap s_colormap;
 static XStandardColormap* colormap_info;
 static XShmSegmentInfo shm_info;
 static Window selectionWindow;
-static int shm_supported;
+static int shm_supported = 0;
 static int shm_pixmaps_supported;
 static int screen_num;
 static int colorDepth = 0;
@@ -706,12 +700,19 @@ void org::xwt::plat::X11::natInit() {
     if (!XInitThreads())
         org::xwt::Platform::criticalAbort(JvNewStringLatin1("Your X11 libraries do not support multithreaded programs"));
 
-    display = XOpenDisplay(NULL);
+    char* DISPLAY = getenv("DISPLAY");
+    if (DISPLAY == NULL || strlen(DISPLAY) == 0) DISPLAY = ":0.0";
+    display = XOpenDisplay(DISPLAY);
+
+    if (display == 0)
+        org::xwt::Platform::criticalAbort(JvNewStringLatin1("Unable to connect to X11 display server"));
+
     screen_num = XDefaultScreen(display);
     colorDepth = (jint)(DefaultDepth(((Display*)display), 0));
     shm_info.shmaddr = NULL;
 
-    shm_supported = (XShmQueryExtension(display) == True);
+    // FIXME: SHM doesn't work on Darwin
+    //shm_supported = (XShmQueryExtension(display) == True);
     if (shm_supported) {
         X11ErrorHandler* oldHandler = XSetErrorHandler(errorHandler);
         XShmSegmentInfo sinfo;