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.80 by root, Fri Jan 20 12:16:28 2006 UTC vs.
Revision 1.95 by root, Sun Jan 29 20:51:28 2006 UTC

113 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 113 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
114 114
115 return (long)mg->mg_ptr; 115 return (long)mg->mg_ptr;
116} 116}
117 117
118#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) 118#define newSVterm(term) SvREFCNT_inc ((SV *)(term)->perl.self)
119#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 119#define SvTERM(sv) (rxvt_term *)SvPTR ((sv), "urxvt::term")
120 120
121///////////////////////////////////////////////////////////////////////////// 121/////////////////////////////////////////////////////////////////////////////
122 122
123#define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, "urxvt::watcher") 123#define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, "urxvt::watcher")
124 124
171 171
172 if (SvTRUE (ERRSV)) 172 if (SvTRUE (ERRSV))
173 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV)); 173 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
174} 174}
175 175
176#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") 176#define newSVtimer(timer) new_ref ((timer)->self, "urxvt::timer")
177#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR (sv, "urxvt::timer") 177#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR ((sv), "urxvt::timer")
178 178
179struct timer : perl_watcher, time_watcher 179struct timer : perl_watcher, time_watcher
180{ 180{
181 tstamp interval; 181 tstamp interval;
182 182
192 192
193 invoke ("urxvt::timer", newSVtimer (this)); 193 invoke ("urxvt::timer", newSVtimer (this));
194 } 194 }
195}; 195};
196 196
197#define newSViow(iow) new_ref (iow->self, "urxvt::iow") 197#define newSViow(iow) new_ref ((iow)->self, "urxvt::iow")
198#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR (sv, "urxvt::iow") 198#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR ((sv), "urxvt::iow")
199 199
200struct iow : perl_watcher, io_watcher 200struct iow : perl_watcher, io_watcher
201{ 201{
202 iow () 202 iow ()
203 : io_watcher (this, &iow::execute) 203 : io_watcher (this, &iow::execute)
208 { 208 {
209 invoke ("urxvt::iow", newSViow (this), revents); 209 invoke ("urxvt::iow", newSViow (this), revents);
210 } 210 }
211}; 211};
212 212
213#define newSViw(iw) new_ref (iw->self, "urxvt::iw") 213#define newSViw(iw) new_ref ((iw)->self, "urxvt::iw")
214#define SvIW(sv) (iw *)(perl_watcher *)SvPTR (sv, "urxvt::iw") 214#define SvIW(sv) (iw *)(perl_watcher *)SvPTR ((sv), "urxvt::iw")
215 215
216struct iw : perl_watcher, idle_watcher 216struct iw : perl_watcher, idle_watcher
217{ 217{
218 iw () 218 iw ()
219 : idle_watcher (this, &iw::execute) 219 : idle_watcher (this, &iw::execute)
224 { 224 {
225 invoke ("urxvt::iw", newSViw (this)); 225 invoke ("urxvt::iw", newSViw (this));
226 } 226 }
227}; 227};
228 228
229#define newSVpw(pw) new_ref (pw->self, "urxvt::pw") 229#define newSVpw(pw) new_ref ((pw)->self, "urxvt::pw")
230#define SvPW(sv) (pw *)(perl_watcher *)SvPTR (sv, "urxvt::pw") 230#define SvPW(sv) (pw *)(perl_watcher *)SvPTR ((sv), "urxvt::pw")
231 231
232struct pw : perl_watcher, child_watcher 232struct pw : perl_watcher, child_watcher
233{ 233{
234 pw () 234 pw ()
235 : child_watcher (this, &pw::execute) 235 : child_watcher (this, &pw::execute)
244 244
245///////////////////////////////////////////////////////////////////////////// 245/////////////////////////////////////////////////////////////////////////////
246 246
247#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 247#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
248 248
249struct overlay { 249class overlay {
250 HV *self;
251 bool visible;
252 rxvt_term *THIS; 250 rxvt_term *THIS;
251 AV *overlay_av;
253 int x, y, w, h; 252 int x, y, w, h;
254 int border; 253 int border;
255 text_t **text; 254 text_t **text;
256 rend_t **rend; 255 rend_t **rend;
257 256
257public:
258 HV *self;
259
258 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); 260 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
259 ~overlay (); 261 ~overlay ();
260 262
261 void show (); 263 void show ();
262 void hide (); 264 void hide ();
265 267
266 void set (int x, int y, SV *str, SV *rend); 268 void set (int x, int y, SV *str, SV *rend);
267}; 269};
268 270
269overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 271overlay::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) 272: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0)
271{ 273{
272 if (border == 2) 274 if (border == 2)
273 { 275 {
274 w += 2; 276 w += 2;
275 h += 2; 277 h += 2;
314 *rp++ = r; 316 *rp++ = r;
315 } 317 }
316 } 318 }
317 319
318 show (); 320 show ();
319 THIS->want_refresh = 1;
320} 321}
321 322
322overlay::~overlay () 323overlay::~overlay ()
323{ 324{
324 hide (); 325 hide ();
329 delete [] rend[y]; 330 delete [] rend[y];
330 } 331 }
331 332
332 delete [] text; 333 delete [] text;
333 delete [] rend; 334 delete [] rend;
335}
336
337void
338overlay::show ()
339{
340 if (overlay_av)
341 return;
342
343 overlay_av = (AV *)SvREFCNT_inc (SvRV (
344 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
345 ));
346 av_push (overlay_av, newSViv ((long)this));
334 347
335 THIS->want_refresh = 1; 348 THIS->want_refresh = 1;
336} 349}
337 350
338void 351void
339overlay::show () 352overlay::hide ()
340{ 353{
341 if (visible) 354 if (!overlay_av)
342 return; 355 return;
343 356
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; 357 int i;
361 358
362 for (i = AvFILL (av); i >= 0; i--) 359 for (i = AvFILL (overlay_av); i >= 0; i--)
363 if (SvIV (*av_fetch (av, i, 1)) == (long)this) 360 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this)
364 { 361 {
365 av_delete (av, i, G_DISCARD); 362 av_delete (overlay_av, i, G_DISCARD);
366 break; 363 break;
367 } 364 }
368 365
369 for (; i < AvFILL (av); i++) 366 for (; i < AvFILL (overlay_av); i++)
370 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0))); 367 av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0)));
371 368
372 av_pop (av); 369 av_pop (overlay_av);
370
371 SvREFCNT_dec (overlay_av);
372 overlay_av = 0;
373
374 THIS->want_refresh = 1;
373} 375}
374 376
375void overlay::swap () 377void overlay::swap ()
376{ 378{
377 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 379 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
492static void 494static void
493ungrab (rxvt_term *THIS) 495ungrab (rxvt_term *THIS)
494{ 496{
495 if (THIS->perl.grabtime) 497 if (THIS->perl.grabtime)
496 { 498 {
497 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); 499 XUngrabKeyboard (THIS->xdisp, THIS->perl.grabtime);
498 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 500 XUngrabPointer (THIS->xdisp, THIS->perl.grabtime);
499 THIS->perl.grabtime = 0; 501 THIS->perl.grabtime = 0;
500 } 502 }
501} 503}
502 504
503bool 505bool
554 break; 556 break;
555 557
556 case DT_STR_LEN: 558 case DT_STR_LEN:
557 { 559 {
558 char *str = va_arg (ap, char *); 560 char *str = va_arg (ap, char *);
559 int len = va_arg (ap, int); 561 int len = va_arg (ap, int);
560 562
561 XPUSHs (sv_2mortal (newSVpvn (str, len))); 563 XPUSHs (sv_2mortal (newSVpvn (str, len)));
562 } 564 }
563 break; 565 break;
564 566
565 case DT_WCS_LEN: 567 case DT_WCS_LEN:
566 { 568 {
567 wchar_t *wstr = va_arg (ap, wchar_t *); 569 wchar_t *wstr = va_arg (ap, wchar_t *);
568 int wlen = va_arg (ap, int); 570 int wlen = va_arg (ap, int);
569 571
570 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 572 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
573 }
574 break;
575
576 case DT_LCS_LEN:
577 {
578 long *lstr = va_arg (ap, long *);
579 int llen = va_arg (ap, int);
580
581 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long))));
571 } 582 }
572 break; 583 break;
573 584
574 case DT_XEVENT: 585 case DT_XEVENT:
575 { 586 {
576 XEvent *xe = va_arg (ap, XEvent *); 587 XEvent *xe = va_arg (ap, XEvent *);
577 HV *hv = newHV (); 588 HV *hv = newHV ();
578 589
579# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 590# 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) 591# 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) 592# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
582# undef set 593# undef set
583 594
584 setiv (type, xe->type); 595 setiv (type, xe->type);
585 setiv (send_event, xe->xany.send_event); 596 setiv (send_event, xe->xany.send_event);
586 setiv (serial, xe->xany.serial); 597 setiv (serial, xe->xany.serial);
587 598
596 setuv (root, xe->xmotion.root); 607 setuv (root, xe->xmotion.root);
597 setuv (subwindow, xe->xmotion.subwindow); 608 setuv (subwindow, xe->xmotion.subwindow);
598 setuv (time, xe->xmotion.time); 609 setuv (time, xe->xmotion.time);
599 setiv (x, xe->xmotion.x); 610 setiv (x, xe->xmotion.x);
600 setiv (y, xe->xmotion.y); 611 setiv (y, xe->xmotion.y);
601 setiv (row, xe->xmotion.y / term->fheight); 612 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
602 setiv (col, xe->xmotion.x / term->fwidth); 613 setiv (col, xe->xmotion.x / term->fwidth);
603 setiv (x_root, xe->xmotion.x_root); 614 setiv (x_root, xe->xmotion.x_root);
604 setiv (y_root, xe->xmotion.y_root); 615 setiv (y_root, xe->xmotion.y_root);
605 setuv (state, xe->xmotion.state); 616 setuv (state, xe->xmotion.state);
606 617
640 break; 651 break;
641 } 652 }
642 653
643 break; 654 break;
644 655
656 case PropertyNotify:
657 setuv (window, xe->xproperty.window);
658 setuv (atom, xe->xproperty.atom);
659 setuv (time, xe->xproperty.time);
660 setiv (state, xe->xproperty.state);
661 break;
662
645 case ClientMessage: 663 case ClientMessage:
646 setuv (window, xe->xclient.window); 664 setuv (window, xe->xclient.window);
647 setuv (message_type, xe->xclient.message_type); 665 setuv (message_type, xe->xclient.message_type);
648 setuv (format, xe->xclient.format); 666 setuv (format, xe->xclient.format);
649 setuv (l0, xe->xclient.data.l[0]); 667 setuv (l0, xe->xclient.data.l[0]);
650 setuv (l1, xe->xclient.data.l[1]); 668 setuv (l1, xe->xclient.data.l[1]);
651 setuv (l2, xe->xclient.data.l[2]); 669 setuv (l2, xe->xclient.data.l[2]);
652 setuv (l3, xe->xclient.data.l[3]); 670 setuv (l3, xe->xclient.data.l[3]);
653 setuv (l4, xe->xclient.data.l[4]); 671 setuv (l4, xe->xclient.data.l[4]);
672 break;
654 } 673 }
655 674
656 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 675 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
657 } 676 }
658 break; 677 break;
708 } 727 }
709 else if (htype == HOOK_DESTROY) 728 else if (htype == HOOK_DESTROY)
710 { 729 {
711 clearSVptr ((SV *)term->perl.self); 730 clearSVptr ((SV *)term->perl.self);
712 SvREFCNT_dec ((SV *)term->perl.self); 731 SvREFCNT_dec ((SV *)term->perl.self);
732
733 // don't allow further calls
734 term->perl.self = 0;
713 } 735 }
714 736
715 swap (perl_environ, environ); 737 swap (perl_environ, environ);
716 738
717 return event_consumed; 739 return event_consumed;
834 const_iv (SelectionRequest), 856 const_iv (SelectionRequest),
835 const_iv (SelectionNotify), 857 const_iv (SelectionNotify),
836 const_iv (ColormapNotify), 858 const_iv (ColormapNotify),
837 const_iv (ClientMessage), 859 const_iv (ClientMessage),
838 const_iv (MappingNotify), 860 const_iv (MappingNotify),
861# if ENABLE_XIM_ONTHESPOT
862 const_iv (XIMReverse),
863 const_iv (XIMUnderline),
864 const_iv (XIMHighlight),
865 const_iv (XIMPrimary),
866 const_iv (XIMSecondary),
867 const_iv (XIMTertiary),
868 const_iv (XIMVisibleToForward),
869 const_iv (XIMVisibleToBackword),
870 const_iv (XIMVisibleToCenter),
871# if 0
872 const_iv (XIMForwardChar),
873 const_iv (XIMBackwardChar),
874 const_iv (XIMForwardWord),
875 const_iv (XIMBackwardWord),
876 const_iv (XIMCaretUp),
877 const_iv (XIMCaretDown),
878 const_iv (XIMNextLine),
879 const_iv (XIMPreviousLine),
880 const_iv (XIMLineStart),
881 const_iv (XIMLineEnd),
882 const_iv (XIMAbsolutePosition),
883 const_iv (XIMDontChange),
884# endif
885# endif
839 }; 886 };
840 887
841 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); 888 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]);
842 civ-- > const_iv; ) 889 civ-- > const_iv; )
843 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 890 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
909 | ((new_value << RS_customShift) & RS_customMask); 956 | ((new_value << RS_customShift) & RS_customMask);
910} 957}
911 OUTPUT: 958 OUTPUT:
912 RETVAL 959 RETVAL
913 960
961void
962termlist ()
963 PPCODE:
964{
965 EXTEND (SP, rxvt_term::termlist.size ());
966
967 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
968 if ((*t)->perl.self)
969 PUSHs (sv_2mortal (newSVterm (*t)));
970}
971
914MODULE = urxvt PACKAGE = urxvt::term 972MODULE = urxvt PACKAGE = urxvt::term
915 973
916SV * 974SV *
917_new (...) 975_new (AV *env, AV *arg)
918 CODE: 976 CODE:
919{ 977{
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; 978 rxvt_term *term = new rxvt_term;
924 979
925 term->argv = new stringvec; 980 stringvec *argv = new stringvec;
926 term->envv = new stringvec; 981 stringvec *envv = new stringvec;
927 982
928 for (int i = 1; i < items; i++) 983 for (int i = 0; i <= AvFILL (arg); i++)
929 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 984 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
930 985
931 AV *envv = (AV *)SvRV (ST (0));
932 for (int i = AvFILL (envv) + 1; i--; ) 986 for (int i = AvFILL (env) + 1; i--; )
933 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 987 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
934 988
935 term->envv->push_back (0); 989 envv->push_back (0);
936 990
937 bool success; 991 bool success;
938 992
939 try 993 try
940 { 994 {
941 success = term->init (term->argv->size (), term->argv->begin ()); 995 success = term->init (argv, envv);
942 } 996 }
943 catch (const class rxvt_failure_exception &e) 997 catch (const class rxvt_failure_exception &e)
944 { 998 {
945 success = false; 999 success = false;
946 } 1000 }
964rxvt_term::set_should_invoke (int htype, int inc) 1018rxvt_term::set_should_invoke (int htype, int inc)
965 CODE: 1019 CODE:
966 THIS->perl.should_invoke [htype] += inc; 1020 THIS->perl.should_invoke [htype] += inc;
967 1021
968void 1022void
969rxvt_term::grab_button (int button, U32 modifiers) 1023rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt)
970 CODE: 1024 CODE:
971 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 1025 XGrabButton (THIS->xdisp, button, modifiers, window, 1,
972 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1026 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
973 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 1027 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
974 1028
1029void
1030rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt)
1031 CODE:
1032 XUngrabButton (THIS->xdisp, button, modifiers, window);
1033
1034#if 0
1035
1036void
1037XGrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt)
1038 C_ARGS:
1039 THIS->xdisp, keycode, modifiers, window, 1,
1040 GrabModeSync, GrabModeSync
1041
1042void
1043XUngrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt)
1044 C_ARGS: THIS->xdisp, keycode, modifiers, window
1045
1046#endif
1047
975bool 1048bool
976rxvt_term::grab (Time eventtime, int sync = 0) 1049rxvt_term::grab (Time eventtime, int sync = 0)
977 CODE: 1050 CODE:
978{ 1051{
979 int mode = sync ? GrabModeSync : GrabModeAsync; 1052 int mode = sync ? GrabModeSync : GrabModeAsync;
980 1053
981 THIS->perl.grabtime = 0; 1054 THIS->perl.grabtime = 0;
982 1055
983 if (!XGrabPointer (THIS->display->display, THIS->vt, 0, 1056 if (!XGrabPointer (THIS->xdisp, THIS->vt, 0,
984 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1057 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
985 mode, mode, None, GRAB_CURSOR, eventtime)) 1058 mode, mode, None, GRAB_CURSOR, eventtime))
986 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) 1059 if (!XGrabKeyboard (THIS->xdisp, THIS->vt, 0, mode, mode, eventtime))
987 THIS->perl.grabtime = eventtime; 1060 THIS->perl.grabtime = eventtime;
988 else 1061 else
989 XUngrabPointer (THIS->display->display, eventtime); 1062 XUngrabPointer (THIS->xdisp, eventtime);
990 1063
991 RETVAL = !!THIS->perl.grabtime; 1064 RETVAL = !!THIS->perl.grabtime;
992} 1065}
993 OUTPUT: 1066 OUTPUT:
994 RETVAL 1067 RETVAL
995 1068
996void 1069void
997rxvt_term::allow_events_async () 1070rxvt_term::allow_events_async ()
998 CODE: 1071 CODE:
999 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); 1072 XAllowEvents (THIS->xdisp, AsyncBoth, THIS->perl.grabtime);
1000 1073
1001void 1074void
1002rxvt_term::allow_events_sync () 1075rxvt_term::allow_events_sync ()
1003 CODE: 1076 CODE:
1004 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); 1077 XAllowEvents (THIS->xdisp, SyncBoth, THIS->perl.grabtime);
1005 1078
1006void 1079void
1007rxvt_term::allow_events_replay () 1080rxvt_term::allow_events_replay ()
1008 CODE: 1081 CODE:
1009 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); 1082 XAllowEvents (THIS->xdisp, ReplayPointer, THIS->perl.grabtime);
1010 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); 1083 XAllowEvents (THIS->xdisp, ReplayKeyboard, THIS->perl.grabtime);
1011 1084
1012void 1085void
1013rxvt_term::ungrab () 1086rxvt_term::ungrab ()
1014 CODE: 1087 CODE:
1015 ungrab (THIS); 1088 ungrab (THIS);
1109rxvt_term::ModLevel3Mask () 1182rxvt_term::ModLevel3Mask ()
1110 ALIAS: 1183 ALIAS:
1111 ModLevel3Mask = 0 1184 ModLevel3Mask = 0
1112 ModMetaMask = 1 1185 ModMetaMask = 1
1113 ModNumLockMask = 2 1186 ModNumLockMask = 2
1187 current_screen = 3
1188 hidden_cursor = 4
1114 CODE: 1189 CODE:
1115 switch (ix) 1190 switch (ix)
1116 { 1191 {
1117 case 0: RETVAL = THIS->ModLevel3Mask; break; 1192 case 0: RETVAL = THIS->ModLevel3Mask; break;
1118 case 1: RETVAL = THIS->ModMetaMask; break; 1193 case 1: RETVAL = THIS->ModMetaMask; break;
1119 case 2: RETVAL = THIS->ModNumLockMask; break; 1194 case 2: RETVAL = THIS->ModNumLockMask; break;
1195 case 3: RETVAL = THIS->current_screen; break;
1196 case 4: RETVAL = THIS->hidden_cursor; break;
1120 } 1197 }
1121 OUTPUT: 1198 OUTPUT:
1122 RETVAL 1199 RETVAL
1123 1200
1124char * 1201char *
1162 if (events != EVENT_UNDEF) 1239 if (events != EVENT_UNDEF)
1163 THIS->pty_ev.set (events); 1240 THIS->pty_ev.set (events);
1164 OUTPUT: 1241 OUTPUT:
1165 RETVAL 1242 RETVAL
1166 1243
1244int
1245rxvt_term::pty_fd ()
1246 CODE:
1247 RETVAL = THIS->pty->pty;
1248 OUTPUT:
1249 RETVAL
1250
1167Window 1251Window
1168rxvt_term::parent () 1252rxvt_term::parent ()
1169 CODE: 1253 CODE:
1170 RETVAL = THIS->parent [0]; 1254 RETVAL = THIS->parent [0];
1171 OUTPUT: 1255 OUTPUT:
1204} 1288}
1205 OUTPUT: 1289 OUTPUT:
1206 RETVAL 1290 RETVAL
1207 1291
1208void 1292void
1293rxvt_term::focus_in ()
1294
1295void
1296rxvt_term::focus_out ()
1297
1298void
1209rxvt_term::want_refresh () 1299rxvt_term::want_refresh ()
1210 CODE: 1300 CODE:
1211 THIS->want_refresh = 1; 1301 THIS->want_refresh = 1;
1212 1302
1213void 1303void
1219 1309
1220 line_t &l = ROW(row_number); 1310 line_t &l = ROW(row_number);
1221 1311
1222 if (GIMME_V != G_VOID) 1312 if (GIMME_V != G_VOID)
1223 { 1313 {
1224 wchar_t *wstr = new wchar_t [THIS->ncol]; 1314 wchar_t *wstr = rxvt_temp_buf<wchar_t> (THIS->ncol);
1225 1315
1226 for (int col = 0; col < THIS->ncol; col++) 1316 for (int col = 0; col < THIS->ncol; col++)
1227 wstr [col] = l.t [col]; 1317 wstr [col] = l.t [col];
1228 1318
1229 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1319 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1230
1231 delete [] wstr;
1232 } 1320 }
1233 1321
1234 if (new_text) 1322 if (new_text)
1235 { 1323 {
1236 wchar_t *wstr = sv2wcs (new_text); 1324 wchar_t *wstr = sv2wcs (new_text);
1237 1325
1238 int len = min (wcslen (wstr) - start_ofs, max_len); 1326 int len = min (wcslen (wstr) - start_ofs, max_len);
1239 1327
1240 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1328 if (start_col < 0 || start_col + len > THIS->ncol)
1241 { 1329 {
1242 free (wstr); 1330 free (wstr);
1243 croak ("new_text extends beyond horizontal margins"); 1331 croak ("new_text extends beyond horizontal margins");
1244 } 1332 }
1245 1333
1279 croak ("new_rend must be arrayref"); 1367 croak ("new_rend must be arrayref");
1280 1368
1281 AV *av = (AV *)SvRV (new_rend); 1369 AV *av = (AV *)SvRV (new_rend);
1282 int len = min (AvFILL (av) + 1 - start_ofs, max_len); 1370 int len = min (AvFILL (av) + 1 - start_ofs, max_len);
1283 1371
1284 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1372 if (start_col < 0 || start_col + len > THIS->ncol)
1285 croak ("new_rend array extends beyond horizontal margins"); 1373 croak ("new_rend array extends beyond horizontal margins");
1286 1374
1287 for (int col = start_col; col < start_col + len; col++) 1375 for (int col = start_col; col < start_col + len; col++)
1288 { 1376 {
1289 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; 1377 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1329rxvt_term::special_encode (SV *string) 1417rxvt_term::special_encode (SV *string)
1330 CODE: 1418 CODE:
1331{ 1419{
1332 wchar_t *wstr = sv2wcs (string); 1420 wchar_t *wstr = sv2wcs (string);
1333 int wlen = wcslen (wstr); 1421 int wlen = wcslen (wstr);
1334 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer 1422 wchar_t *rstr = rxvt_temp_buf<wchar_t> (wlen * 2); // cannot become longer
1335 1423
1336 rxvt_push_locale (THIS->locale); 1424 rxvt_push_locale (THIS->locale);
1337 1425
1338 wchar_t *r = rstr; 1426 wchar_t *r = rstr;
1339 for (wchar_t *s = wstr; *s; s++) 1427 for (wchar_t *s = wstr; *s; s++)
1428 {
1429 int w = WCWIDTH (*s);
1430
1340 if (wcwidth (*s) == 0) 1431 if (w == 0)
1341 { 1432 {
1342 if (r == rstr) 1433 if (r == rstr)
1343 croak ("leading combining character unencodable"); 1434 croak ("leading combining character unencodable");
1344 1435
1345 unicode_t n = rxvt_compose (r[-1], *s); 1436 unicode_t n = rxvt_compose (r[-1], *s);
1346 if (n == NOCHAR) 1437 if (n == NOCHAR)
1347 n = rxvt_composite.compose (r[-1], *s); 1438 n = rxvt_composite.compose (r[-1], *s);
1348 1439
1349 r[-1] = n; 1440 r[-1] = n;
1350 } 1441 }
1351#if !UNICODE_3 1442#if !UNICODE_3
1352 else if (*s >= 0x10000) 1443 else if (*s >= 0x10000)
1353 *r++ = rxvt_composite.compose (*s); 1444 *r++ = rxvt_composite.compose (*s);
1354#endif 1445#endif
1355 else 1446 else
1356 *r++ = *s; 1447 *r++ = *s;
1448
1449 // the *2 above only allows wcwidth <= 2
1450 if (w > 1)
1451 *r++ = NOCHAR;
1452 }
1357 1453
1358 rxvt_pop_locale (); 1454 rxvt_pop_locale ();
1359 1455
1360 RETVAL = wcs2sv (rstr, r - rstr); 1456 RETVAL = wcs2sv (rstr, r - rstr);
1361
1362 delete [] rstr;
1363} 1457}
1364 OUTPUT: 1458 OUTPUT:
1365 RETVAL 1459 RETVAL
1366 1460
1367SV * 1461SV *
1379 else if (IS_COMPOSE (*s)) 1473 else if (IS_COMPOSE (*s))
1380 dlen += rxvt_composite.expand (*s, 0); 1474 dlen += rxvt_composite.expand (*s, 0);
1381 else 1475 else
1382 dlen++; 1476 dlen++;
1383 1477
1384 wchar_t *rstr = new wchar_t [dlen]; 1478 wchar_t *rstr = rxvt_temp_buf<wchar_t> (dlen);
1385 1479
1386 // decode 1480 // decode
1387 wchar_t *r = rstr; 1481 wchar_t *r = rstr;
1388 for (wchar_t *s = wstr; *s; s++) 1482 for (wchar_t *s = wstr; *s; s++)
1389 if (*s == NOCHAR) 1483 if (*s == NOCHAR)
1392 r += rxvt_composite.expand (*s, r); 1486 r += rxvt_composite.expand (*s, r);
1393 else 1487 else
1394 *r++ = *s; 1488 *r++ = *s;
1395 1489
1396 RETVAL = wcs2sv (rstr, r - rstr); 1490 RETVAL = wcs2sv (rstr, r - rstr);
1397
1398 delete [] rstr;
1399} 1491}
1400 OUTPUT: 1492 OUTPUT:
1401 RETVAL 1493 RETVAL
1402 1494
1403void 1495void
1513 if (items == 3) 1605 if (items == 3)
1514 { 1606 {
1515 rc.row = SvIV (ST (1)); 1607 rc.row = SvIV (ST (1));
1516 rc.col = SvIV (ST (2)); 1608 rc.col = SvIV (ST (2));
1517 1609
1518 if (ix == 2 && rc.col == 0) 1610 if (ix == 2)
1519 { 1611 {
1612 if (rc.col == 0)
1613 {
1614 // col == 0 means end of previous line
1520 rc.row--; 1615 rc.row--;
1521 rc.col = THIS->ncol; 1616 rc.col = THIS->ncol;
1617 }
1618 else if (IN_RANGE_EXC (rc.row, THIS->top_row, THIS->nrow)
1619 && rc.col > ROW(rc.row).l)
1620 {
1621 // col >= length means while line and add newline
1622 rc.col = THIS->ncol;
1623 }
1522 } 1624 }
1523 1625
1524 clamp_it (rc.col, 0, THIS->ncol); 1626 clamp_it (rc.col, 0, THIS->ncol);
1525 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1627 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1526 1628
1534 CODE: 1636 CODE:
1535 RETVAL = THIS->charsets [THIS->screen.charset]; 1637 RETVAL = THIS->charsets [THIS->screen.charset];
1536 OUTPUT: 1638 OUTPUT:
1537 RETVAL 1639 RETVAL
1538 1640
1539#void 1641void
1540#rxvt_term::selection_clear () 1642rxvt_term::selection_clear ()
1541 1643
1542void 1644void
1543rxvt_term::selection_make (Time eventtime, bool rect = false) 1645rxvt_term::selection_make (Time eventtime, bool rect = false)
1544 CODE: 1646 CODE:
1545 THIS->selection.op = SELECTION_CONT; 1647 THIS->selection.op = SELECTION_CONT;
1573void 1675void
1574rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) 1676rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1575 1677
1576void 1678void
1577rxvt_term::scr_bell () 1679rxvt_term::scr_bell ()
1680
1681void
1682rxvt_term::scr_change_screen (int screen)
1578 1683
1579void 1684void
1580rxvt_term::scr_add_lines (SV *string) 1685rxvt_term::scr_add_lines (SV *string)
1581 CODE: 1686 CODE:
1582{ 1687{
1632void 1737void
1633rxvt_term::XListProperties (Window window) 1738rxvt_term::XListProperties (Window window)
1634 PPCODE: 1739 PPCODE:
1635{ 1740{
1636 int count; 1741 int count;
1637 Atom *props = XListProperties (THIS->display->display, window, &count); 1742 Atom *props = XListProperties (THIS->xdisp, window, &count);
1638 1743
1639 EXTEND (SP, count); 1744 EXTEND (SP, count);
1640 while (count--) 1745 while (count--)
1641 PUSHs (newSVuv ((U32)props [count])); 1746 PUSHs (newSVuv ((U32)props [count]));
1642 1747
1650 Atom type; 1755 Atom type;
1651 int format; 1756 int format;
1652 unsigned long nitems; 1757 unsigned long nitems;
1653 unsigned long bytes_after; 1758 unsigned long bytes_after;
1654 unsigned char *prop; 1759 unsigned char *prop;
1760
1655 XGetWindowProperty (THIS->display->display, window, property, 1761 XGetWindowProperty (THIS->xdisp, window, property,
1656 0, 1<<30, 0, AnyPropertyType, 1762 0, 1<<24, 0, AnyPropertyType,
1657 &type, &format, &nitems, &bytes_after, &prop); 1763 &type, &format, &nitems, &bytes_after, &prop);
1764
1658 if (type != None) 1765 if (type != None)
1659 { 1766 {
1767 int elemsize = format == 16 ? sizeof (short)
1768 : format == 32 ? sizeof (long)
1769 : 1;
1770
1660 EXTEND (SP, 3); 1771 EXTEND (SP, 3);
1661 PUSHs (newSVuv ((U32)type)); 1772 PUSHs (newSVuv ((U32)type));
1662 PUSHs (newSViv (format)); 1773 PUSHs (newSViv (format));
1663 PUSHs (newSVpvn ((char *)prop, nitems * format / 8)); 1774 PUSHs (newSVpvn ((char *)prop, nitems * elemsize));
1664 XFree (prop); 1775 XFree (prop);
1665 } 1776 }
1666} 1777}
1667 1778
1668void 1779void
1670 CODE: 1781 CODE:
1671{ 1782{
1672 STRLEN len; 1783 STRLEN len;
1673 char *data_ = SvPVbyte (data, len); 1784 char *data_ = SvPVbyte (data, len);
1674 1785
1786 int elemsize = format == 16 ? sizeof (short)
1787 : format == 32 ? sizeof (long)
1788 : 1;
1789
1675 XChangeProperty (THIS->display->display, window, property, 1790 XChangeProperty (THIS->xdisp, window, property,
1676 type, format, PropModeReplace, 1791 type, format, PropModeReplace,
1677 (unsigned char *)data, len * 8 / format); 1792 (unsigned char *)data_, len / elemsize);
1793 XSync (THIS->xdisp, 0);
1678} 1794}
1795
1796Atom
1797XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1798 C_ARGS: term->xdisp, atom_name, only_if_exists
1799
1800char *
1801XGetAtomName (rxvt_term *term, Atom atom)
1802 C_ARGS: term->xdisp, atom
1803 CLEANUP:
1804 XFree (RETVAL);
1679 1805
1680void 1806void
1681XDeleteProperty (rxvt_term *term, Window window, Atom property) 1807XDeleteProperty (rxvt_term *term, Window window, Atom property)
1682 C_ARGS: term->display->display, window, property 1808 C_ARGS: term->xdisp, window, property
1683 1809
1684Window 1810Window
1685rxvt_term::DefaultRootWindow () 1811rxvt_term::DefaultRootWindow ()
1686 CODE: 1812 CODE:
1687 RETVAL = THIS->display->root; 1813 RETVAL = THIS->display->root;
1688 OUTPUT: 1814 OUTPUT:
1689 RETVAL 1815 RETVAL
1690 1816
1817#if 0
1818
1691Window 1819Window
1692XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height) 1820XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1693 C_ARGS: term->display->display, (Window)parent, 1821 C_ARGS: term->xdisp, (Window)parent,
1694 x, y, width, height, 0, 1822 x, y, width, height, 0,
1695 term->pix_colors_focused[Color_border], 1823 term->pix_colors_focused[Color_border],
1696 term->pix_colors_focused[Color_border] 1824 term->pix_colors_focused[Color_border]
1697 1825
1826#endif
1827
1698void 1828void
1699XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0) 1829XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1700 C_ARGS: term->display->display, window, parent, x, y 1830 C_ARGS: term->xdisp, window, parent, x, y
1701 1831
1702void 1832void
1703XMapWindow (rxvt_term *term, Window window) 1833XMapWindow (rxvt_term *term, Window window)
1704 C_ARGS: term->display->display, window 1834 C_ARGS: term->xdisp, window
1705 1835
1706void 1836void
1707XUnmapWindow (rxvt_term *term, Window window) 1837XUnmapWindow (rxvt_term *term, Window window)
1708 C_ARGS: term->display->display, window 1838 C_ARGS: term->xdisp, window
1709 1839
1710void 1840void
1711XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height) 1841XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1712 C_ARGS: term->display->display, (Window)window, x, y, width, height 1842 C_ARGS: term->xdisp, window, x, y, width, height
1843
1844void
1845rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0)
1846 CODE:
1847{
1848 XWindowAttributes attr;
1849 XGetWindowAttributes (THIS->xdisp, window, &attr);
1850 XSelectInput (THIS->xdisp, window, attr.your_event_mask | add_events & ~del_events);
1851}
1852
1853void
1854rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y)
1855 PPCODE:
1856{
1857 int dx, dy;
1858 Window child;
1859
1860 if (XTranslateCoordinates (THIS->xdisp, src, dst, x, y, &dx, &dy, &child))
1861 {
1862 EXTEND (SP, 3);
1863 PUSHs (newSViv (dx));
1864 PUSHs (newSViv (dy));
1865 PUSHs (newSVuv (child));
1866 }
1867}
1713 1868
1714############################################################################# 1869#############################################################################
1715# urxvt::overlay 1870# urxvt::overlay
1716############################################################################# 1871#############################################################################
1717 1872

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines