add meta/hyper to key bindings. Closes T1985

terminology-0.9
Boris Faure 8 years ago
parent 981f76c6e3
commit 52ceae82b1
  1. 4
      src/bin/config.c
  2. 2
      src/bin/config.h
  3. 52
      src/bin/keyin.c
  4. 6
      src/bin/keyin.h
  5. 21
      src/bin/options_keys.c
  6. 15
      src/bin/termio.c

@ -67,6 +67,10 @@ config_init(void)
(edd_keys, Config_Keys, "shift", shift, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_keys, Config_Keys, "win", win, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_keys, Config_Keys, "meta", meta, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_keys, Config_Keys, "hyper", hyper, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_keys, Config_Keys, "cb", cb, EET_T_STRING);

@ -14,6 +14,8 @@ struct _Config_Keys
Eina_Bool alt;
Eina_Bool shift;
Eina_Bool win;
Eina_Bool meta;
Eina_Bool hyper;
const char *cb;
};
/* TODO: separate config per terminal (tab, window) and global. */

@ -42,6 +42,8 @@ struct _Key_Binding
uint16_t alt : 1;
uint16_t shift : 1;
uint16_t win : 1;
uint16_t meta : 1;
uint16_t hyper : 1;
uint16_t len;
@ -179,7 +181,8 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
static Key_Binding *
key_binding_lookup(const char *keyname,
Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win)
Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift,
Eina_Bool win, Eina_Bool meta, Eina_Bool hyper)
{
Key_Binding *kb;
size_t len = strlen(keyname);
@ -192,6 +195,8 @@ key_binding_lookup(const char *keyname,
kb->alt = alt;
kb->shift = shift;
kb->win = win;
kb->meta = meta;
kb->hyper = hyper;
kb->len = len;
kb->keyname = alloca(sizeof(char) * len + 1);
strncpy((char *)kb->keyname, keyname, kb->len + 1);
@ -201,23 +206,18 @@ key_binding_lookup(const char *keyname,
Eina_Bool
keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev,
Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win)
Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win,
Eina_Bool meta, Eina_Bool hyper)
{
if (!evas_key_modifier_is_set(ev->modifiers, "Meta") &&
!evas_key_modifier_is_set(ev->modifiers, "Hyper") &&
!evas_key_modifier_is_set(ev->modifiers, "AltGr") &&
!evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift"))
Key_Binding *kb;
kb = key_binding_lookup(ev->keyname, ctrl, alt, shift, win, meta, hyper);
if (kb)
{
Key_Binding *kb;
kb = key_binding_lookup(ev->keyname, ctrl, alt, shift, win);
if (kb)
if (kb->cb(ty->obj))
{
if (kb->cb(ty->obj))
{
keyin_compose_seq_reset(khdl);
return EINA_TRUE;
}
keyin_compose_seq_reset(khdl);
return EINA_TRUE;
}
}
@ -613,8 +613,10 @@ _key_binding_key_cmp(const void *key1, int key1_length,
return 1;
else
{
unsigned int m1 = (kb1->win << 3) | (kb1->ctrl << 2) | (kb1->alt << 1) | kb1->shift,
m2 = (kb2->win << 3) | (kb2->ctrl << 2) | (kb2->alt << 1) | kb2->shift;
unsigned int m1 = (kb1->hyper << 5) | (kb1->meta << 4) |
(kb1->win << 3) | (kb1->ctrl << 2) | (kb1->alt << 1) | kb1->shift,
m2 = (kb2->hyper << 5) | (kb2->meta << 4) |
(kb2->win << 3) | (kb2->ctrl << 2) | (kb2->alt << 1) | kb2->shift;
if (m1 < m2)
return -1;
else if (m1 > m2)
@ -631,8 +633,13 @@ _key_binding_key_hash(const void *key, int key_length)
int hash;
hash = eina_hash_djb2(key, key_length);
hash &= 0x0fffffff;
hash |= (kb->win << 31) | (kb->ctrl << 30) | (kb->alt << 29) | (kb->shift << 28);
hash &= 0x3ffffff;
hash |= (kb->hyper << 31);
hash |= (kb->meta << 30);
hash |= (kb->win << 29);
hash |= (kb->ctrl << 28);
hash |= (kb->alt << 27);
hash |= (kb->shift << 26);
return hash;
}
@ -640,6 +647,7 @@ _key_binding_key_hash(const void *key, int key_length)
static Key_Binding *
_key_binding_new(const char *keyname,
Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win,
Eina_Bool meta, Eina_Bool hyper,
Key_Binding_Cb cb)
{
Key_Binding *kb;
@ -653,6 +661,8 @@ _key_binding_new(const char *keyname,
kb->alt = alt;
kb->shift = shift;
kb->win = win;
kb->meta = meta;
kb->hyper = hyper;
kb->len = len;
kb->keyname = eina_stringshare_add(keyname);
kb->cb = cb;
@ -681,7 +691,8 @@ keyin_add_config(Config_Keys *key)
{
Key_Binding *kb;
kb = _key_binding_new(key->keyname, key->ctrl, key->alt,
key->shift, key->win, action->cb);
key->shift, key->win, key->meta, key->hyper,
action->cb);
if (!kb)
return -1;
if (eina_hash_find(_key_bindings, kb) ||
@ -701,7 +712,8 @@ keyin_remove_config(Config_Keys *key)
{
Key_Binding *kb;
kb = key_binding_lookup(key->keyname, key->ctrl, key->alt, key->shift, key->win);
kb = key_binding_lookup(key->keyname, key->ctrl, key->alt, key->shift,
key->win, key->meta, key->hyper);
if (kb)
eina_hash_del_by_key(_key_bindings, kb);
return 0;

@ -13,8 +13,10 @@ struct _Keys_Handler
void keyin_compose_seq_reset(Keys_Handler *khdl);
Eina_Bool key_is_modifier(const char *key);
Eina_Bool keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev,
Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win);
Eina_Bool
keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev,
Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win,
Eina_Bool meta, Eina_Bool hyper);
void keyin_handle_up(Keys_Handler *khdl, Evas_Event_Key_Up *ev);

@ -48,11 +48,13 @@ _shortcut_button_add(Evas_Object *bx, const Config_Keys *key)
const char *txt;
Evas_Object *hs;
txt = eina_stringshare_printf("%s%s%s%s%s",
txt = eina_stringshare_printf("%s%s%s%s%s%s%s",
key->ctrl ? _("Ctrl+") : "",
key->alt ? _("Alt+") : "",
key->shift ? _("Shift+") : "",
key->win ? _("Win+") : "",
key->meta ? _("Meta+") : "",
key->hyper ? _("Hyper+") : "",
key->keyname);
hs = elm_hoversel_add(_fr);
elm_hoversel_hover_parent_set(hs, _fr);
@ -73,7 +75,7 @@ _cb_key_up(void *data, Evas *e EINA_UNUSED,
Evas_Object *obj, void *event)
{
Evas_Event_Key_Up *ev = event;
int ctrl, alt, shift, win, res;
int ctrl, alt, shift, win, meta, hyper, res;
Config_Keys *cfg_key;
Shortcut_Action *action;
Evas_Object *bx = data;
@ -85,18 +87,13 @@ _cb_key_up(void *data, Evas *e EINA_UNUSED,
alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
win = evas_key_modifier_is_set(ev->modifiers, "Super");
meta = evas_key_modifier_is_set(ev->modifiers, "Meta") ||
evas_key_modifier_is_set(ev->modifiers, "AltGr") ||
evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift");
hyper = evas_key_modifier_is_set(ev->modifiers, "Hyper");
_hover_del(obj);
if (evas_key_modifier_is_set(ev->modifiers, "Meta") ||
evas_key_modifier_is_set(ev->modifiers, "Hyper") ||
evas_key_modifier_is_set(ev->modifiers, "AltGr") ||
evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift"))
{
ERR("Modifiers Meta/Hyper/ISO_Level3_Shift/AltGr are not supported in keybindings");
return;
}
action = evas_object_data_get(bx, "action");
if (!action)
{
@ -112,6 +109,8 @@ _cb_key_up(void *data, Evas *e EINA_UNUSED,
cfg_key->alt = alt;
cfg_key->shift = shift;
cfg_key->win = win;
cfg_key->meta = meta;
cfg_key->hyper = hyper;
cfg_key->cb = eina_stringshare_add(action->action);
res = keyin_add_config(cfg_key);

@ -1912,10 +1912,7 @@ _smart_cb_key_down(void *data, Evas *e EINA_UNUSED,
{
const Evas_Event_Key_Down *ev = event;
Termio *sd = evas_object_smart_data_get(data);
int ctrl = evas_key_modifier_is_set(ev->modifiers, "Control");
int alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
int shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
int win = evas_key_modifier_is_set(ev->modifiers, "Super");
int ctrl, alt, shift, win, meta, hyper;
EINA_SAFETY_ON_NULL_RETURN(sd);
EINA_SAFETY_ON_NULL_RETURN(ev->key);
@ -1929,8 +1926,16 @@ _smart_cb_key_down(void *data, Evas *e EINA_UNUSED,
return;
}
ctrl = evas_key_modifier_is_set(ev->modifiers, "Control");
alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
win = evas_key_modifier_is_set(ev->modifiers, "Super");
meta = evas_key_modifier_is_set(ev->modifiers, "Meta") ||
evas_key_modifier_is_set(ev->modifiers, "AltGr") ||
evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift");
hyper = evas_key_modifier_is_set(ev->modifiers, "Hyper");
if (keyin_handle(&sd->khdl, sd->pty, ev, ctrl, alt, shift, win))
if (keyin_handle(&sd->khdl, sd->pty, ev, ctrl, alt, shift, win, meta, hyper))
goto end;
if (sd->jump_on_keypress)

Loading…
Cancel
Save