Use XkbKeycodeToKeysym since XKeycodeToKeysym is deprecated


#1

This fixes deprecation warnings with XKeycodeToKeysym.
There is also a bug report on XKeycodeToKeysym
https://bugs.freedesktop.org/show_bug.cgi?id=5349

diff --git a/modules/juce_gui_basics/juce_gui_basics.cpp b/modules/juce_gui_basics/juce_gui_basics.cpp
index 4945104..c495af7 100644
--- a/modules/juce_gui_basics/juce_gui_basics.cpp
+++ b/modules/juce_gui_basics/juce_gui_basics.cpp
@@ -96,6 +96,7 @@
  #include <X11/Xutil.h>
  #include <X11/Xmd.h>
  #include <X11/keysym.h>
+ #include <X11/XKBlib.h>
  #include <X11/cursorfont.h>
  #include <unistd.h>
 
diff --git a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp
index 5a000c7..d5f1394 100644
--- a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp
+++ b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp
@@ -1284,7 +1284,7 @@ public:
             keyCode = (int) unicodeChar;
 
             if (keyCode < 0x20)
-                keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
+                keyCode = XkbKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0, 0);
 
             keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
         }
@@ -1387,7 +1387,7 @@ public:
 
             {
                 ScopedXLock xlock;
-                sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
+                sym = XkbKeycodeToKeysym (display, keyEvent->keycode, 0, 0);
             }
 
             const ModifierKeys oldMods (currentModifiers);

I don’t know how backward compatible this is because I just checked on Ubuntu 11.10 and 12.04 but maybe this could be considered for the future.

Peter


#2

Seems like a good suggestion, and works for me in Ubuntu 10, so I think I’ll go with this. Thanks!


#3

Thanks for merging that in.

Actually there is an error. The one line should be this

diff --git a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp
index d5f1394..5b3c992 100644
--- a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp
+++ b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp
@@ -1284,7 +1284,7 @@ public:
             keyCode = (int) unicodeChar;
 
             if (keyCode < 0x20)
-                keyCode = XkbKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0, 0);
+                keyCode = XkbKeycodeToKeysym (display, keyEvent->keycode, 0, currentModifiers.isShiftDown() ? 1 : 0);
 
             keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
         }

The function is

KeySym XkbKeycodeToKeysym(Display *dpy, KeyCode kc, unsigned int group, unsigned int level);

Sorry for that.

Peter


#4

Doh! Thanks, fixed now.


#5

Still wrong in the latest commit.
You have in line 1287 now this

keyCode = XkbKeycodeToKeysym (display, 0, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);

and should be this

keyCode = XkbKeycodeToKeysym (display, keyEvent->keycode, 0, currentModifiers.isShiftDown() ? 1 : 0);

#6

Jeez… Sorry! Third time lucky!