summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <marcel-hollerbach@t-online.de>2015-12-18 16:39:36 +0100
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2015-12-18 16:44:56 +0100
commitaffee1ec099bc61b45b0073717d8cd930cb32891 (patch)
treeef3e09e7afe1e6536b108c940e51dd41855e5ee0
parentf129e78b203436aebd9858d62734cc2d0d9e8134 (diff)
elm: Add new key bindings infrastucturedevs/bu5hm4n/key_bindings
With the 2 new calls widgets can add keybindings. The config now supports to convert the given config key bindngs struct to a new generel key binding struct. With this infra the keybindings are not depending anymore on the elm_widget_type_get string. ref T2891
-rw-r--r--src/lib/elm_config.c70
-rw-r--r--src/lib/elm_general.eot17
-rw-r--r--src/lib/elm_priv.h3
-rw-r--r--src/lib/elm_widget.c65
-rw-r--r--src/lib/elm_widget.eo20
5 files changed, 174 insertions, 1 deletions
diff --git a/src/lib/elm_config.c b/src/lib/elm_config.c
index 29ef12de6..2c403a210 100644
--- a/src/lib/elm_config.c
+++ b/src/lib/elm_config.c
@@ -2174,6 +2174,76 @@ _elm_config_modifier_check(const Evas_Modifier *m,
2174 return EINA_TRUE; 2174 return EINA_TRUE;
2175} 2175}
2176 2176
2177static Eina_List*
2178_mods_copy(Eina_List *mods)
2179{
2180 Eina_List *l, *result = NULL;
2181 Elm_Config_Binding_Modifier *mod;
2182
2183 EINA_LIST_FOREACH(mods, l, mod) {
2184 Elm_Key_Binding_Modifier *result_mod;
2185
2186 result_mod = calloc(1, sizeof(Elm_Key_Binding_Modifier));
2187
2188 result_mod->mod = mod->mod;
2189 result_mod->flag = mod->flag;
2190
2191 result = eina_list_append(result, result_mod);
2192 }
2193 return result;
2194}
2195
2196static void
2197_mods_free(Eina_List *lst)
2198{
2199 Elm_Key_Binding_Modifier *result_mod;
2200
2201 EINA_LIST_FREE(lst, result_mod)
2202 free(result_mod);
2203
2204}
2205
2206Eina_List*
2207_elm_config_config_to_key_bindings(const char *name)
2208{
2209 Elm_Config_Binding_Key *binding;
2210 Eina_List *binding_list, *l, *result = NULL;
2211
2212 binding_list = eina_hash_find(_elm_key_bindings, name);
2213
2214 if (!binding_list) return NULL;
2215
2216 EINA_LIST_FOREACH(binding_list, l, binding)
2217 {
2218 Elm_Key_Binding *key;
2219
2220 key = calloc(1, sizeof(Elm_Key_Binding));
2221 key->key = eina_stringshare_ref(binding->key);
2222 key->action = eina_stringshare_ref(binding->action);
2223 key->params = eina_stringshare_ref(binding->params);
2224 key->mods = _mods_copy(binding->modifiers);
2225 printf("%s %s %s\n", key->params, key->action, key->key);
2226 result = eina_list_append(result, key);
2227 }
2228
2229 return result;
2230}
2231
2232void
2233_elm_config_key_bindings_free(Eina_List *bindings)
2234{
2235 Elm_Key_Binding *key;
2236
2237 EINA_LIST_FREE(bindings, key)
2238 {
2239 eina_stringshare_del(key->key);
2240 eina_stringshare_del(key->action);
2241 eina_stringshare_del(key->params);
2242 _mods_free(key->mods);
2243 free(key);
2244 }
2245}
2246
2177Eina_Bool 2247Eina_Bool
2178_elm_config_key_binding_call(Evas_Object *obj, 2248_elm_config_key_binding_call(Evas_Object *obj,
2179 const Evas_Event_Key_Down *ev, 2249 const Evas_Event_Key_Down *ev,
diff --git a/src/lib/elm_general.eot b/src/lib/elm_general.eot
index 6388b30fc..936f790de 100644
--- a/src/lib/elm_general.eot
+++ b/src/lib/elm_general.eot
@@ -119,3 +119,20 @@ enum Elm.Focus_Direction
119 left, [[ left direction ]] 119 left, [[ left direction ]]
120} 120}
121 121
122struct Elm.Key_Binding
123{
124 [[Hold information about a key binding.
125 If the given key is pressed with the given mods,
126 the action will be executed with the given params.
127 ]]
128 key : const(char)*;
129 action : const(char)*;
130 params : const(char)*;
131 mods : list<Elm.Key_Binding_Modifier*>*;
132}
133
134struct Elm.Key_Binding_Modifier
135{
136 mod : const(char)*;
137 flag : ubyte;
138} \ No newline at end of file
diff --git a/src/lib/elm_priv.h b/src/lib/elm_priv.h
index be92f1513..aab9c4f96 100644
--- a/src/lib/elm_priv.h
+++ b/src/lib/elm_priv.h
@@ -459,6 +459,9 @@ void _elm_config_color_overlay_apply(void);
459Eina_Bool _elm_config_access_get(void); 459Eina_Bool _elm_config_access_get(void);
460void _elm_config_access_set(Eina_Bool is_access); 460void _elm_config_access_set(Eina_Bool is_access);
461 461
462Eina_List* _elm_config_config_to_key_bindings(const char *name);
463void _elm_config_key_bindings_free(Eina_List *bindings);
464
462Eina_Bool _elm_config_key_binding_call(Evas_Object *obj, 465Eina_Bool _elm_config_key_binding_call(Evas_Object *obj,
463 const Evas_Event_Key_Down *ev, 466 const Evas_Event_Key_Down *ev,
464 const Elm_Action *actions); 467 const Elm_Action *actions);
diff --git a/src/lib/elm_widget.c b/src/lib/elm_widget.c
index c850e4656..1eb3a3d7f 100644
--- a/src/lib/elm_widget.c
+++ b/src/lib/elm_widget.c
@@ -5724,6 +5724,12 @@ elm_widget_tree_dot_dump(const Evas_Object *top,
5724#endif 5724#endif
5725} 5725}
5726 5726
5727EOLIAN static Eina_List *
5728_elm_widget_key_bindings_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *pd EINA_UNUSED) {
5729 return NULL;
5730}
5731
5732
5727EOLIAN static Eo * 5733EOLIAN static Eo *
5728_elm_widget_eo_base_constructor(Eo *obj, Elm_Widget_Smart_Data *sd EINA_UNUSED) 5734_elm_widget_eo_base_constructor(Eo *obj, Elm_Widget_Smart_Data *sd EINA_UNUSED)
5729{ 5735{
@@ -5794,9 +5800,66 @@ _elm_widget_disable(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
5794 return EINA_FALSE; 5800 return EINA_FALSE;
5795} 5801}
5796 5802
5803static Eina_Bool
5804_modifier_check(const Evas_Modifier *m,
5805 Eina_List *mod_list)
5806{
5807 Eina_List *l;
5808 Elm_Key_Binding_Modifier *mod;
5809 EINA_LIST_FOREACH(mod_list, l, mod)
5810 {
5811 if ((evas_key_modifier_is_set(m, mod->mod)) ^ (mod->flag))
5812 return EINA_FALSE;
5813 }
5814 return EINA_TRUE;
5815}
5816
5817Eina_Bool
5818_elm_widget_key_binding_callback(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *pd EINA_UNUSED, const char *action EINA_UNUSED, const char *params EINA_UNUSED)
5819{
5820 return EINA_FALSE;
5821}
5822
5823static Eina_Bool
5824_key_bindings_execute(Evas_Object *obj, Evas_Event_Key_Down *ev)
5825{
5826 Elm_Key_Binding *binding;
5827 Eina_List *node, *key_bindings;
5828
5829 eo_do(obj, key_bindings = elm_obj_widget_key_bindings_get());
5830
5831 EINA_LIST_FOREACH(key_bindings, node, binding)
5832 {
5833 printf("binding %p %p\n",binding, binding->mods);
5834 if (binding->key && (!strcmp(binding->key, ev->key)) &&
5835 _modifier_check(ev->modifiers, binding->mods))
5836 {
5837 Eina_Bool ret;
5838 eo_do_ret(obj, ret, elm_obj_widget_key_binding_callback(binding->action, binding->params));
5839 if (ret) return EINA_TRUE;
5840 }
5841 }
5842
5843 return EINA_FALSE;
5844}
5845
5797EOLIAN static Eina_Bool 5846EOLIAN static Eina_Bool
5798_elm_widget_event(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Evas_Object *source EINA_UNUSED, Evas_Callback_Type type EINA_UNUSED, void *event_info EINA_UNUSED) 5847_elm_widget_event(Eo *obj, Elm_Widget_Smart_Data *_pd, Evas_Object *source EINA_UNUSED, Evas_Callback_Type type EINA_UNUSED, void *event_info EINA_UNUSED)
5799{ 5848{
5849 //check if there are key bindings for this widget
5850 if (_pd->disabled) return EINA_FALSE;
5851
5852 Evas_Event_Key_Down *ev = event_info;
5853 if ((type == EVAS_CALLBACK_KEY_DOWN) &&
5854 !(ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD))
5855 {
5856 if (_key_bindings_execute(obj, event_info))
5857 {
5858 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
5859 return EINA_TRUE;
5860 }
5861 }
5862
5800 return EINA_FALSE; 5863 return EINA_FALSE;
5801} 5864}
5802 5865
diff --git a/src/lib/elm_widget.eo b/src/lib/elm_widget.eo
index 35bed55f1..e88444734 100644
--- a/src/lib/elm_widget.eo
+++ b/src/lib/elm_widget.eo
@@ -556,6 +556,26 @@ abstract Elm.Widget (Evas.Object_Smart, Elm_Interface_Atspi_Accessible, Elm_Inte
556 @in event_flags: Evas_Event_Flags *; 556 @in event_flags: Evas_Event_Flags *;
557 } 557 }
558 } 558 }
559 @property key_bindings {
560 [[Returns a list of keybindings.
561 The list is used to resolve a keyboard event to actions and paramters.
562 key_binding_callback will be called later.
563 ]]
564 get {
565
566 }
567 values {
568 key_bindings : list<Elm.Key_Binding*>*;
569 }
570 }
571 key_binding_callback {
572 [[Called when a key binding action is executed]]
573 params {
574 action : const(char)*; [[Name of the action which is executed]]
575 params : const(char)*; [[The params which where passed to the key press]]
576 }
577 return : bool;
578 }
559 signal_callback_add { 579 signal_callback_add {
560 params { 580 params {
561 @in emission: const(char)*; 581 @in emission: const(char)*;