summaryrefslogtreecommitdiff
path: root/src/bin/keyin.c
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2014-09-30 22:07:28 +0200
committerBoris Faure <billiob@gmail.com>2014-09-30 22:07:28 +0200
commit6f27cdc3ece421ebbfdae83e60df19bc4d356c3d (patch)
treecd9e5f34630a395c97767a500812d1f69f98d1e4 /src/bin/keyin.c
parente69fe704fb769e7461d15bde66d6cbc726c5c895 (diff)
key bindings now support the win key
Diffstat (limited to 'src/bin/keyin.c')
-rw-r--r--src/bin/keyin.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/bin/keyin.c b/src/bin/keyin.c
index ade4a65..e48cfe8 100644
--- a/src/bin/keyin.c
+++ b/src/bin/keyin.c
@@ -41,6 +41,7 @@ struct _Key_Binding
41 uint16_t ctrl : 1; 41 uint16_t ctrl : 1;
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 45
45 uint16_t len; 46 uint16_t len;
46 47
@@ -193,7 +194,7 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
193 194
194static Key_Binding * 195static Key_Binding *
195key_binding_lookup(const char *keyname, 196key_binding_lookup(const char *keyname,
196 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift) 197 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win)
197{ 198{
198 Key_Binding *kb; 199 Key_Binding *kb;
199 size_t len = strlen(keyname); 200 size_t len = strlen(keyname);
@@ -205,6 +206,7 @@ key_binding_lookup(const char *keyname,
205 kb->ctrl = ctrl; 206 kb->ctrl = ctrl;
206 kb->alt = alt; 207 kb->alt = alt;
207 kb->shift = shift; 208 kb->shift = shift;
209 kb->win = win;
208 kb->len = len; 210 kb->len = len;
209 kb->keyname = alloca(sizeof(char) * len + 1); 211 kb->keyname = alloca(sizeof(char) * len + 1);
210 strncpy((char *)kb->keyname, keyname, kb->len + 1); 212 strncpy((char *)kb->keyname, keyname, kb->len + 1);
@@ -214,11 +216,11 @@ key_binding_lookup(const char *keyname,
214 216
215Eina_Bool 217Eina_Bool
216keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev, 218keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev,
217 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift) 219 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win)
218{ 220{
219 Key_Binding *kb; 221 Key_Binding *kb;
220 222
221 kb = key_binding_lookup(ev->keyname, ctrl, alt, shift); 223 kb = key_binding_lookup(ev->keyname, ctrl, alt, shift, win);
222 if (kb) 224 if (kb)
223 { 225 {
224 if (kb->cb(ty->obj)) 226 if (kb->cb(ty->obj))
@@ -605,8 +607,8 @@ _key_binding_key_cmp(const void *key1, int key1_length,
605 return 1; 607 return 1;
606 else 608 else
607 { 609 {
608 unsigned int m1 = (kb1->ctrl << 2) | (kb1->alt << 1) | kb1->shift, 610 unsigned int m1 = (kb1->win << 3) | (kb1->ctrl << 2) | (kb1->alt << 1) | kb1->shift,
609 m2 = (kb2->ctrl << 2) | (kb2->alt << 1) | kb2->shift; 611 m2 = (kb2->win << 3) | (kb2->ctrl << 2) | (kb2->alt << 1) | kb2->shift;
610 if (m1 < m2) 612 if (m1 < m2)
611 return -1; 613 return -1;
612 else if (m1 > m2) 614 else if (m1 > m2)
@@ -623,15 +625,15 @@ _key_binding_key_hash(const void *key, int key_length)
623 int hash; 625 int hash;
624 626
625 hash = eina_hash_djb2(key, key_length); 627 hash = eina_hash_djb2(key, key_length);
626 hash &= 0x1fffffff; 628 hash &= 0x0fffffff;
627 hash |= (kb->ctrl << 31) | (kb->alt << 30) | (kb->shift << 29); 629 hash |= (kb->win << 31) | (kb->ctrl << 30) | (kb->alt << 29) | (kb->shift << 28);
628 return hash; 630 return hash;
629} 631}
630 632
631 633
632static Key_Binding * 634static Key_Binding *
633_key_binding_new(const char *keyname, 635_key_binding_new(const char *keyname,
634 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, 636 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win,
635 Key_Binding_Cb cb) 637 Key_Binding_Cb cb)
636{ 638{
637 Key_Binding *kb; 639 Key_Binding *kb;
@@ -644,6 +646,7 @@ _key_binding_new(const char *keyname,
644 kb->ctrl = ctrl; 646 kb->ctrl = ctrl;
645 kb->alt = alt; 647 kb->alt = alt;
646 kb->shift = shift; 648 kb->shift = shift;
649 kb->win = win;
647 kb->len = len; 650 kb->len = len;
648 kb->keyname = eina_stringshare_add(keyname); 651 kb->keyname = eina_stringshare_add(keyname);
649 kb->cb = cb; 652 kb->cb = cb;
@@ -672,7 +675,7 @@ keyin_add_config(Config_Keys *key)
672 { 675 {
673 Key_Binding *kb; 676 Key_Binding *kb;
674 kb = _key_binding_new(key->keyname, key->ctrl, key->alt, 677 kb = _key_binding_new(key->keyname, key->ctrl, key->alt,
675 key->shift, action->cb); 678 key->shift, key->win, action->cb);
676 if (!kb) return -1; 679 if (!kb) return -1;
677 if (eina_hash_find(_key_bindings, kb) || 680 if (eina_hash_find(_key_bindings, kb) ||
678 (!eina_hash_direct_add(_key_bindings, kb, kb))) 681 (!eina_hash_direct_add(_key_bindings, kb, kb)))
@@ -690,7 +693,7 @@ keyin_remove_config(Config_Keys *key)
690{ 693{
691 Key_Binding *kb; 694 Key_Binding *kb;
692 695
693 kb = key_binding_lookup(key->keyname, key->ctrl, key->alt, key->shift); 696 kb = key_binding_lookup(key->keyname, key->ctrl, key->alt, key->shift, key->win);
694 if (kb) 697 if (kb)
695 eina_hash_del_by_key(_key_bindings, kb); 698 eina_hash_del_by_key(_key_bindings, kb);
696 return 0; 699 return 0;