Browse Source

Cleanup

Thanks to glfwGetKeyScancode we can now pass only a scancode to the
platform layer for glfwGetKeyName.
Camilla Löwy 8 years ago
parent
commit
82284b86eb
8 changed files with 21 additions and 37 deletions
  1. 1 7
      src/cocoa_window.m
  2. 14 8
      src/input.c
  3. 1 5
      src/internal.h
  4. 1 1
      src/mir_window.c
  5. 1 1
      src/null_window.c
  6. 1 7
      src/win32_window.c
  7. 1 1
      src/wl_window.c
  8. 1 7
      src/x11_window.c

+ 1 - 7
src/cocoa_window.m

@@ -1560,14 +1560,8 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
         updateCursorImage(window);
 }
 
-const char* _glfwPlatformGetKeyName(int key, int scancode)
+const char* _glfwPlatformGetScancodeName(int scancode)
 {
-    if (key != GLFW_KEY_UNKNOWN)
-        scancode = _glfw.ns.scancodes[key];
-
-    if (!_glfwIsPrintable(_glfw.ns.keycodes[scancode]))
-        return NULL;
-
     UInt32 deadKeyState = 0;
     UniChar characters[8];
     UniCharCount characterCount = 0;

+ 14 - 8
src/input.c

@@ -289,13 +289,6 @@ void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value)
 //////                       GLFW internal API                      //////
 //////////////////////////////////////////////////////////////////////////
 
-GLFWbool _glfwIsPrintable(int key)
-{
-    return (key >= GLFW_KEY_APOSTROPHE && key <= GLFW_KEY_WORLD_2) ||
-           (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_ADD) ||
-           key == GLFW_KEY_KP_EQUAL;
-}
-
 _GLFWjoystick* _glfwAllocJoystick(const char* name,
                                   const char* guid,
                                   int axisCount,
@@ -450,7 +443,20 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
 GLFWAPI const char* glfwGetKeyName(int key, int scancode)
 {
     _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
-    return _glfwPlatformGetKeyName(key, scancode);
+
+    if (key != GLFW_KEY_UNKNOWN)
+    {
+        if (key != GLFW_KEY_KP_EQUAL &&
+            (key < GLFW_KEY_KP_0 || key > GLFW_KEY_KP_ADD) &&
+            (key < GLFW_KEY_APOSTROPHE || key > GLFW_KEY_WORLD_2))
+        {
+            return NULL;
+        }
+
+        scancode = _glfwPlatformGetKeyScancode(key);
+    }
+
+    return _glfwPlatformGetScancodeName(scancode);
 }
 
 GLFWAPI int glfwGetKeyScancode(int key)

+ 1 - 5
src/internal.h

@@ -630,7 +630,7 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape);
 void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
 void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor);
 
-const char* _glfwPlatformGetKeyName(int key, int scancode);
+const char* _glfwPlatformGetScancodeName(int scancode);
 int _glfwPlatformGetKeyScancode(int key);
 
 void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos);
@@ -990,10 +990,6 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
   */
 void _glfwFreeJoystick(_GLFWjoystick* js);
 
-/*! @ingroup utility
- */
-GLFWbool _glfwIsPrintable(int key);
-
 /*! @ingroup utility
  */
 GLFWbool _glfwInitVulkan(int mode);

+ 1 - 1
src/mir_window.c

@@ -830,7 +830,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
     }
 }
 
-const char* _glfwPlatformGetKeyName(int key, int scancode)
+const char* _glfwPlatformGetScancodeName(int scancode)
 {
     _glfwInputError(GLFW_PLATFORM_ERROR,
                     "Mir: Unsupported function %s", __PRETTY_FUNCTION__);

+ 1 - 1
src/null_window.c

@@ -261,7 +261,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
     return NULL;
 }
 
-const char* _glfwPlatformGetKeyName(int key, int scancode)
+const char* _glfwPlatformGetScancodeName(int scancode)
 {
     return "";
 }

+ 1 - 7
src/win32_window.c

@@ -1609,16 +1609,10 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
         updateCursorImage(window);
 }
 
-const char* _glfwPlatformGetKeyName(int key, int scancode)
+const char* _glfwPlatformGetScancodeName(int scancode)
 {
     WCHAR name[16];
 
-    if (key != GLFW_KEY_UNKNOWN)
-        scancode = _glfw.win32.scancodes[key];
-
-    if (!_glfwIsPrintable(_glfw.win32.keycodes[scancode]))
-        return NULL;
-
     if (!GetKeyNameTextW(scancode << 16, name, sizeof(name) / sizeof(WCHAR)))
         return NULL;
 

+ 1 - 1
src/wl_window.c

@@ -721,7 +721,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
     _glfwPlatformSetCursor(window, window->wl.currentCursor);
 }
 
-const char* _glfwPlatformGetKeyName(int key, int scancode)
+const char* _glfwPlatformGetScancodeName(int scancode)
 {
     // TODO
     return NULL;

+ 1 - 7
src/x11_window.c

@@ -2474,17 +2474,11 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
     XFlush(_glfw.x11.display);
 }
 
-const char* _glfwPlatformGetKeyName(int key, int scancode)
+const char* _glfwPlatformGetScancodeName(int scancode)
 {
     if (!_glfw.x11.xkb.available)
         return NULL;
 
-    if (key != GLFW_KEY_UNKNOWN)
-        scancode = _glfw.x11.scancodes[key];
-
-    if (!_glfwIsPrintable(_glfw.x11.keycodes[scancode]))
-        return NULL;
-
     const KeySym keysym = XkbKeycodeToKeysym(_glfw.x11.display, scancode, 0, 0);
     if (keysym == NoSymbol)
         return NULL;