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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines