2
0
Эх сурвалжийг харах

Wayland: Only input a character on GLFW_PRESS action

Closes #804.
Emmanuel Gil Peyrot 9 жил өмнө
parent
commit
2eb1657d91
1 өөрчлөгдсөн 23 нэмэгдсэн , 16 устгасан
  1. 23 16
      src/wl_init.c

+ 23 - 16
src/wl_init.c

@@ -258,6 +258,27 @@ static int toGLFWKeyCode(uint32_t key)
     return GLFW_KEY_UNKNOWN;
 }
 
+static void inputChar(_GLFWwindow* window, uint32_t key)
+{
+    uint32_t code, num_syms;
+    long cp;
+    const xkb_keysym_t *syms;
+
+    code = key + 8;
+    num_syms = xkb_key_get_syms(_glfw.wl.xkb.state, code, &syms);
+
+    if (num_syms == 1)
+    {
+        cp = _glfwKeySym2Unicode(syms[0]);
+        if (cp != -1)
+        {
+            const int mods = _glfw.wl.xkb.modifiers;
+            const int plain = !(mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT));
+            _glfwInputChar(window, cp, mods, plain);
+        }
+    }
+}
+
 static void keyboardHandleKey(void* data,
                               struct wl_keyboard* keyboard,
                               uint32_t serial,
@@ -265,11 +286,8 @@ static void keyboardHandleKey(void* data,
                               uint32_t key,
                               uint32_t state)
 {
-    uint32_t code, num_syms;
-    long cp;
     int keyCode;
     int action;
-    const xkb_keysym_t *syms;
     _GLFWwindow* window = _glfw.wl.keyboardFocus;
 
     if (!window)
@@ -282,19 +300,8 @@ static void keyboardHandleKey(void* data,
     _glfwInputKey(window, keyCode, key, action,
                   _glfw.wl.xkb.modifiers);
 
-    code = key + 8;
-    num_syms = xkb_key_get_syms(_glfw.wl.xkb.state, code, &syms);
-
-    if (num_syms == 1)
-    {
-        cp = _glfwKeySym2Unicode(syms[0]);
-        if (cp != -1)
-        {
-            const int mods = _glfw.wl.xkb.modifiers;
-            const int plain = !(mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT));
-            _glfwInputChar(window, cp, mods, plain);
-        }
-    }
+    if (action == GLFW_PRESS)
+        inputChar(window, key);
 }
 
 static void keyboardHandleModifiers(void* data,