Build a keymap table using a config file 70/52870/5
authorJengHyun Kang <jhyuni.kang@samsung.com>
Fri, 27 Nov 2015 04:00:59 +0000 (13:00 +0900)
committerJengHyun Kang <jhyuni.kang@samsung.com>
Tue, 8 Dec 2015 03:15:49 +0000 (12:15 +0900)
Change-Id: I12ad192409d6f75c90925d7383932e61c0a0a787

src/Makefile.am
src/e_mod_keyrouter_conf.c [new file with mode: 0644]
src/e_mod_keyrouter_events.c
src/e_mod_keyrouter_list.c
src/e_mod_main_wl.c [changed mode: 0755->0644]
src/e_mod_main_wl.h

index 72fddb7..44cdd1b 100644 (file)
@@ -9,7 +9,8 @@ if WAYLAND_ONLY
 module_la_SOURCES      = e_mod_main_wl.c \
                          e_mod_main_wl.h \
                          e_mod_keyrouter_list.c \
-                         e_mod_keyrouter_events.c
+                         e_mod_keyrouter_events.c \
+                         e_mod_keyrouter_conf.c
 module_la_CFLAGS       = @ENLIGHTENMENT_CFLAGS@ @WAYLAND_CFLAGS@ -DHAVE_WAYLAND_ONLY
 module_la_LDFLAGS      = -module -avoid-version @WAYLAND_LIBS@ @ENLIGHTENMENT_LIBS@
 else
diff --git a/src/e_mod_keyrouter_conf.c b/src/e_mod_keyrouter_conf.c
new file mode 100644 (file)
index 0000000..cc2d336
--- /dev/null
@@ -0,0 +1,50 @@
+#define E_COMP_WL
+#include "e.h"
+#include "e_mod_main_wl.h"
+
+void
+e_keyrouter_conf_init(E_Keyrouter_Config_Data *kconfig)
+{
+   E_Keyrouter_Tizen_HWKey *data;
+   Eina_List *l;
+
+   kconfig->conf_hwkeys_edd= E_CONFIG_DD_NEW("E_Keyrouter_Config_Key",
+                                               E_Keyrouter_Tizen_HWKey);
+#undef T
+#undef D
+#define T E_Keyrouter_Tizen_HWKey
+#define D kconfig->conf_hwkeys_edd
+   E_CONFIG_VAL(D, T, name, STR);
+   E_CONFIG_VAL(D, T, keycode, INT);
+
+   kconfig->conf_edd = E_CONFIG_DD_NEW("Keyrouter_Config", E_Keyrouter_Conf_Edd);
+#undef T
+#undef D
+#define T E_Keyrouter_Conf_Edd
+#define D kconfig->conf_edd
+   E_CONFIG_VAL(D, T, num_keycode, INT);
+   E_CONFIG_VAL(D, T, max_keycode, INT);
+   E_CONFIG_LIST(D, T, KeyList, kconfig->conf_hwkeys_edd);
+
+#undef T
+#undef D
+   kconfig->conf = e_config_domain_load("module.keyrouter", kconfig->conf_edd);
+
+   if (!kconfig->conf)
+     {
+        KLDBG("Failed to find module.keyrouter config file.\n");
+     }
+}
+
+void
+e_keyrouter_conf_deinit(E_Keyrouter_Config_Data *kconfig)
+{
+   if (kconfig->conf)
+     {
+        E_FREE_LIST(kconfig->conf->KeyList, free);
+        free(kconfig->conf);
+     }
+
+   E_CONFIG_DD_FREE(kconfig->conf_hwkeys_edd);
+   E_CONFIG_DD_FREE(kconfig->conf_edd);
+}
index 7067e4f..43ef4ab 100644 (file)
@@ -44,19 +44,19 @@ e_keyrouter_process_key_event(void *event, int type)
 
    KLDBG("type=%s\n", (type == ECORE_EVENT_KEY_DOWN) ? "ECORE_EVENT_KEY_DOWN" : "ECORE_EVENT_KEY_UP");
 
-   if (MAX_HWKEYS <= ev->keycode)
+   if (krt->max_tizen_hwkeys < ev->keycode)
      {
         KLDBG("The key(%d) is too larger to process keyrouting: Invalid keycode\n", ev->keycode);
         return res;
      }
 
-   if ( (ECORE_EVENT_KEY_DOWN == type) && (!_e_keyrouter_is_key_grabbed(ev->keycode)) )
+   if ((ECORE_EVENT_KEY_DOWN == type) && (!_e_keyrouter_is_key_grabbed(ev->keycode)))
      {
         KLDBG("The press key(%d) isn't a grabbable key or has not been grabbed yet !\n", ev->keycode);
         return res;
      }
 
-   if ( (ECORE_EVENT_KEY_UP == type) && (!krt->HardKeys[ev->keycode].press_ptr) )
+   if ((ECORE_EVENT_KEY_UP == type) && (!krt->HardKeys[ev->keycode].press_ptr))
      {
         KLDBG("The release key(%d) isn't a grabbable key or has not been grabbed yet !\n", ev->keycode);
         return res;
index 262b36b..1481bdc 100644 (file)
@@ -306,7 +306,7 @@ e_keyrouter_remove_client_from_list(struct wl_resource *surface, struct wl_clien
 
    EINA_SAFETY_ON_TRUE_RETURN(((!surface) && (!wc)));
 
-   for (i = 0; i < MAX_HWKEYS; i++)
+   for (i = 0; i < krt->max_tizen_hwkeys; i++)
      {
         if (0 == krt->HardKeys[i].keycode) continue;
 
old mode 100755 (executable)
new mode 100644 (file)
index 5d0fd33..e51c182
@@ -6,11 +6,11 @@
 E_KeyrouterPtr krt = NULL;
 EAPI E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Keyrouter Module of Window Manager" };
 
-static Eina_Bool _e_keyrouter_init();
+static E_Keyrouter_Config_Data *_e_keyrouter_init(E_Module *m);
 static void _e_keyrouter_init_handlers(void);
 static void _e_keyrouter_deinit_handlers(void);
 
-static void _e_keyrouter_query_tizen_key_table(void);
+static Eina_Bool _e_keyrouter_query_tizen_key_table(void);
 static int _e_keyrouter_wl_array_length(const struct wl_array *array);
 
 static Eina_Bool _e_keyrouter_client_cb_stack(void *data, int type, void *event);
@@ -43,7 +43,7 @@ _e_keyrouter_keygrab_set(struct wl_client *client, struct wl_resource *surface,
      }
 
    /* Check the given key range */
-   if (MAX_HWKEYS <= key)
+   if (krt->max_tizen_hwkeys < key)
      {
         KLDBG("Invalid range of key ! (keycode:%d)\n", key);
         return TIZEN_KEYROUTER_ERROR_INVALID_KEY;
@@ -347,15 +347,17 @@ _event_filter(void *data, void *loop_data EINA_UNUSED, int type, void *event)
    return EINA_TRUE;
 }
 
-static Eina_Bool
-_e_keyrouter_init()
+static E_Keyrouter_Config_Data *
+_e_keyrouter_init(E_Module *m)
 {
+   E_Keyrouter_Config_Data *kconfig = NULL;
    krt = E_NEW(E_Keyrouter, 1);
+   Eina_Bool res = EINA_FALSE;
 
    if (!krt)
      {
         KLDBG("Failed to allocate memory for krt !\n");
-        return EINA_FALSE;
+        return NULL;
      }
 
    if (!e_comp)
@@ -373,47 +375,57 @@ _e_keyrouter_init()
      }
 
    krt->cdata = cdata;
-   krt->global = wl_global_create(cdata->wl.disp, &tizen_keyrouter_interface, 1, krt, _e_keyrouter_cb_bind);
 
-   if (!krt->global)
-     {
-        KLDBG("Failed to create global !\n");
-        goto err;
-     }
+   kconfig = E_NEW(E_Keyrouter_Config_Data, 1);
+   EINA_SAFETY_ON_NULL_GOTO(kconfig, err);
 
-   /* Get keyname and keycode pair from Tizen Key Layout file */
-   _e_keyrouter_query_tizen_key_table();
+   kconfig->module = m;
 
-#if 0
-   int i = 0;
-   for (i=0 ; i < krt->numTizenHWKeys ; i++)
-     {
-        KLDBG("keycode[%d], keyname[%s] : Enabled to grab\n", krt->TizenHWKeys[i].keycode, krt->TizenHWKeys[i].name);
-     }
-#endif
+   e_keyrouter_conf_init(kconfig);
+   EINA_SAFETY_ON_NULL_GOTO(kconfig->conf, err);
+   krt->conf = kconfig;
+
+   /* Get keyname and keycode pair from Tizen Key Layout file */
+   res = _e_keyrouter_query_tizen_key_table();
+   EINA_SAFETY_ON_FALSE_GOTO(res, err);
 
    /* Add filtering mechanism */
    krt->ef_handler = ecore_event_filter_add(NULL, _event_filter, NULL, NULL);
    _e_keyrouter_init_handlers();
 
-   return EINA_TRUE;
+   krt->global = wl_global_create(cdata->wl.disp, &tizen_keyrouter_interface, 1, krt, _e_keyrouter_cb_bind);
+   if (!krt->global)
+     {
+        KLDBG("Failed to create global !\n");
+        goto err;
+     }
+
+   return kconfig;
 
 err:
+   if (kconfig)
+     {
+        e_keyrouter_conf_deinit(kconfig);
+        E_FREE(kconfig);
+     }
+   _e_keyrouter_deinit_handlers();
    if (krt && krt->ef_handler) ecore_event_filter_del(krt->ef_handler);
    if (krt) E_FREE(krt);
 
-   return EINA_FALSE;
+   return NULL;
 }
 
 EAPI void *
 e_modapi_init(E_Module *m)
 {
-   return (_e_keyrouter_init() ? m : NULL);
+   return _e_keyrouter_init(m);
 }
 
 EAPI int
-e_modapi_shutdown(E_Module *m EINA_UNUSED)
+e_modapi_shutdown(E_Module *m)
 {
+   E_Keyrouter_Config_Data *kconfig = m->data;
+   e_keyrouter_conf_deinit(kconfig);
    _e_keyrouter_deinit_handlers();
    /* TODO: free allocated memory */
 
@@ -421,80 +433,48 @@ e_modapi_shutdown(E_Module *m EINA_UNUSED)
 }
 
 EAPI int
-e_modapi_save(E_Module *m EINA_UNUSED)
+e_modapi_save(E_Module *m)
 {
    /* Save something to be kept */
+   E_Keyrouter_Config_Data *kconfig = m->data;
+   e_config_domain_save("module.keyrouter",
+                        kconfig->conf_edd,
+                        kconfig->conf);
+
    return 1;
 }
 
 /* Function for getting keyname/keycode information from a key layout file */
-static void
+static Eina_Bool
 _e_keyrouter_query_tizen_key_table(void)
 {
-   FILE *fp_key_tables = NULL;
-   char keyname[64] = {0, };
-   int key_count = 0;
-   int key_size = 0;
-   int keycode = 0;
-   int i = 0;
-
-   fp_key_tables = fopen(KEYLAYOUT_PATH, "r");
-
-   if (!fp_key_tables)
-     {
-        KLDBG("Failed to read file (%s)\n", KEYLAYOUT_PATH);
-        return;
-     }
-
-   //KLDBG("Support Tizen Keymap\n");
-   while ( 0 < fscanf(fp_key_tables, "%s %d%*[^\n]c", keyname, &keycode))
-     {
-        key_count++;
-        //KLDBG(" - [%s : %d]\n", keyname, keycode);
-     }
-
-   if (MAX_HWKEYS <= key_count)
-     {
-        KLDBG("[ERR] key_count:%d exceeds limit of arrays!\n", key_count);
-        fclose(fp_key_tables);
-        return;
-     }
+   E_Keyrouter_Conf_Edd *kconf = krt->conf->conf;
+   Eina_List *l;
+   E_Keyrouter_Tizen_HWKey *data;
 
-   krt->TizenHWKeys = E_NEW(E_Keyrouter_Tizen_HWKey, key_count);
-   krt->numTizenHWKeys = key_count;
+   /* TODO: Make struct in HardKeys to pointer.
+                  If a key is defined, allocate memory to pointer,
+                  that makes to save unnecessary memory */
+   krt->HardKeys = E_NEW(E_Keyrouter_Grabbed_Key, kconf->max_keycode + 1);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(krt->HardKeys, EINA_FALSE);
 
-   fseek(fp_key_tables, 0, SEEK_SET);
+   krt->numTizenHWKeys = kconf->num_keycode;
+   krt->max_tizen_hwkeys = kconf->max_keycode;
 
-   for (i=0; i<key_count; i++)
+   EINA_LIST_FOREACH(kconf->KeyList, l, data)
      {
-        if (fscanf(fp_key_tables, "%s %d%*[^\n]c", keyname, &keycode) <= 0) continue;
+        if (!data) continue;
 
-        if ((0 > keycode) || (MAX_HWKEYS <= (keycode + 8)))
+        if (0 > data->keycode || krt->max_tizen_hwkeys < data->keycode)
           {
-             KLDBG("[ERR] Given keycode(%d) is invalid. It must be bigger than zero, smaller than the maximum value or equal to it.\n", keycode);
+             KLDBG("[ERR] Given keycode(%d) is invalid. It must be bigger than zero, smaller than the maximum value(%d) or equal to it.\n", data->keycode, kconf->max_keycode);
              continue;
           }
 
-        key_size = sizeof(keyname);
-
-        krt->TizenHWKeys[i].name = (char*)calloc(key_size, sizeof(char));
-
-        if (!krt->TizenHWKeys[i].name)
-          {
-             KLDBG("Failed to allocate memory !\n");
-             E_FREE(krt->TizenHWKeys);
-             krt->numTizenHWKeys = 0;
-             fclose(fp_key_tables);
-             return;
-          }
-
-        strncpy(krt->TizenHWKeys[i].name, keyname, key_size);
-
-        krt->TizenHWKeys[i].keycode = keycode+8;
-        krt->HardKeys[keycode+8].keycode = keycode+8;
+        krt->HardKeys[data->keycode].keycode = data->keycode;
+        krt->HardKeys[data->keycode].keyname = eina_stringshare_add(data->name);
      }
-
-   fclose(fp_key_tables);
+   return EINA_TRUE;
 }
 
 static int
index b242ce9..6729a66 100644 (file)
@@ -4,7 +4,6 @@
 #include <tizen-extension-server-protocol.h>
 
 /* Temporary value of maximum number of HWKeys */
-#define MAX_HWKEYS 512
 
 #define CHECK_ERR(val) if (TIZEN_KEYROUTER_ERROR_NONE != val) return;
 #define CHECK_ERR_VAL(val) if (TIZEN_KEYROUTER_ERROR_NONE != val) return val;
@@ -23,10 +22,28 @@ typedef struct _E_Keyrouter_Grab_Request E_Keyrouter_Grab_Request;
 typedef struct _E_Keyrouter_Grab_Result E_Keyrouter_Grab_Result;
 typedef struct _E_Keyrouter_Registered_Window_Info E_Keyrouter_Registered_Window_Info;
 
+typedef struct _E_Keyrouter_Conf_Edd E_Keyrouter_Conf_Edd;
+typedef struct _E_Keyrouter_Config_Data E_Keyrouter_Config_Data;
+
 #define TIZEN_KEYROUTER_MODE_PRESSED        TIZEN_KEYROUTER_MODE_REGISTERED+1
 
 extern E_KeyrouterPtr krt;
 
+struct _E_Keyrouter_Conf_Edd
+{
+   int num_keycode;
+   int max_keycode;
+   Eina_List *KeyList;
+};
+
+struct _E_Keyrouter_Config_Data
+{
+   E_Module *module;
+   E_Config_DD *conf_edd;
+   E_Config_DD *conf_hwkeys_edd;
+   E_Keyrouter_Conf_Edd *conf;
+};
+
 struct _E_Keyrouter_Registered_Window_Info
 {
    struct wl_resource *surface;
@@ -65,8 +82,9 @@ struct _E_Keyrouter
    Ecore_Event_Filter *ef_handler;
    Eina_List *handlers;
 
-   E_Keyrouter_Grabbed_Key HardKeys[MAX_HWKEYS];
-   E_Keyrouter_Tizen_HWKey *TizenHWKeys;
+   E_Keyrouter_Config_Data *conf;
+
+   E_Keyrouter_Grabbed_Key *HardKeys;
    Eina_List *surface_grab_client;
    Eina_List *none_surface_grab_client;
 
@@ -74,6 +92,7 @@ struct _E_Keyrouter
 
    Eina_Bool isWindowStackChanged;
    int numTizenHWKeys;
+   int max_tizen_hwkeys;
 };
 
 struct _E_Keyrouter_Grab_Request {
@@ -111,4 +130,7 @@ void e_keyrouter_clear_registered_window(void);
 
 struct wl_resource *e_keyrouter_util_get_surface_from_eclient(E_Client *client);
 
+void e_keyrouter_conf_init(E_Keyrouter_Config_Data *kconfig);
+void e_keyrouter_conf_deinit(E_Keyrouter_Config_Data *kconfig);
+
 #endif