… | |
… | |
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 | { |
… | |
… | |
1097 | THIS->want_refresh = 1; |
1153 | THIS->want_refresh = 1; |
1098 | } |
1154 | } |
1099 | } |
1155 | } |
1100 | |
1156 | |
1101 | int |
1157 | int |
1102 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1158 | rxvt_term::selection_grab (U32 eventtime) |
1103 | |
1159 | |
1104 | void |
1160 | void |
1105 | rxvt_term::selection (SV *newtext = 0) |
1161 | rxvt_term::selection (SV *newtext = 0) |
1106 | PPCODE: |
1162 | PPCODE: |
1107 | { |
1163 | { |
… | |
… | |
1145 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1201 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1146 | |
1202 | |
1147 | THIS->cmdbuf_ptr = str; |
1203 | THIS->cmdbuf_ptr = str; |
1148 | THIS->cmdbuf_endp = str + len; |
1204 | THIS->cmdbuf_endp = str + len; |
1149 | |
1205 | |
|
|
1206 | rxvt_push_locale (THIS->locale); |
1150 | THIS->cmd_parse (); |
1207 | THIS->cmd_parse (); |
|
|
1208 | rxvt_pop_locale (); |
1151 | |
1209 | |
1152 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1210 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1153 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1211 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1154 | } |
1212 | } |
1155 | |
1213 | |