diff options
author | Sven Gothel <[email protected]> | 2011-10-10 05:10:26 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-10-10 05:10:26 +0200 |
commit | 24e0591b6be036d5389cc1eb986ed5e86043ba65 (patch) | |
tree | e9abb4999bad2f01860490338b0dc588818ee495 /src/newt/native | |
parent | 51a9f23d629cd4e6b22d7afaf009bb96b2ed270f (diff) |
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)
Diffstat (limited to 'src/newt/native')
-rw-r--r-- | src/newt/native/X11Window.c | 76 |
1 files changed, 76 insertions, 0 deletions
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; +} + |