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. |
… | |
… | |
51 | char *str = SvPVutf8 (sv, len); |
51 | char *str = SvPVutf8 (sv, len); |
52 | return rxvt_utf8towcs (str, len); |
52 | return rxvt_utf8towcs (str, len); |
53 | } |
53 | } |
54 | |
54 | |
55 | static SV * |
55 | static SV * |
|
|
56 | wcs2sv (wchar_t *wstr, int len = -1) |
|
|
57 | { |
|
|
58 | char *str = rxvt_wcstoutf8 (wstr, len); |
|
|
59 | |
|
|
60 | SV *sv = newSVpv (str, 0); |
|
|
61 | SvUTF8_on (sv); |
|
|
62 | free (str); |
|
|
63 | |
|
|
64 | return sv; |
|
|
65 | } |
|
|
66 | |
|
|
67 | static SV * |
56 | new_ref (HV *hv, const char *klass) |
68 | new_ref (HV *hv, const char *klass) |
57 | { |
69 | { |
58 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
70 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
59 | } |
71 | } |
60 | |
72 | |
… | |
… | |
89 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
101 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
90 | |
102 | |
91 | return (long)mg->mg_ptr; |
103 | return (long)mg->mg_ptr; |
92 | } |
104 | } |
93 | |
105 | |
94 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
106 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
95 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
107 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
96 | |
108 | |
97 | ///////////////////////////////////////////////////////////////////////////// |
109 | ///////////////////////////////////////////////////////////////////////////// |
98 | |
110 | |
99 | struct perl_watcher |
111 | struct perl_watcher |
… | |
… | |
278 | void |
290 | void |
279 | overlay::show () |
291 | overlay::show () |
280 | { |
292 | { |
281 | char key[33]; sprintf (key, "%32lx", (long)this); |
293 | char key[33]; sprintf (key, "%32lx", (long)this); |
282 | |
294 | |
283 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
295 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
284 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
296 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
285 | } |
297 | } |
286 | |
298 | |
287 | void |
299 | void |
288 | overlay::hide () |
300 | overlay::hide () |
289 | { |
301 | { |
290 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); |
302 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
291 | |
303 | |
292 | if (ovs) |
304 | if (ovs) |
293 | { |
305 | { |
294 | char key[33]; sprintf (key, "%32lx", (long)this); |
306 | char key[33]; sprintf (key, "%32lx", (long)this); |
295 | |
307 | |
… | |
… | |
403 | if (!perl) |
415 | if (!perl) |
404 | return false; |
416 | return false; |
405 | |
417 | |
406 | if (htype == HOOK_INIT) // first hook ever called |
418 | if (htype == HOOK_INIT) // first hook ever called |
407 | { |
419 | { |
408 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
420 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
409 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
421 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
410 | } |
422 | } |
411 | else if (!term->self) |
423 | else if (!term->perl.self) |
412 | return false; // perl not initialized for this instance |
424 | return false; // perl not initialized for this instance |
413 | else if (htype == HOOK_DESTROY) |
425 | else if (htype == HOOK_DESTROY) |
414 | { |
426 | { |
415 | // handled later |
427 | // handled later |
416 | } |
428 | } |
417 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
429 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
418 | { |
430 | { |
419 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
431 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
420 | |
432 | |
421 | if (HvKEYS (hv)) |
433 | if (HvKEYS (hv)) |
422 | { |
434 | { |
423 | hv_iterinit (hv); |
435 | hv_iterinit (hv); |
424 | |
436 | |
… | |
… | |
453 | |
465 | |
454 | case DT_LONG: |
466 | case DT_LONG: |
455 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
456 | break; |
468 | break; |
457 | |
469 | |
458 | case DT_STRING: |
470 | case DT_STR: |
459 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
|
|
472 | break; |
|
|
473 | |
|
|
474 | case DT_STR_LEN: |
|
|
475 | { |
|
|
476 | char *str = va_arg (ap, char *); |
|
|
477 | int len = va_arg (ap, int); |
|
|
478 | |
|
|
479 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
|
|
480 | } |
|
|
481 | break; |
|
|
482 | |
|
|
483 | case DT_WCS_LEN: |
|
|
484 | { |
|
|
485 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
486 | int wlen = va_arg (ap, int); |
|
|
487 | |
|
|
488 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
|
|
489 | } |
|
|
490 | break; |
|
|
491 | |
|
|
492 | case DT_XEVENT: |
|
|
493 | { |
|
|
494 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
495 | HV *hv = newHV (); |
|
|
496 | |
|
|
497 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
498 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
499 | # undef set |
|
|
500 | |
|
|
501 | setiv (type, xe->type); |
|
|
502 | setiv (send_event, xe->xany.send_event); |
|
|
503 | setiv (serial, xe->xany.serial); |
|
|
504 | |
|
|
505 | switch (xe->type) |
|
|
506 | { |
|
|
507 | case KeyPress: |
|
|
508 | case KeyRelease: |
|
|
509 | case ButtonPress: |
|
|
510 | case ButtonRelease: |
|
|
511 | case MotionNotify: |
|
|
512 | setiv (time, xe->xmotion.time); |
|
|
513 | setiv (x, xe->xmotion.x); |
|
|
514 | setiv (y, xe->xmotion.y); |
|
|
515 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
516 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
517 | setiv (x_root, xe->xmotion.x_root); |
|
|
518 | setiv (y_root, xe->xmotion.y_root); |
|
|
519 | setiv (state, xe->xmotion.state); |
|
|
520 | break; |
|
|
521 | } |
|
|
522 | |
|
|
523 | switch (xe->type) |
|
|
524 | { |
|
|
525 | case KeyPress: |
|
|
526 | case KeyRelease: |
|
|
527 | setiv (keycode, xe->xkey.keycode); |
|
|
528 | break; |
|
|
529 | |
|
|
530 | case ButtonPress: |
|
|
531 | case ButtonRelease: |
|
|
532 | setiv (button, xe->xbutton.button); |
|
|
533 | break; |
|
|
534 | |
|
|
535 | case MotionNotify: |
|
|
536 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
537 | break; |
|
|
538 | } |
|
|
539 | |
|
|
540 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
541 | } |
460 | break; |
542 | break; |
461 | |
543 | |
462 | case DT_END: |
544 | case DT_END: |
463 | { |
545 | { |
464 | va_end (ap); |
546 | va_end (ap); |
… | |
… | |
480 | if (SvTRUE (ERRSV)) |
562 | if (SvTRUE (ERRSV)) |
481 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
563 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
482 | |
564 | |
483 | if (htype == HOOK_DESTROY) |
565 | if (htype == HOOK_DESTROY) |
484 | { |
566 | { |
485 | clearSVptr ((SV *)term->self); |
567 | clearSVptr ((SV *)term->perl.self); |
486 | SvREFCNT_dec ((SV *)term->self); |
568 | SvREFCNT_dec ((SV *)term->perl.self); |
487 | } |
569 | } |
488 | |
570 | |
489 | return count; |
571 | return count; |
490 | } |
572 | } |
491 | |
573 | |
… | |
… | |
501 | |
583 | |
502 | PROTOTYPES: ENABLE |
584 | PROTOTYPES: ENABLE |
503 | |
585 | |
504 | BOOT: |
586 | BOOT: |
505 | { |
587 | { |
|
|
588 | HV *stash = gv_stashpv ("urxvt", 1); |
506 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
589 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
|
|
590 | |
507 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
591 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
508 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
592 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
509 | # include "hookinc.h" |
593 | # include "hookinc.h" |
510 | # undef def |
594 | # undef def |
511 | |
595 | |
|
|
596 | |
512 | export_const (DEFAULT_RSTYLE); |
597 | export_const_iv (DEFAULT_RSTYLE); |
513 | export_const (OVERLAY_RSTYLE); |
598 | export_const_iv (OVERLAY_RSTYLE); |
514 | export_const (RS_Bold); |
599 | export_const_iv (RS_Bold); |
515 | export_const (RS_Italic); |
600 | export_const_iv (RS_Italic); |
516 | export_const (RS_Blink); |
601 | export_const_iv (RS_Blink); |
517 | export_const (RS_RVid); |
602 | export_const_iv (RS_RVid); |
518 | export_const (RS_Uline); |
603 | export_const_iv (RS_Uline); |
|
|
604 | export_const_iv (CurrentTime); |
519 | |
605 | |
520 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
606 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
521 | } |
607 | } |
|
|
608 | |
|
|
609 | SV * |
|
|
610 | new (...) |
|
|
611 | CODE: |
|
|
612 | { |
|
|
613 | stringvec *argv = new stringvec; |
|
|
614 | bool success; |
|
|
615 | |
|
|
616 | for (int i = 0; i < items ;i++) |
|
|
617 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
618 | |
|
|
619 | rxvt_term *term = new rxvt_term; |
|
|
620 | |
|
|
621 | term->argv = argv; |
|
|
622 | |
|
|
623 | try |
|
|
624 | { |
|
|
625 | if (!term->init (argv->size (), argv->begin ())) |
|
|
626 | term = 0; |
|
|
627 | } |
|
|
628 | catch (const class rxvt_failure_exception &e) |
|
|
629 | { |
|
|
630 | term->destroy (); |
|
|
631 | croak ("exception caught while initializing new terminal instance"); |
|
|
632 | } |
|
|
633 | |
|
|
634 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
|
|
635 | } |
|
|
636 | OUTPUT: |
|
|
637 | RETVAL |
522 | |
638 | |
523 | void |
639 | void |
524 | set_should_invoke (int htype, int value) |
640 | set_should_invoke (int htype, int value) |
525 | CODE: |
641 | CODE: |
526 | rxvt_perl.should_invoke [htype] = value; |
642 | rxvt_perl.should_invoke [htype] = value; |
… | |
… | |
589 | } |
705 | } |
590 | OUTPUT: |
706 | OUTPUT: |
591 | RETVAL |
707 | RETVAL |
592 | |
708 | |
593 | MODULE = urxvt PACKAGE = urxvt::term |
709 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
710 | |
|
|
711 | void |
|
|
712 | rxvt_term::destroy () |
|
|
713 | |
|
|
714 | void |
|
|
715 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
716 | CODE: |
|
|
717 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
718 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
719 | GrabModeSync, GrabModeSync, None, None); |
|
|
720 | |
|
|
721 | bool |
|
|
722 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
723 | CODE: |
|
|
724 | { |
|
|
725 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
726 | |
|
|
727 | THIS->perl.grabtime = 0; |
|
|
728 | |
|
|
729 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
730 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
731 | mode, mode, None, None, eventtime)) |
|
|
732 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
733 | THIS->perl.grabtime = eventtime; |
|
|
734 | else |
|
|
735 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
736 | |
|
|
737 | RETVAL = !!THIS->perl.grabtime; |
|
|
738 | } |
|
|
739 | OUTPUT: |
|
|
740 | RETVAL |
|
|
741 | |
|
|
742 | void |
|
|
743 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
|
|
744 | CODE: |
|
|
745 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
|
|
746 | |
|
|
747 | void |
|
|
748 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
|
|
749 | CODE: |
|
|
750 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
|
|
751 | |
|
|
752 | void |
|
|
753 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
|
|
754 | CODE: |
|
|
755 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
|
|
756 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
|
|
757 | |
|
|
758 | void |
|
|
759 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
|
|
760 | CODE: |
|
|
761 | THIS->perl.grabtime = 0; |
|
|
762 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
763 | XUngrabPointer (THIS->display->display, eventtime); |
594 | |
764 | |
595 | int |
765 | int |
596 | rxvt_term::strwidth (SV *str) |
766 | rxvt_term::strwidth (SV *str) |
597 | CODE: |
767 | CODE: |
598 | { |
768 | { |
… | |
… | |
634 | |
804 | |
635 | rxvt_push_locale (THIS->locale); |
805 | rxvt_push_locale (THIS->locale); |
636 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
806 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
637 | rxvt_pop_locale (); |
807 | rxvt_pop_locale (); |
638 | |
808 | |
639 | char *str = rxvt_wcstoutf8 (wstr); |
809 | RETVAL = wcs2sv (wstr); |
640 | free (wstr); |
810 | free (wstr); |
641 | |
|
|
642 | RETVAL = newSVpv (str, 0); |
|
|
643 | SvUTF8_on (RETVAL); |
|
|
644 | free (str); |
|
|
645 | } |
811 | } |
646 | OUTPUT: |
812 | OUTPUT: |
647 | RETVAL |
813 | RETVAL |
648 | |
814 | |
649 | # very portable, especially on objects as opposed to pods |
815 | # very portable, especially on objects as opposed to pods |
… | |
… | |
681 | RETVAL = *(int *)((char *)THIS + ix); |
847 | RETVAL = *(int *)((char *)THIS + ix); |
682 | OUTPUT: |
848 | OUTPUT: |
683 | RETVAL |
849 | RETVAL |
684 | |
850 | |
685 | U32 |
851 | U32 |
|
|
852 | rxvt_term::parent () |
|
|
853 | CODE: |
|
|
854 | RETVAL = (U32)THIS->parent [0]; |
|
|
855 | OUTPUT: |
|
|
856 | RETVAL |
|
|
857 | |
|
|
858 | U32 |
|
|
859 | rxvt_term::vt () |
|
|
860 | CODE: |
|
|
861 | RETVAL = (U32)THIS->vt; |
|
|
862 | OUTPUT: |
|
|
863 | RETVAL |
|
|
864 | |
|
|
865 | U32 |
686 | rxvt_term::screen_rstyle (U32 new_rstyle = THIS->screen.s_rstyle) |
866 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
687 | CODE: |
867 | CODE: |
688 | { |
868 | { |
689 | RETVAL = THIS->screen.s_rstyle; |
869 | RETVAL = THIS->rstyle; |
690 | THIS->screen.s_rstyle = new_rstyle; |
870 | THIS->rstyle = new_rstyle; |
691 | } |
871 | } |
692 | OUTPUT: |
872 | OUTPUT: |
693 | RETVAL |
873 | RETVAL |
694 | |
874 | |
695 | int |
875 | int |
… | |
… | |
711 | rxvt_term::want_refresh () |
891 | rxvt_term::want_refresh () |
712 | CODE: |
892 | CODE: |
713 | THIS->want_refresh = 1; |
893 | THIS->want_refresh = 1; |
714 | |
894 | |
715 | void |
895 | void |
716 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
896 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
717 | PPCODE: |
897 | PPCODE: |
718 | { |
898 | { |
719 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
899 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
720 | XSRETURN_EMPTY; |
900 | XSRETURN_EMPTY; |
721 | |
901 | |
… | |
… | |
723 | |
903 | |
724 | if (GIMME_V != G_VOID) |
904 | if (GIMME_V != G_VOID) |
725 | { |
905 | { |
726 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
906 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
727 | |
907 | |
728 | for (int col = 0; col <THIS->ncol; col++) |
908 | for (int col = 0; col < THIS->ncol; col++) |
729 | wstr [col] = l.t [col]; |
909 | wstr [col] = l.t [col]; |
730 | |
910 | |
731 | char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); |
|
|
732 | free (wstr); |
|
|
733 | |
|
|
734 | SV *sv = newSVpv (str, 0); |
|
|
735 | SvUTF8_on (sv); |
|
|
736 | XPUSHs (sv_2mortal (sv)); |
911 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
737 | free (str); |
912 | |
|
|
913 | delete [] wstr; |
738 | } |
914 | } |
739 | |
915 | |
740 | if (new_text) |
916 | if (new_text) |
741 | { |
917 | { |
742 | wchar_t *wstr = sv2wcs (new_text); |
918 | wchar_t *wstr = sv2wcs (new_text); |
743 | |
919 | |
744 | int len = wcslen (wstr); |
920 | int len = min (wcslen (wstr) - start_ofs, max_len); |
745 | |
921 | |
746 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
922 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
747 | { |
923 | { |
748 | free (wstr); |
924 | free (wstr); |
749 | croak ("new_text extends beyond horizontal margins"); |
925 | croak ("new_text extends beyond horizontal margins"); |
750 | } |
926 | } |
751 | |
927 | |
752 | for (int col = start_col; col < start_col + len; col++) |
928 | for (int col = start_col; col < start_col + len; col++) |
753 | { |
929 | { |
754 | l.t [col] = wstr [col - start_col]; |
930 | l.t [col] = wstr [start_ofs + col - start_col]; |
755 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
931 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
756 | } |
932 | } |
757 | |
933 | |
758 | free (wstr); |
934 | free (wstr); |
759 | } |
935 | } |
760 | } |
936 | } |
761 | |
937 | |
762 | void |
938 | void |
763 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
939 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
764 | PPCODE: |
940 | PPCODE: |
765 | { |
941 | { |
766 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
942 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
767 | XSRETURN_EMPTY; |
943 | XSRETURN_EMPTY; |
768 | |
944 | |
… | |
… | |
783 | { |
959 | { |
784 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
960 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
785 | croak ("new_rend must be arrayref"); |
961 | croak ("new_rend must be arrayref"); |
786 | |
962 | |
787 | AV *av = (AV *)SvRV (new_rend); |
963 | AV *av = (AV *)SvRV (new_rend); |
788 | int len = av_len (av) + 1; |
964 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
789 | |
965 | |
790 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
966 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
791 | croak ("new_rend array extends beyond horizontal margins"); |
967 | croak ("new_rend array extends beyond horizontal margins"); |
792 | |
968 | |
793 | for (int col = start_col; col < start_col + len; col++) |
969 | for (int col = start_col; col < start_col + len; col++) |
794 | { |
970 | { |
795 | rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
971 | rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
796 | |
972 | |
797 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
973 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
798 | } |
974 | } |
799 | } |
975 | } |
800 | } |
976 | } |
801 | |
977 | |
802 | int |
978 | int |
803 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
979 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
804 | CODE: |
980 | CODE: |
805 | { |
981 | { |
806 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
982 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
807 | XSRETURN_EMPTY; |
983 | XSRETURN_EMPTY; |
808 | |
984 | |
809 | line_t &l = ROW(row_number); |
985 | line_t &l = ROW(row_number); |
810 | RETVAL = l.l < 0 ? THIS->ncol : l.l; |
986 | RETVAL = l.l; |
811 | |
987 | |
812 | if (new_length >= -1) |
988 | if (new_length >= 0) |
813 | l.l = new_length; |
989 | l.l = new_length; |
814 | } |
990 | } |
815 | OUTPUT: |
991 | OUTPUT: |
816 | RETVAL |
992 | RETVAL |
817 | |
993 | |
818 | bool |
994 | bool |
819 | rxvt_term::ROW_is_longer (int row_number) |
995 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
820 | CODE: |
996 | CODE: |
821 | { |
997 | { |
822 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
998 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
823 | XSRETURN_EMPTY; |
999 | XSRETURN_EMPTY; |
824 | |
1000 | |
825 | line_t &l = ROW(row_number); |
1001 | line_t &l = ROW(row_number); |
826 | RETVAL = l.l < 0; |
1002 | RETVAL = l.is_longer (); |
|
|
1003 | |
|
|
1004 | if (new_is_longer >= 0) |
|
|
1005 | l.is_longer (new_is_longer); |
827 | } |
1006 | } |
828 | OUTPUT: |
1007 | OUTPUT: |
829 | RETVAL |
1008 | RETVAL |
830 | |
1009 | |
831 | SV * |
1010 | SV * |
832 | rxvt_term::special_encode (SV *str) |
1011 | rxvt_term::special_encode (SV *string) |
833 | CODE: |
1012 | CODE: |
834 | abort ();//TODO |
1013 | { |
|
|
1014 | wchar_t *wstr = sv2wcs (string); |
|
|
1015 | int wlen = wcslen (wstr); |
|
|
1016 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1017 | |
|
|
1018 | rxvt_push_locale (THIS->locale); |
|
|
1019 | |
|
|
1020 | wchar_t *r = rstr; |
|
|
1021 | for (wchar_t *s = wstr; *s; s++) |
|
|
1022 | if (wcwidth (*s) == 0) |
|
|
1023 | { |
|
|
1024 | if (r == rstr) |
|
|
1025 | croak ("leading combining character unencodable"); |
|
|
1026 | |
|
|
1027 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1028 | if (n == NOCHAR) |
|
|
1029 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1030 | |
|
|
1031 | r[-1] = n; |
|
|
1032 | } |
|
|
1033 | #if !UNICODE_3 |
|
|
1034 | else if (*s >= 0x10000) |
|
|
1035 | *r++ = rxvt_composite.compose (*s); |
|
|
1036 | #endif |
|
|
1037 | else |
|
|
1038 | *r++ = *s; |
|
|
1039 | |
|
|
1040 | rxvt_pop_locale (); |
|
|
1041 | |
|
|
1042 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1043 | |
|
|
1044 | delete [] rstr; |
|
|
1045 | } |
|
|
1046 | OUTPUT: |
|
|
1047 | RETVAL |
835 | |
1048 | |
836 | SV * |
1049 | SV * |
837 | rxvt_term::special_decode (SV *str) |
1050 | rxvt_term::special_decode (SV *text) |
838 | CODE: |
1051 | CODE: |
839 | abort ();//TODO |
1052 | { |
|
|
1053 | wchar_t *wstr = sv2wcs (text); |
|
|
1054 | int wlen = wcslen (wstr); |
|
|
1055 | int dlen = 0; |
|
|
1056 | |
|
|
1057 | // find length |
|
|
1058 | for (wchar_t *s = wstr; *s; s++) |
|
|
1059 | if (*s == NOCHAR) |
|
|
1060 | ; |
|
|
1061 | else if (IS_COMPOSE (*s)) |
|
|
1062 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1063 | else |
|
|
1064 | dlen++; |
|
|
1065 | |
|
|
1066 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1067 | |
|
|
1068 | // decode |
|
|
1069 | wchar_t *r = rstr; |
|
|
1070 | for (wchar_t *s = wstr; *s; s++) |
|
|
1071 | if (*s == NOCHAR) |
|
|
1072 | ; |
|
|
1073 | else if (IS_COMPOSE (*s)) |
|
|
1074 | r += rxvt_composite.expand (*s, r); |
|
|
1075 | else |
|
|
1076 | *r++ = *s; |
|
|
1077 | |
|
|
1078 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1079 | |
|
|
1080 | delete [] rstr; |
|
|
1081 | } |
|
|
1082 | OUTPUT: |
|
|
1083 | RETVAL |
840 | |
1084 | |
841 | void |
1085 | void |
842 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1086 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
843 | PPCODE: |
1087 | PPCODE: |
844 | { |
1088 | { |
… | |
… | |
909 | THIS->want_refresh = 1; |
1153 | THIS->want_refresh = 1; |
910 | } |
1154 | } |
911 | } |
1155 | } |
912 | |
1156 | |
913 | int |
1157 | int |
914 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1158 | rxvt_term::selection_grab (U32 eventtime) |
915 | |
1159 | |
916 | void |
1160 | void |
917 | rxvt_term::selection (SV *newtext = 0) |
1161 | rxvt_term::selection (SV *newtext = 0) |
918 | PPCODE: |
1162 | PPCODE: |
919 | { |
1163 | { |
920 | if (GIMME_V != G_VOID) |
1164 | if (GIMME_V != G_VOID) |
921 | { |
1165 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
922 | char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); |
|
|
923 | SV *sv = newSVpv (sel, 0); |
|
|
924 | SvUTF8_on (sv); |
|
|
925 | free (sel); |
|
|
926 | XPUSHs (sv_2mortal (sv)); |
|
|
927 | } |
|
|
928 | |
1166 | |
929 | if (newtext) |
1167 | if (newtext) |
930 | { |
1168 | { |
931 | free (THIS->selection.text); |
1169 | free (THIS->selection.text); |
932 | |
1170 | |
933 | THIS->selection.text = sv2wcs (newtext); |
1171 | THIS->selection.text = sv2wcs (newtext); |
934 | THIS->selection.len = wcslen (THIS->selection.text); |
1172 | THIS->selection.len = wcslen (THIS->selection.text); |
935 | } |
1173 | } |
|
|
1174 | } |
|
|
1175 | |
|
|
1176 | void |
|
|
1177 | rxvt_term::scr_add_lines (SV *string) |
|
|
1178 | CODE: |
|
|
1179 | { |
|
|
1180 | wchar_t *wstr = sv2wcs (string); |
|
|
1181 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
|
|
1182 | free (wstr); |
936 | } |
1183 | } |
937 | |
1184 | |
938 | void |
1185 | void |
939 | rxvt_term::tt_write (SV *octets) |
1186 | rxvt_term::tt_write (SV *octets) |
940 | INIT: |
1187 | INIT: |
941 | STRLEN len; |
1188 | STRLEN len; |
942 | char *str = SvPVbyte (octets, len); |
1189 | char *str = SvPVbyte (octets, len); |
943 | C_ARGS: |
1190 | C_ARGS: |
944 | str, len |
1191 | str, len |
945 | |
1192 | |
|
|
1193 | void |
|
|
1194 | rxvt_term::cmd_parse (SV *octets) |
|
|
1195 | CODE: |
|
|
1196 | { |
|
|
1197 | STRLEN len; |
|
|
1198 | char *str = SvPVbyte (octets, len); |
|
|
1199 | |
|
|
1200 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1201 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1202 | |
|
|
1203 | THIS->cmdbuf_ptr = str; |
|
|
1204 | THIS->cmdbuf_endp = str + len; |
|
|
1205 | |
|
|
1206 | rxvt_push_locale (THIS->locale); |
|
|
1207 | THIS->cmd_parse (); |
|
|
1208 | rxvt_pop_locale (); |
|
|
1209 | |
|
|
1210 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1211 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1212 | } |
|
|
1213 | |
946 | SV * |
1214 | SV * |
947 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1215 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
948 | CODE: |
1216 | CODE: |
949 | { |
1217 | { |
950 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1218 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |