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 | } |
|
|
490 | break; |
484 | |
491 | |
485 | delete [] wstr; |
492 | case DT_XEVENT: |
486 | } |
493 | { |
|
|
494 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
495 | HV *hv = newHV (); |
|
|
496 | |
|
|
497 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
498 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
499 | # undef set |
|
|
500 | |
|
|
501 | setiv (type, xe->type); |
|
|
502 | setiv (send_event, xe->xany.send_event); |
|
|
503 | setiv (serial, xe->xany.serial); |
|
|
504 | |
|
|
505 | switch (xe->type) |
|
|
506 | { |
|
|
507 | case KeyPress: |
|
|
508 | case KeyRelease: |
|
|
509 | case ButtonPress: |
|
|
510 | case ButtonRelease: |
|
|
511 | case MotionNotify: |
|
|
512 | setiv (time, xe->xmotion.time); |
|
|
513 | setiv (x, xe->xmotion.x); |
|
|
514 | setiv (y, xe->xmotion.y); |
|
|
515 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
516 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
517 | setiv (x_root, xe->xmotion.x_root); |
|
|
518 | setiv (y_root, xe->xmotion.y_root); |
|
|
519 | setiv (state, xe->xmotion.state); |
|
|
520 | break; |
|
|
521 | } |
|
|
522 | |
|
|
523 | switch (xe->type) |
|
|
524 | { |
|
|
525 | case KeyPress: |
|
|
526 | case KeyRelease: |
|
|
527 | setiv (keycode, xe->xkey.keycode); |
|
|
528 | break; |
|
|
529 | |
|
|
530 | case ButtonPress: |
|
|
531 | case ButtonRelease: |
|
|
532 | setiv (button, xe->xbutton.button); |
|
|
533 | break; |
|
|
534 | |
|
|
535 | case MotionNotify: |
|
|
536 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
537 | break; |
|
|
538 | } |
|
|
539 | |
|
|
540 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
541 | } |
|
|
542 | break; |
487 | |
543 | |
488 | case DT_END: |
544 | case DT_END: |
489 | { |
545 | { |
490 | va_end (ap); |
546 | va_end (ap); |
491 | |
547 | |
… | |
… | |
544 | export_const (RS_Uline); |
600 | export_const (RS_Uline); |
545 | |
601 | |
546 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
602 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
547 | } |
603 | } |
548 | |
604 | |
|
|
605 | SV * |
|
|
606 | new (...) |
|
|
607 | CODE: |
|
|
608 | { |
|
|
609 | stringvec *argv = new stringvec; |
|
|
610 | bool success; |
|
|
611 | |
|
|
612 | for (int i = 0; i < items ;i++) |
|
|
613 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
614 | |
|
|
615 | rxvt_term *term = new rxvt_term; |
|
|
616 | |
|
|
617 | term->argv = argv; |
|
|
618 | |
|
|
619 | try |
|
|
620 | { |
|
|
621 | if (!term->init (argv->size (), argv->begin ())) |
|
|
622 | term = 0; |
|
|
623 | } |
|
|
624 | catch (const class rxvt_failure_exception &e) |
|
|
625 | { |
|
|
626 | term->destroy (); |
|
|
627 | croak ("exception caught while initializing new terminal instance"); |
|
|
628 | } |
|
|
629 | |
|
|
630 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
|
|
631 | } |
|
|
632 | OUTPUT: |
|
|
633 | RETVAL |
|
|
634 | |
549 | void |
635 | void |
550 | set_should_invoke (int htype, int value) |
636 | set_should_invoke (int htype, int value) |
551 | CODE: |
637 | CODE: |
552 | rxvt_perl.should_invoke [htype] = value; |
638 | rxvt_perl.should_invoke [htype] = value; |
553 | |
639 | |
… | |
… | |
615 | } |
701 | } |
616 | OUTPUT: |
702 | OUTPUT: |
617 | RETVAL |
703 | RETVAL |
618 | |
704 | |
619 | MODULE = urxvt PACKAGE = urxvt::term |
705 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
706 | |
|
|
707 | void |
|
|
708 | rxvt_term::destroy () |
|
|
709 | |
|
|
710 | void |
|
|
711 | rxvt_term::grab (int eventtime) |
|
|
712 | CODE: |
|
|
713 | { |
|
|
714 | return; |
|
|
715 | XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
716 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
717 | GrabModeAsync, GrabModeAsync, None, None, eventtime); |
|
|
718 | XGrabKeyboard (THIS->display->display, THIS->vt, 0, GrabModeAsync, GrabModeAsync, eventtime); |
|
|
719 | } |
620 | |
720 | |
621 | int |
721 | int |
622 | rxvt_term::strwidth (SV *str) |
722 | rxvt_term::strwidth (SV *str) |
623 | CODE: |
723 | CODE: |
624 | { |
724 | { |
… | |
… | |
703 | RETVAL = *(int *)((char *)THIS + ix); |
803 | RETVAL = *(int *)((char *)THIS + ix); |
704 | OUTPUT: |
804 | OUTPUT: |
705 | RETVAL |
805 | RETVAL |
706 | |
806 | |
707 | U32 |
807 | U32 |
|
|
808 | rxvt_term::parent () |
|
|
809 | CODE: |
|
|
810 | RETVAL = (U32)THIS->parent [0]; |
|
|
811 | OUTPUT: |
|
|
812 | RETVAL |
|
|
813 | |
|
|
814 | U32 |
|
|
815 | rxvt_term::vt () |
|
|
816 | CODE: |
|
|
817 | RETVAL = (U32)THIS->vt; |
|
|
818 | OUTPUT: |
|
|
819 | RETVAL |
|
|
820 | |
|
|
821 | U32 |
708 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
822 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
709 | CODE: |
823 | CODE: |
710 | { |
824 | { |
711 | RETVAL = THIS->rstyle; |
825 | RETVAL = THIS->rstyle; |
712 | THIS->rstyle = new_rstyle; |
826 | THIS->rstyle = new_rstyle; |
… | |
… | |
745 | |
859 | |
746 | if (GIMME_V != G_VOID) |
860 | if (GIMME_V != G_VOID) |
747 | { |
861 | { |
748 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
862 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
749 | |
863 | |
750 | for (int col = 0; col <THIS->ncol; col++) |
864 | for (int col = 0; col < THIS->ncol; col++) |
751 | wstr [col] = l.t [col]; |
865 | wstr [col] = l.t [col]; |
752 | |
866 | |
753 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
867 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
754 | |
868 | |
755 | delete [] wstr; |
869 | delete [] wstr; |
756 | } |
870 | } |
757 | |
871 | |
758 | if (new_text) |
872 | if (new_text) |
… | |
… | |
848 | } |
962 | } |
849 | OUTPUT: |
963 | OUTPUT: |
850 | RETVAL |
964 | RETVAL |
851 | |
965 | |
852 | SV * |
966 | SV * |
853 | rxvt_term::special_encode (SV *str) |
967 | rxvt_term::special_encode (SV *string) |
854 | CODE: |
968 | CODE: |
855 | abort ();//TODO |
969 | { |
|
|
970 | wchar_t *wstr = sv2wcs (string); |
|
|
971 | int wlen = wcslen (wstr); |
|
|
972 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
973 | |
|
|
974 | rxvt_push_locale (THIS->locale); |
|
|
975 | |
|
|
976 | wchar_t *r = rstr; |
|
|
977 | for (wchar_t *s = wstr; *s; s++) |
|
|
978 | if (wcwidth (*s) == 0) |
|
|
979 | { |
|
|
980 | if (r == rstr) |
|
|
981 | croak ("leading combining character unencodable"); |
|
|
982 | |
|
|
983 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
984 | if (n == NOCHAR) |
|
|
985 | n = rxvt_composite.compose (r[-1], *s); |
|
|
986 | |
|
|
987 | r[-1] = n; |
|
|
988 | } |
|
|
989 | #if !UNICODE_3 |
|
|
990 | else if (*s >= 0x10000) |
|
|
991 | *r++ = rxvt_composite.compose (*s); |
|
|
992 | #endif |
|
|
993 | else |
|
|
994 | *r++ = *s; |
|
|
995 | |
|
|
996 | rxvt_pop_locale (); |
|
|
997 | |
|
|
998 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
999 | |
|
|
1000 | delete [] rstr; |
|
|
1001 | } |
|
|
1002 | OUTPUT: |
|
|
1003 | RETVAL |
856 | |
1004 | |
857 | SV * |
1005 | SV * |
858 | rxvt_term::special_decode (SV *str) |
1006 | rxvt_term::special_decode (SV *text) |
859 | CODE: |
1007 | CODE: |
860 | abort ();//TODO |
1008 | { |
|
|
1009 | wchar_t *wstr = sv2wcs (text); |
|
|
1010 | int wlen = wcslen (wstr); |
|
|
1011 | int dlen = 0; |
|
|
1012 | |
|
|
1013 | // find length |
|
|
1014 | for (wchar_t *s = wstr; *s; s++) |
|
|
1015 | if (*s == NOCHAR) |
|
|
1016 | ; |
|
|
1017 | else if (IS_COMPOSE (*s)) |
|
|
1018 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1019 | else |
|
|
1020 | dlen++; |
|
|
1021 | |
|
|
1022 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1023 | |
|
|
1024 | // decode |
|
|
1025 | wchar_t *r = rstr; |
|
|
1026 | for (wchar_t *s = wstr; *s; s++) |
|
|
1027 | if (*s == NOCHAR) |
|
|
1028 | ; |
|
|
1029 | else if (IS_COMPOSE (*s)) |
|
|
1030 | r += rxvt_composite.expand (*s, r); |
|
|
1031 | else |
|
|
1032 | *r++ = *s; |
|
|
1033 | |
|
|
1034 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1035 | |
|
|
1036 | delete [] rstr; |
|
|
1037 | } |
|
|
1038 | OUTPUT: |
|
|
1039 | RETVAL |
861 | |
1040 | |
862 | void |
1041 | void |
863 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1042 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
864 | PPCODE: |
1043 | PPCODE: |
865 | { |
1044 | { |
… | |
… | |
953 | void |
1132 | void |
954 | rxvt_term::scr_add_lines (SV *string) |
1133 | rxvt_term::scr_add_lines (SV *string) |
955 | CODE: |
1134 | CODE: |
956 | { |
1135 | { |
957 | wchar_t *wstr = sv2wcs (string); |
1136 | wchar_t *wstr = sv2wcs (string); |
958 | int wlen = wcslen (wstr); |
|
|
959 | unicode_t *ustr = new unicode_t [wlen]; |
|
|
960 | int nlines = 0; |
|
|
961 | |
|
|
962 | for (int i = wlen; i--; ) |
|
|
963 | { |
|
|
964 | ustr [i] = wstr [i]; |
|
|
965 | nlines += ustr [i] == '\012'; |
|
|
966 | } |
|
|
967 | |
|
|
968 | THIS->scr_add_lines (ustr, nlines, wlen); |
1137 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
969 | |
|
|
970 | free (wstr); |
1138 | free (wstr); |
971 | delete [] ustr; |
|
|
972 | } |
1139 | } |
973 | |
1140 | |
974 | void |
1141 | void |
975 | rxvt_term::tt_write (SV *octets) |
1142 | rxvt_term::tt_write (SV *octets) |
976 | INIT: |
1143 | INIT: |
977 | STRLEN len; |
1144 | STRLEN len; |
978 | char *str = SvPVbyte (octets, len); |
1145 | char *str = SvPVbyte (octets, len); |
979 | C_ARGS: |
1146 | C_ARGS: |
980 | str, len |
1147 | str, len |
981 | |
1148 | |
|
|
1149 | void |
|
|
1150 | rxvt_term::cmd_parse (SV *octets) |
|
|
1151 | CODE: |
|
|
1152 | { |
|
|
1153 | STRLEN len; |
|
|
1154 | char *str = SvPVbyte (octets, len); |
|
|
1155 | |
|
|
1156 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1157 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1158 | |
|
|
1159 | THIS->cmdbuf_ptr = str; |
|
|
1160 | THIS->cmdbuf_endp = str + len; |
|
|
1161 | |
|
|
1162 | rxvt_push_locale (THIS->locale); |
|
|
1163 | THIS->cmd_parse (); |
|
|
1164 | rxvt_pop_locale (); |
|
|
1165 | |
|
|
1166 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1167 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1168 | } |
|
|
1169 | |
982 | SV * |
1170 | SV * |
983 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1171 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
984 | CODE: |
1172 | CODE: |
985 | { |
1173 | { |
986 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1174 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |