aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/Display.java69
-rw-r--r--src/classes/com/sun/javafx/newt/KeyEvent.java12
-rw-r--r--src/classes/com/sun/javafx/newt/MouseEvent.java16
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/Screen.java75
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/Window.java56
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/windows/WindowsWindow.java15
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/x11/X11Window.java33
-rwxr-xr-xsrc/classes/com/sun/opengl/impl/egl/EGLDrawable.java38
-rwxr-xr-xsrc/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java34
-rwxr-xr-xsrc/native/jogl/X11Window.c144
10 files changed, 364 insertions, 128 deletions
diff --git a/src/classes/com/sun/javafx/newt/Display.java b/src/classes/com/sun/javafx/newt/Display.java
new file mode 100755
index 000000000..7be9a1b12
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/Display.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt;
+
+public class Display {
+
+ public Display() {
+ this(null);
+ }
+
+ public Display(String name) {
+ this.name=name;
+ this.handle=-1;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public long getHandle() {
+ return handle;
+ }
+
+ /**
+ * native handle
+ *
+ * write once ..
+ */
+ public void setHandle(long handle) {
+ if(this.handle<0) {
+ this.handle=handle;
+ }
+ }
+
+ protected String name;
+ protected long handle;
+}
+
diff --git a/src/classes/com/sun/javafx/newt/KeyEvent.java b/src/classes/com/sun/javafx/newt/KeyEvent.java
index 96df883df..47d7d1f7d 100644
--- a/src/classes/com/sun/javafx/newt/KeyEvent.java
+++ b/src/classes/com/sun/javafx/newt/KeyEvent.java
@@ -56,7 +56,17 @@ public class KeyEvent extends InputEvent
}
public String toString() {
- return "KeyEvent[code "+keyCode+", char "+keyChar+", "+super.toString();
+ return "KeyEvent["+getEventTypeString(eventType)+
+ ", code "+keyCode+", char "+keyChar+", "+super.toString();
+ }
+
+ public static String getEventTypeString(int type) {
+ switch(type) {
+ case EVENT_KEY_PRESSED: return "EVENT_KEY_PRESSED";
+ case EVENT_KEY_RELEASED: return "EVENT_KEY_RELEASED";
+ case EVENT_KEY_TYPED: return "EVENT_KEY_TYPED";
+ default: return "unknown";
+ }
}
public boolean isActionKey() {
diff --git a/src/classes/com/sun/javafx/newt/MouseEvent.java b/src/classes/com/sun/javafx/newt/MouseEvent.java
index 99026bd7b..19b5f2b93 100644
--- a/src/classes/com/sun/javafx/newt/MouseEvent.java
+++ b/src/classes/com/sun/javafx/newt/MouseEvent.java
@@ -69,7 +69,21 @@ public class MouseEvent extends InputEvent
}
public String toString() {
- return "MouseEvent["+x+"/"+y+", button "+button+", count "+clickCount+", "+super.toString();
+ return "MouseEvent["+getEventTypeString(eventType)+
+ ", "+x+"/"+y+", button "+button+", count "+clickCount+", "+super.toString();
+ }
+
+ public static String getEventTypeString(int type) {
+ switch(type) {
+ case EVENT_MOUSE_CLICKED: return "EVENT_MOUSE_CLICKED";
+ case EVENT_MOUSE_ENTERED: return "EVENT_MOUSE_ENTERED";
+ case EVENT_MOUSE_EXITED: return "EVENT_MOUSE_EXITED";
+ case EVENT_MOUSE_PRESSED: return "EVENT_MOUSE_PRESSED";
+ case EVENT_MOUSE_RELEASED: return "EVENT_MOUSE_RELEASED";
+ case EVENT_MOUSE_MOVED: return "EVENT_MOUSE_MOVED";
+ case EVENT_MOUSE_DRAGGED: return "EVENT_MOUSE_DRAGGED";
+ default: return "unknown";
+ }
}
private int eventType, x, y, clickCount, button;
diff --git a/src/classes/com/sun/javafx/newt/Screen.java b/src/classes/com/sun/javafx/newt/Screen.java
new file mode 100755
index 000000000..b698a0248
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/Screen.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt;
+
+public class Screen {
+
+ public Screen(Display display) {
+ this(display, 0);
+ }
+
+ public Screen(Display display, int idx) {
+ this.display=display;
+ this.index=idx;
+ this.handle=-1;
+ }
+
+ public Display getDisplay() {
+ return display;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public long getHandle() {
+ return handle;
+ }
+
+ /**
+ * native handle
+ *
+ * write once ..
+ */
+ public void setHandle(long handle) {
+ if(this.handle<0) {
+ this.handle=handle;
+ }
+ }
+
+ protected Display display;
+ protected int index;
+ protected long handle;
+}
+
diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java
index 2bfcf1265..27610cdf2 100755
--- a/src/classes/com/sun/javafx/newt/Window.java
+++ b/src/classes/com/sun/javafx/newt/Window.java
@@ -37,6 +37,9 @@ import java.util.ArrayList;
import java.util.Iterator;
public abstract class Window {
+ public static final boolean DEBUG_MOUSE_EVENT = false;
+ public static final boolean DEBUG_KEY_EVENT = false;
+
/** OpenKODE window type */
public static final String KD = "KD";
@@ -50,7 +53,7 @@ public abstract class Window {
public static final String MACOSX = "MacOSX";
/** Creates a Window of the default type for the current operating system. */
- public static Window create(long visualID) {
+ public static Window create(Screen screen, long visualID) {
String osName = System.getProperty("os.name");
String osNameLowerCase = osName.toLowerCase();
String windowType;
@@ -62,7 +65,7 @@ public abstract class Window {
windowType = X11;
}
Window window = create(windowType);
- window.initNative(visualID);
+ window.initNative(screen, visualID);
return window;
}
@@ -87,7 +90,19 @@ public abstract class Window {
}
}
- protected abstract void initNative(long visualID);
+
+ /**
+ * [ display, screen, window ]
+ */
+ public long[] getHandles() {
+ long[] handles = new long[3];
+ handles[0] = getScreen().getDisplay().getHandle();
+ handles[1] = getScreen().getHandle();
+ handles[2] = getWindowHandle();
+ return handles;
+ }
+
+ protected abstract void initNative(Screen screen, long visualID);
public abstract void setVisible(boolean visible);
public abstract void setSize(int width, int height);
@@ -101,9 +116,18 @@ public abstract class Window {
public abstract boolean isFullscreen();
public abstract int getDisplayWidth();
public abstract int getDisplayHeight();
+
+ public abstract Screen getScreen();
public abstract long getWindowHandle();
+
public abstract void pumpMessages();
+ public String toString() {
+ return "Window[handle "+getWindowHandle()+
+ ", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+
+ ", visible "+isVisible()+"]";
+ }
+
//
// MouseListener Support
//
@@ -132,6 +156,10 @@ public abstract class Window {
public static final int ClickTimeout = 200;
private void sendMouseEvent(int eventType, int modifiers, int x, int y, int button) {
+ if(DEBUG_MOUSE_EVENT) {
+ System.out.println("sendMouseEvent: "+MouseEvent.getEventTypeString(eventType)+
+ ", mod "+modifiers+", pos "+x+"/"+y+", button "+button);
+ }
long when = System.currentTimeMillis();
MouseEvent eClicked = null;
MouseEvent e = null;
@@ -151,18 +179,26 @@ public abstract class Window {
if(when-lastMousePressed<ClickTimeout) {
eClicked = new MouseEvent(true, MouseEvent.EVENT_MOUSE_CLICKED, this, when,
modifiers, x, y, lastMouseClickCount, button);
+ } else {
+ lastMouseClickCount=0;
+ lastMousePressed=0;
}
- lastMouseClickCount=0;
- lastMousePressed=0;
} else if(MouseEvent.EVENT_MOUSE_MOVED==eventType &&
1==lastMouseClickCount) {
- e = new MouseEvent(true, eventType, this, when,
+ e = new MouseEvent(true, MouseEvent.EVENT_MOUSE_DRAGGED, this, when,
modifiers, x, y, 1, button);
} else {
e = new MouseEvent(true, eventType, this, when,
modifiers, x, y, 0, button);
}
+ if(DEBUG_MOUSE_EVENT) {
+ System.out.println("sendMouseEvent: event: "+e);
+ if(null!=eClicked) {
+ System.out.println("sendMouseEvent: event Clicked: "+eClicked);
+ }
+ }
+
for(Iterator i = mouseListener.iterator(); i.hasNext(); ) {
switch(eventType) {
case MouseEvent.EVENT_MOUSE_ENTERED:
@@ -175,9 +211,10 @@ public abstract class Window {
((MouseListener)i.next()).mousePressed(e);
break;
case MouseEvent.EVENT_MOUSE_RELEASED:
- ((MouseListener)i.next()).mouseReleased(e);
+ MouseListener ml = (MouseListener)i.next();
+ ml.mouseReleased(e);
if(null!=eClicked) {
- ((MouseListener)i.next()).mouseClicked(eClicked);
+ ml.mouseClicked(eClicked);
}
break;
case MouseEvent.EVENT_MOUSE_MOVED:
@@ -217,6 +254,9 @@ public abstract class Window {
private void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
KeyEvent e = new KeyEvent(true, eventType, this, System.currentTimeMillis(),
modifiers, keyCode, keyChar);
+ if(DEBUG_KEY_EVENT) {
+ System.out.println("sendKeyEvent: "+e);
+ }
for(Iterator i = keyListener.iterator(); i.hasNext(); ) {
switch(eventType) {
case KeyEvent.EVENT_KEY_PRESSED:
diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
index faa26dcb7..e170f9b56 100755
--- a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
+++ b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
@@ -37,8 +37,9 @@ import com.sun.javafx.newt.*;
import com.sun.opengl.impl.*;
public class WindowsWindow extends Window {
- private boolean fullscreen, visible;
+ private Screen screen;
private long visualID;
+ private boolean fullscreen, visible;
private long window;
// Default width and height -- will likely be re-set immediately by user
private int width = 100;
@@ -55,10 +56,12 @@ public class WindowsWindow extends Window {
}
}
- protected WindowsWindow() {
+ public WindowsWindow() {
}
- protected void initNative(long visualID) {
+ public void initNative(Screen screen, long visualID) {
+ this.screen = screen;
+ this.visualID = visualID;
long wndClass = getWindowClass();
fullscreen=false;
visible=false;
@@ -66,6 +69,12 @@ public class WindowsWindow extends Window {
if (window == 0) {
throw new RuntimeException("Error creating window");
}
+ screen.setHandle(0); // dummy
+ screen.getDisplay().setHandle(0); // dummy
+ }
+
+ public Screen getScreen() {
+ return screen;
}
public void setVisible(boolean visible) {
diff --git a/src/classes/com/sun/javafx/newt/x11/X11Window.java b/src/classes/com/sun/javafx/newt/x11/X11Window.java
index 828f08eff..80021dca4 100755
--- a/src/classes/com/sun/javafx/newt/x11/X11Window.java
+++ b/src/classes/com/sun/javafx/newt/x11/X11Window.java
@@ -37,8 +37,10 @@ import com.sun.javafx.newt.*;
import com.sun.opengl.impl.*;
public class X11Window extends Window {
+ private Screen screen;
private long visualID;
- private long dpy, screen, window;
+ private long dpy, scrn, window;
+ private int scrn_idx;
private static final String WINDOW_CLASS_NAME = "NewtWindow";
// Default width and height -- will likely be re-set immediately by user
private int width = 100;
@@ -57,16 +59,24 @@ public class X11Window extends Window {
}
}
- protected X11Window() {
+ public X11Window() {
}
- protected void initNative(long visualID) {
+ public void initNative(Screen screen, long visualID) {
+ this.screen = screen;
+ this.visualID = visualID;
fullscreen=false;
visible=false;
long w = CreateWindow(visualID, x, y, width, height);
if (w == 0 || w!=window) {
throw new RuntimeException("Error creating window: "+w);
}
+ screen.setHandle(scrn);
+ screen.getDisplay().setHandle(dpy);
+ }
+
+ public Screen getScreen() {
+ return screen;
}
public void setVisible(boolean visible) {
@@ -110,8 +120,8 @@ public class X11Window extends Window {
this.fullscreen=fullscreen;
if(this.fullscreen) {
x = 0; y = 0;
- w = getDisplayWidth0(dpy, screen);
- h = getDisplayHeight0(dpy, screen);
+ w = getDisplayWidth0(dpy, scrn_idx)/2;
+ h = getDisplayHeight0(dpy, scrn_idx)/2;
} else {
x = nfs_x;
y = nfs_y;
@@ -137,11 +147,11 @@ public class X11Window extends Window {
}
public int getDisplayWidth() {
- return getDisplayWidth0(dpy, screen);
+ return getDisplayWidth0(dpy, scrn_idx);
}
public int getDisplayHeight() {
- return getDisplayHeight0(dpy, screen);
+ return getDisplayHeight0(dpy, scrn_idx);
}
//----------------------------------------------------------------------
@@ -154,8 +164,8 @@ public class X11Window extends Window {
private native void DispatchMessages(long display, long window);
private native void setSize0(long display, long window, int width, int height);
private native void setPosition0(long display, long window, int x, int y);
- private native int getDisplayWidth0(long display, long screen);
- private native int getDisplayHeight0(long display, long screen);
+ private native int getDisplayWidth0(long display, int scrn_idx);
+ private native int getDisplayHeight0(long display, int scrn_idx);
private void sizeChanged(int newWidth, int newHeight) {
width = newWidth;
@@ -175,9 +185,10 @@ public class X11Window extends Window {
}
}
- private void windowCreated(long dpy, long scrn, long window) {
+ private void windowCreated(long dpy, int scrn_idx, long scrn, long window) {
this.dpy = dpy;
- this.screen = scrn;
+ this.scrn_idx = scrn_idx;
+ this.scrn = scrn;
this.window = window;
}
diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java
index abdbd2b7f..22b39e291 100755
--- a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java
+++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java
@@ -38,7 +38,9 @@ package com.sun.opengl.impl.egl;
import javax.media.opengl.*;
public class EGLDrawable implements GLDrawable {
- private long nativeWindow;
+ private long windowHandle;
+ private long screenHandle;
+ private long displayHandle;
private long display;
private GLCapabilities capabilities;
private GLCapabilitiesChooser chooser;
@@ -46,17 +48,27 @@ public class EGLDrawable implements GLDrawable {
private long surface;
private int[] tmp = new int[1];
- public EGLDrawable(long nativeWindow,
+ public EGLDrawable(long displayHandle,
+ long screenHandle,
+ long windowHandle,
GLCapabilities capabilities,
GLCapabilitiesChooser chooser) throws GLException {
- this.nativeWindow = nativeWindow;
+ this.displayHandle = displayHandle;
+ this.screenHandle = screenHandle;
+ this.windowHandle = windowHandle;
this.capabilities = capabilities;
this.chooser = chooser;
// Set things up
EGLDrawableFactory factory = (EGLDrawableFactory) GLDrawableFactory.getFactory();
- // FIXME: need to ultimately fetch this from the native window, at least on X11 platforms
- display = factory.getDisplay();
+
+ display = EGL.eglGetDisplay((displayHandle>0)?displayHandle:EGL.EGL_DEFAULT_DISPLAY);
+ if (display == EGL.EGL_NO_DISPLAY) {
+ throw new GLException("eglGetDisplay failed");
+ }
+ if (!EGL.eglInitialize(display, null, null)) {
+ throw new GLException("eglInitialize failed");
+ }
int[] attrs = factory.glCapabilities2AttribList(capabilities);
_EGLConfig[] configs = new _EGLConfig[1];
int[] numConfigs = new int[1];
@@ -76,6 +88,10 @@ public class EGLDrawable implements GLDrawable {
return display;
}
+ public void shutdown() {
+ EGL.eglTerminate(display);
+ }
+
public _EGLConfig getConfig() {
return config;
}
@@ -91,7 +107,7 @@ public class EGLDrawable implements GLDrawable {
public void setRealized(boolean realized) {
if (realized) {
// Create the window surface
- surface = EGL.eglCreateWindowSurface(display, config, nativeWindow, null);
+ surface = EGL.eglCreateWindowSurface(display, config, windowHandle, null);
if (surface == EGL.EGL_NO_SURFACE) {
throw new GLException("Creation of window surface (eglCreateWindowSurface) failed");
}
@@ -134,4 +150,14 @@ public class EGLDrawable implements GLDrawable {
// FIXME
return null;
}
+
+ public String toString() {
+ return "EGLDrawable[ displayHandle " + displayHandle +
+ ", screenHandle "+ screenHandle +
+ ", windowHandle "+ windowHandle +
+ ", display " + display +
+ ", config " + config +
+ ", surface " + surface +
+ "]";
+ }
}
diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java
index b66d1d33e..516f6d5a9 100755
--- a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java
+++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java
@@ -48,28 +48,11 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
// We need more than one of these on certain devices (the NVidia APX 2500 in particular)
private List/*<NativeLibrary>*/ glesLibraries;
- // FIXME: this state should probably not be here
- private long display;
- private _EGLConfig config;
-
public EGLDrawableFactory(String profile) {
super(profile);
loadGLESLibrary();
EGL.resetProcAddressTable(this);
-
- // FIXME: this initialization sequence needs to be refactored
- // at least for X11 platforms to allow a little window
- // system-specific code to run (to open the display, in
- // particular)
-
- display = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY);
- if (display == EGL.EGL_NO_DISPLAY) {
- throw new GLException("eglGetDisplay failed");
- }
- if (!EGL.eglInitialize(display, null, null)) {
- throw new GLException("eglInitialize failed");
- }
}
private void loadGLESLibrary() {
@@ -113,10 +96,6 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
glesLibraries = libs;
}
- public void shutdown() {
- EGL.eglTerminate(display);
- }
-
public AbstractGraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities,
GLCapabilitiesChooser chooser,
AbstractGraphicsDevice device) {
@@ -126,7 +105,14 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
public GLDrawable getGLDrawable(Object target,
GLCapabilities capabilities,
GLCapabilitiesChooser chooser) {
- return new EGLDrawable(((Long) target).longValue(),
+ if( !(target instanceof long[]) ) {
+ throw new GLException("target is not instanceof long[]");
+ }
+ long[] targetHandles = (long[])target;
+ if(targetHandles.length!=3) {
+ throw new GLException("target handle array != 3 [display, screen, window]");
+ }
+ return new EGLDrawable(targetHandles[0], targetHandles[1], targetHandles[2],
capabilities,
chooser);
}
@@ -189,10 +175,6 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
return false;
}
- public long getDisplay() {
- return display;
- }
-
public int[] glCapabilities2AttribList(GLCapabilities caps) {
int[] attrs = new int[] {
EGL.EGL_DEPTH_SIZE, caps.getDepthBits(),
diff --git a/src/native/jogl/X11Window.c b/src/native/jogl/X11Window.c
index 1c4200347..e37525be7 100755
--- a/src/native/jogl/X11Window.c
+++ b/src/native/jogl/X11Window.c
@@ -55,54 +55,7 @@ static jmethodID sendKeyEventID = NULL;
// This is set by DispatchMessages, below, and cleared when it exits
static JNIEnv* env = NULL;
-#if 0
-static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
- WPARAM wParam, LPARAM lParam)
-{
- RECT rc;
- int useDefWindowProc = 0;
- jobject window = NULL;
-
- window = (jobject) GetWindowLongPtr(wnd, GWLP_USERDATA);
- if (window == NULL || env == NULL) {
- // Shouldn't happen
- return DefWindowProc(wnd, message, wParam, lParam);
- }
-
- switch (message) {
- case WM_CLOSE:
- (*env)->CallVoidMethod(env, window, windowClosedID);
- DestroyWindow(wnd);
- break;
-
- case WM_DESTROY:
- (*env)->CallVoidMethod(env, window, windowDestroyedID);
- break;
-
- case WM_KEYDOWN:
- (*env)->CallVoidMethod(env, window, keyDownID, (jlong) wParam);
- useDefWindowProc = 1;
- break;
-
- case WM_KEYUP:
- (*env)->CallVoidMethod(env, window, keyUpID, (jlong) wParam);
- useDefWindowProc = 1;
- break;
-
- case WM_SIZE:
- GetClientRect(wnd, &rc);
- (*env)->CallVoidMethod(env, window, sizeChangedID, (jint) rc.right, (jint) rc.bottom);
- break;
-
- default:
- useDefWindowProc = 1;
- }
-
- if (useDefWindowProc)
- return DefWindowProc(wnd, message, wParam, lParam);
- return 0;
-}
-#endif
+// #define VERBOSE_ON 1
/*
* Class: com_sun_javafx_newt_x11_X11Window
@@ -116,7 +69,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_x11_X11Window_initIDs
positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V");
windowClosedID = (*env)->GetMethodID(env, clazz, "windowClosed", "()V");
windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
- windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(JJJ)V");
+ windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(JIJJ)V");
sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIII)V");
sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
if (sizeChangedID == NULL ||
@@ -142,6 +95,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Window_CreateWindow
{
Display * dpy;
Screen * scrn;
+ int scrn_idx;
Window windowParent = 0;
Window window = 0;
@@ -158,17 +112,44 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Window_CreateWindow
return 0;
}
- memset(&visualTemplate, 0, sizeof(XVisualInfo));
- visualTemplate.visualid = (VisualID)visualID;
-
- pVisualQuery = XGetVisualInfo(dpy, VisualIDMask, &visualTemplate,&n);
+ if(visualID>0) {
+ // try given VisualID
+ memset(&visualTemplate, 0, sizeof(XVisualInfo));
+ visualTemplate.visualid = (VisualID)visualID;
+ pVisualQuery = XGetVisualInfo(dpy, VisualIDMask, &visualTemplate,&n);
+ }
+ if (pVisualQuery==NULL)
+ {
+ // try default VisualID
+ scrn = DefaultScreenOfDisplay(dpy);
+ visualID = XVisualIDFromVisual(DefaultVisualOfScreen(scrn));
+ memset(&visualTemplate, 0, sizeof(XVisualInfo));
+ visualTemplate.visualid = (VisualID)visualID;
+ pVisualQuery = XGetVisualInfo(dpy, VisualIDMask, &visualTemplate,&n);
+ }
if (pVisualQuery==NULL)
- {
- fprintf(stderr, "could not query XVisualInfo ..\n");
+ {
+ fprintf(stderr, "could not query any XVisualInfo, bail out!\n");
return 0;
+ }
+#ifdef VERBOSE_ON
+ else {
+ fprintf(stderr, "choosen visual: id: 0x%X, screen %d, depth: %d, class %d, cmap sz: %d, bpp: %d, rgb 0x%X 0x%X 0x%X\n",
+ (int)pVisualQuery->visualid,
+ pVisualQuery->screen,
+ pVisualQuery->depth,
+ pVisualQuery->class,
+ pVisualQuery->colormap_size,
+ pVisualQuery->bits_per_rgb,
+ (int)pVisualQuery->red_mask,
+ (int)pVisualQuery->green_mask,
+ (int)pVisualQuery->blue_mask
+ );
}
+#endif
- scrn = ScreenOfDisplay(dpy, pVisualQuery->screen);
+ scrn_idx = pVisualQuery->screen;
+ scrn = ScreenOfDisplay(dpy, scrn_idx);
windowParent = XRootWindowOfScreen(scrn);
@@ -195,8 +176,16 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Window_CreateWindow
&xswa);
XFree(pVisualQuery);
- (*env)->CallVoidMethod(env, obj, windowCreatedID, (jlong) (intptr_t) dpy, (jlong) (intptr_t) scrn, (jlong) window);
+ //XMapWindow(dpy, window);
+ XClearWindow(dpy, window);
+ XMapRaised(dpy, window);
+ (*env)->CallVoidMethod(env, obj, windowCreatedID, (jlong) (intptr_t) dpy,
+ (jint) scrn_idx, (jlong) (intptr_t) scrn, (jlong) window);
+
+ XSelectInput(dpy, window, ExposureMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask|
+ KeyPressMask|KeyReleaseMask);
+ XSetInputFocus(dpy, window, RevertToNone, CurrentTime);
return (jlong) window;
}
@@ -211,10 +200,11 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setVisible0
Display * dpy = (Display *) (intptr_t) display;
Window w = (Window)window;
if(visible==JNI_TRUE) {
- XMapWindow(dpy, window);
+ XMapRaise(dpy, window);
- XSelectInput(dpy, window, ButtonPressMask|ButtonRelease|PointerMotionMask|
+ XSelectInput(dpy, window, ExposureMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask|
KeyPressMask|KeyReleaseMask);
+ XSetInputFocus(dpy, window, RevertToNone, CurrentTime);
} else {
XSelectInput(dpy, window, 0);
XUnmapWindow(dpy, window);
@@ -236,7 +226,9 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_DispatchMessages
while( XPending(dpy)>0 ) {
int eventType;
XEvent evt;
- int i;
+ KeySym keySym;
+ char keyChar;
+ char text[255];
XNextEvent(dpy, &evt);
@@ -257,14 +249,24 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_DispatchMessages
(jint) evt.xmotion.x, (jint) evt.xmotion.y, (jint) 0);
break;
case KeyPress:
- i = evt.xkey.keycode;
+ if(XLookupString(&evt.xkey,text,255,&keySym,0)==1) {
+ keyChar=text[0];
+ } else {
+ keyChar=0;
+ }
(*env)->CallVoidMethod(env, obj, sendKeyEventID, (jint) EVENT_KEY_PRESSED,
(jint) evt.xkey.state,
- (jint) i, (jchar) ( isascii(i)?i:0 ) );
- // evt.xkey
+ (jint) keySym, (jchar) keyChar);
break;
case KeyRelease:
- // evt.xkey
+ if(XLookupString(&evt.xkey,text,255,&keySym,0)==1) {
+ keyChar=text[0];
+ } else {
+ keyChar=0;
+ }
+ (*env)->CallVoidMethod(env, obj, sendKeyEventID, (jint) EVENT_KEY_RELEASED,
+ (jint) evt.xkey.state,
+ (jint) keySym, (jchar) keyChar);
break;
case FocusIn:
// evt.xfocus
@@ -307,27 +309,25 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setPosition0
/*
* Class: com_sun_javafx_newt_x11_X11Window
* Method: getDisplayWidth0
- * Signature: (JJ)I
+ * Signature: (JI)I
*/
JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_x11_X11Window_getDisplayWidth0
- (JNIEnv *env, jobject obj, jlong display, jlong screen)
+ (JNIEnv *env, jobject obj, jlong display, jint scrn_idx)
{
Display * dpy = (Display *) (intptr_t) display;
- Screen * scrn = (Screen *) (intptr_t) screen;
- return (jint) XDisplayWidth( dpy, scrn);
+ return (jint) XDisplayWidth( dpy, scrn_idx);
}
/*
* Class: com_sun_javafx_newt_x11_X11Window
* Method: getDisplayHeight0
- * Signature: (JJ)I
+ * Signature: (JI)I
*/
JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_x11_X11Window_getDisplayHeight0
- (JNIEnv *env, jobject obj, jlong display, jlong screen)
+ (JNIEnv *env, jobject obj, jlong display, jint scrn_idx)
{
Display * dpy = (Display *) (intptr_t) display;
- Screen * scrn = (Screen *) (intptr_t) screen;
- return (jint) XDisplayHeight( dpy, scrn);
+ return (jint) XDisplayHeight( dpy, scrn_idx);
}