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.32 by root, Fri Jan 6 18:33:30 2006 UTC vs.
Revision 1.39 by root, Sat Jan 7 23:18:56 2006 UTC

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
111struct perl_watcher 112struct perl_watcher
290void 291void
291overlay::show () 292overlay::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
299void 300void
300overlay::hide () 301overlay::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
485 wchar_t *wstr = va_arg (ap, wchar_t *); 486 wchar_t *wstr = va_arg (ap, wchar_t *);
486 int wlen = va_arg (ap, int); 487 int wlen = va_arg (ap, int);
487 488
488 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 489 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
489 } 490 }
491 break;
490 492
491 case DT_XEVENT: 493 case DT_XEVENT:
492 { 494 {
493 XEvent *xe = va_arg (ap, XEvent *); 495 XEvent *xe = va_arg (ap, XEvent *);
494 HV *hv = newHV (); 496 HV *hv = newHV ();
561 if (SvTRUE (ERRSV)) 563 if (SvTRUE (ERRSV))
562 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));
563 565
564 if (htype == HOOK_DESTROY) 566 if (htype == HOOK_DESTROY)
565 { 567 {
566 clearSVptr ((SV *)term->self); 568 clearSVptr ((SV *)term->perl.self);
567 SvREFCNT_dec ((SV *)term->self); 569 SvREFCNT_dec ((SV *)term->perl.self);
568 } 570 }
569 571
570 return count; 572 return count;
571 } 573 }
572 574
582 584
583PROTOTYPES: ENABLE 585PROTOTYPES: ENABLE
584 586
585BOOT: 587BOOT:
586{ 588{
587# 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
588 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 591 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
589# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 592# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
590# include "hookinc.h" 593# include "hookinc.h"
591# undef def 594# undef def
592 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));
593 export_const (DEFAULT_RSTYLE); 605 export_const_iv (DEFAULT_RSTYLE);
594 export_const (OVERLAY_RSTYLE); 606 export_const_iv (OVERLAY_RSTYLE);
595 export_const (RS_Bold); 607 export_const_iv (RS_Bold);
596 export_const (RS_Italic); 608 export_const_iv (RS_Italic);
597 export_const (RS_Blink); 609 export_const_iv (RS_Blink);
598 export_const (RS_RVid); 610 export_const_iv (RS_RVid);
599 export_const (RS_Uline); 611 export_const_iv (RS_Uline);
600 612
601 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);
602} 628}
603 629
604SV * 630SV *
605new (...) 631new (...)
606 CODE: 632 CODE:
624 { 650 {
625 term->destroy (); 651 term->destroy ();
626 croak ("exception caught while initializing new terminal instance"); 652 croak ("exception caught while initializing new terminal instance");
627 } 653 }
628 654
629 RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; 655 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
630} 656}
631 OUTPUT: 657 OUTPUT:
632 RETVAL 658 RETVAL
633 659
634void 660void
703 729
704MODULE = urxvt PACKAGE = urxvt::term 730MODULE = urxvt PACKAGE = urxvt::term
705 731
706void 732void
707rxvt_term::destroy () 733rxvt_term::destroy ()
734
735void
736rxvt_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
742bool
743rxvt_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
763void
764rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime)
765 CODE:
766 XAllowEvents (THIS->display->display, AsyncBoth, eventtime);
767
768void
769rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime)
770 CODE:
771 XAllowEvents (THIS->display->display, SyncBoth, eventtime);
772
773void
774rxvt_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
779void
780rxvt_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);
708 785
709int 786int
710rxvt_term::strwidth (SV *str) 787rxvt_term::strwidth (SV *str)
711 CODE: 788 CODE:
712{ 789{
754 free (wstr); 831 free (wstr);
755} 832}
756 OUTPUT: 833 OUTPUT:
757 RETVAL 834 RETVAL
758 835
759# very portable, especially on objects as opposed to pods 836#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
760#define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0)
761 837
762#define TERM_OFFSET_width TERM_OFFSET(width) 838#define TERM_OFFSET_width TERM_OFFSET(width)
763#define TERM_OFFSET_height TERM_OFFSET(height) 839#define TERM_OFFSET_height TERM_OFFSET(height)
764#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 840#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
765#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 841#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
790 CODE: 866 CODE:
791 RETVAL = *(int *)((char *)THIS + ix); 867 RETVAL = *(int *)((char *)THIS + ix);
792 OUTPUT: 868 OUTPUT:
793 RETVAL 869 RETVAL
794 870
871unsigned int
872rxvt_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
795U32 887U32
796rxvt_term::parent () 888rxvt_term::parent ()
797 CODE: 889 CODE:
798 RETVAL = (U32)THIS->parent [0]; 890 RETVAL = (U32)THIS->parent [0];
799 OUTPUT: 891 OUTPUT:
847 939
848 if (GIMME_V != G_VOID) 940 if (GIMME_V != G_VOID)
849 { 941 {
850 wchar_t *wstr = new wchar_t [THIS->ncol]; 942 wchar_t *wstr = new wchar_t [THIS->ncol];
851 943
852 for (int col = 0; col <THIS->ncol; col++) 944 for (int col = 0; col < THIS->ncol; col++)
853 wstr [col] = l.t [col]; 945 wstr [col] = l.t [col];
854 946
855 XPUSHs (sv_2mortal (wcs2sv (wstr))); 947 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
856 948
857 delete [] wstr; 949 delete [] wstr;
858 } 950 }
859 951
860 if (new_text) 952 if (new_text)
950} 1042}
951 OUTPUT: 1043 OUTPUT:
952 RETVAL 1044 RETVAL
953 1045
954SV * 1046SV *
955rxvt_term::special_encode (SV *str) 1047rxvt_term::special_encode (SV *string)
956 CODE: 1048 CODE:
957 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
958 1084
959SV * 1085SV *
960rxvt_term::special_decode (SV *str) 1086rxvt_term::special_decode (SV *text)
961 CODE: 1087 CODE:
962 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
963 1120
964void 1121void
965rxvt_term::_resource (char *name, int index, SV *newval = 0) 1122rxvt_term::_resource (char *name, int index, SV *newval = 0)
966 PPCODE: 1123 PPCODE:
967{ 1124{
1032 THIS->want_refresh = 1; 1189 THIS->want_refresh = 1;
1033 } 1190 }
1034} 1191}
1035 1192
1036int 1193int
1037rxvt_term::selection_grab (int eventtime = CurrentTime) 1194rxvt_term::selection_grab (U32 eventtime)
1038 1195
1039void 1196void
1040rxvt_term::selection (SV *newtext = 0) 1197rxvt_term::selection (SV *newtext = 0)
1041 PPCODE: 1198 PPCODE:
1042{ 1199{
1080 char *old_cmdbuf_endp = THIS->cmdbuf_endp; 1237 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1081 1238
1082 THIS->cmdbuf_ptr = str; 1239 THIS->cmdbuf_ptr = str;
1083 THIS->cmdbuf_endp = str + len; 1240 THIS->cmdbuf_endp = str + len;
1084 1241
1242 rxvt_push_locale (THIS->locale);
1085 THIS->cmd_parse (); 1243 THIS->cmd_parse ();
1244 rxvt_pop_locale ();
1086 1245
1087 THIS->cmdbuf_ptr = old_cmdbuf_ptr; 1246 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1088 THIS->cmdbuf_endp = old_cmdbuf_endp; 1247 THIS->cmdbuf_endp = old_cmdbuf_endp;
1089} 1248}
1090 1249

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines