summaryrefslogtreecommitdiff
path: root/src
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
parent981f76c6e3b11c260bd637b4e111ae6ece0d59fb (diff)
add meta/hyper to key bindings. Closes T1985
Diffstat (limited to 'src')
-rw-r--r--src/bin/config.c4
-rw-r--r--src/bin/config.h2
-rw-r--r--src/bin/keyin.c52
-rw-r--r--src/bin/keyin.h6
-rw-r--r--src/bin/options_keys.c21
-rw-r--r--src/bin/termio.c15
6 files changed, 62 insertions, 38 deletions
diff --git a/src/bin/config.c b/src/bin/config.c
index aabdfee..5e42395 100644
--- a/src/bin/config.c
+++ b/src/bin/config.c
@@ -68,6 +68,10 @@ config_init(void)
68 EET_DATA_DESCRIPTOR_ADD_BASIC 68 EET_DATA_DESCRIPTOR_ADD_BASIC
69 (edd_keys, Config_Keys, "win", win, EET_T_UCHAR); 69 (edd_keys, Config_Keys, "win", win, EET_T_UCHAR);
70 EET_DATA_DESCRIPTOR_ADD_BASIC 70 EET_DATA_DESCRIPTOR_ADD_BASIC
71 (edd_keys, Config_Keys, "meta", meta, EET_T_UCHAR);
72 EET_DATA_DESCRIPTOR_ADD_BASIC
73 (edd_keys, Config_Keys, "hyper", hyper, EET_T_UCHAR);
74 EET_DATA_DESCRIPTOR_ADD_BASIC
71 (edd_keys, Config_Keys, "cb", cb, EET_T_STRING); 75 (edd_keys, Config_Keys, "cb", cb, EET_T_STRING);
72 76
73 EET_DATA_DESCRIPTOR_ADD_BASIC 77 EET_DATA_DESCRIPTOR_ADD_BASIC
diff --git a/src/bin/config.h b/src/bin/config.h
index b09f123..9cca90d 100644
--- a/src/bin/config.h
+++ b/src/bin/config.h
@@ -14,6 +14,8 @@ struct _Config_Keys
14 Eina_Bool alt; 14 Eina_Bool alt;
15 Eina_Bool shift; 15 Eina_Bool shift;
16 Eina_Bool win; 16 Eina_Bool win;
17 Eina_Bool meta;
18 Eina_Bool hyper;
17 const char *cb; 19 const char *cb;
18}; 20};
19/* TODO: separate config per terminal (tab, window) and global. */ 21/* TODO: separate config per terminal (tab, window) and global. */
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;
diff --git a/src/bin/keyin.h b/src/bin/keyin.h
index ef5fc0e..9687381 100644
--- a/src/bin/keyin.h
+++ b/src/bin/keyin.h
@@ -13,8 +13,10 @@ struct _Keys_Handler
13 13
14void keyin_compose_seq_reset(Keys_Handler *khdl); 14void keyin_compose_seq_reset(Keys_Handler *khdl);
15Eina_Bool key_is_modifier(const char *key); 15Eina_Bool key_is_modifier(const char *key);
16Eina_Bool keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev, 16Eina_Bool
17 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win); 17keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev,
18 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win,
19 Eina_Bool meta, Eina_Bool hyper);
18 20
19void keyin_handle_up(Keys_Handler *khdl, Evas_Event_Key_Up *ev); 21void keyin_handle_up(Keys_Handler *khdl, Evas_Event_Key_Up *ev);
20 22
diff --git a/src/bin/options_keys.c b/src/bin/options_keys.c
index cee8cff..95ca85d 100644
--- a/src/bin/options_keys.c
+++ b/src/bin/options_keys.c
@@ -48,11 +48,13 @@ _shortcut_button_add(Evas_Object *bx, const Config_Keys *key)
48 const char *txt; 48 const char *txt;
49 Evas_Object *hs; 49 Evas_Object *hs;
50 50
51 txt = eina_stringshare_printf("%s%s%s%s%s", 51 txt = eina_stringshare_printf("%s%s%s%s%s%s%s",
52 key->ctrl ? _("Ctrl+") : "", 52 key->ctrl ? _("Ctrl+") : "",
53 key->alt ? _("Alt+") : "", 53 key->alt ? _("Alt+") : "",
54 key->shift ? _("Shift+") : "", 54 key->shift ? _("Shift+") : "",
55 key->win ? _("Win+") : "", 55 key->win ? _("Win+") : "",
56 key->meta ? _("Meta+") : "",
57 key->hyper ? _("Hyper+") : "",
56 key->keyname); 58 key->keyname);
57 hs = elm_hoversel_add(_fr); 59 hs = elm_hoversel_add(_fr);
58 elm_hoversel_hover_parent_set(hs, _fr); 60 elm_hoversel_hover_parent_set(hs, _fr);
@@ -73,7 +75,7 @@ _cb_key_up(void *data, Evas *e EINA_UNUSED,
73 Evas_Object *obj, void *event) 75 Evas_Object *obj, void *event)
74{ 76{
75 Evas_Event_Key_Up *ev = event; 77 Evas_Event_Key_Up *ev = event;
76 int ctrl, alt, shift, win, res; 78 int ctrl, alt, shift, win, meta, hyper, res;
77 Config_Keys *cfg_key; 79 Config_Keys *cfg_key;
78 Shortcut_Action *action; 80 Shortcut_Action *action;
79 Evas_Object *bx = data; 81 Evas_Object *bx = data;
@@ -85,18 +87,13 @@ _cb_key_up(void *data, Evas *e EINA_UNUSED,
85 alt = evas_key_modifier_is_set(ev->modifiers, "Alt"); 87 alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
86 shift = evas_key_modifier_is_set(ev->modifiers, "Shift"); 88 shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
87 win = evas_key_modifier_is_set(ev->modifiers, "Super"); 89 win = evas_key_modifier_is_set(ev->modifiers, "Super");
90 meta = evas_key_modifier_is_set(ev->modifiers, "Meta") ||
91 evas_key_modifier_is_set(ev->modifiers, "AltGr") ||
92 evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift");
93 hyper = evas_key_modifier_is_set(ev->modifiers, "Hyper");
88 94
89 _hover_del(obj); 95 _hover_del(obj);
90 96
91 if (evas_key_modifier_is_set(ev->modifiers, "Meta") ||
92 evas_key_modifier_is_set(ev->modifiers, "Hyper") ||
93 evas_key_modifier_is_set(ev->modifiers, "AltGr") ||
94 evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift"))
95 {
96 ERR("Modifiers Meta/Hyper/ISO_Level3_Shift/AltGr are not supported in keybindings");
97 return;
98 }
99
100 action = evas_object_data_get(bx, "action"); 97 action = evas_object_data_get(bx, "action");
101 if (!action) 98 if (!action)
102 { 99 {
@@ -112,6 +109,8 @@ _cb_key_up(void *data, Evas *e EINA_UNUSED,
112 cfg_key->alt = alt; 109 cfg_key->alt = alt;
113 cfg_key->shift = shift; 110 cfg_key->shift = shift;
114 cfg_key->win = win; 111 cfg_key->win = win;
112 cfg_key->meta = meta;
113 cfg_key->hyper = hyper;
115 cfg_key->cb = eina_stringshare_add(action->action); 114 cfg_key->cb = eina_stringshare_add(action->action);
116 115
117 res = keyin_add_config(cfg_key); 116 res = keyin_add_config(cfg_key);
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 4f03072..ae4a7da 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -1912,10 +1912,7 @@ _smart_cb_key_down(void *data, Evas *e EINA_UNUSED,
1912{ 1912{
1913 const Evas_Event_Key_Down *ev = event; 1913 const Evas_Event_Key_Down *ev = event;
1914 Termio *sd = evas_object_smart_data_get(data); 1914 Termio *sd = evas_object_smart_data_get(data);
1915 int ctrl = evas_key_modifier_is_set(ev->modifiers, "Control"); 1915 int ctrl, alt, shift, win, meta, hyper;
1916 int alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
1917 int shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
1918 int win = evas_key_modifier_is_set(ev->modifiers, "Super");
1919 1916
1920 EINA_SAFETY_ON_NULL_RETURN(sd); 1917 EINA_SAFETY_ON_NULL_RETURN(sd);
1921 EINA_SAFETY_ON_NULL_RETURN(ev->key); 1918 EINA_SAFETY_ON_NULL_RETURN(ev->key);
@@ -1929,8 +1926,16 @@ _smart_cb_key_down(void *data, Evas *e EINA_UNUSED,
1929 return; 1926 return;
1930 } 1927 }
1931 1928
1929 ctrl = evas_key_modifier_is_set(ev->modifiers, "Control");
1930 alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
1931 shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
1932 win = evas_key_modifier_is_set(ev->modifiers, "Super");
1933 meta = evas_key_modifier_is_set(ev->modifiers, "Meta") ||
1934 evas_key_modifier_is_set(ev->modifiers, "AltGr") ||
1935 evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift");
1936 hyper = evas_key_modifier_is_set(ev->modifiers, "Hyper");
1932 1937
1933 if (keyin_handle(&sd->khdl, sd->pty, ev, ctrl, alt, shift, win)) 1938 if (keyin_handle(&sd->khdl, sd->pty, ev, ctrl, alt, shift, win, meta, hyper))
1934 goto end; 1939 goto end;
1935 1940
1936 if (sd->jump_on_keypress) 1941 if (sd->jump_on_keypress)