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.61 by root, Thu Jan 12 10:02:20 2006 UTC vs.
Revision 1.73 by root, Wed Jan 18 09:40:53 2006 UTC

39#include "rxvtutil.h" 39#include "rxvtutil.h"
40#include "rxvtperl.h" 40#include "rxvtperl.h"
41 41
42#include "perlxsi.c" 42#include "perlxsi.c"
43 43
44#if defined(HAVE_SCROLLBARS) || defined(MENUBAR) 44#ifdef HAVE_SCROLLBARS
45# define GRAB_CURSOR THIS->leftptr_cursor 45# define GRAB_CURSOR THIS->leftptr_cursor
46#else 46#else
47# define GRAB_CURSOR None 47# define GRAB_CURSOR None
48#endif 48#endif
49 49
50#undef LINENO 50#undef LINENO
51#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)
52#undef ROW 52#undef ROW
53#define ROW(n) THIS->row_buf [LINENO (n)] 53#define ROW(n) THIS->row_buf [LINENO (n)]
54 54
55#define ENABLE_PERL_FRILLS 1
56
55///////////////////////////////////////////////////////////////////////////// 57/////////////////////////////////////////////////////////////////////////////
56
57static SV *
58taint (SV *sv)
59{
60 SvTAINT (sv);
61 return sv;
62}
63
64static SV *
65taint_if (SV *sv, SV *src)
66{
67 if (SvTAINTED (src))
68 SvTAINT (sv);
69
70 return sv;
71}
72 58
73static wchar_t * 59static wchar_t *
74sv2wcs (SV *sv) 60sv2wcs (SV *sv)
75{ 61{
76 STRLEN len; 62 STRLEN len;
347 for (int y = ov_h; y--; ) 333 for (int y = ov_h; y--; )
348 { 334 {
349 text_t *t1 = text [y]; 335 text_t *t1 = text [y];
350 rend_t *r1 = rend [y]; 336 rend_t *r1 = rend [y];
351 337
352 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;
353 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;
354 340
355 for (int x = ov_w; x--; ) 341 for (int x = ov_w; x--; )
356 { 342 {
357 text_t t = *t1; *t1++ = *t2; *t2++ = t; 343 text_t t = *t1; *t1++ = *t2; *t2++ = t;
358 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));
405 perl_free (perl); 391 perl_free (perl);
406 } 392 }
407} 393}
408 394
409void 395void
410rxvt_perl_interp::init () 396rxvt_perl_interp::init (rxvt_term *term)
411{ 397{
412 if (!perl) 398 if (!perl)
413 { 399 {
400 rxvt_push_locale (""); // perl init destroys current locale
401
414 perl_environ = rxvt_environ; 402 perl_environ = rxvt_environ;
415 swap (perl_environ, environ); 403 swap (perl_environ, environ);
416 404
417 char *argv[] = { 405 char *argv[] = {
418 "", 406 "",
419 "-T", 407 "-e"
420 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 408 "BEGIN {"
409 " urxvt->bootstrap;"
410 " unshift @INC, '" LIBDIR "';"
411 "}"
412 ""
413 "use urxvt;"
421 }; 414 };
422 415
423 perl = perl_alloc (); 416 perl = perl_alloc ();
424 perl_construct (perl); 417 perl_construct (perl);
425 418
426 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) 419 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL)
427 || perl_run (perl)) 420 || perl_run (perl))
428 { 421 {
429 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 422 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
430 423
431 perl_destruct (perl); 424 perl_destruct (perl);
432 perl_free (perl); 425 perl_free (perl);
433 perl = 0; 426 perl = 0;
434 } 427 }
435 428
436 swap (perl_environ, environ); 429 swap (perl_environ, environ);
430
431 rxvt_pop_locale ();
432 }
433
434 if (perl)
435 {
436 // runs outside of perls ENV
437 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
438 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
437 } 439 }
438} 440}
439 441
440static void 442static void
441ungrab (rxvt_term *THIS) 443ungrab (rxvt_term *THIS)
446 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 448 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
447 THIS->perl.grabtime = 0; 449 THIS->perl.grabtime = 0;
448 } 450 }
449} 451}
450 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))
459 {
460 hv_iterinit (hv);
461
462 while (HE *he = hv_iternext (hv))
463 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
464 }
465}
466
451bool 467bool
452rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 468rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
453{ 469{
454 if (!perl) 470 if (!perl || !term->perl.self)
455 return false; 471 return false;
456 472
457 if (htype == HOOK_INIT) // first hook ever called 473 // pre-handling of some events
458 { 474 if (htype == HOOK_REFRESH_END)
459 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 475 swap_overlays (term);
460 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 476
461 } 477 swap (perl_environ, environ);
462 else if (!term->perl.self) 478
463 return false; // perl not initialized for this instance 479 bool event_consumed;
464 else if (htype == HOOK_DESTROY) 480
465 { 481 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
466 // handled later 482 || term->perl.should_invoke [htype])
467 } 483 try
468 else
469 {
470 if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
471 { 484 {
472 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 485 dSP;
486 va_list ap;
473 487
474 if (HvKEYS (hv)) 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)
475 { 502 {
476 hv_iterinit (hv);
477
478 while (HE *he = hv_iternext (hv))
479 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
480 }
481
482 }
483
484 if (!should_invoke [htype])
485 return false;
486 }
487
488 swap (perl_environ, environ);
489
490 try
491 {
492 dSP;
493 va_list ap;
494
495 va_start (ap, htype);
496
497 ENTER;
498 SAVETMPS;
499
500 PUSHMARK (SP);
501
502 XPUSHs (sv_2mortal (newSVterm (term)));
503 XPUSHs (sv_2mortal (newSViv (htype)));
504
505 for (;;) {
506 data_type dt = (data_type)va_arg (ap, int);
507
508 switch (dt)
509 {
510 case DT_INT: 503 case DT_INT:
511 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); 504 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
512 break; 505 break;
513 506
514 case DT_LONG: 507 case DT_LONG:
515 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 508 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
516 break; 509 break;
517 510
518 case DT_STR: 511 case DT_STR:
519 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); 512 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
520 break; 513 break;
521 514
522 case DT_STR_LEN: 515 case DT_STR_LEN:
523 { 516 {
524 char *str = va_arg (ap, char *); 517 char *str = va_arg (ap, char *);
525 int len = va_arg (ap, int); 518 int len = va_arg (ap, int);
526 519
527 XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); 520 XPUSHs (sv_2mortal (newSVpvn (str, len)));
528 } 521 }
529 break; 522 break;
530 523
531 case DT_WCS_LEN: 524 case DT_WCS_LEN:
532 { 525 {
533 wchar_t *wstr = va_arg (ap, wchar_t *); 526 wchar_t *wstr = va_arg (ap, wchar_t *);
534 int wlen = va_arg (ap, int); 527 int wlen = va_arg (ap, int);
535 528
536 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); 529 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
537 } 530 }
538 break; 531 break;
539 532
540 case DT_XEVENT: 533 case DT_XEVENT:
541 { 534 {
542 XEvent *xe = va_arg (ap, XEvent *); 535 XEvent *xe = va_arg (ap, XEvent *);
543 HV *hv = newHV (); 536 HV *hv = newHV ();
544 537
545# 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)
546# 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)
547# undef set 540# undef set
548 541
549 setiv (type, xe->type); 542 setiv (type, xe->type);
550 setiv (send_event, xe->xany.send_event); 543 setiv (send_event, xe->xany.send_event);
551 setiv (serial, xe->xany.serial); 544 setiv (serial, xe->xany.serial);
552 545
553 switch (xe->type) 546 switch (xe->type)
554 { 547 {
555 case KeyPress: 548 case KeyPress:
556 case KeyRelease: 549 case KeyRelease:
557 case ButtonPress: 550 case ButtonPress:
558 case ButtonRelease: 551 case ButtonRelease:
559 case MotionNotify: 552 case MotionNotify:
560 setiv (time, xe->xmotion.time); 553 setiv (time, xe->xmotion.time);
561 setiv (x, xe->xmotion.x); 554 setiv (x, xe->xmotion.x);
562 setiv (y, xe->xmotion.y); 555 setiv (y, xe->xmotion.y);
563 setiv (row, xe->xmotion.y / term->fheight); 556 setiv (row, xe->xmotion.y / term->fheight);
564 setiv (col, xe->xmotion.x / term->fwidth); 557 setiv (col, xe->xmotion.x / term->fwidth);
565 setiv (x_root, xe->xmotion.x_root); 558 setiv (x_root, xe->xmotion.x_root);
566 setiv (y_root, xe->xmotion.y_root); 559 setiv (y_root, xe->xmotion.y_root);
567 setiv (state, xe->xmotion.state); 560 setiv (state, xe->xmotion.state);
568 break; 561 break;
569 } 562 }
570 563
571 switch (xe->type) 564 switch (xe->type)
572 { 565 {
573 case KeyPress: 566 case KeyPress:
574 case KeyRelease: 567 case KeyRelease:
575 setiv (keycode, xe->xkey.keycode); 568 setiv (keycode, xe->xkey.keycode);
576 break; 569 break;
577 570
578 case ButtonPress: 571 case ButtonPress:
579 case ButtonRelease: 572 case ButtonRelease:
580 setiv (button, xe->xbutton.button); 573 setiv (button, xe->xbutton.button);
581 break; 574 break;
582 575
583 case MotionNotify: 576 case MotionNotify:
584 setiv (is_hint, xe->xmotion.is_hint); 577 setiv (is_hint, xe->xmotion.is_hint);
585 break; 578 break;
586 } 579 }
587 580
588 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 581 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
589 } 582 }
590 break; 583 break;
591 584
592 case DT_END: 585 case DT_END:
593 { 586 goto call;
594 va_end (ap);
595 587
596 PUTBACK;
597 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
598 SPAGAIN;
599
600 if (count)
601 {
602 SV *status = POPs;
603 count = SvTRUE (status);
604 }
605
606 PUTBACK;
607 FREETMPS;
608 LEAVE;
609
610 if (SvTRUE (ERRSV))
611 {
612 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
613 ungrab (term); // better lose the grab than the session
614 }
615
616 if (htype == HOOK_DESTROY)
617 {
618 clearSVptr ((SV *)term->perl.self);
619 SvREFCNT_dec ((SV *)term->perl.self);
620 }
621
622 swap (perl_environ, environ);
623 return count;
624 }
625
626 default: 588 default:
627 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); 589 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
628 } 590 }
591 }
592
593 call:
594 va_end (ap);
595
596 PUTBACK;
597 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
598 SPAGAIN;
599
600 if (count)
601 {
602 SV *status = POPs;
603 count = SvTRUE (status);
604 }
605
606 PUTBACK;
607 FREETMPS;
608 LEAVE;
609
610 if (SvTRUE (ERRSV))
611 {
612 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
613 ungrab (term); // better lose the grab than the session
614 }
615
616 event_consumed = !!count;
629 } 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);
630 } 633 }
631 catch (...) 634
632 {
633 swap (perl_environ, environ); 635 swap (perl_environ, environ);
634 throw; 636
635 } 637 return event_consumed;
636} 638}
637 639
638///////////////////////////////////////////////////////////////////////////// 640/////////////////////////////////////////////////////////////////////////////
639 641
640MODULE = urxvt PACKAGE = urxvt 642MODULE = urxvt PACKAGE = urxvt
659# include "optinc.h" 661# include "optinc.h"
660# undef nodef 662# undef nodef
661# undef def 663# undef def
662 664
663 HV *stash = gv_stashpv ("urxvt", 1); 665 HV *stash = gv_stashpv ("urxvt", 1);
664# 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 }
665 export_const_iv (DEFAULT_RSTYLE); 671 const_iv (DEFAULT_RSTYLE),
666 export_const_iv (OVERLAY_RSTYLE); 672 const_iv (OVERLAY_RSTYLE),
667 export_const_iv (RS_Bold); 673 const_iv (RS_Bold),
668 export_const_iv (RS_Italic); 674 const_iv (RS_Italic),
669 export_const_iv (RS_Blink); 675 const_iv (RS_Blink),
670 export_const_iv (RS_RVid); 676 const_iv (RS_RVid),
671 export_const_iv (RS_Uline); 677 const_iv (RS_Uline),
672 678
673 export_const_iv (CurrentTime); 679 const_iv (CurrentTime),
674 export_const_iv (ShiftMask); 680 const_iv (ShiftMask),
675 export_const_iv (LockMask); 681 const_iv (LockMask),
676 export_const_iv (ControlMask); 682 const_iv (ControlMask),
677 export_const_iv (Mod1Mask); 683 const_iv (Mod1Mask),
678 export_const_iv (Mod2Mask); 684 const_iv (Mod2Mask),
679 export_const_iv (Mod3Mask); 685 const_iv (Mod3Mask),
680 export_const_iv (Mod4Mask); 686 const_iv (Mod4Mask),
681 export_const_iv (Mod5Mask); 687 const_iv (Mod5Mask),
682 export_const_iv (Button1Mask); 688 const_iv (Button1Mask),
683 export_const_iv (Button2Mask); 689 const_iv (Button2Mask),
684 export_const_iv (Button3Mask); 690 const_iv (Button3Mask),
685 export_const_iv (Button4Mask); 691 const_iv (Button4Mask),
686 export_const_iv (Button5Mask); 692 const_iv (Button5Mask),
687 export_const_iv (AnyModifier); 693 const_iv (AnyModifier),
688 694
689 export_const_iv (EVENT_NONE); 695 const_iv (EVENT_NONE),
690 export_const_iv (EVENT_READ); 696 const_iv (EVENT_READ),
691 export_const_iv (EVENT_WRITE); 697 const_iv (EVENT_WRITE),
692}
693 698
694void 699 const_iv (NoEventMask),
695set_should_invoke (int htype, int value) 700 const_iv (KeyPressMask),
696 CODE: 701 const_iv (KeyReleaseMask),
697 rxvt_perl.should_invoke [htype] = value; 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),
725
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 };
760
761 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]);
762 civ-- > const_iv; )
763 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
764}
698 765
699void 766void
700warn (const char *msg) 767warn (const char *msg)
701 CODE: 768 CODE:
702 rxvt_warn ("%s", msg); 769 rxvt_warn ("%s", msg);
704void 771void
705fatal (const char *msg) 772fatal (const char *msg)
706 CODE: 773 CODE:
707 rxvt_fatal ("%s", msg); 774 rxvt_fatal ("%s", msg);
708 775
709SV *
710untaint (SV *sv)
711 CODE:
712 RETVAL = newSVsv (sv);
713 SvTAINTED_off (RETVAL);
714 OUTPUT:
715 RETVAL
716
717void 776void
718_exit (int status) 777_exit (int status)
719
720bool
721safe ()
722 CODE:
723 RETVAL = !rxvt_tainted ();
724 OUTPUT:
725 RETVAL
726 778
727NV 779NV
728NOW () 780NOW ()
729 CODE: 781 CODE:
730 RETVAL = NOW; 782 RETVAL = NOW;
825 OUTPUT: 877 OUTPUT:
826 RETVAL 878 RETVAL
827 879
828void 880void
829rxvt_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;
830 976
831void 977void
832rxvt_term::grab_button (int button, U32 modifiers) 978rxvt_term::grab_button (int button, U32 modifiers)
833 CODE: 979 CODE:
834 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 980 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
902 char *mbstr = rxvt_wcstombs (wstr); 1048 char *mbstr = rxvt_wcstombs (wstr);
903 rxvt_pop_locale (); 1049 rxvt_pop_locale ();
904 1050
905 free (wstr); 1051 free (wstr);
906 1052
907 RETVAL = taint_if (newSVpv (mbstr, 0), str); 1053 RETVAL = newSVpv (mbstr, 0);
908 free (mbstr); 1054 free (mbstr);
909} 1055}
910 OUTPUT: 1056 OUTPUT:
911 RETVAL 1057 RETVAL
912 1058
919 1065
920 rxvt_push_locale (THIS->locale); 1066 rxvt_push_locale (THIS->locale);
921 wchar_t *wstr = rxvt_mbstowcs (data, len); 1067 wchar_t *wstr = rxvt_mbstowcs (data, len);
922 rxvt_pop_locale (); 1068 rxvt_pop_locale ();
923 1069
924 RETVAL = taint_if (wcs2sv (wstr), octets); 1070 RETVAL = wcs2sv (wstr);
925 free (wstr); 1071 free (wstr);
926} 1072}
927 OUTPUT: 1073 OUTPUT:
928 RETVAL 1074 RETVAL
929 1075
938#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1084#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
939#define TERM_OFFSET_focus TERM_OFFSET(focus) 1085#define TERM_OFFSET_focus TERM_OFFSET(focus)
940#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1086#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
941#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1087#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
942#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1088#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
943#define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) 1089#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
944 1090
945int 1091int
946rxvt_term::width () 1092rxvt_term::width ()
947 ALIAS: 1093 ALIAS:
948 width = TERM_OFFSET_width 1094 width = TERM_OFFSET_width
954 ncol = TERM_OFFSET_ncol 1100 ncol = TERM_OFFSET_ncol
955 focus = TERM_OFFSET_focus 1101 focus = TERM_OFFSET_focus
956 mapped = TERM_OFFSET_mapped 1102 mapped = TERM_OFFSET_mapped
957 saveLines = TERM_OFFSET_saveLines 1103 saveLines = TERM_OFFSET_saveLines
958 total_rows = TERM_OFFSET_total_rows 1104 total_rows = TERM_OFFSET_total_rows
959 nsaved = TERM_OFFSET_nsaved 1105 top_row = TERM_OFFSET_top_row
960 CODE: 1106 CODE:
961 RETVAL = *(int *)((char *)THIS + ix); 1107 RETVAL = *(int *)((char *)THIS + ix);
962 OUTPUT: 1108 OUTPUT:
963 RETVAL 1109 RETVAL
964 1110
1033 CODE: 1179 CODE:
1034 RETVAL = (U32)THIS->vt; 1180 RETVAL = (U32)THIS->vt;
1035 OUTPUT: 1181 OUTPUT:
1036 RETVAL 1182 RETVAL
1037 1183
1184void
1185rxvt_term::vt_emask_add (U32 emask)
1186 CODE:
1187 THIS->vt_emask_perl |= emask;
1188 THIS->vt_select_input ();
1189
1038U32 1190U32
1039rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) 1191rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
1040 CODE: 1192 CODE:
1041{
1042 RETVAL = THIS->rstyle; 1193 RETVAL = THIS->rstyle;
1043 THIS->rstyle = new_rstyle; 1194 THIS->rstyle = new_rstyle;
1044}
1045 OUTPUT: 1195 OUTPUT:
1046 RETVAL 1196 RETVAL
1047 1197
1048int 1198int
1049rxvt_term::view_start (int newval = -1) 1199rxvt_term::view_start (int newval = 1)
1050 PROTOTYPE: $;$ 1200 PROTOTYPE: $;$
1051 CODE: 1201 CODE:
1052{ 1202{
1053 RETVAL = THIS->view_start; 1203 RETVAL = THIS->view_start;
1054 1204
1055 if (newval >= 0) 1205 if (newval <= 0)
1056 { 1206 THIS->scr_changeview (max (newval, THIS->top_row));
1057 THIS->view_start = min (newval, THIS->nsaved);
1058 THIS->scr_changeview (RETVAL);
1059 }
1060} 1207}
1061 OUTPUT: 1208 OUTPUT:
1062 RETVAL 1209 RETVAL
1063 1210
1064void 1211void
1068 1215
1069void 1216void
1070rxvt_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)
1071 PPCODE: 1218 PPCODE:
1072{ 1219{
1073 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1220 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1074 XSRETURN_EMPTY; 1221 XSRETURN_EMPTY;
1075 1222
1076 line_t &l = ROW(row_number); 1223 line_t &l = ROW(row_number);
1077 1224
1078 if (GIMME_V != G_VOID) 1225 if (GIMME_V != G_VOID)
1080 wchar_t *wstr = new wchar_t [THIS->ncol]; 1227 wchar_t *wstr = new wchar_t [THIS->ncol];
1081 1228
1082 for (int col = 0; col < THIS->ncol; col++) 1229 for (int col = 0; col < THIS->ncol; col++)
1083 wstr [col] = l.t [col]; 1230 wstr [col] = l.t [col];
1084 1231
1085 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); 1232 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1086 1233
1087 delete [] wstr; 1234 delete [] wstr;
1088 } 1235 }
1089 1236
1090 if (new_text) 1237 if (new_text)
1111 1258
1112void 1259void
1113rxvt_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)
1114 PPCODE: 1261 PPCODE:
1115{ 1262{
1116 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1263 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1117 XSRETURN_EMPTY; 1264 XSRETURN_EMPTY;
1118 1265
1119 line_t &l = ROW(row_number); 1266 line_t &l = ROW(row_number);
1120 1267
1121 if (GIMME_V != G_VOID) 1268 if (GIMME_V != G_VOID)
1151 1298
1152int 1299int
1153rxvt_term::ROW_l (int row_number, int new_length = -1) 1300rxvt_term::ROW_l (int row_number, int new_length = -1)
1154 CODE: 1301 CODE:
1155{ 1302{
1156 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1303 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1157 XSRETURN_EMPTY; 1304 XSRETURN_EMPTY;
1158 1305
1159 line_t &l = ROW(row_number); 1306 line_t &l = ROW(row_number);
1160 RETVAL = l.l; 1307 RETVAL = l.l;
1161 1308
1167 1314
1168bool 1315bool
1169rxvt_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)
1170 CODE: 1317 CODE:
1171{ 1318{
1172 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1319 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1173 XSRETURN_EMPTY; 1320 XSRETURN_EMPTY;
1174 1321
1175 line_t &l = ROW(row_number); 1322 line_t &l = ROW(row_number);
1176 RETVAL = l.is_longer (); 1323 RETVAL = l.is_longer ();
1177 1324
1211 else 1358 else
1212 *r++ = *s; 1359 *r++ = *s;
1213 1360
1214 rxvt_pop_locale (); 1361 rxvt_pop_locale ();
1215 1362
1216 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); 1363 RETVAL = wcs2sv (rstr, r - rstr);
1217 1364
1218 delete [] rstr; 1365 delete [] rstr;
1219} 1366}
1220 OUTPUT: 1367 OUTPUT:
1221 RETVAL 1368 RETVAL
1247 else if (IS_COMPOSE (*s)) 1394 else if (IS_COMPOSE (*s))
1248 r += rxvt_composite.expand (*s, r); 1395 r += rxvt_composite.expand (*s, r);
1249 else 1396 else
1250 *r++ = *s; 1397 *r++ = *s;
1251 1398
1252 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); 1399 RETVAL = wcs2sv (rstr, r - rstr);
1253 1400
1254 delete [] rstr; 1401 delete [] rstr;
1255} 1402}
1256 OUTPUT: 1403 OUTPUT:
1257 RETVAL 1404 RETVAL
1279 1426
1280 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1427 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1281 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);
1282 1429
1283 if (GIMME_V != G_VOID) 1430 if (GIMME_V != G_VOID)
1284 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);
1285 1432
1286 if (newval) 1433 if (newval)
1287 { 1434 {
1288 if (SvOK (newval)) 1435 if (SvOK (newval))
1289 { 1436 {
1296 } 1443 }
1297} 1444}
1298 1445
1299const char * 1446const char *
1300rxvt_term::x_resource (const char *name) 1447rxvt_term::x_resource (const char *name)
1301 CLEANUP:
1302 SvTAINTED_on (ST (0));
1303 1448
1304bool 1449bool
1305rxvt_term::option (U32 optval, int set = -1) 1450rxvt_term::option (U32 optval, int set = -1)
1306 CODE: 1451 CODE:
1307{ 1452{
1367 PUSHs (sv_2mortal (newSViv (rc.col))); 1512 PUSHs (sv_2mortal (newSViv (rc.col)));
1368 } 1513 }
1369 1514
1370 if (items == 3) 1515 if (items == 3)
1371 { 1516 {
1372 rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); 1517 rc.row = SvIV (ST (1));
1373 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);
1374 1528
1375 if (ix) 1529 if (ix)
1376 THIS->want_refresh = 1; 1530 THIS->want_refresh = 1;
1377 } 1531 }
1378} 1532}
1401rxvt_term::selection (SV *newtext = 0) 1555rxvt_term::selection (SV *newtext = 0)
1402 PPCODE: 1556 PPCODE:
1403{ 1557{
1404 if (GIMME_V != G_VOID) 1558 if (GIMME_V != G_VOID)
1405 XPUSHs (THIS->selection.text 1559 XPUSHs (THIS->selection.text
1406 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) 1560 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))
1407 : &PL_sv_undef); 1561 : &PL_sv_undef);
1408 1562
1409 if (newtext) 1563 if (newtext)
1410 { 1564 {
1411 free (THIS->selection.text); 1565 free (THIS->selection.text);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines