Add a keymap command to enlightenment_info for query a current keymap 98/68398/4
authorJengHyun Kang <jhyuni.kang@samsung.com>
Wed, 4 May 2016 04:14:50 +0000 (13:14 +0900)
committerGwanglim Lee <gl77.lee@samsung.com>
Wed, 4 May 2016 06:34:40 +0000 (23:34 -0700)
Change-Id: Ic91b668f578c521e3fb62a54454f37c289aa352e

configure.ac
src/bin/e_info_client.c
src/bin/e_info_server.c

index 764b6d13fb672e6911ab2c4e60efcc607cc52a66..2da2d3d7174d5fa5f4bddeded8f5ddc81a1e5b11 100755 (executable)
@@ -270,6 +270,7 @@ PKG_CHECK_MODULES(E_INFO, [
   eina >= ${efl_version}
   ecore >= ${efl_version}
   eldbus >= ${efl_version}
+  xkbcommon
 ])
 
 PKG_CHECK_EXISTS([xkeyboard-config],[
index 2e3a75195a8749a689d1db848f29ddbaab7dd9fe..3ce466e51f45ea09591263261a3fc6188da3a8a0 100644 (file)
@@ -2,6 +2,7 @@
 #include "e_info_shared_types.h"
 #include <time.h>
 #include <dirent.h>
+#include <sys/mman.h>
 
 typedef void (*E_Info_Message_Cb)(const Eldbus_Message *msg);
 
@@ -196,6 +197,82 @@ finish:
      }
 }
 
+static void
+_cb_input_keymap_info_get(const Eldbus_Message *msg)
+{
+   const char *name = NULL, *text = NULL;
+   Eina_Bool res;
+   int i;
+   int min_keycode=0, max_keycode=0, fd=0, size=0, num_mods=0, num_groups = 0;
+   struct xkb_context *context = NULL;
+   struct xkb_keymap *keymap = NULL;
+   struct xkb_state *state = NULL;
+   xkb_keysym_t sym = XKB_KEY_NoSymbol;
+   char keyname[256] = {0, };
+   char *map = NULL;
+
+   res = eldbus_message_error_get(msg, &name, &text);
+   EINA_SAFETY_ON_TRUE_GOTO(res, finish);
+
+   res = eldbus_message_arguments_get(msg, "hi", &fd, &size);
+   EINA_SAFETY_ON_FALSE_GOTO(res, finish);
+
+   context = xkb_context_new(0);
+   EINA_SAFETY_ON_NULL_GOTO(context, finish);
+
+   map = mmap(NULL, size, 0x01, 0x0001, fd, 0);
+   if (map == ((void *)-1))
+     {
+        close(fd);
+        return;
+     }
+
+   keymap = xkb_map_new_from_string(context, map, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
+
+   munmap(map, size);
+   close(fd);
+
+   EINA_SAFETY_ON_NULL_GOTO(keymap, finish);
+   state = xkb_state_new(keymap);
+   EINA_SAFETY_ON_NULL_GOTO(state, finish);
+
+   min_keycode = xkb_keymap_min_keycode(keymap);
+   max_keycode = xkb_keymap_max_keycode(keymap);
+   num_groups = xkb_map_num_groups(keymap);
+   num_mods = xkb_keymap_num_mods(keymap);
+
+   printf("\n");
+   printf("    min keycode: %d\n", min_keycode);
+   printf("    max keycode: %d\n", max_keycode);
+   printf("    num_groups : %d\n", num_groups);
+   printf("    num_mods   : %d\n", num_mods);
+   for (i = 0; i < num_mods; i++)
+     {
+        printf("        [%2d] mod: %s\n", i, xkb_keymap_mod_get_name(keymap, i));
+     }
+
+   printf("\n\n\tkeycode\t\tkeyname\t\t  keysym\t    repeat\n");
+   printf("    ----------------------------------------------------------------------\n");
+
+   for (i = min_keycode; i < (max_keycode + 1); i++)
+     {
+        sym = xkb_state_key_get_one_sym(state, i);
+
+        memset(keyname, 0, sizeof(keyname));
+        xkb_keysym_get_name(sym, keyname, sizeof(keyname));
+
+        printf("\t%4d%-5s%-25s%-20p%-5d\n", i, "", keyname, (void *)sym, xkb_keymap_key_repeats(keymap, i));
+     }
+finish:
+   if ((name) || (text ))
+     {
+        printf("errname:%s errmsg:%s\n", name, text);
+     }
+   if (state) xkb_state_unref(state);
+   if (keymap) xkb_map_unref(keymap);
+   if (context) xkb_context_unref(context);
+}
+
 static void
 _e_info_client_proc_protocol_trace(int argc, char **argv)
 {
@@ -323,6 +400,13 @@ _e_info_client_proc_input_device_info(int argc, char **argv)
    E_FREE_LIST(e_info_client.input_dev, free);
 }
 
+static void
+_e_info_client_proc_keymap_info(int argc, char **argv)
+{
+   if (!_e_info_client_eldbus_message("get_keymap", _cb_input_keymap_info_get))
+      return;
+}
+
 static char *
 _directory_make(char *path)
 {
@@ -1099,6 +1183,11 @@ static struct
       _e_info_client_proc_hwc_trace
    },
 #endif
+   {
+      "keymap", NULL,
+      "Print a current keymap",
+      _e_info_client_proc_keymap_info
+   },
 };
 
 static void
index cde8c32418f094b81c71e02d243fdbe396fc9f9d..3286db60fba9427a0d19e64074a3822e011b48d9 100644 (file)
@@ -906,6 +906,15 @@ _e_info_server_cb_protocol_trace(const Eldbus_Service_Interface *iface EINA_UNUS
    return reply;
 }
 
+static Eldbus_Message *
+_e_info_server_cb_keymap_info_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
+{
+   Eldbus_Message *reply = eldbus_message_method_return_new(msg);
+
+   eldbus_message_arguments_append(reply, "hi", e_comp_wl->xkb.fd, e_comp_wl->xkb.size);
+   return reply;
+}
+
 static Eldbus_Message *
 _e_info_server_cb_fps_info_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
 {
@@ -1191,6 +1200,7 @@ static const Eldbus_Method methods[] = {
 #ifdef HAVE_HWC
    { "hwc_trace_message", ELDBUS_ARGS({"i", "hwc_trace_message"}), NULL, e_info_server_cb_hwc_trace_message, 0},
 #endif
+   { "get_keymap", NULL, ELDBUS_ARGS({"hi", "keymap fd"}), _e_info_server_cb_keymap_info_get, 0},
    { NULL, NULL, NULL, NULL, 0 }
 };