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.127 by root, Sat May 30 08:51:23 2009 UTC vs.
Revision 1.154 by sf-exg, Wed Apr 11 11:32:21 2012 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvtperl.xs 2 * File: rxvtperl.xs
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2008,2011 Marc Lehmann <schmorp@schmorp.de>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
23#define line_t perl_line_t 23#define line_t perl_line_t
24#include <EXTERN.h> 24#include <EXTERN.h>
25#include <perl.h> 25#include <perl.h>
26#include <XSUB.h> 26#include <XSUB.h>
27#undef line_t 27#undef line_t
28#undef bool // perl defines it's own bool type, except with g++... what a trap
28 29
29#include "../config.h" 30#include "../config.h"
30 31
31#include <cstddef> 32#include <stddef.h>
32#include <cstdarg> 33#include <stdarg.h>
33 34
34#include "unistd.h" 35#include "unistd.h"
35 36
36#include "ev_cpp.h" 37#include "ev_cpp.h"
37#include "rxvt.h" 38#include "rxvt.h"
302 THIS->refresh_check (); 303 THIS->refresh_check ();
303} 304}
304 305
305///////////////////////////////////////////////////////////////////////////// 306/////////////////////////////////////////////////////////////////////////////
306 307
307#define IOM_CLASS "urxvt"
308#define IOM_WARN rxvt_warn
309#include "iom_perl.h" 308#include "iom_perl.h"
310 309
311///////////////////////////////////////////////////////////////////////////// 310/////////////////////////////////////////////////////////////////////////////
312 311
313struct rxvt_perl_interp rxvt_perl; 312struct rxvt_perl_interp rxvt_perl;
329{ 328{
330 if (!perl) 329 if (!perl)
331 { 330 {
332 rxvt_push_locale (""); // perl init destroys current locale 331 rxvt_push_locale (""); // perl init destroys current locale
333 332
333 {
334 perl_environ = rxvt_environ; 334 perl_environ = rxvt_environ;
335 swap (perl_environ, environ); 335 localise_env set_environ (perl_environ);
336 336
337 char *args[] = { 337 char *args[] = {
338 "", 338 "",
339 "-e" 339 "-e"
340 "BEGIN {" 340 "BEGIN {"
341 " urxvt->bootstrap;" 341 " urxvt->bootstrap;"
342 " unshift @INC, '" LIBDIR "';" 342 " unshift @INC, '" LIBDIR "';"
343 "}" 343 "}"
344 "" 344 ""
345 "use urxvt;" 345 "use urxvt;"
346 }; 346 };
347 int argc = sizeof (args) / sizeof (args[0]); 347 int argc = ecb_array_length (args);
348 char **argv = args; 348 char **argv = args;
349 349
350 PERL_SYS_INIT3 (&argc, &argv, &environ); 350 PERL_SYS_INIT3 (&argc, &argv, &environ);
351 perl = perl_alloc (); 351 perl = perl_alloc ();
352 perl_construct (perl); 352 perl_construct (perl);
353 353
354 if (perl_parse (perl, xs_init, argc, argv, (char **)NULL) 354 if (perl_parse (perl, xs_init, argc, argv, (char **)NULL)
355 || perl_run (perl)) 355 || perl_run (perl))
356 { 356 {
357 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 357 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
358 358
359 perl_destruct (perl); 359 perl_destruct (perl);
360 perl_free (perl); 360 perl_free (perl);
361 perl = 0; 361 perl = 0;
362 } 362 }
363 363 }
364 swap (perl_environ, environ);
365 364
366 rxvt_pop_locale (); 365 rxvt_pop_locale ();
367 } 366 }
368 367
369 if (perl) 368 if (perl)
370 { 369 {
371 // runs outside of perls ENV 370 // runs outside of perls ENV
372 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 371 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
373 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0); 372 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0);
373 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, newRV_noinc ((SV *)newAV ()), 0);
374 } 374 }
375} 375}
376 376
377static void 377static void
378ungrab (rxvt_term *THIS) 378ungrab (rxvt_term *THIS)
389rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 389rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
390{ 390{
391 if (!perl || !term->perl.self) 391 if (!perl || !term->perl.self)
392 return false; 392 return false;
393 393
394 localise_env set_environ (perl_environ);
395
394 // pre-handling of some events 396 // pre-handling of some events
395 if (htype == HOOK_REFRESH_END) 397 if (htype == HOOK_REFRESH_END)
396 { 398 {
397 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 399 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
398 400
399 for (int i = 0; i <= AvFILL (av); i++) 401 for (int i = 0; i <= AvFILL (av); i++)
400 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 402 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
401 } 403 }
404 else if (htype == HOOK_DESTROY)
405 {
406 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
402 407
403 swap (perl_environ, environ); 408 for (int i = AvFILL (av); i >= 0; i--)
409 {
410 rxvt_selection *req = (rxvt_selection *)SvIV (*av_fetch (av, i, 0));
411 delete req;
412 }
413 }
404 414
405 bool event_consumed; 415 bool event_consumed;
406 416
407 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always 417 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
408 || term->perl.should_invoke [htype]) 418 || term->perl.should_invoke [htype])
409 try
410 { 419 {
411 dSP; 420 dSP;
412 va_list ap; 421 va_list ap;
413 422
414 va_start (ap, htype); 423 va_start (ap, htype);
415 424
416 ENTER; 425 ENTER;
417 SAVETMPS; 426 SAVETMPS;
418 427
419 PUSHMARK (SP); 428 PUSHMARK (SP);
420 429
430 EXTEND (SP, 2);
421 XPUSHs (sv_2mortal (newSVterm (term))); 431 PUSHs (sv_2mortal (newSVterm (term)));
422 XPUSHs (sv_2mortal (newSViv (htype))); 432 PUSHs (sv_2mortal (newSViv (htype)));
423 433
424 for (;;) { 434 for (;;) {
425 data_type dt = (data_type)va_arg (ap, int); 435 data_type dt = (data_type)va_arg (ap, int);
426 436
427 switch (dt) 437 switch (dt)
428 { 438 {
429 case DT_INT: 439 case DT_INT:
430 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); 440 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
431 break; 441 break;
432 442
433 case DT_LONG: 443 case DT_LONG:
434 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 444 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
435 break; 445 break;
436 446
437 case DT_STR: 447 case DT_STR:
438 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 448 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
439 break; 449 break;
440 450
441 case DT_STR_LEN: 451 case DT_STR_LEN:
442 { 452 {
443 char *str = va_arg (ap, char *); 453 char *str = va_arg (ap, char *);
444 int len = va_arg (ap, int); 454 int len = va_arg (ap, int);
445 455
446 XPUSHs (sv_2mortal (newSVpvn (str, len))); 456 XPUSHs (sv_2mortal (newSVpvn (str, len)));
447 } 457 }
448 break; 458 break;
449 459
450 case DT_WCS_LEN: 460 case DT_WCS_LEN:
451 { 461 {
452 wchar_t *wstr = va_arg (ap, wchar_t *); 462 wchar_t *wstr = va_arg (ap, wchar_t *);
453 int wlen = va_arg (ap, int); 463 int wlen = va_arg (ap, int);
454 464
455 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 465 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
456 } 466 }
457 break; 467 break;
458 468
459 case DT_LCS_LEN: 469 case DT_LCS_LEN:
460 { 470 {
461 long *lstr = va_arg (ap, long *); 471 long *lstr = va_arg (ap, long *);
462 int llen = va_arg (ap, int); 472 int llen = va_arg (ap, int);
463 473
464 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long)))); 474 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long))));
465 } 475 }
466 break; 476 break;
467 477
468 case DT_XEVENT: 478 case DT_XEVENT:
469 { 479 {
470 XEvent *xe = va_arg (ap, XEvent *); 480 XEvent *xe = va_arg (ap, XEvent *);
471 HV *hv = newHV (); 481 HV *hv = newHV ();
472 482
473# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 483# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
474# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) 484# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
475# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) 485# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
476# undef set 486# undef set
477 487
478 setiv (type, xe->type); 488 setiv (type, xe->type);
479 setiv (send_event, xe->xany.send_event); 489 setiv (send_event, xe->xany.send_event);
480 setiv (serial, xe->xany.serial); 490 setiv (serial, xe->xany.serial);
481 491
482 switch (xe->type) 492 switch (xe->type)
483 { 493 {
484 case KeyPress: 494 case KeyPress:
485 case KeyRelease: 495 case KeyRelease:
486 case ButtonPress: 496 case ButtonPress:
487 case ButtonRelease: 497 case ButtonRelease:
488 case MotionNotify: 498 case MotionNotify:
489 setuv (window, xe->xmotion.window); 499 setuv (window, xe->xmotion.window);
490 setuv (root, xe->xmotion.root); 500 setuv (root, xe->xmotion.root);
491 setuv (subwindow, xe->xmotion.subwindow); 501 setuv (subwindow, xe->xmotion.subwindow);
492 setuv (time, xe->xmotion.time); 502 setuv (time, xe->xmotion.time);
493 setiv (x, xe->xmotion.x); 503 setiv (x, xe->xmotion.x);
494 setiv (y, xe->xmotion.y); 504 setiv (y, xe->xmotion.y);
495 setiv (row, xe->xmotion.y / term->fheight + term->view_start); 505 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
496 setiv (col, xe->xmotion.x / term->fwidth); 506 setiv (col, xe->xmotion.x / term->fwidth);
497 setiv (x_root, xe->xmotion.x_root); 507 setiv (x_root, xe->xmotion.x_root);
498 setiv (y_root, xe->xmotion.y_root); 508 setiv (y_root, xe->xmotion.y_root);
499 setuv (state, xe->xmotion.state); 509 setuv (state, xe->xmotion.state);
500 510
501 switch (xe->type) 511 switch (xe->type)
502 { 512 {
503 case KeyPress: 513 case KeyPress:
504 case KeyRelease: 514 case KeyRelease:
505 setuv (keycode, xe->xkey.keycode); 515 setuv (keycode, xe->xkey.keycode);
506 break; 516 break;
507 517
508 case ButtonPress: 518 case ButtonPress:
509 case ButtonRelease: 519 case ButtonRelease:
510 setuv (button, xe->xbutton.button); 520 setuv (button, xe->xbutton.button);
511 break; 521 break;
512 522
513 case MotionNotify: 523 case MotionNotify:
514 setiv (is_hint, xe->xmotion.is_hint); 524 setiv (is_hint, xe->xmotion.is_hint);
515 break; 525 break;
516 } 526 }
517 527
518 break; 528 break;
519 529
520 case MapNotify: 530 case MapNotify:
521 case UnmapNotify: 531 case UnmapNotify:
522 case ConfigureNotify: 532 case ConfigureNotify:
523 setuv (event, xe->xconfigure.event); 533 setuv (event, xe->xconfigure.event);
524 setuv (window, xe->xconfigure.window); 534 setuv (window, xe->xconfigure.window);
525 535
526 switch (xe->type) 536 switch (xe->type)
527 { 537 {
528 case ConfigureNotify: 538 case ConfigureNotify:
529 setiv (x, xe->xconfigure.x); 539 setiv (x, xe->xconfigure.x);
530 setiv (y, xe->xconfigure.y); 540 setiv (y, xe->xconfigure.y);
531 setiv (width, xe->xconfigure.width); 541 setiv (width, xe->xconfigure.width);
532 setiv (height, xe->xconfigure.height); 542 setiv (height, xe->xconfigure.height);
533 setuv (above, xe->xconfigure.above); 543 setuv (above, xe->xconfigure.above);
534 break; 544 break;
535 } 545 }
536 546
537 break; 547 break;
538 548
539 case PropertyNotify: 549 case PropertyNotify:
540 setuv (window, xe->xproperty.window); 550 setuv (window, xe->xproperty.window);
541 setuv (atom, xe->xproperty.atom); 551 setuv (atom, xe->xproperty.atom);
542 setuv (time, xe->xproperty.time); 552 setuv (time, xe->xproperty.time);
543 setiv (state, xe->xproperty.state); 553 setiv (state, xe->xproperty.state);
544 break; 554 break;
545 555
546 case ClientMessage: 556 case ClientMessage:
547 setuv (window, xe->xclient.window); 557 setuv (window, xe->xclient.window);
548 setuv (message_type, xe->xclient.message_type); 558 setuv (message_type, xe->xclient.message_type);
549 setuv (format, xe->xclient.format); 559 setuv (format, xe->xclient.format);
550 setuv (l0, xe->xclient.data.l[0]); 560 setuv (l0, xe->xclient.data.l[0]);
551 setuv (l1, xe->xclient.data.l[1]); 561 setuv (l1, xe->xclient.data.l[1]);
552 setuv (l2, xe->xclient.data.l[2]); 562 setuv (l2, xe->xclient.data.l[2]);
553 setuv (l3, xe->xclient.data.l[3]); 563 setuv (l3, xe->xclient.data.l[3]);
554 setuv (l4, xe->xclient.data.l[4]); 564 setuv (l4, xe->xclient.data.l[4]);
555 break; 565 break;
556 } 566 }
557 567
558 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 568 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
559 } 569 }
560 break; 570 break;
561 571
562 case DT_END: 572 case DT_END:
563 goto call; 573 goto call;
564 574
565 default: 575 default:
566 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); 576 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
567 } 577 }
578 }
579
580 call:
581 va_end (ap);
582
583 PUTBACK;
584 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
585 SPAGAIN;
586
587 if (count)
588 {
589 SV *status = POPs;
590 count = SvTRUE (status);
568 } 591 }
569 592
570 call:
571 va_end (ap);
572
573 PUTBACK; 593 PUTBACK;
574 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
575 SPAGAIN;
576
577 if (count)
578 {
579 SV *status = POPs;
580 count = SvTRUE (status);
581 }
582
583 PUTBACK;
584 FREETMPS; 594 FREETMPS;
585 LEAVE; 595 LEAVE;
586 596
587 if (SvTRUE (ERRSV)) 597 if (SvTRUE (ERRSV))
588 { 598 {
589 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 599 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPVbyte_nolen (ERRSV));
590 ungrab (term); // better lose the grab than the session 600 ungrab (term); // better lose the grab than the session
591 } 601 }
592 602
593 event_consumed = !!count; 603 event_consumed = !!count;
594 } 604 }
595 catch (...)
596 {
597 swap (perl_environ, environ);
598 throw;
599 }
600 else 605 else
601 event_consumed = false; 606 event_consumed = false;
602 607
603 // post-handling of some events 608 // post-handling of some events
604 if (htype == HOOK_REFRESH_BEGIN) 609 if (htype == HOOK_REFRESH_BEGIN)
615 620
616 // don't allow further calls 621 // don't allow further calls
617 term->perl.self = 0; 622 term->perl.self = 0;
618 } 623 }
619 624
620 swap (perl_environ, environ);
621
622 return event_consumed; 625 return event_consumed;
626}
627
628void
629rxvt_perl_interp::selection_finish (rxvt_selection *sel, char *data, unsigned int len)
630{
631 localise_env set_environ (perl_environ);
632
633 ENTER;
634 SAVETMPS;
635
636 dSP;
637 XPUSHs (sv_2mortal (newSVpvn (data, len)));
638 call_sv ((SV *)sel->cb_sv, G_VOID | G_DISCARD | G_EVAL);
639
640 if (SvTRUE (ERRSV))
641 rxvt_warn ("perl selection callback evaluation error: %s", SvPVbyte_nolen (ERRSV));
642
643 FREETMPS;
644 LEAVE;
623} 645}
624 646
625///////////////////////////////////////////////////////////////////////////// 647/////////////////////////////////////////////////////////////////////////////
626 648
627MODULE = urxvt PACKAGE = urxvt 649MODULE = urxvt PACKAGE = urxvt
639# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 661# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
640# include "hookinc.h" 662# include "hookinc.h"
641# undef def 663# undef def
642 664
643 HV *option = get_hv ("urxvt::OPTION", 1); 665 HV *option = get_hv ("urxvt::OPTION", 1);
644# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); 666# define def(name) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
645# define nodef(name) 667# define nodef(name)
646# include "optinc.h" 668# include "optinc.h"
647# undef nodef 669# undef nodef
648# undef def 670# undef def
649 671
654 } *civ, const_iv[] = { 676 } *civ, const_iv[] = {
655# define const_iv(name) { # name, (IV)name } 677# define const_iv(name) { # name, (IV)name }
656 const_iv (NUM_RESOURCES), 678 const_iv (NUM_RESOURCES),
657 const_iv (DEFAULT_RSTYLE), 679 const_iv (DEFAULT_RSTYLE),
658 const_iv (OVERLAY_RSTYLE), 680 const_iv (OVERLAY_RSTYLE),
681 const_iv (Color_Bits),
682 const_iv (RS_bgShift), const_iv (RS_bgMask),
683 const_iv (RS_fgShift), const_iv (RS_fgMask),
684 const_iv (RS_Careful),
685 const_iv (RS_fontCount),
686 const_iv (RS_fontShift),
687 const_iv (RS_fontMask),
688 const_iv (RS_baseattrMask),
689 const_iv (RS_attrMask),
690 const_iv (RS_redraw),
691 const_iv (RS_Sel),
659 const_iv (RS_Bold), 692 const_iv (RS_Bold),
660 const_iv (RS_Italic), 693 const_iv (RS_Italic),
661 const_iv (RS_Blink), 694 const_iv (RS_Blink),
662 const_iv (RS_RVid), 695 const_iv (RS_RVid),
663 const_iv (RS_Uline), 696 const_iv (RS_Uline),
767 const_iv (XIMDontChange), 800 const_iv (XIMDontChange),
768# endif 801# endif
769# endif 802# endif
770 }; 803 };
771 804
772 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 805 for (civ = const_iv + ecb_array_length (const_iv); civ > const_iv; civ--)
773 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 806 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
774} 807}
775 808
776void 809void
777warn (const char *msg) 810warn (const char *msg)
778 CODE: 811 CODE:
850 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) 883 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
851 if ((*t)->perl.self) 884 if ((*t)->perl.self)
852 PUSHs (sv_2mortal (newSVterm (*t))); 885 PUSHs (sv_2mortal (newSVterm (*t)));
853} 886}
854 887
888IV
889_new_selection_request (rxvt_term *term, int selnum, Time tm, Window win, Atom prop, SV *cb)
890 CODE:
891 rxvt_selection *req = new rxvt_selection (term->display, selnum, tm, win, prop, term);
892 req->cb_sv = newSVsv (cb);
893 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
894 av_push (av, newSViv ((IV)req));
895 RETVAL = (IV)req;
896 OUTPUT:
897 RETVAL
898
899void
900_delete_selection_request (IV req_)
901 CODE:
902 rxvt_selection *req = (rxvt_selection *)req_;
903 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)req->term->perl.self), "_selection", 10, 0));
904 int i;
905
906 for (i = AvFILL (av); i >= 0; i--)
907 if (SvIV (*av_fetch (av, i, 1)) == req_)
908 break;
909
910 for (; i < AvFILL (av); i++)
911 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0)));
912
913 av_pop (av);
914
915 delete req;
916
855MODULE = urxvt PACKAGE = urxvt::term 917MODULE = urxvt PACKAGE = urxvt::term
856 918
857SV * 919SV *
858_new (AV *env, AV *arg) 920_new (AV *env, AV *arg)
859 CODE: 921 CODE:
860{ 922{
861 rxvt_term *term = new rxvt_term; 923 rxvt_term *term = new rxvt_term;
862 924
863 stringvec *argv = new stringvec; 925 stringvec *argv = new stringvec;
864 stringvec *envv = new stringvec;
865
866 for (int i = 0; i <= AvFILL (arg); i++) 926 for (int i = 0; i <= AvFILL (arg); i++)
867 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1)))); 927 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
868 928
929 stringvec *envv = new stringvec;
869 for (int i = AvFILL (env) + 1; i--; ) 930 for (int i = AvFILL (env) + 1; i--; )
870 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 931 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
871
872 envv->push_back (0);
873 932
874 try 933 try
875 { 934 {
876 term->init (argv, envv); 935 term->init (argv, envv);
877 } 936 }
917 976
918void 977void
919rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt) 978rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt)
920 CODE: 979 CODE:
921 XUngrabKey (THIS->dpy, keycode, modifiers, window); 980 XUngrabKey (THIS->dpy, keycode, modifiers, window);
922
923void
924rxvt_term::XUngrabKeyboard (Time eventtime)
925 CODE:
926 XUngrabKeyboard (THIS->dpy, eventtime);
927 981
928bool 982bool
929rxvt_term::grab (Time eventtime, int sync = 0) 983rxvt_term::grab (Time eventtime, int sync = 0)
930 CODE: 984 CODE:
931{ 985{
1043 rxvt_pop_locale (); 1097 rxvt_pop_locale ();
1044 1098
1045 RETVAL = wcs2sv (wstr); 1099 RETVAL = wcs2sv (wstr);
1046 free (wstr); 1100 free (wstr);
1047} 1101}
1048 OUTPUT:
1049 RETVAL
1050
1051char *
1052rxvt_term::locale ()
1053 CODE:
1054 RETVAL = THIS->locale;
1055 OUTPUT: 1102 OUTPUT:
1056 RETVAL 1103 RETVAL
1057 1104
1058#define TERM_OFFSET(sym) offsetof (TermWin_t, sym) 1105#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
1059 1106
1166 RETVAL 1213 RETVAL
1167 1214
1168Window 1215Window
1169rxvt_term::parent () 1216rxvt_term::parent ()
1170 CODE: 1217 CODE:
1171 RETVAL = THIS->parent [0]; 1218 RETVAL = THIS->parent;
1172 OUTPUT: 1219 OUTPUT:
1173 RETVAL 1220 RETVAL
1174 1221
1175Window 1222Window
1176rxvt_term::vt () 1223rxvt_term::vt ()
1203 if (newval <= 0) 1250 if (newval <= 0)
1204 THIS->scr_changeview (max (newval, THIS->top_row)); 1251 THIS->scr_changeview (max (newval, THIS->top_row));
1205} 1252}
1206 OUTPUT: 1253 OUTPUT:
1207 RETVAL 1254 RETVAL
1255
1256void
1257rxvt_term::set_urgency (bool enable)
1208 1258
1209void 1259void
1210rxvt_term::focus_in () 1260rxvt_term::focus_in ()
1211 1261
1212void 1262void
1445# include "rsinc.h" 1495# include "rsinc.h"
1446# undef def 1496# undef def
1447# undef reserve 1497# undef reserve
1448 }; 1498 };
1449 1499
1450 rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1500 rs = rslist + ecb_array_length (rslist);
1451 1501
1452 if (*name) 1502 if (*name)
1453 { 1503 {
1454 do { 1504 do {
1455 if (rs-- == rslist) 1505 if (rs-- == rslist)
1494 1544
1495 if (set >= 0) 1545 if (set >= 0)
1496 { 1546 {
1497 THIS->set_option (optval, set); 1547 THIS->set_option (optval, set);
1498 1548
1499 if (THIS->env_colorfgbg [0]) // avoid doing this before START 1549 if (THIS->init_done) // avoid doing this before START
1500 switch (optval) 1550 switch (optval)
1501 { 1551 {
1502 case Opt_skipBuiltinGlyphs: 1552 case Opt_skipBuiltinGlyphs:
1503 THIS->set_fonts (); 1553 THIS->set_fonts ();
1504 THIS->scr_remap_chars (); 1554 THIS->scr_remap_chars ();
1505 THIS->scr_touch (true); 1555 THIS->scr_touch (true);
1506 THIS->want_refresh = 1; 1556 THIS->want_refresh = 1;
1507 THIS->refresh_check (); 1557 THIS->refresh_check ();
1508 break; 1558 break;
1559#ifdef CURSOR_BLINK
1560 case Opt_cursorBlink:
1561 THIS->cursor_blink_reset ();
1562 break;
1563#endif
1509 1564
1510 case Opt_cursorUnderline: 1565 case Opt_cursorUnderline:
1511 THIS->want_refresh = 1; 1566 THIS->want_refresh = 1;
1512 THIS->refresh_check (); 1567 THIS->refresh_check ();
1513 break; 1568 break;
1527 CODE: 1582 CODE:
1528 RETVAL = 0 < THIS->parse_keysym (keysym, str); 1583 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1529 THIS->keyboard->register_done (); 1584 THIS->keyboard->register_done ();
1530 OUTPUT: 1585 OUTPUT:
1531 RETVAL 1586 RETVAL
1587
1588void
1589rxvt_term::register_command (int keysym, unsigned int state, SV *str)
1590 CODE:
1591 wchar_t *wstr = sv2wcs (str);
1592 THIS->keyboard->register_user_translation (keysym, state, wstr);
1593 free (wstr);
1532 1594
1533void 1595void
1534rxvt_term::screen_cur (...) 1596rxvt_term::screen_cur (...)
1535 PROTOTYPE: $;$$ 1597 PROTOTYPE: $;$$
1536 ALIAS: 1598 ALIAS:
1550 EXTEND (SP, 2); 1612 EXTEND (SP, 2);
1551 PUSHs (sv_2mortal (newSViv (rc.row))); 1613 PUSHs (sv_2mortal (newSViv (rc.row)));
1552 PUSHs (sv_2mortal (newSViv (rc.col))); 1614 PUSHs (sv_2mortal (newSViv (rc.col)));
1553 } 1615 }
1554 1616
1555 if (items == 3) 1617 if (items >= 3)
1556 { 1618 {
1557 rc.row = SvIV (ST (1)); 1619 rc.row = SvIV (ST (1));
1558 rc.col = SvIV (ST (2)); 1620 rc.col = SvIV (ST (2));
1559 1621
1560 if (ix == 2) 1622 if (ix == 2)
1576 clamp_it (rc.col, 0, THIS->ncol); 1638 clamp_it (rc.col, 0, THIS->ncol);
1577 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1639 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1578 1640
1579 if (ix) 1641 if (ix)
1580 { 1642 {
1643 THIS->selection.screen = THIS->current_screen;
1644
1581 THIS->want_refresh = 1; 1645 THIS->want_refresh = 1;
1582 THIS->refresh_check (); 1646 THIS->refresh_check ();
1583 } 1647 }
1584 } 1648 }
1585} 1649}
1586 1650
1587char 1651int
1588rxvt_term::cur_charset () 1652rxvt_term::selection_screen (int screen = -1)
1589 CODE: 1653 CODE:
1590 RETVAL = THIS->charsets [THIS->screen.charset]; 1654 RETVAL = THIS->selection.screen;
1591 OUTPUT: 1655 if (screen >= 0)
1656 THIS->selection.screen = screen;
1657 OUTPUT:
1592 RETVAL 1658 RETVAL
1593 1659
1594void 1660void
1595rxvt_term::selection_clear () 1661rxvt_term::selection_clear (bool clipboard = false)
1596 1662
1597void 1663void
1598rxvt_term::selection_make (Time eventtime, bool rect = false) 1664rxvt_term::selection_make (Time eventtime, bool rect = false)
1599 CODE: 1665 CODE:
1600 THIS->selection.op = SELECTION_CONT; 1666 THIS->selection.op = SELECTION_CONT;
1601 THIS->selection.rect = rect; 1667 THIS->selection.rect = rect;
1602 THIS->selection_make (eventtime); 1668 THIS->selection_make (eventtime);
1603 1669
1604int 1670int
1605rxvt_term::selection_grab (Time eventtime) 1671rxvt_term::selection_grab (Time eventtime, bool clipboard = false)
1606 1672
1607void 1673void
1608rxvt_term::selection (SV *newtext = 0) 1674rxvt_term::selection (SV *newtext = 0, bool clipboard = false)
1609 PPCODE: 1675 PPCODE:
1610{ 1676{
1677 wchar_t * &text = clipboard ? THIS->selection.clip_text : THIS->selection.text;
1678 unsigned int &len = clipboard ? THIS->selection.clip_len : THIS->selection.len;
1679
1611 if (GIMME_V != G_VOID) 1680 if (GIMME_V != G_VOID)
1612 XPUSHs (THIS->selection.text 1681 XPUSHs (text
1613 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) 1682 ? sv_2mortal (wcs2sv (text, len))
1614 : &PL_sv_undef); 1683 : &PL_sv_undef);
1615 1684
1616 if (newtext) 1685 if (newtext)
1617 { 1686 {
1618 free (THIS->selection.text); 1687 free (text);
1619 1688
1620 THIS->selection.text = sv2wcs (newtext); 1689 text = sv2wcs (newtext);
1621 THIS->selection.len = wcslen (THIS->selection.text); 1690 len = wcslen (text);
1622 } 1691 }
1623} 1692}
1693
1694char
1695rxvt_term::cur_charset ()
1696 CODE:
1697 RETVAL = THIS->charsets [THIS->screen.charset];
1698 OUTPUT:
1699 RETVAL
1624 1700
1625void 1701void
1626rxvt_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) 1702rxvt_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)
1627 1703
1628void 1704void
1650 char *str = SvPVbyte (octets, len); 1726 char *str = SvPVbyte (octets, len);
1651 C_ARGS: 1727 C_ARGS:
1652 str, len 1728 str, len
1653 1729
1654void 1730void
1731rxvt_term::tt_paste (SV *octets)
1732 INIT:
1733 STRLEN len;
1734 char *str = SvPVbyte (octets, len);
1735 C_ARGS:
1736 str, len
1737
1738void
1655rxvt_term::cmd_parse (SV *octets) 1739rxvt_term::cmd_parse (SV *octets)
1656 CODE: 1740 CODE:
1657{ 1741{
1658 STRLEN len; 1742 STRLEN len;
1659 char *str = SvPVbyte (octets, len); 1743 char *str = SvPVbyte (octets, len);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines