Linux: Moved the pointer warp X11 atom from native to java
This commit is contained in:
parent
5dba786574
commit
8296ae06cb
|
@ -84,6 +84,9 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
/** Current mode swithcing API */
|
/** Current mode swithcing API */
|
||||||
private int current_displaymode_extension = NONE;
|
private int current_displaymode_extension = NONE;
|
||||||
|
|
||||||
|
/** Atom used for the pointer warp messages */
|
||||||
|
private long warp_atom;
|
||||||
|
|
||||||
private PeerInfo peer_info;
|
private PeerInfo peer_info;
|
||||||
|
|
||||||
/** Saved gamma used to restore display settings */
|
/** Saved gamma used to restore display settings */
|
||||||
|
@ -447,6 +450,20 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
}
|
}
|
||||||
private static native void nSwitchDisplayMode(long display, int screen, int extension, DisplayMode mode) throws LWJGLException;
|
private static native void nSwitchDisplayMode(long display, int screen, int extension, DisplayMode mode) throws LWJGLException;
|
||||||
|
|
||||||
|
static long getWarpAtom() throws LWJGLException {
|
||||||
|
return internAtom("_LWJGL", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long internAtom(String atom_name, boolean only_if_exists) throws LWJGLException {
|
||||||
|
incDisplay();
|
||||||
|
try {
|
||||||
|
return nInternAtom(getDisplay(), atom_name, only_if_exists);
|
||||||
|
} finally {
|
||||||
|
decDisplay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static native long nInternAtom(long display, String atom_name, boolean only_if_exists);
|
||||||
|
|
||||||
public void resetDisplayMode() {
|
public void resetDisplayMode() {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
|
@ -527,6 +544,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
public DisplayMode init() throws LWJGLException {
|
public DisplayMode init() throws LWJGLException {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
|
warp_atom = getWarpAtom();
|
||||||
current_displaymode_extension = getBestDisplayModeExtension();
|
current_displaymode_extension = getBestDisplayModeExtension();
|
||||||
if (current_displaymode_extension == NONE)
|
if (current_displaymode_extension == NONE)
|
||||||
throw new LWJGLException("No display mode extension is available");
|
throw new LWJGLException("No display mode extension is available");
|
||||||
|
@ -607,7 +625,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
public void update() {
|
public void update() {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
nUpdate(getDisplay());
|
nUpdate(getDisplay(), warp_atom);
|
||||||
checkInput();
|
checkInput();
|
||||||
} catch (LWJGLException e) {
|
} catch (LWJGLException e) {
|
||||||
LWJGLUtil.log("Caught exception while processing messages: " + e);
|
LWJGLUtil.log("Caught exception while processing messages: " + e);
|
||||||
|
@ -615,7 +633,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
unlockAWT();
|
unlockAWT();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private native void nUpdate(long display) throws LWJGLException;
|
private native void nUpdate(long display, long warp_atom) throws LWJGLException;
|
||||||
|
|
||||||
public void reshape(int x, int y, int width, int height) {
|
public void reshape(int x, int y, int width, int height) {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
|
@ -655,7 +673,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
public void createMouse() {
|
public void createMouse() {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
mouse = new LinuxMouse(getDisplay(), getWindow());
|
mouse = new LinuxMouse(getDisplay(), getWindow(), warp_atom);
|
||||||
} finally {
|
} finally {
|
||||||
unlockAWT();
|
unlockAWT();
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,6 @@ static Visual *current_visual;
|
||||||
static int current_screen;
|
static int current_screen;
|
||||||
static bool async_x_error;
|
static bool async_x_error;
|
||||||
static char error_message[ERR_MSG_SIZE];
|
static char error_message[ERR_MSG_SIZE];
|
||||||
static Atom warp_atom;
|
|
||||||
|
|
||||||
int getCurrentScreen(void) {
|
int getCurrentScreen(void) {
|
||||||
return current_screen;
|
return current_screen;
|
||||||
|
@ -119,12 +118,18 @@ static jlong openDisplay(JNIEnv *env) {
|
||||||
return (intptr_t)NULL;
|
return (intptr_t)NULL;
|
||||||
}
|
}
|
||||||
current_screen = XDefaultScreen(display_connection);
|
current_screen = XDefaultScreen(display_connection);
|
||||||
warp_atom = XInternAtom(display_connection, "_LWJGL_WARP", False);
|
|
||||||
return (intptr_t)display_connection;
|
return (intptr_t)display_connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
Atom getWarpAtom(void) {
|
|
||||||
return warp_atom;
|
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nInternAtom(JNIEnv *env, jclass unused, jlong display_ptr, jstring atom_name_obj, jboolean only_if_exists) {
|
||||||
|
Display *disp = (Display *)(intptr_t)display_ptr;
|
||||||
|
char *atom_name = GetStringNativeChars(env, atom_name_obj);
|
||||||
|
if (atom_name == NULL)
|
||||||
|
return 0;
|
||||||
|
Atom atom = XInternAtom(disp, atom_name, only_if_exists ? True : False);
|
||||||
|
free(atom_name);
|
||||||
|
return atom;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void waitMapped(Display *disp, Window win) {
|
static void waitMapped(Display *disp, Window win) {
|
||||||
|
@ -157,7 +162,7 @@ static bool isLegacyFullscreen(jint window_mode) {
|
||||||
return window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_LEGACY;
|
return window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_LEGACY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleMessages(JNIEnv *env, Display *disp, jobject disp_obj) {
|
static void handleMessages(JNIEnv *env, Display *disp, jobject disp_obj, Atom warp_atom) {
|
||||||
XEvent event;
|
XEvent event;
|
||||||
jclass disp_class = (*env)->GetObjectClass(env, disp_obj);
|
jclass disp_class = (*env)->GetObjectClass(env, disp_obj);
|
||||||
if (disp_class == NULL)
|
if (disp_class == NULL)
|
||||||
|
@ -375,9 +380,10 @@ Window getCurrentWindow(void) {
|
||||||
return current_win;
|
return current_win;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate(JNIEnv *env, jobject disp_obj, jlong display) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate(JNIEnv *env, jobject disp_obj, jlong display, jlong warp_atom_ptr) {
|
||||||
Display *disp = (Display *)(intptr_t)display;
|
Display *disp = (Display *)(intptr_t)display;
|
||||||
handleMessages(env, disp, disp_obj);
|
Atom warp_atom = (Atom)warp_atom_ptr;
|
||||||
|
handleMessages(env, disp, disp_obj, warp_atom);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateWindow(JNIEnv *env, jclass clazz, jlong display, jobject peer_info_handle, jobject mode, jint window_mode, jint x, jint y) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateWindow(JNIEnv *env, jclass clazz, jlong display, jobject peer_info_handle, jobject mode, jint window_mode, jint x, jint y) {
|
||||||
|
|
|
@ -91,13 +91,14 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_LinuxMouse_nQueryPointer(JNIEnv *e
|
||||||
return root_return;
|
return root_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxMouse_nSendWarpEvent(JNIEnv *env, jclass unusued, jlong display_ptr, jlong window_ptr, jint x, jint y) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxMouse_nSendWarpEvent(JNIEnv *env, jclass unusued, jlong display_ptr, jlong window_ptr, jlong warp_atom_ptr, jint x, jint y) {
|
||||||
|
Atom warp_atom = (Atom)warp_atom_ptr;
|
||||||
Display *disp = (Display *)(intptr_t)display_ptr;
|
Display *disp = (Display *)(intptr_t)display_ptr;
|
||||||
Window win = (Window)window_ptr;
|
Window win = (Window)window_ptr;
|
||||||
XEvent warp_event;
|
XEvent warp_event;
|
||||||
warp_event.type = ClientMessage;
|
warp_event.type = ClientMessage;
|
||||||
warp_event.xclient.window = win;
|
warp_event.xclient.window = win;
|
||||||
warp_event.xclient.message_type = getWarpAtom();
|
warp_event.xclient.message_type = warp_atom;
|
||||||
warp_event.xclient.format = 32;
|
warp_event.xclient.format = 32;
|
||||||
warp_event.xclient.data.l[0] = x;
|
warp_event.xclient.data.l[0] = x;
|
||||||
warp_event.xclient.data.l[1] = y;
|
warp_event.xclient.data.l[1] = y;
|
||||||
|
|
Loading…
Reference in New Issue