Related to #983.
This commit is contained in:
Camilla Löwy
2017-05-17 22:12:47 +02:00
parent c8ea64976f
commit 186d03b32a
4 changed files with 30 additions and 43 deletions
+27 -30
View File
@@ -879,31 +879,32 @@ static void releaseMonitor(_GLFWwindow* window)
// Encode a Unicode code point to a UTF-8 stream
// Based on cutef8 by Jeff Bezanson (Public Domain)
//
static size_t encodeUTF8(char *dest, uint32_t ch)
static size_t encodeUTF8(char* s, unsigned int ch)
{
if (ch < 0x80) {
dest[0] = (char)ch;
return 1;
size_t count = 0;
if (ch < 0x80)
s[count++] = (char) ch;
else if (ch < 0x800)
{
s[count++] = (ch >> 6) | 0xc0;
s[count++] = (ch & 0x3f) | 0x80;
}
if (ch < 0x800) {
dest[0] = (ch>>6) | 0xC0;
dest[1] = (ch & 0x3F) | 0x80;
return 2;
else if (ch < 0x10000)
{
s[count++] = (ch >> 12) | 0xe0;
s[count++] = ((ch >> 6) & 0x3f) | 0x80;
s[count++] = (ch & 0x3f) | 0x80;
}
if (ch < 0x10000) {
dest[0] = (ch>>12) | 0xE0;
dest[1] = ((ch>>6) & 0x3F) | 0x80;
dest[2] = (ch & 0x3F) | 0x80;
return 3;
else if (ch < 0x110000)
{
s[count++] = (ch >> 18) | 0xf0;
s[count++] = ((ch >> 12) & 0x3f) | 0x80;
s[count++] = ((ch >> 6) & 0x3f) | 0x80;
s[count++] = (ch & 0x3f) | 0x80;
}
if (ch < 0x110000) {
dest[0] = (ch>>18) | 0xF0;
dest[1] = ((ch>>12) & 0x3F) | 0x80;
dest[2] = ((ch>>6) & 0x3F) | 0x80;
dest[3] = (ch & 0x3F) | 0x80;
return 4;
}
return 0;
return count;
}
// Decode a Unicode code point from a UTF-8 stream
@@ -2475,10 +2476,6 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
const char* _glfwPlatformGetKeyName(int key, int scancode)
{
KeySym keysym;
long ch;
size_t sz;
if (!_glfw.x11.xkb.available)
return NULL;
@@ -2488,19 +2485,19 @@ const char* _glfwPlatformGetKeyName(int key, int scancode)
if (!_glfwIsPrintable(_glfw.x11.keycodes[scancode]))
return NULL;
keysym = XkbKeycodeToKeysym(_glfw.x11.display, scancode, 0, 0);
const KeySym keysym = XkbKeycodeToKeysym(_glfw.x11.display, scancode, 0, 0);
if (keysym == NoSymbol)
return NULL;
ch = _glfwKeySym2Unicode(keysym);
const long ch = _glfwKeySym2Unicode(keysym);
if (ch == -1)
return NULL;
sz = encodeUTF8(_glfw.x11.keyName, (uint32_t)ch);
if (sz == 0)
const size_t count = encodeUTF8(_glfw.x11.keyName, (unsigned int) ch);
if (count == 0)
return NULL;
_glfw.x11.keyName[sz] = '\0';
_glfw.x11.keyName[count] = '\0';
return _glfw.x11.keyName;
}