summaryrefslogtreecommitdiff
path: root/src/bin/keyin.c
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2014-08-24 20:47:57 +0200
committerBoris Faure <billiob@gmail.com>2014-09-02 20:42:45 +0200
commit772843d5681b27f0b1c2266dc0424564497123b2 (patch)
tree95ea14f1415d326cd54b38ce14556c44c8df431d /src/bin/keyin.c
parent57b06067a88c5f98d5e3d1bd39414488fc9c2a1a (diff)
add ui to configure key bindings
Diffstat (limited to 'src/bin/keyin.c')
-rw-r--r--src/bin/keyin.c60
1 files changed, 44 insertions, 16 deletions
diff --git a/src/bin/keyin.c b/src/bin/keyin.c
index 5edfb28..f81fbc4 100644
--- a/src/bin/keyin.c
+++ b/src/bin/keyin.c
@@ -551,11 +551,11 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
551} 551}
552 552
553static Key_Binding * 553static Key_Binding *
554key_binding_lookup(const Evas_Event_Key_Down *ev, 554key_binding_lookup(const char *keyname,
555 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift) 555 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift)
556{ 556{
557 Key_Binding *kb; 557 Key_Binding *kb;
558 size_t len = strlen(ev->keyname); 558 size_t len = strlen(keyname);
559 559
560 if (len > UINT16_MAX) return NULL; 560 if (len > UINT16_MAX) return NULL;
561 561
@@ -566,7 +566,7 @@ key_binding_lookup(const Evas_Event_Key_Down *ev,
566 kb->shift = shift; 566 kb->shift = shift;
567 kb->len = len; 567 kb->len = len;
568 kb->keyname = alloca(sizeof(char) * len + 1); 568 kb->keyname = alloca(sizeof(char) * len + 1);
569 strncpy((char *)kb->keyname, ev->keyname, kb->len + 1); 569 strncpy((char *)kb->keyname, keyname, kb->len + 1);
570 570
571 return eina_hash_find(_key_bindings, kb); 571 return eina_hash_find(_key_bindings, kb);
572} 572}
@@ -577,7 +577,7 @@ keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev,
577{ 577{
578 Key_Binding *kb; 578 Key_Binding *kb;
579 579
580 kb = key_binding_lookup(ev, ctrl, alt, shift); 580 kb = key_binding_lookup(ev->keyname, ctrl, alt, shift);
581 if (kb) 581 if (kb)
582 { 582 {
583 if (kb->cb(ty->obj)) 583 if (kb->cb(ty->obj))
@@ -1006,9 +1006,45 @@ _key_binding_free(void *data)
1006 free(kb); 1006 free(kb);
1007} 1007}
1008 1008
1009int key_bindings_load(Config *config) 1009int
1010keyin_add_config(Config_Keys *key)
1011{
1012 Shortcut_Action *action = _actions;
1013
1014 while (action->action && strcmp(action->action, key->cb))
1015 action++;
1016
1017 if (action->action)
1018 {
1019 Key_Binding *kb;
1020 kb = _key_binding_new(key->keyname, key->ctrl, key->alt,
1021 key->shift, action->cb);
1022 if (!kb) return -1;
1023 if (eina_hash_find(_key_bindings, kb) ||
1024 (!eina_hash_direct_add(_key_bindings, kb, kb)))
1025 {
1026 _key_binding_free(kb);
1027 return -1;
1028 }
1029 return 0;
1030 }
1031 return -1;
1032}
1033
1034int
1035keyin_remove_config(Config_Keys *key)
1010{ 1036{
1011 Key_Binding *kb; 1037 Key_Binding *kb;
1038
1039
1040 kb = key_binding_lookup(key->keyname, key->ctrl, key->alt, key->shift);
1041 if (kb)
1042 eina_hash_del_by_key(_key_bindings, kb);
1043 return 0;
1044}
1045
1046int key_bindings_load(Config *config)
1047{
1012 Shortcut_Action *action = _actions; 1048 Shortcut_Action *action = _actions;
1013 Config_Keys *key; 1049 Config_Keys *key;
1014 Eina_List *l; 1050 Eina_List *l;
@@ -1036,17 +1072,9 @@ int key_bindings_load(Config *config)
1036 1072
1037 EINA_LIST_FOREACH(config->keys, l, key) 1073 EINA_LIST_FOREACH(config->keys, l, key)
1038 { 1074 {
1039 action = _actions; 1075 int res = keyin_add_config(key);
1040 while (action->action && strcmp(action->action, key->cb)) 1076 if (res != 0)
1041 action++; 1077 return res;
1042
1043 if (action->action)
1044 {
1045 kb = _key_binding_new(key->keyname, key->ctrl, key->alt,
1046 key->shift, action->cb);
1047 if (!kb) return -1;
1048 if (!eina_hash_direct_add(_key_bindings, kb, kb)) return -1;
1049 }
1050 } 1078 }
1051 1079
1052 return 0; 1080 return 0;