mmi-legacy-input : add doing keygrab 53/264053/1
authordyamy-lee <dyamy.lee@samsung.com>
Wed, 25 Aug 2021 11:05:30 +0000 (20:05 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Mon, 13 Sep 2021 11:25:03 +0000 (20:25 +0900)
Change-Id: I79b06bb8df785a325082e36e3a3490b9d352ceee

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

index 925888c..7f91b24 100644 (file)
@@ -49,6 +49,21 @@ struct tizen_keyrouter_notify
     unsigned int error;
 };
 
+typedef struct keycode_map keycode_map_t;
+struct keycode_map
+{
+    xkb_keysym_t keysym;
+    xkb_keycode_t *keycodes;
+    int nkeycodes;
+};
+
+typedef struct keymap_info keymap_info_t;
+struct keymap_info
+{
+    const char *keyname;
+    int mode;
+};
+
 unsigned int has_keymap = 0;
 unsigned int set_keymap = 0;
 
@@ -353,6 +368,102 @@ void xkb_shutdown(void)
     xkb_context_unref(xkb_context);
 }
 
+static void
+find_keycode(struct xkb_keymap *keymap, xkb_keycode_t key, void *data)
+{
+    keycode_map_t *found_keycodes = (keycode_map_t *)data;
+    xkb_keysym_t keysym = found_keycodes->keysym;
+    int nsyms = 0;
+    const xkb_keysym_t *syms_out = NULL;
+    xkb_keycode_t *tmp_keycodes = NULL;
+
+    if(!keymap)
+    {
+        LOGE("Invalied keymap \n");
+        return;
+    }
+
+    nsyms = xkb_keymap_key_get_syms_by_level(keymap, key, 0, 0, &syms_out);
+
+    if (nsyms && syms_out)
+    {
+        if (*syms_out == keysym)
+        {
+            tmp_keycodes = calloc(1, sizeof(int)*(found_keycodes->nkeycodes+1));
+
+            if (tmp_keycodes)
+            {
+                memcpy(tmp_keycodes, found_keycodes->keycodes, sizeof(int)*found_keycodes->nkeycodes);
+                free(found_keycodes->keycodes);
+
+                found_keycodes->nkeycodes++;
+                found_keycodes->keycodes = tmp_keycodes;
+                found_keycodes->keycodes[found_keycodes->nkeycodes-1] = key;
+            }
+        }
+    }
+}
+
+int xkb_keycode_from_keysym(struct xkb_keymap *keymap, xkb_keysym_t keysym, xkb_keycode_t **keycodes)
+{
+    keycode_map_t found_keycodes = {0,};
+    found_keycodes.keysym = keysym;
+
+    if(!keymap)
+    {
+        LOGE("Invalied keymap \n");
+        return 0;
+    }
+
+    xkb_keymap_key_for_each(keymap, find_keycode, &found_keycodes);
+
+    *keycodes = found_keycodes.keycodes;
+    return found_keycodes.nkeycodes;
+}
+
+void _do_keygrab(const char *keyname, uint32_t mode)
+{
+    xkb_keysym_t keysym = 0x0;
+    int nkeycodes = 0;
+    xkb_keycode_t *keycodes = NULL;
+    int i;
+
+    keysym = xkb_keysym_from_name(keyname, XKB_KEYSYM_NO_FLAGS);
+    nkeycodes = xkb_keycode_from_keysym(keymap, keysym, &keycodes);
+    if(!nkeycodes)
+    {
+        LOGE("Failed do keygrab on %s(%d)\n", keyname, keysym);
+        free(keycodes);
+        keycodes = NULL;
+        return;
+    }
+
+    for(i=0; i<nkeycodes; i++)
+    {
+        tizen_keyrouter_set_keygrab(tz_keyrouter, NULL, keycodes[i], mode);
+        wl_display_dispatch(display);
+    }
+
+}
+
+static keymap_info_t stored_keymap[] = {
+        { "XF86Back", TIZEN_KEYROUTER_MODE_EXCLUSIVE },
+        { "XF86Info", TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE}
+};
+
+void _keygrab_init(void)
+{
+    int i;
+    int size = sizeof(stored_keymap)/sizeof(keymap_info_t);
+
+    LOGD("stored keymap size = %d\n", size);
+    for(i=0; i < size; i++)
+    {
+        LOGD("stored keymap %d = %s, %d\n", i, stored_keymap[i].keyname, stored_keymap[i].mode);
+        _do_keygrab(stored_keymap[i].keyname, stored_keymap[i].mode);
+    }
+}
+
 void _wl_init(void)
 {
     int res = 0;
@@ -407,6 +518,7 @@ void _wl_shutdown(void)
 void legacy_input_init(void)
 {
     _wl_init();
+    _keygrab_init();
 }
 
 void legacy_input_shutdown(void)