… | |
… | |
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 | |
… | |
… | |
485 | wchar_t *wstr = va_arg (ap, wchar_t *); |
486 | wchar_t *wstr = va_arg (ap, wchar_t *); |
486 | int wlen = va_arg (ap, int); |
487 | int wlen = va_arg (ap, int); |
487 | |
488 | |
488 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
489 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
489 | } |
490 | } |
|
|
491 | break; |
490 | |
492 | |
491 | case DT_XEVENT: |
493 | case DT_XEVENT: |
492 | { |
494 | { |
493 | XEvent *xe = va_arg (ap, XEvent *); |
495 | XEvent *xe = va_arg (ap, XEvent *); |
494 | HV *hv = newHV (); |
496 | HV *hv = newHV (); |
… | |
… | |
561 | if (SvTRUE (ERRSV)) |
563 | if (SvTRUE (ERRSV)) |
562 | 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)); |
563 | |
565 | |
564 | if (htype == HOOK_DESTROY) |
566 | if (htype == HOOK_DESTROY) |
565 | { |
567 | { |
566 | clearSVptr ((SV *)term->self); |
568 | clearSVptr ((SV *)term->perl.self); |
567 | SvREFCNT_dec ((SV *)term->self); |
569 | SvREFCNT_dec ((SV *)term->perl.self); |
568 | } |
570 | } |
569 | |
571 | |
570 | return count; |
572 | return count; |
571 | } |
573 | } |
572 | |
574 | |
… | |
… | |
582 | |
584 | |
583 | PROTOTYPES: ENABLE |
585 | PROTOTYPES: ENABLE |
584 | |
586 | |
585 | BOOT: |
587 | BOOT: |
586 | { |
588 | { |
|
|
589 | HV *stash = gv_stashpv ("urxvt", 1); |
587 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
590 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
|
|
591 | |
588 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
592 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
589 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
593 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
590 | # include "hookinc.h" |
594 | # include "hookinc.h" |
591 | # undef def |
595 | # undef def |
592 | |
596 | |
|
|
597 | |
593 | export_const (DEFAULT_RSTYLE); |
598 | export_const_iv (DEFAULT_RSTYLE); |
594 | export_const (OVERLAY_RSTYLE); |
599 | export_const_iv (OVERLAY_RSTYLE); |
595 | export_const (RS_Bold); |
600 | export_const_iv (RS_Bold); |
596 | export_const (RS_Italic); |
601 | export_const_iv (RS_Italic); |
597 | export_const (RS_Blink); |
602 | export_const_iv (RS_Blink); |
598 | export_const (RS_RVid); |
603 | export_const_iv (RS_RVid); |
599 | export_const (RS_Uline); |
604 | export_const_iv (RS_Uline); |
600 | |
605 | |
601 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
606 | export_const_iv (CurrentTime); |
|
|
607 | export_const_iv (ShiftMask); |
|
|
608 | export_const_iv (LockMask); |
|
|
609 | export_const_iv (ControlMask); |
|
|
610 | export_const_iv (Mod1Mask); |
|
|
611 | export_const_iv (Mod2Mask); |
|
|
612 | export_const_iv (Mod3Mask); |
|
|
613 | export_const_iv (Mod4Mask); |
|
|
614 | export_const_iv (Mod5Mask); |
|
|
615 | export_const_iv (Button1Mask); |
|
|
616 | export_const_iv (Button2Mask); |
|
|
617 | export_const_iv (Button3Mask); |
|
|
618 | export_const_iv (Button4Mask); |
|
|
619 | export_const_iv (Button5Mask); |
|
|
620 | export_const_iv (AnyModifier); |
|
|
621 | |
|
|
622 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
602 | } |
623 | } |
603 | |
624 | |
604 | SV * |
625 | SV * |
605 | new (...) |
626 | new (...) |
606 | CODE: |
627 | CODE: |
… | |
… | |
624 | { |
645 | { |
625 | term->destroy (); |
646 | term->destroy (); |
626 | croak ("exception caught while initializing new terminal instance"); |
647 | croak ("exception caught while initializing new terminal instance"); |
627 | } |
648 | } |
628 | |
649 | |
629 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
650 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
630 | } |
651 | } |
631 | OUTPUT: |
652 | OUTPUT: |
632 | RETVAL |
653 | RETVAL |
633 | |
654 | |
634 | void |
655 | void |
… | |
… | |
703 | |
724 | |
704 | MODULE = urxvt PACKAGE = urxvt::term |
725 | MODULE = urxvt PACKAGE = urxvt::term |
705 | |
726 | |
706 | void |
727 | void |
707 | rxvt_term::destroy () |
728 | rxvt_term::destroy () |
|
|
729 | |
|
|
730 | void |
|
|
731 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
732 | CODE: |
|
|
733 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
734 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
735 | GrabModeSync, GrabModeSync, None, None); |
|
|
736 | |
|
|
737 | bool |
|
|
738 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
739 | CODE: |
|
|
740 | { |
|
|
741 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
742 | |
|
|
743 | THIS->perl.grabtime = 0; |
|
|
744 | |
|
|
745 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
746 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
747 | mode, mode, None, None, eventtime)) |
|
|
748 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
749 | THIS->perl.grabtime = eventtime; |
|
|
750 | else |
|
|
751 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
752 | |
|
|
753 | RETVAL = !!THIS->perl.grabtime; |
|
|
754 | } |
|
|
755 | OUTPUT: |
|
|
756 | RETVAL |
|
|
757 | |
|
|
758 | void |
|
|
759 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
|
|
760 | CODE: |
|
|
761 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
|
|
762 | |
|
|
763 | void |
|
|
764 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
|
|
765 | CODE: |
|
|
766 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
|
|
767 | |
|
|
768 | void |
|
|
769 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
|
|
770 | CODE: |
|
|
771 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
|
|
772 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
|
|
773 | |
|
|
774 | void |
|
|
775 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
|
|
776 | CODE: |
|
|
777 | THIS->perl.grabtime = 0; |
|
|
778 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
779 | XUngrabPointer (THIS->display->display, eventtime); |
708 | |
780 | |
709 | int |
781 | int |
710 | rxvt_term::strwidth (SV *str) |
782 | rxvt_term::strwidth (SV *str) |
711 | CODE: |
783 | CODE: |
712 | { |
784 | { |
… | |
… | |
754 | free (wstr); |
826 | free (wstr); |
755 | } |
827 | } |
756 | OUTPUT: |
828 | OUTPUT: |
757 | RETVAL |
829 | RETVAL |
758 | |
830 | |
759 | # very portable, especially on objects as opposed to pods |
831 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
760 | #define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
|
|
761 | |
832 | |
762 | #define TERM_OFFSET_width TERM_OFFSET(width) |
833 | #define TERM_OFFSET_width TERM_OFFSET(width) |
763 | #define TERM_OFFSET_height TERM_OFFSET(height) |
834 | #define TERM_OFFSET_height TERM_OFFSET(height) |
764 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
835 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
765 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
836 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
… | |
… | |
790 | CODE: |
861 | CODE: |
791 | RETVAL = *(int *)((char *)THIS + ix); |
862 | RETVAL = *(int *)((char *)THIS + ix); |
792 | OUTPUT: |
863 | OUTPUT: |
793 | RETVAL |
864 | RETVAL |
794 | |
865 | |
|
|
866 | unsigned int |
|
|
867 | rxvt_term::ModLevel3Mask () |
|
|
868 | ALIAS: |
|
|
869 | ModLevel3Mask = 0 |
|
|
870 | ModMetaMask = 1 |
|
|
871 | ModNumLockMask = 2 |
|
|
872 | CODE: |
|
|
873 | switch (ix) |
|
|
874 | { |
|
|
875 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
876 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
877 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
878 | } |
|
|
879 | OUTPUT: |
|
|
880 | RETVAL |
|
|
881 | |
795 | U32 |
882 | U32 |
796 | rxvt_term::parent () |
883 | rxvt_term::parent () |
797 | CODE: |
884 | CODE: |
798 | RETVAL = (U32)THIS->parent [0]; |
885 | RETVAL = (U32)THIS->parent [0]; |
799 | OUTPUT: |
886 | OUTPUT: |
… | |
… | |
1097 | THIS->want_refresh = 1; |
1184 | THIS->want_refresh = 1; |
1098 | } |
1185 | } |
1099 | } |
1186 | } |
1100 | |
1187 | |
1101 | int |
1188 | int |
1102 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1189 | rxvt_term::selection_grab (U32 eventtime) |
1103 | |
1190 | |
1104 | void |
1191 | void |
1105 | rxvt_term::selection (SV *newtext = 0) |
1192 | rxvt_term::selection (SV *newtext = 0) |
1106 | PPCODE: |
1193 | PPCODE: |
1107 | { |
1194 | { |
… | |
… | |
1145 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1232 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1146 | |
1233 | |
1147 | THIS->cmdbuf_ptr = str; |
1234 | THIS->cmdbuf_ptr = str; |
1148 | THIS->cmdbuf_endp = str + len; |
1235 | THIS->cmdbuf_endp = str + len; |
1149 | |
1236 | |
|
|
1237 | rxvt_push_locale (THIS->locale); |
1150 | THIS->cmd_parse (); |
1238 | THIS->cmd_parse (); |
|
|
1239 | rxvt_pop_locale (); |
1151 | |
1240 | |
1152 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1241 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1153 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1242 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1154 | } |
1243 | } |
1155 | |
1244 | |