summaryrefslogtreecommitdiff
path: root/src/bin/keyin.c
blob: 3247326ec527bf0fcfa4b99e4f2cba97e712b812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
#include <Elementary.h>
#include <Ecore_Input.h>
#include <Ecore_IMF.h>
#include <Ecore_IMF_Evas.h>
#include "private.h"
#include "termpty.h"
#include "termio.h"
#include "termcmd.h"
#include "keyin.h"

typedef struct _Tty_Key Tty_Key;
typedef struct _Key_Values Key_Values;

struct _s {
    char *s;
    ssize_t len;
};

struct _Key_Values {
    struct _s plain;
    struct _s alt;
    struct _s ctrl;
    struct _s ctrl_alt;
    struct _s shift;
    struct _s shift_alt;
    struct _s shift_ctrl;
    struct _s shift_ctrl_alt;
};
struct _Tty_Key
{
    char *key;
    int key_len;
    Key_Values default_mode;
    Key_Values cursor;
};

typedef struct _Key_Binding Key_Binding;

struct _Key_Binding
{
   uint16_t ctrl  : 1;
   uint16_t alt   : 1;
   uint16_t shift : 1;
   uint16_t win   : 1;

   uint16_t len;

   Key_Binding_Cb cb;
   const char *keyname;
};

static Eina_Hash *_key_bindings = NULL;

/* {{{ Keys to TTY */

static Eina_Bool
_key_try(Termpty *ty, const Tty_Key *map, int len, const Evas_Event_Key_Down *ev,
         int alt, int shift, int ctrl)
{
   int i, inlen;

   inlen = strlen(ev->key);
   for (i = 0; i < len; i++)
     {
        if ((inlen == map[i].key_len) && (!memcmp(ev->key, map[i].key, inlen)))
          {
             const struct _s *s;
             const Key_Values *kv;

             if (!ty->state.appcursor)
               {
                  kv = &map[i].default_mode;
               }
             else
               {
                  kv = &map[i].cursor;
               }
             if (!alt && !ctrl && !shift)
                  s = &kv->plain;
             else if (alt && !ctrl && !shift)
                  s = &kv->alt;
             else if (!alt && ctrl && !shift)
                  s = &kv->ctrl;
             else if (alt && ctrl && !shift)
                  s = &kv->ctrl_alt;
             else if (!alt && !ctrl && shift)
                  s = &kv->shift;
             else if (alt && !ctrl && shift)
                  s = &kv->shift_alt;
             else if (!alt && ctrl && shift)
                  s = &kv->shift_ctrl;
             else if (alt && ctrl && shift)
                  s = &kv->shift_ctrl_alt;

             termpty_write(ty, s->s, s->len);
             return EINA_TRUE;
          }
     }
   return EINA_FALSE;
}

/* }}} */
/* {{{ Handle keys */

void
keyin_compose_seq_reset(Keys_Handler *khdl)
{
   char *str;

   EINA_LIST_FREE(khdl->seq, str) eina_stringshare_del(str);
   khdl->composing = EINA_FALSE;
}

#include "tty_keys.h"

static void
_handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
                   int alt, int shift, int ctrl)
{
   if (!ev->key)
     return;

   if (!strcmp(ev->key, "BackSpace"))
     {
        if (alt)
          termpty_write(ty, "\033", 1);
        if (ty->state.send_bs)
          {
             termpty_write(ty, "\b", 1);
          }
        else
          {
             Config *cfg = termpty_config_get(ty);

             if (cfg->erase_is_del && !ctrl)
               {
                  termpty_write(ty, "\177", sizeof("\177") - 1);
               }
             else
               {
                  termpty_write(ty, "\b", sizeof("\b") - 1);
               }
          }
        return;
     }
   if (!strcmp(ev->key, "Return"))
     {
      if (ty->state.crlf)
        {
           termpty_write(ty, "\r\n", sizeof("\r\n") - 1);
           return;
        }
      else
        {
           termpty_write(ty, "\r", sizeof("\r") - 1);
           return;
        }
     }
   if (ev->key && ev->key[0] == 'K' && ev->key[1] == 'k')
     {
        if (!evas_key_lock_is_set(ev->locks, "Num_Lock"))
          {
             if (ty->state.alt_kp)
               {
                  if (_key_try(ty, tty_keys_kp_app,
                               sizeof(tty_keys_kp_app)/sizeof(tty_keys_kp_app[0]),
                               ev, alt, shift, ctrl))
                    return;
               }
             else
               {
                  if (_key_try(ty, tty_keys_kp_plain,
                               sizeof(tty_keys_kp_plain)/sizeof(tty_keys_kp_plain[0]),
                               ev, alt, shift, ctrl))
                    return;
               }
          }
     }
   else
     if (_key_try(ty, tty_keys, sizeof(tty_keys)/sizeof(tty_keys[0]), ev,
                  alt, shift, ctrl))
       return;

   if (ev->string)
     {
        if ((ev->string[0]) && (!ev->string[1]))
          {
             if (alt)
               termpty_write(ty, "\033", 1);
          }
        termpty_write(ty, ev->string, strlen(ev->string));
     }
}

