summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorJaeun Choi <jaeun12.choi@samsung.com>2014-02-28 10:36:15 +0900
committerChunEon Park <hermet@hermet.pe.kr>2014-02-28 10:47:03 +0900
commit7d627d90f7f1e9aa93fe40400e04e0f2f414b041 (patch)
treedc0e52d05014b228009399cb3787e54bc2235df3 /src/lib
parent8a8c4c08c035389f445d9faee27257045c1c8673 (diff)
elementary key binding feature implementation
Summary: This patch implements elementary key binding feature. Test Plan: None Reviewers: Hermet, raster CC: seoz Differential Revision: https://phab.enlightenment.org/D506 Conflicts: src/lib/elm_config.c
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/elm_config.c133
-rw-r--r--src/lib/elm_panel.c20
-rw-r--r--src/lib/elm_priv.h23
-rw-r--r--src/lib/elm_widget.h8
4 files changed, 177 insertions, 7 deletions
diff --git a/src/lib/elm_config.c b/src/lib/elm_config.c
index 7a93b904c..daa67aab7 100644
--- a/src/lib/elm_config.c
+++ b/src/lib/elm_config.c
@@ -19,12 +19,16 @@ static Eet_Data_Descriptor *_config_font_overlay_edd = NULL;
19static Eet_Data_Descriptor *_config_color_edd = NULL; 19static Eet_Data_Descriptor *_config_color_edd = NULL;
20static Eet_Data_Descriptor *_config_color_palette_edd = NULL; 20static Eet_Data_Descriptor *_config_color_palette_edd = NULL;
21static Eet_Data_Descriptor *_config_color_overlay_edd = NULL; 21static Eet_Data_Descriptor *_config_color_overlay_edd = NULL;
22static Eet_Data_Descriptor *_config_bindings_widget_edd = NULL;
23static Eet_Data_Descriptor *_config_binding_key_edd = NULL;
22const char *_elm_preferred_engine = NULL; 24const char *_elm_preferred_engine = NULL;
23Eina_List *_font_overlays_del = NULL; 25Eina_List *_font_overlays_del = NULL;
24Eina_List *_color_overlays_del = NULL; 26Eina_List *_color_overlays_del = NULL;
25 27
26static Ecore_Poller *_elm_cache_flush_poller = NULL; 28static Ecore_Poller *_elm_cache_flush_poller = NULL;
27 29
30Eina_Hash *_elm_key_bindings = NULL;
31
28const char *_elm_engines[] = { 32const char *_elm_engines[] = {
29 "software_x11", 33 "software_x11",
30 "fb", 34 "fb",
@@ -359,6 +363,31 @@ _desc_init(void)
359 return; 363 return;
360 } 364 }
361 365
366 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Config_Bindings_Widget);
367 eddc.func.str_direct_alloc = NULL;
368 eddc.func.str_direct_free = NULL;
369
370 _config_bindings_widget_edd = eet_data_descriptor_stream_new(&eddc);
371 if (!_config_bindings_widget_edd)
372 {
373 ERR("EEEK! eet_data_descriptor_stream_new() failed.");
374 eet_data_descriptor_free(_config_edd);
375 return;
376 }
377
378 memset(&eddc, 0, sizeof(eddc)); /* just in case... */
379 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Config_Binding_Key);
380 eddc.func.str_direct_alloc = NULL;
381 eddc.func.str_direct_free = NULL;
382
383 _config_binding_key_edd = eet_data_descriptor_stream_new(&eddc);
384 if (!_config_binding_key_edd)
385 {
386 ERR("EEEK! eet_data_descriptor_stream_new() failed.");
387 eet_data_descriptor_free(_config_edd);
388 return;
389 }
390
362#define T_INT EET_T_INT 391#define T_INT EET_T_INT
363#define T_DOUBLE EET_T_DOUBLE 392#define T_DOUBLE EET_T_DOUBLE
364#define T_STRING EET_T_STRING 393#define T_STRING EET_T_STRING
@@ -406,6 +435,24 @@ _desc_init(void)
406#undef T 435#undef T
407#undef D 436#undef D
408 437
438#define T Elm_Config_Bindings_Widget
439#define D _config_bindings_widget_edd
440 ELM_CONFIG_VAL(D, T, name, EET_T_STRING);
441 ELM_CONFIG_LIST(D, T, key_bindings, _config_binding_key_edd);
442#undef T
443#undef D
444
445#define T Elm_Config_Binding_Key
446#define D _config_binding_key_edd
447 ELM_CONFIG_VAL(D, T, context, EET_T_INT);
448 ELM_CONFIG_VAL(D, T, modifiers, EET_T_STRING);
449 ELM_CONFIG_VAL(D, T, key, EET_T_STRING);
450 ELM_CONFIG_VAL(D, T, action, EET_T_STRING);
451 ELM_CONFIG_VAL(D, T, params, EET_T_STRING);
452 ELM_CONFIG_VAL(D, T, any_mod, EET_T_UCHAR);
453#undef T
454#undef D
455
409#define T Elm_Config 456#define T Elm_Config
410#define D _config_edd 457#define D _config_edd
411 ELM_CONFIG_VAL(D, T, config_version, T_INT); 458 ELM_CONFIG_VAL(D, T, config_version, T_INT);
@@ -510,6 +557,7 @@ _desc_init(void)
510 ELM_CONFIG_VAL(D, T, audio_mute_input, T_UCHAR); 557 ELM_CONFIG_VAL(D, T, audio_mute_input, T_UCHAR);
511 ELM_CONFIG_VAL(D, T, audio_mute_alert, T_UCHAR); 558 ELM_CONFIG_VAL(D, T, audio_mute_alert, T_UCHAR);
512 ELM_CONFIG_VAL(D, T, audio_mute_all, T_UCHAR); 559 ELM_CONFIG_VAL(D, T, audio_mute_all, T_UCHAR);
560 ELM_CONFIG_LIST(D, T, bindings, _config_bindings_widget_edd);
513#undef T 561#undef T
514#undef D 562#undef D
515#undef T_INT 563#undef T_INT
@@ -550,6 +598,18 @@ _desc_shutdown(void)
550 eet_data_descriptor_free(_config_color_overlay_edd); 598 eet_data_descriptor_free(_config_color_overlay_edd);
551 _config_color_overlay_edd = NULL; 599 _config_color_overlay_edd = NULL;
552 } 600 }
601
602 if (_config_bindings_widget_edd)
603 {
604 eet_data_descriptor_free(_config_bindings_widget_edd);
605 _config_bindings_widget_edd = NULL;
606 }
607
608 if (_config_binding_key_edd)
609 {
610 eet_data_descriptor_free(_config_binding_key_edd);
611 _config_binding_key_edd = NULL;
612 }
553} 613}
554 614
555static int 615static int
@@ -1208,6 +1268,8 @@ _config_free(Elm_Config *cfg)
1208 Elm_Custom_Palette *palette; 1268 Elm_Custom_Palette *palette;
1209 Elm_Color_RGBA *color; 1269 Elm_Color_RGBA *color;
1210 char *color_class; 1270 char *color_class;
1271 Elm_Config_Bindings_Widget *wb;
1272 Elm_Config_Binding_Key *kb;
1211 1273
1212 if (!cfg) return; 1274 if (!cfg) return;
1213 EINA_LIST_FREE(cfg->font_dirs, fontdir) 1275 EINA_LIST_FREE(cfg->font_dirs, fontdir)
@@ -1234,6 +1296,19 @@ _config_free(Elm_Config *cfg)
1234 EINA_LIST_FREE(palette->color_list, color) free(color); 1296 EINA_LIST_FREE(palette->color_list, color) free(color);
1235 free(palette); 1297 free(palette);
1236 } 1298 }
1299 EINA_LIST_FREE(cfg->bindings, wb)
1300 {
1301 eina_stringshare_del(wb->name);
1302 EINA_LIST_FREE(wb->key_bindings, kb)
1303 {
1304 eina_stringshare_del(kb->modifiers);
1305 eina_stringshare_del(kb->key);
1306 eina_stringshare_del(kb->action);
1307 eina_stringshare_del(kb->params);
1308 free(kb);
1309 }
1310 free(wb);
1311 }
1237 eina_stringshare_del(cfg->theme); 1312 eina_stringshare_del(cfg->theme);
1238 eina_stringshare_del(cfg->modules); 1313 eina_stringshare_del(cfg->modules);
1239 eina_stringshare_del(cfg->indicator_service_0); 1314 eina_stringshare_del(cfg->indicator_service_0);
@@ -2041,6 +2116,58 @@ _env_get(void)
2041 if (s) _elm_config->magnifier_scale = _elm_atof(s); 2116 if (s) _elm_config->magnifier_scale = _elm_atof(s);
2042} 2117}
2043 2118
2119void
2120_elm_config_key_binding_hash(void)
2121{
2122 Elm_Config_Bindings_Widget *wb;
2123 Eina_List *l;
2124
2125 if (_elm_key_bindings)
2126 eina_hash_free(_elm_key_bindings);
2127
2128 _elm_key_bindings = eina_hash_string_superfast_new(NULL);
2129 EINA_LIST_FOREACH(_elm_config->bindings, l, wb)
2130 {
2131 eina_hash_add(_elm_key_bindings, wb->name, wb->key_bindings);
2132 }
2133}
2134
2135Eina_Bool
2136_elm_config_key_binding_call(Evas_Object *obj,
2137 const Evas_Event_Key_Down *ev,
2138 const Elm_Action *actions)
2139{
2140 Elm_Config_Binding_Key *binding;
2141 Eina_List *binding_list, *l;
2142 int i = 0;
2143
2144 binding_list = eina_hash_find(_elm_key_bindings, elm_widget_type_get(obj));
2145
2146 if (binding_list)
2147 {
2148 EINA_LIST_FOREACH(binding_list, l, binding)
2149 {
2150 if (binding->key && (!strcmp(binding->key, ev->keyname))
2151 && ((evas_key_modifier_is_set
2152 (ev->modifiers, binding->modifiers)
2153 || (binding->any_mod))))
2154 {
2155 while (actions[i].name)
2156 {
2157 if (!strcmp(binding->action, actions[i].name))
2158 {
2159 actions[i].func(obj, binding->params);
2160 return EINA_TRUE;
2161 }
2162 i++;
2163 }
2164 break;
2165 }
2166 }
2167 }
2168 return EINA_FALSE;
2169}
2170
2044EAPI Eina_Bool 2171EAPI Eina_Bool
2045elm_config_mirrored_get(void) 2172elm_config_mirrored_get(void)
2046{ 2173{
@@ -2884,6 +3011,7 @@ _elm_config_init(void)
2884 _elm_config_color_overlay_apply(); 3011 _elm_config_color_overlay_apply();
2885 _elm_recache(); 3012 _elm_recache();
2886 _elm_clouseau_reload(); 3013 _elm_clouseau_reload();
3014 _elm_config_key_binding_hash();
2887} 3015}
2888 3016
2889void 3017void
@@ -2987,6 +3115,7 @@ _elm_config_reload(void)
2987 _elm_rescale(); 3115 _elm_rescale();
2988 _elm_recache(); 3116 _elm_recache();
2989 _elm_clouseau_reload(); 3117 _elm_clouseau_reload();
3118 _elm_config_key_binding_hash();
2990 ecore_event_add(ELM_EVENT_CONFIG_ALL_CHANGED, NULL, NULL, NULL); 3119 ecore_event_add(ELM_EVENT_CONFIG_ALL_CHANGED, NULL, NULL, NULL);
2991} 3120}
2992 3121
@@ -3059,6 +3188,7 @@ _elm_config_profile_set(const char *profile)
3059 _elm_rescale(); 3188 _elm_rescale();
3060 _elm_recache(); 3189 _elm_recache();
3061 _elm_clouseau_reload(); 3190 _elm_clouseau_reload();
3191 _elm_config_key_binding_hash();
3062} 3192}
3063 3193
3064void 3194void
@@ -3084,4 +3214,7 @@ _elm_config_shutdown(void)
3084#endif 3214#endif
3085 3215
3086 _desc_shutdown(); 3216 _desc_shutdown();
3217
3218 if (_elm_key_bindings)
3219 eina_hash_free(_elm_key_bindings);
3087} 3220}
diff --git a/src/lib/elm_panel.c b/src/lib/elm_panel.c
index 060c82f52..a6d30720c 100644
--- a/src/lib/elm_panel.c
+++ b/src/lib/elm_panel.c
@@ -20,6 +20,13 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = {
20 {NULL, NULL} 20 {NULL, NULL}
21}; 21};
22 22
23void _key_action_toggle(Evas_Object *obj, const char *params);
24
25static const Elm_Action key_actions[] = {
26 {"toggle", _key_action_toggle},
27 {NULL, NULL}
28};
29
23static void 30static void
24_mirrored_set(Evas_Object *obj, 31_mirrored_set(Evas_Object *obj,
25 Eina_Bool rtl) 32 Eina_Bool rtl)
@@ -247,10 +254,14 @@ _panel_toggle(void *data EINA_UNUSED,
247 edje_object_message_signal_process(wd->resize_obj); 254 edje_object_message_signal_process(wd->resize_obj);
248} 255}
249 256
257void _key_action_toggle(Evas_Object *obj, const char *params EINA_UNUSED)
258{
259 _panel_toggle(NULL, obj, NULL, NULL);
260}
261
250static void 262static void
251_elm_panel_smart_event(Eo *obj, void *_pd EINA_UNUSED, va_list *list) 263_elm_panel_smart_event(Eo *obj, void *_pd EINA_UNUSED, va_list *list)
252{ 264{
253
254 Evas_Object *src = va_arg(*list, Evas_Object *); 265 Evas_Object *src = va_arg(*list, Evas_Object *);
255 Evas_Callback_Type type = va_arg(*list, Evas_Callback_Type); 266 Evas_Callback_Type type = va_arg(*list, Evas_Callback_Type);
256 Evas_Event_Key_Down *ev = va_arg(*list, void *); 267 Evas_Event_Key_Down *ev = va_arg(*list, void *);
@@ -263,12 +274,7 @@ _elm_panel_smart_event(Eo *obj, void *_pd EINA_UNUSED, va_list *list)
263 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; 274 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
264 if (src != obj) return; 275 if (src != obj) return;
265 276
266 if ((strcmp(ev->key, "Return")) && 277 _elm_config_key_binding_call(obj, ev, key_actions);
267 (strcmp(ev->key, "KP_Enter")) &&
268 (strcmp(ev->key, "space")))
269 return;
270
271 _panel_toggle(NULL, obj, NULL, NULL);
272 278
273 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; 279 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
274 if (ret) *ret = EINA_TRUE; 280 if (ret) *ret = EINA_TRUE;
diff --git a/src/lib/elm_priv.h b/src/lib/elm_priv.h
index 5d18a9f92..e1081e356 100644
--- a/src/lib/elm_priv.h
+++ b/src/lib/elm_priv.h
@@ -76,6 +76,8 @@
76typedef struct _Elm_Theme_Files Elm_Theme_Files; 76typedef struct _Elm_Theme_Files Elm_Theme_Files;
77typedef struct _Edje_Signal_Data Edje_Signal_Data; 77typedef struct _Edje_Signal_Data Edje_Signal_Data;
78typedef struct _Elm_Config Elm_Config; 78typedef struct _Elm_Config Elm_Config;
79typedef struct _Elm_Config_Bindings_Widget Elm_Config_Bindings_Widget;
80typedef struct _Elm_Config_Binding_Key Elm_Config_Binding_Key;
79typedef struct _Elm_Module Elm_Module; 81typedef struct _Elm_Module Elm_Module;
80typedef struct _Elm_Datetime_Module_Data Elm_Datetime_Module_Data; 82typedef struct _Elm_Datetime_Module_Data Elm_Datetime_Module_Data;
81 83
@@ -275,12 +277,29 @@ struct _Elm_Config
275 unsigned char audio_mute_input; 277 unsigned char audio_mute_input;
276 unsigned char audio_mute_alert; 278 unsigned char audio_mute_alert;
277 unsigned char audio_mute_all; 279 unsigned char audio_mute_all;
280 Eina_List *bindings;
278 281
279 /* Not part of the EET file */ 282 /* Not part of the EET file */
280 Eina_Bool is_mirrored : 1; 283 Eina_Bool is_mirrored : 1;
281 Eina_Bool translate : 1; 284 Eina_Bool translate : 1;
282}; 285};
283 286
287struct _Elm_Config_Bindings_Widget
288{
289 const char *name;
290 Eina_List *key_bindings;
291};
292
293struct _Elm_Config_Binding_Key
294{
295 int context;
296 const char *modifiers;
297 const char *key;
298 const char *action;
299 const char *params;
300 unsigned char any_mod;
301};
302
284struct _Elm_Module 303struct _Elm_Module
285{ 304{
286 int version; 305 int version;
@@ -421,6 +440,10 @@ void _elm_config_color_overlay_apply(void);
421Eina_Bool _elm_config_access_get(void); 440Eina_Bool _elm_config_access_get(void);
422void _elm_config_access_set(Eina_Bool is_access); 441void _elm_config_access_set(Eina_Bool is_access);
423 442
443Eina_Bool _elm_config_key_binding_call(Evas_Object *obj,
444 const Evas_Event_Key_Down *ev,
445 const Elm_Action *actions);
446
424Elm_Font_Properties *_elm_font_properties_get(Eina_Hash **font_hash, 447Elm_Font_Properties *_elm_font_properties_get(Eina_Hash **font_hash,
425 const char *font); 448 const char *font);
426Eina_Hash *_elm_font_available_hash_add(Eina_Hash *font_hash, 449Eina_Hash *_elm_font_available_hash_add(Eina_Hash *font_hash,
diff --git a/src/lib/elm_widget.h b/src/lib/elm_widget.h
index 137717990..a205ed952 100644
--- a/src/lib/elm_widget.h
+++ b/src/lib/elm_widget.h
@@ -456,6 +456,8 @@ typedef struct _Elm_Access_Info Elm_Access_Info;
456/**< accessibility info item */ 456/**< accessibility info item */
457typedef struct _Elm_Access_Item Elm_Access_Item; 457typedef struct _Elm_Access_Item Elm_Access_Item;
458 458
459typedef struct _Elm_Action Elm_Action;
460
459typedef void (*Elm_Widget_Text_Set_Cb)(void *data, const char *part, const char *text); 461typedef void (*Elm_Widget_Text_Set_Cb)(void *data, const char *part, const char *text);
460typedef void (*Elm_Widget_Content_Set_Cb)(void *data, const char *part, Evas_Object *content); 462typedef void (*Elm_Widget_Content_Set_Cb)(void *data, const char *part, Evas_Object *content);
461typedef const char *(*Elm_Widget_Text_Get_Cb)(const void *data, const char *part); 463typedef const char *(*Elm_Widget_Text_Get_Cb)(const void *data, const char *part);
@@ -503,6 +505,12 @@ struct _Elm_Access_Info
503 Evas_Object *prev; 505 Evas_Object *prev;
504}; 506};
505 507
508struct _Elm_Action
509{
510 const char *name;
511 void (*func)(Evas_Object *obj, const char *params);
512};
513
506void _elm_access_shutdown(); 514void _elm_access_shutdown();
507void _elm_access_mouse_event_enabled_set(Eina_Bool enabled); 515void _elm_access_mouse_event_enabled_set(Eina_Bool enabled);
508 516