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.29 by root, Fri Jan 6 03:40:19 2006 UTC vs.
Revision 1.37 by root, Sat Jan 7 20:23:52 2006 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-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.
101 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);
102 102
103 return (long)mg->mg_ptr; 103 return (long)mg->mg_ptr;
104} 104}
105 105
106#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 106#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
107#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 107#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
108 108
109///////////////////////////////////////////////////////////////////////////// 109/////////////////////////////////////////////////////////////////////////////
110 110
111struct perl_watcher 111struct perl_watcher
290void 290void
291overlay::show () 291overlay::show ()
292{ 292{
293 char key[33]; sprintf (key, "%32lx", (long)this); 293 char key[33]; sprintf (key, "%32lx", (long)this);
294 294
295 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));
296 hv_store (hv, key, 32, newSViv ((long)this), 0); 296 hv_store (hv, key, 32, newSViv ((long)this), 0);
297} 297}
298 298
299void 299void
300overlay::hide () 300overlay::hide ()
301{ 301{
302 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);
303 303
304 if (ovs) 304 if (ovs)
305 { 305 {
306 char key[33]; sprintf (key, "%32lx", (long)this); 306 char key[33]; sprintf (key, "%32lx", (long)this);
307 307
415 if (!perl) 415 if (!perl)
416 return false; 416 return false;
417 417
418 if (htype == HOOK_INIT) // first hook ever called 418 if (htype == HOOK_INIT) // first hook ever called
419 { 419 {
420 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 420 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
421 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);
422 } 422 }
423 else if (!term->self) 423 else if (!term->perl.self)
424 return false; // perl not initialized for this instance 424 return false; // perl not initialized for this instance
425 else if (htype == HOOK_DESTROY) 425 else if (htype == HOOK_DESTROY)
426 { 426 {
427 // handled later 427 // handled later
428 } 428 }
429 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 429 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
430 { 430 {
431 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));
432 432
433 if (HvKEYS (hv)) 433 if (HvKEYS (hv))
434 { 434 {
435 hv_iterinit (hv); 435 hv_iterinit (hv);
436 436
465 465
466 case DT_LONG: 466 case DT_LONG:
467 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 467 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
468 break; 468 break;
469 469
470 case DT_STRING: 470 case DT_STR:
471 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 471 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
472 break; 472 break;
473 473
474 case DT_STRING_LEN: 474 case DT_STR_LEN:
475 { 475 {
476 char *str = va_arg (ap, char *); 476 char *str = va_arg (ap, char *);
477 int len = va_arg (ap, int); 477 int len = va_arg (ap, int);
478 478
479 XPUSHs (sv_2mortal (newSVpvn (str, len))); 479 XPUSHs (sv_2mortal (newSVpvn (str, len)));
480 } 480 }
481 break; 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;
482 491
483 case DT_XEVENT: 492 case DT_XEVENT:
484 { 493 {
485 XEvent *xe = va_arg (ap, XEvent *); 494 XEvent *xe = va_arg (ap, XEvent *);
486 HV *hv = newHV (); 495 HV *hv = newHV ();
501 case ButtonRelease: 510 case ButtonRelease:
502 case MotionNotify: 511 case MotionNotify:
503 setiv (time, xe->xmotion.time); 512 setiv (time, xe->xmotion.time);
504 setiv (x, xe->xmotion.x); 513 setiv (x, xe->xmotion.x);
505 setiv (y, xe->xmotion.y); 514 setiv (y, xe->xmotion.y);
515 setiv (row, xe->xmotion.y / term->fheight);
516 setiv (col, xe->xmotion.x / term->fwidth);
506 setiv (x_root, xe->xmotion.x_root); 517 setiv (x_root, xe->xmotion.x_root);
507 setiv (y_root, xe->xmotion.y_root); 518 setiv (y_root, xe->xmotion.y_root);
508 setiv (state, xe->xmotion.state); 519 setiv (state, xe->xmotion.state);
509 break; 520 break;
510 } 521 }
528 539
529 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 540 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
530 } 541 }
531 break; 542 break;
532 543
533 case DT_USTRING_LEN:
534 {
535 unicode_t *ustr = va_arg (ap, unicode_t *);
536 int ulen = va_arg (ap, int);
537 wchar_t *wstr = new wchar_t [ulen];
538
539 for (int i = ulen; i--; )
540 wstr [i] = ustr [i];
541
542 XPUSHs (sv_2mortal (wcs2sv (wstr, ulen)));
543
544 delete [] wstr;
545 }
546
547 case DT_END: 544 case DT_END:
548 { 545 {
549 va_end (ap); 546 va_end (ap);
550 547
551 PUTBACK; 548 PUTBACK;
565 if (SvTRUE (ERRSV)) 562 if (SvTRUE (ERRSV))
566 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));
567 564
568 if (htype == HOOK_DESTROY) 565 if (htype == HOOK_DESTROY)
569 { 566 {
570 clearSVptr ((SV *)term->self); 567 clearSVptr ((SV *)term->perl.self);
571 SvREFCNT_dec ((SV *)term->self); 568 SvREFCNT_dec ((SV *)term->perl.self);
572 } 569 }
573 570
574 return count; 571 return count;
575 } 572 }
576 573
586 583
587PROTOTYPES: ENABLE 584PROTOTYPES: ENABLE
588 585
589BOOT: 586BOOT:
590{ 587{
588 HV *stash = gv_stashpv ("urxvt", 1);
591# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); 589# define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
590
592 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 591 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
593# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 592# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
594# include "hookinc.h" 593# include "hookinc.h"
595# undef def 594# undef def
596 595
596
597 export_const (DEFAULT_RSTYLE); 597 export_const_iv (DEFAULT_RSTYLE);
598 export_const (OVERLAY_RSTYLE); 598 export_const_iv (OVERLAY_RSTYLE);
599 export_const (RS_Bold); 599 export_const_iv (RS_Bold);
600 export_const (RS_Italic); 600 export_const_iv (RS_Italic);
601 export_const (RS_Blink); 601 export_const_iv (RS_Blink);
602 export_const (RS_RVid); 602 export_const_iv (RS_RVid);
603 export_const (RS_Uline); 603 export_const_iv (RS_Uline);
604 export_const_iv (CurrentTime);
604 605
605 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 606 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
606} 607}
607 608
608SV * 609SV *
609new (...) 610new (...)
610 CODE: 611 CODE:
628 { 629 {
629 term->destroy (); 630 term->destroy ();
630 croak ("exception caught while initializing new terminal instance"); 631 croak ("exception caught while initializing new terminal instance");
631 } 632 }
632 633
633 RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; 634 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
634} 635}
635 OUTPUT: 636 OUTPUT:
636 RETVAL 637 RETVAL
637 638
638void 639void
707 708
708MODULE = urxvt PACKAGE = urxvt::term 709MODULE = urxvt PACKAGE = urxvt::term
709 710
710void 711void
711rxvt_term::destroy () 712rxvt_term::destroy ()
713
714void
715rxvt_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
721bool
722rxvt_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
742void
743rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime)
744 CODE:
745 XAllowEvents (THIS->display->display, AsyncBoth, eventtime);
746
747void
748rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime)
749 CODE:
750 XAllowEvents (THIS->display->display, SyncBoth, eventtime);
751
752void
753rxvt_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
758void
759rxvt_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);
712 764
713int 765int
714rxvt_term::strwidth (SV *str) 766rxvt_term::strwidth (SV *str)
715 CODE: 767 CODE:
716{ 768{
795 RETVAL = *(int *)((char *)THIS + ix); 847 RETVAL = *(int *)((char *)THIS + ix);
796 OUTPUT: 848 OUTPUT:
797 RETVAL 849 RETVAL
798 850
799U32 851U32
852rxvt_term::parent ()
853 CODE:
854 RETVAL = (U32)THIS->parent [0];
855 OUTPUT:
856 RETVAL
857
858U32
859rxvt_term::vt ()
860 CODE:
861 RETVAL = (U32)THIS->vt;
862 OUTPUT:
863 RETVAL
864
865U32
800rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) 866rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
801 CODE: 867 CODE:
802{ 868{
803 RETVAL = THIS->rstyle; 869 RETVAL = THIS->rstyle;
804 THIS->rstyle = new_rstyle; 870 THIS->rstyle = new_rstyle;
837 903
838 if (GIMME_V != G_VOID) 904 if (GIMME_V != G_VOID)
839 { 905 {
840 wchar_t *wstr = new wchar_t [THIS->ncol]; 906 wchar_t *wstr = new wchar_t [THIS->ncol];
841 907
842 for (int col = 0; col <THIS->ncol; col++) 908 for (int col = 0; col < THIS->ncol; col++)
843 wstr [col] = l.t [col]; 909 wstr [col] = l.t [col];
844 910
845 XPUSHs (sv_2mortal (wcs2sv (wstr))); 911 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
846 912
847 delete [] wstr; 913 delete [] wstr;
848 } 914 }
849 915
850 if (new_text) 916 if (new_text)
940} 1006}
941 OUTPUT: 1007 OUTPUT:
942 RETVAL 1008 RETVAL
943 1009
944SV * 1010SV *
945rxvt_term::special_encode (SV *str) 1011rxvt_term::special_encode (SV *string)
946 CODE: 1012 CODE:
947 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
948 1048
949SV * 1049SV *
950rxvt_term::special_decode (SV *str) 1050rxvt_term::special_decode (SV *text)
951 CODE: 1051 CODE:
952 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
953 1084
954void 1085void
955rxvt_term::_resource (char *name, int index, SV *newval = 0) 1086rxvt_term::_resource (char *name, int index, SV *newval = 0)
956 PPCODE: 1087 PPCODE:
957{ 1088{
1022 THIS->want_refresh = 1; 1153 THIS->want_refresh = 1;
1023 } 1154 }
1024} 1155}
1025 1156
1026int 1157int
1027rxvt_term::selection_grab (int eventtime = CurrentTime) 1158rxvt_term::selection_grab (U32 eventtime)
1028 1159
1029void 1160void
1030rxvt_term::selection (SV *newtext = 0) 1161rxvt_term::selection (SV *newtext = 0)
1031 PPCODE: 1162 PPCODE:
1032{ 1163{
1045void 1176void
1046rxvt_term::scr_add_lines (SV *string) 1177rxvt_term::scr_add_lines (SV *string)
1047 CODE: 1178 CODE:
1048{ 1179{
1049 wchar_t *wstr = sv2wcs (string); 1180 wchar_t *wstr = sv2wcs (string);
1050 int wlen = wcslen (wstr);
1051 unicode_t *ustr = new unicode_t [wlen];
1052 int nlines = 0;
1053
1054 for (int i = wlen; i--; )
1055 {
1056 ustr [i] = wstr [i];
1057 nlines += ustr [i] == '\012';
1058 }
1059
1060 THIS->scr_add_lines (ustr, nlines, wlen); 1181 THIS->scr_add_lines (wstr, wcslen (wstr));
1061
1062 free (wstr); 1182 free (wstr);
1063 delete [] ustr;
1064} 1183}
1065 1184
1066void 1185void
1067rxvt_term::tt_write (SV *octets) 1186rxvt_term::tt_write (SV *octets)
1068 INIT: 1187 INIT:
1082 char *old_cmdbuf_endp = THIS->cmdbuf_endp; 1201 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1083 1202
1084 THIS->cmdbuf_ptr = str; 1203 THIS->cmdbuf_ptr = str;
1085 THIS->cmdbuf_endp = str + len; 1204 THIS->cmdbuf_endp = str + len;
1086 1205
1206 rxvt_push_locale (THIS->locale);
1087 THIS->cmd_parse (); 1207 THIS->cmd_parse ();
1208 rxvt_pop_locale ();
1088 1209
1089 THIS->cmdbuf_ptr = old_cmdbuf_ptr; 1210 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1090 THIS->cmdbuf_endp = old_cmdbuf_endp; 1211 THIS->cmdbuf_endp = old_cmdbuf_endp;
1091} 1212}
1092 1213

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines