Commit 79f4ec68 authored by Camilla Löwy's avatar Camilla Löwy
Browse files

Unify key name string handling

This makes key names per-key static strings for all supported platforms.

Fixes #1200.

(cherry picked from commit 56ca0cb3b30ecb1310752360e9c875fc1b2bab5e)
parent 2032a8f0
......@@ -4193,9 +4193,11 @@ GLFWAPI int glfwRawMouseMotionSupported(void);
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_ERROR.
*
* @remark The contents of the returned string may change when a keyboard
* layout change event is received.
*
* @pointer_lifetime The returned string is allocated and freed by GLFW. You
* should not free it yourself. It is valid until the next call to @ref
* glfwGetKeyName, or until the library is terminated.
* should not free it yourself. It is valid until the library is terminated.
*
* @thread_safety This function must only be called from the main thread.
*
......
......@@ -139,7 +139,7 @@ typedef struct _GLFWlibraryNS
id keyUpMonitor;
id nibObjects;
char keyName[64];
char keynames[GLFW_KEY_LAST + 1][17];
short int keycodes[256];
short int scancodes[GLFW_KEY_LAST + 1];
char* clipboardString;
......
......@@ -1503,8 +1503,10 @@ const char* _glfwPlatformGetScancodeName(int scancode)
{
@autoreleasepool {
const int key = _glfw.ns.keycodes[scancode];
UInt32 deadKeyState = 0;
UniChar characters[8];
UniChar characters[4];
UniCharCount characterCount = 0;
if (UCKeyTranslate([(NSData*) _glfw.ns.unicodeData bytes],
......@@ -1529,12 +1531,12 @@ const char* _glfwPlatformGetScancodeName(int scancode)
characterCount,
kCFAllocatorNull);
CFStringGetCString(string,
_glfw.ns.keyName,
sizeof(_glfw.ns.keyName),
_glfw.ns.keynames[key],
sizeof(_glfw.ns.keynames[key]),
kCFStringEncodingUTF8);
CFRelease(string);
return _glfw.ns.keyName;
return _glfw.ns.keynames[key];
} // autoreleasepool
}
......
......@@ -228,7 +228,7 @@ typedef struct _GLFWlibraryX11
// Clipboard string (while the selection is owned)
char* clipboardString;
// Key name string
char keyName[5];
char keynames[GLFW_KEY_LAST + 1][5];
// X11 keycode to GLFW key LUT
short int keycodes[256];
// GLFW key to X11 keycode LUT
......
......@@ -2792,6 +2792,7 @@ const char* _glfwPlatformGetScancodeName(int scancode)
if (!_glfw.x11.xkb.available)
return NULL;
const int key = _glfw.x11.keycodes[scancode];
const KeySym keysym = XkbKeycodeToKeysym(_glfw.x11.display,
scancode, _glfw.x11.xkb.group, 0);
if (keysym == NoSymbol)
......@@ -2801,12 +2802,12 @@ const char* _glfwPlatformGetScancodeName(int scancode)
if (ch == -1)
return NULL;
const size_t count = encodeUTF8(_glfw.x11.keyName, (unsigned int) ch);
const size_t count = encodeUTF8(_glfw.x11.keynames[key], (unsigned int) ch);
if (count == 0)
return NULL;
_glfw.x11.keyName[count] = '\0';
return _glfw.x11.keyName;
_glfw.x11.keynames[key][count] = '\0';
return _glfw.x11.keynames[key];
}
int _glfwPlatformGetKeyScancode(int key)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment