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.72 by root, Wed Jan 18 08:33:34 2006 UTC vs.
Revision 1.90 by root, Sun Jan 22 20:39:47 2006 UTC

50#undef LINENO 50#undef LINENO
51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
52#undef ROW 52#undef ROW
53#define ROW(n) THIS->row_buf [LINENO (n)] 53#define ROW(n) THIS->row_buf [LINENO (n)]
54 54
55#define ENABLE_PERL_FRILLS 1 55typedef int CHAINED UNUSED;
56 56
57///////////////////////////////////////////////////////////////////////////// 57/////////////////////////////////////////////////////////////////////////////
58 58
59static wchar_t * 59static wchar_t *
60sv2wcs (SV *sv) 60sv2wcs (SV *sv)
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")
124
123struct perl_watcher 125struct perl_watcher
124{ 126{
125 SV *cbsv; 127 SV *cbsv;
126 HV *self; 128 HV *self;
127 129
128 perl_watcher () 130 perl_watcher ()
129 : cbsv (newSV (0)) 131 : cbsv (0)
130 { 132 {
131 } 133 }
132 134
133 ~perl_watcher () 135 ~perl_watcher ()
134 { 136 {
135 SvREFCNT_dec (cbsv); 137 SvREFCNT_dec (cbsv);
136 } 138 }
137 139
138 void cb (SV *cb) 140 void cb (SV *cb)
139 { 141 {
140 sv_setsv (cbsv, cb); 142 SvREFCNT_dec (cbsv);
143 cbsv = newSVsv (cb);
141 } 144 }
142 145
143 void invoke (const char *type, SV *self, int arg = -1); 146 void invoke (const char *type, SV *self, int arg = -1);
144}; 147};
145 148
169 if (SvTRUE (ERRSV)) 172 if (SvTRUE (ERRSV))
170 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV)); 173 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
171} 174}
172 175
173#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") 176#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
174#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") 177#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR (sv, "urxvt::timer")
175 178
176struct timer : time_watcher, perl_watcher 179struct timer : perl_watcher, time_watcher
177{ 180{
178 tstamp interval; 181 tstamp interval;
179 182
180 timer () 183 timer ()
181 : time_watcher (this, &timer::execute) 184 : time_watcher (this, &timer::execute)
190 invoke ("urxvt::timer", newSVtimer (this)); 193 invoke ("urxvt::timer", newSVtimer (this));
191 } 194 }
192}; 195};
193 196
194#define newSViow(iow) new_ref (iow->self, "urxvt::iow") 197#define newSViow(iow) new_ref (iow->self, "urxvt::iow")
195#define SvIOW(sv) (iow *)SvPTR (sv, "urxvt::iow") 198#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR (sv, "urxvt::iow")
196 199
197struct iow : io_watcher, perl_watcher 200struct iow : perl_watcher, io_watcher
198{ 201{
199 iow () 202 iow ()
200 : io_watcher (this, &iow::execute) 203 : io_watcher (this, &iow::execute)
201 { 204 {
202 } 205 }
205 { 208 {
206 invoke ("urxvt::iow", newSViow (this), revents); 209 invoke ("urxvt::iow", newSViow (this), revents);
207 } 210 }
208}; 211};
209 212
213#define newSViw(iw) new_ref (iw->self, "urxvt::iw")
214#define SvIW(sv) (iw *)(perl_watcher *)SvPTR (sv, "urxvt::iw")
215
216struct iw : perl_watcher, idle_watcher
217{
218 iw ()
219 : idle_watcher (this, &iw::execute)
220 {
221 }
222
223 void execute (idle_watcher &w)
224 {
225 invoke ("urxvt::iw", newSViw (this));
226 }
227};
228
229#define newSVpw(pw) new_ref (pw->self, "urxvt::pw")
230#define SvPW(sv) (pw *)(perl_watcher *)SvPTR (sv, "urxvt::pw")
231
232struct pw : perl_watcher, child_watcher
233{
234 pw ()
235 : child_watcher (this, &pw::execute)
236 {
237 }
238
239 void execute (child_watcher &w, int status)
240 {
241 invoke ("urxvt::pw", newSVpw (this), status);
242 }
243};
244
210///////////////////////////////////////////////////////////////////////////// 245/////////////////////////////////////////////////////////////////////////////
211 246
212#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 247#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
213 248
214struct overlay { 249struct overlay {
215 HV *self; 250 HV *self;
251 bool visible;
216 rxvt_term *THIS; 252 rxvt_term *THIS;
217 int x, y, w, h; 253 int x, y, w, h;
218 int border; 254 int border;
219 text_t **text; 255 text_t **text;
220 rend_t **rend; 256 rend_t **rend;
229 265
230 void set (int x, int y, SV *str, SV *rend); 266 void set (int x, int y, SV *str, SV *rend);
231}; 267};
232 268
233overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 269overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
234: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2) 270: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), visible(false)
235{ 271{
236 if (border == 2) 272 if (border == 2)
237 { 273 {
238 w += 2; 274 w += 2;
239 h += 2; 275 h += 2;
300} 336}
301 337
302void 338void
303overlay::show () 339overlay::show ()
304{ 340{
305 char key[33]; sprintf (key, "%32lx", (long)this); 341 if (visible)
342 return;
306 343
344 visible = true;
345
307 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); 346 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
308 hv_store (hv, key, 32, newSViv ((long)this), 0); 347 av_push (av, newSViv ((long)this));
309} 348}
310 349
311void 350void
312overlay::hide () 351overlay::hide ()
313{ 352{
353 if (!visible)
354 return;
355
356 visible = false;
357
314 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); 358 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
315 359
316 if (ovs) 360 int i;
361
362 for (i = AvFILL (av); i >= 0; i--)
363 if (SvIV (*av_fetch (av, i, 1)) == (long)this)
317 { 364 {
318 char key[33]; sprintf (key, "%32lx", (long)this);
319
320 HV *hv = (HV *)SvRV (*ovs);
321 hv_delete (hv, key, 32, G_DISCARD); 365 av_delete (av, i, G_DISCARD);
366 break;
322 } 367 }
368
369 for (; i < AvFILL (av); i++)
370 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0)));
371
372 av_pop (av);
323} 373}
324 374
325void overlay::swap () 375void overlay::swap ()
326{ 376{
327 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 377 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
367 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) 417 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
368 croak ("rend must be arrayref"); 418 croak ("rend must be arrayref");
369 419
370 AV *av = (AV *)SvRV (rend); 420 AV *av = (AV *)SvRV (rend);
371 421
372 for (int col = min (av_len (av) + 1, w - x - border); col--; ) 422 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
373 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 423 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
374 } 424 }
375 425
376 THIS->want_refresh = 1; 426 THIS->want_refresh = 1;
377} 427}
433 483
434 if (perl) 484 if (perl)
435 { 485 {
436 // runs outside of perls ENV 486 // runs outside of perls ENV
437 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 487 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
438 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 488 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0);
439 } 489 }
440} 490}
441 491
442static void 492static void
443ungrab (rxvt_term *THIS) 493ungrab (rxvt_term *THIS)
448 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 498 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
449 THIS->perl.grabtime = 0; 499 THIS->perl.grabtime = 0;
450 } 500 }
451} 501}
452 502
453static void
454swap_overlays (rxvt_term *term)
455{
456 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
457
458 if (HvKEYS (hv))
459 {
460 hv_iterinit (hv);
461
462 while (HE *he = hv_iternext (hv))
463 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
464 }
465}
466
467bool 503bool
468rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 504rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
469{ 505{
470 if (!perl || !term->perl.self) 506 if (!perl || !term->perl.self)
471 return false; 507 return false;
472 508
473 // pre-handling of some events 509 // pre-handling of some events
474 if (htype == HOOK_REFRESH_END) 510 if (htype == HOOK_REFRESH_END)
475 swap_overlays (term); 511 {
512 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
513
514 for (int i = 0; i <= AvFILL (av); i++)
515 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
516 }
476 517
477 swap (perl_environ, environ); 518 swap (perl_environ, environ);
478 519
479 bool event_consumed; 520 bool event_consumed;
480 521
535 XEvent *xe = va_arg (ap, XEvent *); 576 XEvent *xe = va_arg (ap, XEvent *);
536 HV *hv = newHV (); 577 HV *hv = newHV ();
537 578
538# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 579# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
539# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) 580# 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)
540# undef set 582# undef set
541 583
542 setiv (type, xe->type); 584 setiv (type, xe->type);
543 setiv (send_event, xe->xany.send_event); 585 setiv (send_event, xe->xany.send_event);
544 setiv (serial, xe->xany.serial); 586 setiv (serial, xe->xany.serial);
548 case KeyPress: 590 case KeyPress:
549 case KeyRelease: 591 case KeyRelease:
550 case ButtonPress: 592 case ButtonPress:
551 case ButtonRelease: 593 case ButtonRelease:
552 case MotionNotify: 594 case MotionNotify:
595 setuv (window, xe->xmotion.window);
596 setuv (root, xe->xmotion.root);
597 setuv (subwindow, xe->xmotion.subwindow);
553 setiv (time, xe->xmotion.time); 598 setuv (time, xe->xmotion.time);
554 setiv (x, xe->xmotion.x); 599 setiv (x, xe->xmotion.x);
555 setiv (y, xe->xmotion.y); 600 setiv (y, xe->xmotion.y);
556 setiv (row, xe->xmotion.y / term->fheight); 601 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
557 setiv (col, xe->xmotion.x / term->fwidth); 602 setiv (col, xe->xmotion.x / term->fwidth);
558 setiv (x_root, xe->xmotion.x_root); 603 setiv (x_root, xe->xmotion.x_root);
559 setiv (y_root, xe->xmotion.y_root); 604 setiv (y_root, xe->xmotion.y_root);
560 setiv (state, xe->xmotion.state); 605 setuv (state, xe->xmotion.state);
606
607 switch (xe->type)
608 {
609 case KeyPress:
610 case KeyRelease:
611 setuv (keycode, xe->xkey.keycode);
612 break;
613
614 case ButtonPress:
615 case ButtonRelease:
616 setuv (button, xe->xbutton.button);
617 break;
618
619 case MotionNotify:
620 setiv (is_hint, xe->xmotion.is_hint);
621 break;
622 }
623
561 break; 624 break;
562 }
563 625
626 case MapNotify:
627 case UnmapNotify:
628 case ConfigureNotify:
629 setuv (event, xe->xconfigure.event);
630 setuv (window, xe->xconfigure.window);
631
564 switch (xe->type) 632 switch (xe->type)
565 { 633 {
566 case KeyPress: 634 case ConfigureNotify:
567 case KeyRelease: 635 setiv (x, xe->xconfigure.x);
568 setiv (keycode, xe->xkey.keycode); 636 setiv (y, xe->xconfigure.y);
637 setiv (width, xe->xconfigure.width);
638 setiv (height, xe->xconfigure.height);
639 setuv (above, xe->xconfigure.above);
640 break;
641 }
642
569 break; 643 break;
570 644
571 case ButtonPress: 645 case PropertyNotify:
572 case ButtonRelease: 646 setuv (window, xe->xproperty.window);
573 setiv (button, xe->xbutton.button); 647 setuv (atom, xe->xproperty.atom);
648 setuv (time, xe->xproperty.time);
649 setiv (state, xe->xproperty.state);
574 break; 650 break;
575 651
576 case MotionNotify: 652 case ClientMessage:
577 setiv (is_hint, xe->xmotion.is_hint); 653 setuv (window, xe->xclient.window);
654 setuv (message_type, xe->xclient.message_type);
655 setuv (format, xe->xclient.format);
656 setuv (l0, xe->xclient.data.l[0]);
657 setuv (l1, xe->xclient.data.l[1]);
658 setuv (l2, xe->xclient.data.l[2]);
659 setuv (l3, xe->xclient.data.l[3]);
660 setuv (l4, xe->xclient.data.l[4]);
578 break; 661 break;
579 } 662 }
580 663
581 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 664 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
582 } 665 }
623 else 706 else
624 event_consumed = false; 707 event_consumed = false;
625 708
626 // post-handling of some events 709 // post-handling of some events
627 if (htype == HOOK_REFRESH_BEGIN) 710 if (htype == HOOK_REFRESH_BEGIN)
628 swap_overlays (term); 711 {
712 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
713
714 for (int i = AvFILL (av); i >= 0; i--)
715 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
716 }
629 else if (htype == HOOK_DESTROY) 717 else if (htype == HOOK_DESTROY)
630 { 718 {
631 clearSVptr ((SV *)term->perl.self); 719 clearSVptr ((SV *)term->perl.self);
632 SvREFCNT_dec ((SV *)term->perl.self); 720 SvREFCNT_dec ((SV *)term->perl.self);
633 } 721 }
840 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) 928 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
841 croak ("first argument to urxvt::term->_new must be arrayref"); 929 croak ("first argument to urxvt::term->_new must be arrayref");
842 930
843 rxvt_term *term = new rxvt_term; 931 rxvt_term *term = new rxvt_term;
844 932
845 term->argv = new stringvec; 933 stringvec *argv = new stringvec;
846 term->envv = new stringvec; 934 stringvec *envv = new stringvec;
847 935
848 for (int i = 1; i < items; i++) 936 for (int i = 1; i < items; i++)
849 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 937 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
850 938
851 AV *envv = (AV *)SvRV (ST (0)); 939 AV *env = (AV *)SvRV (ST (0));
852 for (int i = av_len (envv) + 1; i--; ) 940 for (int i = AvFILL (env) + 1; i--; )
853 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 941 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
854 942
855 term->envv->push_back (0); 943 envv->push_back (0);
856 944
857 bool success; 945 bool success;
858 946
859 try 947 try
860 { 948 {
861 success = term->init (term->argv->size (), term->argv->begin ()); 949 success = term->init (argv, envv);
862 } 950 }
863 catch (const class rxvt_failure_exception &e) 951 catch (const class rxvt_failure_exception &e)
864 { 952 {
865 success = false; 953 success = false;
866 } 954 }
878 RETVAL 966 RETVAL
879 967
880void 968void
881rxvt_term::destroy () 969rxvt_term::destroy ()
882 970
883#if ENABLE_PERL_FRILLS
884
885void
886rxvt_term::XListProperties (U32 window)
887 PPCODE:
888{
889 int count;
890 Atom *props = XListProperties (THIS->display->display, (Window)window, &count);
891
892 EXTEND (SP, count);
893 while (count--)
894 PUSHs (newSVuv ((U32)props [count]));
895
896 XFree (props);
897}
898
899void
900rxvt_term::XGetWindowProperty (U32 window, U32 property)
901 PPCODE:
902{
903 Atom type;
904 int format;
905 unsigned long nitems;
906 unsigned long bytes_after;
907 unsigned char *prop;
908 XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property,
909 0, 1<<30, 0, AnyPropertyType,
910 &type, &format, &nitems, &bytes_after, &prop);
911 if (type != None)
912 {
913 EXTEND (SP, 3);
914 PUSHs (newSVuv ((U32)type));
915 PUSHs (newSViv (format));
916 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
917 XFree (prop);
918 }
919}
920
921void
922rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data)
923 CODE:
924{
925 STRLEN len;
926 char *data_ = SvPVbyte (data, len);
927
928 XChangeProperty (THIS->display->display, (Window)window, (Atom)property,
929 type, format, PropModeReplace,
930 (unsigned char *)data, len * 8 / format);
931}
932
933void
934rxvt_term::XDeleteProperty (U32 window, U32 property)
935 CODE:
936 XDeleteProperty (THIS->display->display, (Window)window, (Atom)property);
937
938U32
939rxvt_term::DefaultRootWindow ()
940 CODE:
941 RETVAL = (U32)THIS->display->root;
942 OUTPUT:
943 RETVAL
944
945U32
946rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height)
947 CODE:
948 RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent,
949 x, y, width, height, 0,
950 THIS->pix_colors_focused[Color_border],
951 THIS->pix_colors_focused[Color_border]);
952 OUTPUT:
953 RETVAL
954
955void
956rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0)
957 CODE:
958 XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y);
959
960void
961rxvt_term::XMapWindow (U32 window)
962 CODE:
963 XMapWindow (THIS->display->display, (Window)window);
964
965void
966rxvt_term::XUnmapWindow (U32 window)
967 CODE:
968 XUnmapWindow (THIS->display->display, (Window)window);
969
970#endif
971
972void 971void
973rxvt_term::set_should_invoke (int htype, int inc) 972rxvt_term::set_should_invoke (int htype, int inc)
974 CODE: 973 CODE:
975 THIS->perl.should_invoke [htype] += inc; 974 THIS->perl.should_invoke [htype] += inc;
976 975
980 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 979 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
981 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 980 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
982 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 981 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
983 982
984bool 983bool
985rxvt_term::grab (U32 eventtime, int sync = 0) 984rxvt_term::grab (Time eventtime, int sync = 0)
986 CODE: 985 CODE:
987{ 986{
988 int mode = sync ? GrabModeSync : GrabModeAsync; 987 int mode = sync ? GrabModeSync : GrabModeAsync;
989 988
990 THIS->perl.grabtime = 0; 989 THIS->perl.grabtime = 0;
1082#define TERM_OFFSET_fbase TERM_OFFSET(fbase) 1081#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1083#define TERM_OFFSET_nrow TERM_OFFSET(nrow) 1082#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1084#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1083#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1085#define TERM_OFFSET_focus TERM_OFFSET(focus) 1084#define TERM_OFFSET_focus TERM_OFFSET(focus)
1086#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1085#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
1086#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth)
1087#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth)
1088#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace)
1087#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1089#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1088#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1090#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1089#define TERM_OFFSET_top_row TERM_OFFSET(top_row) 1091#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1090 1092
1091int 1093int
1098 fbase = TERM_OFFSET_fbase 1100 fbase = TERM_OFFSET_fbase
1099 nrow = TERM_OFFSET_nrow 1101 nrow = TERM_OFFSET_nrow
1100 ncol = TERM_OFFSET_ncol 1102 ncol = TERM_OFFSET_ncol
1101 focus = TERM_OFFSET_focus 1103 focus = TERM_OFFSET_focus
1102 mapped = TERM_OFFSET_mapped 1104 mapped = TERM_OFFSET_mapped
1105 int_bwidth = TERM_OFFSET_int_bwidth
1106 ext_bwidth = TERM_OFFSET_ext_bwidth
1107 lineSpace = TERM_OFFSET_lineSpace
1103 saveLines = TERM_OFFSET_saveLines 1108 saveLines = TERM_OFFSET_saveLines
1104 total_rows = TERM_OFFSET_total_rows 1109 total_rows = TERM_OFFSET_total_rows
1105 top_row = TERM_OFFSET_top_row 1110 top_row = TERM_OFFSET_top_row
1106 CODE: 1111 CODE:
1107 RETVAL = *(int *)((char *)THIS + ix); 1112 RETVAL = *(int *)((char *)THIS + ix);
1112rxvt_term::ModLevel3Mask () 1117rxvt_term::ModLevel3Mask ()
1113 ALIAS: 1118 ALIAS:
1114 ModLevel3Mask = 0 1119 ModLevel3Mask = 0
1115 ModMetaMask = 1 1120 ModMetaMask = 1
1116 ModNumLockMask = 2 1121 ModNumLockMask = 2
1122 current_screen = 3
1123 hidden_cursor = 4
1117 CODE: 1124 CODE:
1118 switch (ix) 1125 switch (ix)
1119 { 1126 {
1120 case 0: RETVAL = THIS->ModLevel3Mask; break; 1127 case 0: RETVAL = THIS->ModLevel3Mask; break;
1121 case 1: RETVAL = THIS->ModMetaMask; break; 1128 case 1: RETVAL = THIS->ModMetaMask; break;
1122 case 2: RETVAL = THIS->ModNumLockMask; break; 1129 case 2: RETVAL = THIS->ModNumLockMask; break;
1130 case 3: RETVAL = THIS->current_screen; break;
1131 case 4: RETVAL = THIS->hidden_cursor; break;
1123 } 1132 }
1124 OUTPUT: 1133 OUTPUT:
1125 RETVAL 1134 RETVAL
1126 1135
1127char * 1136char *
1165 if (events != EVENT_UNDEF) 1174 if (events != EVENT_UNDEF)
1166 THIS->pty_ev.set (events); 1175 THIS->pty_ev.set (events);
1167 OUTPUT: 1176 OUTPUT:
1168 RETVAL 1177 RETVAL
1169 1178
1170U32 1179int
1180rxvt_term::pty_fd ()
1181 CODE:
1182 RETVAL = THIS->pty->pty;
1183 OUTPUT:
1184 RETVAL
1185
1186Window
1171rxvt_term::parent () 1187rxvt_term::parent ()
1172 CODE: 1188 CODE:
1173 RETVAL = (U32)THIS->parent [0]; 1189 RETVAL = THIS->parent [0];
1174 OUTPUT: 1190 OUTPUT:
1175 RETVAL 1191 RETVAL
1176 1192
1177U32 1193Window
1178rxvt_term::vt () 1194rxvt_term::vt ()
1179 CODE: 1195 CODE:
1180 RETVAL = (U32)THIS->vt; 1196 RETVAL = THIS->vt;
1181 OUTPUT: 1197 OUTPUT:
1182 RETVAL 1198 RETVAL
1183 1199
1184void 1200void
1185rxvt_term::vt_emask_add (U32 emask) 1201rxvt_term::vt_emask_add (U32 emask)
1207} 1223}
1208 OUTPUT: 1224 OUTPUT:
1209 RETVAL 1225 RETVAL
1210 1226
1211void 1227void
1228rxvt_term::focus_in ()
1229
1230void
1231rxvt_term::focus_out ()
1232
1233void
1212rxvt_term::want_refresh () 1234rxvt_term::want_refresh ()
1213 CODE: 1235 CODE:
1214 THIS->want_refresh = 1; 1236 THIS->want_refresh = 1;
1215 1237
1216void 1238void
1238 { 1260 {
1239 wchar_t *wstr = sv2wcs (new_text); 1261 wchar_t *wstr = sv2wcs (new_text);
1240 1262
1241 int len = min (wcslen (wstr) - start_ofs, max_len); 1263 int len = min (wcslen (wstr) - start_ofs, max_len);
1242 1264
1243 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1265 if (start_col < 0 || start_col + len > THIS->ncol)
1244 { 1266 {
1245 free (wstr); 1267 free (wstr);
1246 croak ("new_text extends beyond horizontal margins"); 1268 croak ("new_text extends beyond horizontal margins");
1247 } 1269 }
1248 1270
1280 { 1302 {
1281 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1303 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1282 croak ("new_rend must be arrayref"); 1304 croak ("new_rend must be arrayref");
1283 1305
1284 AV *av = (AV *)SvRV (new_rend); 1306 AV *av = (AV *)SvRV (new_rend);
1285 int len = min (av_len (av) + 1 - start_ofs, max_len); 1307 int len = min (AvFILL (av) + 1 - start_ofs, max_len);
1286 1308
1287 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1309 if (start_col < 0 || start_col + len > THIS->ncol)
1288 croak ("new_rend array extends beyond horizontal margins"); 1310 croak ("new_rend array extends beyond horizontal margins");
1289 1311
1290 for (int col = start_col; col < start_col + len; col++) 1312 for (int col = start_col; col < start_col + len; col++)
1291 { 1313 {
1292 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; 1314 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1457 if (set) 1479 if (set)
1458 THIS->options |= optval; 1480 THIS->options |= optval;
1459 else 1481 else
1460 THIS->options &= ~optval; 1482 THIS->options &= ~optval;
1461 1483
1484 if (THIS->check_ev.is_active ()) // avoid doing this before START
1462 switch (optval) 1485 switch (optval)
1463 { 1486 {
1464 case Opt_skipBuiltinGlyphs: 1487 case Opt_skipBuiltinGlyphs:
1465 THIS->set_fonts (); 1488 THIS->set_fonts ();
1466 THIS->scr_remap_chars (); 1489 THIS->scr_remap_chars ();
1467 THIS->scr_touch (true); 1490 THIS->scr_touch (true);
1468 THIS->want_refresh = 1; 1491 THIS->want_refresh = 1;
1469 break; 1492 break;
1470 1493
1471 case Opt_cursorUnderline: 1494 case Opt_cursorUnderline:
1472 THIS->want_refresh = 1; 1495 THIS->want_refresh = 1;
1473 break; 1496 break;
1474 1497
1475# case Opt_scrollBar_floating: 1498# case Opt_scrollBar_floating:
1476# case Opt_scrollBar_right: 1499# case Opt_scrollBar_right:
1477# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1500# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1478# break; 1501# break;
1479 } 1502 }
1480 } 1503 }
1481} 1504}
1482 OUTPUT: 1505 OUTPUT:
1483 RETVAL 1506 RETVAL
1484 1507
1512 PUSHs (sv_2mortal (newSViv (rc.col))); 1535 PUSHs (sv_2mortal (newSViv (rc.col)));
1513 } 1536 }
1514 1537
1515 if (items == 3) 1538 if (items == 3)
1516 { 1539 {
1540 rc.row = SvIV (ST (1));
1541 rc.col = SvIV (ST (2));
1542
1543 if (ix == 2)
1544 {
1545 if (rc.col == 0)
1546 {
1547 // col == 0 means end of previous line
1548 rc.row--;
1549 rc.col = THIS->ncol;
1550 }
1551 else if (IN_RANGE_EXC (rc.row, THIS->top_row, THIS->nrow)
1552 && rc.col > ROW(rc.row).l)
1553 {
1554 // col >= length means while line and add newline
1555 rc.col = THIS->ncol;
1556 }
1557 }
1558
1559 clamp_it (rc.col, 0, THIS->ncol);
1517 rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1); 1560 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1518 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
1519 1561
1520 if (ix) 1562 if (ix)
1521 THIS->want_refresh = 1; 1563 THIS->want_refresh = 1;
1522 } 1564 }
1523} 1565}
1531 1573
1532#void 1574#void
1533#rxvt_term::selection_clear () 1575#rxvt_term::selection_clear ()
1534 1576
1535void 1577void
1536rxvt_term::selection_make (U32 eventtime, bool rect = false) 1578rxvt_term::selection_make (Time eventtime, bool rect = false)
1537 CODE: 1579 CODE:
1538 THIS->selection.op = SELECTION_CONT; 1580 THIS->selection.op = SELECTION_CONT;
1539 THIS->selection.rect = rect; 1581 THIS->selection.rect = rect;
1540 THIS->selection_make (eventtime); 1582 THIS->selection_make (eventtime);
1541 1583
1542int 1584int
1543rxvt_term::selection_grab (U32 eventtime) 1585rxvt_term::selection_grab (Time eventtime)
1544 1586
1545void 1587void
1546rxvt_term::selection (SV *newtext = 0) 1588rxvt_term::selection (SV *newtext = 0)
1547 PPCODE: 1589 PPCODE:
1548{ 1590{
1566void 1608void
1567rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) 1609rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1568 1610
1569void 1611void
1570rxvt_term::scr_bell () 1612rxvt_term::scr_bell ()
1613
1614void
1615rxvt_term::scr_change_screen (int screen)
1571 1616
1572void 1617void
1573rxvt_term::scr_add_lines (SV *string) 1618rxvt_term::scr_add_lines (SV *string)
1574 CODE: 1619 CODE:
1575{ 1620{
1616 o->self = (HV *)SvRV (RETVAL); 1661 o->self = (HV *)SvRV (RETVAL);
1617} 1662}
1618 OUTPUT: 1663 OUTPUT:
1619 RETVAL 1664 RETVAL
1620 1665
1666#############################################################################
1667# Various X Utility Functions
1668#############################################################################
1669
1670void
1671rxvt_term::XListProperties (Window window)
1672 PPCODE:
1673{
1674 int count;
1675 Atom *props = XListProperties (THIS->display->display, window, &count);
1676
1677 EXTEND (SP, count);
1678 while (count--)
1679 PUSHs (newSVuv ((U32)props [count]));
1680
1681 XFree (props);
1682}
1683
1684void
1685rxvt_term::XGetWindowProperty (Window window, Atom property)
1686 PPCODE:
1687{
1688 Atom type;
1689 int format;
1690 unsigned long nitems;
1691 unsigned long bytes_after;
1692 unsigned char *prop;
1693
1694 XGetWindowProperty (THIS->display->display, window, property,
1695 0, 1<<24, 0, AnyPropertyType,
1696 &type, &format, &nitems, &bytes_after, &prop);
1697
1698 if (type != None)
1699 {
1700 int elemsize = format == 16 ? sizeof (short)
1701 : format == 32 ? sizeof (long)
1702 : 1;
1703
1704 EXTEND (SP, 3);
1705 PUSHs (newSVuv ((U32)type));
1706 PUSHs (newSViv (format));
1707 PUSHs (newSVpvn ((char *)prop, nitems * elemsize));
1708 XFree (prop);
1709 }
1710}
1711
1712void
1713rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data)
1714 CODE:
1715{
1716 STRLEN len;
1717 char *data_ = SvPVbyte (data, len);
1718
1719 int elemsize = format == 16 ? sizeof (short)
1720 : format == 32 ? sizeof (long)
1721 : 1;
1722
1723 XChangeProperty (THIS->display->display, window, property,
1724 type, format, PropModeReplace,
1725 (unsigned char *)data_, len / elemsize);
1726 XSync (THIS->display->display, 0);
1727}
1728
1729Atom
1730XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1731 C_ARGS: term->display->display, atom_name, only_if_exists
1732
1733char *
1734XGetAtomName (rxvt_term *term, Atom atom)
1735 C_ARGS: term->display->display, atom
1736 CLEANUP:
1737 XFree (RETVAL);
1738
1739void
1740XDeleteProperty (rxvt_term *term, Window window, Atom property)
1741 C_ARGS: term->display->display, window, property
1742
1743Window
1744rxvt_term::DefaultRootWindow ()
1745 CODE:
1746 RETVAL = THIS->display->root;
1747 OUTPUT:
1748 RETVAL
1749
1750#if 0
1751
1752Window
1753XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1754 C_ARGS: term->display->display, (Window)parent,
1755 x, y, width, height, 0,
1756 term->pix_colors_focused[Color_border],
1757 term->pix_colors_focused[Color_border]
1758
1759#endif
1760
1761void
1762XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1763 C_ARGS: term->display->display, window, parent, x, y
1764
1765void
1766XMapWindow (rxvt_term *term, Window window)
1767 C_ARGS: term->display->display, window
1768
1769void
1770XUnmapWindow (rxvt_term *term, Window window)
1771 C_ARGS: term->display->display, window
1772
1773void
1774XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1775 C_ARGS: term->display->display, window, x, y, width, height
1776
1777void
1778rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0)
1779 CODE:
1780{
1781 XWindowAttributes attr;
1782 XGetWindowAttributes (THIS->display->display, window, &attr);
1783 XSelectInput (THIS->display->display, window, attr.your_event_mask | add_events & ~del_events);
1784}
1785
1786void
1787rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y)
1788 PPCODE:
1789{
1790 int dx, dy;
1791 Window child;
1792
1793 if (XTranslateCoordinates (THIS->display->display, src, dst, x, y, &dx, &dy, &child))
1794 {
1795 EXTEND (SP, 3);
1796 PUSHs (newSViv (dx));
1797 PUSHs (newSViv (dy));
1798 PUSHs (newSVuv (child));
1799 }
1800}
1801
1802#############################################################################
1803# urxvt::overlay
1804#############################################################################
1805
1621MODULE = urxvt PACKAGE = urxvt::overlay 1806MODULE = urxvt PACKAGE = urxvt::overlay
1622 1807
1623void 1808void
1624overlay::set (int x, int y, SV *text, SV *rend = 0) 1809overlay::set (int x, int y, SV *text, SV *rend = 0)
1625 1810
1629void 1814void
1630overlay::hide () 1815overlay::hide ()
1631 1816
1632void 1817void
1633overlay::DESTROY () 1818overlay::DESTROY ()
1819
1820#############################################################################
1821# urxvt::watcher
1822#############################################################################
1823
1824MODULE = urxvt PACKAGE = urxvt::watcher
1825
1826CHAINED
1827perl_watcher::cb (SV *cb)
1828 CODE:
1829 THIS->cb (cb);
1830 OUTPUT:
1831 RETVAL
1832
1833#############################################################################
1834# urxvt::timer
1835#############################################################################
1634 1836
1635MODULE = urxvt PACKAGE = urxvt::timer 1837MODULE = urxvt PACKAGE = urxvt::timer
1636 1838
1637SV * 1839SV *
1638timer::new () 1840timer::new ()
1639 CODE: 1841 CODE:
1640 timer *w = new timer; 1842 timer *w = new timer;
1641 w->start (NOW); 1843 w->start (NOW);
1642 RETVAL = newSVptr ((void *)w, "urxvt::timer"); 1844 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::timer");
1643 w->self = (HV *)SvRV (RETVAL); 1845 w->self = (HV *)SvRV (RETVAL);
1644 OUTPUT:
1645 RETVAL
1646
1647timer *
1648timer::cb (SV *cb)
1649 CODE:
1650 THIS->cb (cb);
1651 RETVAL = THIS;
1652 OUTPUT: 1846 OUTPUT:
1653 RETVAL 1847 RETVAL
1654 1848
1655NV 1849NV
1656timer::at () 1850timer::at ()
1657 CODE: 1851 CODE:
1658 RETVAL = THIS->at; 1852 RETVAL = THIS->at;
1659 OUTPUT: 1853 OUTPUT:
1660 RETVAL 1854 RETVAL
1661 1855
1662timer * 1856CHAINED
1663timer::interval (NV interval) 1857timer::interval (NV interval)
1664 CODE: 1858 CODE:
1665 THIS->interval = interval; 1859 THIS->interval = interval;
1860 OUTPUT:
1666 RETVAL = THIS; 1861 RETVAL
1667 OUTPUT:
1668 RETVAL
1669 1862
1670timer * 1863CHAINED
1671timer::set (NV tstamp) 1864timer::set (NV tstamp)
1672 CODE: 1865 CODE:
1673 THIS->set (tstamp); 1866 THIS->set (tstamp);
1867 OUTPUT:
1674 RETVAL = THIS; 1868 RETVAL
1675 OUTPUT:
1676 RETVAL
1677 1869
1678timer * 1870CHAINED
1679timer::start (NV tstamp = THIS->at) 1871timer::start (NV tstamp = THIS->at)
1680 CODE: 1872 CODE:
1681 THIS->start (tstamp); 1873 THIS->start (tstamp);
1874 OUTPUT:
1682 RETVAL = THIS; 1875 RETVAL
1683 OUTPUT:
1684 RETVAL
1685 1876
1686timer * 1877CHAINED
1878timer::after (NV delay)
1879 CODE:
1880 THIS->start (NOW + delay);
1881 OUTPUT:
1882 RETVAL
1883
1884CHAINED
1687timer::stop () 1885timer::stop ()
1688 CODE: 1886 CODE:
1689 THIS->stop (); 1887 THIS->stop ();
1690 RETVAL = THIS;
1691 OUTPUT: 1888 OUTPUT:
1692 RETVAL 1889 RETVAL
1693 1890
1694void 1891void
1695timer::DESTROY () 1892timer::DESTROY ()
1893
1894#############################################################################
1895# urxvt::iow
1896#############################################################################
1696 1897
1697MODULE = urxvt PACKAGE = urxvt::iow 1898MODULE = urxvt PACKAGE = urxvt::iow
1698 1899
1699SV * 1900SV *
1700iow::new () 1901iow::new ()
1701 CODE: 1902 CODE:
1702 iow *w = new iow; 1903 iow *w = new iow;
1703 RETVAL = newSVptr ((void *)w, "urxvt::iow"); 1904 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iow");
1704 w->self = (HV *)SvRV (RETVAL); 1905 w->self = (HV *)SvRV (RETVAL);
1705 OUTPUT: 1906 OUTPUT:
1706 RETVAL 1907 RETVAL
1707 1908
1708iow * 1909CHAINED
1709iow::cb (SV *cb)
1710 CODE:
1711 THIS->cb (cb);
1712 RETVAL = THIS;
1713 OUTPUT:
1714 RETVAL
1715
1716iow *
1717iow::fd (int fd) 1910iow::fd (int fd)
1718 CODE: 1911 CODE:
1719 THIS->fd = fd; 1912 THIS->fd = fd;
1913 OUTPUT:
1720 RETVAL = THIS; 1914 RETVAL
1721 OUTPUT:
1722 RETVAL
1723 1915
1724iow * 1916CHAINED
1725iow::events (short events) 1917iow::events (short events)
1726 CODE: 1918 CODE:
1727 THIS->events = events; 1919 THIS->events = events;
1920 OUTPUT:
1728 RETVAL = THIS; 1921 RETVAL
1729 OUTPUT:
1730 RETVAL
1731 1922
1732iow * 1923CHAINED
1733iow::start () 1924iow::start ()
1734 CODE: 1925 CODE:
1735 THIS->start (); 1926 THIS->start ();
1927 OUTPUT:
1736 RETVAL = THIS; 1928 RETVAL
1737 OUTPUT:
1738 RETVAL
1739 1929
1740iow * 1930CHAINED
1741iow::stop () 1931iow::stop ()
1742 CODE: 1932 CODE:
1743 THIS->stop (); 1933 THIS->stop ();
1744 RETVAL = THIS;
1745 OUTPUT: 1934 OUTPUT:
1746 RETVAL 1935 RETVAL
1747 1936
1748void 1937void
1749iow::DESTROY () 1938iow::DESTROY ()
1750 1939
1940#############################################################################
1941# urxvt::iw
1942#############################################################################
1751 1943
1944MODULE = urxvt PACKAGE = urxvt::iw
1945
1946SV *
1947iw::new ()
1948 CODE:
1949 iw *w = new iw;
1950 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iw");
1951 w->self = (HV *)SvRV (RETVAL);
1952 OUTPUT:
1953 RETVAL
1954
1955CHAINED
1956iw::start ()
1957 CODE:
1958 THIS->start ();
1959 OUTPUT:
1960 RETVAL
1961
1962CHAINED
1963iw::stop ()
1964 CODE:
1965 THIS->stop ();
1966 OUTPUT:
1967 RETVAL
1968
1969void
1970iw::DESTROY ()
1971
1972#############################################################################
1973# urxvt::pw
1974#############################################################################
1975
1976MODULE = urxvt PACKAGE = urxvt::pw
1977
1978SV *
1979pw::new ()
1980 CODE:
1981 pw *w = new pw;
1982 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::pw");
1983 w->self = (HV *)SvRV (RETVAL);
1984 OUTPUT:
1985 RETVAL
1986
1987CHAINED
1988pw::start (int pid)
1989 CODE:
1990 THIS->start (pid);
1991 OUTPUT:
1992 RETVAL
1993
1994CHAINED
1995pw::stop ()
1996 CODE:
1997 THIS->stop ();
1998 OUTPUT:
1999 RETVAL
2000
2001void
2002pw::DESTROY ()
2003
2004

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines