Replace XKeycodeToKeysym

When I try to create my code with X11 headers in Ubuntu 12.04

case KeyPress: xcommon_update_server_time( event.xkey.time ); /* if( event.xkey.state & ShiftMask ) arg |= I_SHIFT; */ /* this alternate approach allows handling of keys like '<' and '>' -- mrallen */ if( event.xkey.state & ShiftMask ) { mykey = XKeycodeToKeysym( display, event.xkey.keycode, 1 ); } else { mykey = XKeycodeToKeysym( display, event.xkey.keycode, 0 ); } 

What is the expected result? Collects.

What happens instead?

 warning: 'XKeycodeToKeysym' is deprecated (declared at /usr/include/X11/Xlib.h:1695) [-Wdeprecated-declarations] 

As a result, https://bugs.freedesktop.org/show_bug.cgi?id=5349 XKeycodeToKeysym is now correctly marked as deprecated.

How to fix my code for a free warning and proper assembly?

thanks

+7
source share
2 answers

If XKB available, then the easiest replacement for XKeycodeToKeysym :

 #include <X11/XKBlib.h> /* which declares: KeySym XkbKeycodeToKeysym(Display *dpy, KeyCode kc, unsigned int group, unsigned int level); */ 

... and then the source code of the question can become:

  mykey = XkbKeycodeToKeysym( display, event.xkey.keycode, 0, event.xkey.state & ShiftMask ? 1 : 0); 

notes:

+9
source

Show an example, and you can do the same in your source.

Replace

keysym = XKeycodeToKeysym(dpy,xe->xkey.keycode,0)

from

 { int keysyms_per_keycode_return; KeySym *keysym = XGetKeyboardMapping(dpy, xe->xkey.keycode, 1, &keysyms_per_keycode_return); /* do something with keysym[0] */ XFree(keysym); } 

Remember to free the return value.

+6
source

All Articles