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.70 by root, Tue Jan 17 09:34:21 2006 UTC vs.
Revision 1.79 by root, Fri Jan 20 10:27:08 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
59static SV *
60taint (SV *sv)
61{
62 SvTAINT (sv);
63 return sv;
64}
65
66static SV *
67taint_if (SV *sv, SV *src)
68{
69 if (SvTAINTED (src))
70 SvTAINT (sv);
71
72 return sv;
73}
74 58
75static wchar_t * 59static wchar_t *
76sv2wcs (SV *sv) 60sv2wcs (SV *sv)
77{ 61{
78 STRLEN len; 62 STRLEN len;
134#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) 118#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
135#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 119#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
136 120
137///////////////////////////////////////////////////////////////////////////// 121/////////////////////////////////////////////////////////////////////////////
138 122
123#define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, "urxvt::watcher")
124
139struct perl_watcher 125struct perl_watcher
140{ 126{
141 SV *cbsv; 127 SV *cbsv;
142 HV *self; 128 HV *self;
143 129
144 perl_watcher () 130 perl_watcher ()
145 : cbsv (newSV (0)) 131 : cbsv (0)
146 { 132 {
147 } 133 }
148 134
149 ~perl_watcher () 135 ~perl_watcher ()
150 { 136 {
151 SvREFCNT_dec (cbsv); 137 SvREFCNT_dec (cbsv);
152 } 138 }
153 139
154 void cb (SV *cb) 140 void cb (SV *cb)
155 { 141 {
156 sv_setsv (cbsv, cb); 142 SvREFCNT_dec (cbsv);
143 cbsv = newSVsv (cb);
157 } 144 }
158 145
159 void invoke (const char *type, SV *self, int arg = -1); 146 void invoke (const char *type, SV *self, int arg = -1);
160}; 147};
161 148
185 if (SvTRUE (ERRSV)) 172 if (SvTRUE (ERRSV))
186 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV)); 173 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
187} 174}
188 175
189#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") 176#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
190#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") 177#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR (sv, "urxvt::timer")
191 178
192struct timer : time_watcher, perl_watcher 179struct timer : perl_watcher, time_watcher
193{ 180{
194 tstamp interval; 181 tstamp interval;
195 182
196 timer () 183 timer ()
197 : time_watcher (this, &timer::execute) 184 : time_watcher (this, &timer::execute)
206 invoke ("urxvt::timer", newSVtimer (this)); 193 invoke ("urxvt::timer", newSVtimer (this));
207 } 194 }
208}; 195};
209 196
210#define newSViow(iow) new_ref (iow->self, "urxvt::iow") 197#define newSViow(iow) new_ref (iow->self, "urxvt::iow")
211#define SvIOW(sv) (iow *)SvPTR (sv, "urxvt::iow") 198#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR (sv, "urxvt::iow")
212 199
213struct iow : io_watcher, perl_watcher 200struct iow : perl_watcher, io_watcher
214{ 201{
215 iow () 202 iow ()
216 : io_watcher (this, &iow::execute) 203 : io_watcher (this, &iow::execute)
217 { 204 {
218 } 205 }
221 { 208 {
222 invoke ("urxvt::iow", newSViow (this), revents); 209 invoke ("urxvt::iow", newSViow (this), revents);
223 } 210 }
224}; 211};
225 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
226///////////////////////////////////////////////////////////////////////////// 245/////////////////////////////////////////////////////////////////////////////
227 246
228#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 247#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
229 248
230struct overlay { 249struct overlay {
231 HV *self; 250 HV *self;
251 bool visible;
232 rxvt_term *THIS; 252 rxvt_term *THIS;
233 int x, y, w, h; 253 int x, y, w, h;
234 int border; 254 int border;
235 text_t **text; 255 text_t **text;
236 rend_t **rend; 256 rend_t **rend;
245 265
246 void set (int x, int y, SV *str, SV *rend); 266 void set (int x, int y, SV *str, SV *rend);
247}; 267};
248 268
249overlay::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)
250: 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)
251{ 271{
252 if (border == 2) 272 if (border == 2)
253 { 273 {
254 w += 2; 274 w += 2;
255 h += 2; 275 h += 2;
316} 336}
317 337
318void 338void
319overlay::show () 339overlay::show ()
320{ 340{
321 char key[33]; sprintf (key, "%32lx", (long)this); 341 if (visible)
342 return;
322 343
344 visible = true;
345
323 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));
324 hv_store (hv, key, 32, newSViv ((long)this), 0); 347 av_push (av, newSViv ((long)this));
325} 348}
326 349
327void 350void
328overlay::hide () 351overlay::hide ()
329{ 352{
353 if (!visible)
354 return;
355
356 visible = false;
357
330 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));
331 359
332 if (ovs) 360 int i;
361
362 for (i = AvFILL (av); i >= 0; i--)
363 if (SvIV (*av_fetch (av, i, 1)) == (long)this)
333 { 364 {
334 char key[33]; sprintf (key, "%32lx", (long)this);
335
336 HV *hv = (HV *)SvRV (*ovs);
337 hv_delete (hv, key, 32, G_DISCARD); 365 av_delete (av, i, G_DISCARD);
366 break;
338 } 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);
339} 373}
340 374
341void overlay::swap () 375void overlay::swap ()
342{ 376{
343 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));
383 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) 417 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
384 croak ("rend must be arrayref"); 418 croak ("rend must be arrayref");
385 419
386 AV *av = (AV *)SvRV (rend); 420 AV *av = (AV *)SvRV (rend);
387 421
388 for (int col = min (av_len (av) + 1, w - x - border); col--; ) 422 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
389 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 423 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
390 } 424 }
391 425
392 THIS->want_refresh = 1; 426 THIS->want_refresh = 1;
393} 427}
418 perl_environ = rxvt_environ; 452 perl_environ = rxvt_environ;
419 swap (perl_environ, environ); 453 swap (perl_environ, environ);
420 454
421 char *argv[] = { 455 char *argv[] = {
422 "", 456 "",
423 "-T", 457 "-e"
424 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 458 "BEGIN {"
459 " urxvt->bootstrap;"
460 " unshift @INC, '" LIBDIR "';"
461 "}"
462 ""
463 "use urxvt;"
425 }; 464 };
426 465
427 perl = perl_alloc (); 466 perl = perl_alloc ();
428 perl_construct (perl); 467 perl_construct (perl);
429 468
430 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) 469 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL)
431 || perl_run (perl)) 470 || perl_run (perl))
432 { 471 {
433 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 472 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
434 473
435 perl_destruct (perl); 474 perl_destruct (perl);
444 483
445 if (perl) 484 if (perl)
446 { 485 {
447 // runs outside of perls ENV 486 // runs outside of perls ENV
448 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 487 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
449 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);
450 } 489 }
451} 490}
452 491
453static void 492static void
454ungrab (rxvt_term *THIS) 493ungrab (rxvt_term *THIS)
459 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 498 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
460 THIS->perl.grabtime = 0; 499 THIS->perl.grabtime = 0;
461 } 500 }
462} 501}
463 502
464static void
465swap_overlays (rxvt_term *term)
466{
467 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
468
469 if (HvKEYS (hv))
470 {
471 hv_iterinit (hv);
472
473 while (HE *he = hv_iternext (hv))
474 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
475 }
476}
477
478bool 503bool
479rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 504rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
480{ 505{
481 if (!perl || !term->perl.self) 506 if (!perl || !term->perl.self)
482 return false; 507 return false;
483 508
484 // pre-handling of some events 509 // pre-handling of some events
485 if (htype == HOOK_REFRESH_END) 510 if (htype == HOOK_REFRESH_END)
486 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 }
487 517
488 swap (perl_environ, environ); 518 swap (perl_environ, environ);
489 519
490 bool event_consumed; 520 bool event_consumed;
491 521
518 case DT_LONG: 548 case DT_LONG:
519 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 549 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
520 break; 550 break;
521 551
522 case DT_STR: 552 case DT_STR:
523 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); 553 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
524 break; 554 break;
525 555
526 case DT_STR_LEN: 556 case DT_STR_LEN:
527 { 557 {
528 char *str = va_arg (ap, char *); 558 char *str = va_arg (ap, char *);
529 int len = va_arg (ap, int); 559 int len = va_arg (ap, int);
530 560
531 XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); 561 XPUSHs (sv_2mortal (newSVpvn (str, len)));
532 } 562 }
533 break; 563 break;
534 564
535 case DT_WCS_LEN: 565 case DT_WCS_LEN:
536 { 566 {
537 wchar_t *wstr = va_arg (ap, wchar_t *); 567 wchar_t *wstr = va_arg (ap, wchar_t *);
538 int wlen = va_arg (ap, int); 568 int wlen = va_arg (ap, int);
539 569
540 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); 570 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
541 } 571 }
542 break; 572 break;
543 573
544 case DT_XEVENT: 574 case DT_XEVENT:
545 { 575 {
546 XEvent *xe = va_arg (ap, XEvent *); 576 XEvent *xe = va_arg (ap, XEvent *);
547 HV *hv = newHV (); 577 HV *hv = newHV ();
548 578
549# 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)
550# 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)
551# undef set 582# undef set
552 583
553 setiv (type, xe->type); 584 setiv (type, xe->type);
554 setiv (send_event, xe->xany.send_event); 585 setiv (send_event, xe->xany.send_event);
555 setiv (serial, xe->xany.serial); 586 setiv (serial, xe->xany.serial);
559 case KeyPress: 590 case KeyPress:
560 case KeyRelease: 591 case KeyRelease:
561 case ButtonPress: 592 case ButtonPress:
562 case ButtonRelease: 593 case ButtonRelease:
563 case MotionNotify: 594 case MotionNotify:
595 setuv (window, xe->xmotion.window);
596 setuv (root, xe->xmotion.root);
597 setuv (subwindow, xe->xmotion.subwindow);
564 setiv (time, xe->xmotion.time); 598 setuv (time, xe->xmotion.time);
565 setiv (x, xe->xmotion.x); 599 setiv (x, xe->xmotion.x);
566 setiv (y, xe->xmotion.y); 600 setiv (y, xe->xmotion.y);
567 setiv (row, xe->xmotion.y / term->fheight); 601 setiv (row, xe->xmotion.y / term->fheight);
568 setiv (col, xe->xmotion.x / term->fwidth); 602 setiv (col, xe->xmotion.x / term->fwidth);
569 setiv (x_root, xe->xmotion.x_root); 603 setiv (x_root, xe->xmotion.x_root);
570 setiv (y_root, xe->xmotion.y_root); 604 setiv (y_root, xe->xmotion.y_root);
571 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
572 break; 624 break;
573 }
574 625
626 case MapNotify:
627 case UnmapNotify:
628 case ConfigureNotify:
629 setuv (event, xe->xconfigure.event);
630 setuv (window, xe->xconfigure.window);
631
575 switch (xe->type) 632 switch (xe->type)
576 { 633 {
577 case KeyPress: 634 case ConfigureNotify:
578 case KeyRelease: 635 setiv (x, xe->xconfigure.x);
579 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);
580 break; 640 break;
581
582 case ButtonPress:
583 case ButtonRelease:
584 setiv (button, xe->xbutton.button);
585 break; 641 }
586 642
587 case MotionNotify:
588 setiv (is_hint, xe->xmotion.is_hint);
589 break; 643 break;
590 } 644 }
591 645
592 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 646 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
593 } 647 }
634 else 688 else
635 event_consumed = false; 689 event_consumed = false;
636 690
637 // post-handling of some events 691 // post-handling of some events
638 if (htype == HOOK_REFRESH_BEGIN) 692 if (htype == HOOK_REFRESH_BEGIN)
639 swap_overlays (term); 693 {
694 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
695
696 for (int i = AvFILL (av); i >= 0; i--)
697 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
698 }
640 else if (htype == HOOK_DESTROY) 699 else if (htype == HOOK_DESTROY)
641 { 700 {
642 clearSVptr ((SV *)term->perl.self); 701 clearSVptr ((SV *)term->perl.self);
643 SvREFCNT_dec ((SV *)term->perl.self); 702 SvREFCNT_dec ((SV *)term->perl.self);
644 } 703 }
782void 841void
783fatal (const char *msg) 842fatal (const char *msg)
784 CODE: 843 CODE:
785 rxvt_fatal ("%s", msg); 844 rxvt_fatal ("%s", msg);
786 845
787SV *
788untaint (SV *sv)
789 CODE:
790 RETVAL = newSVsv (sv);
791 SvTAINTED_off (RETVAL);
792 OUTPUT:
793 RETVAL
794
795void 846void
796_exit (int status) 847_exit (int status)
797
798bool
799safe ()
800 CODE:
801 RETVAL = !rxvt_tainted ();
802 OUTPUT:
803 RETVAL
804 848
805NV 849NV
806NOW () 850NOW ()
807 CODE: 851 CODE:
808 RETVAL = NOW; 852 RETVAL = NOW;
873 917
874 for (int i = 1; i < items; i++) 918 for (int i = 1; i < items; i++)
875 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 919 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
876 920
877 AV *envv = (AV *)SvRV (ST (0)); 921 AV *envv = (AV *)SvRV (ST (0));
878 for (int i = av_len (envv) + 1; i--; ) 922 for (int i = AvFILL (envv) + 1; i--; )
879 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 923 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
880 924
881 term->envv->push_back (0); 925 term->envv->push_back (0);
882 926
883 bool success; 927 bool success;
904 RETVAL 948 RETVAL
905 949
906void 950void
907rxvt_term::destroy () 951rxvt_term::destroy ()
908 952
909#if ENABLE_PERL_FRILLS
910
911void
912rxvt_term::XListProperties (U32 window)
913 PPCODE:
914{
915 int count;
916 Atom *props = XListProperties (THIS->display->display, (Window)window, &count);
917
918 EXTEND (SP, count);
919 while (count--)
920 PUSHs (newSVuv ((U32)props [count]));
921
922 XFree (props);
923}
924
925void
926rxvt_term::XGetWindowProperty (U32 window, U32 property)
927 PPCODE:
928{
929 Atom type;
930 int format;
931 unsigned long nitems;
932 unsigned long bytes_after;
933 unsigned char *prop;
934 XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property,
935 0, 1<<30, 0, AnyPropertyType,
936 &type, &format, &nitems, &bytes_after, &prop);
937 if (type != None)
938 {
939 EXTEND (SP, 3);
940 PUSHs (newSVuv ((U32)type));
941 PUSHs (newSViv (format));
942 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
943 XFree (prop);
944 }
945}
946
947void
948rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data)
949 CODE:
950{
951 STRLEN len;
952 char *data_ = SvPVbyte (data, len);
953
954 XChangeProperty (THIS->display->display, (Window)window, (Atom)property,
955 type, format, PropModeReplace,
956 (unsigned char *)data, len * 8 / format);
957}
958
959void
960rxvt_term::XDeleteProperty (U32 window, U32 property)
961 CODE:
962 XDeleteProperty (THIS->display->display, (Window)window, (Atom)property);
963
964U32
965rxvt_term::DefaultRootWindow ()
966 CODE:
967 RETVAL = (U32)THIS->display->root;
968 OUTPUT:
969 RETVAL
970
971U32
972rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height)
973 CODE:
974 RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent,
975 x, y, width, height, 0,
976 THIS->pix_colors_focused[Color_border],
977 THIS->pix_colors_focused[Color_border]);
978 OUTPUT:
979 RETVAL
980
981void
982rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0)
983 CODE:
984 XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y);
985
986void
987rxvt_term::XMapWindow (U32 window)
988 CODE:
989 XMapWindow (THIS->display->display, (Window)window);
990
991void
992rxvt_term::XUnmapWindow (U32 window)
993 CODE:
994 XUnmapWindow (THIS->display->display, (Window)window);
995
996#endif
997
998void 953void
999rxvt_term::set_should_invoke (int htype, int inc) 954rxvt_term::set_should_invoke (int htype, int inc)
1000 CODE: 955 CODE:
1001 THIS->perl.should_invoke [htype] += inc; 956 THIS->perl.should_invoke [htype] += inc;
1002 957
1006 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 961 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
1007 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 962 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1008 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 963 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
1009 964
1010bool 965bool
1011rxvt_term::grab (U32 eventtime, int sync = 0) 966rxvt_term::grab (Time eventtime, int sync = 0)
1012 CODE: 967 CODE:
1013{ 968{
1014 int mode = sync ? GrabModeSync : GrabModeAsync; 969 int mode = sync ? GrabModeSync : GrabModeAsync;
1015 970
1016 THIS->perl.grabtime = 0; 971 THIS->perl.grabtime = 0;
1074 char *mbstr = rxvt_wcstombs (wstr); 1029 char *mbstr = rxvt_wcstombs (wstr);
1075 rxvt_pop_locale (); 1030 rxvt_pop_locale ();
1076 1031
1077 free (wstr); 1032 free (wstr);
1078 1033
1079 RETVAL = taint_if (newSVpv (mbstr, 0), str); 1034 RETVAL = newSVpv (mbstr, 0);
1080 free (mbstr); 1035 free (mbstr);
1081} 1036}
1082 OUTPUT: 1037 OUTPUT:
1083 RETVAL 1038 RETVAL
1084 1039
1091 1046
1092 rxvt_push_locale (THIS->locale); 1047 rxvt_push_locale (THIS->locale);
1093 wchar_t *wstr = rxvt_mbstowcs (data, len); 1048 wchar_t *wstr = rxvt_mbstowcs (data, len);
1094 rxvt_pop_locale (); 1049 rxvt_pop_locale ();
1095 1050
1096 RETVAL = taint_if (wcs2sv (wstr), octets); 1051 RETVAL = wcs2sv (wstr);
1097 free (wstr); 1052 free (wstr);
1098} 1053}
1099 OUTPUT: 1054 OUTPUT:
1100 RETVAL 1055 RETVAL
1101 1056
1191 if (events != EVENT_UNDEF) 1146 if (events != EVENT_UNDEF)
1192 THIS->pty_ev.set (events); 1147 THIS->pty_ev.set (events);
1193 OUTPUT: 1148 OUTPUT:
1194 RETVAL 1149 RETVAL
1195 1150
1196U32 1151Window
1197rxvt_term::parent () 1152rxvt_term::parent ()
1198 CODE: 1153 CODE:
1199 RETVAL = (U32)THIS->parent [0]; 1154 RETVAL = THIS->parent [0];
1200 OUTPUT: 1155 OUTPUT:
1201 RETVAL 1156 RETVAL
1202 1157
1203U32 1158Window
1204rxvt_term::vt () 1159rxvt_term::vt ()
1205 CODE: 1160 CODE:
1206 RETVAL = (U32)THIS->vt; 1161 RETVAL = THIS->vt;
1207 OUTPUT: 1162 OUTPUT:
1208 RETVAL 1163 RETVAL
1209 1164
1210void 1165void
1211rxvt_term::vt_emask_add (U32 emask) 1166rxvt_term::vt_emask_add (U32 emask)
1253 wchar_t *wstr = new wchar_t [THIS->ncol]; 1208 wchar_t *wstr = new wchar_t [THIS->ncol];
1254 1209
1255 for (int col = 0; col < THIS->ncol; col++) 1210 for (int col = 0; col < THIS->ncol; col++)
1256 wstr [col] = l.t [col]; 1211 wstr [col] = l.t [col];
1257 1212
1258 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); 1213 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1259 1214
1260 delete [] wstr; 1215 delete [] wstr;
1261 } 1216 }
1262 1217
1263 if (new_text) 1218 if (new_text)
1306 { 1261 {
1307 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1262 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1308 croak ("new_rend must be arrayref"); 1263 croak ("new_rend must be arrayref");
1309 1264
1310 AV *av = (AV *)SvRV (new_rend); 1265 AV *av = (AV *)SvRV (new_rend);
1311 int len = min (av_len (av) + 1 - start_ofs, max_len); 1266 int len = min (AvFILL (av) + 1 - start_ofs, max_len);
1312 1267
1313 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1268 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
1314 croak ("new_rend array extends beyond horizontal margins"); 1269 croak ("new_rend array extends beyond horizontal margins");
1315 1270
1316 for (int col = start_col; col < start_col + len; col++) 1271 for (int col = start_col; col < start_col + len; col++)
1384 else 1339 else
1385 *r++ = *s; 1340 *r++ = *s;
1386 1341
1387 rxvt_pop_locale (); 1342 rxvt_pop_locale ();
1388 1343
1389 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); 1344 RETVAL = wcs2sv (rstr, r - rstr);
1390 1345
1391 delete [] rstr; 1346 delete [] rstr;
1392} 1347}
1393 OUTPUT: 1348 OUTPUT:
1394 RETVAL 1349 RETVAL
1420 else if (IS_COMPOSE (*s)) 1375 else if (IS_COMPOSE (*s))
1421 r += rxvt_composite.expand (*s, r); 1376 r += rxvt_composite.expand (*s, r);
1422 else 1377 else
1423 *r++ = *s; 1378 *r++ = *s;
1424 1379
1425 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); 1380 RETVAL = wcs2sv (rstr, r - rstr);
1426 1381
1427 delete [] rstr; 1382 delete [] rstr;
1428} 1383}
1429 OUTPUT: 1384 OUTPUT:
1430 RETVAL 1385 RETVAL
1452 1407
1453 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1408 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1454 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1409 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1455 1410
1456 if (GIMME_V != G_VOID) 1411 if (GIMME_V != G_VOID)
1457 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); 1412 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef);
1458 1413
1459 if (newval) 1414 if (newval)
1460 { 1415 {
1461 if (SvOK (newval)) 1416 if (SvOK (newval))
1462 { 1417 {
1469 } 1424 }
1470} 1425}
1471 1426
1472const char * 1427const char *
1473rxvt_term::x_resource (const char *name) 1428rxvt_term::x_resource (const char *name)
1474 CLEANUP:
1475 SvTAINTED_on (ST (0));
1476 1429
1477bool 1430bool
1478rxvt_term::option (U32 optval, int set = -1) 1431rxvt_term::option (U32 optval, int set = -1)
1479 CODE: 1432 CODE:
1480{ 1433{
1485 if (set) 1438 if (set)
1486 THIS->options |= optval; 1439 THIS->options |= optval;
1487 else 1440 else
1488 THIS->options &= ~optval; 1441 THIS->options &= ~optval;
1489 1442
1443 if (THIS->check_ev.is_active ()) // avoid doing this before START
1490 switch (optval) 1444 switch (optval)
1491 { 1445 {
1492 case Opt_skipBuiltinGlyphs: 1446 case Opt_skipBuiltinGlyphs:
1493 THIS->set_fonts (); 1447 THIS->set_fonts ();
1494 THIS->scr_remap_chars (); 1448 THIS->scr_remap_chars ();
1495 THIS->scr_touch (true); 1449 THIS->scr_touch (true);
1496 THIS->want_refresh = 1; 1450 THIS->want_refresh = 1;
1497 break; 1451 break;
1498 1452
1499 case Opt_cursorUnderline: 1453 case Opt_cursorUnderline:
1500 THIS->want_refresh = 1; 1454 THIS->want_refresh = 1;
1501 break; 1455 break;
1502 1456
1503# case Opt_scrollBar_floating: 1457# case Opt_scrollBar_floating:
1504# case Opt_scrollBar_right: 1458# case Opt_scrollBar_right:
1505# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1459# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1506# break; 1460# break;
1507 } 1461 }
1508 } 1462 }
1509} 1463}
1510 OUTPUT: 1464 OUTPUT:
1511 RETVAL 1465 RETVAL
1512 1466
1540 PUSHs (sv_2mortal (newSViv (rc.col))); 1494 PUSHs (sv_2mortal (newSViv (rc.col)));
1541 } 1495 }
1542 1496
1543 if (items == 3) 1497 if (items == 3)
1544 { 1498 {
1499 rc.row = SvIV (ST (1));
1500 rc.col = SvIV (ST (2));
1501
1502 if (ix == 2 && rc.col == 0)
1503 {
1504 rc.row--;
1505 rc.col = THIS->ncol;
1506 }
1507
1508 clamp_it (rc.col, 0, THIS->ncol);
1545 rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1); 1509 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1546 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
1547 1510
1548 if (ix) 1511 if (ix)
1549 THIS->want_refresh = 1; 1512 THIS->want_refresh = 1;
1550 } 1513 }
1551} 1514}
1559 1522
1560#void 1523#void
1561#rxvt_term::selection_clear () 1524#rxvt_term::selection_clear ()
1562 1525
1563void 1526void
1564rxvt_term::selection_make (U32 eventtime, bool rect = false) 1527rxvt_term::selection_make (Time eventtime, bool rect = false)
1565 CODE: 1528 CODE:
1566 THIS->selection.op = SELECTION_CONT; 1529 THIS->selection.op = SELECTION_CONT;
1567 THIS->selection.rect = rect; 1530 THIS->selection.rect = rect;
1568 THIS->selection_make (eventtime); 1531 THIS->selection_make (eventtime);
1569 1532
1570int 1533int
1571rxvt_term::selection_grab (U32 eventtime) 1534rxvt_term::selection_grab (Time eventtime)
1572 1535
1573void 1536void
1574rxvt_term::selection (SV *newtext = 0) 1537rxvt_term::selection (SV *newtext = 0)
1575 PPCODE: 1538 PPCODE:
1576{ 1539{
1577 if (GIMME_V != G_VOID) 1540 if (GIMME_V != G_VOID)
1578 XPUSHs (THIS->selection.text 1541 XPUSHs (THIS->selection.text
1579 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) 1542 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))
1580 : &PL_sv_undef); 1543 : &PL_sv_undef);
1581 1544
1582 if (newtext) 1545 if (newtext)
1583 { 1546 {
1584 free (THIS->selection.text); 1547 free (THIS->selection.text);
1644 o->self = (HV *)SvRV (RETVAL); 1607 o->self = (HV *)SvRV (RETVAL);
1645} 1608}
1646 OUTPUT: 1609 OUTPUT:
1647 RETVAL 1610 RETVAL
1648 1611
1612#############################################################################
1613# Various X Utility Functions
1614#############################################################################
1615
1616void
1617rxvt_term::XListProperties (Window window)
1618 PPCODE:
1619{
1620 int count;
1621 Atom *props = XListProperties (THIS->display->display, window, &count);
1622
1623 EXTEND (SP, count);
1624 while (count--)
1625 PUSHs (newSVuv ((U32)props [count]));
1626
1627 XFree (props);
1628}
1629
1630void
1631rxvt_term::XGetWindowProperty (Window window, Atom property)
1632 PPCODE:
1633{
1634 Atom type;
1635 int format;
1636 unsigned long nitems;
1637 unsigned long bytes_after;
1638 unsigned char *prop;
1639 XGetWindowProperty (THIS->display->display, window, property,
1640 0, 1<<30, 0, AnyPropertyType,
1641 &type, &format, &nitems, &bytes_after, &prop);
1642 if (type != None)
1643 {
1644 EXTEND (SP, 3);
1645 PUSHs (newSVuv ((U32)type));
1646 PUSHs (newSViv (format));
1647 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
1648 XFree (prop);
1649 }
1650}
1651
1652void
1653rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data)
1654 CODE:
1655{
1656 STRLEN len;
1657 char *data_ = SvPVbyte (data, len);
1658
1659 XChangeProperty (THIS->display->display, window, property,
1660 type, format, PropModeReplace,
1661 (unsigned char *)data, len * 8 / format);
1662}
1663
1664void
1665XDeleteProperty (rxvt_term *term, Window window, Atom property)
1666 C_ARGS: term->display->display, window, property
1667
1668Window
1669rxvt_term::DefaultRootWindow ()
1670 CODE:
1671 RETVAL = THIS->display->root;
1672 OUTPUT:
1673 RETVAL
1674
1675Window
1676XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1677 C_ARGS: term->display->display, (Window)parent,
1678 x, y, width, height, 0,
1679 term->pix_colors_focused[Color_border],
1680 term->pix_colors_focused[Color_border]
1681
1682void
1683XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1684 C_ARGS: term->display->display, window, parent, x, y
1685
1686void
1687XMapWindow (rxvt_term *term, Window window)
1688 C_ARGS: term->display->display, window
1689
1690void
1691XUnmapWindow (rxvt_term *term, Window window)
1692 C_ARGS: term->display->display, window
1693
1694void
1695XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1696 C_ARGS: term->display->display, (Window)window, x, y, width, height
1697
1698#############################################################################
1699# urxvt::overlay
1700#############################################################################
1701
1649MODULE = urxvt PACKAGE = urxvt::overlay 1702MODULE = urxvt PACKAGE = urxvt::overlay
1650 1703
1651void 1704void
1652overlay::set (int x, int y, SV *text, SV *rend = 0) 1705overlay::set (int x, int y, SV *text, SV *rend = 0)
1653 1706
1657void 1710void
1658overlay::hide () 1711overlay::hide ()
1659 1712
1660void 1713void
1661overlay::DESTROY () 1714overlay::DESTROY ()
1715
1716#############################################################################
1717# urxvt::watcher
1718#############################################################################
1719
1720MODULE = urxvt PACKAGE = urxvt::watcher
1721
1722CHAINED
1723perl_watcher::cb (SV *cb)
1724 CODE:
1725 THIS->cb (cb);
1726 OUTPUT:
1727 RETVAL
1728
1729#############################################################################
1730# urxvt::timer
1731#############################################################################
1662 1732
1663MODULE = urxvt PACKAGE = urxvt::timer 1733MODULE = urxvt PACKAGE = urxvt::timer
1664 1734
1665SV * 1735SV *
1666timer::new () 1736timer::new ()
1667 CODE: 1737 CODE:
1668 timer *w = new timer; 1738 timer *w = new timer;
1669 w->start (NOW); 1739 w->start (NOW);
1670 RETVAL = newSVptr ((void *)w, "urxvt::timer"); 1740 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::timer");
1671 w->self = (HV *)SvRV (RETVAL); 1741 w->self = (HV *)SvRV (RETVAL);
1672 OUTPUT:
1673 RETVAL
1674
1675timer *
1676timer::cb (SV *cb)
1677 CODE:
1678 THIS->cb (cb);
1679 RETVAL = THIS;
1680 OUTPUT: 1742 OUTPUT:
1681 RETVAL 1743 RETVAL
1682 1744
1683NV 1745NV
1684timer::at () 1746timer::at ()
1685 CODE: 1747 CODE:
1686 RETVAL = THIS->at; 1748 RETVAL = THIS->at;
1687 OUTPUT: 1749 OUTPUT:
1688 RETVAL 1750 RETVAL
1689 1751
1690timer * 1752CHAINED
1691timer::interval (NV interval) 1753timer::interval (NV interval)
1692 CODE: 1754 CODE:
1693 THIS->interval = interval; 1755 THIS->interval = interval;
1756 OUTPUT:
1694 RETVAL = THIS; 1757 RETVAL
1695 OUTPUT:
1696 RETVAL
1697 1758
1698timer * 1759CHAINED
1699timer::set (NV tstamp) 1760timer::set (NV tstamp)
1700 CODE: 1761 CODE:
1701 THIS->set (tstamp); 1762 THIS->set (tstamp);
1763 OUTPUT:
1702 RETVAL = THIS; 1764 RETVAL
1703 OUTPUT:
1704 RETVAL
1705 1765
1706timer * 1766CHAINED
1707timer::start (NV tstamp = THIS->at) 1767timer::start (NV tstamp = THIS->at)
1708 CODE: 1768 CODE:
1709 THIS->start (tstamp); 1769 THIS->start (tstamp);
1770 OUTPUT:
1710 RETVAL = THIS; 1771 RETVAL
1711 OUTPUT:
1712 RETVAL
1713 1772
1714timer * 1773CHAINED
1774timer::after (NV delay)
1775 CODE:
1776 THIS->start (NOW + delay);
1777 OUTPUT:
1778 RETVAL
1779
1780CHAINED
1715timer::stop () 1781timer::stop ()
1716 CODE: 1782 CODE:
1717 THIS->stop (); 1783 THIS->stop ();
1718 RETVAL = THIS;
1719 OUTPUT: 1784 OUTPUT:
1720 RETVAL 1785 RETVAL
1721 1786
1722void 1787void
1723timer::DESTROY () 1788timer::DESTROY ()
1789
1790#############################################################################
1791# urxvt::iow
1792#############################################################################
1724 1793
1725MODULE = urxvt PACKAGE = urxvt::iow 1794MODULE = urxvt PACKAGE = urxvt::iow
1726 1795
1727SV * 1796SV *
1728iow::new () 1797iow::new ()
1729 CODE: 1798 CODE:
1730 iow *w = new iow; 1799 iow *w = new iow;
1731 RETVAL = newSVptr ((void *)w, "urxvt::iow"); 1800 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iow");
1732 w->self = (HV *)SvRV (RETVAL); 1801 w->self = (HV *)SvRV (RETVAL);
1733 OUTPUT: 1802 OUTPUT:
1734 RETVAL 1803 RETVAL
1735 1804
1736iow * 1805CHAINED
1737iow::cb (SV *cb)
1738 CODE:
1739 THIS->cb (cb);
1740 RETVAL = THIS;
1741 OUTPUT:
1742 RETVAL
1743
1744iow *
1745iow::fd (int fd) 1806iow::fd (int fd)
1746 CODE: 1807 CODE:
1747 THIS->fd = fd; 1808 THIS->fd = fd;
1809 OUTPUT:
1748 RETVAL = THIS; 1810 RETVAL
1749 OUTPUT:
1750 RETVAL
1751 1811
1752iow * 1812CHAINED
1753iow::events (short events) 1813iow::events (short events)
1754 CODE: 1814 CODE:
1755 THIS->events = events; 1815 THIS->events = events;
1816 OUTPUT:
1756 RETVAL = THIS; 1817 RETVAL
1757 OUTPUT:
1758 RETVAL
1759 1818
1760iow * 1819CHAINED
1761iow::start () 1820iow::start ()
1762 CODE: 1821 CODE:
1763 THIS->start (); 1822 THIS->start ();
1823 OUTPUT:
1764 RETVAL = THIS; 1824 RETVAL
1765 OUTPUT:
1766 RETVAL
1767 1825
1768iow * 1826CHAINED
1769iow::stop () 1827iow::stop ()
1770 CODE: 1828 CODE:
1771 THIS->stop (); 1829 THIS->stop ();
1772 RETVAL = THIS;
1773 OUTPUT: 1830 OUTPUT:
1774 RETVAL 1831 RETVAL
1775 1832
1776void 1833void
1777iow::DESTROY () 1834iow::DESTROY ()
1778 1835
1836#############################################################################
1837# urxvt::iw
1838#############################################################################
1779 1839
1840MODULE = urxvt PACKAGE = urxvt::iw
1841
1842SV *
1843iw::new ()
1844 CODE:
1845 iw *w = new iw;
1846 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iw");
1847 w->self = (HV *)SvRV (RETVAL);
1848 OUTPUT:
1849 RETVAL
1850
1851CHAINED
1852iow::start ()
1853 CODE:
1854 THIS->start ();
1855 OUTPUT:
1856 RETVAL
1857
1858CHAINED
1859iow::stop ()
1860 CODE:
1861 THIS->stop ();
1862 OUTPUT:
1863 RETVAL
1864
1865void
1866iw::DESTROY ()
1867
1868#############################################################################
1869# urxvt::pw
1870#############################################################################
1871
1872MODULE = urxvt PACKAGE = urxvt::pw
1873
1874SV *
1875pw::new ()
1876 CODE:
1877 pw *w = new pw;
1878 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::pw");
1879 w->self = (HV *)SvRV (RETVAL);
1880 OUTPUT:
1881 RETVAL
1882
1883CHAINED
1884pw::start (int pid)
1885 CODE:
1886 THIS->start (pid);
1887 OUTPUT:
1888 RETVAL
1889
1890CHAINED
1891iow::stop ()
1892 CODE:
1893 THIS->stop ();
1894 OUTPUT:
1895 RETVAL
1896
1897void
1898pw::DESTROY ()
1899
1900

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines