summaryrefslogtreecommitdiff
path: root/src/bin/keyin.c
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2015-04-13 21:37:09 +0200
committerBoris Faure <billiob@gmail.com>2015-04-13 21:37:09 +0200
commit52ceae82b1f4cb33541573489439e11d960fb1fe (patch)
tree7b68026882afc3aa84967e145489d2ac4f4c3190 /src/bin/keyin.c
parent981f76c6e3b11c260bd637b4e111ae6ece0d59fb (diff)
add meta/hyper to key bindings. Closes T1985
Diffstat (limited to 'src/bin/keyin.c')
-rw-r--r--src/bin/keyin.c52
1 files changed, 32 insertions, 20 deletions
diff --git a/src/bin/keyin.c b/src/bin/keyin.c
index 50cb9ed..e61f210 100644
--- a/src/bin/keyin.c
+++ b/src/bin/keyin.c
@@ -42,6 +42,8 @@ struct _Key_Binding
42 uint16_t alt : 1; 42 uint16_t alt : 1;
43 uint16_t shift : 1; 43 uint16_t shift : 1;
44 uint16_t win : 1; 44 uint16_t win : 1;
45 uint16_t meta : 1;
46 uint16_t hyper : 1;
45 47
46 uint16_t len; 48 uint16_t len;
47 49
@@ -179,7 +181,8 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
179 181
180static Key_Binding * 182static Key_Binding *
181key_binding_lookup(const char *keyname, 183key_binding_lookup(const char *keyname,
182 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win) 184 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift,
185 Eina_Bool win, Eina_Bool meta, Eina_Bool hyper)
183{ 186{
184 Key_Binding *kb; 187 Key_Binding *kb;
185 size_t len = strlen(keyname); 188 size_t len = strlen(keyname);
@@ -192,6 +195,8 @@ key_binding_lookup(const char *keyname,
192 kb->alt = alt; 195 kb->alt = alt;
193 kb->shift = shift; 196 kb->shift = shift;
194 kb->win = win; 197 kb->win = win;
198 kb->meta = meta;
199 kb->hyper = hyper;
195 kb->len = len; 200 kb->len = len;
196 kb->keyname = alloca(sizeof(char) * len + 1); 201 kb->keyname = alloca(sizeof(char) * len + 1);
197 strncpy((char *)kb->keyname, keyname, kb->len + 1); 202 strncpy((char *)kb->keyname, keyname, kb->len + 1);
@@ -201,23 +206,18 @@ key_binding_lookup(const char *keyname,
201 206
202Eina_Bool 207Eina_Bool
203keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev, 208keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev,
204 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win) 209 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win,
210 Eina_Bool meta, Eina_Bool hyper)
205{ 211{
206 212
207 if (!evas_key_modifier_is_set(ev->modifiers, "Meta") && 213 Key_Binding *kb;
208 !evas_key_modifier_is_set(ev->modifiers, "Hyper") && 214 kb = key_binding_lookup(ev->keyname, ctrl, alt, shift, win, meta, hyper);
209 !evas_key_modifier_is_set(ev->modifiers, "AltGr") && 215 if (kb)
210 !evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift"))
211 { 216 {
212 Key_Binding *kb; 217 if (kb->cb(ty->obj))
213 kb = key_binding_lookup(ev->keyname, ctrl, alt, shift, win);
214 if (kb)
215 { 218 {
216 if (kb->cb(ty->obj)) 219 keyin_compose_seq_reset(khdl);
217 { 220 return EINA_TRUE;
218 keyin_compose_seq_reset(khdl);
219 return EINA_TRUE;
220 }
221 } 221 }
222 } 222 }
223 223
@@ -613,8 +613,10 @@ _key_binding_key_cmp(const void *key1, int key1_length,
613 return 1; 613 return 1;
614 else 614 else
615 { 615 {
616 unsigned int m1 = (kb1->win << 3) | (kb1->ctrl << 2) | (kb1->alt << 1) | kb1->shift, 616 unsigned int m1 = (kb1->hyper << 5) | (kb1->meta << 4) |
617 m2 = (kb2->win << 3) | (kb2->ctrl << 2) | (kb2->alt << 1) | kb2->shift; 617 (kb1->win << 3) | (kb1->ctrl << 2) | (kb1->alt << 1) | kb1->shift,
618 m2 = (kb2->hyper << 5) | (kb2->meta << 4) |
619 (kb2->win << 3) | (kb2->ctrl << 2) | (kb2->alt << 1) | kb2->shift;
618 if (m1 < m2) 620 if (m1 < m2)
619 return -1; 621 return -1;
620 else if (m1 > m2) 622 else if (m1 > m2)
@@ -631,8 +633,13 @@ _key_binding_key_hash(const void *key, int key_length)
631 int hash; 633 int hash;
632 634
633 hash = eina_hash_djb2(key, key_length); 635 hash = eina_hash_djb2(key, key_length);
634 hash &= 0x0fffffff; 636 hash &= 0x3ffffff;
635 hash |= (kb->win << 31) | (kb->ctrl << 30) | (kb->alt << 29) | (kb->shift << 28); 637 hash |= (kb->hyper << 31);
638 hash |= (kb->meta << 30);
639 hash |= (kb->win << 29);
640 hash |= (kb->ctrl << 28);
641 hash |= (kb->alt << 27);
642 hash |= (kb->shift << 26);
636 return hash; 643 return hash;
637} 644}
638 645
@@ -640,6 +647,7 @@ _key_binding_key_hash(const void *key, int key_length)
640static Key_Binding * 647static Key_Binding *
641_key_binding_new(const char *keyname, 648_key_binding_new(const char *keyname,
642 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win, 649 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win,
650 Eina_Bool meta, Eina_Bool hyper,
643 Key_Binding_Cb cb) 651 Key_Binding_Cb cb)
644{ 652{
645 Key_Binding *kb; 653 Key_Binding *kb;
@@ -653,6 +661,8 @@ _key_binding_new(const char *keyname,
653 kb->alt = alt; 661 kb->alt = alt;
654 kb->shift = shift; 662 kb->shift = shift;
655 kb->win = win; 663 kb->win = win;
664 kb->meta = meta;
665 kb->hyper = hyper;
656 kb->len = len; 666 kb->len = len;
657 kb->keyname = eina_stringshare_add(keyname); 667 kb->keyname = eina_stringshare_add(keyname);
658 kb->cb = cb; 668 kb->cb = cb;
@@ -681,7 +691,8 @@ keyin_add_config(Config_Keys *key)
681 { 691 {
682 Key_Binding *kb; 692 Key_Binding *kb;
683 kb = _key_binding_new(key->keyname, key->ctrl, key->alt, 693 kb = _key_binding_new(key->keyname, key->ctrl, key->alt,
684 key->shift, key->win, action->cb); 694 key->shift, key->win, key->meta, key->hyper,
695 action->cb);
685 if (!kb) 696 if (!kb)
686 return -1; 697 return -1;
687 if (eina_hash_find(_key_bindings, kb) || 698 if (eina_hash_find(_key_bindings, kb) ||
@@ -701,7 +712,8 @@ keyin_remove_config(Config_Keys *key)
701{ 712{
702 Key_Binding *kb; 713 Key_Binding *kb;
703 714
704 kb = key_binding_lookup(key->keyname, key->ctrl, key->alt, key->shift, key->win); 715 kb = key_binding_lookup(key->keyname, key->ctrl, key->alt, key->shift,
716 key->win, key->meta, key->hyper);
705 if (kb) 717 if (kb)
706 eina_hash_del_by_key(_key_bindings, kb); 718 eina_hash_del_by_key(_key_bindings, kb);
707 return 0; 719 return 0;