2003/09/04 07:16:17
[org.ibex.core.git] / src / org / xwt / plat / X11.cc
index 684f3bb..876c9a8 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>
 #include <java/lang/System.h>
 #include <java/io/PrintStream.h>
 
-#include "POSIX.cc"
-
 // static (per-xserver) data
 static Visual* visual;
 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;
@@ -585,8 +577,8 @@ void org::xwt::plat::X11$X11Surface::dispatchEvent(gnu::gcj::RawData* ev) {
         int x_out, y_out;
         XConfigureEvent* xce = (XConfigureEvent*)(e);
         XTranslateCoordinates(display, (*((Window*)window)), RootWindow(display, screen_num), 0, 0, &x_out, &y_out, &child);
-        if (xce->width != width || xce->height != height) SizeChange(xce->width, xce->height);
-        if (x_out != root->abs(0) || y_out != root->abs(1)) PosChange(x_out, y_out);
+        if (xce->width != root->width || xce->height != root->height) SizeChange(xce->width, xce->height);
+        if (x_out != root->x || y_out != root->y) PosChange(x_out, y_out);
         
     }
 }
@@ -708,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;