# HG changeset patch # User alanbur # Date 1475779160 25200 # Node ID fef33230eaf897c38c52ccaf94992cf12bc2838d # Parent 13effd4d383be1bc072ea187d7beba00f53e2051 8165232: XKeycodeToKeysym is deprecated and should be replaced Reviewed-by: prr, azvegint diff -r 13effd4d383b -r fef33230eaf8 jdk/src/java.desktop/unix/native/libawt_xawt/xawt/XWindow.c --- a/jdk/src/java.desktop/unix/native/libawt_xawt/xawt/XWindow.c Thu Oct 06 20:51:34 2016 +0530 +++ b/jdk/src/java.desktop/unix/native/libawt_xawt/xawt/XWindow.c Thu Oct 06 11:39:20 2016 -0700 @@ -818,6 +818,32 @@ } return awt_UseXKB; } + +/* + * Map a keycode to the corresponding keysym. + * This replaces the deprecated X11 function XKeycodeToKeysym + */ +KeySym +keycodeToKeysym(Display *display, KeyCode keycode, int index) { + static int min_kc = -1; + static int max_kc; + if (min_kc == -1) { + (void) XDisplayKeycodes(display, &min_kc, &max_kc); + } + if (keycode < min_kc || keycode > max_kc || index < 0) { + return NoSymbol; + } + int num_syms; + KeySym *key_syms = XGetKeyboardMapping(display, keycode, 1, &num_syms); + if (index >= num_syms) { + XFree(key_syms); + return NoSymbol; + } + KeySym ks = key_syms[index]; + XFree(key_syms); + return ks; +} + static Boolean isKPevent(XEvent *event) { @@ -833,14 +859,14 @@ */ Boolean bsun = isXsunServer( event ); Boolean bxkb = isXKBenabled( event->xkey.display ); - return IsKeypadKey( XKeycodeToKeysym(event->xkey.display, event->xkey.keycode,(bsun && !bxkb ? 2 : 1) ) ); + return IsKeypadKey( keycodeToKeysym(event->xkey.display, event->xkey.keycode,(bsun && !bxkb ? 2 : 1) ) ); } static void dumpKeysymArray(XEvent *event) { - printf(" 0x%X\n",XKeycodeToKeysym(event->xkey.display, event->xkey.keycode, 0)); - printf(" 0x%X\n",XKeycodeToKeysym(event->xkey.display, event->xkey.keycode, 1)); - printf(" 0x%X\n",XKeycodeToKeysym(event->xkey.display, event->xkey.keycode, 2)); - printf(" 0x%X\n",XKeycodeToKeysym(event->xkey.display, event->xkey.keycode, 3)); + printf(" 0x%X\n",keycodeToKeysym(event->xkey.display, event->xkey.keycode, 0)); + printf(" 0x%X\n",keycodeToKeysym(event->xkey.display, event->xkey.keycode, 1)); + printf(" 0x%X\n",keycodeToKeysym(event->xkey.display, event->xkey.keycode, 2)); + printf(" 0x%X\n",keycodeToKeysym(event->xkey.display, event->xkey.keycode, 3)); } /* * In a next redesign, get rid of this code altogether. @@ -855,20 +881,20 @@ } if( isXsunServer( event ) && !awt_UseXKB) { if( (event->xkey.state & ShiftMask) ) { // shift modifier is on - *keysym = XKeycodeToKeysym(event->xkey.display, + *keysym = keycodeToKeysym(event->xkey.display, event->xkey.keycode, 3); }else { - *keysym = XKeycodeToKeysym(event->xkey.display, + *keysym = keycodeToKeysym(event->xkey.display, event->xkey.keycode, 2); } } else { if( (event->xkey.state & ShiftMask) || // shift modifier is on ((event->xkey.state & LockMask) && // lock modifier is on (awt_ModLockIsShiftLock)) ) { // it is interpreted as ShiftLock - *keysym = XKeycodeToKeysym(event->xkey.display, + *keysym = keycodeToKeysym(event->xkey.display, event->xkey.keycode, 0); }else{ - *keysym = XKeycodeToKeysym(event->xkey.display, + *keysym = keycodeToKeysym(event->xkey.display, event->xkey.keycode, 1); } } @@ -903,7 +929,7 @@ Perhaps using the index (modn in awt_MToolkit.c:setup_modifier_map) would be more correct. */ - *keysym = XKeycodeToKeysym(event->xkey.display, + *keysym = keycodeToKeysym(event->xkey.display, event->xkey.keycode, 2); if (originalKeysym != *keysym) { DTRACE_PRINTLN3("%s originalKeysym=0x%x, keysym=0x%x", @@ -999,7 +1025,6 @@ } } - /* This function is called as the keyChar parameter of a call to * awt_post_java_key_event. It depends on being called after adjustKeySym. * diff -r 13effd4d383b -r fef33230eaf8 jdk/src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c --- a/jdk/src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c Thu Oct 06 20:51:34 2016 +0530 +++ b/jdk/src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c Thu Oct 06 11:39:20 2016 -0700 @@ -49,6 +49,9 @@ #include +// From XWindow.c +extern KeySym keycodeToKeysym(Display *display, KeyCode keycode, int index); + #if defined(DEBUG) static jmethodID lockIsHeldMID = NULL; @@ -1286,7 +1289,7 @@ // report arbitrarily false. return JNI_FALSE; } else { - long ks2 = XKeycodeToKeysym((Display*)jlong_to_ptr(display), kc7, 2); + long ks2 = keycodeToKeysym((Display*)jlong_to_ptr(display), kc7, 2); if( ks2 == XK_KP_7 ) { //XXX If some Xorg server would put XK_KP_7 in keysymarray[2] as well, //XXX for yet unknown to me reason, the sniffer would lie. @@ -1915,12 +1918,13 @@ XQueryKeymap( (Display *) jlong_to_ptr(display), (char *) jlong_to_ptr(vector)); } +// XKeycodeToKeysym is deprecated but for compatibility we keep the API. JNIEXPORT jlong JNICALL Java_sun_awt_X11_XlibWrapper_XKeycodeToKeysym(JNIEnv *env, jclass clazz, jlong display, jint keycode, jint index) { AWT_CHECK_HAVE_LOCK_RETURN(0); - return XKeycodeToKeysym((Display*) jlong_to_ptr(display), (unsigned int)keycode, (int)index); + return keycodeToKeysym((Display*)jlong_to_ptr(display), (unsigned int)keycode, (int)index); } JNIEXPORT jint JNICALL