static Key_Binding *
key_binding_lookup(const char *keyname,
                   Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win)
{
   Key_Binding *kb;
   size_t len = strlen(keyname);

   if (len > UINT16_MAX) return NULL;

   kb = alloca(sizeof(Key_Binding));
   if (!kb) return NULL;
   kb->ctrl = ctrl;
   kb->alt = alt;
   kb->shift = shift;
   kb->win = win;
   kb->len = len;
   kb->keyname = alloca(sizeof(char) * len + 1);
   strncpy((char *)kb->keyname, keyname, kb->len + 1);

   return eina_hash_find(_key_bindings, kb);
}

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)
{

   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);
        if (kb)
          {
             if (kb->cb(ty->obj))
               {
                  keyin_compose_seq_reset(khdl);
                  return EINA_TRUE;
               }
          }
     }

   /* composing */
   if (khdl->imf)
     {
        // EXCEPTION. Don't filter modifiers alt+shift -> breaks emacs
        // and jed (alt+shift+5 for search/replace for example)
        // Don't filter modifiers alt, is used by shells
        if ((!alt) && (!ctrl))
          {
             Ecore_IMF_Event_Key_Down imf_ev;

             ecore_imf_evas_event_key_down_wrap((Evas_Event_Key_Down*)ev, &imf_ev);
             if (!khdl->composing)
               {
                  if (ecore_imf_context_filter_event
                      (khdl->imf, ECORE_IMF_EVENT_KEY_DOWN, (Ecore_IMF_Event *)&imf_ev))
                    goto end;
               }
          }
     }

   // if term app asked for kbd lock - dont handle here
   if (ty->state.kbd_lock) return EINA_TRUE;
   // if app asked us to not do autorepeat - ignore press if is it is the same
   // timestamp as last one
   if ((ty->state.no_autorepeat) &&
       (ev->timestamp == khdl->last_keyup)) return EINA_TRUE;
   if (!khdl->composing)
     {
        Ecore_Compose_State state;
        char *compres = NULL;

        keyin_compose_seq_reset(khdl);
        khdl->seq = eina_list_append(khdl->seq, eina_stringshare_add(ev->key));
        state = ecore_compose_get(khdl->seq, &compres);
        if (state == ECORE_COMPOSE_MIDDLE) khdl->composing = EINA_TRUE;
        else khdl->composing = EINA_FALSE;
        if (!khdl->composing) keyin_compose_seq_reset(khdl);
        else goto end;
     }
   else
     {
        Ecore_Compose_State state;
        char *compres = NULL;

        if (key_is_modifier(ev->key)) goto end;
        khdl->seq = eina_list_append(khdl->seq, eina_stringshare_add(ev->key));
        state = ecore_compose_get(khdl->seq, &compres);
        if (state == ECORE_COMPOSE_NONE) keyin_compose_seq_reset(khdl);
        else if (state == ECORE_COMPOSE_DONE)
          {
             keyin_compose_seq_reset(khdl);
             if (compres)
               {
                  termpty_write(ty, compres, strlen(compres));
                  free(compres);
                  compres = NULL;
               }
             goto end;
          }
        else goto end;
     }


   _handle_key_to_pty(ty, ev, alt, shift, ctrl);


end:
   return EINA_FALSE;
}

