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.82 by root, Fri Jan 20 14:41:07 2006 UTC vs.
Revision 1.97 by root, Sat Feb 4 16:12:48 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{
272 if (border == 2) 273 if (border == 2)
273 { 274 {
274 w += 2; 275 w += 2;
275 h += 2; 276 h += 2;
314 *rp++ = r; 315 *rp++ = r;
315 } 316 }
316 } 317 }
317 318
318 show (); 319 show ();
319 THIS->want_refresh = 1;
320} 320}
321 321
322overlay::~overlay () 322overlay::~overlay ()
323{ 323{
324 hide (); 324 hide ();
329 delete [] rend[y]; 329 delete [] rend[y];
330 } 330 }
331 331
332 delete [] text; 332 delete [] text;
333 delete [] rend; 333 delete [] rend;
334}
335
336void
337overlay::show ()
338{
339 if (overlay_av)
340 return;
341
342 overlay_av = (AV *)SvREFCNT_inc (SvRV (
343 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
344 ));
345 av_push (overlay_av, newSViv ((long)this));
334 346
335 THIS->want_refresh = 1; 347 THIS->want_refresh = 1;
336} 348}
337 349
338void 350void
339overlay::show () 351overlay::hide ()
340{ 352{
341 if (visible) 353 if (!overlay_av)
342 return; 354 return;
343 355
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; 356 int i;
361 357
362 for (i = AvFILL (av); i >= 0; i--) 358 for (i = AvFILL (overlay_av); i >= 0; i--)
363 if (SvIV (*av_fetch (av, i, 1)) == (long)this) 359 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this)
364 { 360 {
365 av_delete (av, i, G_DISCARD); 361 av_delete (overlay_av, i, G_DISCARD);
366 break; 362 break;
367 } 363 }
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
596 setuv (root, xe->xmotion.root); 606 setuv (root, xe->xmotion.root);
597 setuv (subwindow, xe->xmotion.subwindow); 607 setuv (subwindow, xe->xmotion.subwindow);
598 setuv (time, xe->xmotion.time); 608 setuv (time, xe->xmotion.time);
599 setiv (x, xe->xmotion.x); 609 setiv (x, xe->xmotion.x);
600 setiv (y, xe->xmotion.y); 610 setiv (y, xe->xmotion.y);
601 setiv (row, xe->xmotion.y / term->fheight); 611 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
602 setiv (col, xe->xmotion.x / term->fwidth); 612 setiv (col, xe->xmotion.x / term->fwidth);
603 setiv (x_root, xe->xmotion.x_root); 613 setiv (x_root, xe->xmotion.x_root);
604 setiv (y_root, xe->xmotion.y_root); 614 setiv (y_root, xe->xmotion.y_root);
605 setuv (state, xe->xmotion.state); 615 setuv (state, xe->xmotion.state);
606 616
640 break; 650 break;
641 } 651 }
642 652
643 break; 653 break;
644 654
655 case PropertyNotify:
656 setuv (window, xe->xproperty.window);
657 setuv (atom, xe->xproperty.atom);
658 setuv (time, xe->xproperty.time);
659 setiv (state, xe->xproperty.state);
660 break;
661
645 case ClientMessage: 662 case ClientMessage:
646 setuv (window, xe->xclient.window); 663 setuv (window, xe->xclient.window);
647 setuv (message_type, xe->xclient.message_type); 664 setuv (message_type, xe->xclient.message_type);
648 setuv (format, xe->xclient.format); 665 setuv (format, xe->xclient.format);
649 setuv (l0, xe->xclient.data.l[0]); 666 setuv (l0, xe->xclient.data.l[0]);
650 setuv (l1, xe->xclient.data.l[1]); 667 setuv (l1, xe->xclient.data.l[1]);
651 setuv (l2, xe->xclient.data.l[2]); 668 setuv (l2, xe->xclient.data.l[2]);
652 setuv (l3, xe->xclient.data.l[3]); 669 setuv (l3, xe->xclient.data.l[3]);
653 setuv (l4, xe->xclient.data.l[4]); 670 setuv (l4, xe->xclient.data.l[4]);
671 break;
654 } 672 }
655 673
656 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 674 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
657 } 675 }
658 break; 676 break;
708 } 726 }
709 else if (htype == HOOK_DESTROY) 727 else if (htype == HOOK_DESTROY)
710 { 728 {
711 clearSVptr ((SV *)term->perl.self); 729 clearSVptr ((SV *)term->perl.self);
712 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;
713 } 734 }
714 735
715 swap (perl_environ, environ); 736 swap (perl_environ, environ);
716 737
717 return event_consumed; 738 return event_consumed;
741# include "optinc.h" 762# include "optinc.h"
742# undef nodef 763# undef nodef
743# undef def 764# undef def
744 765
745 HV *stash = gv_stashpv ("urxvt", 1); 766 HV *stash = gv_stashpv ("urxvt", 1);
746 struct { 767 static const struct {
747 const char *name; 768 const char *name;
748 IV iv; 769 IV iv;
749 } *civ, const_iv[] = { 770 } *civ, const_iv[] = {
750# define const_iv(name) { # name, (IV)name } 771# define const_iv(name) { # name, (IV)name }
751 const_iv (DEFAULT_RSTYLE), 772 const_iv (DEFAULT_RSTYLE),
834 const_iv (SelectionRequest), 855 const_iv (SelectionRequest),
835 const_iv (SelectionNotify), 856 const_iv (SelectionNotify),
836 const_iv (ColormapNotify), 857 const_iv (ColormapNotify),
837 const_iv (ClientMessage), 858 const_iv (ClientMessage),
838 const_iv (MappingNotify), 859 const_iv (MappingNotify),
860# if ENABLE_XIM_ONTHESPOT
861 const_iv (XIMReverse),
862 const_iv (XIMUnderline),
863 const_iv (XIMHighlight),
864 const_iv (XIMPrimary),
865 const_iv (XIMSecondary),
866 const_iv (XIMTertiary),
867 const_iv (XIMVisibleToForward),
868 const_iv (XIMVisibleToBackword),
869 const_iv (XIMVisibleToCenter),
870# if 0
871 const_iv (XIMForwardChar),
872 const_iv (XIMBackwardChar),
873 const_iv (XIMForwardWord),
874 const_iv (XIMBackwardWord),
875 const_iv (XIMCaretUp),
876 const_iv (XIMCaretDown),
877 const_iv (XIMNextLine),
878 const_iv (XIMPreviousLine),
879 const_iv (XIMLineStart),
880 const_iv (XIMLineEnd),
881 const_iv (XIMAbsolutePosition),
882 const_iv (XIMDontChange),
883# endif
884# endif
839 }; 885 };
840 886
841 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); 887 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
842 civ-- > const_iv; )
843 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 888 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
844} 889}
845 890
846void 891void
847warn (const char *msg) 892warn (const char *msg)
909 | ((new_value << RS_customShift) & RS_customMask); 954 | ((new_value << RS_customShift) & RS_customMask);
910} 955}
911 OUTPUT: 956 OUTPUT:
912 RETVAL 957 RETVAL
913 958
959void
960termlist ()
961 PPCODE:
962{
963 EXTEND (SP, rxvt_term::termlist.size ());
964
965 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
966 if ((*t)->perl.self)
967 PUSHs (sv_2mortal (newSVterm (*t)));
968}
969
914MODULE = urxvt PACKAGE = urxvt::term 970MODULE = urxvt PACKAGE = urxvt::term
915 971
916SV * 972SV *
917_new (...) 973_new (AV *env, AV *arg)
918 CODE: 974 CODE:
919{ 975{
920 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
921 croak ("first argument to urxvt::term->_new must be arrayref");
922
923 rxvt_term *term = new rxvt_term; 976 rxvt_term *term = new rxvt_term;
924 977
925 term->argv = new stringvec; 978 stringvec *argv = new stringvec;
926 term->envv = new stringvec; 979 stringvec *envv = new stringvec;
927 980
928 for (int i = 1; i < items; i++) 981 for (int i = 0; i <= AvFILL (arg); i++)
929 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 982 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
930 983
931 AV *envv = (AV *)SvRV (ST (0));
932 for (int i = AvFILL (envv) + 1; i--; ) 984 for (int i = AvFILL (env) + 1; i--; )
933 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 985 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
934 986
935 term->envv->push_back (0); 987 envv->push_back (0);
936 988
937 bool success; 989 bool success;
938 990
939 try 991 try
940 { 992 {
941 success = term->init (term->argv->size (), term->argv->begin ()); 993 success = term->init (argv, envv);
942 } 994 }
943 catch (const class rxvt_failure_exception &e) 995 catch (const class rxvt_failure_exception &e)
944 { 996 {
945 success = false; 997 success = false;
946 } 998 }
964rxvt_term::set_should_invoke (int htype, int inc) 1016rxvt_term::set_should_invoke (int htype, int inc)
965 CODE: 1017 CODE:
966 THIS->perl.should_invoke [htype] += inc; 1018 THIS->perl.should_invoke [htype] += inc;
967 1019
968void 1020void
969rxvt_term::grab_button (int button, U32 modifiers) 1021rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt)
970 CODE: 1022 CODE:
971 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 1023 XGrabButton (THIS->dpy, button, modifiers, window, 1,
972 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1024 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
973 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 1025 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
974 1026
1027void
1028rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt)
1029 CODE:
1030 XUngrabButton (THIS->dpy, button, modifiers, window);
1031
1032#if 0
1033
1034void
1035XGrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt)
1036 C_ARGS:
1037 THIS->dpy, keycode, modifiers, window, 1,
1038 GrabModeSync, GrabModeSync
1039
1040void
1041XUngrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt)
1042 C_ARGS: THIS->dpy, keycode, modifiers, window
1043
1044#endif
1045
975bool 1046bool
976rxvt_term::grab (Time eventtime, int sync = 0) 1047rxvt_term::grab (Time eventtime, int sync = 0)
977 CODE: 1048 CODE:
978{ 1049{
979 int mode = sync ? GrabModeSync : GrabModeAsync; 1050 int mode = sync ? GrabModeSync : GrabModeAsync;
980 1051
981 THIS->perl.grabtime = 0; 1052 THIS->perl.grabtime = 0;
982 1053
983 if (!XGrabPointer (THIS->display->display, THIS->vt, 0, 1054 if (!XGrabPointer (THIS->dpy, THIS->vt, 0,
984 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1055 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
985 mode, mode, None, GRAB_CURSOR, eventtime)) 1056 mode, mode, None, GRAB_CURSOR, eventtime))
986 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) 1057 if (!XGrabKeyboard (THIS->dpy, THIS->vt, 0, mode, mode, eventtime))
987 THIS->perl.grabtime = eventtime; 1058 THIS->perl.grabtime = eventtime;
988 else 1059 else
989 XUngrabPointer (THIS->display->display, eventtime); 1060 XUngrabPointer (THIS->dpy, eventtime);
990 1061
991 RETVAL = !!THIS->perl.grabtime; 1062 RETVAL = !!THIS->perl.grabtime;
992} 1063}
993 OUTPUT: 1064 OUTPUT:
994 RETVAL 1065 RETVAL
995 1066
996void 1067void
997rxvt_term::allow_events_async () 1068rxvt_term::allow_events_async ()
998 CODE: 1069 CODE:
999 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); 1070 XAllowEvents (THIS->dpy, AsyncBoth, THIS->perl.grabtime);
1000 1071
1001void 1072void
1002rxvt_term::allow_events_sync () 1073rxvt_term::allow_events_sync ()
1003 CODE: 1074 CODE:
1004 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); 1075 XAllowEvents (THIS->dpy, SyncBoth, THIS->perl.grabtime);
1005 1076
1006void 1077void
1007rxvt_term::allow_events_replay () 1078rxvt_term::allow_events_replay ()
1008 CODE: 1079 CODE:
1009 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); 1080 XAllowEvents (THIS->dpy, ReplayPointer, THIS->perl.grabtime);
1010 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); 1081 XAllowEvents (THIS->dpy, ReplayKeyboard, THIS->perl.grabtime);
1011 1082
1012void 1083void
1013rxvt_term::ungrab () 1084rxvt_term::ungrab ()
1014 CODE: 1085 CODE:
1015 ungrab (THIS); 1086 ungrab (THIS);
1109rxvt_term::ModLevel3Mask () 1180rxvt_term::ModLevel3Mask ()
1110 ALIAS: 1181 ALIAS:
1111 ModLevel3Mask = 0 1182 ModLevel3Mask = 0
1112 ModMetaMask = 1 1183 ModMetaMask = 1
1113 ModNumLockMask = 2 1184 ModNumLockMask = 2
1185 current_screen = 3
1186 hidden_cursor = 4
1114 CODE: 1187 CODE:
1115 switch (ix) 1188 switch (ix)
1116 { 1189 {
1117 case 0: RETVAL = THIS->ModLevel3Mask; break; 1190 case 0: RETVAL = THIS->ModLevel3Mask; break;
1118 case 1: RETVAL = THIS->ModMetaMask; break; 1191 case 1: RETVAL = THIS->ModMetaMask; break;
1119 case 2: RETVAL = THIS->ModNumLockMask; break; 1192 case 2: RETVAL = THIS->ModNumLockMask; break;
1193 case 3: RETVAL = THIS->current_screen; break;
1194 case 4: RETVAL = THIS->hidden_cursor; break;
1120 } 1195 }
1121 OUTPUT: 1196 OUTPUT:
1122 RETVAL 1197 RETVAL
1123 1198
1124char * 1199char *
1162 if (events != EVENT_UNDEF) 1237 if (events != EVENT_UNDEF)
1163 THIS->pty_ev.set (events); 1238 THIS->pty_ev.set (events);
1164 OUTPUT: 1239 OUTPUT:
1165 RETVAL 1240 RETVAL
1166 1241
1242int
1243rxvt_term::pty_fd ()
1244 CODE:
1245 RETVAL = THIS->pty->pty;
1246 OUTPUT:
1247 RETVAL
1248
1167Window 1249Window
1168rxvt_term::parent () 1250rxvt_term::parent ()
1169 CODE: 1251 CODE:
1170 RETVAL = THIS->parent [0]; 1252 RETVAL = THIS->parent [0];
1171 OUTPUT: 1253 OUTPUT:
1204} 1286}
1205 OUTPUT: 1287 OUTPUT:
1206 RETVAL 1288 RETVAL
1207 1289
1208void 1290void
1291rxvt_term::focus_in ()
1292
1293void
1294rxvt_term::focus_out ()
1295
1296void
1209rxvt_term::want_refresh () 1297rxvt_term::want_refresh ()
1210 CODE: 1298 CODE:
1211 THIS->want_refresh = 1; 1299 THIS->want_refresh = 1;
1212 1300
1213void 1301void
1219 1307
1220 line_t &l = ROW(row_number); 1308 line_t &l = ROW(row_number);
1221 1309
1222 if (GIMME_V != G_VOID) 1310 if (GIMME_V != G_VOID)
1223 { 1311 {
1224 wchar_t *wstr = new wchar_t [THIS->ncol]; 1312 wchar_t *wstr = rxvt_temp_buf<wchar_t> (THIS->ncol);
1225 1313
1226 for (int col = 0; col < THIS->ncol; col++) 1314 for (int col = 0; col < THIS->ncol; col++)
1227 wstr [col] = l.t [col]; 1315 wstr [col] = l.t [col];
1228 1316
1229 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1317 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1230
1231 delete [] wstr;
1232 } 1318 }
1233 1319
1234 if (new_text) 1320 if (new_text)
1235 { 1321 {
1236 wchar_t *wstr = sv2wcs (new_text); 1322 wchar_t *wstr = sv2wcs (new_text);
1237 1323
1238 int len = min (wcslen (wstr) - start_ofs, max_len); 1324 int len = min (wcslen (wstr) - start_ofs, max_len);
1239 1325
1240 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1326 if (start_col < 0 || start_col + len > THIS->ncol)
1241 { 1327 {
1242 free (wstr); 1328 free (wstr);
1243 croak ("new_text extends beyond horizontal margins"); 1329 croak ("new_text extends beyond horizontal margins");
1244 } 1330 }
1245 1331
1279 croak ("new_rend must be arrayref"); 1365 croak ("new_rend must be arrayref");
1280 1366
1281 AV *av = (AV *)SvRV (new_rend); 1367 AV *av = (AV *)SvRV (new_rend);
1282 int len = min (AvFILL (av) + 1 - start_ofs, max_len); 1368 int len = min (AvFILL (av) + 1 - start_ofs, max_len);
1283 1369
1284 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1370 if (start_col < 0 || start_col + len > THIS->ncol)
1285 croak ("new_rend array extends beyond horizontal margins"); 1371 croak ("new_rend array extends beyond horizontal margins");
1286 1372
1287 for (int col = start_col; col < start_col + len; col++) 1373 for (int col = start_col; col < start_col + len; col++)
1288 { 1374 {
1289 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; 1375 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1329rxvt_term::special_encode (SV *string) 1415rxvt_term::special_encode (SV *string)
1330 CODE: 1416 CODE:
1331{ 1417{
1332 wchar_t *wstr = sv2wcs (string); 1418 wchar_t *wstr = sv2wcs (string);
1333 int wlen = wcslen (wstr); 1419 int wlen = wcslen (wstr);
1334 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer 1420 wchar_t *rstr = rxvt_temp_buf<wchar_t> (wlen * 2); // cannot become longer
1335 1421
1336 rxvt_push_locale (THIS->locale); 1422 rxvt_push_locale (THIS->locale);
1337 1423
1338 wchar_t *r = rstr; 1424 wchar_t *r = rstr;
1339 for (wchar_t *s = wstr; *s; s++) 1425 for (wchar_t *s = wstr; *s; s++)
1426 {
1427 int w = WCWIDTH (*s);
1428
1340 if (wcwidth (*s) == 0) 1429 if (w == 0)
1341 { 1430 {
1342 if (r == rstr) 1431 if (r == rstr)
1343 croak ("leading combining character unencodable"); 1432 croak ("leading combining character unencodable");
1344 1433
1345 unicode_t n = rxvt_compose (r[-1], *s); 1434 unicode_t n = rxvt_compose (r[-1], *s);
1346 if (n == NOCHAR) 1435 if (n == NOCHAR)
1347 n = rxvt_composite.compose (r[-1], *s); 1436 n = rxvt_composite.compose (r[-1], *s);
1348 1437
1349 r[-1] = n; 1438 r[-1] = n;
1350 } 1439 }
1351#if !UNICODE_3 1440#if !UNICODE_3
1352 else if (*s >= 0x10000) 1441 else if (*s >= 0x10000)
1353 *r++ = rxvt_composite.compose (*s); 1442 *r++ = rxvt_composite.compose (*s);
1354#endif 1443#endif
1355 else 1444 else
1356 *r++ = *s; 1445 *r++ = *s;
1446
1447 // the *2 above only allows wcwidth <= 2
1448 if (w > 1)
1449 *r++ = NOCHAR;
1450 }
1357 1451
1358 rxvt_pop_locale (); 1452 rxvt_pop_locale ();
1359 1453
1360 RETVAL = wcs2sv (rstr, r - rstr); 1454 RETVAL = wcs2sv (rstr, r - rstr);
1361
1362 delete [] rstr;
1363} 1455}
1364 OUTPUT: 1456 OUTPUT:
1365 RETVAL 1457 RETVAL
1366 1458
1367SV * 1459SV *
1379 else if (IS_COMPOSE (*s)) 1471 else if (IS_COMPOSE (*s))
1380 dlen += rxvt_composite.expand (*s, 0); 1472 dlen += rxvt_composite.expand (*s, 0);
1381 else 1473 else
1382 dlen++; 1474 dlen++;
1383 1475
1384 wchar_t *rstr = new wchar_t [dlen]; 1476 wchar_t *rstr = rxvt_temp_buf<wchar_t> (dlen);
1385 1477
1386 // decode 1478 // decode
1387 wchar_t *r = rstr; 1479 wchar_t *r = rstr;
1388 for (wchar_t *s = wstr; *s; s++) 1480 for (wchar_t *s = wstr; *s; s++)
1389 if (*s == NOCHAR) 1481 if (*s == NOCHAR)
1392 r += rxvt_composite.expand (*s, r); 1484 r += rxvt_composite.expand (*s, r);
1393 else 1485 else
1394 *r++ = *s; 1486 *r++ = *s;
1395 1487
1396 RETVAL = wcs2sv (rstr, r - rstr); 1488 RETVAL = wcs2sv (rstr, r - rstr);
1397
1398 delete [] rstr;
1399} 1489}
1400 OUTPUT: 1490 OUTPUT:
1401 RETVAL 1491 RETVAL
1402 1492
1403void 1493void
1404rxvt_term::_resource (char *name, int index, SV *newval = 0) 1494rxvt_term::_resource (char *name, int index, SV *newval = 0)
1405 PPCODE: 1495 PPCODE:
1406{ 1496{
1407 struct resval { const char *name; int value; } rslist [] = { 1497 static const struct resval { const char *name; int value; } *rs, rslist [] = {
1408# define def(name) { # name, Rs_ ## name }, 1498# define def(name) { # name, Rs_ ## name },
1409# define reserve(name,count) 1499# define reserve(name,count)
1410# include "rsinc.h" 1500# include "rsinc.h"
1411# undef def 1501# undef def
1412# undef reserve 1502# undef reserve
1413 }; 1503 };
1414 1504
1415 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1505 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1416 1506
1417 do { 1507 do {
1418 if (rs-- == rslist) 1508 if (rs-- == rslist)
1419 croak ("no such resource '%s', requested", name); 1509 croak ("no such resource '%s', requested", name);
1420 } while (strcmp (name, rs->name)); 1510 } while (strcmp (name, rs->name));
1513 if (items == 3) 1603 if (items == 3)
1514 { 1604 {
1515 rc.row = SvIV (ST (1)); 1605 rc.row = SvIV (ST (1));
1516 rc.col = SvIV (ST (2)); 1606 rc.col = SvIV (ST (2));
1517 1607
1518 if (ix == 2 && rc.col == 0) 1608 if (ix == 2)
1519 { 1609 {
1610 if (rc.col == 0)
1611 {
1612 // col == 0 means end of previous line
1520 rc.row--; 1613 rc.row--;
1521 rc.col = THIS->ncol; 1614 rc.col = THIS->ncol;
1615 }
1616 else if (IN_RANGE_EXC (rc.row, THIS->top_row, THIS->nrow)
1617 && rc.col > ROW(rc.row).l)
1618 {
1619 // col >= length means while line and add newline
1620 rc.col = THIS->ncol;
1621 }
1522 } 1622 }
1523 1623
1524 clamp_it (rc.col, 0, THIS->ncol); 1624 clamp_it (rc.col, 0, THIS->ncol);
1525 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1625 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1526 1626
1534 CODE: 1634 CODE:
1535 RETVAL = THIS->charsets [THIS->screen.charset]; 1635 RETVAL = THIS->charsets [THIS->screen.charset];
1536 OUTPUT: 1636 OUTPUT:
1537 RETVAL 1637 RETVAL
1538 1638
1539#void 1639void
1540#rxvt_term::selection_clear () 1640rxvt_term::selection_clear ()
1541 1641
1542void 1642void
1543rxvt_term::selection_make (Time eventtime, bool rect = false) 1643rxvt_term::selection_make (Time eventtime, bool rect = false)
1544 CODE: 1644 CODE:
1545 THIS->selection.op = SELECTION_CONT; 1645 THIS->selection.op = SELECTION_CONT;
1573void 1673void
1574rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) 1674rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1575 1675
1576void 1676void
1577rxvt_term::scr_bell () 1677rxvt_term::scr_bell ()
1678
1679void
1680rxvt_term::scr_change_screen (int screen)
1578 1681
1579void 1682void
1580rxvt_term::scr_add_lines (SV *string) 1683rxvt_term::scr_add_lines (SV *string)
1581 CODE: 1684 CODE:
1582{ 1685{
1632void 1735void
1633rxvt_term::XListProperties (Window window) 1736rxvt_term::XListProperties (Window window)
1634 PPCODE: 1737 PPCODE:
1635{ 1738{
1636 int count; 1739 int count;
1637 Atom *props = XListProperties (THIS->display->display, window, &count); 1740 Atom *props = XListProperties (THIS->dpy, window, &count);
1638 1741
1639 EXTEND (SP, count); 1742 EXTEND (SP, count);
1640 while (count--) 1743 while (count--)
1641 PUSHs (newSVuv ((U32)props [count])); 1744 PUSHs (newSVuv ((U32)props [count]));
1642 1745
1651 int format; 1754 int format;
1652 unsigned long nitems; 1755 unsigned long nitems;
1653 unsigned long bytes_after; 1756 unsigned long bytes_after;
1654 unsigned char *prop; 1757 unsigned char *prop;
1655 1758
1656 XGetWindowProperty (THIS->display->display, window, property, 1759 XGetWindowProperty (THIS->dpy, window, property,
1657 0, 1<<24, 0, AnyPropertyType, 1760 0, 1<<24, 0, AnyPropertyType,
1658 &type, &format, &nitems, &bytes_after, &prop); 1761 &type, &format, &nitems, &bytes_after, &prop);
1659 1762
1660 if (type != None) 1763 if (type != None)
1661 { 1764 {
1680 1783
1681 int elemsize = format == 16 ? sizeof (short) 1784 int elemsize = format == 16 ? sizeof (short)
1682 : format == 32 ? sizeof (long) 1785 : format == 32 ? sizeof (long)
1683 : 1; 1786 : 1;
1684 1787
1685 XChangeProperty (THIS->display->display, window, property, 1788 XChangeProperty (THIS->dpy, window, property,
1686 type, format, PropModeReplace, 1789 type, format, PropModeReplace,
1687 (unsigned char *)data_, len / elemsize); 1790 (unsigned char *)data_, len / elemsize);
1688 XSync (THIS->display->display, 0); 1791 XSync (THIS->dpy, 0);
1689} 1792}
1690 1793
1691Atom 1794Atom
1692XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE) 1795XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1693 C_ARGS: term->display->display, atom_name, only_if_exists 1796 C_ARGS: term->dpy, atom_name, only_if_exists
1694 1797
1695char * 1798char *
1696XGetAtomName (rxvt_term *term, Atom atom) 1799XGetAtomName (rxvt_term *term, Atom atom)
1697 C_ARGS: term->display->display, atom 1800 C_ARGS: term->dpy, atom
1698 CLEANUP: 1801 CLEANUP:
1699 XFree (RETVAL); 1802 XFree (RETVAL);
1700 1803
1701void 1804void
1702XDeleteProperty (rxvt_term *term, Window window, Atom property) 1805XDeleteProperty (rxvt_term *term, Window window, Atom property)
1703 C_ARGS: term->display->display, window, property 1806 C_ARGS: term->dpy, window, property
1704 1807
1705Window 1808Window
1706rxvt_term::DefaultRootWindow () 1809rxvt_term::DefaultRootWindow ()
1707 CODE: 1810 CODE:
1708 RETVAL = THIS->display->root; 1811 RETVAL = THIS->display->root;
1711 1814
1712#if 0 1815#if 0
1713 1816
1714Window 1817Window
1715XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height) 1818XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1716 C_ARGS: term->display->display, (Window)parent, 1819 C_ARGS: term->dpy, (Window)parent,
1717 x, y, width, height, 0, 1820 x, y, width, height, 0,
1718 term->pix_colors_focused[Color_border], 1821 term->pix_colors_focused[Color_border],
1719 term->pix_colors_focused[Color_border] 1822 term->pix_colors_focused[Color_border]
1720 1823
1721#endif 1824#endif
1722 1825
1723void 1826void
1724XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0) 1827XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1725 C_ARGS: term->display->display, window, parent, x, y 1828 C_ARGS: term->dpy, window, parent, x, y
1726 1829
1727void 1830void
1728XMapWindow (rxvt_term *term, Window window) 1831XMapWindow (rxvt_term *term, Window window)
1729 C_ARGS: term->display->display, window 1832 C_ARGS: term->dpy, window
1730 1833
1731void 1834void
1732XUnmapWindow (rxvt_term *term, Window window) 1835XUnmapWindow (rxvt_term *term, Window window)
1733 C_ARGS: term->display->display, window 1836 C_ARGS: term->dpy, window
1734 1837
1735void 1838void
1736XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height) 1839XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1737 C_ARGS: term->display->display, (Window)window, x, y, width, height 1840 C_ARGS: term->dpy, window, x, y, width, height
1841
1842void
1843rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0)
1844 CODE:
1845{
1846 XWindowAttributes attr;
1847 XGetWindowAttributes (THIS->dpy, window, &attr);
1848 XSelectInput (THIS->dpy, window, attr.your_event_mask | add_events & ~del_events);
1849}
1738 1850
1739void 1851void
1740rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y) 1852rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y)
1741 PPCODE: 1853 PPCODE:
1742{ 1854{
1743 int dx, dy; 1855 int dx, dy;
1744 Window child; 1856 Window child;
1745 1857
1746 if (XTranslateCoordinates (THIS->display->display, src, dst, x, y, &dx, &dy, &child)) 1858 if (XTranslateCoordinates (THIS->dpy, src, dst, x, y, &dx, &dy, &child))
1747 { 1859 {
1748 EXTEND (SP, 3); 1860 EXTEND (SP, 3);
1749 PUSHs (newSViv (dx)); 1861 PUSHs (newSViv (dx));
1750 PUSHs (newSViv (dy)); 1862 PUSHs (newSViv (dy));
1751 PUSHs (newSVuv (child)); 1863 PUSHs (newSVuv (child));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines