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.54 by root, Wed Jan 11 00:59:58 2006 UTC vs.
Revision 1.77 by root, Thu Jan 19 17:55:27 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
34#include "iom.h" 36#include "iom.h"
35#include "rxvt.h" 37#include "rxvt.h"
36#include "keyboard.h" 38#include "keyboard.h"
37#include "rxvtutil.h" 39#include "rxvtutil.h"
38#include "rxvtperl.h" 40#include "rxvtperl.h"
39 41
40#include "perlxsi.c" 42#include "perlxsi.c"
41 43
42#if defined(HAVE_SCROLLBARS) || defined(MENUBAR) 44#ifdef HAVE_SCROLLBARS
43# define GRAB_CURSOR THIS->leftptr_cursor 45# define GRAB_CURSOR THIS->leftptr_cursor
44#else 46#else
45# define GRAB_CURSOR None 47# define GRAB_CURSOR None
46#endif 48#endif
47 49
48#undef LINENO 50#undef LINENO
49#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)
50#undef ROW 52#undef ROW
51#define ROW(n) THIS->row_buf [LINENO (n)] 53#define ROW(n) THIS->row_buf [LINENO (n)]
52 54
55#define ENABLE_PERL_FRILLS 1
56
53///////////////////////////////////////////////////////////////////////////// 57/////////////////////////////////////////////////////////////////////////////
54
55static SV *
56taint (SV *sv)
57{
58 SvTAINT (sv);
59 return sv;
60}
61
62static SV *
63taint_if (SV *sv, SV *src)
64{
65 if (SvTAINTED (src))
66 SvTAINT (sv);
67
68 return sv;
69}
70 58
71static wchar_t * 59static wchar_t *
72sv2wcs (SV *sv) 60sv2wcs (SV *sv)
73{ 61{
74 STRLEN len; 62 STRLEN len;
223 211
224#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 212#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
225 213
226struct overlay { 214struct overlay {
227 HV *self; 215 HV *self;
216 bool visible;
228 rxvt_term *THIS; 217 rxvt_term *THIS;
229 int x, y, w, h; 218 int x, y, w, h;
230 int border; 219 int border;
231 text_t **text; 220 text_t **text;
232 rend_t **rend; 221 rend_t **rend;
241 230
242 void set (int x, int y, SV *str, SV *rend); 231 void set (int x, int y, SV *str, SV *rend);
243}; 232};
244 233
245overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 234overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
246: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2) 235: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), visible(false)
247{ 236{
248 if (border == 2) 237 if (border == 2)
249 { 238 {
250 w += 2; 239 w += 2;
251 h += 2; 240 h += 2;
312} 301}
313 302
314void 303void
315overlay::show () 304overlay::show ()
316{ 305{
317 char key[33]; sprintf (key, "%32lx", (long)this); 306 if (visible)
307 return;
318 308
309 visible = true;
310
319 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); 311 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
320 hv_store (hv, key, 32, newSViv ((long)this), 0); 312 av_push (av, newSViv ((long)this));
321} 313}
322 314
323void 315void
324overlay::hide () 316overlay::hide ()
325{ 317{
318 if (!visible)
319 return;
320
321 visible = false;
322
326 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); 323 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
327 324
328 if (ovs) 325 int i;
326
327 for (i = AvFILL (av); i >= 0; i--)
328 if (SvIV (*av_fetch (av, i, 1)) == (long)this)
329 { 329 {
330 char key[33]; sprintf (key, "%32lx", (long)this);
331
332 HV *hv = (HV *)SvRV (*ovs);
333 hv_delete (hv, key, 32, G_DISCARD); 330 av_delete (av, i, G_DISCARD);
331 break;
334 } 332 }
333
334 for (; i < AvFILL (av); i++)
335 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0)));
336
337 av_pop (av);
335} 338}
336 339
337void overlay::swap () 340void overlay::swap ()
338{ 341{
339 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 342 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
345 for (int y = ov_h; y--; ) 348 for (int y = ov_h; y--; )
346 { 349 {
347 text_t *t1 = text [y]; 350 text_t *t1 = text [y];
348 rend_t *r1 = rend [y]; 351 rend_t *r1 = rend [y];
349 352
350 text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; 353 text_t *t2 = ROW(y + ov_y + THIS->view_start).t + ov_x;
351 rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; 354 rend_t *r2 = ROW(y + ov_y + THIS->view_start).r + ov_x;
352 355
353 for (int x = ov_w; x--; ) 356 for (int x = ov_w; x--; )
354 { 357 {
355 text_t t = *t1; *t1++ = *t2; *t2++ = t; 358 text_t t = *t1; *t1++ = *t2; *t2++ = t;
356 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); 359 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t));
379 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) 382 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
380 croak ("rend must be arrayref"); 383 croak ("rend must be arrayref");
381 384
382 AV *av = (AV *)SvRV (rend); 385 AV *av = (AV *)SvRV (rend);
383 386
384 for (int col = min (av_len (av) + 1, w - x - border); col--; ) 387 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
385 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 388 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
386 } 389 }
387 390
388 THIS->want_refresh = 1; 391 THIS->want_refresh = 1;
389} 392}
392///////////////////////////////////////////////////////////////////////////// 395/////////////////////////////////////////////////////////////////////////////
393 396
394struct rxvt_perl_interp rxvt_perl; 397struct rxvt_perl_interp rxvt_perl;
395 398
396static PerlInterpreter *perl; 399static PerlInterpreter *perl;
397
398rxvt_perl_interp::rxvt_perl_interp ()
399{
400}
401 400
402rxvt_perl_interp::~rxvt_perl_interp () 401rxvt_perl_interp::~rxvt_perl_interp ()
403{ 402{
404 if (perl) 403 if (perl)
405 { 404 {
407 perl_free (perl); 406 perl_free (perl);
408 } 407 }
409} 408}
410 409
411void 410void
412rxvt_perl_interp::init () 411rxvt_perl_interp::init (rxvt_term *term)
413{ 412{
414 if (!perl) 413 if (!perl)
415 { 414 {
415 rxvt_push_locale (""); // perl init destroys current locale
416
417 perl_environ = rxvt_environ;
418 swap (perl_environ, environ);
419
416 char *argv[] = { 420 char *argv[] = {
417 "", 421 "",
418 "-T", 422 "-e"
419 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 423 "BEGIN {"
424 " urxvt->bootstrap;"
425 " unshift @INC, '" LIBDIR "';"
426 "}"
427 ""
428 "use urxvt;"
420 }; 429 };
421 430
422 perl = perl_alloc (); 431 perl = perl_alloc ();
423 perl_construct (perl); 432 perl_construct (perl);
424 433
425 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) 434 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL)
426 || perl_run (perl)) 435 || perl_run (perl))
427 { 436 {
428 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 437 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
429 438
430 perl_destruct (perl); 439 perl_destruct (perl);
431 perl_free (perl); 440 perl_free (perl);
432 perl = 0; 441 perl = 0;
433 } 442 }
443
444 swap (perl_environ, environ);
445
446 rxvt_pop_locale ();
447 }
448
449 if (perl)
450 {
451 // runs outside of perls ENV
452 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
453 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0);
434 } 454 }
435} 455}
436 456
437static void 457static void
438ungrab (rxvt_term *THIS) 458ungrab (rxvt_term *THIS)
446} 466}
447 467
448bool 468bool
449rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 469rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
450{ 470{
451 if (!perl) 471 if (!perl || !term->perl.self)
452 return false; 472 return false;
453 473
454 if (htype == HOOK_INIT) // first hook ever called 474 // pre-handling of some events
475 if (htype == HOOK_REFRESH_END)
455 { 476 {
456 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 477 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
457 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 478
479 for (int i = 0; i <= AvFILL (av); i++)
480 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
458 } 481 }
459 else if (!term->perl.self) 482
460 return false; // perl not initialized for this instance 483 swap (perl_environ, environ);
484
485 bool event_consumed;
486
487 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
488 || term->perl.should_invoke [htype])
489 try
490 {
491 dSP;
492 va_list ap;
493
494 va_start (ap, htype);
495
496 ENTER;
497 SAVETMPS;
498
499 PUSHMARK (SP);
500
501 XPUSHs (sv_2mortal (newSVterm (term)));
502 XPUSHs (sv_2mortal (newSViv (htype)));
503
504 for (;;) {
505 data_type dt = (data_type)va_arg (ap, int);
506
507 switch (dt)
508 {
509 case DT_INT:
510 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
511 break;
512
513 case DT_LONG:
514 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
515 break;
516
517 case DT_STR:
518 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
519 break;
520
521 case DT_STR_LEN:
522 {
523 char *str = va_arg (ap, char *);
524 int len = va_arg (ap, int);
525
526 XPUSHs (sv_2mortal (newSVpvn (str, len)));
527 }
528 break;
529
530 case DT_WCS_LEN:
531 {
532 wchar_t *wstr = va_arg (ap, wchar_t *);
533 int wlen = va_arg (ap, int);
534
535 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
536 }
537 break;
538
539 case DT_XEVENT:
540 {
541 XEvent *xe = va_arg (ap, XEvent *);
542 HV *hv = newHV ();
543
544# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
545# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
546# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
547# undef set
548
549 setiv (type, xe->type);
550 setiv (send_event, xe->xany.send_event);
551 setiv (serial, xe->xany.serial);
552
553 switch (xe->type)
554 {
555 case KeyPress:
556 case KeyRelease:
557 case ButtonPress:
558 case ButtonRelease:
559 case MotionNotify:
560 setuv (window, xe->xmotion.window);
561 setuv (root, xe->xmotion.root);
562 setuv (subwindow, xe->xmotion.subwindow);
563 setuv (time, xe->xmotion.time);
564 setiv (x, xe->xmotion.x);
565 setiv (y, xe->xmotion.y);
566 setiv (row, xe->xmotion.y / term->fheight);
567 setiv (col, xe->xmotion.x / term->fwidth);
568 setiv (x_root, xe->xmotion.x_root);
569 setiv (y_root, xe->xmotion.y_root);
570 setuv (state, xe->xmotion.state);
571
572 switch (xe->type)
573 {
574 case KeyPress:
575 case KeyRelease:
576 setuv (keycode, xe->xkey.keycode);
577 break;
578
579 case ButtonPress:
580 case ButtonRelease:
581 setuv (button, xe->xbutton.button);
582 break;
583
584 case MotionNotify:
585 setiv (is_hint, xe->xmotion.is_hint);
586 break;
587 }
588
589 break;
590
591 case MapNotify:
592 case UnmapNotify:
593 case ConfigureNotify:
594 setuv (event, xe->xconfigure.event);
595 setuv (window, xe->xconfigure.window);
596
597 switch (xe->type)
598 {
599 case ConfigureNotify:
600 setiv (x, xe->xconfigure.x);
601 setiv (y, xe->xconfigure.y);
602 setiv (width, xe->xconfigure.width);
603 setiv (height, xe->xconfigure.height);
604 setuv (above, xe->xconfigure.above);
605 break;
606 }
607
608 break;
609 }
610
611 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
612 }
613 break;
614
615 case DT_END:
616 goto call;
617
618 default:
619 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
620 }
621 }
622
623 call:
624 va_end (ap);
625
626 PUTBACK;
627 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
628 SPAGAIN;
629
630 if (count)
631 {
632 SV *status = POPs;
633 count = SvTRUE (status);
634 }
635
636 PUTBACK;
637 FREETMPS;
638 LEAVE;
639
640 if (SvTRUE (ERRSV))
641 {
642 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
643 ungrab (term); // better lose the grab than the session
644 }
645
646 event_consumed = !!count;
647 }
648 catch (...)
649 {
650 swap (perl_environ, environ);
651 throw;
652 }
653 else
654 event_consumed = false;
655
656 // post-handling of some events
657 if (htype == HOOK_REFRESH_BEGIN)
658 {
659 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
660
661 for (int i = AvFILL (av); i >= 0; i--)
662 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
663 }
461 else if (htype == HOOK_DESTROY) 664 else if (htype == HOOK_DESTROY)
462 { 665 {
463 // handled later 666 clearSVptr ((SV *)term->perl.self);
667 SvREFCNT_dec ((SV *)term->perl.self);
464 } 668 }
465 else
466 {
467 if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
468 {
469 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
470 669
471 if (HvKEYS (hv)) 670 swap (perl_environ, environ);
472 {
473 hv_iterinit (hv);
474 671
475 while (HE *he = hv_iternext (hv)) 672 return event_consumed;
476 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
477 }
478
479 }
480
481 if (!should_invoke [htype])
482 return false;
483 }
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 {
503 case DT_INT:
504 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
505 break;
506
507 case DT_LONG:
508 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
509 break;
510
511 case DT_STR:
512 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
513 break;
514
515 case DT_STR_LEN:
516 {
517 char *str = va_arg (ap, char *);
518 int len = va_arg (ap, int);
519
520 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
521 }
522 break;
523
524 case DT_WCS_LEN:
525 {
526 wchar_t *wstr = va_arg (ap, wchar_t *);
527 int wlen = va_arg (ap, int);
528
529 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
530 }
531 break;
532
533 case DT_XEVENT:
534 {
535 XEvent *xe = va_arg (ap, XEvent *);
536 HV *hv = newHV ();
537
538# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
539# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
540# undef set
541
542 setiv (type, xe->type);
543 setiv (send_event, xe->xany.send_event);
544 setiv (serial, xe->xany.serial);
545
546 switch (xe->type)
547 {
548 case KeyPress:
549 case KeyRelease:
550 case ButtonPress:
551 case ButtonRelease:
552 case MotionNotify:
553 setiv (time, xe->xmotion.time);
554 setiv (x, xe->xmotion.x);
555 setiv (y, xe->xmotion.y);
556 setiv (row, xe->xmotion.y / term->fheight);
557 setiv (col, xe->xmotion.x / term->fwidth);
558 setiv (x_root, xe->xmotion.x_root);
559 setiv (y_root, xe->xmotion.y_root);
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 }
583 break;
584
585 case DT_END:
586 {
587 va_end (ap);
588
589 PUTBACK;
590 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
591 SPAGAIN;
592
593 if (count)
594 {
595 SV *status = POPs;
596 count = SvTRUE (status);
597 }
598
599 PUTBACK;
600 FREETMPS;
601 LEAVE;
602
603 if (SvTRUE (ERRSV))
604 {
605 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
606 ungrab (term); // better lose the grab than the session
607 }
608
609 if (htype == HOOK_DESTROY)
610 {
611 clearSVptr ((SV *)term->perl.self);
612 SvREFCNT_dec ((SV *)term->perl.self);
613 }
614
615 return count;
616 }
617
618 default:
619 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
620 }
621 }
622} 673}
623 674
624///////////////////////////////////////////////////////////////////////////// 675/////////////////////////////////////////////////////////////////////////////
625 676
626MODULE = urxvt PACKAGE = urxvt 677MODULE = urxvt PACKAGE = urxvt
645# include "optinc.h" 696# include "optinc.h"
646# undef nodef 697# undef nodef
647# undef def 698# undef def
648 699
649 HV *stash = gv_stashpv ("urxvt", 1); 700 HV *stash = gv_stashpv ("urxvt", 1);
650# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); 701 struct {
702 const char *name;
703 IV iv;
704 } *civ, const_iv[] = {
705# define const_iv(name) { # name, (IV)name }
651 export_const_iv (DEFAULT_RSTYLE); 706 const_iv (DEFAULT_RSTYLE),
652 export_const_iv (OVERLAY_RSTYLE); 707 const_iv (OVERLAY_RSTYLE),
653 export_const_iv (RS_Bold); 708 const_iv (RS_Bold),
654 export_const_iv (RS_Italic); 709 const_iv (RS_Italic),
655 export_const_iv (RS_Blink); 710 const_iv (RS_Blink),
656 export_const_iv (RS_RVid); 711 const_iv (RS_RVid),
657 export_const_iv (RS_Uline); 712 const_iv (RS_Uline),
658 713
659 export_const_iv (CurrentTime); 714 const_iv (CurrentTime),
660 export_const_iv (ShiftMask); 715 const_iv (ShiftMask),
661 export_const_iv (LockMask); 716 const_iv (LockMask),
662 export_const_iv (ControlMask); 717 const_iv (ControlMask),
663 export_const_iv (Mod1Mask); 718 const_iv (Mod1Mask),
664 export_const_iv (Mod2Mask); 719 const_iv (Mod2Mask),
665 export_const_iv (Mod3Mask); 720 const_iv (Mod3Mask),
666 export_const_iv (Mod4Mask); 721 const_iv (Mod4Mask),
667 export_const_iv (Mod5Mask); 722 const_iv (Mod5Mask),
668 export_const_iv (Button1Mask); 723 const_iv (Button1Mask),
669 export_const_iv (Button2Mask); 724 const_iv (Button2Mask),
670 export_const_iv (Button3Mask); 725 const_iv (Button3Mask),
671 export_const_iv (Button4Mask); 726 const_iv (Button4Mask),
672 export_const_iv (Button5Mask); 727 const_iv (Button5Mask),
673 export_const_iv (AnyModifier); 728 const_iv (AnyModifier),
674 729
675 export_const_iv (EVENT_NONE); 730 const_iv (EVENT_NONE),
676 export_const_iv (EVENT_READ); 731 const_iv (EVENT_READ),
677 export_const_iv (EVENT_WRITE); 732 const_iv (EVENT_WRITE),
678}
679 733
680void 734 const_iv (NoEventMask),
681set_should_invoke (int htype, int value) 735 const_iv (KeyPressMask),
682 CODE: 736 const_iv (KeyReleaseMask),
683 rxvt_perl.should_invoke [htype] = value; 737 const_iv (ButtonPressMask),
738 const_iv (ButtonReleaseMask),
739 const_iv (EnterWindowMask),
740 const_iv (LeaveWindowMask),
741 const_iv (PointerMotionMask),
742 const_iv (PointerMotionHintMask),
743 const_iv (Button1MotionMask),
744 const_iv (Button2MotionMask),
745 const_iv (Button3MotionMask),
746 const_iv (Button4MotionMask),
747 const_iv (Button5MotionMask),
748 const_iv (ButtonMotionMask),
749 const_iv (KeymapStateMask),
750 const_iv (ExposureMask),
751 const_iv (VisibilityChangeMask),
752 const_iv (StructureNotifyMask),
753 const_iv (ResizeRedirectMask),
754 const_iv (SubstructureNotifyMask),
755 const_iv (SubstructureRedirectMask),
756 const_iv (FocusChangeMask),
757 const_iv (PropertyChangeMask),
758 const_iv (ColormapChangeMask),
759 const_iv (OwnerGrabButtonMask),
760
761 const_iv (KeyPress),
762 const_iv (KeyRelease),
763 const_iv (ButtonPress),
764 const_iv (ButtonRelease),
765 const_iv (MotionNotify),
766 const_iv (EnterNotify),
767 const_iv (LeaveNotify),
768 const_iv (FocusIn),
769 const_iv (FocusOut),
770 const_iv (KeymapNotify),
771 const_iv (Expose),
772 const_iv (GraphicsExpose),
773 const_iv (NoExpose),
774 const_iv (VisibilityNotify),
775 const_iv (CreateNotify),
776 const_iv (DestroyNotify),
777 const_iv (UnmapNotify),
778 const_iv (MapNotify),
779 const_iv (MapRequest),
780 const_iv (ReparentNotify),
781 const_iv (ConfigureNotify),
782 const_iv (ConfigureRequest),
783 const_iv (GravityNotify),
784 const_iv (ResizeRequest),
785 const_iv (CirculateNotify),
786 const_iv (CirculateRequest),
787 const_iv (PropertyNotify),
788 const_iv (SelectionClear),
789 const_iv (SelectionRequest),
790 const_iv (SelectionNotify),
791 const_iv (ColormapNotify),
792 const_iv (ClientMessage),
793 const_iv (MappingNotify),
794 };
795
796 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]);
797 civ-- > const_iv; )
798 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
799}
684 800
685void 801void
686warn (const char *msg) 802warn (const char *msg)
687 CODE: 803 CODE:
688 rxvt_warn ("%s", msg); 804 rxvt_warn ("%s", msg);
690void 806void
691fatal (const char *msg) 807fatal (const char *msg)
692 CODE: 808 CODE:
693 rxvt_fatal ("%s", msg); 809 rxvt_fatal ("%s", msg);
694 810
695SV * 811void
696untaint (SV *sv) 812_exit (int status)
697 CODE:
698 RETVAL = newSVsv (sv);
699 SvTAINTED_off (RETVAL);
700 OUTPUT:
701 RETVAL
702
703bool
704safe ()
705 CODE:
706 RETVAL = !rxvt_tainted ();
707 OUTPUT:
708 RETVAL
709 813
710NV 814NV
711NOW () 815NOW ()
712 CODE: 816 CODE:
713 RETVAL = NOW; 817 RETVAL = NOW;
778 882
779 for (int i = 1; i < items; i++) 883 for (int i = 1; i < items; i++)
780 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 884 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
781 885
782 AV *envv = (AV *)SvRV (ST (0)); 886 AV *envv = (AV *)SvRV (ST (0));
783 for (int i = av_len (envv) + 1; i--; ) 887 for (int i = AvFILL (envv) + 1; i--; )
784 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 888 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
785 889
786 term->envv->push_back (0); 890 term->envv->push_back (0);
787 891
788 bool success; 892 bool success;
809 RETVAL 913 RETVAL
810 914
811void 915void
812rxvt_term::destroy () 916rxvt_term::destroy ()
813 917
918#if ENABLE_PERL_FRILLS
919
920void
921rxvt_term::XListProperties (U32 window)
922 PPCODE:
923{
924 int count;
925 Atom *props = XListProperties (THIS->display->display, (Window)window, &count);
926
927 EXTEND (SP, count);
928 while (count--)
929 PUSHs (newSVuv ((U32)props [count]));
930
931 XFree (props);
932}
933
934void
935rxvt_term::XGetWindowProperty (U32 window, U32 property)
936 PPCODE:
937{
938 Atom type;
939 int format;
940 unsigned long nitems;
941 unsigned long bytes_after;
942 unsigned char *prop;
943 XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property,
944 0, 1<<30, 0, AnyPropertyType,
945 &type, &format, &nitems, &bytes_after, &prop);
946 if (type != None)
947 {
948 EXTEND (SP, 3);
949 PUSHs (newSVuv ((U32)type));
950 PUSHs (newSViv (format));
951 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
952 XFree (prop);
953 }
954}
955
956void
957rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data)
958 CODE:
959{
960 STRLEN len;
961 char *data_ = SvPVbyte (data, len);
962
963 XChangeProperty (THIS->display->display, (Window)window, (Atom)property,
964 type, format, PropModeReplace,
965 (unsigned char *)data, len * 8 / format);
966}
967
968void
969rxvt_term::XDeleteProperty (U32 window, U32 property)
970 CODE:
971 XDeleteProperty (THIS->display->display, (Window)window, (Atom)property);
972
973U32
974rxvt_term::DefaultRootWindow ()
975 CODE:
976 RETVAL = (U32)THIS->display->root;
977 OUTPUT:
978 RETVAL
979
980U32
981rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height)
982 CODE:
983 RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent,
984 x, y, width, height, 0,
985 THIS->pix_colors_focused[Color_border],
986 THIS->pix_colors_focused[Color_border]);
987 OUTPUT:
988 RETVAL
989
990void
991rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0)
992 CODE:
993 XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y);
994
995void
996rxvt_term::XMapWindow (U32 window)
997 CODE:
998 XMapWindow (THIS->display->display, (Window)window);
999
1000void
1001rxvt_term::XUnmapWindow (U32 window)
1002 CODE:
1003 XUnmapWindow (THIS->display->display, (Window)window);
1004
1005#endif
1006
1007void
1008rxvt_term::set_should_invoke (int htype, int inc)
1009 CODE:
1010 THIS->perl.should_invoke [htype] += inc;
1011
814void 1012void
815rxvt_term::grab_button (int button, U32 modifiers) 1013rxvt_term::grab_button (int button, U32 modifiers)
816 CODE: 1014 CODE:
817 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 1015 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
818 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1016 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
885 char *mbstr = rxvt_wcstombs (wstr); 1083 char *mbstr = rxvt_wcstombs (wstr);
886 rxvt_pop_locale (); 1084 rxvt_pop_locale ();
887 1085
888 free (wstr); 1086 free (wstr);
889 1087
890 RETVAL = taint_if (newSVpv (mbstr, 0), str); 1088 RETVAL = newSVpv (mbstr, 0);
891 free (mbstr); 1089 free (mbstr);
892} 1090}
893 OUTPUT: 1091 OUTPUT:
894 RETVAL 1092 RETVAL
895 1093
902 1100
903 rxvt_push_locale (THIS->locale); 1101 rxvt_push_locale (THIS->locale);
904 wchar_t *wstr = rxvt_mbstowcs (data, len); 1102 wchar_t *wstr = rxvt_mbstowcs (data, len);
905 rxvt_pop_locale (); 1103 rxvt_pop_locale ();
906 1104
907 RETVAL = taint_if (wcs2sv (wstr), octets); 1105 RETVAL = wcs2sv (wstr);
908 free (wstr); 1106 free (wstr);
909} 1107}
910 OUTPUT: 1108 OUTPUT:
911 RETVAL 1109 RETVAL
912 1110
921#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1119#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
922#define TERM_OFFSET_focus TERM_OFFSET(focus) 1120#define TERM_OFFSET_focus TERM_OFFSET(focus)
923#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1121#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
924#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1122#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
925#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1123#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
926#define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) 1124#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
927 1125
928int 1126int
929rxvt_term::width () 1127rxvt_term::width ()
930 ALIAS: 1128 ALIAS:
931 width = TERM_OFFSET_width 1129 width = TERM_OFFSET_width
937 ncol = TERM_OFFSET_ncol 1135 ncol = TERM_OFFSET_ncol
938 focus = TERM_OFFSET_focus 1136 focus = TERM_OFFSET_focus
939 mapped = TERM_OFFSET_mapped 1137 mapped = TERM_OFFSET_mapped
940 saveLines = TERM_OFFSET_saveLines 1138 saveLines = TERM_OFFSET_saveLines
941 total_rows = TERM_OFFSET_total_rows 1139 total_rows = TERM_OFFSET_total_rows
942 nsaved = TERM_OFFSET_nsaved 1140 top_row = TERM_OFFSET_top_row
943 CODE: 1141 CODE:
944 RETVAL = *(int *)((char *)THIS + ix); 1142 RETVAL = *(int *)((char *)THIS + ix);
945 OUTPUT: 1143 OUTPUT:
946 RETVAL 1144 RETVAL
947 1145
1016 CODE: 1214 CODE:
1017 RETVAL = (U32)THIS->vt; 1215 RETVAL = (U32)THIS->vt;
1018 OUTPUT: 1216 OUTPUT:
1019 RETVAL 1217 RETVAL
1020 1218
1219void
1220rxvt_term::vt_emask_add (U32 emask)
1221 CODE:
1222 THIS->vt_emask_perl |= emask;
1223 THIS->vt_select_input ();
1224
1021U32 1225U32
1022rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) 1226rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
1023 CODE: 1227 CODE:
1024{
1025 RETVAL = THIS->rstyle; 1228 RETVAL = THIS->rstyle;
1026 THIS->rstyle = new_rstyle; 1229 THIS->rstyle = new_rstyle;
1027}
1028 OUTPUT: 1230 OUTPUT:
1029 RETVAL 1231 RETVAL
1030 1232
1031int 1233int
1032rxvt_term::view_start (int newval = -1) 1234rxvt_term::view_start (int newval = 1)
1235 PROTOTYPE: $;$
1033 CODE: 1236 CODE:
1034{ 1237{
1035 RETVAL = THIS->view_start; 1238 RETVAL = THIS->view_start;
1036 1239
1037 if (newval >= 0) 1240 if (newval <= 0)
1038 { 1241 THIS->scr_changeview (max (newval, THIS->top_row));
1039 THIS->view_start = min (newval, THIS->nsaved);
1040 THIS->scr_changeview (RETVAL);
1041 }
1042} 1242}
1043 OUTPUT: 1243 OUTPUT:
1044 RETVAL 1244 RETVAL
1045 1245
1046void 1246void
1050 1250
1051void 1251void
1052rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1252rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1053 PPCODE: 1253 PPCODE:
1054{ 1254{
1055 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1255 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1056 XSRETURN_EMPTY; 1256 XSRETURN_EMPTY;
1057 1257
1058 line_t &l = ROW(row_number); 1258 line_t &l = ROW(row_number);
1059 1259
1060 if (GIMME_V != G_VOID) 1260 if (GIMME_V != G_VOID)
1062 wchar_t *wstr = new wchar_t [THIS->ncol]; 1262 wchar_t *wstr = new wchar_t [THIS->ncol];
1063 1263
1064 for (int col = 0; col < THIS->ncol; col++) 1264 for (int col = 0; col < THIS->ncol; col++)
1065 wstr [col] = l.t [col]; 1265 wstr [col] = l.t [col];
1066 1266
1067 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); 1267 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1068 1268
1069 delete [] wstr; 1269 delete [] wstr;
1070 } 1270 }
1071 1271
1072 if (new_text) 1272 if (new_text)
1093 1293
1094void 1294void
1095rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1295rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1096 PPCODE: 1296 PPCODE:
1097{ 1297{
1098 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1298 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1099 XSRETURN_EMPTY; 1299 XSRETURN_EMPTY;
1100 1300
1101 line_t &l = ROW(row_number); 1301 line_t &l = ROW(row_number);
1102 1302
1103 if (GIMME_V != G_VOID) 1303 if (GIMME_V != G_VOID)
1115 { 1315 {
1116 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1316 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1117 croak ("new_rend must be arrayref"); 1317 croak ("new_rend must be arrayref");
1118 1318
1119 AV *av = (AV *)SvRV (new_rend); 1319 AV *av = (AV *)SvRV (new_rend);
1120 int len = min (av_len (av) + 1 - start_ofs, max_len); 1320 int len = min (AvFILL (av) + 1 - start_ofs, max_len);
1121 1321
1122 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1322 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
1123 croak ("new_rend array extends beyond horizontal margins"); 1323 croak ("new_rend array extends beyond horizontal margins");
1124 1324
1125 for (int col = start_col; col < start_col + len; col++) 1325 for (int col = start_col; col < start_col + len; col++)
1133 1333
1134int 1334int
1135rxvt_term::ROW_l (int row_number, int new_length = -1) 1335rxvt_term::ROW_l (int row_number, int new_length = -1)
1136 CODE: 1336 CODE:
1137{ 1337{
1138 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1338 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1139 XSRETURN_EMPTY; 1339 XSRETURN_EMPTY;
1140 1340
1141 line_t &l = ROW(row_number); 1341 line_t &l = ROW(row_number);
1142 RETVAL = l.l; 1342 RETVAL = l.l;
1143 1343
1149 1349
1150bool 1350bool
1151rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) 1351rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
1152 CODE: 1352 CODE:
1153{ 1353{
1154 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1354 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1155 XSRETURN_EMPTY; 1355 XSRETURN_EMPTY;
1156 1356
1157 line_t &l = ROW(row_number); 1357 line_t &l = ROW(row_number);
1158 RETVAL = l.is_longer (); 1358 RETVAL = l.is_longer ();
1159 1359
1193 else 1393 else
1194 *r++ = *s; 1394 *r++ = *s;
1195 1395
1196 rxvt_pop_locale (); 1396 rxvt_pop_locale ();
1197 1397
1198 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); 1398 RETVAL = wcs2sv (rstr, r - rstr);
1199 1399
1200 delete [] rstr; 1400 delete [] rstr;
1201} 1401}
1202 OUTPUT: 1402 OUTPUT:
1203 RETVAL 1403 RETVAL
1229 else if (IS_COMPOSE (*s)) 1429 else if (IS_COMPOSE (*s))
1230 r += rxvt_composite.expand (*s, r); 1430 r += rxvt_composite.expand (*s, r);
1231 else 1431 else
1232 *r++ = *s; 1432 *r++ = *s;
1233 1433
1234 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); 1434 RETVAL = wcs2sv (rstr, r - rstr);
1235 1435
1236 delete [] rstr; 1436 delete [] rstr;
1237} 1437}
1238 OUTPUT: 1438 OUTPUT:
1239 RETVAL 1439 RETVAL
1261 1461
1262 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1462 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1263 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1463 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1264 1464
1265 if (GIMME_V != G_VOID) 1465 if (GIMME_V != G_VOID)
1266 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); 1466 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef);
1267 1467
1268 if (newval) 1468 if (newval)
1269 { 1469 {
1270 if (SvOK (newval)) 1470 if (SvOK (newval))
1271 { 1471 {
1276 else 1476 else
1277 THIS->rs [index] = 0; 1477 THIS->rs [index] = 0;
1278 } 1478 }
1279} 1479}
1280 1480
1481const char *
1482rxvt_term::x_resource (const char *name)
1483
1281bool 1484bool
1282rxvt_term::option (U32 optval, int set = -1) 1485rxvt_term::option (U32 optval, int set = -1)
1283 CODE: 1486 CODE:
1284{ 1487{
1285 RETVAL = THIS->options & optval; 1488 RETVAL = THIS->options & optval;
1344 PUSHs (sv_2mortal (newSViv (rc.col))); 1547 PUSHs (sv_2mortal (newSViv (rc.col)));
1345 } 1548 }
1346 1549
1347 if (items == 3) 1550 if (items == 3)
1348 { 1551 {
1349 rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); 1552 rc.row = SvIV (ST (1));
1350 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); 1553 rc.col = SvIV (ST (2));
1554
1555 if (ix == 2 && rc.col == 0)
1556 {
1557 rc.row--;
1558 rc.col = THIS->ncol;
1559 }
1560
1561 clamp_it (rc.col, 0, THIS->ncol);
1562 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1351 1563
1352 if (ix) 1564 if (ix)
1353 THIS->want_refresh = 1; 1565 THIS->want_refresh = 1;
1354 } 1566 }
1355} 1567}
1359 CODE: 1571 CODE:
1360 RETVAL = THIS->charsets [THIS->screen.charset]; 1572 RETVAL = THIS->charsets [THIS->screen.charset];
1361 OUTPUT: 1573 OUTPUT:
1362 RETVAL 1574 RETVAL
1363 1575
1576#void
1577#rxvt_term::selection_clear ()
1578
1579void
1580rxvt_term::selection_make (U32 eventtime, bool rect = false)
1581 CODE:
1582 THIS->selection.op = SELECTION_CONT;
1583 THIS->selection.rect = rect;
1584 THIS->selection_make (eventtime);
1585
1364int 1586int
1365rxvt_term::selection_grab (U32 eventtime) 1587rxvt_term::selection_grab (U32 eventtime)
1366 1588
1367void 1589void
1368rxvt_term::selection (SV *newtext = 0) 1590rxvt_term::selection (SV *newtext = 0)
1369 PPCODE: 1591 PPCODE:
1370{ 1592{
1371 if (GIMME_V != G_VOID) 1593 if (GIMME_V != G_VOID)
1372 XPUSHs (THIS->selection.text 1594 XPUSHs (THIS->selection.text
1373 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) 1595 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))
1374 : &PL_sv_undef); 1596 : &PL_sv_undef);
1375 1597
1376 if (newtext) 1598 if (newtext)
1377 { 1599 {
1378 free (THIS->selection.text); 1600 free (THIS->selection.text);
1504 RETVAL = THIS; 1726 RETVAL = THIS;
1505 OUTPUT: 1727 OUTPUT:
1506 RETVAL 1728 RETVAL
1507 1729
1508timer * 1730timer *
1731timer::after (NV delay)
1732 CODE:
1733 THIS->start (NOW + delay);
1734 RETVAL = THIS;
1735 OUTPUT:
1736 RETVAL
1737
1738timer *
1509timer::stop () 1739timer::stop ()
1510 CODE: 1740 CODE:
1511 THIS->stop (); 1741 THIS->stop ();
1512 RETVAL = THIS; 1742 RETVAL = THIS;
1513 OUTPUT: 1743 OUTPUT:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines