--- /dev/null
+#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);
+}
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);
}
/* 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;
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)
}
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 */
}
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
#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;
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;
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;
Eina_Bool isWindowStackChanged;
int numTizenHWKeys;
+ int max_tizen_hwkeys;
};
struct _E_Keyrouter_Grab_Request {
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