ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtperl.xs
(Generate patch)

Comparing rxvt-unicode/src/rxvtperl.xs (file contents):
Revision 1.42 by root, Sun Jan 8 08:43:11 2006 UTC vs.
Revision 1.73 by root, Wed Jan 18 09:40:53 2006 UTC

29#include "../config.h" 29#include "../config.h"
30 30
31#include <cstddef> 31#include <cstddef>
32#include <cstdarg> 32#include <cstdarg>
33 33
34#include "unistd.h"
35
36#include "iom.h"
34#include "rxvt.h" 37#include "rxvt.h"
35#include "iom.h" 38#include "keyboard.h"
36#include "rxvtutil.h" 39#include "rxvtutil.h"
37#include "rxvtperl.h" 40#include "rxvtperl.h"
38 41
39#include "perlxsi.c" 42#include "perlxsi.c"
40 43
41#if defined(HAVE_SCROLLBARS) || defined(MENUBAR) 44#ifdef HAVE_SCROLLBARS
42# define GRAB_CURSOR THIS->leftptr_cursor 45# define GRAB_CURSOR THIS->leftptr_cursor
43#else 46#else
44# define GRAB_CURSOR None 47# define GRAB_CURSOR None
45#endif 48#endif
46 49
47#undef LINENO 50#undef LINENO
48#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
49#undef ROW 52#undef ROW
50#define ROW(n) THIS->row_buf [LINENO (n)] 53#define ROW(n) THIS->row_buf [LINENO (n)]
51 54
55#define ENABLE_PERL_FRILLS 1
56
52///////////////////////////////////////////////////////////////////////////// 57/////////////////////////////////////////////////////////////////////////////
53
54static SV *
55taint (SV *sv)
56{
57 SvTAINT (sv);
58 return sv;
59}
60
61static SV *
62taint_if (SV *sv, SV *src)
63{
64 if (SvTAINTED (src))
65 SvTAINT (sv);
66
67 return sv;
68}
69 58
70static wchar_t * 59static wchar_t *
71sv2wcs (SV *sv) 60sv2wcs (SV *sv)
72{ 61{
73 STRLEN len; 62 STRLEN len;
344 for (int y = ov_h; y--; ) 333 for (int y = ov_h; y--; )
345 { 334 {
346 text_t *t1 = text [y]; 335 text_t *t1 = text [y];
347 rend_t *r1 = rend [y]; 336 rend_t *r1 = rend [y];
348 337
349 text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; 338 text_t *t2 = ROW(y + ov_y + THIS->view_start).t + ov_x;
350 rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; 339 rend_t *r2 = ROW(y + ov_y + THIS->view_start).r + ov_x;
351 340
352 for (int x = ov_w; x--; ) 341 for (int x = ov_w; x--; )
353 { 342 {
354 text_t t = *t1; *t1++ = *t2; *t2++ = t; 343 text_t t = *t1; *t1++ = *t2; *t2++ = t;
355 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); 344 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t));
392 381
393struct rxvt_perl_interp rxvt_perl; 382struct rxvt_perl_interp rxvt_perl;
394 383
395static PerlInterpreter *perl; 384static PerlInterpreter *perl;
396 385
397rxvt_perl_interp::rxvt_perl_interp ()
398{
399}
400
401rxvt_perl_interp::~rxvt_perl_interp () 386rxvt_perl_interp::~rxvt_perl_interp ()
402{ 387{
403 if (perl) 388 if (perl)
404 { 389 {
405 perl_destruct (perl); 390 perl_destruct (perl);
406 perl_free (perl); 391 perl_free (perl);
407 } 392 }
408} 393}
409 394
410void 395void
411rxvt_perl_interp::init (bool tainted) 396rxvt_perl_interp::init (rxvt_term *term)
412{ 397{
413 if (!perl) 398 if (!perl)
414 { 399 {
400 rxvt_push_locale (""); // perl init destroys current locale
401
402 perl_environ = rxvt_environ;
403 swap (perl_environ, environ);
404
415 char *argv[] = { 405 char *argv[] = {
416 "", 406 "",
417 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
418 "-T", 407 "-e"
408 "BEGIN {"
409 " urxvt->bootstrap;"
410 " unshift @INC, '" LIBDIR "';"
411 "}"
412 ""
413 "use urxvt;"
419 }; 414 };
420 415
421 perl = perl_alloc (); 416 perl = perl_alloc ();
422 perl_construct (perl); 417 perl_construct (perl);
423 418
424 if (perl_parse (perl, xs_init, 2 + !!tainted, argv, (char **)NULL) 419 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL)
425 || perl_run (perl)) 420 || perl_run (perl))
426 { 421 {
427 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 422 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
428 423
429 perl_destruct (perl); 424 perl_destruct (perl);
430 perl_free (perl); 425 perl_free (perl);
431 perl = 0; 426 perl = 0;
432 } 427 }
428
429 swap (perl_environ, environ);
430
431 rxvt_pop_locale ();
433 } 432 }
434}
435 433
436bool
437rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
438{
439 if (!perl) 434 if (perl)
440 return false;
441
442 if (htype == HOOK_INIT) // first hook ever called
443 { 435 {
436 // runs outside of perls ENV
444 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 437 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
445 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 438 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
446 } 439 }
447 else if (!term->perl.self) 440}
448 return false; // perl not initialized for this instance 441
449 else if (htype == HOOK_DESTROY) 442static void
443ungrab (rxvt_term *THIS)
444{
445 if (THIS->perl.grabtime)
450 { 446 {
451 // handled later 447 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
448 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
449 THIS->perl.grabtime = 0;
452 } 450 }
453 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 451}
452
453static void
454swap_overlays (rxvt_term *term)
455{
456 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
457
458 if (HvKEYS (hv))
454 { 459 {
455 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
456
457 if (HvKEYS (hv))
458 {
459 hv_iterinit (hv); 460 hv_iterinit (hv);
460 461
461 while (HE *he = hv_iternext (hv)) 462 while (HE *he = hv_iternext (hv))
462 ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); 463 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
463 }
464 } 464 }
465 else if (!should_invoke [htype]) 465}
466
467bool
468rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
469{
470 if (!perl || !term->perl.self)
466 return false; 471 return false;
467 472
468 dSP; 473 // pre-handling of some events
469 va_list ap; 474 if (htype == HOOK_REFRESH_END)
475 swap_overlays (term);
470 476
471 va_start (ap, htype); 477 swap (perl_environ, environ);
472 478
473 ENTER; 479 bool event_consumed;
474 SAVETMPS;
475 480
476 PUSHMARK (SP); 481 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
477 482 || term->perl.should_invoke [htype])
478 XPUSHs (sv_2mortal (newSVterm (term))); 483 try
479 XPUSHs (sv_2mortal (newSViv (htype)));
480
481 for (;;) {
482 data_type dt = (data_type)va_arg (ap, int);
483
484 switch (dt)
485 { 484 {
485 dSP;
486 va_list ap;
487
488 va_start (ap, htype);
489
490 ENTER;
491 SAVETMPS;
492
493 PUSHMARK (SP);
494
495 XPUSHs (sv_2mortal (newSVterm (term)));
496 XPUSHs (sv_2mortal (newSViv (htype)));
497
498 for (;;) {
499 data_type dt = (data_type)va_arg (ap, int);
500
501 switch (dt)
502 {
486 case DT_INT: 503 case DT_INT:
487 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); 504 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
488 break; 505 break;
489 506
490 case DT_LONG: 507 case DT_LONG:
491 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 508 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
492 break; 509 break;
493 510
494 case DT_STR: 511 case DT_STR:
495 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); 512 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
496 break; 513 break;
497 514
498 case DT_STR_LEN: 515 case DT_STR_LEN:
499 { 516 {
500 char *str = va_arg (ap, char *); 517 char *str = va_arg (ap, char *);
501 int len = va_arg (ap, int); 518 int len = va_arg (ap, int);
502 519
503 XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); 520 XPUSHs (sv_2mortal (newSVpvn (str, len)));
504 } 521 }
505 break; 522 break;
506 523
507 case DT_WCS_LEN: 524 case DT_WCS_LEN:
508 { 525 {
509 wchar_t *wstr = va_arg (ap, wchar_t *); 526 wchar_t *wstr = va_arg (ap, wchar_t *);
510 int wlen = va_arg (ap, int); 527 int wlen = va_arg (ap, int);
511 528
512 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); 529 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
513 } 530 }
514 break; 531 break;
515 532
516 case DT_XEVENT: 533 case DT_XEVENT:
517 { 534 {
518 XEvent *xe = va_arg (ap, XEvent *); 535 XEvent *xe = va_arg (ap, XEvent *);
519 HV *hv = newHV (); 536 HV *hv = newHV ();
520 537
521# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 538# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
522# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) 539# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
523# undef set 540# undef set
524 541
525 setiv (type, xe->type); 542 setiv (type, xe->type);
526 setiv (send_event, xe->xany.send_event); 543 setiv (send_event, xe->xany.send_event);
527 setiv (serial, xe->xany.serial); 544 setiv (serial, xe->xany.serial);
528 545
529 switch (xe->type) 546 switch (xe->type)
530 { 547 {
531 case KeyPress: 548 case KeyPress:
532 case KeyRelease: 549 case KeyRelease:
533 case ButtonPress: 550 case ButtonPress:
534 case ButtonRelease: 551 case ButtonRelease:
535 case MotionNotify: 552 case MotionNotify:
536 setiv (time, xe->xmotion.time); 553 setiv (time, xe->xmotion.time);
537 setiv (x, xe->xmotion.x); 554 setiv (x, xe->xmotion.x);
538 setiv (y, xe->xmotion.y); 555 setiv (y, xe->xmotion.y);
539 setiv (row, xe->xmotion.y / term->fheight); 556 setiv (row, xe->xmotion.y / term->fheight);
540 setiv (col, xe->xmotion.x / term->fwidth); 557 setiv (col, xe->xmotion.x / term->fwidth);
541 setiv (x_root, xe->xmotion.x_root); 558 setiv (x_root, xe->xmotion.x_root);
542 setiv (y_root, xe->xmotion.y_root); 559 setiv (y_root, xe->xmotion.y_root);
543 setiv (state, xe->xmotion.state); 560 setiv (state, xe->xmotion.state);
561 break;
562 }
563
564 switch (xe->type)
565 {
566 case KeyPress:
567 case KeyRelease:
568 setiv (keycode, xe->xkey.keycode);
569 break;
570
571 case ButtonPress:
572 case ButtonRelease:
573 setiv (button, xe->xbutton.button);
574 break;
575
576 case MotionNotify:
577 setiv (is_hint, xe->xmotion.is_hint);
578 break;
579 }
580
581 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
582 }
544 break; 583 break;
584
585 case DT_END:
586 goto call;
587
588 default:
589 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
545 } 590 }
546
547 switch (xe->type)
548 {
549 case KeyPress:
550 case KeyRelease:
551 setiv (keycode, xe->xkey.keycode);
552 break;
553
554 case ButtonPress:
555 case ButtonRelease:
556 setiv (button, xe->xbutton.button);
557 break;
558
559 case MotionNotify:
560 setiv (is_hint, xe->xmotion.is_hint);
561 break;
562 }
563
564 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
565 } 591 }
566 break;
567 592
568 case DT_END: 593 call:
569 {
570 va_end (ap); 594 va_end (ap);
571 595
572 PUTBACK; 596 PUTBACK;
573 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); 597 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
574 SPAGAIN; 598 SPAGAIN;
575 599
576 if (count) 600 if (count)
577 { 601 {
578 SV *status = POPs; 602 SV *status = POPs;
579 count = SvTRUE (status); 603 count = SvTRUE (status);
580 } 604 }
581 605
582 PUTBACK; 606 PUTBACK;
583 FREETMPS; 607 FREETMPS;
584 LEAVE; 608 LEAVE;
585 609
586 if (SvTRUE (ERRSV)) 610 if (SvTRUE (ERRSV))
611 {
587 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 612 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
588 613 ungrab (term); // better lose the grab than the session
589 if (htype == HOOK_DESTROY)
590 {
591 clearSVptr ((SV *)term->perl.self);
592 SvREFCNT_dec ((SV *)term->perl.self);
593 } 614 }
594 615
595 return count; 616 event_consumed = !!count;
596 }
597
598 default:
599 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
600 } 617 }
618 catch (...)
619 {
620 swap (perl_environ, environ);
621 throw;
622 }
623 else
624 event_consumed = false;
625
626 // post-handling of some events
627 if (htype == HOOK_REFRESH_BEGIN)
628 swap_overlays (term);
629 else if (htype == HOOK_DESTROY)
630 {
631 clearSVptr ((SV *)term->perl.self);
632 SvREFCNT_dec ((SV *)term->perl.self);
601 } 633 }
634
635 swap (perl_environ, environ);
636
637 return event_consumed;
602} 638}
603 639
604///////////////////////////////////////////////////////////////////////////// 640/////////////////////////////////////////////////////////////////////////////
605 641
606MODULE = urxvt PACKAGE = urxvt 642MODULE = urxvt PACKAGE = urxvt
607 643
608PROTOTYPES: ENABLE 644PROTOTYPES: ENABLE
609 645
610BOOT: 646BOOT:
611{ 647{
612 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); 648 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
649 sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1));
650 sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1));
651 sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1));
613 652
614 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 653 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
615# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 654# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
616# include "hookinc.h" 655# include "hookinc.h"
617# undef def 656# undef def
622# include "optinc.h" 661# include "optinc.h"
623# undef nodef 662# undef nodef
624# undef def 663# undef def
625 664
626 HV *stash = gv_stashpv ("urxvt", 1); 665 HV *stash = gv_stashpv ("urxvt", 1);
627# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); 666 struct {
667 const char *name;
668 IV iv;
669 } *civ, const_iv[] = {
670# define const_iv(name) { # name, (IV)name }
628 export_const_iv (DEFAULT_RSTYLE); 671 const_iv (DEFAULT_RSTYLE),
629 export_const_iv (OVERLAY_RSTYLE); 672 const_iv (OVERLAY_RSTYLE),
630 export_const_iv (RS_Bold); 673 const_iv (RS_Bold),
631 export_const_iv (RS_Italic); 674 const_iv (RS_Italic),
632 export_const_iv (RS_Blink); 675 const_iv (RS_Blink),
633 export_const_iv (RS_RVid); 676 const_iv (RS_RVid),
634 export_const_iv (RS_Uline); 677 const_iv (RS_Uline),
635 678
636 export_const_iv (CurrentTime); 679 const_iv (CurrentTime),
637 export_const_iv (ShiftMask); 680 const_iv (ShiftMask),
638 export_const_iv (LockMask); 681 const_iv (LockMask),
639 export_const_iv (ControlMask); 682 const_iv (ControlMask),
640 export_const_iv (Mod1Mask); 683 const_iv (Mod1Mask),
641 export_const_iv (Mod2Mask); 684 const_iv (Mod2Mask),
642 export_const_iv (Mod3Mask); 685 const_iv (Mod3Mask),
643 export_const_iv (Mod4Mask); 686 const_iv (Mod4Mask),
644 export_const_iv (Mod5Mask); 687 const_iv (Mod5Mask),
645 export_const_iv (Button1Mask); 688 const_iv (Button1Mask),
646 export_const_iv (Button2Mask); 689 const_iv (Button2Mask),
647 export_const_iv (Button3Mask); 690 const_iv (Button3Mask),
648 export_const_iv (Button4Mask); 691 const_iv (Button4Mask),
649 export_const_iv (Button5Mask); 692 const_iv (Button5Mask),
650 export_const_iv (AnyModifier); 693 const_iv (AnyModifier),
651}
652 694
653SV * 695 const_iv (EVENT_NONE),
654new (...) 696 const_iv (EVENT_READ),
655 CODE: 697 const_iv (EVENT_WRITE),
656{
657 stringvec *argv = new stringvec;
658 bool success;
659 698
660 for (int i = 0; i < items ;i++) 699 const_iv (NoEventMask),
661 argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 700 const_iv (KeyPressMask),
701 const_iv (KeyReleaseMask),
702 const_iv (ButtonPressMask),
703 const_iv (ButtonReleaseMask),
704 const_iv (EnterWindowMask),
705 const_iv (LeaveWindowMask),
706 const_iv (PointerMotionMask),
707 const_iv (PointerMotionHintMask),
708 const_iv (Button1MotionMask),
709 const_iv (Button2MotionMask),
710 const_iv (Button3MotionMask),
711 const_iv (Button4MotionMask),
712 const_iv (Button5MotionMask),
713 const_iv (ButtonMotionMask),
714 const_iv (KeymapStateMask),
715 const_iv (ExposureMask),
716 const_iv (VisibilityChangeMask),
717 const_iv (StructureNotifyMask),
718 const_iv (ResizeRedirectMask),
719 const_iv (SubstructureNotifyMask),
720 const_iv (SubstructureRedirectMask),
721 const_iv (FocusChangeMask),
722 const_iv (PropertyChangeMask),
723 const_iv (ColormapChangeMask),
724 const_iv (OwnerGrabButtonMask),
662 725
663 rxvt_term *term = new rxvt_term; 726 const_iv (KeyPress),
727 const_iv (KeyRelease),
728 const_iv (ButtonPress),
729 const_iv (ButtonRelease),
730 const_iv (MotionNotify),
731 const_iv (EnterNotify),
732 const_iv (LeaveNotify),
733 const_iv (FocusIn),
734 const_iv (FocusOut),
735 const_iv (KeymapNotify),
736 const_iv (Expose),
737 const_iv (GraphicsExpose),
738 const_iv (NoExpose),
739 const_iv (VisibilityNotify),
740 const_iv (CreateNotify),
741 const_iv (DestroyNotify),
742 const_iv (UnmapNotify),
743 const_iv (MapNotify),
744 const_iv (MapRequest),
745 const_iv (ReparentNotify),
746 const_iv (ConfigureNotify),
747 const_iv (ConfigureRequest),
748 const_iv (GravityNotify),
749 const_iv (ResizeRequest),
750 const_iv (CirculateNotify),
751 const_iv (CirculateRequest),
752 const_iv (PropertyNotify),
753 const_iv (SelectionClear),
754 const_iv (SelectionRequest),
755 const_iv (SelectionNotify),
756 const_iv (ColormapNotify),
757 const_iv (ClientMessage),
758 const_iv (MappingNotify),
759 };
664 760
665 term->argv = argv; 761 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]);
666 762 civ-- > const_iv; )
667 try 763 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
668 {
669 if (!term->init (argv->size (), argv->begin ()))
670 term = 0;
671 }
672 catch (const class rxvt_failure_exception &e)
673 {
674 term->destroy ();
675 croak ("exception caught while initializing new terminal instance");
676 }
677
678 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
679} 764}
680 OUTPUT:
681 RETVAL
682
683void
684set_should_invoke (int htype, int value)
685 CODE:
686 rxvt_perl.should_invoke [htype] = value;
687 765
688void 766void
689warn (const char *msg) 767warn (const char *msg)
690 CODE: 768 CODE:
691 rxvt_warn ("%s", msg); 769 rxvt_warn ("%s", msg);
692 770
693void 771void
694fatal (const char *msg) 772fatal (const char *msg)
695 CODE: 773 CODE:
696 rxvt_fatal ("%s", msg); 774 rxvt_fatal ("%s", msg);
775
776void
777_exit (int status)
697 778
698NV 779NV
699NOW () 780NOW ()
700 CODE: 781 CODE:
701 RETVAL = NOW; 782 RETVAL = NOW;
750 OUTPUT: 831 OUTPUT:
751 RETVAL 832 RETVAL
752 833
753MODULE = urxvt PACKAGE = urxvt::term 834MODULE = urxvt PACKAGE = urxvt::term
754 835
836SV *
837_new (...)
838 CODE:
839{
840 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
841 croak ("first argument to urxvt::term->_new must be arrayref");
842
843 rxvt_term *term = new rxvt_term;
844
845 term->argv = new stringvec;
846 term->envv = new stringvec;
847
848 for (int i = 1; i < items; i++)
849 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
850
851 AV *envv = (AV *)SvRV (ST (0));
852 for (int i = av_len (envv) + 1; i--; )
853 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
854
855 term->envv->push_back (0);
856
857 bool success;
858
859 try
860 {
861 success = term->init (term->argv->size (), term->argv->begin ());
862 }
863 catch (const class rxvt_failure_exception &e)
864 {
865 success = false;
866 }
867
868 if (!success)
869 {
870 term->destroy ();
871 croak ("error while initializing new terminal instance");
872 }
873
874 RETVAL = term && term->perl.self
875 ? newSVterm (term) : &PL_sv_undef;
876}
877 OUTPUT:
878 RETVAL
879
755void 880void
756rxvt_term::destroy () 881rxvt_term::destroy ()
882
883#if ENABLE_PERL_FRILLS
884
885void
886rxvt_term::XListProperties (U32 window)
887 PPCODE:
888{
889 int count;
890 Atom *props = XListProperties (THIS->display->display, (Window)window, &count);
891
892 EXTEND (SP, count);
893 while (count--)
894 PUSHs (newSVuv ((U32)props [count]));
895
896 XFree (props);
897}
898
899void
900rxvt_term::XGetWindowProperty (U32 window, U32 property)
901 PPCODE:
902{
903 Atom type;
904 int format;
905 unsigned long nitems;
906 unsigned long bytes_after;
907 unsigned char *prop;
908 XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property,
909 0, 1<<30, 0, AnyPropertyType,
910 &type, &format, &nitems, &bytes_after, &prop);
911 if (type != None)
912 {
913 EXTEND (SP, 3);
914 PUSHs (newSVuv ((U32)type));
915 PUSHs (newSViv (format));
916 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
917 XFree (prop);
918 }
919}
920
921void
922rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data)
923 CODE:
924{
925 STRLEN len;
926 char *data_ = SvPVbyte (data, len);
927
928 XChangeProperty (THIS->display->display, (Window)window, (Atom)property,
929 type, format, PropModeReplace,
930 (unsigned char *)data, len * 8 / format);
931}
932
933void
934rxvt_term::XDeleteProperty (U32 window, U32 property)
935 CODE:
936 XDeleteProperty (THIS->display->display, (Window)window, (Atom)property);
937
938U32
939rxvt_term::DefaultRootWindow ()
940 CODE:
941 RETVAL = (U32)THIS->display->root;
942 OUTPUT:
943 RETVAL
944
945U32
946rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height)
947 CODE:
948 RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent,
949 x, y, width, height, 0,
950 THIS->pix_colors_focused[Color_border],
951 THIS->pix_colors_focused[Color_border]);
952 OUTPUT:
953 RETVAL
954
955void
956rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0)
957 CODE:
958 XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y);
959
960void
961rxvt_term::XMapWindow (U32 window)
962 CODE:
963 XMapWindow (THIS->display->display, (Window)window);
964
965void
966rxvt_term::XUnmapWindow (U32 window)
967 CODE:
968 XUnmapWindow (THIS->display->display, (Window)window);
969
970#endif
971
972void
973rxvt_term::set_should_invoke (int htype, int inc)
974 CODE:
975 THIS->perl.should_invoke [htype] += inc;
757 976
758void 977void
759rxvt_term::grab_button (int button, U32 modifiers) 978rxvt_term::grab_button (int button, U32 modifiers)
760 CODE: 979 CODE:
761 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 980 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
782} 1001}
783 OUTPUT: 1002 OUTPUT:
784 RETVAL 1003 RETVAL
785 1004
786void 1005void
787rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) 1006rxvt_term::allow_events_async ()
788 CODE: 1007 CODE:
789 XAllowEvents (THIS->display->display, AsyncBoth, eventtime); 1008 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
790 1009
791void 1010void
792rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) 1011rxvt_term::allow_events_sync ()
793 CODE: 1012 CODE:
794 XAllowEvents (THIS->display->display, SyncBoth, eventtime); 1013 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
795 1014
796void 1015void
797rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) 1016rxvt_term::allow_events_replay ()
798 CODE: 1017 CODE:
799 XAllowEvents (THIS->display->display, ReplayPointer, eventtime); 1018 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
800 XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); 1019 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
801 1020
802void 1021void
803rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) 1022rxvt_term::ungrab ()
804 CODE: 1023 CODE:
805 THIS->perl.grabtime = 0; 1024 ungrab (THIS);
806 XUngrabKeyboard (THIS->display->display, eventtime);
807 XUngrabPointer (THIS->display->display, eventtime);
808 1025
809int 1026int
810rxvt_term::strwidth (SV *str) 1027rxvt_term::strwidth (SV *str)
811 CODE: 1028 CODE:
812{ 1029{
831 char *mbstr = rxvt_wcstombs (wstr); 1048 char *mbstr = rxvt_wcstombs (wstr);
832 rxvt_pop_locale (); 1049 rxvt_pop_locale ();
833 1050
834 free (wstr); 1051 free (wstr);
835 1052
836 RETVAL = taint_if (newSVpv (mbstr, 0), str); 1053 RETVAL = newSVpv (mbstr, 0);
837 free (mbstr); 1054 free (mbstr);
838} 1055}
839 OUTPUT: 1056 OUTPUT:
840 RETVAL 1057 RETVAL
841 1058
848 1065
849 rxvt_push_locale (THIS->locale); 1066 rxvt_push_locale (THIS->locale);
850 wchar_t *wstr = rxvt_mbstowcs (data, len); 1067 wchar_t *wstr = rxvt_mbstowcs (data, len);
851 rxvt_pop_locale (); 1068 rxvt_pop_locale ();
852 1069
853 RETVAL = taint_if (wcs2sv (wstr), octets); 1070 RETVAL = wcs2sv (wstr);
854 free (wstr); 1071 free (wstr);
855} 1072}
856 OUTPUT: 1073 OUTPUT:
857 RETVAL 1074 RETVAL
858 1075
867#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1084#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
868#define TERM_OFFSET_focus TERM_OFFSET(focus) 1085#define TERM_OFFSET_focus TERM_OFFSET(focus)
869#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1086#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
870#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1087#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
871#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1088#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
872#define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) 1089#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
873 1090
874int 1091int
875rxvt_term::width () 1092rxvt_term::width ()
876 ALIAS: 1093 ALIAS:
877 width = TERM_OFFSET_width 1094 width = TERM_OFFSET_width
883 ncol = TERM_OFFSET_ncol 1100 ncol = TERM_OFFSET_ncol
884 focus = TERM_OFFSET_focus 1101 focus = TERM_OFFSET_focus
885 mapped = TERM_OFFSET_mapped 1102 mapped = TERM_OFFSET_mapped
886 saveLines = TERM_OFFSET_saveLines 1103 saveLines = TERM_OFFSET_saveLines
887 total_rows = TERM_OFFSET_total_rows 1104 total_rows = TERM_OFFSET_total_rows
888 nsaved = TERM_OFFSET_nsaved 1105 top_row = TERM_OFFSET_top_row
889 CODE: 1106 CODE:
890 RETVAL = *(int *)((char *)THIS + ix); 1107 RETVAL = *(int *)((char *)THIS + ix);
891 OUTPUT: 1108 OUTPUT:
892 RETVAL 1109 RETVAL
893 1110
905 case 2: RETVAL = THIS->ModNumLockMask; break; 1122 case 2: RETVAL = THIS->ModNumLockMask; break;
906 } 1123 }
907 OUTPUT: 1124 OUTPUT:
908 RETVAL 1125 RETVAL
909 1126
1127char *
1128rxvt_term::display_id ()
1129 ALIAS:
1130 display_id = 0
1131 locale = 1
1132 CODE:
1133 switch (ix)
1134 {
1135 case 0: RETVAL = THIS->display->id; break;
1136 case 1: RETVAL = THIS->locale; break;
1137 }
1138 OUTPUT:
1139 RETVAL
1140
1141SV *
1142rxvt_term::_env ()
1143 CODE:
1144{
1145 if (THIS->envv)
1146 {
1147 AV *av = newAV ();
1148
1149 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i)
1150 if (*i)
1151 av_push (av, newSVpv (*i, 0));
1152
1153 RETVAL = newRV_noinc ((SV *)av);
1154 }
1155 else
1156 RETVAL = &PL_sv_undef;
1157}
1158 OUTPUT:
1159 RETVAL
1160
1161int
1162rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1163 CODE:
1164 RETVAL = THIS->pty_ev.events;
1165 if (events != EVENT_UNDEF)
1166 THIS->pty_ev.set (events);
1167 OUTPUT:
1168 RETVAL
1169
910U32 1170U32
911rxvt_term::parent () 1171rxvt_term::parent ()
912 CODE: 1172 CODE:
913 RETVAL = (U32)THIS->parent [0]; 1173 RETVAL = (U32)THIS->parent [0];
914 OUTPUT: 1174 OUTPUT:
919 CODE: 1179 CODE:
920 RETVAL = (U32)THIS->vt; 1180 RETVAL = (U32)THIS->vt;
921 OUTPUT: 1181 OUTPUT:
922 RETVAL 1182 RETVAL
923 1183
1184void
1185rxvt_term::vt_emask_add (U32 emask)
1186 CODE:
1187 THIS->vt_emask_perl |= emask;
1188 THIS->vt_select_input ();
1189
924U32 1190U32
925rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) 1191rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
926 CODE: 1192 CODE:
927{
928 RETVAL = THIS->rstyle; 1193 RETVAL = THIS->rstyle;
929 THIS->rstyle = new_rstyle; 1194 THIS->rstyle = new_rstyle;
930}
931 OUTPUT: 1195 OUTPUT:
932 RETVAL 1196 RETVAL
933 1197
934int 1198int
935rxvt_term::view_start (int newval = -1) 1199rxvt_term::view_start (int newval = 1)
1200 PROTOTYPE: $;$
936 CODE: 1201 CODE:
937{ 1202{
938 RETVAL = THIS->view_start; 1203 RETVAL = THIS->view_start;
939 1204
940 if (newval >= 0) 1205 if (newval <= 0)
941 { 1206 THIS->scr_changeview (max (newval, THIS->top_row));
942 THIS->view_start = min (newval, THIS->nsaved);
943 THIS->scr_changeview (RETVAL);
944 }
945} 1207}
946 OUTPUT: 1208 OUTPUT:
947 RETVAL 1209 RETVAL
948 1210
949void 1211void
953 1215
954void 1216void
955rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1217rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
956 PPCODE: 1218 PPCODE:
957{ 1219{
958 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1220 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
959 XSRETURN_EMPTY; 1221 XSRETURN_EMPTY;
960 1222
961 line_t &l = ROW(row_number); 1223 line_t &l = ROW(row_number);
962 1224
963 if (GIMME_V != G_VOID) 1225 if (GIMME_V != G_VOID)
965 wchar_t *wstr = new wchar_t [THIS->ncol]; 1227 wchar_t *wstr = new wchar_t [THIS->ncol];
966 1228
967 for (int col = 0; col < THIS->ncol; col++) 1229 for (int col = 0; col < THIS->ncol; col++)
968 wstr [col] = l.t [col]; 1230 wstr [col] = l.t [col];
969 1231
970 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); 1232 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
971 1233
972 delete [] wstr; 1234 delete [] wstr;
973 } 1235 }
974 1236
975 if (new_text) 1237 if (new_text)
996 1258
997void 1259void
998rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1260rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
999 PPCODE: 1261 PPCODE:
1000{ 1262{
1001 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1263 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1002 XSRETURN_EMPTY; 1264 XSRETURN_EMPTY;
1003 1265
1004 line_t &l = ROW(row_number); 1266 line_t &l = ROW(row_number);
1005 1267
1006 if (GIMME_V != G_VOID) 1268 if (GIMME_V != G_VOID)
1036 1298
1037int 1299int
1038rxvt_term::ROW_l (int row_number, int new_length = -1) 1300rxvt_term::ROW_l (int row_number, int new_length = -1)
1039 CODE: 1301 CODE:
1040{ 1302{
1041 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1303 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1042 XSRETURN_EMPTY; 1304 XSRETURN_EMPTY;
1043 1305
1044 line_t &l = ROW(row_number); 1306 line_t &l = ROW(row_number);
1045 RETVAL = l.l; 1307 RETVAL = l.l;
1046 1308
1052 1314
1053bool 1315bool
1054rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) 1316rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
1055 CODE: 1317 CODE:
1056{ 1318{
1057 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1319 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1058 XSRETURN_EMPTY; 1320 XSRETURN_EMPTY;
1059 1321
1060 line_t &l = ROW(row_number); 1322 line_t &l = ROW(row_number);
1061 RETVAL = l.is_longer (); 1323 RETVAL = l.is_longer ();
1062 1324
1096 else 1358 else
1097 *r++ = *s; 1359 *r++ = *s;
1098 1360
1099 rxvt_pop_locale (); 1361 rxvt_pop_locale ();
1100 1362
1101 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); 1363 RETVAL = wcs2sv (rstr, r - rstr);
1102 1364
1103 delete [] rstr; 1365 delete [] rstr;
1104} 1366}
1105 OUTPUT: 1367 OUTPUT:
1106 RETVAL 1368 RETVAL
1132 else if (IS_COMPOSE (*s)) 1394 else if (IS_COMPOSE (*s))
1133 r += rxvt_composite.expand (*s, r); 1395 r += rxvt_composite.expand (*s, r);
1134 else 1396 else
1135 *r++ = *s; 1397 *r++ = *s;
1136 1398
1137 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); 1399 RETVAL = wcs2sv (rstr, r - rstr);
1138 1400
1139 delete [] rstr; 1401 delete [] rstr;
1140} 1402}
1141 OUTPUT: 1403 OUTPUT:
1142 RETVAL 1404 RETVAL
1164 1426
1165 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1427 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1166 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1428 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1167 1429
1168 if (GIMME_V != G_VOID) 1430 if (GIMME_V != G_VOID)
1169 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); 1431 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef);
1170 1432
1171 if (newval) 1433 if (newval)
1172 { 1434 {
1173 if (SvOK (newval)) 1435 if (SvOK (newval))
1174 { 1436 {
1179 else 1441 else
1180 THIS->rs [index] = 0; 1442 THIS->rs [index] = 0;
1181 } 1443 }
1182} 1444}
1183 1445
1446const char *
1447rxvt_term::x_resource (const char *name)
1448
1184bool 1449bool
1185rxvt_term::option (U32 optval, int set = -1) 1450rxvt_term::option (U32 optval, int set = -1)
1186 CODE: 1451 CODE:
1187{ 1452{
1188 RETVAL = THIS->options & optval; 1453 RETVAL = THIS->options & optval;
1215 } 1480 }
1216} 1481}
1217 OUTPUT: 1482 OUTPUT:
1218 RETVAL 1483 RETVAL
1219 1484
1485bool
1486rxvt_term::parse_keysym (char *keysym, char *str)
1487 CODE:
1488 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1489 THIS->keyboard->register_done ();
1490 OUTPUT:
1491 RETVAL
1492
1220void 1493void
1221rxvt_term::cur (...) 1494rxvt_term::screen_cur (...)
1222 PROTOTYPE: $;$$ 1495 PROTOTYPE: $;$$
1223 ALIAS: 1496 ALIAS:
1224 screen_cur = 0 1497 screen_cur = 0
1225 selection_beg = 1 1498 selection_beg = 1
1226 selection_end = 2 1499 selection_end = 2
1239 PUSHs (sv_2mortal (newSViv (rc.col))); 1512 PUSHs (sv_2mortal (newSViv (rc.col)));
1240 } 1513 }
1241 1514
1242 if (items == 3) 1515 if (items == 3)
1243 { 1516 {
1244 rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); 1517 rc.row = SvIV (ST (1));
1245 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); 1518 rc.col = SvIV (ST (2));
1519
1520 if (ix == 2 && rc.col == 0)
1521 {
1522 rc.row--;
1523 rc.col = THIS->ncol;
1524 }
1525
1526 clamp_it (rc.col, 0, THIS->ncol);
1527 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1246 1528
1247 if (ix) 1529 if (ix)
1248 THIS->want_refresh = 1; 1530 THIS->want_refresh = 1;
1249 } 1531 }
1250} 1532}
1251 1533
1534char
1535rxvt_term::cur_charset ()
1536 CODE:
1537 RETVAL = THIS->charsets [THIS->screen.charset];
1538 OUTPUT:
1539 RETVAL
1540
1541#void
1542#rxvt_term::selection_clear ()
1543
1544void
1545rxvt_term::selection_make (U32 eventtime, bool rect = false)
1546 CODE:
1547 THIS->selection.op = SELECTION_CONT;
1548 THIS->selection.rect = rect;
1549 THIS->selection_make (eventtime);
1550
1252int 1551int
1253rxvt_term::selection_grab (U32 eventtime) 1552rxvt_term::selection_grab (U32 eventtime)
1254 1553
1255void 1554void
1256rxvt_term::selection (SV *newtext = 0) 1555rxvt_term::selection (SV *newtext = 0)
1257 PPCODE: 1556 PPCODE:
1258{ 1557{
1259 if (GIMME_V != G_VOID) 1558 if (GIMME_V != G_VOID)
1559 XPUSHs (THIS->selection.text
1260 XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))); 1560 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))
1561 : &PL_sv_undef);
1261 1562
1262 if (newtext) 1563 if (newtext)
1263 { 1564 {
1264 free (THIS->selection.text); 1565 free (THIS->selection.text);
1265 1566
1266 THIS->selection.text = sv2wcs (newtext); 1567 THIS->selection.text = sv2wcs (newtext);
1267 THIS->selection.len = wcslen (THIS->selection.text); 1568 THIS->selection.len = wcslen (THIS->selection.text);
1268 } 1569 }
1269} 1570}
1571
1572void
1573rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle1 = RS_RVid, U32 rstyle2 = RS_RVid | RS_Uline)
1574
1575void
1576rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1577
1578void
1579rxvt_term::scr_bell ()
1270 1580
1271void 1581void
1272rxvt_term::scr_add_lines (SV *string) 1582rxvt_term::scr_add_lines (SV *string)
1273 CODE: 1583 CODE:
1274{ 1584{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines