|
From: <ka...@us...> - 2012-02-18 01:49:52
|
Revision: 3742
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3742&view=rev
Author: kappa1
Date: 2012-02-18 01:49:46 +0000 (Sat, 18 Feb 2012)
Log Message:
-----------
Implement the ability for the native Display window on Linux to get its x and y position. In preparation for adding the new Display.getX() & getY() API's.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxEvent.java
trunk/LWJGL/src/native/linux/opengl/org_lwjgl_opengl_Display.c
trunk/LWJGL/src/native/linux/opengles/org_lwjgl_opengl_Display.c
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2012-02-06 20:35:25 UTC (rev 3741)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2012-02-18 01:49:46 UTC (rev 3742)
@@ -144,6 +144,8 @@
private boolean resizable;
private boolean resized;
+ private int window_x;
+ private int window_y;
private int window_width;
private int window_height;
@@ -516,6 +518,8 @@
private static native long nGetInputFocus(long display) throws LWJGLException;
private static native void nSetInputFocus(long display, long window, long time);
private static native void nSetWindowSize(long display, long window, int width, int height, boolean resizable);
+ private static native int nGetX(long display, long window);
+ private static native int nGetY(long display, long window);
private static native int nGetWidth(long display, long window);
private static native int nGetHeight(long display, long window);
@@ -840,10 +844,17 @@
break;
case LinuxEvent.Expose:
dirty = true;
+ break;
+ case LinuxEvent.ConfigureNotify:
+ int x = nGetX(getDisplay(), getWindow());
+ int y = nGetY(getDisplay(), getWindow());
int width = nGetWidth(getDisplay(), getWindow());
int height = nGetHeight(getDisplay(), getWindow());
+ window_x = x;
+ window_y = y;
+
if (window_width != width || window_height != height) {
resized = true;
window_width = width;
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxEvent.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxEvent.java 2012-02-06 20:35:25 UTC (rev 3741)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxEvent.java 2012-02-18 01:49:46 UTC (rev 3742)
@@ -53,6 +53,7 @@
public static final int UnmapNotify = 18;
public static final int MapNotify = 19;
public static final int Expose = 12;
+ public static final int ConfigureNotify = 22;
public static final int ClientMessage = 33;
private final ByteBuffer event_buffer;
Modified: trunk/LWJGL/src/native/linux/opengl/org_lwjgl_opengl_Display.c
===================================================================
--- trunk/LWJGL/src/native/linux/opengl/org_lwjgl_opengl_Display.c 2012-02-06 20:35:25 UTC (rev 3741)
+++ trunk/LWJGL/src/native/linux/opengl/org_lwjgl_opengl_Display.c 2012-02-18 01:49:46 UTC (rev 3742)
@@ -283,6 +283,49 @@
return RootWindow(disp, screen);
}
+static Window getCurrentWindow(JNIEnv *env, jlong display_ptr, jlong window_ptr) {
+ Display *disp = (Display *)(intptr_t)display_ptr;
+
+ Window parent = (Window)window_ptr;
+ Window win, root;
+
+ Window *children;
+ unsigned int nchildren;
+
+ do {
+ win = parent;
+
+ if (XQueryTree(disp, win, &root, &parent, &children, &nchildren) == 0) {
+ throwException(env, "XQueryTree failed");
+ return 0;
+ }
+
+ if (children != NULL) XFree(children);
+ } while (parent != root);
+
+ return win;
+}
+
+JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetX(JNIEnv *env, jclass unused, jlong display_ptr, jlong window_ptr) {
+ Display *disp = (Display *)(intptr_t)display_ptr;
+ Window win = getCurrentWindow(env, display_ptr, window_ptr);
+
+ XWindowAttributes win_attribs;
+ XGetWindowAttributes(disp, win, &win_attribs);
+
+ return win_attribs.x;
+}
+
+JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetY(JNIEnv *env, jclass unused, jlong display_ptr, jlong window_ptr) {
+ Display *disp = (Display *)(intptr_t)display_ptr;
+ Window win = getCurrentWindow(env, display_ptr, window_ptr);
+
+ XWindowAttributes win_attribs;
+ XGetWindowAttributes(disp, win, &win_attribs);
+
+ return win_attribs.y;
+}
+
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetWidth(JNIEnv *env, jclass unused, jlong display_ptr, jlong window_ptr) {
Display *disp = (Display *)(intptr_t)display_ptr;
Window win = (Window)window_ptr;
@@ -381,7 +424,7 @@
setDecorations(disp, win, 0);
}
- if (RootWindow(disp, screen) == parent_handle) { // on set hints when Display.setParent isn't used
+ if (RootWindow(disp, screen) == parent_handle) { // only set hints when Display.setParent isn't used
updateWindowBounds(disp, win, x, y, width, height, JNI_TRUE, resizable);
updateWindowHints(env, disp, win);
}
Modified: trunk/LWJGL/src/native/linux/opengles/org_lwjgl_opengl_Display.c
===================================================================
--- trunk/LWJGL/src/native/linux/opengles/org_lwjgl_opengl_Display.c 2012-02-06 20:35:25 UTC (rev 3741)
+++ trunk/LWJGL/src/native/linux/opengles/org_lwjgl_opengl_Display.c 2012-02-18 01:49:46 UTC (rev 3742)
@@ -273,6 +273,49 @@
return RootWindow(disp, screen);
}
+static Window getCurrentWindow(JNIEnv *env, jlong display_ptr, jlong window_ptr) {
+ Display *disp = (Display *)(intptr_t)display_ptr;
+
+ Window parent = (Window)window_ptr;
+ Window win, root;
+
+ Window *children;
+ unsigned int nchildren;
+
+ do {
+ win = parent;
+
+ if (XQueryTree(disp, win, &root, &parent, &children, &nchildren) == 0) {
+ throwException(env, "XQueryTree failed");
+ return 0;
+ }
+
+ if (children != NULL) XFree(children);
+ } while (parent != root);
+
+ return win;
+}
+
+JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetX(JNIEnv *env, jclass unused, jlong display_ptr, jlong window_ptr) {
+ Display *disp = (Display *)(intptr_t)display_ptr;
+ Window win = getCurrentWindow(env, display_ptr, window_ptr);
+
+ XWindowAttributes win_attribs;
+ XGetWindowAttributes(disp, win, &win_attribs);
+
+ return win_attribs.x;
+}
+
+JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetY(JNIEnv *env, jclass unused, jlong display_ptr, jlong window_ptr) {
+ Display *disp = (Display *)(intptr_t)display_ptr;
+ Window win = getCurrentWindow(env, display_ptr, window_ptr);
+
+ XWindowAttributes win_attribs;
+ XGetWindowAttributes(disp, win, &win_attribs);
+
+ return win_attribs.y;
+}
+
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetWidth(JNIEnv *env, jclass unused, jlong display_ptr, jlong window_ptr) {
Display *disp = (Display *)(intptr_t)display_ptr;
Window win = (Window)window_ptr;
@@ -375,7 +418,7 @@
setDecorations(disp, win, 0);
}
- if (RootWindow(disp, screen) == parent_handle) { // on set hints when Display.setParent isn't used
+ if (RootWindow(disp, screen) == parent_handle) { // only set hints when Display.setParent isn't used
updateWindowBounds(disp, win, x, y, width, height, JNI_TRUE, resizable);
updateWindowHints(env, disp, win);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|