summaryrefslogtreecommitdiff
path: root/src/bin/keyin.c
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2014-08-23 18:35:53 +0200
committerBoris Faure <billiob@gmail.com>2014-09-02 20:42:45 +0200
commitc839959a518fdc9b28ca7e69ac51e7156384e1f1 (patch)
tree90283d69c50d7aae236425032ab345ff0ed74375 /src/bin/keyin.c
parent2f9532d28c1526c0dd96cb8544a4f9ea836c77e4 (diff)
have all the default shortcuts in the hash map
Diffstat (limited to 'src/bin/keyin.c')
-rw-r--r--src/bin/keyin.c480
1 files changed, 244 insertions, 236 deletions
diff --git a/src/bin/keyin.c b/src/bin/keyin.c
index aa823b9..a555363 100644
--- a/src/bin/keyin.c
+++ b/src/bin/keyin.c
@@ -20,7 +20,7 @@ struct _Keyout
20 20
21static Eina_Hash *_key_bindings = NULL; 21static Eina_Hash *_key_bindings = NULL;
22 22
23 23/* {{{ Keys to TTY */
24 24
25#define KEY(in, out) {in, out, sizeof(in) - 1, sizeof(out) - 1} 25#define KEY(in, out) {in, out, sizeof(in) - 1, sizeof(out) - 1}
26 26
@@ -408,6 +408,9 @@ _key_try(Termpty *ty, const Keyout *map, const Evas_Event_Key_Down *ev)
408 return EINA_FALSE; 408 return EINA_FALSE;
409} 409}
410 410
411/* }}} */
412/* {{{ Handle keys */
413
411void 414void
412keyin_compose_seq_reset(Keys_Handler *khdl) 415keyin_compose_seq_reset(Keys_Handler *khdl)
413{ 416{
@@ -417,97 +420,6 @@ keyin_compose_seq_reset(Keys_Handler *khdl)
417 khdl->composing = EINA_FALSE; 420 khdl->composing = EINA_FALSE;
418} 421}
419 422
420static Eina_Bool
421_handle_alt_ctrl(const char *keyname, Evas_Object *term)
422{
423 if (!strcmp(keyname, "equal"))
424 termcmd_do(term, NULL, NULL, "f+");
425 else if (!strcmp(keyname, "minus"))
426 termcmd_do(term, NULL, NULL, "f-");
427 else if (!strcmp(keyname, "0"))
428 termcmd_do(term, NULL, NULL, "f");
429 else if (!strcmp(keyname, "9"))
430 termcmd_do(term, NULL, NULL, "fb");
431 else
432 return EINA_FALSE;
433
434 return EINA_TRUE;
435}
436
437static Eina_Bool
438_handle_shift(const Evas_Event_Key_Down *ev, Termpty *ty)
439{
440 if (!strcmp(ev->key, "Prior"))
441 {
442 if (!ty->altbuf)
443 {
444 termio_scroll_delta(ty->obj, 1, 1);
445 return EINA_TRUE;
446 }
447 return EINA_FALSE;
448 }
449 else if (!strcmp(ev->key, "Next"))
450 {
451 if (!ty->altbuf)
452 {
453 termio_scroll_delta(ty->obj, -1, 1);
454 return EINA_TRUE;
455 }
456 return EINA_FALSE;
457 }
458 else if (!strcmp(ev->key, "Up"))
459 {
460 if (!ty->altbuf)
461 {
462 termio_scroll_delta(ty->obj, 1, 0);
463 return EINA_TRUE;
464 }
465 return EINA_FALSE;
466 }
467 else if (!strcmp(ev->key, "Down"))
468 {
469 if (!ty->altbuf)
470 {
471 termio_scroll_delta(ty->obj, -1, 0);
472 return EINA_TRUE;
473 }
474 return EINA_FALSE;
475 }
476 else if (!strcmp(ev->key, "Insert"))
477 {
478 /*XXX CTRL*/
479 if (evas_key_modifier_is_set(ev->modifiers, "Control"))
480 termio_paste_selection(ty->obj, ELM_SEL_TYPE_CLIPBOARD);
481 else
482 termio_paste_selection(ty->obj, ELM_SEL_TYPE_PRIMARY);
483 }
484 else if (!strcmp(ev->key, "KP_Add"))
485 {
486 Config *config = termpty_config_get(ty);
487
488 if (config) termio_font_size_set(ty->obj, config->font.size + 1);
489 }
490 else if (!strcmp(ev->key, "KP_Subtract"))
491 {
492 Config *config = termpty_config_get(ty);
493
494 if (config) termio_font_size_set(ty->obj, config->font.size - 1);
495 }
496 else if (!strcmp(ev->key, "KP_Multiply"))
497 {
498 Config *config = termpty_config_get(ty);
499
500 if (config) termio_font_size_set(ty->obj, 10);
501 }
502 else if (!strcmp(ev->key, "KP_Divide"))
503 termio_take_selection(ty->obj, ELM_SEL_TYPE_CLIPBOARD);
504 else
505 return EINA_FALSE;
506
507 return EINA_TRUE;
508}
509
510
511static void 423static void
512_handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev, 424_handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
513 int alt, int shift, int ctrl) 425 int alt, int shift, int ctrl)
@@ -654,152 +566,12 @@ keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev,
654 if (kb) 566 if (kb)
655 { 567 {
656 if (kb->cb(ty->obj)) 568 if (kb->cb(ty->obj))
657 goto end;
658 }
659
660
661 if ((!alt) && (ctrl) && (!shift))
662 {
663 if (!strcmp(ev->key, "Next"))
664 {
665 keyin_compose_seq_reset(khdl);
666 evas_object_smart_callback_call(ty->obj, "next", NULL);
667 return EINA_TRUE;
668 }
669 else if (!strcmp(ev->key, "1"))
670 {
671 keyin_compose_seq_reset(khdl);
672 evas_object_smart_callback_call(ty->obj, "tab,1", NULL);
673 return EINA_TRUE;
674 }
675 else if (!strcmp(ev->key, "2"))
676 {
677 keyin_compose_seq_reset(khdl);
678 evas_object_smart_callback_call(ty->obj, "tab,2", NULL);
679 return EINA_TRUE;
680 }
681 else if (!strcmp(ev->key, "3"))
682 { 569 {
683 keyin_compose_seq_reset(khdl); 570 keyin_compose_seq_reset(khdl);
684 evas_object_smart_callback_call(ty->obj, "tab,3", NULL); 571 goto end;
685 return EINA_TRUE;
686 }
687 else if (!strcmp(ev->key, "4"))
688 {
689 keyin_compose_seq_reset(khdl);
690 evas_object_smart_callback_call(ty->obj, "tab,4", NULL);
691 return EINA_TRUE;
692 }
693 else if (!strcmp(ev->key, "5"))
694 {
695 keyin_compose_seq_reset(khdl);
696 evas_object_smart_callback_call(ty->obj, "tab,5", NULL);
697 return EINA_TRUE;
698 }
699 else if (!strcmp(ev->key, "6"))
700 {
701 keyin_compose_seq_reset(khdl);
702 evas_object_smart_callback_call(ty->obj, "tab,6", NULL);
703 return EINA_TRUE;
704 }
705 else if (!strcmp(ev->key, "7"))
706 {
707 keyin_compose_seq_reset(khdl);
708 evas_object_smart_callback_call(ty->obj, "tab,7", NULL);
709 return EINA_TRUE;
710 }
711 else if (!strcmp(ev->key, "8"))
712 {
713 keyin_compose_seq_reset(khdl);
714 evas_object_smart_callback_call(ty->obj, "tab,8", NULL);
715 return EINA_TRUE;
716 }
717 else if (!strcmp(ev->key, "9"))
718 {
719 keyin_compose_seq_reset(khdl);
720 evas_object_smart_callback_call(ty->obj, "tab,9", NULL);
721 return EINA_TRUE;
722 }
723 else if (!strcmp(ev->key, "0"))
724 {
725 keyin_compose_seq_reset(khdl);
726 evas_object_smart_callback_call(ty->obj, "tab,0", NULL);
727 return EINA_TRUE;
728 }
729 }
730 if ((!alt) && (ctrl) && (shift))
731 {
732 if (!strcmp(ev->key, "Prior"))
733 {
734 keyin_compose_seq_reset(khdl);
735 evas_object_smart_callback_call(ty->obj, "split,h", NULL);
736 return EINA_TRUE;
737 }
738 else if (!strcmp(ev->key, "Next"))
739 {
740 keyin_compose_seq_reset(khdl);
741 evas_object_smart_callback_call(ty->obj, "split,v", NULL);
742 return EINA_TRUE;
743 }
744 else if (!strcasecmp(ev->key, "t"))
745 {
746 keyin_compose_seq_reset(khdl);
747 evas_object_smart_callback_call(ty->obj, "new", NULL);
748 return EINA_TRUE;
749 }
750 else if (!strcmp(ev->key, "Home"))
751 {
752 keyin_compose_seq_reset(khdl);
753 evas_object_smart_callback_call(ty->obj, "select", NULL);
754 return EINA_TRUE;
755 }
756 else if (!strcasecmp(ev->key, "c"))
757 {
758 keyin_compose_seq_reset(khdl);
759 termio_take_selection(ty->obj, ELM_SEL_TYPE_CLIPBOARD);
760 return EINA_TRUE;
761 }
762 else if (!strcasecmp(ev->key, "v"))
763 {
764 keyin_compose_seq_reset(khdl);
765 termio_paste_selection(ty->obj, ELM_SEL_TYPE_CLIPBOARD);
766 return EINA_TRUE;
767 }
768 else if (!strcasecmp(ev->keyname, "h"))
769 {
770 term_miniview_toggle(termio_term_get(ty->obj));
771 return EINA_TRUE;
772 }
773 }
774 if ((alt) && (!shift) && (!ctrl))
775 {
776 if (!strcmp(ev->key, "Home"))
777 {
778 keyin_compose_seq_reset(khdl);
779 evas_object_smart_callback_call(ty->obj, "cmdbox", NULL);
780 return EINA_TRUE;
781 }
782 }
783 if ((alt) && (ctrl) && (!shift))
784 {
785 if (_handle_alt_ctrl(ev->key, ty->obj))
786 {
787 keyin_compose_seq_reset(khdl);
788 return EINA_TRUE;
789 }
790 }
791 if (shift)
792 {
793 if (_handle_shift(ev, ty))
794 {
795 keyin_compose_seq_reset(khdl);
796 return EINA_TRUE;
797 } 572 }
798 } 573 }
799 574
800
801 /* actions => return Eina_True */
802
803 /* composing */ 575 /* composing */
804 if (khdl->imf) 576 if (khdl->imf)
805 { 577 {
@@ -904,6 +676,9 @@ keyin_handle_up(Keys_Handler *khdl, Evas_Event_Key_Up *ev)
904 } 676 }
905} 677}
906 678
679/* }}} */
680/* {{{ Callbacks */
681
907static Eina_Bool 682static Eina_Bool
908cb_term_prev(Evas_Object *term) 683cb_term_prev(Evas_Object *term)
909{ 684{
@@ -911,6 +686,190 @@ cb_term_prev(Evas_Object *term)
911 return EINA_TRUE; 686 return EINA_TRUE;
912} 687}
913 688
689static Eina_Bool
690cb_term_next(Evas_Object *term)
691{
692 evas_object_smart_callback_call(term, "next", NULL);
693 return EINA_TRUE;
694}
695
696#define CB_TAB(N)\
697static Eina_Bool \
698cb_tab_##N(Evas_Object *term) \
699{ \
700 evas_object_smart_callback_call(term, "tab,"#N, NULL); \
701 return EINA_TRUE; \
702}
703
704CB_TAB(0)
705CB_TAB(1)
706CB_TAB(2)
707CB_TAB(3)
708CB_TAB(4)
709CB_TAB(5)
710CB_TAB(6)
711CB_TAB(7)
712CB_TAB(8)
713CB_TAB(9)
714#undef CB_TAB
715
716static Eina_Bool
717cb_cmd_box(Evas_Object *term)
718{
719 evas_object_smart_callback_call(term, "cmdbox", NULL);
720 return EINA_TRUE;
721}
722
723static Eina_Bool
724cb_split_h(Evas_Object *term)
725{
726 evas_object_smart_callback_call(term, "split,h", NULL);
727 return EINA_TRUE;
728}
729
730static Eina_Bool
731cb_split_v(Evas_Object *term)
732{
733 evas_object_smart_callback_call(term, "split,v", NULL);
734 return EINA_TRUE;
735}
736
737static Eina_Bool
738cb_tab_new(Evas_Object *term)
739{
740 evas_object_smart_callback_call(term, "new", NULL);
741 return EINA_TRUE;
742}
743
744static Eina_Bool
745cb_tab_select(Evas_Object *term)
746{
747 evas_object_smart_callback_call(term, "select", NULL);
748 return EINA_TRUE;
749}
750
751static Eina_Bool
752cb_copy_clipboard(Evas_Object *term)
753{
754 Termpty *ty = termio_pty_get(term);
755
756 if (!ty || !ty->selection.is_active)
757 return EINA_FALSE;
758 termio_take_selection(term, ELM_SEL_TYPE_CLIPBOARD);
759 return EINA_TRUE;
760}
761
762static Eina_Bool
763cb_paste_clipboard(Evas_Object *term)
764{
765 termio_paste_selection(term, ELM_SEL_TYPE_CLIPBOARD);
766 return EINA_TRUE;
767}
768
769static Eina_Bool
770cb_paste_primary(Evas_Object *term)
771{
772 termio_paste_selection(term, ELM_SEL_TYPE_PRIMARY);
773 return EINA_TRUE;
774}
775
776static Eina_Bool
777cb_copy_primary(Evas_Object *term)
778{
779 Termpty *ty = termio_pty_get(term);
780
781 if (!ty || !ty->selection.is_active)
782 return EINA_FALSE;
783 termio_take_selection(term, ELM_SEL_TYPE_PRIMARY);
784 return EINA_TRUE;
785}
786
787static Eina_Bool
788cb_miniview(Evas_Object *term)
789{
790 term_miniview_toggle(termio_term_get(term));
791 return EINA_TRUE;
792}
793
794static Eina_Bool
795cb_increase_font_size(Evas_Object *term)
796{
797 termcmd_do(term, NULL, NULL, "f+");
798 return EINA_TRUE;
799}
800
801static Eina_Bool
802cb_decrease_font_size(Evas_Object *term)
803{
804 termcmd_do(term, NULL, NULL, "f-");
805 return EINA_TRUE;
806}
807
808static Eina_Bool
809cb_reset_font_size(Evas_Object *term)
810{
811 termcmd_do(term, NULL, NULL, "f");
812 return EINA_TRUE;
813}
814
815static Eina_Bool
816cb_big_font_size(Evas_Object *term)
817{
818 termcmd_do(term, NULL, NULL, "fb");
819 return EINA_TRUE;
820}
821
822static Eina_Bool
823cb_scroll_up_page(Evas_Object *term)
824{
825 Termpty *ty = termio_pty_get(term);
826
827 if (!ty || ty->altbuf)
828 return EINA_FALSE;
829
830 termio_scroll_delta(term, 1, 1);
831 return EINA_TRUE;
832}
833
834static Eina_Bool
835cb_scroll_down_page(Evas_Object *term)
836{
837 Termpty *ty = termio_pty_get(term);
838
839 if (!ty || ty->altbuf)
840 return EINA_FALSE;
841
842 termio_scroll_delta(term, -1, 1);
843 return EINA_TRUE;
844}
845
846static Eina_Bool
847cb_scroll_up_line(Evas_Object *term)
848{
849 Termpty *ty = termio_pty_get(term);
850
851 if (!ty || ty->altbuf)
852 return EINA_FALSE;
853
854 termio_scroll_delta(term, 1, 0);
855 return EINA_TRUE;
856}
857
858static Eina_Bool
859cb_scroll_down_line(Evas_Object *term)
860{
861 Termpty *ty = termio_pty_get(term);
862
863 if (!ty || ty->altbuf)
864 return EINA_FALSE;
865
866 termio_scroll_delta(term, -1, 0);
867 return EINA_TRUE;
868}
869
870/* }}} */
871/* {{{ Key bindings */
872
914static unsigned int 873static unsigned int
915key_binding_key_length(EINA_UNUSED const void *key) 874key_binding_key_length(EINA_UNUSED const void *key)
916{ 875{
@@ -987,11 +946,58 @@ int key_bindings_init(void)
987 5); 946 5);
988 if (!_key_bindings) return -1; 947 if (!_key_bindings) return -1;
989 948
990 kb = key_binding_new("Prior", 1, 0, 0, cb_term_prev); 949#define ADD_KB(Name, Ctrl, Alt, Shift, Cb) \
991 if (!kb) return -1; 950 kb = key_binding_new(Name, Ctrl, Alt, Shift, Cb); \
951 if (!kb) return -1; \
992 if (!eina_hash_direct_add(_key_bindings, kb, kb)) return -1; 952 if (!eina_hash_direct_add(_key_bindings, kb, kb)) return -1;
993 953
994 954 /* Ctrl- */
955 ADD_KB("Prior", 1, 0, 0, cb_term_prev);
956 ADD_KB("Next", 1, 0, 0, cb_term_next);
957 ADD_KB("0", 1, 0, 0, cb_tab_0);
958 ADD_KB("1", 1, 0, 0, cb_tab_1);
959 ADD_KB("2", 1, 0, 0, cb_tab_2);
960 ADD_KB("3", 1, 0, 0, cb_tab_3);
961 ADD_KB("4", 1, 0, 0, cb_tab_4);
962 ADD_KB("5", 1, 0, 0, cb_tab_5);
963 ADD_KB("6", 1, 0, 0, cb_tab_6);
964 ADD_KB("7", 1, 0, 0, cb_tab_7);
965 ADD_KB("8", 1, 0, 0, cb_tab_8);
966 ADD_KB("9", 1, 0, 0, cb_tab_9);
967
968 /* Alt- */
969 ADD_KB("Home", 0, 1, 0, cb_cmd_box);
970 ADD_KB("w", 0, 1, 0, cb_copy_primary);
971 ADD_KB("Return", 0, 1, 0, cb_paste_primary);
972
973 /* Ctrl-Shift- */
974 ADD_KB("Prior", 1, 0, 1, cb_split_h);
975 ADD_KB("Next", 1, 0, 1, cb_split_v);
976 ADD_KB("t", 1, 0, 1, cb_tab_new);
977 ADD_KB("Home", 1, 0, 1, cb_tab_select);
978 ADD_KB("c", 1, 0, 1, cb_copy_clipboard);
979 ADD_KB("v", 1, 0, 1, cb_paste_clipboard);
980 ADD_KB("h", 1, 0, 1, cb_miniview);
981 ADD_KB("Insert", 1, 0, 1, cb_paste_clipboard);
982
983 /* Ctrl-Alt- */
984 ADD_KB("equal", 1, 1, 0, cb_increase_font_size);
985 ADD_KB("minus", 1, 1, 0, cb_decrease_font_size);
986 ADD_KB("0", 1, 1, 0, cb_reset_font_size);
987 ADD_KB("9", 1, 1, 0, cb_big_font_size);
988
989 /* Shift- */
990 ADD_KB("Prior", 0, 0, 1, cb_scroll_up_page);
991 ADD_KB("Next", 0, 0, 1, cb_scroll_down_page);
992 ADD_KB("Up", 0, 0, 1, cb_scroll_up_line);
993 ADD_KB("Down", 0, 0, 1, cb_scroll_down_line);
994 ADD_KB("Insert", 0, 0, 1, cb_paste_primary);
995 ADD_KB("KP_Add", 0, 0, 1, cb_increase_font_size);
996 ADD_KB("KP_Subtract", 0, 0, 1, cb_decrease_font_size);
997 ADD_KB("KP_Multiply", 0, 0, 1, cb_reset_font_size);
998 ADD_KB("KP_Divide", 0, 0, 1, cb_copy_clipboard);
999
1000#undef ADD_KB
995 return 0; 1001 return 0;
996} 1002}
997 1003
@@ -1001,3 +1007,5 @@ void key_bindings_shutdown(void)
1001 eina_hash_free(_key_bindings); 1007 eina_hash_free(_key_bindings);
1002 _key_bindings = NULL; 1008 _key_bindings = NULL;
1003} 1009}
1010
1011/* }}} */