… | |
… | |
26 | #include <XSUB.h> |
26 | #include <XSUB.h> |
27 | #undef line_t |
27 | #undef line_t |
28 | |
28 | |
29 | #include "../config.h" |
29 | #include "../config.h" |
30 | |
30 | |
|
|
31 | #include <cstddef> |
31 | #include <cstdarg> |
32 | #include <cstdarg> |
32 | |
33 | |
33 | #include "rxvt.h" |
34 | #include "rxvt.h" |
34 | #include "iom.h" |
35 | #include "iom.h" |
35 | #include "rxvtutil.h" |
36 | #include "rxvtutil.h" |
… | |
… | |
101 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
102 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
102 | |
103 | |
103 | return (long)mg->mg_ptr; |
104 | return (long)mg->mg_ptr; |
104 | } |
105 | } |
105 | |
106 | |
106 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
107 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
107 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
108 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
108 | |
109 | |
109 | ///////////////////////////////////////////////////////////////////////////// |
110 | ///////////////////////////////////////////////////////////////////////////// |
110 | |
111 | |
111 | struct perl_watcher |
112 | struct perl_watcher |
… | |
… | |
290 | void |
291 | void |
291 | overlay::show () |
292 | overlay::show () |
292 | { |
293 | { |
293 | char key[33]; sprintf (key, "%32lx", (long)this); |
294 | char key[33]; sprintf (key, "%32lx", (long)this); |
294 | |
295 | |
295 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
296 | 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); |
297 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
297 | } |
298 | } |
298 | |
299 | |
299 | void |
300 | void |
300 | overlay::hide () |
301 | overlay::hide () |
301 | { |
302 | { |
302 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); |
303 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
303 | |
304 | |
304 | if (ovs) |
305 | if (ovs) |
305 | { |
306 | { |
306 | char key[33]; sprintf (key, "%32lx", (long)this); |
307 | char key[33]; sprintf (key, "%32lx", (long)this); |
307 | |
308 | |
… | |
… | |
415 | if (!perl) |
416 | if (!perl) |
416 | return false; |
417 | return false; |
417 | |
418 | |
418 | if (htype == HOOK_INIT) // first hook ever called |
419 | if (htype == HOOK_INIT) // first hook ever called |
419 | { |
420 | { |
420 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
421 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
421 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
422 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
422 | } |
423 | } |
423 | else if (!term->self) |
424 | else if (!term->perl.self) |
424 | return false; // perl not initialized for this instance |
425 | return false; // perl not initialized for this instance |
425 | else if (htype == HOOK_DESTROY) |
426 | else if (htype == HOOK_DESTROY) |
426 | { |
427 | { |
427 | // handled later |
428 | // handled later |
428 | } |
429 | } |
429 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
430 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
430 | { |
431 | { |
431 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
432 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
432 | |
433 | |
433 | if (HvKEYS (hv)) |
434 | if (HvKEYS (hv)) |
434 | { |
435 | { |
435 | hv_iterinit (hv); |
436 | hv_iterinit (hv); |
436 | |
437 | |
… | |
… | |
562 | if (SvTRUE (ERRSV)) |
563 | if (SvTRUE (ERRSV)) |
563 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
564 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
564 | |
565 | |
565 | if (htype == HOOK_DESTROY) |
566 | if (htype == HOOK_DESTROY) |
566 | { |
567 | { |
567 | clearSVptr ((SV *)term->self); |
568 | clearSVptr ((SV *)term->perl.self); |
568 | SvREFCNT_dec ((SV *)term->self); |
569 | SvREFCNT_dec ((SV *)term->perl.self); |
569 | } |
570 | } |
570 | |
571 | |
571 | return count; |
572 | return count; |
572 | } |
573 | } |
573 | |
574 | |
… | |
… | |
583 | |
584 | |
584 | PROTOTYPES: ENABLE |
585 | PROTOTYPES: ENABLE |
585 | |
586 | |
586 | BOOT: |
587 | BOOT: |
587 | { |
588 | { |
588 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
589 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
|
|
590 | |
589 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
591 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
590 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
592 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
591 | # include "hookinc.h" |
593 | # include "hookinc.h" |
592 | # undef def |
594 | # undef def |
593 | |
595 | |
|
|
596 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
597 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
598 | # define nodef(name) |
|
|
599 | # include "optinc.h" |
|
|
600 | # undef nodef |
|
|
601 | # undef def |
|
|
602 | |
|
|
603 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
604 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
594 | export_const (DEFAULT_RSTYLE); |
605 | export_const_iv (DEFAULT_RSTYLE); |
595 | export_const (OVERLAY_RSTYLE); |
606 | export_const_iv (OVERLAY_RSTYLE); |
596 | export_const (RS_Bold); |
607 | export_const_iv (RS_Bold); |
597 | export_const (RS_Italic); |
608 | export_const_iv (RS_Italic); |
598 | export_const (RS_Blink); |
609 | export_const_iv (RS_Blink); |
599 | export_const (RS_RVid); |
610 | export_const_iv (RS_RVid); |
600 | export_const (RS_Uline); |
611 | export_const_iv (RS_Uline); |
601 | |
612 | |
602 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
613 | export_const_iv (CurrentTime); |
|
|
614 | export_const_iv (ShiftMask); |
|
|
615 | export_const_iv (LockMask); |
|
|
616 | export_const_iv (ControlMask); |
|
|
617 | export_const_iv (Mod1Mask); |
|
|
618 | export_const_iv (Mod2Mask); |
|
|
619 | export_const_iv (Mod3Mask); |
|
|
620 | export_const_iv (Mod4Mask); |
|
|
621 | export_const_iv (Mod5Mask); |
|
|
622 | export_const_iv (Button1Mask); |
|
|
623 | export_const_iv (Button2Mask); |
|
|
624 | export_const_iv (Button3Mask); |
|
|
625 | export_const_iv (Button4Mask); |
|
|
626 | export_const_iv (Button5Mask); |
|
|
627 | export_const_iv (AnyModifier); |
603 | } |
628 | } |
604 | |
629 | |
605 | SV * |
630 | SV * |
606 | new (...) |
631 | new (...) |
607 | CODE: |
632 | CODE: |
… | |
… | |
625 | { |
650 | { |
626 | term->destroy (); |
651 | term->destroy (); |
627 | croak ("exception caught while initializing new terminal instance"); |
652 | croak ("exception caught while initializing new terminal instance"); |
628 | } |
653 | } |
629 | |
654 | |
630 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
655 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
631 | } |
656 | } |
632 | OUTPUT: |
657 | OUTPUT: |
633 | RETVAL |
658 | RETVAL |
634 | |
659 | |
635 | void |
660 | void |
… | |
… | |
704 | |
729 | |
705 | MODULE = urxvt PACKAGE = urxvt::term |
730 | MODULE = urxvt PACKAGE = urxvt::term |
706 | |
731 | |
707 | void |
732 | void |
708 | rxvt_term::destroy () |
733 | rxvt_term::destroy () |
|
|
734 | |
|
|
735 | void |
|
|
736 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
737 | CODE: |
|
|
738 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
739 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
740 | GrabModeSync, GrabModeSync, None, None); |
|
|
741 | |
|
|
742 | bool |
|
|
743 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
744 | CODE: |
|
|
745 | { |
|
|
746 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
747 | |
|
|
748 | THIS->perl.grabtime = 0; |
|
|
749 | |
|
|
750 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
751 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
752 | mode, mode, None, None, eventtime)) |
|
|
753 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
754 | THIS->perl.grabtime = eventtime; |
|
|
755 | else |
|
|
756 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
757 | |
|
|
758 | RETVAL = !!THIS->perl.grabtime; |
|
|
759 | } |
|
|
760 | OUTPUT: |
|
|
761 | RETVAL |
|
|
762 | |
|
|
763 | void |
|
|
764 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
|
|
765 | CODE: |
|
|
766 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
|
|
767 | |
|
|
768 | void |
|
|
769 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
|
|
770 | CODE: |
|
|
771 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
|
|
772 | |
|
|
773 | void |
|
|
774 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
|
|
775 | CODE: |
|
|
776 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
|
|
777 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
|
|
778 | |
|
|
779 | void |
|
|
780 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
|
|
781 | CODE: |
|
|
782 | THIS->perl.grabtime = 0; |
|
|
783 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
784 | XUngrabPointer (THIS->display->display, eventtime); |
709 | |
785 | |
710 | int |
786 | int |
711 | rxvt_term::strwidth (SV *str) |
787 | rxvt_term::strwidth (SV *str) |
712 | CODE: |
788 | CODE: |
713 | { |
789 | { |
… | |
… | |
755 | free (wstr); |
831 | free (wstr); |
756 | } |
832 | } |
757 | OUTPUT: |
833 | OUTPUT: |
758 | RETVAL |
834 | RETVAL |
759 | |
835 | |
760 | # very portable, especially on objects as opposed to pods |
836 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
761 | #define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
|
|
762 | |
837 | |
763 | #define TERM_OFFSET_width TERM_OFFSET(width) |
838 | #define TERM_OFFSET_width TERM_OFFSET(width) |
764 | #define TERM_OFFSET_height TERM_OFFSET(height) |
839 | #define TERM_OFFSET_height TERM_OFFSET(height) |
765 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
840 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
766 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
841 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
… | |
… | |
791 | CODE: |
866 | CODE: |
792 | RETVAL = *(int *)((char *)THIS + ix); |
867 | RETVAL = *(int *)((char *)THIS + ix); |
793 | OUTPUT: |
868 | OUTPUT: |
794 | RETVAL |
869 | RETVAL |
795 | |
870 | |
|
|
871 | unsigned int |
|
|
872 | rxvt_term::ModLevel3Mask () |
|
|
873 | ALIAS: |
|
|
874 | ModLevel3Mask = 0 |
|
|
875 | ModMetaMask = 1 |
|
|
876 | ModNumLockMask = 2 |
|
|
877 | CODE: |
|
|
878 | switch (ix) |
|
|
879 | { |
|
|
880 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
881 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
882 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
883 | } |
|
|
884 | OUTPUT: |
|
|
885 | RETVAL |
|
|
886 | |
796 | U32 |
887 | U32 |
797 | rxvt_term::parent () |
888 | rxvt_term::parent () |
798 | CODE: |
889 | CODE: |
799 | RETVAL = (U32)THIS->parent [0]; |
890 | RETVAL = (U32)THIS->parent [0]; |
800 | OUTPUT: |
891 | OUTPUT: |
… | |
… | |
1065 | else |
1156 | else |
1066 | THIS->rs [index] = 0; |
1157 | THIS->rs [index] = 0; |
1067 | } |
1158 | } |
1068 | } |
1159 | } |
1069 | |
1160 | |
|
|
1161 | bool |
|
|
1162 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1163 | CODE: |
|
|
1164 | { |
|
|
1165 | RETVAL = THIS->options & optval; |
|
|
1166 | |
|
|
1167 | if (set >= 0) |
|
|
1168 | { |
|
|
1169 | if (set) |
|
|
1170 | THIS->options |= optval; |
|
|
1171 | else |
|
|
1172 | THIS->options &= ~optval; |
|
|
1173 | |
|
|
1174 | switch (optval) |
|
|
1175 | { |
|
|
1176 | case Opt_skipBuiltinGlyphs: |
|
|
1177 | THIS->set_fonts (); |
|
|
1178 | THIS->scr_remap_chars (); |
|
|
1179 | THIS->scr_touch (true); |
|
|
1180 | THIS->want_refresh = 1; |
|
|
1181 | break; |
|
|
1182 | |
|
|
1183 | case Opt_cursorUnderline: |
|
|
1184 | THIS->want_refresh = 1; |
|
|
1185 | break; |
|
|
1186 | |
|
|
1187 | # case Opt_scrollBar_floating: |
|
|
1188 | # case Opt_scrollBar_right: |
|
|
1189 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1190 | # break; |
|
|
1191 | } |
|
|
1192 | } |
|
|
1193 | } |
|
|
1194 | OUTPUT: |
|
|
1195 | RETVAL |
|
|
1196 | |
1070 | void |
1197 | void |
1071 | rxvt_term::cur (...) |
1198 | rxvt_term::cur (...) |
1072 | PROTOTYPE: $;$$ |
1199 | PROTOTYPE: $;$$ |
1073 | ALIAS: |
1200 | ALIAS: |
1074 | screen_cur = 0 |
1201 | screen_cur = 0 |
… | |
… | |
1098 | THIS->want_refresh = 1; |
1225 | THIS->want_refresh = 1; |
1099 | } |
1226 | } |
1100 | } |
1227 | } |
1101 | |
1228 | |
1102 | int |
1229 | int |
1103 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1230 | rxvt_term::selection_grab (U32 eventtime) |
1104 | |
1231 | |
1105 | void |
1232 | void |
1106 | rxvt_term::selection (SV *newtext = 0) |
1233 | rxvt_term::selection (SV *newtext = 0) |
1107 | PPCODE: |
1234 | PPCODE: |
1108 | { |
1235 | { |
… | |
… | |
1146 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1273 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1147 | |
1274 | |
1148 | THIS->cmdbuf_ptr = str; |
1275 | THIS->cmdbuf_ptr = str; |
1149 | THIS->cmdbuf_endp = str + len; |
1276 | THIS->cmdbuf_endp = str + len; |
1150 | |
1277 | |
|
|
1278 | rxvt_push_locale (THIS->locale); |
1151 | THIS->cmd_parse (); |
1279 | THIS->cmd_parse (); |
|
|
1280 | rxvt_pop_locale (); |
1152 | |
1281 | |
1153 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1282 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1154 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1283 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1155 | } |
1284 | } |
1156 | |
1285 | |