Eina_Bool
key_is_modifier(const char *key)
{
#define STATIC_STR_EQUAL(STR) (!strncmp(key, STR, strlen(STR)))
   if ((key != NULL) && (
       STATIC_STR_EQUAL("Shift") ||
       STATIC_STR_EQUAL("Control") ||
       STATIC_STR_EQUAL("Alt") ||
       STATIC_STR_EQUAL("AltGr") ||
       STATIC_STR_EQUAL("Meta") ||
       STATIC_STR_EQUAL("Super") ||
       STATIC_STR_EQUAL("Hyper") ||
       STATIC_STR_EQUAL("Scroll_Lock") ||
       STATIC_STR_EQUAL("Num_Lock") ||
       STATIC_STR_EQUAL("ISO_Level3_Shift") ||
       STATIC_STR_EQUAL("Caps_Lock")))
     return EINA_TRUE;
#undef STATIC_STR_EQUAL
   return EINA_FALSE;
}

void
keyin_handle_up(Keys_Handler *khdl, Evas_Event_Key_Up *ev)
{
   khdl->last_keyup = ev->timestamp;
   if (khdl->imf)
     {
        Ecore_IMF_Event_Key_Up imf_ev;
        ecore_imf_evas_event_key_up_wrap(ev, &imf_ev);
        if (ecore_imf_context_filter_event
            (khdl->imf, ECORE_IMF_EVENT_KEY_UP, (Ecore_IMF_Event *)&imf_ev))
          return;
     }
}

/* }}} */
/* {{{ Callbacks */

static Eina_Bool
cb_term_prev(Evas_Object *term)
{
   evas_object_smart_callback_call(term, "prev", NULL);
   return EINA_TRUE;
}

static Eina_Bool
cb_term_next(Evas_Object *term)
{
   evas_object_smart_callback_call(term, "next", NULL);
   return EINA_TRUE;
}

#define CB_TAB(N)\
static Eina_Bool \
cb_tab_##N(Evas_Object *term) \
{                            \
   evas_object_smart_callback_call(term, "tab,"#N, NULL); \
   return EINA_TRUE; \
}

CB_TAB(0)
CB_TAB(1)
CB_TAB(2)
CB_TAB(3)
CB_TAB(4)
CB_TAB(5)
CB_TAB(6)
CB_TAB(7)
CB_TAB(8)
CB_TAB(9)
#undef CB_TAB

static Eina_Bool
cb_cmd_box(Evas_Object *term)
{
   evas_object_smart_callback_call(term, "cmdbox", NULL);
   return EINA_TRUE;
}

static Eina_Bool
cb_split_h(Evas_Object *term)
{
   evas_object_smart_callback_call(term, "split,h", NULL);
   return EINA_TRUE;
}

static Eina_Bool
cb_split_v(Evas_Object *term)
{
   evas_object_smart_callback_call(term, "split,v", NULL);
   return EINA_TRUE;
}

static Eina_Bool
cb_tab_new(Evas_Object *term)
{
   evas_object_smart_callback_call(term, "new", NULL);
   return EINA_TRUE;
}

static Eina_Bool
cb_exited(Evas_Object *term)
{
   evas_object_smart_callback_call(term, "exited", NULL);
   return EINA_TRUE;
}

static Eina_Bool
cb_tab_select(Evas_Object *term)
{
   evas_object_smart_callback_call(term, "select", NULL);
   return EINA_TRUE;
}

static Eina_Bool
cb_copy_clipboard(Evas_Object *term)
{
   Termpty *ty = termio_pty_get(term);

   if (!ty || !ty->selection.is_active)
     return EINA_FALSE;
   termio_take_selection(term, ELM_SEL_TYPE_CLIPBOARD);
   return EINA_TRUE;
}

static Eina_Bool
cb_paste_clipboard(Evas_Object *term)
{
   termio_paste_selection(term, ELM_SEL_TYPE_CLIPBOARD);
   return EINA_TRUE;
}

static Eina_Bool
cb_paste_primary(Evas_Object *term)
{
   termio_paste_selection(term, ELM_SEL_TYPE_PRIMARY);
   return EINA_TRUE;
}

static Eina_Bool
cb_copy_primary(Evas_Object *term)
{
   Termpty *ty = termio_pty_get(term);

   if (!ty || !ty->selection.is_active)
     return EINA_FALSE;
   termio_take_selection(term, ELM_SEL_TYPE_PRIMARY);
   return EINA_TRUE;
}

static Eina_Bool
cb_miniview(Evas_Object *term)
{
   term_miniview_toggle(termio_term_get(term));
   return EINA_TRUE;
}

static Eina_Bool
cb_increase_font_size(Evas_Object *term)
{
   termcmd_do(term, NULL, NULL, "f+");
   return EINA_TRUE;
}

static Eina_Bool
cb_decrease_font_size(Evas_Object *term)
{
   termcmd_do(term, NULL, NULL, "f-");
   return EINA_TRUE;
}

static Eina_Bool
cb_reset_font_size(Evas_Object *term)
{
   termcmd_do(term, NULL, NULL, "f");
   return EINA_TRUE;
}

static Eina_Bool
cb_big_font_size(Evas_Object *term)
{
   termcmd_do(term, NULL, NULL, "fb");
   return EINA_TRUE;
}

static Eina_Bool
cb_scroll_up_page(Evas_Object *term)
{
   Termpty *ty = termio_pty_get(term);

   if (!ty || ty->altbuf)
     return EINA_FALSE;

   termio_scroll_delta(term, 1, 1);
   return EINA_TRUE;
}

static Eina_Bool
cb_scroll_down_page(Evas_Object *term)
{
   Termpty *ty = termio_pty_get(term);

   if (!ty || ty->altbuf)
     return EINA_FALSE;

   termio_scroll_delta(term, -1, 1);
   return EINA_TRUE;
}

static Eina_Bool
cb_scroll_up_line(Evas_Object *term)
{
   Termpty *ty = termio_pty_get(term);

   if (!ty || ty->altbuf)
     return EINA_FALSE;

   termio_scroll_delta(term, 1, 0);
   return EINA_TRUE;
}

static Eina_Bool
cb_scroll_down_line(Evas_Object *term)
{
   Termpty *ty = termio_pty_get(term);

   if (!ty || ty->altbuf)
     return EINA_FALSE;

   termio_scroll_delta(term, -1, 0);
   return EINA_TRUE;
}


static Shortcut_Action _actions[] =
{
     {"group", gettext_noop("Scrolling"), NULL},
     {"one_page_up", gettext_noop("Scroll one page up"), cb_scroll_up_page},
     {"one_page_down", gettext_noop("Scroll one page down"), cb_scroll_down_page},
     {"one_line_up", gettext_noop("Scroll one line up"), cb_scroll_up_line},
     {"one_line_down", gettext_noop("Scroll one line down"), cb_scroll_down_line},

     {"group", gettext_noop("Copy/Paste"), NULL},
     {"copy_primary", gettext_noop("Copy selection to Primary buffer"), cb_copy_primary},
     {"copy_clipboard", gettext_noop("Copy selection to Clipboard buffer"), cb_copy_clipboard},
     {"paste_primary", gettext_noop("Paste Primary buffer (highlight)"), cb_paste_primary},
     {"paste_clipboard", gettext_noop("Paste Clipboard buffer (ctrl+c/v)"), cb_paste_clipboard},

     {"group", gettext_noop("Splits/Tabs"), NULL},
     {"term_prev", gettext_noop("Focus to the previous terminal"), cb_term_prev},
     {"term_next", gettext_noop("Focus to the next terminal"), cb_term_next},
     {"split_h", gettext_noop("Split horizontally (new below)"), cb_split_h},
     {"split_v", gettext_noop("Split vertically (new on right)"), cb_split_v},
     {"tab_new", gettext_noop("Create a new \"tab\""), cb_tab_new},
     {"exited", gettext_noop("Close the focused terminal"), cb_exited},
     {"tab_select", gettext_noop("Bring up \"tab\" switcher"), cb_tab_select},
     {"tab_1", gettext_noop("Switch to terminal tab 1"), cb_tab_1},
     {"tab_2", gettext_noop("Switch to terminal tab 2"), cb_tab_2},
     {"tab_3", gettext_noop("Switch to terminal tab 3"), cb_tab_3},
     {"tab_4", gettext_noop("Switch to terminal tab 4"), cb_tab_4},
     {"tab_5", gettext_noop("Switch to terminal tab 5"), cb_tab_5},
     {"tab_6", gettext_noop("Switch to terminal tab 6"), cb_tab_6},
     {"tab_7", gettext_noop("Switch to terminal tab 7"), cb_tab_7},
     {"tab_8", gettext_noop("Switch to terminal tab 8"), cb_tab_8},
     {"tab_9", gettext_noop("Switch to terminal tab 9"), cb_tab_9},
     {"tab_10", gettext_noop("Switch to terminal tab 10"), cb_tab_0},

     {"group", gettext_noop("Font size"), NULL},
     {"increase_font_size", gettext_noop("Font size up 1"), cb_increase_font_size},
     {"decrease_font_size", gettext_noop("Font size down 1"), cb_decrease_font_size},
     {"big_font_size", gettext_noop("Display big font size"), cb_big_font_size},
     {"reset_font_size", gettext_noop("Reset font size"), cb_reset_font_size},

     {"group", gettext_noop("Actions"), NULL},
     {"miniview", gettext_noop("Display the history miniview"), cb_miniview},
     {"cmd_box", gettext_noop("Display the command box"), cb_cmd_box},

     {NULL, NULL, NULL}
};

const Shortcut_Action *
shortcut_actions_get(void)
{
   return _actions;
}

/* }}} */
/* {{{ Key bindings */

static unsigned int
_key_binding_key_length(EINA_UNUSED const void *key)
{
   return 0;
}

static int
_key_binding_key_cmp(const void *key1, int key1_length,
                     const void *key2, int key2_length)
{
   const Key_Binding *kb1 = key1,
                     *kb2 = key2;

   if (key1_length < key2_length)
     return -1;
   else if (key1_length > key2_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;
        if (m1 < m2)
          return -1;
        else if (m1 > m2)
          return 1;
        else
          return strncmp(kb1->keyname, kb2->keyname, kb1->len);
     }
}

static int
_key_binding_key_hash(const void *key, int key_length)
{
   const Key_Binding *kb = key;
   int hash;

   hash = eina_hash_djb2(key, key_length);
   hash &= 0x0fffffff;
   hash |= (kb->win << 31) | (kb->ctrl << 30) | (kb->alt << 29) | (kb->shift << 28);
   return hash;
}


static Key_Binding *
_key_binding_new(const char *keyname,
                 Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win,
                 Key_Binding_Cb cb)
{
   Key_Binding *kb;
   size_t len = strlen(keyname);

   if (len > UINT16_MAX) return NULL;

   kb = malloc(sizeof(Key_Binding) + len + 1);
   if (!kb) return NULL;
   kb->ctrl = ctrl;
   kb->alt = alt;
   kb->shift = shift;
   kb->win = win;
   kb->len = len;
   kb->keyname = eina_stringshare_add(keyname);
   kb->cb = cb;

   return kb;
}

static void
_key_binding_free(void *data)
{
   Key_Binding *kb = data;
   if (!kb) return;
   eina_stringshare_del(kb->keyname);
   free(kb);
}

int
keyin_add_config(Config_Keys *key)
{
   Shortcut_Action *action = _actions;

   while (action->action && strcmp(action->action, key->cb))
     action++;

   if (action->action)
     {
        Key_Binding *kb;
        kb = _key_binding_new(key->keyname, key->ctrl, key->alt,
                              key->shift, key->win, action->cb);
        if (!kb) return -1;
        if (eina_hash_find(_key_bindings, kb) ||
            (!eina_hash_direct_add(_key_bindings, kb, kb)))
          {
             _key_binding_free(kb);
             return -1;
          }
        return 0;
     }
   return -1;
}

int
keyin_remove_config(Config_Keys *key)
{
   Key_Binding *kb;

   kb = key_binding_lookup(key->keyname, key->ctrl, key->alt, key->shift, key->win);
   if (kb)
     eina_hash_del_by_key(_key_bindings, kb);
   return 0;
}

int 
key_bindings_load(Config *config)
{
   Config_Keys *key;
   Eina_List *l;

   if (!_key_bindings)
     {
#if HAVE_GETTEXT && ENABLE_NLS
        Shortcut_Action *action = _actions;

        while (action->action)
          {
             action->description = gettext(action->description);
             action++;
          }
#endif
        _key_bindings = eina_hash_new(_key_binding_key_length,
                                      _key_binding_key_cmp,
                                      _key_binding_key_hash,
                                      _key_binding_free,
                                      5);
        if (!_key_bindings) return -1;
     }
   else
     {
        eina_hash_free_buckets(_key_bindings);
     }

   EINA_LIST_FOREACH(config->keys, l, key)
     {
        int res = keyin_add_config(key);
        if (res != 0)
          return res;
     }

   return 0;
}

void 
key_bindings_shutdown(void)
{
   if (_key_bindings)
     eina_hash_free(_key_bindings);
   _key_bindings = NULL;
}

/* }}} */