… | |
… | |
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 | |
… | |
… | |
485 | wchar_t *wstr = va_arg (ap, wchar_t *); |
485 | wchar_t *wstr = va_arg (ap, wchar_t *); |
486 | int wlen = va_arg (ap, int); |
486 | int wlen = va_arg (ap, int); |
487 | |
487 | |
488 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
488 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
489 | } |
489 | } |
|
|
490 | break; |
490 | |
491 | |
491 | case DT_XEVENT: |
492 | case DT_XEVENT: |
492 | { |
493 | { |
493 | XEvent *xe = va_arg (ap, XEvent *); |
494 | XEvent *xe = va_arg (ap, XEvent *); |
494 | HV *hv = newHV (); |
495 | HV *hv = newHV (); |
… | |
… | |
561 | if (SvTRUE (ERRSV)) |
562 | if (SvTRUE (ERRSV)) |
562 | 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)); |
563 | |
564 | |
564 | if (htype == HOOK_DESTROY) |
565 | if (htype == HOOK_DESTROY) |
565 | { |
566 | { |
566 | clearSVptr ((SV *)term->self); |
567 | clearSVptr ((SV *)term->perl.self); |
567 | SvREFCNT_dec ((SV *)term->self); |
568 | SvREFCNT_dec ((SV *)term->perl.self); |
568 | } |
569 | } |
569 | |
570 | |
570 | return count; |
571 | return count; |
571 | } |
572 | } |
572 | |
573 | |
… | |
… | |
582 | |
583 | |
583 | PROTOTYPES: ENABLE |
584 | PROTOTYPES: ENABLE |
584 | |
585 | |
585 | BOOT: |
586 | BOOT: |
586 | { |
587 | { |
|
|
588 | HV *stash = gv_stashpv ("urxvt", 1); |
587 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
589 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
|
|
590 | |
588 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
591 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
589 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
592 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
590 | # include "hookinc.h" |
593 | # include "hookinc.h" |
591 | # undef def |
594 | # undef def |
592 | |
595 | |
|
|
596 | |
593 | export_const (DEFAULT_RSTYLE); |
597 | export_const_iv (DEFAULT_RSTYLE); |
594 | export_const (OVERLAY_RSTYLE); |
598 | export_const_iv (OVERLAY_RSTYLE); |
595 | export_const (RS_Bold); |
599 | export_const_iv (RS_Bold); |
596 | export_const (RS_Italic); |
600 | export_const_iv (RS_Italic); |
597 | export_const (RS_Blink); |
601 | export_const_iv (RS_Blink); |
598 | export_const (RS_RVid); |
602 | export_const_iv (RS_RVid); |
599 | export_const (RS_Uline); |
603 | export_const_iv (RS_Uline); |
|
|
604 | export_const_iv (CurrentTime); |
600 | |
605 | |
601 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
606 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
602 | } |
607 | } |
603 | |
608 | |
604 | SV * |
609 | SV * |
605 | new (...) |
610 | new (...) |
606 | CODE: |
611 | CODE: |
… | |
… | |
624 | { |
629 | { |
625 | term->destroy (); |
630 | term->destroy (); |
626 | croak ("exception caught while initializing new terminal instance"); |
631 | croak ("exception caught while initializing new terminal instance"); |
627 | } |
632 | } |
628 | |
633 | |
629 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
634 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
630 | } |
635 | } |
631 | OUTPUT: |
636 | OUTPUT: |
632 | RETVAL |
637 | RETVAL |
633 | |
638 | |
634 | void |
639 | void |
… | |
… | |
703 | |
708 | |
704 | MODULE = urxvt PACKAGE = urxvt::term |
709 | MODULE = urxvt PACKAGE = urxvt::term |
705 | |
710 | |
706 | void |
711 | void |
707 | 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); |
708 | |
764 | |
709 | int |
765 | int |
710 | rxvt_term::strwidth (SV *str) |
766 | rxvt_term::strwidth (SV *str) |
711 | CODE: |
767 | CODE: |
712 | { |
768 | { |
… | |
… | |
847 | |
903 | |
848 | if (GIMME_V != G_VOID) |
904 | if (GIMME_V != G_VOID) |
849 | { |
905 | { |
850 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
906 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
851 | |
907 | |
852 | for (int col = 0; col <THIS->ncol; col++) |
908 | for (int col = 0; col < THIS->ncol; col++) |
853 | wstr [col] = l.t [col]; |
909 | wstr [col] = l.t [col]; |
854 | |
910 | |
855 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
911 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
856 | |
912 | |
857 | delete [] wstr; |
913 | delete [] wstr; |
858 | } |
914 | } |
859 | |
915 | |
860 | if (new_text) |
916 | if (new_text) |
… | |
… | |
950 | } |
1006 | } |
951 | OUTPUT: |
1007 | OUTPUT: |
952 | RETVAL |
1008 | RETVAL |
953 | |
1009 | |
954 | SV * |
1010 | SV * |
955 | rxvt_term::special_encode (SV *str) |
1011 | rxvt_term::special_encode (SV *string) |
956 | CODE: |
1012 | CODE: |
957 | 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 |
958 | |
1048 | |
959 | SV * |
1049 | SV * |
960 | rxvt_term::special_decode (SV *str) |
1050 | rxvt_term::special_decode (SV *text) |
961 | CODE: |
1051 | CODE: |
962 | 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 |
963 | |
1084 | |
964 | void |
1085 | void |
965 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1086 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
966 | PPCODE: |
1087 | PPCODE: |
967 | { |
1088 | { |
… | |
… | |
1032 | THIS->want_refresh = 1; |
1153 | THIS->want_refresh = 1; |
1033 | } |
1154 | } |
1034 | } |
1155 | } |
1035 | |
1156 | |
1036 | int |
1157 | int |
1037 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1158 | rxvt_term::selection_grab (U32 eventtime) |
1038 | |
1159 | |
1039 | void |
1160 | void |
1040 | rxvt_term::selection (SV *newtext = 0) |
1161 | rxvt_term::selection (SV *newtext = 0) |
1041 | PPCODE: |
1162 | PPCODE: |
1042 | { |
1163 | { |
… | |
… | |
1080 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1201 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1081 | |
1202 | |
1082 | THIS->cmdbuf_ptr = str; |
1203 | THIS->cmdbuf_ptr = str; |
1083 | THIS->cmdbuf_endp = str + len; |
1204 | THIS->cmdbuf_endp = str + len; |
1084 | |
1205 | |
|
|
1206 | rxvt_push_locale (THIS->locale); |
1085 | THIS->cmd_parse (); |
1207 | THIS->cmd_parse (); |
|
|
1208 | rxvt_pop_locale (); |
1086 | |
1209 | |
1087 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1210 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1088 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1211 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1089 | } |
1212 | } |
1090 | |
1213 | |