1 | /*----------------------------------------------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: rxvtperl.xs |
2 | * File: rxvtperl.xs |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2005-2005 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
… | |
… | |
465 | |
465 | |
466 | case DT_LONG: |
466 | case DT_LONG: |
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
468 | break; |
468 | break; |
469 | |
469 | |
470 | case DT_STRING: |
470 | case DT_STR: |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
472 | break; |
472 | break; |
473 | |
473 | |
474 | case DT_USTRING_LEN: |
474 | case DT_STR_LEN: |
475 | { |
475 | { |
476 | unicode_t *ustr = va_arg (ap, unicode_t *); |
476 | char *str = va_arg (ap, char *); |
477 | int ulen = va_arg (ap, int); |
477 | int len = va_arg (ap, int); |
|
|
478 | |
|
|
479 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
|
|
480 | } |
|
|
481 | break; |
|
|
482 | |
|
|
483 | case DT_WCS_LEN: |
|
|
484 | { |
478 | wchar_t *wstr = new wchar_t [ulen]; |
485 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
486 | int wlen = va_arg (ap, int); |
479 | |
487 | |
480 | for (int i = ulen; i--; ) |
|
|
481 | wstr [i] = ustr [i]; |
|
|
482 | |
|
|
483 | XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); |
488 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
|
|
489 | } |
484 | |
490 | |
485 | delete [] wstr; |
491 | case DT_XEVENT: |
486 | } |
492 | { |
|
|
493 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
494 | HV *hv = newHV (); |
|
|
495 | |
|
|
496 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
497 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
498 | # undef set |
|
|
499 | |
|
|
500 | setiv (type, xe->type); |
|
|
501 | setiv (send_event, xe->xany.send_event); |
|
|
502 | setiv (serial, xe->xany.serial); |
|
|
503 | |
|
|
504 | switch (xe->type) |
|
|
505 | { |
|
|
506 | case KeyPress: |
|
|
507 | case KeyRelease: |
|
|
508 | case ButtonPress: |
|
|
509 | case ButtonRelease: |
|
|
510 | case MotionNotify: |
|
|
511 | setiv (time, xe->xmotion.time); |
|
|
512 | setiv (x, xe->xmotion.x); |
|
|
513 | setiv (y, xe->xmotion.y); |
|
|
514 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
515 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
516 | setiv (x_root, xe->xmotion.x_root); |
|
|
517 | setiv (y_root, xe->xmotion.y_root); |
|
|
518 | setiv (state, xe->xmotion.state); |
|
|
519 | break; |
|
|
520 | } |
|
|
521 | |
|
|
522 | switch (xe->type) |
|
|
523 | { |
|
|
524 | case KeyPress: |
|
|
525 | case KeyRelease: |
|
|
526 | setiv (keycode, xe->xkey.keycode); |
|
|
527 | break; |
|
|
528 | |
|
|
529 | case ButtonPress: |
|
|
530 | case ButtonRelease: |
|
|
531 | setiv (button, xe->xbutton.button); |
|
|
532 | break; |
|
|
533 | |
|
|
534 | case MotionNotify: |
|
|
535 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
536 | break; |
|
|
537 | } |
|
|
538 | |
|
|
539 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
540 | } |
|
|
541 | break; |
487 | |
542 | |
488 | case DT_END: |
543 | case DT_END: |
489 | { |
544 | { |
490 | va_end (ap); |
545 | va_end (ap); |
491 | |
546 | |
… | |
… | |
544 | export_const (RS_Uline); |
599 | export_const (RS_Uline); |
545 | |
600 | |
546 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
601 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
547 | } |
602 | } |
548 | |
603 | |
|
|
604 | SV * |
|
|
605 | new (...) |
|
|
606 | CODE: |
|
|
607 | { |
|
|
608 | stringvec *argv = new stringvec; |
|
|
609 | bool success; |
|
|
610 | |
|
|
611 | for (int i = 0; i < items ;i++) |
|
|
612 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
613 | |
|
|
614 | rxvt_term *term = new rxvt_term; |
|
|
615 | |
|
|
616 | term->argv = argv; |
|
|
617 | |
|
|
618 | try |
|
|
619 | { |
|
|
620 | if (!term->init (argv->size (), argv->begin ())) |
|
|
621 | term = 0; |
|
|
622 | } |
|
|
623 | catch (const class rxvt_failure_exception &e) |
|
|
624 | { |
|
|
625 | term->destroy (); |
|
|
626 | croak ("exception caught while initializing new terminal instance"); |
|
|
627 | } |
|
|
628 | |
|
|
629 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
|
|
630 | } |
|
|
631 | OUTPUT: |
|
|
632 | RETVAL |
|
|
633 | |
549 | void |
634 | void |
550 | set_should_invoke (int htype, int value) |
635 | set_should_invoke (int htype, int value) |
551 | CODE: |
636 | CODE: |
552 | rxvt_perl.should_invoke [htype] = value; |
637 | rxvt_perl.should_invoke [htype] = value; |
553 | |
638 | |
… | |
… | |
615 | } |
700 | } |
616 | OUTPUT: |
701 | OUTPUT: |
617 | RETVAL |
702 | RETVAL |
618 | |
703 | |
619 | MODULE = urxvt PACKAGE = urxvt::term |
704 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
705 | |
|
|
706 | void |
|
|
707 | rxvt_term::destroy () |
620 | |
708 | |
621 | int |
709 | int |
622 | rxvt_term::strwidth (SV *str) |
710 | rxvt_term::strwidth (SV *str) |
623 | CODE: |
711 | CODE: |
624 | { |
712 | { |
… | |
… | |
703 | RETVAL = *(int *)((char *)THIS + ix); |
791 | RETVAL = *(int *)((char *)THIS + ix); |
704 | OUTPUT: |
792 | OUTPUT: |
705 | RETVAL |
793 | RETVAL |
706 | |
794 | |
707 | U32 |
795 | U32 |
|
|
796 | rxvt_term::parent () |
|
|
797 | CODE: |
|
|
798 | RETVAL = (U32)THIS->parent [0]; |
|
|
799 | OUTPUT: |
|
|
800 | RETVAL |
|
|
801 | |
|
|
802 | U32 |
|
|
803 | rxvt_term::vt () |
|
|
804 | CODE: |
|
|
805 | RETVAL = (U32)THIS->vt; |
|
|
806 | OUTPUT: |
|
|
807 | RETVAL |
|
|
808 | |
|
|
809 | U32 |
708 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
810 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
709 | CODE: |
811 | CODE: |
710 | { |
812 | { |
711 | RETVAL = THIS->rstyle; |
813 | RETVAL = THIS->rstyle; |
712 | THIS->rstyle = new_rstyle; |
814 | THIS->rstyle = new_rstyle; |
… | |
… | |
733 | rxvt_term::want_refresh () |
835 | rxvt_term::want_refresh () |
734 | CODE: |
836 | CODE: |
735 | THIS->want_refresh = 1; |
837 | THIS->want_refresh = 1; |
736 | |
838 | |
737 | void |
839 | void |
738 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
840 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
739 | PPCODE: |
841 | PPCODE: |
740 | { |
842 | { |
741 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
843 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
742 | XSRETURN_EMPTY; |
844 | XSRETURN_EMPTY; |
743 | |
845 | |
… | |
… | |
757 | |
859 | |
758 | if (new_text) |
860 | if (new_text) |
759 | { |
861 | { |
760 | wchar_t *wstr = sv2wcs (new_text); |
862 | wchar_t *wstr = sv2wcs (new_text); |
761 | |
863 | |
762 | int len = wcslen (wstr); |
864 | int len = min (wcslen (wstr) - start_ofs, max_len); |
763 | |
865 | |
764 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
866 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
765 | { |
867 | { |
766 | free (wstr); |
868 | free (wstr); |
767 | croak ("new_text extends beyond horizontal margins"); |
869 | croak ("new_text extends beyond horizontal margins"); |
768 | } |
870 | } |
769 | |
871 | |
770 | for (int col = start_col; col < start_col + len; col++) |
872 | for (int col = start_col; col < start_col + len; col++) |
771 | { |
873 | { |
772 | l.t [col] = wstr [col - start_col]; |
874 | l.t [col] = wstr [start_ofs + col - start_col]; |
773 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
875 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
774 | } |
876 | } |
775 | |
877 | |
776 | free (wstr); |
878 | free (wstr); |
777 | } |
879 | } |
778 | } |
880 | } |
779 | |
881 | |
780 | void |
882 | void |
781 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
883 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
782 | PPCODE: |
884 | PPCODE: |
783 | { |
885 | { |
784 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
886 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
785 | XSRETURN_EMPTY; |
887 | XSRETURN_EMPTY; |
786 | |
888 | |
… | |
… | |
801 | { |
903 | { |
802 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
904 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
803 | croak ("new_rend must be arrayref"); |
905 | croak ("new_rend must be arrayref"); |
804 | |
906 | |
805 | AV *av = (AV *)SvRV (new_rend); |
907 | AV *av = (AV *)SvRV (new_rend); |
806 | int len = av_len (av) + 1; |
908 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
807 | |
909 | |
808 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
910 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
809 | croak ("new_rend array extends beyond horizontal margins"); |
911 | croak ("new_rend array extends beyond horizontal margins"); |
810 | |
912 | |
811 | for (int col = start_col; col < start_col + len; col++) |
913 | for (int col = start_col; col < start_col + len; col++) |
812 | { |
914 | { |
813 | rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
915 | rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
814 | |
916 | |
815 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
917 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
816 | } |
918 | } |
817 | } |
919 | } |
818 | } |
920 | } |
819 | |
921 | |
820 | int |
922 | int |
821 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
923 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
822 | CODE: |
924 | CODE: |
823 | { |
925 | { |
824 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
926 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
825 | XSRETURN_EMPTY; |
927 | XSRETURN_EMPTY; |
826 | |
928 | |
827 | line_t &l = ROW(row_number); |
929 | line_t &l = ROW(row_number); |
828 | RETVAL = l.l < 0 ? THIS->ncol : l.l; |
930 | RETVAL = l.l; |
829 | |
931 | |
830 | if (new_length >= -1) |
932 | if (new_length >= 0) |
831 | l.l = new_length; |
933 | l.l = new_length; |
832 | } |
934 | } |
833 | OUTPUT: |
935 | OUTPUT: |
834 | RETVAL |
936 | RETVAL |
835 | |
937 | |
836 | bool |
938 | bool |
837 | rxvt_term::ROW_is_longer (int row_number) |
939 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
838 | CODE: |
940 | CODE: |
839 | { |
941 | { |
840 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
942 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
841 | XSRETURN_EMPTY; |
943 | XSRETURN_EMPTY; |
842 | |
944 | |
843 | line_t &l = ROW(row_number); |
945 | line_t &l = ROW(row_number); |
844 | RETVAL = l.l < 0; |
946 | RETVAL = l.is_longer (); |
|
|
947 | |
|
|
948 | if (new_is_longer >= 0) |
|
|
949 | l.is_longer (new_is_longer); |
845 | } |
950 | } |
846 | OUTPUT: |
951 | OUTPUT: |
847 | RETVAL |
952 | RETVAL |
848 | |
953 | |
849 | SV * |
954 | SV * |
… | |
… | |
950 | void |
1055 | void |
951 | rxvt_term::scr_add_lines (SV *string) |
1056 | rxvt_term::scr_add_lines (SV *string) |
952 | CODE: |
1057 | CODE: |
953 | { |
1058 | { |
954 | wchar_t *wstr = sv2wcs (string); |
1059 | wchar_t *wstr = sv2wcs (string); |
955 | int wlen = wcslen (wstr); |
|
|
956 | unicode_t *ustr = new unicode_t [wlen]; |
|
|
957 | int nlines = 0; |
|
|
958 | |
|
|
959 | for (int i = wlen; i--; ) |
|
|
960 | { |
|
|
961 | ustr [i] = wstr [i]; |
|
|
962 | nlines += ustr [i] == '\012'; |
|
|
963 | } |
|
|
964 | |
|
|
965 | THIS->scr_add_lines (ustr, nlines, wlen); |
1060 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
966 | |
|
|
967 | free (wstr); |
1061 | free (wstr); |
968 | delete [] ustr; |
|
|
969 | } |
1062 | } |
970 | |
1063 | |
971 | void |
1064 | void |
972 | rxvt_term::tt_write (SV *octets) |
1065 | rxvt_term::tt_write (SV *octets) |
973 | INIT: |
1066 | INIT: |
974 | STRLEN len; |
1067 | STRLEN len; |
975 | char *str = SvPVbyte (octets, len); |
1068 | char *str = SvPVbyte (octets, len); |
976 | C_ARGS: |
1069 | C_ARGS: |
977 | str, len |
1070 | str, len |
978 | |
1071 | |
|
|
1072 | void |
|
|
1073 | rxvt_term::cmd_parse (SV *octets) |
|
|
1074 | CODE: |
|
|
1075 | { |
|
|
1076 | STRLEN len; |
|
|
1077 | char *str = SvPVbyte (octets, len); |
|
|
1078 | |
|
|
1079 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1080 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1081 | |
|
|
1082 | THIS->cmdbuf_ptr = str; |
|
|
1083 | THIS->cmdbuf_endp = str + len; |
|
|
1084 | |
|
|
1085 | THIS->cmd_parse (); |
|
|
1086 | |
|
|
1087 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1088 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1089 | } |
|
|
1090 | |
979 | SV * |
1091 | SV * |
980 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1092 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
981 | CODE: |
1093 | CODE: |
982 | { |
1094 | { |
983 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1095 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |