From 25905450a1935f007eb3a255482489466921529a Mon Sep 17 00:00:00 2001 From: JengHyun Kang Date: Wed, 20 Apr 2016 14:17:39 +0900 Subject: [PATCH] Enable/disable gesture and swipe back key by config file and aux hint Change-Id: Idadfafe8ec3f44bb6b648d7dd357154368a5e6ff --- src/Makefile.am | 3 +- src/e_mod_gesture_conf.c | 61 ++++++++++++++++++++++++++++++++++++++ src/e_mod_gesture_events.c | 46 +++++++++++++++------------- src/e_mod_main.c | 74 ++++++++++++++++++++++++++++++++++++++++++---- src/e_mod_main.h | 31 +++++++++++++++++++ 5 files changed, 188 insertions(+), 27 deletions(-) create mode 100644 src/e_mod_gesture_conf.c diff --git a/src/Makefile.am b/src/Makefile.am index 563afca..75ef645 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,7 +8,8 @@ pkg_LTLIBRARIES = module.la module_la_SOURCES = e_mod_main.c \ e_mod_main.h \ e_mod_gesture_events.c \ - e_mod_gesture_device.c + e_mod_gesture_device.c \ + e_mod_gesture_conf.c module_la_CFLAGS = @ENLIGHTENMENT_CFLAGS@ @WAYLAND_CFLAGS@ -DHAVE_WAYLAND_ONLY module_la_LDFLAGS = -module -avoid-version @WAYLAND_LIBS@ @ENLIGHTENMENT_LIBS@ diff --git a/src/e_mod_gesture_conf.c b/src/e_mod_gesture_conf.c new file mode 100644 index 0000000..beb0422 --- /dev/null +++ b/src/e_mod_gesture_conf.c @@ -0,0 +1,61 @@ +#define E_COMP_WL +#include "e_mod_main.h" + +void +_e_gesture_conf_value_check(E_Gesture_Config_Data* gconfig) +{ + E_Gesture_Conf_Edd *conf; + if (!gconfig->conf) gconfig->conf = E_NEW(E_Gesture_Conf_Edd, 1); + EINA_SAFETY_ON_NULL_RETURN(gconfig->conf); + + conf = gconfig->conf; + if (!conf->key_device_name) conf->key_device_name = strdup(E_GESTURE_KEYBOARD_DEVICE); + if (conf->swipe.time_done <= 0.0) conf->swipe.time_done = E_GESTURE_SWIPE_DONE_TIME; + if (conf->swipe.time_begin <= 0.0) conf->swipe.time_begin = E_GESTURE_SWIPE_START_TIME; + if (conf->swipe.area_offset <= 0) conf->swipe.area_offset = E_GESTURE_SWIPE_START_AREA; + if (conf->swipe.min_length <= 0) conf->swipe.min_length = E_GESTURE_SWIPE_DIFF_FAIL; + if (conf->swipe.max_length <= 0) conf->swipe.max_length = E_GESTURE_SWIPE_DIFF_SUCCESS; + if (conf->swipe.compose_key <= 0) conf->swipe.compose_key = E_GESTURE_SWIPE_COMBINE_KEY; + if (conf->swipe.back_key <= 0) conf->swipe.back_key = E_GESTURE_SWIPE_BACK_KEY; +} + +void +e_gesture_conf_init(E_Gesture_Config_Data *gconfig) +{ + gconfig->conf_edd = E_CONFIG_DD_NEW("Gesture_Config", E_Gesture_Conf_Edd); +#undef T +#undef D +#define T E_Gesture_Conf_Edd +#define D gconfig->conf_edd + E_CONFIG_VAL(D, T, key_device_name, STR); + E_CONFIG_VAL(D, T, swipe.time_done, DOUBLE); + E_CONFIG_VAL(D, T, swipe.time_begin, DOUBLE); + E_CONFIG_VAL(D, T, swipe.area_offset, INT); + E_CONFIG_VAL(D, T, swipe.min_length, INT); + E_CONFIG_VAL(D, T, swipe.max_length, INT); + E_CONFIG_VAL(D, T, swipe.compose_key, INT); + E_CONFIG_VAL(D, T, swipe.back_key, INT); + E_CONFIG_VAL(D, T, swipe.default_enable_back, CHAR); + +#undef T +#undef D + gconfig->conf = e_config_domain_load("module.gesture", gconfig->conf_edd); + + if (!gconfig->conf) + { + GTWRN("Failed to find module.keyrouter config file.\n"); + } + _e_gesture_conf_value_check(gconfig); +} + +void +e_gesture_conf_deinit(E_Gesture_Config_Data *gconfig) +{ + if (gconfig->conf) + { + E_FREE(gconfig->conf->key_device_name); + E_FREE(gconfig->conf); + } + E_CONFIG_DD_FREE(gconfig->conf_edd); + E_FREE(gconfig); +} diff --git a/src/e_mod_gesture_events.c b/src/e_mod_gesture_events.c index 5492964..b0548b8 100644 --- a/src/e_mod_gesture_events.c +++ b/src/e_mod_gesture_events.c @@ -44,6 +44,7 @@ static void _e_gesture_send_back_key(Eina_Bool pressed) { Ecore_Event_Key *ev; + E_Gesture_Conf_Edd *conf = gesture->config->conf; EINA_SAFETY_ON_NULL_RETURN(e_comp_wl->xkb.keymap); @@ -55,7 +56,7 @@ _e_gesture_send_back_key(Eina_Bool pressed) ev->compose = (char *)eina_stringshare_add(ev->key); ev->timestamp = (int)(ecore_time_get()*1000); ev->same_screen = 1; - ev->keycode = E_GESTURE_SWIPE_BACK_KEY; + ev->keycode = conf->swipe.back_key; ev->dev = gesture->device.kbd_device; if (pressed) @@ -69,6 +70,7 @@ _e_gesture_send_swipe(int fingers, int x, int y, int direction, struct wl_client { enum tizen_gesture_direction dir = 0; Ecore_Event_Mouse_Button *ev_cancel; + E_Gesture_Conf_Edd *conf = gesture->config->conf; switch (direction) { @@ -96,7 +98,7 @@ _e_gesture_send_swipe(int fingers, int x, int y, int direction, struct wl_client GTINF("Send swipe gesture (direction: %d) to client: %p\n", dir, client); - if (E_GESTURE_SWIPE_BACK_DEFAULT_ENABLE && + if (conf->swipe.default_enable_back && direction == E_GESTURE_DIRECTION_DOWN) { _e_gesture_send_back_key(EINA_TRUE); @@ -163,6 +165,7 @@ static void _e_gesture_process_swipe_down(Ecore_Event_Mouse_Button *ev) { E_Gesture_Event_Swipe *swipes = &gesture->gesture_events.swipes; + E_Gesture_Conf_Edd *conf = gesture->config->conf; int i; unsigned int idx = ev->multi.device+1; @@ -176,17 +179,17 @@ _e_gesture_process_swipe_down(Ecore_Event_Mouse_Button *ev) } } - if (ev->y < E_GESTURE_SWIPE_START_AREA) + if (ev->y < conf->swipe.area_offset) swipes->direction = E_GESTURE_DIRECTION_DOWN; - else if (ev->y > e_comp->h - E_GESTURE_SWIPE_START_AREA) + else if (ev->y > e_comp->h - conf->swipe.area_offset) swipes->direction = E_GESTURE_DIRECTION_UP; - else if (ev->x < E_GESTURE_SWIPE_START_AREA) + else if (ev->x < conf->swipe.area_offset) swipes->direction = E_GESTURE_DIRECTION_RIGHT; - else if (ev->x > e_comp->w - E_GESTURE_SWIPE_START_AREA) + else if (ev->x > e_comp->w - conf->swipe.area_offset) swipes->direction = E_GESTURE_DIRECTION_LEFT; if (swipes->direction != E_GESTURE_DIRECTION_DOWN && - !((swipes->combined_keycode == E_GESTURE_SWIPE_COMBINE_KEY) && swipes->direction == E_GESTURE_DIRECTION_RIGHT)) + !((swipes->combined_keycode == conf->swipe.compose_key) && swipes->direction == E_GESTURE_DIRECTION_RIGHT)) { _e_gesture_swipe_cancel(); } @@ -194,8 +197,8 @@ _e_gesture_process_swipe_down(Ecore_Event_Mouse_Button *ev) { swipes->fingers[idx].start.x = ev->x; swipes->fingers[idx].start.y = ev->y; - swipes->start_timer = ecore_timer_add(E_GESTURE_SWIPE_START_TIME, _e_gesture_timer_swipe_start, NULL); - swipes->done_timer = ecore_timer_add(E_GESTURE_SWIPE_DONE_TIME, _e_gesture_timer_swipe_done, NULL); + swipes->start_timer = ecore_timer_add(conf->swipe.time_begin, _e_gesture_timer_swipe_start, NULL); + swipes->done_timer = ecore_timer_add(conf->swipe.time_done, _e_gesture_timer_swipe_done, NULL); } } else @@ -212,6 +215,7 @@ static void _e_gesture_process_swipe_move(Ecore_Event_Mouse_Move *ev) { E_Gesture_Event_Swipe *swipes = &gesture->gesture_events.swipes; + E_Gesture_Conf_Edd *conf = gesture->config->conf; Coords diff; unsigned int idx = ev->multi.device+1; @@ -224,45 +228,45 @@ _e_gesture_process_swipe_move(Ecore_Event_Mouse_Move *ev) switch(swipes->direction) { case E_GESTURE_DIRECTION_DOWN: - if (diff.x > E_GESTURE_SWIPE_DIFF_FAIL) + if (diff.x > conf->swipe.min_length) { _e_gesture_swipe_cancel(); break; } - if (diff.y > E_GESTURE_SWIPE_DIFF_SUCCESS) + if (diff.y > conf->swipe.max_length) { _e_gesture_send_swipe(idx, swipes->fingers[idx].start.x, swipes->fingers[idx].start.y, swipes->direction, swipes->fingers[idx].direction[E_GESTURE_DIRECTION_DOWN].client, swipes->fingers[idx].direction[E_GESTURE_DIRECTION_DOWN].res); } break; case E_GESTURE_DIRECTION_LEFT: - if (diff.y > E_GESTURE_SWIPE_DIFF_FAIL) + if (diff.y > conf->swipe.min_length) { _e_gesture_swipe_cancel(); break; } - if (diff.x > E_GESTURE_SWIPE_DIFF_SUCCESS) + if (diff.x > conf->swipe.max_length) { _e_gesture_send_swipe(idx, swipes->fingers[idx].start.x, swipes->fingers[idx].start.y, swipes->direction, swipes->fingers[idx].direction[E_GESTURE_DIRECTION_LEFT].client, swipes->fingers[idx].direction[E_GESTURE_DIRECTION_LEFT].res); } break; case E_GESTURE_DIRECTION_UP: - if (diff.x > E_GESTURE_SWIPE_DIFF_FAIL) + if (diff.x > conf->swipe.min_length) { _e_gesture_swipe_cancel(); break; } - if (diff.y > E_GESTURE_SWIPE_DIFF_SUCCESS) + if (diff.y > conf->swipe.max_length) { _e_gesture_send_swipe(idx, swipes->fingers[idx].start.x, swipes->fingers[idx].start.y, swipes->direction, swipes->fingers[idx].direction[E_GESTURE_DIRECTION_UP].client, swipes->fingers[idx].direction[E_GESTURE_DIRECTION_UP].res); } break; case E_GESTURE_DIRECTION_RIGHT: - if (diff.y > E_GESTURE_SWIPE_DIFF_FAIL) + if (diff.y > conf->swipe.min_length) { _e_gesture_swipe_cancel(); break; } - if (diff.x > E_GESTURE_SWIPE_DIFF_SUCCESS) + if (diff.x > conf->swipe.max_length) { _e_gesture_send_swipe(idx, swipes->fingers[idx].start.x, swipes->fingers[idx].start.y, swipes->direction, swipes->fingers[idx].direction[E_GESTURE_DIRECTION_RIGHT].client, swipes->fingers[idx].direction[E_GESTURE_DIRECTION_RIGHT].res); } @@ -383,10 +387,11 @@ static Eina_Bool _e_gesture_process_key_down(void *event) { Ecore_Event_Key *ev = event; + E_Gesture_Conf_Edd *conf = gesture->config->conf; - if (ev->keycode == E_GESTURE_SWIPE_COMBINE_KEY) + if (ev->keycode == conf->swipe.compose_key) { - gesture->gesture_events.swipes.combined_keycode = E_GESTURE_SWIPE_COMBINE_KEY; + gesture->gesture_events.swipes.combined_keycode = conf->swipe.compose_key; } return EINA_TRUE; @@ -396,8 +401,9 @@ static Eina_Bool _e_gesture_process_key_up(void *event) { Ecore_Event_Key *ev = event; + E_Gesture_Conf_Edd *conf = gesture->config->conf; - if (ev->keycode == E_GESTURE_SWIPE_COMBINE_KEY) + if (ev->keycode == conf->swipe.compose_key) { gesture->gesture_events.swipes.combined_keycode = 0; } diff --git a/src/e_mod_main.c b/src/e_mod_main.c index 529a02f..d5c4f88 100644 --- a/src/e_mod_main.c +++ b/src/e_mod_main.c @@ -5,7 +5,7 @@ E_GesturePtr gesture = NULL; E_API E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Gesture Module of Window Manager" }; -static void *_e_gesture_init(E_Module *m); +static E_Gesture_Config_Data *_e_gesture_init(E_Module *m); static void _e_gesture_init_handlers(void); @@ -318,15 +318,51 @@ _e_gesture_event_filter(void *data, void *loop_data EINA_UNUSED, int type, void return e_gesture_process_events(event, type); } +static Eina_Bool +_e_gesture_cb_client_focus_in(void *data, int type, void *event) +{ + E_Client *ec; + E_Comp_Wl_Aux_Hint *hint; + Eina_List *l; + Eina_Bool gesture_disable = EINA_FALSE; + E_Event_Client *ev = (E_Event_Client *)event; + + EINA_SAFETY_ON_NULL_RETURN_VAL(ev, ECORE_CALLBACK_PASS_ON); + ec = ev->ec; + EINA_SAFETY_ON_NULL_RETURN_VAL(ec, ECORE_CALLBACK_PASS_ON); + EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, ECORE_CALLBACK_PASS_ON); + + if (ec->gesture_disable && gesture->enable) + { + GTINF("Disable gesture\n"); + ecore_event_filter_del(gesture->ef_handler); + gesture->ef_handler = NULL; + gesture->enable = EINA_FALSE; + } + else if (!ec->gesture_disable && !gesture->enable) + { + GTINF("enable gesture\n"); + gesture->ef_handler = ecore_event_filter_add(NULL, _e_gesture_event_filter, NULL, NULL); + gesture->enable = EINA_TRUE; + } + + return ECORE_CALLBACK_PASS_ON; +} + static void _e_gesture_init_handlers(void) { gesture->ef_handler = ecore_event_filter_add(NULL, _e_gesture_event_filter, NULL, NULL); + + gesture->handlers = eina_list_append(gesture->handlers, + ecore_event_handler_add(E_EVENT_CLIENT_FOCUS_IN, + _e_gesture_cb_client_focus_in, NULL)); } -static void * +static E_Gesture_Config_Data * _e_gesture_init(E_Module *m) { + E_Gesture_Config_Data *gconfig = NULL; gesture = E_NEW(E_Gesture, 1); if (!gesture) @@ -341,8 +377,25 @@ _e_gesture_init(E_Module *m) goto err; } - /* Add filtering mechanism */ + /* Add filtering mechanism + * FIXME: Add handlers after first gesture is grabbed + */ _e_gesture_init_handlers(); + + /* Init config */ + gconfig = E_NEW(E_Gesture_Config_Data, 1); + EINA_SAFETY_ON_NULL_GOTO(gconfig, err); + gconfig->module = m; + + e_gesture_conf_init(gconfig); + EINA_SAFETY_ON_NULL_GOTO(gconfig->conf, err); + gesture->config = gconfig; + + GTDBG("config value\n"); + GTDBG("keyboard: %s, time_done: %lf, time_begin: %lf\n", gconfig->conf->key_device_name, gconfig->conf->swipe.time_done, gconfig->conf->swipe.time_begin); + GTDBG("area_offset: %d, min_length: %d, max_length: %d\n", gconfig->conf->swipe.area_offset, gconfig->conf->swipe.min_length, gconfig->conf->swipe.max_length); + GTDBG("compose key: %d, back: %d, default: %d\n", gconfig->conf->swipe.compose_key, gconfig->conf->swipe.back_key, gconfig->conf->swipe.default_enable_back); + gesture->global = wl_global_create(e_comp_wl->wl.disp, &tizen_gesture_interface, 1, gesture, _e_gesture_cb_bind); if (!gesture->global) { @@ -352,7 +405,7 @@ _e_gesture_init(E_Module *m) gesture->gesture_filter = E_GESTURE_TYPE_MAX; - if (E_GESTURE_SWIPE_BACK_DEFAULT_ENABLE) + if (gconfig->conf->swipe.default_enable_back) { gesture->grabbed_gesture |= TIZEN_GESTURE_TYPE_SWIPE; gesture->gesture_events.swipes.fingers[1].enabled = EINA_TRUE; @@ -360,11 +413,14 @@ _e_gesture_init(E_Module *m) gesture->gesture_events.swipes.fingers[1].direction[E_GESTURE_DIRECTION_DOWN].res = (void *)0x1; } - e_gesture_device_keydev_set(E_GESTURE_KEYBOARD_DEVICE); + e_gesture_device_keydev_set(gesture->config->conf->key_device_name); + + gesture->enable = EINA_TRUE; - return m; + return gconfig; err: + if (gconfig) e_gesture_conf_deinit(gconfig); if (gesture && gesture->ef_handler) ecore_event_filter_del(gesture->ef_handler); if (gesture) E_FREE(gesture); @@ -380,6 +436,8 @@ e_modapi_init(E_Module *m) E_API int e_modapi_shutdown(E_Module *m) { + E_Gesture_Config_Data *gconfig = m->data; + e_gesture_conf_deinit(gconfig); e_gesture_device_shutdown(); return 1; } @@ -388,6 +446,10 @@ E_API int e_modapi_save(E_Module *m) { /* Save something to be kept */ + E_Gesture_Config_Data *gconfig = m->data; + e_config_domain_save("module.gesture", + gconfig->conf_edd, + gconfig->conf); return 1; } diff --git a/src/e_mod_main.h b/src/e_mod_main.h index 6fca7ef..2f552f4 100644 --- a/src/e_mod_main.h +++ b/src/e_mod_main.h @@ -37,6 +37,8 @@ typedef struct _E_Gesture_Event_Swipe E_Gesture_Event_Swipe; typedef struct _E_Gesture_Event_Swipe_Finger E_Gesture_Event_Swipe_Finger; typedef struct _E_Gesture_Event_Swipe_Finger_Direction E_Gesture_Event_Swipe_Finger_Direction; typedef struct _E_Gesture_Grabbed_Client E_Gesture_Grabbed_Client; +typedef struct _E_Gesture_Conf_Edd E_Gesture_Conf_Edd; +typedef struct _E_Gesture_Config_Data E_Gesture_Config_Data; typedef struct _Coords Coords; @@ -59,6 +61,29 @@ struct _Coords int x, y; }; +struct _E_Gesture_Conf_Edd +{ + char *key_device_name; + struct + { + double time_done; + double time_begin; + int area_offset; + int min_length; + int max_length; + int compose_key; + int back_key; + Eina_Bool default_enable_back; + } swipe; +}; + +struct _E_Gesture_Config_Data +{ + E_Module *module; + E_Config_DD *conf_edd; + E_Gesture_Conf_Edd *conf; +}; + struct _E_Gesture_Event_Swipe_Finger_Direction { struct wl_client *client; @@ -106,6 +131,8 @@ struct _E_Gesture_Event struct _E_Gesture { struct wl_global *global; + E_Gesture_Config_Data *config; + Eina_Bool enable; Ecore_Event_Filter *ef_handler; Eina_List *handlers; @@ -136,6 +163,10 @@ E_API int e_modapi_save(E_Module *m); Eina_Bool e_gesture_process_events(void *event, int type); int e_gesture_type_convert(uint32_t type); +/* Config */ +void e_gesture_conf_init(E_Gesture_Config_Data *gconfig); +void e_gesture_conf_deinit(E_Gesture_Config_Data *gconfig); + /* Device control */ void e_gesture_device_shutdown(void); Eina_Bool e_gesture_device_add(Ecore_Event_Device_Info *ev); -- 2.7.4