When I try to build my code with the 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? Compiles.
What happens instead?
warning: 'XKeycodeToKeysym' is deprecated (declared at /usr/include/X11/Xlib.h:1695) [-Wdeprecated-declarations]
As a result of https://bugs.freedesktop.org/show_bug.cgi?id=5349 XKeycodeToKeysym is now properly marked as being deprecated.
How to fix my code for warning free and correct build?
Thanks
Provided XKB
is available then the simplest replacement for XKeycodeToKeysym
is:
#include <X11/XKBlib.h>
/* which declares:
KeySym XkbKeycodeToKeysym(Display *dpy, KeyCode kc,
unsigned int group, unsigned int level); */
... and then the original question's code could become:
mykey = XkbKeycodeToKeysym( display, event.xkey.keycode,
0, event.xkey.state & ShiftMask ? 1 : 0);
notes:
XGetKeyboardMapping
and the XKB
replacement solutions.Show you an example and you can do the same on your source.
Replace
keysym = XKeycodeToKeysym(dpy,xe->xkey.keycode,0)
with
{
int keysyms_per_keycode_return;
KeySym *keysym = XGetKeyboardMapping(dpy,
xe->xkey.keycode,
1,
&keysyms_per_keycode_return);
/* do something with keysym[0] */
XFree(keysym);
}
Not forgetting to free the return value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With