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.71 by root, Tue Jan 17 16:22:41 2006 UTC vs.
Revision 1.89 by root, Sun Jan 22 11:57:06 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}
402 perl_environ = rxvt_environ; 452 perl_environ = rxvt_environ;
403 swap (perl_environ, environ); 453 swap (perl_environ, environ);
404 454
405 char *argv[] = { 455 char *argv[] = {
406 "", 456 "",
407 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 457 "-e"
458 "BEGIN {"
459 " urxvt->bootstrap;"
460 " unshift @INC, '" LIBDIR "';"
461 "}"
462 ""
463 "use urxvt;"
408 }; 464 };
409 465
410 perl = perl_alloc (); 466 perl = perl_alloc ();
411 perl_construct (perl); 467 perl_construct (perl);
412 468
427 483
428 if (perl) 484 if (perl)
429 { 485 {
430 // runs outside of perls ENV 486 // runs outside of perls ENV
431 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 487 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
432 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);
433 } 489 }
434} 490}
435 491
436static void 492static void
437ungrab (rxvt_term *THIS) 493ungrab (rxvt_term *THIS)
442 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 498 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
443 THIS->perl.grabtime = 0; 499 THIS->perl.grabtime = 0;
444 } 500 }
445} 501}
446 502
447static void
448swap_overlays (rxvt_term *term)
449{
450 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
451
452 if (HvKEYS (hv))
453 {
454 hv_iterinit (hv);
455
456 while (HE *he = hv_iternext (hv))
457 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
458 }
459}
460
461bool 503bool
462rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 504rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
463{ 505{
464 if (!perl || !term->perl.self) 506 if (!perl || !term->perl.self)
465 return false; 507 return false;
466 508
467 // pre-handling of some events 509 // pre-handling of some events
468 if (htype == HOOK_REFRESH_END) 510 if (htype == HOOK_REFRESH_END)
469 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 }
470 517
471 swap (perl_environ, environ); 518 swap (perl_environ, environ);
472 519
473 bool event_consumed; 520 bool event_consumed;
474 521
529 XEvent *xe = va_arg (ap, XEvent *); 576 XEvent *xe = va_arg (ap, XEvent *);
530 HV *hv = newHV (); 577 HV *hv = newHV ();
531 578
532# 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)
533# 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)
534# undef set 582# undef set
535 583
536 setiv (type, xe->type); 584 setiv (type, xe->type);
537 setiv (send_event, xe->xany.send_event); 585 setiv (send_event, xe->xany.send_event);
538 setiv (serial, xe->xany.serial); 586 setiv (serial, xe->xany.serial);
542 case KeyPress: 590 case KeyPress:
543 case KeyRelease: 591 case KeyRelease:
544 case ButtonPress: 592 case ButtonPress:
545 case ButtonRelease: 593 case ButtonRelease:
546 case MotionNotify: 594 case MotionNotify:
595 setuv (window, xe->xmotion.window);
596 setuv (root, xe->xmotion.root);
597 setuv (subwindow, xe->xmotion.subwindow);
547 setiv (time, xe->xmotion.time); 598 setuv (time, xe->xmotion.time);
548 setiv (x, xe->xmotion.x); 599 setiv (x, xe->xmotion.x);
549 setiv (y, xe->xmotion.y); 600 setiv (y, xe->xmotion.y);
550 setiv (row, xe->xmotion.y / term->fheight); 601 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
551 setiv (col, xe->xmotion.x / term->fwidth); 602 setiv (col, xe->xmotion.x / term->fwidth);
552 setiv (x_root, xe->xmotion.x_root); 603 setiv (x_root, xe->xmotion.x_root);
553 setiv (y_root, xe->xmotion.y_root); 604 setiv (y_root, xe->xmotion.y_root);
554 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
555 break; 624 break;
556 }
557 625
626 case MapNotify:
627 case UnmapNotify:
628 case ConfigureNotify:
629 setuv (event, xe->xconfigure.event);
630 setuv (window, xe->xconfigure.window);
631
558 switch (xe->type) 632 switch (xe->type)
559 { 633 {
560 case KeyPress: 634 case ConfigureNotify:
561 case KeyRelease: 635 setiv (x, xe->xconfigure.x);
562 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
563 break; 643 break;
564 644
565 case ButtonPress: 645 case PropertyNotify:
566 case ButtonRelease: 646 setuv (window, xe->xproperty.window);
567 setiv (button, xe->xbutton.button); 647 setuv (atom, xe->xproperty.atom);
648 setuv (time, xe->xproperty.time);
649 setiv (state, xe->xproperty.state);
568 break; 650 break;
569 651
570 case MotionNotify: 652 case ClientMessage:
571 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]);
572 break; 661 break;
573 } 662 }
574 663
575 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 664 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
576 } 665 }
617 else 706 else
618 event_consumed = false; 707 event_consumed = false;
619 708
620 // post-handling of some events 709 // post-handling of some events
621 if (htype == HOOK_REFRESH_BEGIN) 710 if (htype == HOOK_REFRESH_BEGIN)
622 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 }
623 else if (htype == HOOK_DESTROY) 717 else if (htype == HOOK_DESTROY)
624 { 718 {
625 clearSVptr ((SV *)term->perl.self); 719 clearSVptr ((SV *)term->perl.self);
626 SvREFCNT_dec ((SV *)term->perl.self); 720 SvREFCNT_dec ((SV *)term->perl.self);
627 } 721 }
834 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)
835 croak ("first argument to urxvt::term->_new must be arrayref"); 929 croak ("first argument to urxvt::term->_new must be arrayref");
836 930
837 rxvt_term *term = new rxvt_term; 931 rxvt_term *term = new rxvt_term;
838 932
839 term->argv = new stringvec; 933 stringvec *argv = new stringvec;
840 term->envv = new stringvec; 934 stringvec *envv = new stringvec;
841 935
842 for (int i = 1; i < items; i++) 936 for (int i = 1; i < items; i++)
843 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 937 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
844 938
845 AV *envv = (AV *)SvRV (ST (0)); 939 AV *env = (AV *)SvRV (ST (0));
846 for (int i = av_len (envv) + 1; i--; ) 940 for (int i = AvFILL (env) + 1; i--; )
847 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 941 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
848 942
849 term->envv->push_back (0); 943 envv->push_back (0);
850 944
851 bool success; 945 bool success;
852 946
853 try 947 try
854 { 948 {
855 success = term->init (term->argv->size (), term->argv->begin ()); 949 success = term->init (argv, envv);
856 } 950 }
857 catch (const class rxvt_failure_exception &e) 951 catch (const class rxvt_failure_exception &e)
858 { 952 {
859 success = false; 953 success = false;
860 } 954 }
872 RETVAL 966 RETVAL
873 967
874void 968void
875rxvt_term::destroy () 969rxvt_term::destroy ()
876 970
877#if ENABLE_PERL_FRILLS
878
879void
880rxvt_term::XListProperties (U32 window)
881 PPCODE:
882{
883 int count;
884 Atom *props = XListProperties (THIS->display->display, (Window)window, &count);
885
886 EXTEND (SP, count);
887 while (count--)
888 PUSHs (newSVuv ((U32)props [count]));
889
890 XFree (props);
891}
892
893void
894rxvt_term::XGetWindowProperty (U32 window, U32 property)
895 PPCODE:
896{
897 Atom type;
898 int format;
899 unsigned long nitems;
900 unsigned long bytes_after;
901 unsigned char *prop;
902 XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property,
903 0, 1<<30, 0, AnyPropertyType,
904 &type, &format, &nitems, &bytes_after, &prop);
905 if (type != None)
906 {
907 EXTEND (SP, 3);
908 PUSHs (newSVuv ((U32)type));
909 PUSHs (newSViv (format));
910 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
911 XFree (prop);
912 }
913}
914
915void
916rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data)
917 CODE:
918{
919 STRLEN len;
920 char *data_ = SvPVbyte (data, len);
921
922 XChangeProperty (THIS->display->display, (Window)window, (Atom)property,
923 type, format, PropModeReplace,
924 (unsigned char *)data, len * 8 / format);
925}
926
927void
928rxvt_term::XDeleteProperty (U32 window, U32 property)
929 CODE:
930 XDeleteProperty (THIS->display->display, (Window)window, (Atom)property);
931
932U32
933rxvt_term::DefaultRootWindow ()
934 CODE:
935 RETVAL = (U32)THIS->display->root;
936 OUTPUT:
937 RETVAL
938
939U32
940rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height)
941 CODE:
942 RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent,
943 x, y, width, height, 0,
944 THIS->pix_colors_focused[Color_border],
945 THIS->pix_colors_focused[Color_border]);
946 OUTPUT:
947 RETVAL
948
949void
950rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0)
951 CODE:
952 XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y);
953
954void
955rxvt_term::XMapWindow (U32 window)
956 CODE:
957 XMapWindow (THIS->display->display, (Window)window);
958
959void
960rxvt_term::XUnmapWindow (U32 window)
961 CODE:
962 XUnmapWindow (THIS->display->display, (Window)window);
963
964#endif
965
966void 971void
967rxvt_term::set_should_invoke (int htype, int inc) 972rxvt_term::set_should_invoke (int htype, int inc)
968 CODE: 973 CODE:
969 THIS->perl.should_invoke [htype] += inc; 974 THIS->perl.should_invoke [htype] += inc;
970 975
974 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 979 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
975 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 980 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
976 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 981 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
977 982
978bool 983bool
979rxvt_term::grab (U32 eventtime, int sync = 0) 984rxvt_term::grab (Time eventtime, int sync = 0)
980 CODE: 985 CODE:
981{ 986{
982 int mode = sync ? GrabModeSync : GrabModeAsync; 987 int mode = sync ? GrabModeSync : GrabModeAsync;
983 988
984 THIS->perl.grabtime = 0; 989 THIS->perl.grabtime = 0;
1076#define TERM_OFFSET_fbase TERM_OFFSET(fbase) 1081#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1077#define TERM_OFFSET_nrow TERM_OFFSET(nrow) 1082#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1078#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1083#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1079#define TERM_OFFSET_focus TERM_OFFSET(focus) 1084#define TERM_OFFSET_focus TERM_OFFSET(focus)
1080#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)
1081#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1089#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1082#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1090#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1083#define TERM_OFFSET_top_row TERM_OFFSET(top_row) 1091#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1084 1092
1085int 1093int
1092 fbase = TERM_OFFSET_fbase 1100 fbase = TERM_OFFSET_fbase
1093 nrow = TERM_OFFSET_nrow 1101 nrow = TERM_OFFSET_nrow
1094 ncol = TERM_OFFSET_ncol 1102 ncol = TERM_OFFSET_ncol
1095 focus = TERM_OFFSET_focus 1103 focus = TERM_OFFSET_focus
1096 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
1097 saveLines = TERM_OFFSET_saveLines 1108 saveLines = TERM_OFFSET_saveLines
1098 total_rows = TERM_OFFSET_total_rows 1109 total_rows = TERM_OFFSET_total_rows
1099 top_row = TERM_OFFSET_top_row 1110 top_row = TERM_OFFSET_top_row
1100 CODE: 1111 CODE:
1101 RETVAL = *(int *)((char *)THIS + ix); 1112 RETVAL = *(int *)((char *)THIS + ix);
1106rxvt_term::ModLevel3Mask () 1117rxvt_term::ModLevel3Mask ()
1107 ALIAS: 1118 ALIAS:
1108 ModLevel3Mask = 0 1119 ModLevel3Mask = 0
1109 ModMetaMask = 1 1120 ModMetaMask = 1
1110 ModNumLockMask = 2 1121 ModNumLockMask = 2
1122 current_screen = 3
1123 hidden_cursor = 4
1111 CODE: 1124 CODE:
1112 switch (ix) 1125 switch (ix)
1113 { 1126 {
1114 case 0: RETVAL = THIS->ModLevel3Mask; break; 1127 case 0: RETVAL = THIS->ModLevel3Mask; break;
1115 case 1: RETVAL = THIS->ModMetaMask; break; 1128 case 1: RETVAL = THIS->ModMetaMask; break;
1116 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;
1117 } 1132 }
1118 OUTPUT: 1133 OUTPUT:
1119 RETVAL 1134 RETVAL
1120 1135
1121char * 1136char *
1159 if (events != EVENT_UNDEF) 1174 if (events != EVENT_UNDEF)
1160 THIS->pty_ev.set (events); 1175 THIS->pty_ev.set (events);
1161 OUTPUT: 1176 OUTPUT:
1162 RETVAL 1177 RETVAL
1163 1178
1164U32 1179Window
1165rxvt_term::parent () 1180rxvt_term::parent ()
1166 CODE: 1181 CODE:
1167 RETVAL = (U32)THIS->parent [0]; 1182 RETVAL = THIS->parent [0];
1168 OUTPUT: 1183 OUTPUT:
1169 RETVAL 1184 RETVAL
1170 1185
1171U32 1186Window
1172rxvt_term::vt () 1187rxvt_term::vt ()
1173 CODE: 1188 CODE:
1174 RETVAL = (U32)THIS->vt; 1189 RETVAL = THIS->vt;
1175 OUTPUT: 1190 OUTPUT:
1176 RETVAL 1191 RETVAL
1177 1192
1178void 1193void
1179rxvt_term::vt_emask_add (U32 emask) 1194rxvt_term::vt_emask_add (U32 emask)
1201} 1216}
1202 OUTPUT: 1217 OUTPUT:
1203 RETVAL 1218 RETVAL
1204 1219
1205void 1220void
1221rxvt_term::focus_in ()
1222
1223void
1224rxvt_term::focus_out ()
1225
1226void
1206rxvt_term::want_refresh () 1227rxvt_term::want_refresh ()
1207 CODE: 1228 CODE:
1208 THIS->want_refresh = 1; 1229 THIS->want_refresh = 1;
1209 1230
1210void 1231void
1232 { 1253 {
1233 wchar_t *wstr = sv2wcs (new_text); 1254 wchar_t *wstr = sv2wcs (new_text);
1234 1255
1235 int len = min (wcslen (wstr) - start_ofs, max_len); 1256 int len = min (wcslen (wstr) - start_ofs, max_len);
1236 1257
1237 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1258 if (start_col < 0 || start_col + len > THIS->ncol)
1238 { 1259 {
1239 free (wstr); 1260 free (wstr);
1240 croak ("new_text extends beyond horizontal margins"); 1261 croak ("new_text extends beyond horizontal margins");
1241 } 1262 }
1242 1263
1274 { 1295 {
1275 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1296 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1276 croak ("new_rend must be arrayref"); 1297 croak ("new_rend must be arrayref");
1277 1298
1278 AV *av = (AV *)SvRV (new_rend); 1299 AV *av = (AV *)SvRV (new_rend);
1279 int len = min (av_len (av) + 1 - start_ofs, max_len); 1300 int len = min (AvFILL (av) + 1 - start_ofs, max_len);
1280 1301
1281 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1302 if (start_col < 0 || start_col + len > THIS->ncol)
1282 croak ("new_rend array extends beyond horizontal margins"); 1303 croak ("new_rend array extends beyond horizontal margins");
1283 1304
1284 for (int col = start_col; col < start_col + len; col++) 1305 for (int col = start_col; col < start_col + len; col++)
1285 { 1306 {
1286 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; 1307 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1451 if (set) 1472 if (set)
1452 THIS->options |= optval; 1473 THIS->options |= optval;
1453 else 1474 else
1454 THIS->options &= ~optval; 1475 THIS->options &= ~optval;
1455 1476
1477 if (THIS->check_ev.is_active ()) // avoid doing this before START
1456 switch (optval) 1478 switch (optval)
1457 { 1479 {
1458 case Opt_skipBuiltinGlyphs: 1480 case Opt_skipBuiltinGlyphs:
1459 THIS->set_fonts (); 1481 THIS->set_fonts ();
1460 THIS->scr_remap_chars (); 1482 THIS->scr_remap_chars ();
1461 THIS->scr_touch (true); 1483 THIS->scr_touch (true);
1462 THIS->want_refresh = 1; 1484 THIS->want_refresh = 1;
1463 break; 1485 break;
1464 1486
1465 case Opt_cursorUnderline: 1487 case Opt_cursorUnderline:
1466 THIS->want_refresh = 1; 1488 THIS->want_refresh = 1;
1467 break; 1489 break;
1468 1490
1469# case Opt_scrollBar_floating: 1491# case Opt_scrollBar_floating:
1470# case Opt_scrollBar_right: 1492# case Opt_scrollBar_right:
1471# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1493# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1472# break; 1494# break;
1473 } 1495 }
1474 } 1496 }
1475} 1497}
1476 OUTPUT: 1498 OUTPUT:
1477 RETVAL 1499 RETVAL
1478 1500
1506 PUSHs (sv_2mortal (newSViv (rc.col))); 1528 PUSHs (sv_2mortal (newSViv (rc.col)));
1507 } 1529 }
1508 1530
1509 if (items == 3) 1531 if (items == 3)
1510 { 1532 {
1533 rc.row = SvIV (ST (1));
1534 rc.col = SvIV (ST (2));
1535
1536 if (ix == 2)
1537 {
1538 if (rc.col == 0)
1539 {
1540 // col == 0 means end of previous line
1541 rc.row--;
1542 rc.col = THIS->ncol;
1543 }
1544 else if (IN_RANGE_EXC (rc.row, THIS->top_row, THIS->nrow)
1545 && rc.col > ROW(rc.row).l)
1546 {
1547 // col >= length means while line and add newline
1548 rc.col = THIS->ncol;
1549 }
1550 }
1551
1552 clamp_it (rc.col, 0, THIS->ncol);
1511 rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1); 1553 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1512 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
1513 1554
1514 if (ix) 1555 if (ix)
1515 THIS->want_refresh = 1; 1556 THIS->want_refresh = 1;
1516 } 1557 }
1517} 1558}
1525 1566
1526#void 1567#void
1527#rxvt_term::selection_clear () 1568#rxvt_term::selection_clear ()
1528 1569
1529void 1570void
1530rxvt_term::selection_make (U32 eventtime, bool rect = false) 1571rxvt_term::selection_make (Time eventtime, bool rect = false)
1531 CODE: 1572 CODE:
1532 THIS->selection.op = SELECTION_CONT; 1573 THIS->selection.op = SELECTION_CONT;
1533 THIS->selection.rect = rect; 1574 THIS->selection.rect = rect;
1534 THIS->selection_make (eventtime); 1575 THIS->selection_make (eventtime);
1535 1576
1536int 1577int
1537rxvt_term::selection_grab (U32 eventtime) 1578rxvt_term::selection_grab (Time eventtime)
1538 1579
1539void 1580void
1540rxvt_term::selection (SV *newtext = 0) 1581rxvt_term::selection (SV *newtext = 0)
1541 PPCODE: 1582 PPCODE:
1542{ 1583{
1560void 1601void
1561rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) 1602rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1562 1603
1563void 1604void
1564rxvt_term::scr_bell () 1605rxvt_term::scr_bell ()
1606
1607void
1608rxvt_term::scr_change_screen (int screen)
1565 1609
1566void 1610void
1567rxvt_term::scr_add_lines (SV *string) 1611rxvt_term::scr_add_lines (SV *string)
1568 CODE: 1612 CODE:
1569{ 1613{
1610 o->self = (HV *)SvRV (RETVAL); 1654 o->self = (HV *)SvRV (RETVAL);
1611} 1655}
1612 OUTPUT: 1656 OUTPUT:
1613 RETVAL 1657 RETVAL
1614 1658
1659#############################################################################
1660# Various X Utility Functions
1661#############################################################################
1662
1663void
1664rxvt_term::XListProperties (Window window)
1665 PPCODE:
1666{
1667 int count;
1668 Atom *props = XListProperties (THIS->display->display, window, &count);
1669
1670 EXTEND (SP, count);
1671 while (count--)
1672 PUSHs (newSVuv ((U32)props [count]));
1673
1674 XFree (props);
1675}
1676
1677void
1678rxvt_term::XGetWindowProperty (Window window, Atom property)
1679 PPCODE:
1680{
1681 Atom type;
1682 int format;
1683 unsigned long nitems;
1684 unsigned long bytes_after;
1685 unsigned char *prop;
1686
1687 XGetWindowProperty (THIS->display->display, window, property,
1688 0, 1<<24, 0, AnyPropertyType,
1689 &type, &format, &nitems, &bytes_after, &prop);
1690
1691 if (type != None)
1692 {
1693 int elemsize = format == 16 ? sizeof (short)
1694 : format == 32 ? sizeof (long)
1695 : 1;
1696
1697 EXTEND (SP, 3);
1698 PUSHs (newSVuv ((U32)type));
1699 PUSHs (newSViv (format));
1700 PUSHs (newSVpvn ((char *)prop, nitems * elemsize));
1701 XFree (prop);
1702 }
1703}
1704
1705void
1706rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data)
1707 CODE:
1708{
1709 STRLEN len;
1710 char *data_ = SvPVbyte (data, len);
1711
1712 int elemsize = format == 16 ? sizeof (short)
1713 : format == 32 ? sizeof (long)
1714 : 1;
1715
1716 XChangeProperty (THIS->display->display, window, property,
1717 type, format, PropModeReplace,
1718 (unsigned char *)data_, len / elemsize);
1719 XSync (THIS->display->display, 0);
1720}
1721
1722Atom
1723XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1724 C_ARGS: term->display->display, atom_name, only_if_exists
1725
1726char *
1727XGetAtomName (rxvt_term *term, Atom atom)
1728 C_ARGS: term->display->display, atom
1729 CLEANUP:
1730 XFree (RETVAL);
1731
1732void
1733XDeleteProperty (rxvt_term *term, Window window, Atom property)
1734 C_ARGS: term->display->display, window, property
1735
1736Window
1737rxvt_term::DefaultRootWindow ()
1738 CODE:
1739 RETVAL = THIS->display->root;
1740 OUTPUT:
1741 RETVAL
1742
1743#if 0
1744
1745Window
1746XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1747 C_ARGS: term->display->display, (Window)parent,
1748 x, y, width, height, 0,
1749 term->pix_colors_focused[Color_border],
1750 term->pix_colors_focused[Color_border]
1751
1752#endif
1753
1754void
1755XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1756 C_ARGS: term->display->display, window, parent, x, y
1757
1758void
1759XMapWindow (rxvt_term *term, Window window)
1760 C_ARGS: term->display->display, window
1761
1762void
1763XUnmapWindow (rxvt_term *term, Window window)
1764 C_ARGS: term->display->display, window
1765
1766void
1767XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1768 C_ARGS: term->display->display, window, x, y, width, height
1769
1770void
1771rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0)
1772 CODE:
1773{
1774 XWindowAttributes attr;
1775 XGetWindowAttributes (THIS->display->display, window, &attr);
1776 XSelectInput (THIS->display->display, window, attr.your_event_mask | add_events & ~del_events);
1777}
1778
1779void
1780rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y)
1781 PPCODE:
1782{
1783 int dx, dy;
1784 Window child;
1785
1786 if (XTranslateCoordinates (THIS->display->display, src, dst, x, y, &dx, &dy, &child))
1787 {
1788 EXTEND (SP, 3);
1789 PUSHs (newSViv (dx));
1790 PUSHs (newSViv (dy));
1791 PUSHs (newSVuv (child));
1792 }
1793}
1794
1795#############################################################################
1796# urxvt::overlay
1797#############################################################################
1798
1615MODULE = urxvt PACKAGE = urxvt::overlay 1799MODULE = urxvt PACKAGE = urxvt::overlay
1616 1800
1617void 1801void
1618overlay::set (int x, int y, SV *text, SV *rend = 0) 1802overlay::set (int x, int y, SV *text, SV *rend = 0)
1619 1803
1623void 1807void
1624overlay::hide () 1808overlay::hide ()
1625 1809
1626void 1810void
1627overlay::DESTROY () 1811overlay::DESTROY ()
1812
1813#############################################################################
1814# urxvt::watcher
1815#############################################################################
1816
1817MODULE = urxvt PACKAGE = urxvt::watcher
1818
1819CHAINED
1820perl_watcher::cb (SV *cb)
1821 CODE:
1822 THIS->cb (cb);
1823 OUTPUT:
1824 RETVAL
1825
1826#############################################################################
1827# urxvt::timer
1828#############################################################################
1628 1829
1629MODULE = urxvt PACKAGE = urxvt::timer 1830MODULE = urxvt PACKAGE = urxvt::timer
1630 1831
1631SV * 1832SV *
1632timer::new () 1833timer::new ()
1633 CODE: 1834 CODE:
1634 timer *w = new timer; 1835 timer *w = new timer;
1635 w->start (NOW); 1836 w->start (NOW);
1636 RETVAL = newSVptr ((void *)w, "urxvt::timer"); 1837 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::timer");
1637 w->self = (HV *)SvRV (RETVAL); 1838 w->self = (HV *)SvRV (RETVAL);
1638 OUTPUT:
1639 RETVAL
1640
1641timer *
1642timer::cb (SV *cb)
1643 CODE:
1644 THIS->cb (cb);
1645 RETVAL = THIS;
1646 OUTPUT: 1839 OUTPUT:
1647 RETVAL 1840 RETVAL
1648 1841
1649NV 1842NV
1650timer::at () 1843timer::at ()
1651 CODE: 1844 CODE:
1652 RETVAL = THIS->at; 1845 RETVAL = THIS->at;
1653 OUTPUT: 1846 OUTPUT:
1654 RETVAL 1847 RETVAL
1655 1848
1656timer * 1849CHAINED
1657timer::interval (NV interval) 1850timer::interval (NV interval)
1658 CODE: 1851 CODE:
1659 THIS->interval = interval; 1852 THIS->interval = interval;
1853 OUTPUT:
1660 RETVAL = THIS; 1854 RETVAL
1661 OUTPUT:
1662 RETVAL
1663 1855
1664timer * 1856CHAINED
1665timer::set (NV tstamp) 1857timer::set (NV tstamp)
1666 CODE: 1858 CODE:
1667 THIS->set (tstamp); 1859 THIS->set (tstamp);
1860 OUTPUT:
1668 RETVAL = THIS; 1861 RETVAL
1669 OUTPUT:
1670 RETVAL
1671 1862
1672timer * 1863CHAINED
1673timer::start (NV tstamp = THIS->at) 1864timer::start (NV tstamp = THIS->at)
1674 CODE: 1865 CODE:
1675 THIS->start (tstamp); 1866 THIS->start (tstamp);
1867 OUTPUT:
1676 RETVAL = THIS; 1868 RETVAL
1677 OUTPUT:
1678 RETVAL
1679 1869
1680timer * 1870CHAINED
1871timer::after (NV delay)
1872 CODE:
1873 THIS->start (NOW + delay);
1874 OUTPUT:
1875 RETVAL
1876
1877CHAINED
1681timer::stop () 1878timer::stop ()
1682 CODE: 1879 CODE:
1683 THIS->stop (); 1880 THIS->stop ();
1684 RETVAL = THIS;
1685 OUTPUT: 1881 OUTPUT:
1686 RETVAL 1882 RETVAL
1687 1883
1688void 1884void
1689timer::DESTROY () 1885timer::DESTROY ()
1886
1887#############################################################################
1888# urxvt::iow
1889#############################################################################
1690 1890
1691MODULE = urxvt PACKAGE = urxvt::iow 1891MODULE = urxvt PACKAGE = urxvt::iow
1692 1892
1693SV * 1893SV *
1694iow::new () 1894iow::new ()
1695 CODE: 1895 CODE:
1696 iow *w = new iow; 1896 iow *w = new iow;
1697 RETVAL = newSVptr ((void *)w, "urxvt::iow"); 1897 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iow");
1698 w->self = (HV *)SvRV (RETVAL); 1898 w->self = (HV *)SvRV (RETVAL);
1699 OUTPUT: 1899 OUTPUT:
1700 RETVAL 1900 RETVAL
1701 1901
1702iow * 1902CHAINED
1703iow::cb (SV *cb)
1704 CODE:
1705 THIS->cb (cb);
1706 RETVAL = THIS;
1707 OUTPUT:
1708 RETVAL
1709
1710iow *
1711iow::fd (int fd) 1903iow::fd (int fd)
1712 CODE: 1904 CODE:
1713 THIS->fd = fd; 1905 THIS->fd = fd;
1906 OUTPUT:
1714 RETVAL = THIS; 1907 RETVAL
1715 OUTPUT:
1716 RETVAL
1717 1908
1718iow * 1909CHAINED
1719iow::events (short events) 1910iow::events (short events)
1720 CODE: 1911 CODE:
1721 THIS->events = events; 1912 THIS->events = events;
1913 OUTPUT:
1722 RETVAL = THIS; 1914 RETVAL
1723 OUTPUT:
1724 RETVAL
1725 1915
1726iow * 1916CHAINED
1727iow::start () 1917iow::start ()
1728 CODE: 1918 CODE:
1729 THIS->start (); 1919 THIS->start ();
1920 OUTPUT:
1730 RETVAL = THIS; 1921 RETVAL
1731 OUTPUT:
1732 RETVAL
1733 1922
1734iow * 1923CHAINED
1735iow::stop () 1924iow::stop ()
1736 CODE: 1925 CODE:
1737 THIS->stop (); 1926 THIS->stop ();
1738 RETVAL = THIS;
1739 OUTPUT: 1927 OUTPUT:
1740 RETVAL 1928 RETVAL
1741 1929
1742void 1930void
1743iow::DESTROY () 1931iow::DESTROY ()
1744 1932
1933#############################################################################
1934# urxvt::iw
1935#############################################################################
1745 1936
1937MODULE = urxvt PACKAGE = urxvt::iw
1938
1939SV *
1940iw::new ()
1941 CODE:
1942 iw *w = new iw;
1943 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iw");
1944 w->self = (HV *)SvRV (RETVAL);
1945 OUTPUT:
1946 RETVAL
1947
1948CHAINED
1949iw::start ()
1950 CODE:
1951 THIS->start ();
1952 OUTPUT:
1953 RETVAL
1954
1955CHAINED
1956iw::stop ()
1957 CODE:
1958 THIS->stop ();
1959 OUTPUT:
1960 RETVAL
1961
1962void
1963iw::DESTROY ()
1964
1965#############################################################################
1966# urxvt::pw
1967#############################################################################
1968
1969MODULE = urxvt PACKAGE = urxvt::pw
1970
1971SV *
1972pw::new ()
1973 CODE:
1974 pw *w = new pw;
1975 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::pw");
1976 w->self = (HV *)SvRV (RETVAL);
1977 OUTPUT:
1978 RETVAL
1979
1980CHAINED
1981pw::start (int pid)
1982 CODE:
1983 THIS->start (pid);
1984 OUTPUT:
1985 RETVAL
1986
1987CHAINED
1988pw::stop ()
1989 CODE:
1990 THIS->stop ();
1991 OUTPUT:
1992 RETVAL
1993
1994void
1995pw::DESTROY ()
1996
1997

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines