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-2005 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
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. |
… | |
… | |
26 | #include <XSUB.h> |
26 | #include <XSUB.h> |
27 | #undef line_t |
27 | #undef line_t |
28 | |
28 | |
29 | #include "../config.h" |
29 | #include "../config.h" |
30 | |
30 | |
|
|
31 | #include <cstddef> |
31 | #include <cstdarg> |
32 | #include <cstdarg> |
32 | |
33 | |
|
|
34 | #include "iom.h" |
33 | #include "rxvt.h" |
35 | #include "rxvt.h" |
34 | #include "iom.h" |
36 | #include "keyboard.h" |
35 | #include "rxvtutil.h" |
37 | #include "rxvtutil.h" |
36 | #include "rxvtperl.h" |
38 | #include "rxvtperl.h" |
37 | |
39 | |
38 | #include "perlxsi.c" |
40 | #include "perlxsi.c" |
|
|
41 | |
|
|
42 | #if defined(HAVE_SCROLLBARS) || defined(MENUBAR) |
|
|
43 | # define GRAB_CURSOR THIS->leftptr_cursor |
|
|
44 | #else |
|
|
45 | # define GRAB_CURSOR None |
|
|
46 | #endif |
39 | |
47 | |
40 | #undef LINENO |
48 | #undef LINENO |
41 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
49 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
42 | #undef ROW |
50 | #undef ROW |
43 | #define ROW(n) THIS->row_buf [LINENO (n)] |
51 | #define ROW(n) THIS->row_buf [LINENO (n)] |
44 | |
52 | |
45 | ///////////////////////////////////////////////////////////////////////////// |
53 | ///////////////////////////////////////////////////////////////////////////// |
46 | |
54 | |
|
|
55 | static SV * |
|
|
56 | taint (SV *sv) |
|
|
57 | { |
|
|
58 | SvTAINT (sv); |
|
|
59 | return sv; |
|
|
60 | } |
|
|
61 | |
|
|
62 | static SV * |
|
|
63 | taint_if (SV *sv, SV *src) |
|
|
64 | { |
|
|
65 | if (SvTAINTED (src)) |
|
|
66 | SvTAINT (sv); |
|
|
67 | |
|
|
68 | return sv; |
|
|
69 | } |
|
|
70 | |
47 | static wchar_t * |
71 | static wchar_t * |
48 | sv2wcs (SV *sv) |
72 | sv2wcs (SV *sv) |
49 | { |
73 | { |
50 | STRLEN len; |
74 | STRLEN len; |
51 | char *str = SvPVutf8 (sv, len); |
75 | char *str = SvPVutf8 (sv, len); |
… | |
… | |
101 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
125 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
102 | |
126 | |
103 | return (long)mg->mg_ptr; |
127 | return (long)mg->mg_ptr; |
104 | } |
128 | } |
105 | |
129 | |
106 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
130 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
107 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
131 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
108 | |
132 | |
109 | ///////////////////////////////////////////////////////////////////////////// |
133 | ///////////////////////////////////////////////////////////////////////////// |
110 | |
134 | |
111 | struct perl_watcher |
135 | struct perl_watcher |
… | |
… | |
290 | void |
314 | void |
291 | overlay::show () |
315 | overlay::show () |
292 | { |
316 | { |
293 | char key[33]; sprintf (key, "%32lx", (long)this); |
317 | char key[33]; sprintf (key, "%32lx", (long)this); |
294 | |
318 | |
295 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
319 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
296 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
320 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
297 | } |
321 | } |
298 | |
322 | |
299 | void |
323 | void |
300 | overlay::hide () |
324 | overlay::hide () |
301 | { |
325 | { |
302 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); |
326 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
303 | |
327 | |
304 | if (ovs) |
328 | if (ovs) |
305 | { |
329 | { |
306 | char key[33]; sprintf (key, "%32lx", (long)this); |
330 | char key[33]; sprintf (key, "%32lx", (long)this); |
307 | |
331 | |
… | |
… | |
389 | { |
413 | { |
390 | if (!perl) |
414 | if (!perl) |
391 | { |
415 | { |
392 | char *argv[] = { |
416 | char *argv[] = { |
393 | "", |
417 | "", |
|
|
418 | "-T", |
394 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
419 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
395 | }; |
420 | }; |
396 | |
421 | |
397 | perl = perl_alloc (); |
422 | perl = perl_alloc (); |
398 | perl_construct (perl); |
423 | perl_construct (perl); |
399 | |
424 | |
400 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
425 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
401 | || perl_run (perl)) |
426 | || perl_run (perl)) |
402 | { |
427 | { |
403 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
428 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
404 | |
429 | |
405 | perl_destruct (perl); |
430 | perl_destruct (perl); |
… | |
… | |
407 | perl = 0; |
432 | perl = 0; |
408 | } |
433 | } |
409 | } |
434 | } |
410 | } |
435 | } |
411 | |
436 | |
|
|
437 | static void |
|
|
438 | ungrab (rxvt_term *THIS) |
|
|
439 | { |
|
|
440 | if (THIS->perl.grabtime) |
|
|
441 | { |
|
|
442 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
443 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
444 | THIS->perl.grabtime = 0; |
|
|
445 | } |
|
|
446 | } |
|
|
447 | |
412 | bool |
448 | bool |
413 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
449 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
414 | { |
450 | { |
415 | if (!perl) |
451 | if (!perl) |
416 | return false; |
452 | return false; |
417 | |
453 | |
418 | if (htype == HOOK_INIT) // first hook ever called |
454 | if (htype == HOOK_INIT) // first hook ever called |
419 | { |
455 | { |
420 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
456 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
421 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
457 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
422 | } |
458 | } |
423 | else if (!term->self) |
459 | else if (!term->perl.self) |
424 | return false; // perl not initialized for this instance |
460 | return false; // perl not initialized for this instance |
425 | else if (htype == HOOK_DESTROY) |
461 | else if (htype == HOOK_DESTROY) |
426 | { |
462 | { |
427 | // handled later |
463 | // handled later |
428 | } |
464 | } |
429 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
465 | else |
430 | { |
466 | { |
431 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
467 | if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
432 | |
|
|
433 | if (HvKEYS (hv)) |
|
|
434 | { |
468 | { |
|
|
469 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
470 | |
|
|
471 | if (HvKEYS (hv)) |
|
|
472 | { |
435 | hv_iterinit (hv); |
473 | hv_iterinit (hv); |
436 | |
474 | |
437 | while (HE *he = hv_iternext (hv)) |
475 | while (HE *he = hv_iternext (hv)) |
438 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
476 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
477 | } |
|
|
478 | |
439 | } |
479 | } |
|
|
480 | |
|
|
481 | if (!should_invoke [htype]) |
|
|
482 | return false; |
440 | } |
483 | } |
441 | else if (!should_invoke [htype]) |
|
|
442 | return false; |
|
|
443 | |
484 | |
444 | dSP; |
485 | dSP; |
445 | va_list ap; |
486 | va_list ap; |
446 | |
487 | |
447 | va_start (ap, htype); |
488 | va_start (ap, htype); |
… | |
… | |
465 | |
506 | |
466 | case DT_LONG: |
507 | case DT_LONG: |
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
508 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
468 | break; |
509 | break; |
469 | |
510 | |
470 | case DT_STRING: |
511 | case DT_STR: |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
512 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
472 | break; |
513 | break; |
473 | |
514 | |
474 | case DT_USTRING_LEN: |
515 | case DT_STR_LEN: |
475 | { |
516 | { |
476 | unicode_t *ustr = va_arg (ap, unicode_t *); |
517 | char *str = va_arg (ap, char *); |
477 | int ulen = va_arg (ap, int); |
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 | { |
478 | wchar_t *wstr = new wchar_t [ulen]; |
526 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
527 | int wlen = va_arg (ap, int); |
479 | |
528 | |
480 | for (int i = ulen; i--; ) |
|
|
481 | wstr [i] = ustr [i]; |
|
|
482 | |
|
|
483 | XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); |
529 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
|
|
530 | } |
|
|
531 | break; |
484 | |
532 | |
485 | delete [] wstr; |
533 | case DT_XEVENT: |
486 | } |
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; |
487 | |
584 | |
488 | case DT_END: |
585 | case DT_END: |
489 | { |
586 | { |
490 | va_end (ap); |
587 | va_end (ap); |
491 | |
588 | |
… | |
… | |
502 | PUTBACK; |
599 | PUTBACK; |
503 | FREETMPS; |
600 | FREETMPS; |
504 | LEAVE; |
601 | LEAVE; |
505 | |
602 | |
506 | if (SvTRUE (ERRSV)) |
603 | if (SvTRUE (ERRSV)) |
|
|
604 | { |
507 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
605 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
606 | ungrab (term); // better lose the grab than the session |
|
|
607 | } |
508 | |
608 | |
509 | if (htype == HOOK_DESTROY) |
609 | if (htype == HOOK_DESTROY) |
510 | { |
610 | { |
511 | clearSVptr ((SV *)term->self); |
611 | clearSVptr ((SV *)term->perl.self); |
512 | SvREFCNT_dec ((SV *)term->self); |
612 | SvREFCNT_dec ((SV *)term->perl.self); |
513 | } |
613 | } |
514 | |
614 | |
515 | return count; |
615 | return count; |
516 | } |
616 | } |
517 | |
617 | |
… | |
… | |
527 | |
627 | |
528 | PROTOTYPES: ENABLE |
628 | PROTOTYPES: ENABLE |
529 | |
629 | |
530 | BOOT: |
630 | BOOT: |
531 | { |
631 | { |
532 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
632 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
|
|
633 | |
533 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
634 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
534 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
635 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
535 | # include "hookinc.h" |
636 | # include "hookinc.h" |
536 | # undef def |
637 | # undef def |
537 | |
638 | |
|
|
639 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
640 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
641 | # define nodef(name) |
|
|
642 | # include "optinc.h" |
|
|
643 | # undef nodef |
|
|
644 | # undef def |
|
|
645 | |
|
|
646 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
647 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
538 | export_const (DEFAULT_RSTYLE); |
648 | export_const_iv (DEFAULT_RSTYLE); |
539 | export_const (OVERLAY_RSTYLE); |
649 | export_const_iv (OVERLAY_RSTYLE); |
540 | export_const (RS_Bold); |
650 | export_const_iv (RS_Bold); |
541 | export_const (RS_Italic); |
651 | export_const_iv (RS_Italic); |
542 | export_const (RS_Blink); |
652 | export_const_iv (RS_Blink); |
543 | export_const (RS_RVid); |
653 | export_const_iv (RS_RVid); |
544 | export_const (RS_Uline); |
654 | export_const_iv (RS_Uline); |
545 | |
655 | |
546 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
656 | export_const_iv (CurrentTime); |
|
|
657 | export_const_iv (ShiftMask); |
|
|
658 | export_const_iv (LockMask); |
|
|
659 | export_const_iv (ControlMask); |
|
|
660 | export_const_iv (Mod1Mask); |
|
|
661 | export_const_iv (Mod2Mask); |
|
|
662 | export_const_iv (Mod3Mask); |
|
|
663 | export_const_iv (Mod4Mask); |
|
|
664 | export_const_iv (Mod5Mask); |
|
|
665 | export_const_iv (Button1Mask); |
|
|
666 | export_const_iv (Button2Mask); |
|
|
667 | export_const_iv (Button3Mask); |
|
|
668 | export_const_iv (Button4Mask); |
|
|
669 | export_const_iv (Button5Mask); |
|
|
670 | export_const_iv (AnyModifier); |
|
|
671 | |
|
|
672 | export_const_iv (EVENT_NONE); |
|
|
673 | export_const_iv (EVENT_READ); |
|
|
674 | export_const_iv (EVENT_WRITE); |
547 | } |
675 | } |
548 | |
676 | |
549 | SV * |
677 | SV * |
550 | new (...) |
678 | new (...) |
551 | CODE: |
679 | CODE: |
… | |
… | |
569 | { |
697 | { |
570 | term->destroy (); |
698 | term->destroy (); |
571 | croak ("exception caught while initializing new terminal instance"); |
699 | croak ("exception caught while initializing new terminal instance"); |
572 | } |
700 | } |
573 | |
701 | |
574 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
702 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
575 | } |
703 | } |
576 | OUTPUT: |
704 | OUTPUT: |
577 | RETVAL |
705 | RETVAL |
578 | |
706 | |
579 | void |
707 | void |
… | |
… | |
588 | |
716 | |
589 | void |
717 | void |
590 | fatal (const char *msg) |
718 | fatal (const char *msg) |
591 | CODE: |
719 | CODE: |
592 | rxvt_fatal ("%s", msg); |
720 | rxvt_fatal ("%s", msg); |
|
|
721 | |
|
|
722 | SV * |
|
|
723 | untaint (SV *sv) |
|
|
724 | CODE: |
|
|
725 | RETVAL = newSVsv (sv); |
|
|
726 | SvTAINTED_off (RETVAL); |
|
|
727 | OUTPUT: |
|
|
728 | RETVAL |
|
|
729 | |
|
|
730 | bool |
|
|
731 | safe () |
|
|
732 | CODE: |
|
|
733 | RETVAL = !rxvt_tainted (); |
|
|
734 | OUTPUT: |
|
|
735 | RETVAL |
593 | |
736 | |
594 | NV |
737 | NV |
595 | NOW () |
738 | NOW () |
596 | CODE: |
739 | CODE: |
597 | RETVAL = NOW; |
740 | RETVAL = NOW; |
… | |
… | |
648 | |
791 | |
649 | MODULE = urxvt PACKAGE = urxvt::term |
792 | MODULE = urxvt PACKAGE = urxvt::term |
650 | |
793 | |
651 | void |
794 | void |
652 | rxvt_term::destroy () |
795 | rxvt_term::destroy () |
|
|
796 | |
|
|
797 | void |
|
|
798 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
799 | CODE: |
|
|
800 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
801 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
802 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
|
|
803 | |
|
|
804 | bool |
|
|
805 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
806 | CODE: |
|
|
807 | { |
|
|
808 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
809 | |
|
|
810 | THIS->perl.grabtime = 0; |
|
|
811 | |
|
|
812 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
813 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
814 | mode, mode, None, GRAB_CURSOR, eventtime)) |
|
|
815 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
816 | THIS->perl.grabtime = eventtime; |
|
|
817 | else |
|
|
818 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
819 | |
|
|
820 | RETVAL = !!THIS->perl.grabtime; |
|
|
821 | } |
|
|
822 | OUTPUT: |
|
|
823 | RETVAL |
|
|
824 | |
|
|
825 | void |
|
|
826 | rxvt_term::allow_events_async () |
|
|
827 | CODE: |
|
|
828 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
|
|
829 | |
|
|
830 | void |
|
|
831 | rxvt_term::allow_events_sync () |
|
|
832 | CODE: |
|
|
833 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
|
|
834 | |
|
|
835 | void |
|
|
836 | rxvt_term::allow_events_replay () |
|
|
837 | CODE: |
|
|
838 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
|
|
839 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
|
|
840 | |
|
|
841 | void |
|
|
842 | rxvt_term::ungrab () |
|
|
843 | CODE: |
|
|
844 | ungrab (THIS); |
653 | |
845 | |
654 | int |
846 | int |
655 | rxvt_term::strwidth (SV *str) |
847 | rxvt_term::strwidth (SV *str) |
656 | CODE: |
848 | CODE: |
657 | { |
849 | { |
… | |
… | |
676 | char *mbstr = rxvt_wcstombs (wstr); |
868 | char *mbstr = rxvt_wcstombs (wstr); |
677 | rxvt_pop_locale (); |
869 | rxvt_pop_locale (); |
678 | |
870 | |
679 | free (wstr); |
871 | free (wstr); |
680 | |
872 | |
681 | RETVAL = newSVpv (mbstr, 0); |
873 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
682 | free (mbstr); |
874 | free (mbstr); |
683 | } |
875 | } |
684 | OUTPUT: |
876 | OUTPUT: |
685 | RETVAL |
877 | RETVAL |
686 | |
878 | |
… | |
… | |
693 | |
885 | |
694 | rxvt_push_locale (THIS->locale); |
886 | rxvt_push_locale (THIS->locale); |
695 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
887 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
696 | rxvt_pop_locale (); |
888 | rxvt_pop_locale (); |
697 | |
889 | |
698 | RETVAL = wcs2sv (wstr); |
890 | RETVAL = taint_if (wcs2sv (wstr), octets); |
699 | free (wstr); |
891 | free (wstr); |
700 | } |
892 | } |
701 | OUTPUT: |
893 | OUTPUT: |
702 | RETVAL |
894 | RETVAL |
703 | |
895 | |
704 | # very portable, especially on objects as opposed to pods |
896 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
705 | #define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
|
|
706 | |
897 | |
707 | #define TERM_OFFSET_width TERM_OFFSET(width) |
898 | #define TERM_OFFSET_width TERM_OFFSET(width) |
708 | #define TERM_OFFSET_height TERM_OFFSET(height) |
899 | #define TERM_OFFSET_height TERM_OFFSET(height) |
709 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
900 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
710 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
901 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
… | |
… | |
735 | CODE: |
926 | CODE: |
736 | RETVAL = *(int *)((char *)THIS + ix); |
927 | RETVAL = *(int *)((char *)THIS + ix); |
737 | OUTPUT: |
928 | OUTPUT: |
738 | RETVAL |
929 | RETVAL |
739 | |
930 | |
|
|
931 | unsigned int |
|
|
932 | rxvt_term::ModLevel3Mask () |
|
|
933 | ALIAS: |
|
|
934 | ModLevel3Mask = 0 |
|
|
935 | ModMetaMask = 1 |
|
|
936 | ModNumLockMask = 2 |
|
|
937 | CODE: |
|
|
938 | switch (ix) |
|
|
939 | { |
|
|
940 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
941 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
942 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
943 | } |
|
|
944 | OUTPUT: |
|
|
945 | RETVAL |
|
|
946 | |
|
|
947 | char * |
|
|
948 | rxvt_term::display_id () |
|
|
949 | ALIAS: |
|
|
950 | display_id = 0 |
|
|
951 | locale = 1 |
|
|
952 | CODE: |
|
|
953 | switch (ix) |
|
|
954 | { |
|
|
955 | case 0: RETVAL = THIS->display->id; break; |
|
|
956 | case 1: RETVAL = THIS->locale; break; |
|
|
957 | } |
|
|
958 | OUTPUT: |
|
|
959 | RETVAL |
|
|
960 | |
|
|
961 | int |
|
|
962 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
|
|
963 | CODE: |
|
|
964 | RETVAL = THIS->pty_ev.events; |
|
|
965 | if (events != EVENT_UNDEF) |
|
|
966 | THIS->pty_ev.set (events); |
|
|
967 | OUTPUT: |
|
|
968 | RETVAL |
|
|
969 | |
|
|
970 | U32 |
|
|
971 | rxvt_term::parent () |
|
|
972 | CODE: |
|
|
973 | RETVAL = (U32)THIS->parent [0]; |
|
|
974 | OUTPUT: |
|
|
975 | RETVAL |
|
|
976 | |
|
|
977 | U32 |
|
|
978 | rxvt_term::vt () |
|
|
979 | CODE: |
|
|
980 | RETVAL = (U32)THIS->vt; |
|
|
981 | OUTPUT: |
|
|
982 | RETVAL |
|
|
983 | |
740 | U32 |
984 | U32 |
741 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
985 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
742 | CODE: |
986 | CODE: |
743 | { |
987 | { |
744 | RETVAL = THIS->rstyle; |
988 | RETVAL = THIS->rstyle; |
… | |
… | |
778 | |
1022 | |
779 | if (GIMME_V != G_VOID) |
1023 | if (GIMME_V != G_VOID) |
780 | { |
1024 | { |
781 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1025 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
782 | |
1026 | |
783 | for (int col = 0; col <THIS->ncol; col++) |
1027 | for (int col = 0; col < THIS->ncol; col++) |
784 | wstr [col] = l.t [col]; |
1028 | wstr [col] = l.t [col]; |
785 | |
1029 | |
786 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
1030 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
787 | |
1031 | |
788 | delete [] wstr; |
1032 | delete [] wstr; |
789 | } |
1033 | } |
790 | |
1034 | |
791 | if (new_text) |
1035 | if (new_text) |
… | |
… | |
881 | } |
1125 | } |
882 | OUTPUT: |
1126 | OUTPUT: |
883 | RETVAL |
1127 | RETVAL |
884 | |
1128 | |
885 | SV * |
1129 | SV * |
886 | rxvt_term::special_encode (SV *str) |
1130 | rxvt_term::special_encode (SV *string) |
887 | CODE: |
1131 | CODE: |
888 | abort ();//TODO |
1132 | { |
|
|
1133 | wchar_t *wstr = sv2wcs (string); |
|
|
1134 | int wlen = wcslen (wstr); |
|
|
1135 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1136 | |
|
|
1137 | rxvt_push_locale (THIS->locale); |
|
|
1138 | |
|
|
1139 | wchar_t *r = rstr; |
|
|
1140 | for (wchar_t *s = wstr; *s; s++) |
|
|
1141 | if (wcwidth (*s) == 0) |
|
|
1142 | { |
|
|
1143 | if (r == rstr) |
|
|
1144 | croak ("leading combining character unencodable"); |
|
|
1145 | |
|
|
1146 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1147 | if (n == NOCHAR) |
|
|
1148 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1149 | |
|
|
1150 | r[-1] = n; |
|
|
1151 | } |
|
|
1152 | #if !UNICODE_3 |
|
|
1153 | else if (*s >= 0x10000) |
|
|
1154 | *r++ = rxvt_composite.compose (*s); |
|
|
1155 | #endif |
|
|
1156 | else |
|
|
1157 | *r++ = *s; |
|
|
1158 | |
|
|
1159 | rxvt_pop_locale (); |
|
|
1160 | |
|
|
1161 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
|
|
1162 | |
|
|
1163 | delete [] rstr; |
|
|
1164 | } |
|
|
1165 | OUTPUT: |
|
|
1166 | RETVAL |
889 | |
1167 | |
890 | SV * |
1168 | SV * |
891 | rxvt_term::special_decode (SV *str) |
1169 | rxvt_term::special_decode (SV *text) |
892 | CODE: |
1170 | CODE: |
893 | abort ();//TODO |
1171 | { |
|
|
1172 | wchar_t *wstr = sv2wcs (text); |
|
|
1173 | int wlen = wcslen (wstr); |
|
|
1174 | int dlen = 0; |
|
|
1175 | |
|
|
1176 | // find length |
|
|
1177 | for (wchar_t *s = wstr; *s; s++) |
|
|
1178 | if (*s == NOCHAR) |
|
|
1179 | ; |
|
|
1180 | else if (IS_COMPOSE (*s)) |
|
|
1181 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1182 | else |
|
|
1183 | dlen++; |
|
|
1184 | |
|
|
1185 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1186 | |
|
|
1187 | // decode |
|
|
1188 | wchar_t *r = rstr; |
|
|
1189 | for (wchar_t *s = wstr; *s; s++) |
|
|
1190 | if (*s == NOCHAR) |
|
|
1191 | ; |
|
|
1192 | else if (IS_COMPOSE (*s)) |
|
|
1193 | r += rxvt_composite.expand (*s, r); |
|
|
1194 | else |
|
|
1195 | *r++ = *s; |
|
|
1196 | |
|
|
1197 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
|
|
1198 | |
|
|
1199 | delete [] rstr; |
|
|
1200 | } |
|
|
1201 | OUTPUT: |
|
|
1202 | RETVAL |
894 | |
1203 | |
895 | void |
1204 | void |
896 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1205 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
897 | PPCODE: |
1206 | PPCODE: |
898 | { |
1207 | { |
… | |
… | |
915 | |
1224 | |
916 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1225 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
917 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1226 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
918 | |
1227 | |
919 | if (GIMME_V != G_VOID) |
1228 | if (GIMME_V != G_VOID) |
920 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1229 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
921 | |
1230 | |
922 | if (newval) |
1231 | if (newval) |
923 | { |
1232 | { |
924 | if (SvOK (newval)) |
1233 | if (SvOK (newval)) |
925 | { |
1234 | { |
… | |
… | |
930 | else |
1239 | else |
931 | THIS->rs [index] = 0; |
1240 | THIS->rs [index] = 0; |
932 | } |
1241 | } |
933 | } |
1242 | } |
934 | |
1243 | |
|
|
1244 | bool |
|
|
1245 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1246 | CODE: |
|
|
1247 | { |
|
|
1248 | RETVAL = THIS->options & optval; |
|
|
1249 | |
|
|
1250 | if (set >= 0) |
|
|
1251 | { |
|
|
1252 | if (set) |
|
|
1253 | THIS->options |= optval; |
|
|
1254 | else |
|
|
1255 | THIS->options &= ~optval; |
|
|
1256 | |
|
|
1257 | switch (optval) |
|
|
1258 | { |
|
|
1259 | case Opt_skipBuiltinGlyphs: |
|
|
1260 | THIS->set_fonts (); |
|
|
1261 | THIS->scr_remap_chars (); |
|
|
1262 | THIS->scr_touch (true); |
|
|
1263 | THIS->want_refresh = 1; |
|
|
1264 | break; |
|
|
1265 | |
|
|
1266 | case Opt_cursorUnderline: |
|
|
1267 | THIS->want_refresh = 1; |
|
|
1268 | break; |
|
|
1269 | |
|
|
1270 | # case Opt_scrollBar_floating: |
|
|
1271 | # case Opt_scrollBar_right: |
|
|
1272 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1273 | # break; |
|
|
1274 | } |
|
|
1275 | } |
|
|
1276 | } |
|
|
1277 | OUTPUT: |
|
|
1278 | RETVAL |
|
|
1279 | |
|
|
1280 | bool |
|
|
1281 | rxvt_term::parse_keysym (char *keysym, char *str) |
|
|
1282 | CODE: |
|
|
1283 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
|
|
1284 | THIS->keyboard->register_done (); |
|
|
1285 | OUTPUT: |
|
|
1286 | RETVAL |
|
|
1287 | |
935 | void |
1288 | void |
936 | rxvt_term::cur (...) |
1289 | rxvt_term::screen_cur (...) |
937 | PROTOTYPE: $;$$ |
1290 | PROTOTYPE: $;$$ |
938 | ALIAS: |
1291 | ALIAS: |
939 | screen_cur = 0 |
1292 | screen_cur = 0 |
940 | selection_beg = 1 |
1293 | selection_beg = 1 |
941 | selection_end = 2 |
1294 | selection_end = 2 |
… | |
… | |
963 | THIS->want_refresh = 1; |
1316 | THIS->want_refresh = 1; |
964 | } |
1317 | } |
965 | } |
1318 | } |
966 | |
1319 | |
967 | int |
1320 | int |
968 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1321 | rxvt_term::selection_grab (U32 eventtime) |
969 | |
1322 | |
970 | void |
1323 | void |
971 | rxvt_term::selection (SV *newtext = 0) |
1324 | rxvt_term::selection (SV *newtext = 0) |
972 | PPCODE: |
1325 | PPCODE: |
973 | { |
1326 | { |
974 | if (GIMME_V != G_VOID) |
1327 | if (GIMME_V != G_VOID) |
|
|
1328 | XPUSHs (THIS->selection.text |
975 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1329 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
|
|
1330 | : &PL_sv_undef); |
976 | |
1331 | |
977 | if (newtext) |
1332 | if (newtext) |
978 | { |
1333 | { |
979 | free (THIS->selection.text); |
1334 | free (THIS->selection.text); |
980 | |
1335 | |
… | |
… | |
982 | THIS->selection.len = wcslen (THIS->selection.text); |
1337 | THIS->selection.len = wcslen (THIS->selection.text); |
983 | } |
1338 | } |
984 | } |
1339 | } |
985 | |
1340 | |
986 | void |
1341 | void |
|
|
1342 | rxvt_term::scr_bell () |
|
|
1343 | |
|
|
1344 | void |
987 | rxvt_term::scr_add_lines (SV *string) |
1345 | rxvt_term::scr_add_lines (SV *string) |
988 | CODE: |
1346 | CODE: |
989 | { |
1347 | { |
990 | wchar_t *wstr = sv2wcs (string); |
1348 | wchar_t *wstr = sv2wcs (string); |
991 | int wlen = wcslen (wstr); |
|
|
992 | unicode_t *ustr = new unicode_t [wlen]; |
|
|
993 | int nlines = 0; |
|
|
994 | |
|
|
995 | for (int i = wlen; i--; ) |
|
|
996 | { |
|
|
997 | ustr [i] = wstr [i]; |
|
|
998 | nlines += ustr [i] == '\012'; |
|
|
999 | } |
|
|
1000 | |
|
|
1001 | THIS->scr_add_lines (ustr, nlines, wlen); |
1349 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
1002 | |
|
|
1003 | free (wstr); |
1350 | free (wstr); |
1004 | delete [] ustr; |
|
|
1005 | } |
1351 | } |
1006 | |
1352 | |
1007 | void |
1353 | void |
1008 | rxvt_term::tt_write (SV *octets) |
1354 | rxvt_term::tt_write (SV *octets) |
1009 | INIT: |
1355 | INIT: |
… | |
… | |
1023 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1369 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1024 | |
1370 | |
1025 | THIS->cmdbuf_ptr = str; |
1371 | THIS->cmdbuf_ptr = str; |
1026 | THIS->cmdbuf_endp = str + len; |
1372 | THIS->cmdbuf_endp = str + len; |
1027 | |
1373 | |
|
|
1374 | rxvt_push_locale (THIS->locale); |
1028 | THIS->cmd_parse (); |
1375 | THIS->cmd_parse (); |
|
|
1376 | rxvt_pop_locale (); |
1029 | |
1377 | |
1030 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1378 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1031 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1379 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1032 | } |
1380 | } |
1033 | |
1381 | |