mmi-legacy-input : implemente wl_keyboard events with keymap 51/264051/1
authordyamy-lee <dyamy.lee@samsung.com>
Wed, 25 Aug 2021 10:49:32 +0000 (19:49 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Mon, 13 Sep 2021 11:24:59 +0000 (20:24 +0900)
Change-Id: I92db70fab7d20e4ed3e4394fe56e9bde1dfd546b

src/modules/modality_keyboard/mmi-legacy-input.c

index 89c9d2c..c7c4732 100644 (file)
@@ -37,6 +37,10 @@ struct wl_seat *seat = NULL;
 struct wl_keyboard *keyboard = NULL;
 
 struct xkb_context *xkb_context;
+struct xkb_keymap *keymap;
+
+unsigned int has_keymap = 0;
+unsigned int set_keymap = 0;
 
 // wl_registry listener
 static void handle_global(void *, struct wl_registry *, unsigned int, const char *, unsigned int);
@@ -127,10 +131,48 @@ seat_name(void *data, struct wl_seat *seat, const char *name)
 static void
 keyboard_keymap(void *data, struct wl_keyboard *keyboard, unsigned int format, int fd, unsigned int size)
 {
-    (void) keyboard;
-    (void) format;
-    (void) fd;
-    (void) size;
+    char *map = NULL;
+
+    LOGD("...WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1=%d, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP=%d\n",
+                    WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP);
+    LOGD("... format=%d, fd=%d, size=%d\n",  format, fd, size);
+
+    if (!xkb_context)
+    {
+        LOGE("... This client failed to make xkb context\n");
+        close(fd);
+        return;
+    }
+    if (format == WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP)
+    {
+        has_keymap = 0;
+    }
+    else
+    {
+        LOGD("wl_keyboard has keymap...\n");
+        map = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
+        if(map == MAP_FAILED)
+        {
+            LOGE("... Failed to mmap from fd(%d) size(%d)\n", fd, size);
+            close(fd);
+            return;
+        }
+
+        keymap = xkb_map_new_from_string(xkb_context, map, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
+        if(!keymap) {
+            LOGE("... Failed to get keymap from fd(%d)\n", fd);
+            munmap(map, size);
+            close(fd);
+            return;
+        }
+
+        munmap(map, size);
+        close(fd);
+        has_keymap = 1;
+    }
+
+    LOGD("has_keymap = %s\n", has_keymap ? "true" : "false");
+    set_keymap = 1;
 }
 
 static void
@@ -150,14 +192,37 @@ keyboard_leave(void *data, struct wl_keyboard *keyboard, unsigned int serial, st
     (void) surface;
 }
 
+static int
+covert_kernel_keycode_to_user_keycode(int kernel_keycode)
+{
+    LOGD("kernel keycode : %d, user keycode : %d\n", kernel_keycode, kernel_keycode+8);
+    return (kernel_keycode+8);
+}
+
 static void
 keyboard_key(void *data, struct wl_keyboard *keyboard, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state)
 {
-    (void) keyboard;
-    (void) serial;
-    (void) timestamp;
-    (void) keycode;
-    (void) state;
+    int user_keycode = covert_kernel_keycode_to_user_keycode(keycode);
+
+    LOGD("... serial=%d, time=%d, key=%d, state=%d\n", serial, timestamp, user_keycode, state);
+    if (!has_keymap)
+    {
+        //TODO : do anything with the given keycode
+        //           ex> call application callback(s)
+        LOGD("keycode : %d, state : %d, timestamp : %d\n", user_keycode, state, timestamp);
+    }
+    else
+    {
+        LOGD("has_keymap | keycode : %d, state : %d, timestamp : %d\n", user_keycode, state, timestamp);
+        if(keymap)
+        {
+            const char * name = NULL;
+            if((name = xkb_keymap_key_get_name(keymap, user_keycode)))
+                LOGD("key name = %s, keycode = %d\n", name, user_keycode);
+            else
+                LOGD("No matched keyname from keycode = %d\n", user_keycode);
+        }
+    }
 }
 
 static void
@@ -237,7 +302,8 @@ void _wl_init(void)
     }
     wl_registry_add_listener(registry, &registry_listener, NULL);
 
-    wl_display_dispatch(display);
+    while(!set_keymap)
+        wl_display_roundtrip(display);
 }
 
 void _wl_shutdown(void)