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.126 by root, Wed Nov 5 14:43:54 2008 UTC vs.
Revision 1.151 by root, Thu Jan 19 13:04:12 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 <cstddef>
32#include <cstdarg> 33#include <cstdarg>
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{
1046 free (wstr); 1100 free (wstr);
1047} 1101}
1048 OUTPUT: 1102 OUTPUT:
1049 RETVAL 1103 RETVAL
1050 1104
1051char *
1052rxvt_term::locale ()
1053 CODE:
1054 RETVAL = THIS->locale;
1055 OUTPUT:
1056 RETVAL
1057
1058#define TERM_OFFSET(sym) offsetof (TermWin_t, sym) 1105#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
1059 1106
1060#define TERM_OFFSET_width TERM_OFFSET(width) 1107#define TERM_OFFSET_width TERM_OFFSET(width)
1061#define TERM_OFFSET_height TERM_OFFSET(height) 1108#define TERM_OFFSET_height TERM_OFFSET(height)
1062#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 1109#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
1063#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 1110#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
1064#define TERM_OFFSET_fbase TERM_OFFSET(fbase) 1111#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1065#define TERM_OFFSET_nrow TERM_OFFSET(nrow) 1112#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1066#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1113#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1067#define TERM_OFFSET_focus TERM_OFFSET(focus) 1114#define TERM_OFFSET_focus TERM_OFFSET(focus)
1068#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1115#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
1069#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth) 1116#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth)
1070#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth) 1117#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth)
1071#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace) 1118#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace)
1119#define TERM_OFFSET_letterSpace TERM_OFFSET(letterSpace)
1072#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1120#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1073#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1121#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1074#define TERM_OFFSET_top_row TERM_OFFSET(top_row) 1122#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1075 1123
1076int 1124int
1077rxvt_term::width () 1125rxvt_term::width ()
1078 ALIAS: 1126 ALIAS:
1079 width = TERM_OFFSET_width 1127 width = TERM_OFFSET_width
1080 height = TERM_OFFSET_height 1128 height = TERM_OFFSET_height
1081 fwidth = TERM_OFFSET_fwidth 1129 fwidth = TERM_OFFSET_fwidth
1082 fheight = TERM_OFFSET_fheight 1130 fheight = TERM_OFFSET_fheight
1083 fbase = TERM_OFFSET_fbase 1131 fbase = TERM_OFFSET_fbase
1084 nrow = TERM_OFFSET_nrow 1132 nrow = TERM_OFFSET_nrow
1085 ncol = TERM_OFFSET_ncol 1133 ncol = TERM_OFFSET_ncol
1086 focus = TERM_OFFSET_focus 1134 focus = TERM_OFFSET_focus
1087 mapped = TERM_OFFSET_mapped 1135 mapped = TERM_OFFSET_mapped
1088 int_bwidth = TERM_OFFSET_int_bwidth 1136 int_bwidth = TERM_OFFSET_int_bwidth
1089 ext_bwidth = TERM_OFFSET_ext_bwidth 1137 ext_bwidth = TERM_OFFSET_ext_bwidth
1090 lineSpace = TERM_OFFSET_lineSpace 1138 lineSpace = TERM_OFFSET_lineSpace
1139 letterSpace = TERM_OFFSET_letterSpace
1091 saveLines = TERM_OFFSET_saveLines 1140 saveLines = TERM_OFFSET_saveLines
1092 total_rows = TERM_OFFSET_total_rows 1141 total_rows = TERM_OFFSET_total_rows
1093 top_row = TERM_OFFSET_top_row 1142 top_row = TERM_OFFSET_top_row
1094 CODE: 1143 CODE:
1095 RETVAL = *(int *)((char *)THIS + ix); 1144 RETVAL = *(int *)((char *)THIS + ix);
1096 OUTPUT: 1145 OUTPUT:
1097 RETVAL 1146 RETVAL
1098 1147
1164 RETVAL 1213 RETVAL
1165 1214
1166Window 1215Window
1167rxvt_term::parent () 1216rxvt_term::parent ()
1168 CODE: 1217 CODE:
1169 RETVAL = THIS->parent [0]; 1218 RETVAL = THIS->parent;
1170 OUTPUT: 1219 OUTPUT:
1171 RETVAL 1220 RETVAL
1172 1221
1173Window 1222Window
1174rxvt_term::vt () 1223rxvt_term::vt ()
1201 if (newval <= 0) 1250 if (newval <= 0)
1202 THIS->scr_changeview (max (newval, THIS->top_row)); 1251 THIS->scr_changeview (max (newval, THIS->top_row));
1203} 1252}
1204 OUTPUT: 1253 OUTPUT:
1205 RETVAL 1254 RETVAL
1255
1256void
1257rxvt_term::set_urgency (bool enable)
1206 1258
1207void 1259void
1208rxvt_term::focus_in () 1260rxvt_term::focus_in ()
1209 1261
1210void 1262void
1443# include "rsinc.h" 1495# include "rsinc.h"
1444# undef def 1496# undef def
1445# undef reserve 1497# undef reserve
1446 }; 1498 };
1447 1499
1448 rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1500 rs = rslist + ecb_array_length (rslist);
1449 1501
1450 if (*name) 1502 if (*name)
1451 { 1503 {
1452 do { 1504 do {
1453 if (rs-- == rslist) 1505 if (rs-- == rslist)
1492 1544
1493 if (set >= 0) 1545 if (set >= 0)
1494 { 1546 {
1495 THIS->set_option (optval, set); 1547 THIS->set_option (optval, set);
1496 1548
1497 if (THIS->env_colorfgbg [0]) // avoid doing this before START 1549 if (THIS->init_done) // avoid doing this before START
1498 switch (optval) 1550 switch (optval)
1499 { 1551 {
1500 case Opt_skipBuiltinGlyphs: 1552 case Opt_skipBuiltinGlyphs:
1501 THIS->set_fonts (); 1553 THIS->set_fonts ();
1502 THIS->scr_remap_chars (); 1554 THIS->scr_remap_chars ();
1527 THIS->keyboard->register_done (); 1579 THIS->keyboard->register_done ();
1528 OUTPUT: 1580 OUTPUT:
1529 RETVAL 1581 RETVAL
1530 1582
1531void 1583void
1584rxvt_term::register_command (int keysym, unsigned int state, SV *str)
1585 CODE:
1586 wchar_t *wstr = sv2wcs (str);
1587 THIS->keyboard->register_user_translation (keysym, state, wstr);
1588 free (wstr);
1589
1590void
1532rxvt_term::screen_cur (...) 1591rxvt_term::screen_cur (...)
1533 PROTOTYPE: $;$$ 1592 PROTOTYPE: $;$$
1534 ALIAS: 1593 ALIAS:
1535 screen_cur = 0 1594 screen_cur = 0
1536 selection_beg = 1 1595 selection_beg = 1
1548 EXTEND (SP, 2); 1607 EXTEND (SP, 2);
1549 PUSHs (sv_2mortal (newSViv (rc.row))); 1608 PUSHs (sv_2mortal (newSViv (rc.row)));
1550 PUSHs (sv_2mortal (newSViv (rc.col))); 1609 PUSHs (sv_2mortal (newSViv (rc.col)));
1551 } 1610 }
1552 1611
1553 if (items == 3) 1612 if (items >= 3)
1554 { 1613 {
1555 rc.row = SvIV (ST (1)); 1614 rc.row = SvIV (ST (1));
1556 rc.col = SvIV (ST (2)); 1615 rc.col = SvIV (ST (2));
1557 1616
1558 if (ix == 2) 1617 if (ix == 2)
1574 clamp_it (rc.col, 0, THIS->ncol); 1633 clamp_it (rc.col, 0, THIS->ncol);
1575 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1634 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1576 1635
1577 if (ix) 1636 if (ix)
1578 { 1637 {
1638 THIS->selection.screen = THIS->current_screen;
1639
1579 THIS->want_refresh = 1; 1640 THIS->want_refresh = 1;
1580 THIS->refresh_check (); 1641 THIS->refresh_check ();
1581 } 1642 }
1582 } 1643 }
1583} 1644}
1584 1645
1585char 1646int
1586rxvt_term::cur_charset () 1647rxvt_term::selection_screen (int screen = -1)
1587 CODE: 1648 CODE:
1588 RETVAL = THIS->charsets [THIS->screen.charset]; 1649 RETVAL = THIS->selection.screen;
1589 OUTPUT: 1650 if (screen >= 0)
1651 THIS->selection.screen = screen;
1652 OUTPUT:
1590 RETVAL 1653 RETVAL
1591 1654
1592void 1655void
1593rxvt_term::selection_clear () 1656rxvt_term::selection_clear (bool clipboard = false)
1594 1657
1595void 1658void
1596rxvt_term::selection_make (Time eventtime, bool rect = false) 1659rxvt_term::selection_make (Time eventtime, bool rect = false)
1597 CODE: 1660 CODE:
1598 THIS->selection.op = SELECTION_CONT; 1661 THIS->selection.op = SELECTION_CONT;
1599 THIS->selection.rect = rect; 1662 THIS->selection.rect = rect;
1600 THIS->selection_make (eventtime); 1663 THIS->selection_make (eventtime);
1601 1664
1602int 1665int
1603rxvt_term::selection_grab (Time eventtime) 1666rxvt_term::selection_grab (Time eventtime, bool clipboard = false)
1604 1667
1605void 1668void
1606rxvt_term::selection (SV *newtext = 0) 1669rxvt_term::selection (SV *newtext = 0, bool clipboard = false)
1607 PPCODE: 1670 PPCODE:
1608{ 1671{
1672 wchar_t * &text = clipboard ? THIS->selection.clip_text : THIS->selection.text;
1673 unsigned int &len = clipboard ? THIS->selection.clip_len : THIS->selection.len;
1674
1609 if (GIMME_V != G_VOID) 1675 if (GIMME_V != G_VOID)
1610 XPUSHs (THIS->selection.text 1676 XPUSHs (text
1611 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) 1677 ? sv_2mortal (wcs2sv (text, len))
1612 : &PL_sv_undef); 1678 : &PL_sv_undef);
1613 1679
1614 if (newtext) 1680 if (newtext)
1615 { 1681 {
1616 free (THIS->selection.text); 1682 free (text);
1617 1683
1618 THIS->selection.text = sv2wcs (newtext); 1684 text = sv2wcs (newtext);
1619 THIS->selection.len = wcslen (THIS->selection.text); 1685 len = wcslen (text);
1620 } 1686 }
1621} 1687}
1688
1689char
1690rxvt_term::cur_charset ()
1691 CODE:
1692 RETVAL = THIS->charsets [THIS->screen.charset];
1693 OUTPUT:
1694 RETVAL
1622 1695
1623void 1696void
1624rxvt_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) 1697rxvt_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)
1625 1698
1626void 1699void
1648 char *str = SvPVbyte (octets, len); 1721 char *str = SvPVbyte (octets, len);
1649 C_ARGS: 1722 C_ARGS:
1650 str, len 1723 str, len
1651 1724
1652void 1725void
1726rxvt_term::tt_paste (SV *octets)
1727 INIT:
1728 STRLEN len;
1729 char *str = SvPVbyte (octets, len);
1730 C_ARGS:
1731 str, len
1732
1733void
1653rxvt_term::cmd_parse (SV *octets) 1734rxvt_term::cmd_parse (SV *octets)
1654 CODE: 1735 CODE:
1655{ 1736{
1656 STRLEN len; 1737 STRLEN len;
1657 char *str = SvPVbyte (octets, len); 1738 char *str = SvPVbyte (octets, len);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines