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 | |
33 | #include "rxvt.h" |
34 | #include "rxvt.h" |
34 | #include "iom.h" |
35 | #include "iom.h" |
35 | #include "rxvtutil.h" |
36 | #include "rxvtutil.h" |
… | |
… | |
101 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
102 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
102 | |
103 | |
103 | return (long)mg->mg_ptr; |
104 | return (long)mg->mg_ptr; |
104 | } |
105 | } |
105 | |
106 | |
106 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
107 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
107 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
108 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
108 | |
109 | |
109 | ///////////////////////////////////////////////////////////////////////////// |
110 | ///////////////////////////////////////////////////////////////////////////// |
110 | |
111 | |
111 | struct perl_watcher |
112 | struct perl_watcher |
… | |
… | |
290 | void |
291 | void |
291 | overlay::show () |
292 | overlay::show () |
292 | { |
293 | { |
293 | char key[33]; sprintf (key, "%32lx", (long)this); |
294 | char key[33]; sprintf (key, "%32lx", (long)this); |
294 | |
295 | |
295 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
296 | 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); |
297 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
297 | } |
298 | } |
298 | |
299 | |
299 | void |
300 | void |
300 | overlay::hide () |
301 | overlay::hide () |
301 | { |
302 | { |
302 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); |
303 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
303 | |
304 | |
304 | if (ovs) |
305 | if (ovs) |
305 | { |
306 | { |
306 | char key[33]; sprintf (key, "%32lx", (long)this); |
307 | char key[33]; sprintf (key, "%32lx", (long)this); |
307 | |
308 | |
… | |
… | |
415 | if (!perl) |
416 | if (!perl) |
416 | return false; |
417 | return false; |
417 | |
418 | |
418 | if (htype == HOOK_INIT) // first hook ever called |
419 | if (htype == HOOK_INIT) // first hook ever called |
419 | { |
420 | { |
420 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
421 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
421 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
422 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
422 | } |
423 | } |
423 | else if (!term->self) |
424 | else if (!term->perl.self) |
424 | return false; // perl not initialized for this instance |
425 | return false; // perl not initialized for this instance |
425 | else if (htype == HOOK_DESTROY) |
426 | else if (htype == HOOK_DESTROY) |
426 | { |
427 | { |
427 | // handled later |
428 | // handled later |
428 | } |
429 | } |
429 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
430 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
430 | { |
431 | { |
431 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
432 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
432 | |
433 | |
433 | if (HvKEYS (hv)) |
434 | if (HvKEYS (hv)) |
434 | { |
435 | { |
435 | hv_iterinit (hv); |
436 | hv_iterinit (hv); |
436 | |
437 | |
… | |
… | |
465 | |
466 | |
466 | case DT_LONG: |
467 | case DT_LONG: |
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
468 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
468 | break; |
469 | break; |
469 | |
470 | |
470 | case DT_STRING: |
471 | case DT_STR: |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
472 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
472 | break; |
473 | break; |
473 | |
474 | |
474 | case DT_USTRING_LEN: |
475 | case DT_STR_LEN: |
475 | { |
476 | { |
476 | unicode_t *ustr = va_arg (ap, unicode_t *); |
477 | char *str = va_arg (ap, char *); |
477 | int ulen = va_arg (ap, int); |
478 | int len = va_arg (ap, int); |
|
|
479 | |
|
|
480 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
|
|
481 | } |
|
|
482 | break; |
|
|
483 | |
|
|
484 | case DT_WCS_LEN: |
|
|
485 | { |
478 | wchar_t *wstr = new wchar_t [ulen]; |
486 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
487 | int wlen = va_arg (ap, int); |
479 | |
488 | |
480 | for (int i = ulen; i--; ) |
|
|
481 | wstr [i] = ustr [i]; |
|
|
482 | |
|
|
483 | XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); |
489 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
|
|
490 | } |
|
|
491 | break; |
484 | |
492 | |
485 | delete [] wstr; |
493 | case DT_XEVENT: |
486 | } |
494 | { |
|
|
495 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
496 | HV *hv = newHV (); |
|
|
497 | |
|
|
498 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
499 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
500 | # undef set |
|
|
501 | |
|
|
502 | setiv (type, xe->type); |
|
|
503 | setiv (send_event, xe->xany.send_event); |
|
|
504 | setiv (serial, xe->xany.serial); |
|
|
505 | |
|
|
506 | switch (xe->type) |
|
|
507 | { |
|
|
508 | case KeyPress: |
|
|
509 | case KeyRelease: |
|
|
510 | case ButtonPress: |
|
|
511 | case ButtonRelease: |
|
|
512 | case MotionNotify: |
|
|
513 | setiv (time, xe->xmotion.time); |
|
|
514 | setiv (x, xe->xmotion.x); |
|
|
515 | setiv (y, xe->xmotion.y); |
|
|
516 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
517 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
518 | setiv (x_root, xe->xmotion.x_root); |
|
|
519 | setiv (y_root, xe->xmotion.y_root); |
|
|
520 | setiv (state, xe->xmotion.state); |
|
|
521 | break; |
|
|
522 | } |
|
|
523 | |
|
|
524 | switch (xe->type) |
|
|
525 | { |
|
|
526 | case KeyPress: |
|
|
527 | case KeyRelease: |
|
|
528 | setiv (keycode, xe->xkey.keycode); |
|
|
529 | break; |
|
|
530 | |
|
|
531 | case ButtonPress: |
|
|
532 | case ButtonRelease: |
|
|
533 | setiv (button, xe->xbutton.button); |
|
|
534 | break; |
|
|
535 | |
|
|
536 | case MotionNotify: |
|
|
537 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
538 | break; |
|
|
539 | } |
|
|
540 | |
|
|
541 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
542 | } |
|
|
543 | break; |
487 | |
544 | |
488 | case DT_END: |
545 | case DT_END: |
489 | { |
546 | { |
490 | va_end (ap); |
547 | va_end (ap); |
491 | |
548 | |
… | |
… | |
506 | if (SvTRUE (ERRSV)) |
563 | if (SvTRUE (ERRSV)) |
507 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
564 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
508 | |
565 | |
509 | if (htype == HOOK_DESTROY) |
566 | if (htype == HOOK_DESTROY) |
510 | { |
567 | { |
511 | clearSVptr ((SV *)term->self); |
568 | clearSVptr ((SV *)term->perl.self); |
512 | SvREFCNT_dec ((SV *)term->self); |
569 | SvREFCNT_dec ((SV *)term->perl.self); |
513 | } |
570 | } |
514 | |
571 | |
515 | return count; |
572 | return count; |
516 | } |
573 | } |
517 | |
574 | |
… | |
… | |
527 | |
584 | |
528 | PROTOTYPES: ENABLE |
585 | PROTOTYPES: ENABLE |
529 | |
586 | |
530 | BOOT: |
587 | BOOT: |
531 | { |
588 | { |
532 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
589 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
|
|
590 | |
533 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
591 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
534 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
592 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
535 | # include "hookinc.h" |
593 | # include "hookinc.h" |
536 | # undef def |
594 | # undef def |
537 | |
595 | |
|
|
596 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
597 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
598 | # define nodef(name) |
|
|
599 | # include "optinc.h" |
|
|
600 | # undef nodef |
|
|
601 | # undef def |
|
|
602 | |
|
|
603 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
604 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
538 | export_const (DEFAULT_RSTYLE); |
605 | export_const_iv (DEFAULT_RSTYLE); |
539 | export_const (OVERLAY_RSTYLE); |
606 | export_const_iv (OVERLAY_RSTYLE); |
540 | export_const (RS_Bold); |
607 | export_const_iv (RS_Bold); |
541 | export_const (RS_Italic); |
608 | export_const_iv (RS_Italic); |
542 | export_const (RS_Blink); |
609 | export_const_iv (RS_Blink); |
543 | export_const (RS_RVid); |
610 | export_const_iv (RS_RVid); |
544 | export_const (RS_Uline); |
611 | export_const_iv (RS_Uline); |
545 | |
612 | |
546 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
613 | export_const_iv (CurrentTime); |
|
|
614 | export_const_iv (ShiftMask); |
|
|
615 | export_const_iv (LockMask); |
|
|
616 | export_const_iv (ControlMask); |
|
|
617 | export_const_iv (Mod1Mask); |
|
|
618 | export_const_iv (Mod2Mask); |
|
|
619 | export_const_iv (Mod3Mask); |
|
|
620 | export_const_iv (Mod4Mask); |
|
|
621 | export_const_iv (Mod5Mask); |
|
|
622 | export_const_iv (Button1Mask); |
|
|
623 | export_const_iv (Button2Mask); |
|
|
624 | export_const_iv (Button3Mask); |
|
|
625 | export_const_iv (Button4Mask); |
|
|
626 | export_const_iv (Button5Mask); |
|
|
627 | export_const_iv (AnyModifier); |
547 | } |
628 | } |
|
|
629 | |
|
|
630 | SV * |
|
|
631 | new (...) |
|
|
632 | CODE: |
|
|
633 | { |
|
|
634 | stringvec *argv = new stringvec; |
|
|
635 | bool success; |
|
|
636 | |
|
|
637 | for (int i = 0; i < items ;i++) |
|
|
638 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
639 | |
|
|
640 | rxvt_term *term = new rxvt_term; |
|
|
641 | |
|
|
642 | term->argv = argv; |
|
|
643 | |
|
|
644 | try |
|
|
645 | { |
|
|
646 | if (!term->init (argv->size (), argv->begin ())) |
|
|
647 | term = 0; |
|
|
648 | } |
|
|
649 | catch (const class rxvt_failure_exception &e) |
|
|
650 | { |
|
|
651 | term->destroy (); |
|
|
652 | croak ("exception caught while initializing new terminal instance"); |
|
|
653 | } |
|
|
654 | |
|
|
655 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
|
|
656 | } |
|
|
657 | OUTPUT: |
|
|
658 | RETVAL |
548 | |
659 | |
549 | void |
660 | void |
550 | set_should_invoke (int htype, int value) |
661 | set_should_invoke (int htype, int value) |
551 | CODE: |
662 | CODE: |
552 | rxvt_perl.should_invoke [htype] = value; |
663 | rxvt_perl.should_invoke [htype] = value; |
… | |
… | |
615 | } |
726 | } |
616 | OUTPUT: |
727 | OUTPUT: |
617 | RETVAL |
728 | RETVAL |
618 | |
729 | |
619 | MODULE = urxvt PACKAGE = urxvt::term |
730 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
731 | |
|
|
732 | void |
|
|
733 | rxvt_term::destroy () |
|
|
734 | |
|
|
735 | void |
|
|
736 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
737 | CODE: |
|
|
738 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
739 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
740 | GrabModeSync, GrabModeSync, None, None); |
|
|
741 | |
|
|
742 | bool |
|
|
743 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
744 | CODE: |
|
|
745 | { |
|
|
746 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
747 | |
|
|
748 | THIS->perl.grabtime = 0; |
|
|
749 | |
|
|
750 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
751 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
752 | mode, mode, None, None, eventtime)) |
|
|
753 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
754 | THIS->perl.grabtime = eventtime; |
|
|
755 | else |
|
|
756 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
757 | |
|
|
758 | RETVAL = !!THIS->perl.grabtime; |
|
|
759 | } |
|
|
760 | OUTPUT: |
|
|
761 | RETVAL |
|
|
762 | |
|
|
763 | void |
|
|
764 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
|
|
765 | CODE: |
|
|
766 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
|
|
767 | |
|
|
768 | void |
|
|
769 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
|
|
770 | CODE: |
|
|
771 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
|
|
772 | |
|
|
773 | void |
|
|
774 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
|
|
775 | CODE: |
|
|
776 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
|
|
777 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
|
|
778 | |
|
|
779 | void |
|
|
780 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
|
|
781 | CODE: |
|
|
782 | THIS->perl.grabtime = 0; |
|
|
783 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
784 | XUngrabPointer (THIS->display->display, eventtime); |
620 | |
785 | |
621 | int |
786 | int |
622 | rxvt_term::strwidth (SV *str) |
787 | rxvt_term::strwidth (SV *str) |
623 | CODE: |
788 | CODE: |
624 | { |
789 | { |
… | |
… | |
666 | free (wstr); |
831 | free (wstr); |
667 | } |
832 | } |
668 | OUTPUT: |
833 | OUTPUT: |
669 | RETVAL |
834 | RETVAL |
670 | |
835 | |
671 | # very portable, especially on objects as opposed to pods |
836 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
672 | #define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
|
|
673 | |
837 | |
674 | #define TERM_OFFSET_width TERM_OFFSET(width) |
838 | #define TERM_OFFSET_width TERM_OFFSET(width) |
675 | #define TERM_OFFSET_height TERM_OFFSET(height) |
839 | #define TERM_OFFSET_height TERM_OFFSET(height) |
676 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
840 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
677 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
841 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
… | |
… | |
702 | CODE: |
866 | CODE: |
703 | RETVAL = *(int *)((char *)THIS + ix); |
867 | RETVAL = *(int *)((char *)THIS + ix); |
704 | OUTPUT: |
868 | OUTPUT: |
705 | RETVAL |
869 | RETVAL |
706 | |
870 | |
|
|
871 | unsigned int |
|
|
872 | rxvt_term::ModLevel3Mask () |
|
|
873 | ALIAS: |
|
|
874 | ModLevel3Mask = 0 |
|
|
875 | ModMetaMask = 1 |
|
|
876 | ModNumLockMask = 2 |
|
|
877 | CODE: |
|
|
878 | switch (ix) |
|
|
879 | { |
|
|
880 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
881 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
882 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
883 | } |
|
|
884 | OUTPUT: |
|
|
885 | RETVAL |
|
|
886 | |
|
|
887 | U32 |
|
|
888 | rxvt_term::parent () |
|
|
889 | CODE: |
|
|
890 | RETVAL = (U32)THIS->parent [0]; |
|
|
891 | OUTPUT: |
|
|
892 | RETVAL |
|
|
893 | |
|
|
894 | U32 |
|
|
895 | rxvt_term::vt () |
|
|
896 | CODE: |
|
|
897 | RETVAL = (U32)THIS->vt; |
|
|
898 | OUTPUT: |
|
|
899 | RETVAL |
|
|
900 | |
707 | U32 |
901 | U32 |
708 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
902 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
709 | CODE: |
903 | CODE: |
710 | { |
904 | { |
711 | RETVAL = THIS->rstyle; |
905 | RETVAL = THIS->rstyle; |
… | |
… | |
733 | rxvt_term::want_refresh () |
927 | rxvt_term::want_refresh () |
734 | CODE: |
928 | CODE: |
735 | THIS->want_refresh = 1; |
929 | THIS->want_refresh = 1; |
736 | |
930 | |
737 | void |
931 | void |
738 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
932 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
739 | PPCODE: |
933 | PPCODE: |
740 | { |
934 | { |
741 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
935 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
742 | XSRETURN_EMPTY; |
936 | XSRETURN_EMPTY; |
743 | |
937 | |
… | |
… | |
745 | |
939 | |
746 | if (GIMME_V != G_VOID) |
940 | if (GIMME_V != G_VOID) |
747 | { |
941 | { |
748 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
942 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
749 | |
943 | |
750 | for (int col = 0; col <THIS->ncol; col++) |
944 | for (int col = 0; col < THIS->ncol; col++) |
751 | wstr [col] = l.t [col]; |
945 | wstr [col] = l.t [col]; |
752 | |
946 | |
753 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
947 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
754 | |
948 | |
755 | delete [] wstr; |
949 | delete [] wstr; |
756 | } |
950 | } |
757 | |
951 | |
758 | if (new_text) |
952 | if (new_text) |
759 | { |
953 | { |
760 | wchar_t *wstr = sv2wcs (new_text); |
954 | wchar_t *wstr = sv2wcs (new_text); |
761 | |
955 | |
762 | int len = wcslen (wstr); |
956 | int len = min (wcslen (wstr) - start_ofs, max_len); |
763 | |
957 | |
764 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
958 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
765 | { |
959 | { |
766 | free (wstr); |
960 | free (wstr); |
767 | croak ("new_text extends beyond horizontal margins"); |
961 | croak ("new_text extends beyond horizontal margins"); |
768 | } |
962 | } |
769 | |
963 | |
770 | for (int col = start_col; col < start_col + len; col++) |
964 | for (int col = start_col; col < start_col + len; col++) |
771 | { |
965 | { |
772 | l.t [col] = wstr [col - start_col]; |
966 | l.t [col] = wstr [start_ofs + col - start_col]; |
773 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
967 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
774 | } |
968 | } |
775 | |
969 | |
776 | free (wstr); |
970 | free (wstr); |
777 | } |
971 | } |
778 | } |
972 | } |
779 | |
973 | |
780 | void |
974 | void |
781 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
975 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
782 | PPCODE: |
976 | PPCODE: |
783 | { |
977 | { |
784 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
978 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
785 | XSRETURN_EMPTY; |
979 | XSRETURN_EMPTY; |
786 | |
980 | |
… | |
… | |
801 | { |
995 | { |
802 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
996 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
803 | croak ("new_rend must be arrayref"); |
997 | croak ("new_rend must be arrayref"); |
804 | |
998 | |
805 | AV *av = (AV *)SvRV (new_rend); |
999 | AV *av = (AV *)SvRV (new_rend); |
806 | int len = av_len (av) + 1; |
1000 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
807 | |
1001 | |
808 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
1002 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
809 | croak ("new_rend array extends beyond horizontal margins"); |
1003 | croak ("new_rend array extends beyond horizontal margins"); |
810 | |
1004 | |
811 | for (int col = start_col; col < start_col + len; col++) |
1005 | for (int col = start_col; col < start_col + len; col++) |
812 | { |
1006 | { |
813 | rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
1007 | rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
814 | |
1008 | |
815 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
1009 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
816 | } |
1010 | } |
817 | } |
1011 | } |
818 | } |
1012 | } |
… | |
… | |
848 | } |
1042 | } |
849 | OUTPUT: |
1043 | OUTPUT: |
850 | RETVAL |
1044 | RETVAL |
851 | |
1045 | |
852 | SV * |
1046 | SV * |
853 | rxvt_term::special_encode (SV *str) |
1047 | rxvt_term::special_encode (SV *string) |
854 | CODE: |
1048 | CODE: |
855 | abort ();//TODO |
1049 | { |
|
|
1050 | wchar_t *wstr = sv2wcs (string); |
|
|
1051 | int wlen = wcslen (wstr); |
|
|
1052 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1053 | |
|
|
1054 | rxvt_push_locale (THIS->locale); |
|
|
1055 | |
|
|
1056 | wchar_t *r = rstr; |
|
|
1057 | for (wchar_t *s = wstr; *s; s++) |
|
|
1058 | if (wcwidth (*s) == 0) |
|
|
1059 | { |
|
|
1060 | if (r == rstr) |
|
|
1061 | croak ("leading combining character unencodable"); |
|
|
1062 | |
|
|
1063 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1064 | if (n == NOCHAR) |
|
|
1065 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1066 | |
|
|
1067 | r[-1] = n; |
|
|
1068 | } |
|
|
1069 | #if !UNICODE_3 |
|
|
1070 | else if (*s >= 0x10000) |
|
|
1071 | *r++ = rxvt_composite.compose (*s); |
|
|
1072 | #endif |
|
|
1073 | else |
|
|
1074 | *r++ = *s; |
|
|
1075 | |
|
|
1076 | rxvt_pop_locale (); |
|
|
1077 | |
|
|
1078 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1079 | |
|
|
1080 | delete [] rstr; |
|
|
1081 | } |
|
|
1082 | OUTPUT: |
|
|
1083 | RETVAL |
856 | |
1084 | |
857 | SV * |
1085 | SV * |
858 | rxvt_term::special_decode (SV *str) |
1086 | rxvt_term::special_decode (SV *text) |
859 | CODE: |
1087 | CODE: |
860 | abort ();//TODO |
1088 | { |
|
|
1089 | wchar_t *wstr = sv2wcs (text); |
|
|
1090 | int wlen = wcslen (wstr); |
|
|
1091 | int dlen = 0; |
|
|
1092 | |
|
|
1093 | // find length |
|
|
1094 | for (wchar_t *s = wstr; *s; s++) |
|
|
1095 | if (*s == NOCHAR) |
|
|
1096 | ; |
|
|
1097 | else if (IS_COMPOSE (*s)) |
|
|
1098 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1099 | else |
|
|
1100 | dlen++; |
|
|
1101 | |
|
|
1102 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1103 | |
|
|
1104 | // decode |
|
|
1105 | wchar_t *r = rstr; |
|
|
1106 | for (wchar_t *s = wstr; *s; s++) |
|
|
1107 | if (*s == NOCHAR) |
|
|
1108 | ; |
|
|
1109 | else if (IS_COMPOSE (*s)) |
|
|
1110 | r += rxvt_composite.expand (*s, r); |
|
|
1111 | else |
|
|
1112 | *r++ = *s; |
|
|
1113 | |
|
|
1114 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1115 | |
|
|
1116 | delete [] rstr; |
|
|
1117 | } |
|
|
1118 | OUTPUT: |
|
|
1119 | RETVAL |
861 | |
1120 | |
862 | void |
1121 | void |
863 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1122 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
864 | PPCODE: |
1123 | PPCODE: |
865 | { |
1124 | { |
… | |
… | |
897 | else |
1156 | else |
898 | THIS->rs [index] = 0; |
1157 | THIS->rs [index] = 0; |
899 | } |
1158 | } |
900 | } |
1159 | } |
901 | |
1160 | |
|
|
1161 | bool |
|
|
1162 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1163 | CODE: |
|
|
1164 | { |
|
|
1165 | RETVAL = THIS->options & optval; |
|
|
1166 | |
|
|
1167 | if (set >= 0) |
|
|
1168 | { |
|
|
1169 | if (set) |
|
|
1170 | THIS->options |= optval; |
|
|
1171 | else |
|
|
1172 | THIS->options &= ~optval; |
|
|
1173 | |
|
|
1174 | switch (optval) |
|
|
1175 | { |
|
|
1176 | case Opt_skipBuiltinGlyphs: |
|
|
1177 | THIS->set_fonts (); |
|
|
1178 | THIS->scr_remap_chars (); |
|
|
1179 | THIS->scr_touch (true); |
|
|
1180 | THIS->want_refresh = 1; |
|
|
1181 | break; |
|
|
1182 | |
|
|
1183 | case Opt_cursorUnderline: |
|
|
1184 | THIS->want_refresh = 1; |
|
|
1185 | break; |
|
|
1186 | |
|
|
1187 | # case Opt_scrollBar_floating: |
|
|
1188 | # case Opt_scrollBar_right: |
|
|
1189 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1190 | # break; |
|
|
1191 | } |
|
|
1192 | } |
|
|
1193 | } |
|
|
1194 | OUTPUT: |
|
|
1195 | RETVAL |
|
|
1196 | |
902 | void |
1197 | void |
903 | rxvt_term::cur (...) |
1198 | rxvt_term::cur (...) |
904 | PROTOTYPE: $;$$ |
1199 | PROTOTYPE: $;$$ |
905 | ALIAS: |
1200 | ALIAS: |
906 | screen_cur = 0 |
1201 | screen_cur = 0 |
… | |
… | |
930 | THIS->want_refresh = 1; |
1225 | THIS->want_refresh = 1; |
931 | } |
1226 | } |
932 | } |
1227 | } |
933 | |
1228 | |
934 | int |
1229 | int |
935 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1230 | rxvt_term::selection_grab (U32 eventtime) |
936 | |
1231 | |
937 | void |
1232 | void |
938 | rxvt_term::selection (SV *newtext = 0) |
1233 | rxvt_term::selection (SV *newtext = 0) |
939 | PPCODE: |
1234 | PPCODE: |
940 | { |
1235 | { |
… | |
… | |
953 | void |
1248 | void |
954 | rxvt_term::scr_add_lines (SV *string) |
1249 | rxvt_term::scr_add_lines (SV *string) |
955 | CODE: |
1250 | CODE: |
956 | { |
1251 | { |
957 | wchar_t *wstr = sv2wcs (string); |
1252 | wchar_t *wstr = sv2wcs (string); |
958 | int wlen = wcslen (wstr); |
|
|
959 | unicode_t *ustr = new unicode_t [wlen]; |
|
|
960 | int nlines = 0; |
|
|
961 | |
|
|
962 | for (int i = wlen; i--; ) |
|
|
963 | { |
|
|
964 | ustr [i] = wstr [i]; |
|
|
965 | nlines += ustr [i] == '\012'; |
|
|
966 | } |
|
|
967 | |
|
|
968 | THIS->scr_add_lines (ustr, nlines, wlen); |
1253 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
969 | |
|
|
970 | free (wstr); |
1254 | free (wstr); |
971 | delete [] ustr; |
|
|
972 | } |
1255 | } |
973 | |
1256 | |
974 | void |
1257 | void |
975 | rxvt_term::tt_write (SV *octets) |
1258 | rxvt_term::tt_write (SV *octets) |
976 | INIT: |
1259 | INIT: |
977 | STRLEN len; |
1260 | STRLEN len; |
978 | char *str = SvPVbyte (octets, len); |
1261 | char *str = SvPVbyte (octets, len); |
979 | C_ARGS: |
1262 | C_ARGS: |
980 | str, len |
1263 | str, len |
981 | |
1264 | |
|
|
1265 | void |
|
|
1266 | rxvt_term::cmd_parse (SV *octets) |
|
|
1267 | CODE: |
|
|
1268 | { |
|
|
1269 | STRLEN len; |
|
|
1270 | char *str = SvPVbyte (octets, len); |
|
|
1271 | |
|
|
1272 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1273 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1274 | |
|
|
1275 | THIS->cmdbuf_ptr = str; |
|
|
1276 | THIS->cmdbuf_endp = str + len; |
|
|
1277 | |
|
|
1278 | rxvt_push_locale (THIS->locale); |
|
|
1279 | THIS->cmd_parse (); |
|
|
1280 | rxvt_pop_locale (); |
|
|
1281 | |
|
|
1282 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1283 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1284 | } |
|
|
1285 | |
982 | SV * |
1286 | SV * |
983 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1287 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
984 | CODE: |
1288 | CODE: |
985 | { |
1289 | { |
986 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1290 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |