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.87 by root, Sat Jan 21 08:07:38 2006 UTC vs.
Revision 1.104 by root, Mon Aug 7 22:28:18 2006 UTC

80new_ref (HV *hv, const char *klass) 80new_ref (HV *hv, const char *klass)
81{ 81{
82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
83} 83}
84 84
85//TODO: use magic
86static SV * 85static SV *
87newSVptr (void *ptr, const char *klass) 86newSVptr (void *ptr, const char *klass)
88{ 87{
89 HV *hv = newHV (); 88 HV *hv = newHV ();
90 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 89 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
113 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 112 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
114 113
115 return (long)mg->mg_ptr; 114 return (long)mg->mg_ptr;
116} 115}
117 116
118#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) 117#define newSVterm(term) SvREFCNT_inc ((SV *)(term)->perl.self)
119#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 118#define SvTERM(sv) (rxvt_term *)SvPTR ((sv), "urxvt::term")
120 119
121///////////////////////////////////////////////////////////////////////////// 120/////////////////////////////////////////////////////////////////////////////
122 121
123#define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, "urxvt::watcher") 122#define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, "urxvt::watcher")
124 123
171 170
172 if (SvTRUE (ERRSV)) 171 if (SvTRUE (ERRSV))
173 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV)); 172 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
174} 173}
175 174
176#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") 175#define newSVtimer(timer) new_ref ((timer)->self, "urxvt::timer")
177#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR (sv, "urxvt::timer") 176#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR ((sv), "urxvt::timer")
178 177
179struct timer : perl_watcher, time_watcher 178struct timer : perl_watcher, time_watcher
180{ 179{
181 tstamp interval; 180 tstamp interval;
182 181
192 191
193 invoke ("urxvt::timer", newSVtimer (this)); 192 invoke ("urxvt::timer", newSVtimer (this));
194 } 193 }
195}; 194};
196 195
197#define newSViow(iow) new_ref (iow->self, "urxvt::iow") 196#define newSViow(iow) new_ref ((iow)->self, "urxvt::iow")
198#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR (sv, "urxvt::iow") 197#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR ((sv), "urxvt::iow")
199 198
200struct iow : perl_watcher, io_watcher 199struct iow : perl_watcher, io_watcher
201{ 200{
202 iow () 201 iow ()
203 : io_watcher (this, &iow::execute) 202 : io_watcher (this, &iow::execute)
208 { 207 {
209 invoke ("urxvt::iow", newSViow (this), revents); 208 invoke ("urxvt::iow", newSViow (this), revents);
210 } 209 }
211}; 210};
212 211
213#define newSViw(iw) new_ref (iw->self, "urxvt::iw") 212#define newSViw(iw) new_ref ((iw)->self, "urxvt::iw")
214#define SvIW(sv) (iw *)(perl_watcher *)SvPTR (sv, "urxvt::iw") 213#define SvIW(sv) (iw *)(perl_watcher *)SvPTR ((sv), "urxvt::iw")
215 214
216struct iw : perl_watcher, idle_watcher 215struct iw : perl_watcher, idle_watcher
217{ 216{
218 iw () 217 iw ()
219 : idle_watcher (this, &iw::execute) 218 : idle_watcher (this, &iw::execute)
224 { 223 {
225 invoke ("urxvt::iw", newSViw (this)); 224 invoke ("urxvt::iw", newSViw (this));
226 } 225 }
227}; 226};
228 227
229#define newSVpw(pw) new_ref (pw->self, "urxvt::pw") 228#define newSVpw(pw) new_ref ((pw)->self, "urxvt::pw")
230#define SvPW(sv) (pw *)(perl_watcher *)SvPTR (sv, "urxvt::pw") 229#define SvPW(sv) (pw *)(perl_watcher *)SvPTR ((sv), "urxvt::pw")
231 230
232struct pw : perl_watcher, child_watcher 231struct pw : perl_watcher, child_watcher
233{ 232{
234 pw () 233 pw ()
235 : child_watcher (this, &pw::execute) 234 : child_watcher (this, &pw::execute)
244 243
245///////////////////////////////////////////////////////////////////////////// 244/////////////////////////////////////////////////////////////////////////////
246 245
247#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 246#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
248 247
249struct overlay { 248class overlay {
250 HV *self;
251 bool visible;
252 rxvt_term *THIS; 249 rxvt_term *THIS;
250 AV *overlay_av;
253 int x, y, w, h; 251 int x, y, w, h;
254 int border; 252 int border;
255 text_t **text; 253 text_t **text;
256 rend_t **rend; 254 rend_t **rend;
257 255
256public:
257 HV *self;
258
258 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); 259 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
259 ~overlay (); 260 ~overlay ();
260 261
261 void show (); 262 void show ();
262 void hide (); 263 void hide ();
265 266
266 void set (int x, int y, SV *str, SV *rend); 267 void set (int x, int y, SV *str, SV *rend);
267}; 268};
268 269
269overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 270overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
270: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), visible(false) 271: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0)
271{ 272{
273 if (w < 0) w = 0;
274 if (h < 0) h = 0;
275
272 if (border == 2) 276 if (border == 2)
273 { 277 {
274 w += 2; 278 w += 2;
275 h += 2; 279 h += 2;
276 } 280 }
314 *rp++ = r; 318 *rp++ = r;
315 } 319 }
316 } 320 }
317 321
318 show (); 322 show ();
319 THIS->want_refresh = 1;
320} 323}
321 324
322overlay::~overlay () 325overlay::~overlay ()
323{ 326{
324 hide (); 327 hide ();
329 delete [] rend[y]; 332 delete [] rend[y];
330 } 333 }
331 334
332 delete [] text; 335 delete [] text;
333 delete [] rend; 336 delete [] rend;
337}
338
339void
340overlay::show ()
341{
342 if (overlay_av)
343 return;
344
345 overlay_av = (AV *)SvREFCNT_inc (SvRV (
346 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
347 ));
348 av_push (overlay_av, newSViv ((long)this));
334 349
335 THIS->want_refresh = 1; 350 THIS->want_refresh = 1;
336} 351}
337 352
338void 353void
339overlay::show () 354overlay::hide ()
340{ 355{
341 if (visible) 356 if (!overlay_av)
342 return; 357 return;
343 358
344 visible = true;
345
346 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
347 av_push (av, newSViv ((long)this));
348}
349
350void
351overlay::hide ()
352{
353 if (!visible)
354 return;
355
356 visible = false;
357
358 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
359
360 int i; 359 int i;
361 360
362 for (i = AvFILL (av); i >= 0; i--) 361 for (i = AvFILL (overlay_av); i >= 0; i--)
363 if (SvIV (*av_fetch (av, i, 1)) == (long)this) 362 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this)
364 {
365 av_delete (av, i, G_DISCARD);
366 break; 363 break;
367 }
368 364
369 for (; i < AvFILL (av); i++) 365 for (; i < AvFILL (overlay_av); i++)
370 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0))); 366 av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0)));
371 367
372 av_pop (av); 368 av_pop (overlay_av);
369
370 SvREFCNT_dec (overlay_av);
371 overlay_av = 0;
372
373 THIS->want_refresh = 1;
373} 374}
374 375
375void overlay::swap () 376void overlay::swap ()
376{ 377{
377 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 378 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
492static void 493static void
493ungrab (rxvt_term *THIS) 494ungrab (rxvt_term *THIS)
494{ 495{
495 if (THIS->perl.grabtime) 496 if (THIS->perl.grabtime)
496 { 497 {
497 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); 498 XUngrabKeyboard (THIS->dpy, THIS->perl.grabtime);
498 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 499 XUngrabPointer (THIS->dpy, THIS->perl.grabtime);
499 THIS->perl.grabtime = 0; 500 THIS->perl.grabtime = 0;
500 } 501 }
501} 502}
502 503
503bool 504bool
554 break; 555 break;
555 556
556 case DT_STR_LEN: 557 case DT_STR_LEN:
557 { 558 {
558 char *str = va_arg (ap, char *); 559 char *str = va_arg (ap, char *);
559 int len = va_arg (ap, int); 560 int len = va_arg (ap, int);
560 561
561 XPUSHs (sv_2mortal (newSVpvn (str, len))); 562 XPUSHs (sv_2mortal (newSVpvn (str, len)));
562 } 563 }
563 break; 564 break;
564 565
565 case DT_WCS_LEN: 566 case DT_WCS_LEN:
566 { 567 {
567 wchar_t *wstr = va_arg (ap, wchar_t *); 568 wchar_t *wstr = va_arg (ap, wchar_t *);
568 int wlen = va_arg (ap, int); 569 int wlen = va_arg (ap, int);
569 570
570 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 571 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
572 }
573 break;
574
575 case DT_LCS_LEN:
576 {
577 long *lstr = va_arg (ap, long *);
578 int llen = va_arg (ap, int);
579
580 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long))));
571 } 581 }
572 break; 582 break;
573 583
574 case DT_XEVENT: 584 case DT_XEVENT:
575 { 585 {
576 XEvent *xe = va_arg (ap, XEvent *); 586 XEvent *xe = va_arg (ap, XEvent *);
577 HV *hv = newHV (); 587 HV *hv = newHV ();
578 588
579# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 589# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
580# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) 590# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
581# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) 591# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
582# undef set 592# undef set
583 593
584 setiv (type, xe->type); 594 setiv (type, xe->type);
585 setiv (send_event, xe->xany.send_event); 595 setiv (send_event, xe->xany.send_event);
586 setiv (serial, xe->xany.serial); 596 setiv (serial, xe->xany.serial);
587 597
716 } 726 }
717 else if (htype == HOOK_DESTROY) 727 else if (htype == HOOK_DESTROY)
718 { 728 {
719 clearSVptr ((SV *)term->perl.self); 729 clearSVptr ((SV *)term->perl.self);
720 SvREFCNT_dec ((SV *)term->perl.self); 730 SvREFCNT_dec ((SV *)term->perl.self);
731
732 // don't allow further calls
733 term->perl.self = 0;
721 } 734 }
722 735
723 swap (perl_environ, environ); 736 swap (perl_environ, environ);
724 737
725 return event_consumed; 738 return event_consumed;
749# include "optinc.h" 762# include "optinc.h"
750# undef nodef 763# undef nodef
751# undef def 764# undef def
752 765
753 HV *stash = gv_stashpv ("urxvt", 1); 766 HV *stash = gv_stashpv ("urxvt", 1);
754 struct { 767 static const struct {
755 const char *name; 768 const char *name;
756 IV iv; 769 IV iv;
757 } *civ, const_iv[] = { 770 } *civ, const_iv[] = {
758# define const_iv(name) { # name, (IV)name } 771# define const_iv(name) { # name, (IV)name }
759 const_iv (DEFAULT_RSTYLE), 772 const_iv (DEFAULT_RSTYLE),
777 const_iv (Button2Mask), 790 const_iv (Button2Mask),
778 const_iv (Button3Mask), 791 const_iv (Button3Mask),
779 const_iv (Button4Mask), 792 const_iv (Button4Mask),
780 const_iv (Button5Mask), 793 const_iv (Button5Mask),
781 const_iv (AnyModifier), 794 const_iv (AnyModifier),
795
796 const_iv (NoSymbol),
797 const_iv (GrabModeSync),
798 const_iv (GrabModeAsync),
782 799
783 const_iv (EVENT_NONE), 800 const_iv (EVENT_NONE),
784 const_iv (EVENT_READ), 801 const_iv (EVENT_READ),
785 const_iv (EVENT_WRITE), 802 const_iv (EVENT_WRITE),
786 803
842 const_iv (SelectionRequest), 859 const_iv (SelectionRequest),
843 const_iv (SelectionNotify), 860 const_iv (SelectionNotify),
844 const_iv (ColormapNotify), 861 const_iv (ColormapNotify),
845 const_iv (ClientMessage), 862 const_iv (ClientMessage),
846 const_iv (MappingNotify), 863 const_iv (MappingNotify),
864# if ENABLE_XIM_ONTHESPOT
865 const_iv (XIMReverse),
866 const_iv (XIMUnderline),
867 const_iv (XIMHighlight),
868 const_iv (XIMPrimary),
869 const_iv (XIMSecondary),
870 const_iv (XIMTertiary),
871 const_iv (XIMVisibleToForward),
872 const_iv (XIMVisibleToBackword),
873 const_iv (XIMVisibleToCenter),
874# if 0
875 const_iv (XIMForwardChar),
876 const_iv (XIMBackwardChar),
877 const_iv (XIMForwardWord),
878 const_iv (XIMBackwardWord),
879 const_iv (XIMCaretUp),
880 const_iv (XIMCaretDown),
881 const_iv (XIMNextLine),
882 const_iv (XIMPreviousLine),
883 const_iv (XIMLineStart),
884 const_iv (XIMLineEnd),
885 const_iv (XIMAbsolutePosition),
886 const_iv (XIMDontChange),
887# endif
888# endif
847 }; 889 };
848 890
849 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); 891 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
850 civ-- > const_iv; )
851 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 892 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
852} 893}
853 894
854void 895void
855warn (const char *msg) 896warn (const char *msg)
886 RETVAL 927 RETVAL
887 928
888int 929int
889SET_FGCOLOR (int rend, int new_color) 930SET_FGCOLOR (int rend, int new_color)
890 CODE: 931 CODE:
891 RETVAL = SET_FGCOLOR (rend, new_color); 932 RETVAL = SET_FGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
892 OUTPUT: 933 OUTPUT:
893 RETVAL 934 RETVAL
894 935
895int 936int
896SET_BGCOLOR (int rend, int new_color) 937SET_BGCOLOR (int rend, int new_color)
897 CODE: 938 CODE:
898 RETVAL = SET_BGCOLOR (rend, new_color); 939 RETVAL = SET_BGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
899 OUTPUT: 940 OUTPUT:
900 RETVAL 941 RETVAL
901 942
902int 943int
903GET_CUSTOM (int rend) 944GET_CUSTOM (int rend)
917 | ((new_value << RS_customShift) & RS_customMask); 958 | ((new_value << RS_customShift) & RS_customMask);
918} 959}
919 OUTPUT: 960 OUTPUT:
920 RETVAL 961 RETVAL
921 962
963void
964termlist ()
965 PPCODE:
966{
967 EXTEND (SP, rxvt_term::termlist.size ());
968
969 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
970 if ((*t)->perl.self)
971 PUSHs (sv_2mortal (newSVterm (*t)));
972}
973
922MODULE = urxvt PACKAGE = urxvt::term 974MODULE = urxvt PACKAGE = urxvt::term
923 975
924SV * 976SV *
925_new (...) 977_new (AV *env, AV *arg)
926 CODE: 978 CODE:
927{ 979{
928 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
929 croak ("first argument to urxvt::term->_new must be arrayref");
930
931 rxvt_term *term = new rxvt_term; 980 rxvt_term *term = new rxvt_term;
932 981
933 term->argv = new stringvec; 982 stringvec *argv = new stringvec;
934 term->envv = new stringvec; 983 stringvec *envv = new stringvec;
935 984
936 for (int i = 1; i < items; i++) 985 for (int i = 0; i <= AvFILL (arg); i++)
937 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 986 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
938 987
939 AV *envv = (AV *)SvRV (ST (0));
940 for (int i = AvFILL (envv) + 1; i--; ) 988 for (int i = AvFILL (env) + 1; i--; )
941 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 989 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
942 990
943 term->envv->push_back (0); 991 envv->push_back (0);
944 992
945 bool success; 993 bool success;
946 994
947 try 995 try
948 { 996 {
949 success = term->init (term->argv->size (), term->argv->begin ()); 997 success = term->init (argv, envv);
950 } 998 }
951 catch (const class rxvt_failure_exception &e) 999 catch (const class rxvt_failure_exception &e)
952 { 1000 {
953 success = false; 1001 success = false;
954 } 1002 }
971void 1019void
972rxvt_term::set_should_invoke (int htype, int inc) 1020rxvt_term::set_should_invoke (int htype, int inc)
973 CODE: 1021 CODE:
974 THIS->perl.should_invoke [htype] += inc; 1022 THIS->perl.should_invoke [htype] += inc;
975 1023
976void 1024int
977rxvt_term::grab_button (int button, U32 modifiers) 1025rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt)
978 CODE: 1026 CODE:
979 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 1027 RETVAL = XGrabButton (THIS->dpy, button, modifiers, window, 1,
980 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1028 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
981 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 1029 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
1030 OUTPUT: RETVAL
1031
1032int
1033rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt)
1034 CODE:
1035 RETVAL = XUngrabButton (THIS->dpy, button, modifiers, window);
1036 OUTPUT: RETVAL
1037
1038void
1039rxvt_term::XGrabKey (int keycode, U32 modifiers, Window window = THIS->vt, \
1040 int owner_events = 1, int pointer_mode = GrabModeAsync, int keyboard_mode = GrabModeAsync)
1041 CODE:
1042 XGrabKey (THIS->dpy, keycode, modifiers, window, owner_events, pointer_mode, keyboard_mode);
1043
1044void
1045rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt)
1046 CODE:
1047 XUngrabKey (THIS->dpy, keycode, modifiers, window);
1048
1049void
1050rxvt_term::XUngrabKeyboard (Time eventtime)
1051 CODE:
1052 XUngrabKeyboard (THIS->dpy, eventtime);
982 1053
983bool 1054bool
984rxvt_term::grab (Time eventtime, int sync = 0) 1055rxvt_term::grab (Time eventtime, int sync = 0)
985 CODE: 1056 CODE:
986{ 1057{
987 int mode = sync ? GrabModeSync : GrabModeAsync; 1058 int mode = sync ? GrabModeSync : GrabModeAsync;
988 1059
989 THIS->perl.grabtime = 0; 1060 THIS->perl.grabtime = 0;
990 1061
991 if (!XGrabPointer (THIS->display->display, THIS->vt, 0, 1062 if (!XGrabPointer (THIS->dpy, THIS->vt, 0,
992 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1063 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
993 mode, mode, None, GRAB_CURSOR, eventtime)) 1064 mode, mode, None, GRAB_CURSOR, eventtime))
994 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) 1065 if (!XGrabKeyboard (THIS->dpy, THIS->vt, 0, mode, mode, eventtime))
995 THIS->perl.grabtime = eventtime; 1066 THIS->perl.grabtime = eventtime;
996 else 1067 else
997 XUngrabPointer (THIS->display->display, eventtime); 1068 XUngrabPointer (THIS->dpy, eventtime);
998 1069
999 RETVAL = !!THIS->perl.grabtime; 1070 RETVAL = !!THIS->perl.grabtime;
1000} 1071}
1001 OUTPUT: 1072 OUTPUT:
1002 RETVAL 1073 RETVAL
1003 1074
1004void 1075void
1005rxvt_term::allow_events_async () 1076rxvt_term::allow_events_async ()
1006 CODE: 1077 CODE:
1007 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); 1078 XAllowEvents (THIS->dpy, AsyncBoth, THIS->perl.grabtime);
1008 1079
1009void 1080void
1010rxvt_term::allow_events_sync () 1081rxvt_term::allow_events_sync ()
1011 CODE: 1082 CODE:
1012 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); 1083 XAllowEvents (THIS->dpy, SyncBoth, THIS->perl.grabtime);
1013 1084
1014void 1085void
1015rxvt_term::allow_events_replay () 1086rxvt_term::allow_events_replay ()
1016 CODE: 1087 CODE:
1017 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); 1088 XAllowEvents (THIS->dpy, ReplayPointer, THIS->perl.grabtime);
1018 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); 1089 XAllowEvents (THIS->dpy, ReplayKeyboard, THIS->perl.grabtime);
1019 1090
1020void 1091void
1021rxvt_term::ungrab () 1092rxvt_term::ungrab ()
1022 CODE: 1093 CODE:
1023 ungrab (THIS); 1094 ungrab (THIS);
1095
1096int
1097rxvt_term::XStringToKeysym (char *string)
1098 CODE:
1099 RETVAL = XStringToKeysym (string);
1100 OUTPUT: RETVAL
1101
1102char *
1103rxvt_term::XKeysymToString (int sym)
1104 CODE:
1105 RETVAL = XKeysymToString (sym);
1106 OUTPUT: RETVAL
1107
1108int
1109rxvt_term::XKeysymToKeycode (int sym)
1110 CODE:
1111 RETVAL = XKeysymToKeycode (THIS->dpy, sym);
1112 OUTPUT: RETVAL
1113
1114int
1115rxvt_term::XKeycodeToKeysym (int code, int index)
1116 CODE:
1117 RETVAL = XKeycodeToKeysym (THIS->dpy, code, index);
1118 OUTPUT: RETVAL
1024 1119
1025int 1120int
1026rxvt_term::strwidth (SV *str) 1121rxvt_term::strwidth (SV *str)
1027 CODE: 1122 CODE:
1028{ 1123{
1029 wchar_t *wstr = sv2wcs (str); 1124 wchar_t *wstr = sv2wcs (str);
1030 1125
1031 rxvt_push_locale (THIS->locale); 1126 rxvt_push_locale (THIS->locale);
1127 //TODO: use same algorithm as screen.C
1032 RETVAL = wcswidth (wstr, wcslen (wstr)); 1128 RETVAL = wcswidth (wstr, wcslen (wstr));
1033 rxvt_pop_locale (); 1129 rxvt_pop_locale ();
1034 1130
1035 free (wstr); 1131 free (wstr);
1036} 1132}
1146 } 1242 }
1147 OUTPUT: 1243 OUTPUT:
1148 RETVAL 1244 RETVAL
1149 1245
1150SV * 1246SV *
1151rxvt_term::_env () 1247rxvt_term::envv ()
1248 ALIAS:
1249 argv = 1
1152 CODE: 1250 PPCODE:
1153{ 1251{
1154 if (THIS->envv) 1252 stringvec *vec = ix ? THIS->argv : THIS->envv;
1155 {
1156 AV *av = newAV ();
1157 1253
1254 EXTEND (SP, vec->size ());
1255
1158 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) 1256 for (char **i = vec->begin (); i != vec->end (); ++i)
1159 if (*i) 1257 if (*i)
1160 av_push (av, newSVpv (*i, 0)); 1258 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1161
1162 RETVAL = newRV_noinc ((SV *)av);
1163 }
1164 else
1165 RETVAL = &PL_sv_undef;
1166} 1259}
1167 OUTPUT:
1168 RETVAL
1169 1260
1170int 1261int
1171rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1262rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1172 CODE: 1263 CODE:
1173 RETVAL = THIS->pty_ev.events; 1264 RETVAL = THIS->pty_ev.events;
1174 if (events != EVENT_UNDEF) 1265 if (events != EVENT_UNDEF)
1175 THIS->pty_ev.set (events); 1266 THIS->pty_ev.set (events);
1176 OUTPUT: 1267 OUTPUT:
1177 RETVAL 1268 RETVAL
1178 1269
1270int
1271rxvt_term::pty_fd ()
1272 CODE:
1273 RETVAL = THIS->pty->pty;
1274 OUTPUT:
1275 RETVAL
1276
1179Window 1277Window
1180rxvt_term::parent () 1278rxvt_term::parent ()
1181 CODE: 1279 CODE:
1182 RETVAL = THIS->parent [0]; 1280 RETVAL = THIS->parent [0];
1183 OUTPUT: 1281 OUTPUT:
1222 1320
1223void 1321void
1224rxvt_term::focus_out () 1322rxvt_term::focus_out ()
1225 1323
1226void 1324void
1325rxvt_term::key_press (unsigned int state, unsigned int keycode, Time time = CurrentTime)
1326 ALIAS:
1327 key_release = 1
1328 CODE:
1329{
1330 XKeyEvent xkey;
1331
1332 memset (&xkey, 0, sizeof (xkey));
1333
1334 xkey.time = time;
1335 xkey.state = state;
1336 xkey.keycode = keycode;
1337
1338 xkey.type = ix ? KeyRelease : KeyPress;
1339 xkey.display = THIS->dpy;
1340 xkey.window = THIS->vt;
1341 xkey.root = THIS->display->root;
1342 xkey.subwindow = THIS->vt;
1343
1344 if (ix)
1345 THIS->key_release (xkey);
1346 else
1347 THIS->key_press (xkey);
1348}
1349
1350void
1227rxvt_term::want_refresh () 1351rxvt_term::want_refresh ()
1228 CODE: 1352 CODE:
1229 THIS->want_refresh = 1; 1353 THIS->want_refresh = 1;
1230 1354
1231void 1355void
1237 1361
1238 line_t &l = ROW(row_number); 1362 line_t &l = ROW(row_number);
1239 1363
1240 if (GIMME_V != G_VOID) 1364 if (GIMME_V != G_VOID)
1241 { 1365 {
1242 wchar_t *wstr = new wchar_t [THIS->ncol]; 1366 wchar_t *wstr = rxvt_temp_buf<wchar_t> (THIS->ncol);
1243 1367
1244 for (int col = 0; col < THIS->ncol; col++) 1368 for (int col = 0; col < THIS->ncol; col++)
1245 wstr [col] = l.t [col]; 1369 wstr [col] = l.t [col];
1246 1370
1247 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1371 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1248
1249 delete [] wstr;
1250 } 1372 }
1251 1373
1252 if (new_text) 1374 if (new_text)
1253 { 1375 {
1254 wchar_t *wstr = sv2wcs (new_text); 1376 wchar_t *wstr = sv2wcs (new_text);
1347rxvt_term::special_encode (SV *string) 1469rxvt_term::special_encode (SV *string)
1348 CODE: 1470 CODE:
1349{ 1471{
1350 wchar_t *wstr = sv2wcs (string); 1472 wchar_t *wstr = sv2wcs (string);
1351 int wlen = wcslen (wstr); 1473 int wlen = wcslen (wstr);
1352 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer 1474 wchar_t *rstr = rxvt_temp_buf<wchar_t> (wlen * 2); // cannot become longer
1353 1475
1354 rxvt_push_locale (THIS->locale); 1476 rxvt_push_locale (THIS->locale);
1355 1477
1356 wchar_t *r = rstr; 1478 wchar_t *r = rstr;
1357 for (wchar_t *s = wstr; *s; s++) 1479 for (wchar_t *s = wstr; *s; s++)
1480 {
1481 int w = WCWIDTH (*s);
1482
1358 if (wcwidth (*s) == 0) 1483 if (w == 0)
1359 { 1484 {
1360 if (r == rstr) 1485 if (r == rstr)
1361 croak ("leading combining character unencodable"); 1486 croak ("leading combining character unencodable");
1362 1487
1363 unicode_t n = rxvt_compose (r[-1], *s); 1488 unicode_t n = rxvt_compose (r[-1], *s);
1364 if (n == NOCHAR) 1489 if (n == NOCHAR)
1365 n = rxvt_composite.compose (r[-1], *s); 1490 n = rxvt_composite.compose (r[-1], *s);
1366 1491
1367 r[-1] = n; 1492 r[-1] = n;
1368 } 1493 }
1369#if !UNICODE_3 1494#if !UNICODE_3
1370 else if (*s >= 0x10000) 1495 else if (*s >= 0x10000)
1371 *r++ = rxvt_composite.compose (*s); 1496 *r++ = rxvt_composite.compose (*s);
1372#endif 1497#endif
1373 else 1498 else
1374 *r++ = *s; 1499 *r++ = *s;
1500
1501 // the *2 above only allows wcwidth <= 2
1502 if (w > 1)
1503 *r++ = NOCHAR;
1504 }
1375 1505
1376 rxvt_pop_locale (); 1506 rxvt_pop_locale ();
1377 1507
1378 RETVAL = wcs2sv (rstr, r - rstr); 1508 RETVAL = wcs2sv (rstr, r - rstr);
1379
1380 delete [] rstr;
1381} 1509}
1382 OUTPUT: 1510 OUTPUT:
1383 RETVAL 1511 RETVAL
1384 1512
1385SV * 1513SV *
1397 else if (IS_COMPOSE (*s)) 1525 else if (IS_COMPOSE (*s))
1398 dlen += rxvt_composite.expand (*s, 0); 1526 dlen += rxvt_composite.expand (*s, 0);
1399 else 1527 else
1400 dlen++; 1528 dlen++;
1401 1529
1402 wchar_t *rstr = new wchar_t [dlen]; 1530 wchar_t *rstr = rxvt_temp_buf<wchar_t> (dlen);
1403 1531
1404 // decode 1532 // decode
1405 wchar_t *r = rstr; 1533 wchar_t *r = rstr;
1406 for (wchar_t *s = wstr; *s; s++) 1534 for (wchar_t *s = wstr; *s; s++)
1407 if (*s == NOCHAR) 1535 if (*s == NOCHAR)
1410 r += rxvt_composite.expand (*s, r); 1538 r += rxvt_composite.expand (*s, r);
1411 else 1539 else
1412 *r++ = *s; 1540 *r++ = *s;
1413 1541
1414 RETVAL = wcs2sv (rstr, r - rstr); 1542 RETVAL = wcs2sv (rstr, r - rstr);
1415
1416 delete [] rstr;
1417} 1543}
1418 OUTPUT: 1544 OUTPUT:
1419 RETVAL 1545 RETVAL
1420 1546
1421void 1547void
1422rxvt_term::_resource (char *name, int index, SV *newval = 0) 1548rxvt_term::_resource (char *name, int index, SV *newval = 0)
1423 PPCODE: 1549 PPCODE:
1424{ 1550{
1425 struct resval { const char *name; int value; } rslist [] = { 1551 static const struct resval { const char *name; int value; } *rs, rslist [] = {
1426# define def(name) { # name, Rs_ ## name }, 1552# define def(name) { # name, Rs_ ## name },
1427# define reserve(name,count) 1553# define reserve(name,count)
1428# include "rsinc.h" 1554# include "rsinc.h"
1429# undef def 1555# undef def
1430# undef reserve 1556# undef reserve
1431 }; 1557 };
1432 1558
1433 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1559 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1434 1560
1435 do { 1561 do {
1436 if (rs-- == rslist) 1562 if (rs-- == rslist)
1437 croak ("no such resource '%s', requested", name); 1563 croak ("no such resource '%s', requested", name);
1438 } while (strcmp (name, rs->name)); 1564 } while (strcmp (name, rs->name));
1531 if (items == 3) 1657 if (items == 3)
1532 { 1658 {
1533 rc.row = SvIV (ST (1)); 1659 rc.row = SvIV (ST (1));
1534 rc.col = SvIV (ST (2)); 1660 rc.col = SvIV (ST (2));
1535 1661
1536 if (ix == 2 && rc.col == 0) 1662 if (ix == 2)
1537 { 1663 {
1664 if (rc.col == 0)
1665 {
1666 // col == 0 means end of previous line
1538 rc.row--; 1667 rc.row--;
1539 rc.col = THIS->ncol; 1668 rc.col = THIS->ncol;
1669 }
1670 else if (IN_RANGE_EXC (rc.row, THIS->top_row, THIS->nrow)
1671 && rc.col > ROW(rc.row).l)
1672 {
1673 // col >= length means while line and add newline
1674 rc.col = THIS->ncol;
1675 }
1540 } 1676 }
1541 1677
1542 clamp_it (rc.col, 0, THIS->ncol); 1678 clamp_it (rc.col, 0, THIS->ncol);
1543 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1679 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1544 1680
1552 CODE: 1688 CODE:
1553 RETVAL = THIS->charsets [THIS->screen.charset]; 1689 RETVAL = THIS->charsets [THIS->screen.charset];
1554 OUTPUT: 1690 OUTPUT:
1555 RETVAL 1691 RETVAL
1556 1692
1557#void 1693void
1558#rxvt_term::selection_clear () 1694rxvt_term::selection_clear ()
1559 1695
1560void 1696void
1561rxvt_term::selection_make (Time eventtime, bool rect = false) 1697rxvt_term::selection_make (Time eventtime, bool rect = false)
1562 CODE: 1698 CODE:
1563 THIS->selection.op = SELECTION_CONT; 1699 THIS->selection.op = SELECTION_CONT;
1653void 1789void
1654rxvt_term::XListProperties (Window window) 1790rxvt_term::XListProperties (Window window)
1655 PPCODE: 1791 PPCODE:
1656{ 1792{
1657 int count; 1793 int count;
1658 Atom *props = XListProperties (THIS->display->display, window, &count); 1794 Atom *props = XListProperties (THIS->dpy, window, &count);
1659 1795
1660 EXTEND (SP, count); 1796 EXTEND (SP, count);
1661 while (count--) 1797 while (count--)
1662 PUSHs (newSVuv ((U32)props [count])); 1798 PUSHs (newSVuv ((U32)props [count]));
1663 1799
1672 int format; 1808 int format;
1673 unsigned long nitems; 1809 unsigned long nitems;
1674 unsigned long bytes_after; 1810 unsigned long bytes_after;
1675 unsigned char *prop; 1811 unsigned char *prop;
1676 1812
1677 XGetWindowProperty (THIS->display->display, window, property, 1813 XGetWindowProperty (THIS->dpy, window, property,
1678 0, 1<<24, 0, AnyPropertyType, 1814 0, 1<<24, 0, AnyPropertyType,
1679 &type, &format, &nitems, &bytes_after, &prop); 1815 &type, &format, &nitems, &bytes_after, &prop);
1680 1816
1681 if (type != None) 1817 if (type != None)
1682 { 1818 {
1701 1837
1702 int elemsize = format == 16 ? sizeof (short) 1838 int elemsize = format == 16 ? sizeof (short)
1703 : format == 32 ? sizeof (long) 1839 : format == 32 ? sizeof (long)
1704 : 1; 1840 : 1;
1705 1841
1706 XChangeProperty (THIS->display->display, window, property, 1842 XChangeProperty (THIS->dpy, window, property,
1707 type, format, PropModeReplace, 1843 type, format, PropModeReplace,
1708 (unsigned char *)data_, len / elemsize); 1844 (unsigned char *)data_, len / elemsize);
1709 XSync (THIS->display->display, 0);
1710} 1845}
1711 1846
1712Atom 1847Atom
1713XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE) 1848XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1714 C_ARGS: term->display->display, atom_name, only_if_exists 1849 C_ARGS: term->dpy, atom_name, only_if_exists
1715 1850
1716char * 1851char *
1717XGetAtomName (rxvt_term *term, Atom atom) 1852XGetAtomName (rxvt_term *term, Atom atom)
1718 C_ARGS: term->display->display, atom 1853 C_ARGS: term->dpy, atom
1719 CLEANUP: 1854 CLEANUP:
1720 XFree (RETVAL); 1855 XFree (RETVAL);
1721 1856
1722void 1857void
1723XDeleteProperty (rxvt_term *term, Window window, Atom property) 1858XDeleteProperty (rxvt_term *term, Window window, Atom property)
1724 C_ARGS: term->display->display, window, property 1859 C_ARGS: term->dpy, window, property
1725 1860
1726Window 1861Window
1727rxvt_term::DefaultRootWindow () 1862rxvt_term::DefaultRootWindow ()
1728 CODE: 1863 CODE:
1729 RETVAL = THIS->display->root; 1864 RETVAL = THIS->display->root;
1732 1867
1733#if 0 1868#if 0
1734 1869
1735Window 1870Window
1736XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height) 1871XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1737 C_ARGS: term->display->display, (Window)parent, 1872 C_ARGS: term->dpy, (Window)parent,
1738 x, y, width, height, 0, 1873 x, y, width, height, 0,
1739 term->pix_colors_focused[Color_border], 1874 term->pix_colors_focused[Color_border],
1740 term->pix_colors_focused[Color_border] 1875 term->pix_colors_focused[Color_border]
1741 1876
1742#endif 1877#endif
1743 1878
1744void 1879void
1745XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0) 1880XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1746 C_ARGS: term->display->display, window, parent, x, y 1881 C_ARGS: term->dpy, window, parent, x, y
1747 1882
1748void 1883void
1749XMapWindow (rxvt_term *term, Window window) 1884XMapWindow (rxvt_term *term, Window window)
1750 C_ARGS: term->display->display, window 1885 C_ARGS: term->dpy, window
1751 1886
1752void 1887void
1753XUnmapWindow (rxvt_term *term, Window window) 1888XUnmapWindow (rxvt_term *term, Window window)
1754 C_ARGS: term->display->display, window 1889 C_ARGS: term->dpy, window
1755 1890
1756void 1891void
1757XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height) 1892XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1758 C_ARGS: term->display->display, window, x, y, width, height 1893 C_ARGS: term->dpy, window, x, y, width, height
1759 1894
1760void 1895void
1761rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0) 1896rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0)
1762 CODE: 1897 CODE:
1763{ 1898{
1764 XWindowAttributes attr; 1899 XWindowAttributes attr;
1765 XGetWindowAttributes (THIS->display->display, window, &attr); 1900 XGetWindowAttributes (THIS->dpy, window, &attr);
1766 XSelectInput (THIS->display->display, window, attr.your_event_mask | add_events & ~del_events); 1901 XSelectInput (THIS->dpy, window, attr.your_event_mask | add_events & ~del_events);
1767} 1902}
1768 1903
1769void 1904void
1770rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y) 1905rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y)
1771 PPCODE: 1906 PPCODE:
1772{ 1907{
1773 int dx, dy; 1908 int dx, dy;
1774 Window child; 1909 Window child;
1775 1910
1776 if (XTranslateCoordinates (THIS->display->display, src, dst, x, y, &dx, &dy, &child)) 1911 if (XTranslateCoordinates (THIS->dpy, src, dst, x, y, &dx, &dy, &child))
1777 { 1912 {
1778 EXTEND (SP, 3); 1913 EXTEND (SP, 3);
1779 PUSHs (newSViv (dx)); 1914 PUSHs (newSViv (dx));
1780 PUSHs (newSViv (dy)); 1915 PUSHs (newSViv (dy));
1781 PUSHs (newSVuv (child)); 1916 PUSHs (newSVuv (child));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines