… | |
… | |
101 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
101 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
102 | |
102 | |
103 | return (long)mg->mg_ptr; |
103 | return (long)mg->mg_ptr; |
104 | } |
104 | } |
105 | |
105 | |
106 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
106 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
107 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
107 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
108 | |
108 | |
109 | ///////////////////////////////////////////////////////////////////////////// |
109 | ///////////////////////////////////////////////////////////////////////////// |
110 | |
110 | |
111 | struct perl_watcher |
111 | struct perl_watcher |
… | |
… | |
290 | void |
290 | void |
291 | overlay::show () |
291 | overlay::show () |
292 | { |
292 | { |
293 | char key[33]; sprintf (key, "%32lx", (long)this); |
293 | char key[33]; sprintf (key, "%32lx", (long)this); |
294 | |
294 | |
295 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
295 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
296 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
296 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
297 | } |
297 | } |
298 | |
298 | |
299 | void |
299 | void |
300 | overlay::hide () |
300 | overlay::hide () |
301 | { |
301 | { |
302 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); |
302 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
303 | |
303 | |
304 | if (ovs) |
304 | if (ovs) |
305 | { |
305 | { |
306 | char key[33]; sprintf (key, "%32lx", (long)this); |
306 | char key[33]; sprintf (key, "%32lx", (long)this); |
307 | |
307 | |
… | |
… | |
415 | if (!perl) |
415 | if (!perl) |
416 | return false; |
416 | return false; |
417 | |
417 | |
418 | if (htype == HOOK_INIT) // first hook ever called |
418 | if (htype == HOOK_INIT) // first hook ever called |
419 | { |
419 | { |
420 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
420 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
421 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
421 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
422 | } |
422 | } |
423 | else if (!term->self) |
423 | else if (!term->perl.self) |
424 | return false; // perl not initialized for this instance |
424 | return false; // perl not initialized for this instance |
425 | else if (htype == HOOK_DESTROY) |
425 | else if (htype == HOOK_DESTROY) |
426 | { |
426 | { |
427 | // handled later |
427 | // handled later |
428 | } |
428 | } |
429 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
429 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
430 | { |
430 | { |
431 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
431 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
432 | |
432 | |
433 | if (HvKEYS (hv)) |
433 | if (HvKEYS (hv)) |
434 | { |
434 | { |
435 | hv_iterinit (hv); |
435 | hv_iterinit (hv); |
436 | |
436 | |
… | |
… | |
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_STRING_LEN: |
474 | case DT_STR_LEN: |
475 | { |
475 | { |
476 | char *str = va_arg (ap, char *); |
476 | char *str = va_arg (ap, char *); |
477 | int len = va_arg (ap, int); |
477 | int len = va_arg (ap, int); |
478 | |
478 | |
479 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
479 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
480 | } |
480 | } |
481 | break; |
481 | break; |
|
|
482 | |
|
|
483 | case DT_WCS_LEN: |
|
|
484 | { |
|
|
485 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
486 | int wlen = va_arg (ap, int); |
|
|
487 | |
|
|
488 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
|
|
489 | } |
|
|
490 | break; |
482 | |
491 | |
483 | case DT_XEVENT: |
492 | case DT_XEVENT: |
484 | { |
493 | { |
485 | XEvent *xe = va_arg (ap, XEvent *); |
494 | XEvent *xe = va_arg (ap, XEvent *); |
486 | HV *hv = newHV (); |
495 | HV *hv = newHV (); |
… | |
… | |
530 | |
539 | |
531 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
540 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
532 | } |
541 | } |
533 | break; |
542 | break; |
534 | |
543 | |
535 | case DT_USTRING_LEN: |
|
|
536 | { |
|
|
537 | unicode_t *ustr = va_arg (ap, unicode_t *); |
|
|
538 | int ulen = va_arg (ap, int); |
|
|
539 | wchar_t *wstr = new wchar_t [ulen]; |
|
|
540 | |
|
|
541 | for (int i = ulen; i--; ) |
|
|
542 | wstr [i] = ustr [i]; |
|
|
543 | |
|
|
544 | XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); |
|
|
545 | |
|
|
546 | delete [] wstr; |
|
|
547 | } |
|
|
548 | |
|
|
549 | case DT_END: |
544 | case DT_END: |
550 | { |
545 | { |
551 | va_end (ap); |
546 | va_end (ap); |
552 | |
547 | |
553 | PUTBACK; |
548 | PUTBACK; |
… | |
… | |
567 | if (SvTRUE (ERRSV)) |
562 | if (SvTRUE (ERRSV)) |
568 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
563 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
569 | |
564 | |
570 | if (htype == HOOK_DESTROY) |
565 | if (htype == HOOK_DESTROY) |
571 | { |
566 | { |
572 | clearSVptr ((SV *)term->self); |
567 | clearSVptr ((SV *)term->perl.self); |
573 | SvREFCNT_dec ((SV *)term->self); |
568 | SvREFCNT_dec ((SV *)term->perl.self); |
574 | } |
569 | } |
575 | |
570 | |
576 | return count; |
571 | return count; |
577 | } |
572 | } |
578 | |
573 | |
… | |
… | |
588 | |
583 | |
589 | PROTOTYPES: ENABLE |
584 | PROTOTYPES: ENABLE |
590 | |
585 | |
591 | BOOT: |
586 | BOOT: |
592 | { |
587 | { |
|
|
588 | HV *stash = gv_stashpv ("urxvt", 1); |
593 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
589 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
|
|
590 | |
594 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
591 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
595 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
592 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
596 | # include "hookinc.h" |
593 | # include "hookinc.h" |
597 | # undef def |
594 | # undef def |
598 | |
595 | |
|
|
596 | |
599 | export_const (DEFAULT_RSTYLE); |
597 | export_const_iv (DEFAULT_RSTYLE); |
600 | export_const (OVERLAY_RSTYLE); |
598 | export_const_iv (OVERLAY_RSTYLE); |
601 | export_const (RS_Bold); |
599 | export_const_iv (RS_Bold); |
602 | export_const (RS_Italic); |
600 | export_const_iv (RS_Italic); |
603 | export_const (RS_Blink); |
601 | export_const_iv (RS_Blink); |
604 | export_const (RS_RVid); |
602 | export_const_iv (RS_RVid); |
605 | export_const (RS_Uline); |
603 | export_const_iv (RS_Uline); |
|
|
604 | export_const_iv (CurrentTime); |
606 | |
605 | |
607 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
606 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
608 | } |
607 | } |
609 | |
608 | |
610 | SV * |
609 | SV * |
611 | new (...) |
610 | new (...) |
612 | CODE: |
611 | CODE: |
… | |
… | |
630 | { |
629 | { |
631 | term->destroy (); |
630 | term->destroy (); |
632 | croak ("exception caught while initializing new terminal instance"); |
631 | croak ("exception caught while initializing new terminal instance"); |
633 | } |
632 | } |
634 | |
633 | |
635 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
634 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
636 | } |
635 | } |
637 | OUTPUT: |
636 | OUTPUT: |
638 | RETVAL |
637 | RETVAL |
639 | |
638 | |
640 | void |
639 | void |
… | |
… | |
709 | |
708 | |
710 | MODULE = urxvt PACKAGE = urxvt::term |
709 | MODULE = urxvt PACKAGE = urxvt::term |
711 | |
710 | |
712 | void |
711 | void |
713 | rxvt_term::destroy () |
712 | rxvt_term::destroy () |
|
|
713 | |
|
|
714 | void |
|
|
715 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
716 | CODE: |
|
|
717 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
718 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
719 | GrabModeSync, GrabModeSync, None, None); |
|
|
720 | |
|
|
721 | bool |
|
|
722 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
723 | CODE: |
|
|
724 | { |
|
|
725 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
726 | |
|
|
727 | THIS->perl.grabtime = 0; |
|
|
728 | |
|
|
729 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
730 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
731 | mode, mode, None, None, eventtime)) |
|
|
732 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
733 | THIS->perl.grabtime = eventtime; |
|
|
734 | else |
|
|
735 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
736 | |
|
|
737 | RETVAL = !!THIS->perl.grabtime; |
|
|
738 | } |
|
|
739 | OUTPUT: |
|
|
740 | RETVAL |
|
|
741 | |
|
|
742 | void |
|
|
743 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
|
|
744 | CODE: |
|
|
745 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
|
|
746 | |
|
|
747 | void |
|
|
748 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
|
|
749 | CODE: |
|
|
750 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
|
|
751 | |
|
|
752 | void |
|
|
753 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
|
|
754 | CODE: |
|
|
755 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
|
|
756 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
|
|
757 | |
|
|
758 | void |
|
|
759 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
|
|
760 | CODE: |
|
|
761 | THIS->perl.grabtime = 0; |
|
|
762 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
763 | XUngrabPointer (THIS->display->display, eventtime); |
714 | |
764 | |
715 | int |
765 | int |
716 | rxvt_term::strwidth (SV *str) |
766 | rxvt_term::strwidth (SV *str) |
717 | CODE: |
767 | CODE: |
718 | { |
768 | { |
… | |
… | |
853 | |
903 | |
854 | if (GIMME_V != G_VOID) |
904 | if (GIMME_V != G_VOID) |
855 | { |
905 | { |
856 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
906 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
857 | |
907 | |
858 | for (int col = 0; col <THIS->ncol; col++) |
908 | for (int col = 0; col < THIS->ncol; col++) |
859 | wstr [col] = l.t [col]; |
909 | wstr [col] = l.t [col]; |
860 | |
910 | |
861 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
911 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
862 | |
912 | |
863 | delete [] wstr; |
913 | delete [] wstr; |
864 | } |
914 | } |
865 | |
915 | |
866 | if (new_text) |
916 | if (new_text) |
… | |
… | |
956 | } |
1006 | } |
957 | OUTPUT: |
1007 | OUTPUT: |
958 | RETVAL |
1008 | RETVAL |
959 | |
1009 | |
960 | SV * |
1010 | SV * |
961 | rxvt_term::special_encode (SV *str) |
1011 | rxvt_term::special_encode (SV *string) |
962 | CODE: |
1012 | CODE: |
963 | abort ();//TODO |
1013 | { |
|
|
1014 | wchar_t *wstr = sv2wcs (string); |
|
|
1015 | int wlen = wcslen (wstr); |
|
|
1016 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1017 | |
|
|
1018 | rxvt_push_locale (THIS->locale); |
|
|
1019 | |
|
|
1020 | wchar_t *r = rstr; |
|
|
1021 | for (wchar_t *s = wstr; *s; s++) |
|
|
1022 | if (wcwidth (*s) == 0) |
|
|
1023 | { |
|
|
1024 | if (r == rstr) |
|
|
1025 | croak ("leading combining character unencodable"); |
|
|
1026 | |
|
|
1027 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1028 | if (n == NOCHAR) |
|
|
1029 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1030 | |
|
|
1031 | r[-1] = n; |
|
|
1032 | } |
|
|
1033 | #if !UNICODE_3 |
|
|
1034 | else if (*s >= 0x10000) |
|
|
1035 | *r++ = rxvt_composite.compose (*s); |
|
|
1036 | #endif |
|
|
1037 | else |
|
|
1038 | *r++ = *s; |
|
|
1039 | |
|
|
1040 | rxvt_pop_locale (); |
|
|
1041 | |
|
|
1042 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1043 | |
|
|
1044 | delete [] rstr; |
|
|
1045 | } |
|
|
1046 | OUTPUT: |
|
|
1047 | RETVAL |
964 | |
1048 | |
965 | SV * |
1049 | SV * |
966 | rxvt_term::special_decode (SV *str) |
1050 | rxvt_term::special_decode (SV *text) |
967 | CODE: |
1051 | CODE: |
968 | abort ();//TODO |
1052 | { |
|
|
1053 | wchar_t *wstr = sv2wcs (text); |
|
|
1054 | int wlen = wcslen (wstr); |
|
|
1055 | int dlen = 0; |
|
|
1056 | |
|
|
1057 | // find length |
|
|
1058 | for (wchar_t *s = wstr; *s; s++) |
|
|
1059 | if (*s == NOCHAR) |
|
|
1060 | ; |
|
|
1061 | else if (IS_COMPOSE (*s)) |
|
|
1062 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1063 | else |
|
|
1064 | dlen++; |
|
|
1065 | |
|
|
1066 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1067 | |
|
|
1068 | // decode |
|
|
1069 | wchar_t *r = rstr; |
|
|
1070 | for (wchar_t *s = wstr; *s; s++) |
|
|
1071 | if (*s == NOCHAR) |
|
|
1072 | ; |
|
|
1073 | else if (IS_COMPOSE (*s)) |
|
|
1074 | r += rxvt_composite.expand (*s, r); |
|
|
1075 | else |
|
|
1076 | *r++ = *s; |
|
|
1077 | |
|
|
1078 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1079 | |
|
|
1080 | delete [] rstr; |
|
|
1081 | } |
|
|
1082 | OUTPUT: |
|
|
1083 | RETVAL |
969 | |
1084 | |
970 | void |
1085 | void |
971 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1086 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
972 | PPCODE: |
1087 | PPCODE: |
973 | { |
1088 | { |
… | |
… | |
1038 | THIS->want_refresh = 1; |
1153 | THIS->want_refresh = 1; |
1039 | } |
1154 | } |
1040 | } |
1155 | } |
1041 | |
1156 | |
1042 | int |
1157 | int |
1043 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1158 | rxvt_term::selection_grab (U32 eventtime) |
1044 | |
1159 | |
1045 | void |
1160 | void |
1046 | rxvt_term::selection (SV *newtext = 0) |
1161 | rxvt_term::selection (SV *newtext = 0) |
1047 | PPCODE: |
1162 | PPCODE: |
1048 | { |
1163 | { |
… | |
… | |
1061 | void |
1176 | void |
1062 | rxvt_term::scr_add_lines (SV *string) |
1177 | rxvt_term::scr_add_lines (SV *string) |
1063 | CODE: |
1178 | CODE: |
1064 | { |
1179 | { |
1065 | wchar_t *wstr = sv2wcs (string); |
1180 | wchar_t *wstr = sv2wcs (string); |
1066 | int wlen = wcslen (wstr); |
|
|
1067 | unicode_t *ustr = new unicode_t [wlen]; |
|
|
1068 | int nlines = 0; |
|
|
1069 | |
|
|
1070 | for (int i = wlen; i--; ) |
|
|
1071 | { |
|
|
1072 | ustr [i] = wstr [i]; |
|
|
1073 | nlines += ustr [i] == '\012'; |
|
|
1074 | } |
|
|
1075 | |
|
|
1076 | THIS->scr_add_lines (ustr, nlines, wlen); |
1181 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
1077 | |
|
|
1078 | free (wstr); |
1182 | free (wstr); |
1079 | delete [] ustr; |
|
|
1080 | } |
1183 | } |
1081 | |
1184 | |
1082 | void |
1185 | void |
1083 | rxvt_term::tt_write (SV *octets) |
1186 | rxvt_term::tt_write (SV *octets) |
1084 | INIT: |
1187 | INIT: |
… | |
… | |
1098 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1201 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1099 | |
1202 | |
1100 | THIS->cmdbuf_ptr = str; |
1203 | THIS->cmdbuf_ptr = str; |
1101 | THIS->cmdbuf_endp = str + len; |
1204 | THIS->cmdbuf_endp = str + len; |
1102 | |
1205 | |
|
|
1206 | rxvt_push_locale (THIS->locale); |
1103 | THIS->cmd_parse (); |
1207 | THIS->cmd_parse (); |
|
|
1208 | rxvt_pop_locale (); |
1104 | |
1209 | |
1105 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1210 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1106 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1211 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1107 | } |
1212 | } |
1108 | |
1213 | |