| ︙ | | |
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
|
+
-
+
-
+
|
#define KEY_PRESSED(k) \
(inst->keystate[(k) / 32] & (1 << ((k) % 32)))
gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
struct gui_data *inst = (struct gui_data *)data;
char output[32];
wchar_t ucsoutput[2];
int start, end, special;
int ucsval, start, end, special, use_ucsoutput;
/* By default, nothing is generated. */
end = start = 0;
special = FALSE;
special = use_ucsoutput = FALSE;
/*
* If Alt is being released after typing an Alt+numberpad
* sequence, we should generate the code that was typed.
*
* Note that we only do this if more than one key was actually
* pressed - I don't think Alt+NumPad4 should be ^D or that
|
| ︙ | | |
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
|
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
|
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
|
*/
if (event->keyval == GDK_Insert && (event->state & GDK_SHIFT_MASK)) {
request_paste(inst);
return TRUE;
}
special = FALSE;
use_ucsoutput = FALSE;
/* ALT+things gives leading Escape. */
output[0] = '\033';
strncpy(output+1, event->string, 31);
if (!*event->string &&
(ucsval = keysym_to_unicode(event->keyval)) >= 0) {
ucsoutput[0] = '\033';
ucsoutput[1] = ucsval;
use_ucsoutput = TRUE;
end = 2;
} else {
output[31] = '\0';
end = strlen(output);
output[31] = '\0';
end = strlen(output);
}
if (event->state & GDK_MOD1_MASK) {
start = 0;
if (end == 1) end = 0;
} else
start = 1;
/* Control-` is the same as Control-\ (unless gtk has a better idea) */
if (!event->string[0] && event->keyval == '`' &&
(event->state & GDK_CONTROL_MASK)) {
output[1] = '\x1C';
use_ucsoutput = FALSE;
end = 2;
}
/* Control-Break is the same as Control-C */
if (event->keyval == GDK_Break &&
(event->state & GDK_CONTROL_MASK)) {
output[1] = '\003';
use_ucsoutput = FALSE;
end = 2;
special = TRUE;
}
/* We handle Return ourselves, because it needs to be flagged as
* special to ldisc. */
if (event->keyval == GDK_Return) {
output[1] = '\015';
use_ucsoutput = FALSE;
end = 2;
special = TRUE;
}
/* Control-2, Control-Space and Control-@ are NUL */
if (!event->string[0] &&
(event->keyval == ' ' || event->keyval == '2' ||
event->keyval == '@') &&
(event->state & (GDK_SHIFT_MASK |
GDK_CONTROL_MASK)) == GDK_CONTROL_MASK) {
output[1] = '\0';
use_ucsoutput = FALSE;
end = 2;
}
/* Control-Shift-Space is 160 (ISO8859 nonbreaking space) */
if (!event->string[0] && event->keyval == ' ' &&
(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) ==
(GDK_SHIFT_MASK | GDK_CONTROL_MASK)) {
output[1] = '\240';
use_ucsoutput = FALSE;
end = 2;
}
/* We don't let GTK tell us what Backspace is! We know better. */
if (event->keyval == GDK_BackSpace &&
!(event->state & GDK_SHIFT_MASK)) {
output[1] = inst->cfg.bksp_is_delete ? '\x7F' : '\x08';
use_ucsoutput = FALSE;
end = 2;
special = TRUE;
}
/* For Shift Backspace, do opposite of what is configured. */
if (event->keyval == GDK_BackSpace &&
(event->state & GDK_SHIFT_MASK)) {
output[1] = inst->cfg.bksp_is_delete ? '\x08' : '\x7F';
use_ucsoutput = FALSE;
end = 2;
special = TRUE;
}
/* Shift-Tab is ESC [ Z */
if (event->keyval == GDK_ISO_Left_Tab ||
(event->keyval == GDK_Tab && (event->state & GDK_SHIFT_MASK))) {
end = 1 + sprintf(output+1, "\033[Z");
use_ucsoutput = FALSE;
}
/*
* NetHack keypad mode.
*/
if (inst->cfg.nethack_keypad) {
char *keys = NULL;
|
| ︙ | | |
658
659
660
661
662
663
664
665
666
667
668
669
670
671
|
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
|
+
|
}
if (keys) {
end = 2;
if (event->state & GDK_SHIFT_MASK)
output[1] = keys[1];
else
output[1] = keys[0];
use_ucsoutput = FALSE;
goto done;
}
}
/*
* Application keypad mode.
*/
|
| ︙ | | |
710
711
712
713
714
715
716
717
718
719
720
721
722
723
|
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
|
+
|
if (inst->term->vt52_mode) {
if (xkey >= 'P' && xkey <= 'S')
end = 1 + sprintf(output+1, "\033%c", xkey);
else
end = 1 + sprintf(output+1, "\033?%c", xkey);
} else
end = 1 + sprintf(output+1, "\033O%c", xkey);
use_ucsoutput = FALSE;
goto done;
}
}
/*
* Next, all the keys that do tilde codes. (ESC '[' nn '~',
* for integer decimal nn.)
|
| ︙ | | |
813
814
815
816
817
818
819
820
821
822
823
824
825
826
|
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
|
+
|
}
/* Reorder edit keys to physical order */
if (inst->cfg.funky_type == 3 && code <= 6)
code = "\0\2\1\4\5\3\6"[code];
if (inst->term->vt52_mode && code > 0 && code <= 6) {
end = 1 + sprintf(output+1, "\x1B%c", " HLMEIG"[code]);
use_ucsoutput = FALSE;
goto done;
}
if (inst->cfg.funky_type == 5 && /* SCO function keys */
code >= 11 && code <= 34) {
char codes[] = "MNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@[\\]^_`{";
int index = 0;
|
| ︙ | | |
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
|
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
|
+
+
+
+
+
+
+
|
case GDK_F10: index = 9; break;
case GDK_F11: index = 10; break;
case GDK_F12: index = 11; break;
}
if (event->state & GDK_SHIFT_MASK) index += 12;
if (event->state & GDK_CONTROL_MASK) index += 24;
end = 1 + sprintf(output+1, "\x1B[%c", codes[index]);
use_ucsoutput = FALSE;
goto done;
}
if (inst->cfg.funky_type == 5 && /* SCO small keypad */
code >= 1 && code <= 6) {
char codes[] = "HL.FIG";
if (code == 3) {
output[1] = '\x7F';
end = 2;
} else {
end = 1 + sprintf(output+1, "\x1B[%c", codes[code-1]);
}
use_ucsoutput = FALSE;
goto done;
}
if ((inst->term->vt52_mode || inst->cfg.funky_type == 4) &&
code >= 11 && code <= 24) {
int offt = 0;
if (code > 15)
offt++;
if (code > 21)
offt++;
if (inst->term->vt52_mode)
end = 1 + sprintf(output+1,
"\x1B%c", code + 'P' - 11 - offt);
else
end = 1 + sprintf(output+1,
"\x1BO%c", code + 'P' - 11 - offt);
use_ucsoutput = FALSE;
goto done;
}
if (inst->cfg.funky_type == 1 && code >= 11 && code <= 15) {
end = 1 + sprintf(output+1, "\x1B[[%c", code + 'A' - 11);
use_ucsoutput = FALSE;
goto done;
}
if (inst->cfg.funky_type == 2 && code >= 11 && code <= 14) {
if (inst->term->vt52_mode)
end = 1 + sprintf(output+1, "\x1B%c", code + 'P' - 11);
else
end = 1 + sprintf(output+1, "\x1BO%c", code + 'P' - 11);
use_ucsoutput = FALSE;
goto done;
}
if (inst->cfg.rxvt_homeend && (code == 1 || code == 4)) {
end = 1 + sprintf(output+1, code == 1 ? "\x1B[H" : "\x1BOw");
use_ucsoutput = FALSE;
goto done;
}
if (code) {
end = 1 + sprintf(output+1, "\x1B[%d~", code);
use_ucsoutput = FALSE;
goto done;
}
}
/*
* Cursor keys. (This includes the numberpad cursor keys,
* if we haven't already done them due to app keypad mode.)
|
| ︙ | | |
916
917
918
919
920
921
922
923
924
925
926
927
928
929
|
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
|
+
|
end = 1 + sprintf(output+1, "\033%c", xkey);
} else if (!inst->term->app_cursor_keys ^
!(event->state & GDK_CONTROL_MASK)) {
end = 1 + sprintf(output+1, "\033O%c", xkey);
} else {
end = 1 + sprintf(output+1, "\033[%c", xkey);
}
use_ucsoutput = FALSE;
goto done;
}
}
goto done;
}
done:
|
| ︙ | | |
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
|
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
|
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
|
/*
* For special control characters, the character set
* should never matter.
*/
output[end] = '\0'; /* NUL-terminate */
ldisc_send(inst->ldisc, output+start, -2, 1);
} else if (!inst->direct_to_font) {
if (!use_ucsoutput) {
/*
* The stuff we've just generated is assumed to be
* ISO-8859-1! This sounds insane, but `man
* XLookupString' agrees: strings of this type returned
* from the X server are hardcoded to 8859-1. Strictly
* speaking we should be doing this using some sort of
* GtkIMContext, which (if we're lucky) would give us
* our data directly in Unicode; but that's not
* supported in GTK 1.2 as far as I can tell, and it's
* poorly documented even in 2.0, so it'll have to
/*
* The stuff we've just generated is assumed to be
* ISO-8859-1! This sounds insane, but `man
* XLookupString' agrees: strings of this type
* returned from the X server are hardcoded to
* 8859-1. Strictly speaking we should be doing
* this using some sort of GtkIMContext, which (if
* we're lucky) would give us our data directly in
* Unicode; but that's not supported in GTK 1.2 as
* far as I can tell, and it's poorly documented
* even in 2.0, so it'll have to wait.
* wait.
*/
lpage_send(inst->ldisc, CS_ISO8859_1, output+start, end-start, 1);
*/
lpage_send(inst->ldisc, CS_ISO8859_1, output+start,
end-start, 1);
} else {
/*
* We generated our own Unicode key data from the
* keysym, so use that instead.
*/
luni_send(inst->ldisc, ucsoutput+start, end-start, 1);
}
} else {
/*
* In direct-to-font mode, we just send the string
* exactly as we received it.
*/
ldisc_send(inst->ldisc, output+start, end-start, 1);
}
|
| ︙ | | |