From 24e0591b6be036d5389cc1eb986ed5e86043ba65 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 10 Oct 2011 05:10:26 +0200 Subject: NEWT: Add pointer features: visibility, confined and warp (move) visibility: - set pointer visible or invisible confined: - confine pointer to window, or not warp: - set mouse position within the window Implemented for X11, tested manually with TestGearsES2NEWT (see code for action keys). TODO: Windows, MaxOSX and Android (limited) --- src/newt/native/X11Window.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'src/newt/native') diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index f2af91970..2038237cd 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -1903,3 +1903,79 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_X11Window_setTitle0 #endif } +/* + * Class: Java_jogamp_newt_driver_x11_X11Window + * Method: setPointerVisible0 + * Signature: (JJZ)Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_X11Window_setPointerVisible0 + (JNIEnv *env, jclass clazz, jlong display, jlong window, jboolean mouseVisible) +{ + static char noData[] = { 0,0,0,0,0,0,0,0 }; + static XColor black = { 0 }; + + Display * dpy = (Display *) (intptr_t) display; + Window w = (Window)window; + + DBG_PRINT( "X11: setPointerVisible0: %d\n", mouseVisible); + + if(JNI_TRUE == mouseVisible) { + XUndefineCursor(dpy, w); + } else { + Pixmap bitmapNoData; + Cursor invisibleCursor; + + bitmapNoData = XCreateBitmapFromData(dpy, w, noData, 8, 8); + if(None == bitmapNoData) { + return JNI_FALSE; + } + invisibleCursor = XCreatePixmapCursor(dpy, bitmapNoData, bitmapNoData, &black, &black, 0, 0); + XDefineCursor(dpy, w, invisibleCursor); + XFreeCursor(dpy, invisibleCursor); + XFreePixmap(dpy, bitmapNoData); + } + return JNI_TRUE; +} + +/* + * Class: Java_jogamp_newt_driver_x11_X11Window + * Method: confinePointer0 + * Signature: (JJZ)Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_X11Window_confinePointer0 + (JNIEnv *env, jclass clazz, jlong display, jlong window, jboolean confine) +{ + Display * dpy = (Display *) (intptr_t) display; + Window w = (Window)window; + int res; + + DBG_PRINT( "X11: confinePointer0: %d\n", confine); + + if(JNI_TRUE == confine) { + return GrabSuccess == XGrabPointer(dpy, w, True, + ButtonPressMask | ButtonReleaseMask | PointerMotionMask, + GrabModeAsync, GrabModeAsync, w, None, CurrentTime) + ? JNI_TRUE : JNI_FALSE ; + } + XUngrabPointer(dpy, CurrentTime); + return JNI_TRUE; +} + +/* + * Class: Java_jogamp_newt_driver_x11_X11Window + * Method: warpPointer0 + * Signature: (JJII)Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_X11Window_warpPointer0 + (JNIEnv *env, jclass clazz, jlong display, jlong window, jint x, jint y) +{ + Display * dpy = (Display *) (intptr_t) display; + Window w = (Window)window; + int res; + + DBG_PRINT( "X11: warpPointer0: %d/%d\n", x, y); + + XWarpPointer(dpy, None, w, 0, 0, 0, 0, x, y); + return JNI_TRUE; +} + -- cgit v1.2.3