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.69 by root, Mon Jan 16 15:00:20 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);
440 swap (perl_environ, environ); 479 swap (perl_environ, environ);
441 480
442 rxvt_pop_locale (); 481 rxvt_pop_locale ();
443 } 482 }
444 483
484 if (perl)
485 {
445 // runs outside of perls ENV 486 // runs outside of perls ENV
446 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 487 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
447 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);
489 }
448} 490}
449 491
450static void 492static void
451ungrab (rxvt_term *THIS) 493ungrab (rxvt_term *THIS)
452{ 494{
456 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 498 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
457 THIS->perl.grabtime = 0; 499 THIS->perl.grabtime = 0;
458 } 500 }
459} 501}
460 502
461static void
462swap_overlays (rxvt_term *term)
463{
464 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
465
466 if (HvKEYS (hv))
467 {
468 hv_iterinit (hv);
469
470 while (HE *he = hv_iternext (hv))
471 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
472 }
473}
474
475bool 503bool
476rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 504rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
477{ 505{
478 if (!perl || !term->perl.self) 506 if (!perl || !term->perl.self)
479 return false; 507 return false;
480 508
481 // pre-handling of some events 509 // pre-handling of some events
482 if (htype == HOOK_REFRESH_END) 510 if (htype == HOOK_REFRESH_END)
483 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 }
484 517
485 swap (perl_environ, environ); 518 swap (perl_environ, environ);
486 519
487 bool event_consumed; 520 bool event_consumed;
488 521
515 case DT_LONG: 548 case DT_LONG:
516 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 549 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
517 break; 550 break;
518 551
519 case DT_STR: 552 case DT_STR:
520 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); 553 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
521 break; 554 break;
522 555
523 case DT_STR_LEN: 556 case DT_STR_LEN:
524 { 557 {
525 char *str = va_arg (ap, char *); 558 char *str = va_arg (ap, char *);
526 int len = va_arg (ap, int); 559 int len = va_arg (ap, int);
527 560
528 XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); 561 XPUSHs (sv_2mortal (newSVpvn (str, len)));
529 } 562 }
530 break; 563 break;
531 564
532 case DT_WCS_LEN: 565 case DT_WCS_LEN:
533 { 566 {
534 wchar_t *wstr = va_arg (ap, wchar_t *); 567 wchar_t *wstr = va_arg (ap, wchar_t *);
535 int wlen = va_arg (ap, int); 568 int wlen = va_arg (ap, int);
536 569
537 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); 570 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
538 } 571 }
539 break; 572 break;
540 573
541 case DT_XEVENT: 574 case DT_XEVENT:
542 { 575 {
543 XEvent *xe = va_arg (ap, XEvent *); 576 XEvent *xe = va_arg (ap, XEvent *);
544 HV *hv = newHV (); 577 HV *hv = newHV ();
545 578
546# 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)
547# 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)
548# undef set 582# undef set
549 583
550 setiv (type, xe->type); 584 setiv (type, xe->type);
551 setiv (send_event, xe->xany.send_event); 585 setiv (send_event, xe->xany.send_event);
552 setiv (serial, xe->xany.serial); 586 setiv (serial, xe->xany.serial);
556 case KeyPress: 590 case KeyPress:
557 case KeyRelease: 591 case KeyRelease:
558 case ButtonPress: 592 case ButtonPress:
559 case ButtonRelease: 593 case ButtonRelease:
560 case MotionNotify: 594 case MotionNotify:
595 setuv (window, xe->xmotion.window);
596 setuv (root, xe->xmotion.root);
597 setuv (subwindow, xe->xmotion.subwindow);
561 setiv (time, xe->xmotion.time); 598 setuv (time, xe->xmotion.time);
562 setiv (x, xe->xmotion.x); 599 setiv (x, xe->xmotion.x);
563 setiv (y, xe->xmotion.y); 600 setiv (y, xe->xmotion.y);
564 setiv (row, xe->xmotion.y / term->fheight); 601 setiv (row, xe->xmotion.y / term->fheight);
565 setiv (col, xe->xmotion.x / term->fwidth); 602 setiv (col, xe->xmotion.x / term->fwidth);
566 setiv (x_root, xe->xmotion.x_root); 603 setiv (x_root, xe->xmotion.x_root);
567 setiv (y_root, xe->xmotion.y_root); 604 setiv (y_root, xe->xmotion.y_root);
568 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
569 break; 624 break;
570 }
571 625
626 case MapNotify:
627 case UnmapNotify:
628 case ConfigureNotify:
629 setuv (event, xe->xconfigure.event);
630 setuv (window, xe->xconfigure.window);
631
572 switch (xe->type) 632 switch (xe->type)
573 { 633 {
574 case KeyPress: 634 case ConfigureNotify:
575 case KeyRelease: 635 setiv (x, xe->xconfigure.x);
576 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);
577 break; 640 break;
578
579 case ButtonPress:
580 case ButtonRelease:
581 setiv (button, xe->xbutton.button);
582 break; 641 }
583 642
584 case MotionNotify:
585 setiv (is_hint, xe->xmotion.is_hint);
586 break; 643 break;
587 } 644 }
588 645
589 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 646 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
590 } 647 }
631 else 688 else
632 event_consumed = false; 689 event_consumed = false;
633 690
634 // post-handling of some events 691 // post-handling of some events
635 if (htype == HOOK_REFRESH_BEGIN) 692 if (htype == HOOK_REFRESH_BEGIN)
636 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 }
637 else if (htype == HOOK_DESTROY) 699 else if (htype == HOOK_DESTROY)
638 { 700 {
639 clearSVptr ((SV *)term->perl.self); 701 clearSVptr ((SV *)term->perl.self);
640 SvREFCNT_dec ((SV *)term->perl.self); 702 SvREFCNT_dec ((SV *)term->perl.self);
641 } 703 }
779void 841void
780fatal (const char *msg) 842fatal (const char *msg)
781 CODE: 843 CODE:
782 rxvt_fatal ("%s", msg); 844 rxvt_fatal ("%s", msg);
783 845
784SV *
785untaint (SV *sv)
786 CODE:
787 RETVAL = newSVsv (sv);
788 SvTAINTED_off (RETVAL);
789 OUTPUT:
790 RETVAL
791
792void 846void
793_exit (int status) 847_exit (int status)
794
795bool
796safe ()
797 CODE:
798 RETVAL = !rxvt_tainted ();
799 OUTPUT:
800 RETVAL
801 848
802NV 849NV
803NOW () 850NOW ()
804 CODE: 851 CODE:
805 RETVAL = NOW; 852 RETVAL = NOW;
870 917
871 for (int i = 1; i < items; i++) 918 for (int i = 1; i < items; i++)
872 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 919 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
873 920
874 AV *envv = (AV *)SvRV (ST (0)); 921 AV *envv = (AV *)SvRV (ST (0));
875 for (int i = av_len (envv) + 1; i--; ) 922 for (int i = AvFILL (envv) + 1; i--; )
876 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))));
877 924
878 term->envv->push_back (0); 925 term->envv->push_back (0);
879 926
880 bool success; 927 bool success;
901 RETVAL 948 RETVAL
902 949
903void 950void
904rxvt_term::destroy () 951rxvt_term::destroy ()
905 952
906#if ENABLE_PERL_FRILLS
907
908void
909rxvt_term::XListProperties (U32 window)
910 PPCODE:
911{
912 int count;
913 Atom *props = XListProperties (THIS->display->display, (Window)window, &count);
914
915 EXTEND (SP, count);
916 while (count--)
917 PUSHs (newSVuv ((U32)props [count]));
918
919 XFree (props);
920}
921
922void
923rxvt_term::XGetWindowProperty (U32 window, U32 property)
924 PPCODE:
925{
926 Atom type;
927 int format;
928 unsigned long nitems;
929 unsigned long bytes_after;
930 unsigned char *prop;
931 XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property,
932 0, 1<<30, 0, AnyPropertyType,
933 &type, &format, &nitems, &bytes_after, &prop);
934 if (type != None)
935 {
936 EXTEND (SP, 3);
937 PUSHs (newSVuv ((U32)type));
938 PUSHs (newSViv (format));
939 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
940 XFree (prop);
941 }
942}
943
944void
945rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data)
946 CODE:
947{
948 STRLEN len;
949 char *data_ = SvPVbyte (data, len);
950
951 XChangeProperty (THIS->display->display, (Window)window, (Atom)property,
952 type, format, PropModeReplace,
953 (unsigned char *)data, len * 8 / format);
954}
955
956void
957rxvt_term::XDeleteProperty (U32 window, U32 property)
958 CODE:
959 XDeleteProperty (THIS->display->display, (Window)window, (Atom)property);
960
961U32
962rxvt_term::DefaultRootWindow ()
963 CODE:
964 RETVAL = (U32)THIS->display->root;
965 OUTPUT:
966 RETVAL
967
968U32
969rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height)
970 CODE:
971 RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent,
972 x, y, width, height, 0,
973 THIS->pix_colors_focused[Color_border],
974 THIS->pix_colors_focused[Color_border]);
975 OUTPUT:
976 RETVAL
977
978void
979rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0)
980 CODE:
981 XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y);
982
983void
984rxvt_term::XMapWindow (U32 window)
985 CODE:
986 XMapWindow (THIS->display->display, (Window)window);
987
988void
989rxvt_term::XUnmapWindow (U32 window)
990 CODE:
991 XUnmapWindow (THIS->display->display, (Window)window);
992
993#endif
994
995void 953void
996rxvt_term::set_should_invoke (int htype, int inc) 954rxvt_term::set_should_invoke (int htype, int inc)
997 CODE: 955 CODE:
998 THIS->perl.should_invoke [htype] += inc; 956 THIS->perl.should_invoke [htype] += inc;
999 957
1003 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 961 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
1004 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 962 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1005 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 963 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
1006 964
1007bool 965bool
1008rxvt_term::grab (U32 eventtime, int sync = 0) 966rxvt_term::grab (Time eventtime, int sync = 0)
1009 CODE: 967 CODE:
1010{ 968{
1011 int mode = sync ? GrabModeSync : GrabModeAsync; 969 int mode = sync ? GrabModeSync : GrabModeAsync;
1012 970
1013 THIS->perl.grabtime = 0; 971 THIS->perl.grabtime = 0;
1071 char *mbstr = rxvt_wcstombs (wstr); 1029 char *mbstr = rxvt_wcstombs (wstr);
1072 rxvt_pop_locale (); 1030 rxvt_pop_locale ();
1073 1031
1074 free (wstr); 1032 free (wstr);
1075 1033
1076 RETVAL = taint_if (newSVpv (mbstr, 0), str); 1034 RETVAL = newSVpv (mbstr, 0);
1077 free (mbstr); 1035 free (mbstr);
1078} 1036}
1079 OUTPUT: 1037 OUTPUT:
1080 RETVAL 1038 RETVAL
1081 1039
1088 1046
1089 rxvt_push_locale (THIS->locale); 1047 rxvt_push_locale (THIS->locale);
1090 wchar_t *wstr = rxvt_mbstowcs (data, len); 1048 wchar_t *wstr = rxvt_mbstowcs (data, len);
1091 rxvt_pop_locale (); 1049 rxvt_pop_locale ();
1092 1050
1093 RETVAL = taint_if (wcs2sv (wstr), octets); 1051 RETVAL = wcs2sv (wstr);
1094 free (wstr); 1052 free (wstr);
1095} 1053}
1096 OUTPUT: 1054 OUTPUT:
1097 RETVAL 1055 RETVAL
1098 1056
1188 if (events != EVENT_UNDEF) 1146 if (events != EVENT_UNDEF)
1189 THIS->pty_ev.set (events); 1147 THIS->pty_ev.set (events);
1190 OUTPUT: 1148 OUTPUT:
1191 RETVAL 1149 RETVAL
1192 1150
1193U32 1151Window
1194rxvt_term::parent () 1152rxvt_term::parent ()
1195 CODE: 1153 CODE:
1196 RETVAL = (U32)THIS->parent [0]; 1154 RETVAL = THIS->parent [0];
1197 OUTPUT: 1155 OUTPUT:
1198 RETVAL 1156 RETVAL
1199 1157
1200U32 1158Window
1201rxvt_term::vt () 1159rxvt_term::vt ()
1202 CODE: 1160 CODE:
1203 RETVAL = (U32)THIS->vt; 1161 RETVAL = THIS->vt;
1204 OUTPUT: 1162 OUTPUT:
1205 RETVAL 1163 RETVAL
1206 1164
1207void 1165void
1208rxvt_term::vt_emask_add (U32 emask) 1166rxvt_term::vt_emask_add (U32 emask)
1250 wchar_t *wstr = new wchar_t [THIS->ncol]; 1208 wchar_t *wstr = new wchar_t [THIS->ncol];
1251 1209
1252 for (int col = 0; col < THIS->ncol; col++) 1210 for (int col = 0; col < THIS->ncol; col++)
1253 wstr [col] = l.t [col]; 1211 wstr [col] = l.t [col];
1254 1212
1255 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); 1213 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1256 1214
1257 delete [] wstr; 1215 delete [] wstr;
1258 } 1216 }
1259 1217
1260 if (new_text) 1218 if (new_text)
1303 { 1261 {
1304 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1262 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1305 croak ("new_rend must be arrayref"); 1263 croak ("new_rend must be arrayref");
1306 1264
1307 AV *av = (AV *)SvRV (new_rend); 1265 AV *av = (AV *)SvRV (new_rend);
1308 int len = min (av_len (av) + 1 - start_ofs, max_len); 1266 int len = min (AvFILL (av) + 1 - start_ofs, max_len);
1309 1267
1310 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1268 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
1311 croak ("new_rend array extends beyond horizontal margins"); 1269 croak ("new_rend array extends beyond horizontal margins");
1312 1270
1313 for (int col = start_col; col < start_col + len; col++) 1271 for (int col = start_col; col < start_col + len; col++)
1381 else 1339 else
1382 *r++ = *s; 1340 *r++ = *s;
1383 1341
1384 rxvt_pop_locale (); 1342 rxvt_pop_locale ();
1385 1343
1386 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); 1344 RETVAL = wcs2sv (rstr, r - rstr);
1387 1345
1388 delete [] rstr; 1346 delete [] rstr;
1389} 1347}
1390 OUTPUT: 1348 OUTPUT:
1391 RETVAL 1349 RETVAL
1417 else if (IS_COMPOSE (*s)) 1375 else if (IS_COMPOSE (*s))
1418 r += rxvt_composite.expand (*s, r); 1376 r += rxvt_composite.expand (*s, r);
1419 else 1377 else
1420 *r++ = *s; 1378 *r++ = *s;
1421 1379
1422 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); 1380 RETVAL = wcs2sv (rstr, r - rstr);
1423 1381
1424 delete [] rstr; 1382 delete [] rstr;
1425} 1383}
1426 OUTPUT: 1384 OUTPUT:
1427 RETVAL 1385 RETVAL
1449 1407
1450 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1408 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1451 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);
1452 1410
1453 if (GIMME_V != G_VOID) 1411 if (GIMME_V != G_VOID)
1454 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);
1455 1413
1456 if (newval) 1414 if (newval)
1457 { 1415 {
1458 if (SvOK (newval)) 1416 if (SvOK (newval))
1459 { 1417 {
1466 } 1424 }
1467} 1425}
1468 1426
1469const char * 1427const char *
1470rxvt_term::x_resource (const char *name) 1428rxvt_term::x_resource (const char *name)
1471 CLEANUP:
1472 SvTAINTED_on (ST (0));
1473 1429
1474bool 1430bool
1475rxvt_term::option (U32 optval, int set = -1) 1431rxvt_term::option (U32 optval, int set = -1)
1476 CODE: 1432 CODE:
1477{ 1433{
1482 if (set) 1438 if (set)
1483 THIS->options |= optval; 1439 THIS->options |= optval;
1484 else 1440 else
1485 THIS->options &= ~optval; 1441 THIS->options &= ~optval;
1486 1442
1443 if (THIS->check_ev.is_active ()) // avoid doing this before START
1487 switch (optval) 1444 switch (optval)
1488 { 1445 {
1489 case Opt_skipBuiltinGlyphs: 1446 case Opt_skipBuiltinGlyphs:
1490 THIS->set_fonts (); 1447 THIS->set_fonts ();
1491 THIS->scr_remap_chars (); 1448 THIS->scr_remap_chars ();
1492 THIS->scr_touch (true); 1449 THIS->scr_touch (true);
1493 THIS->want_refresh = 1; 1450 THIS->want_refresh = 1;
1494 break; 1451 break;
1495 1452
1496 case Opt_cursorUnderline: 1453 case Opt_cursorUnderline:
1497 THIS->want_refresh = 1; 1454 THIS->want_refresh = 1;
1498 break; 1455 break;
1499 1456
1500# case Opt_scrollBar_floating: 1457# case Opt_scrollBar_floating:
1501# case Opt_scrollBar_right: 1458# case Opt_scrollBar_right:
1502# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1459# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1503# break; 1460# break;
1504 } 1461 }
1505 } 1462 }
1506} 1463}
1507 OUTPUT: 1464 OUTPUT:
1508 RETVAL 1465 RETVAL
1509 1466
1537 PUSHs (sv_2mortal (newSViv (rc.col))); 1494 PUSHs (sv_2mortal (newSViv (rc.col)));
1538 } 1495 }
1539 1496
1540 if (items == 3) 1497 if (items == 3)
1541 { 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);
1542 rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1); 1509 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1543 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
1544 1510
1545 if (ix) 1511 if (ix)
1546 THIS->want_refresh = 1; 1512 THIS->want_refresh = 1;
1547 } 1513 }
1548} 1514}
1556 1522
1557#void 1523#void
1558#rxvt_term::selection_clear () 1524#rxvt_term::selection_clear ()
1559 1525
1560void 1526void
1561rxvt_term::selection_make (U32 eventtime, bool rect = false) 1527rxvt_term::selection_make (Time eventtime, bool rect = false)
1562 CODE: 1528 CODE:
1563 THIS->selection.op = SELECTION_CONT; 1529 THIS->selection.op = SELECTION_CONT;
1564 THIS->selection.rect = rect; 1530 THIS->selection.rect = rect;
1565 THIS->selection_make (eventtime); 1531 THIS->selection_make (eventtime);
1566 1532
1567int 1533int
1568rxvt_term::selection_grab (U32 eventtime) 1534rxvt_term::selection_grab (Time eventtime)
1569 1535
1570void 1536void
1571rxvt_term::selection (SV *newtext = 0) 1537rxvt_term::selection (SV *newtext = 0)
1572 PPCODE: 1538 PPCODE:
1573{ 1539{
1574 if (GIMME_V != G_VOID) 1540 if (GIMME_V != G_VOID)
1575 XPUSHs (THIS->selection.text 1541 XPUSHs (THIS->selection.text
1576 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) 1542 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))
1577 : &PL_sv_undef); 1543 : &PL_sv_undef);
1578 1544
1579 if (newtext) 1545 if (newtext)
1580 { 1546 {
1581 free (THIS->selection.text); 1547 free (THIS->selection.text);
1641 o->self = (HV *)SvRV (RETVAL); 1607 o->self = (HV *)SvRV (RETVAL);
1642} 1608}
1643 OUTPUT: 1609 OUTPUT:
1644 RETVAL 1610 RETVAL
1645 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
1646MODULE = urxvt PACKAGE = urxvt::overlay 1702MODULE = urxvt PACKAGE = urxvt::overlay
1647 1703
1648void 1704void
1649overlay::set (int x, int y, SV *text, SV *rend = 0) 1705overlay::set (int x, int y, SV *text, SV *rend = 0)
1650 1706
1654void 1710void
1655overlay::hide () 1711overlay::hide ()
1656 1712
1657void 1713void
1658overlay::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#############################################################################
1659 1732
1660MODULE = urxvt PACKAGE = urxvt::timer 1733MODULE = urxvt PACKAGE = urxvt::timer
1661 1734
1662SV * 1735SV *
1663timer::new () 1736timer::new ()
1664 CODE: 1737 CODE:
1665 timer *w = new timer; 1738 timer *w = new timer;
1666 w->start (NOW); 1739 w->start (NOW);
1667 RETVAL = newSVptr ((void *)w, "urxvt::timer"); 1740 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::timer");
1668 w->self = (HV *)SvRV (RETVAL); 1741 w->self = (HV *)SvRV (RETVAL);
1669 OUTPUT:
1670 RETVAL
1671
1672timer *
1673timer::cb (SV *cb)
1674 CODE:
1675 THIS->cb (cb);
1676 RETVAL = THIS;
1677 OUTPUT: 1742 OUTPUT:
1678 RETVAL 1743 RETVAL
1679 1744
1680NV 1745NV
1681timer::at () 1746timer::at ()
1682 CODE: 1747 CODE:
1683 RETVAL = THIS->at; 1748 RETVAL = THIS->at;
1684 OUTPUT: 1749 OUTPUT:
1685 RETVAL 1750 RETVAL
1686 1751
1687timer * 1752CHAINED
1688timer::interval (NV interval) 1753timer::interval (NV interval)
1689 CODE: 1754 CODE:
1690 THIS->interval = interval; 1755 THIS->interval = interval;
1756 OUTPUT:
1691 RETVAL = THIS; 1757 RETVAL
1692 OUTPUT:
1693 RETVAL
1694 1758
1695timer * 1759CHAINED
1696timer::set (NV tstamp) 1760timer::set (NV tstamp)
1697 CODE: 1761 CODE:
1698 THIS->set (tstamp); 1762 THIS->set (tstamp);
1763 OUTPUT:
1699 RETVAL = THIS; 1764 RETVAL
1700 OUTPUT:
1701 RETVAL
1702 1765
1703timer * 1766CHAINED
1704timer::start (NV tstamp = THIS->at) 1767timer::start (NV tstamp = THIS->at)
1705 CODE: 1768 CODE:
1706 THIS->start (tstamp); 1769 THIS->start (tstamp);
1770 OUTPUT:
1707 RETVAL = THIS; 1771 RETVAL
1708 OUTPUT:
1709 RETVAL
1710 1772
1711timer * 1773CHAINED
1774timer::after (NV delay)
1775 CODE:
1776 THIS->start (NOW + delay);
1777 OUTPUT:
1778 RETVAL
1779
1780CHAINED
1712timer::stop () 1781timer::stop ()
1713 CODE: 1782 CODE:
1714 THIS->stop (); 1783 THIS->stop ();
1715 RETVAL = THIS;
1716 OUTPUT: 1784 OUTPUT:
1717 RETVAL 1785 RETVAL
1718 1786
1719void 1787void
1720timer::DESTROY () 1788timer::DESTROY ()
1789
1790#############################################################################
1791# urxvt::iow
1792#############################################################################
1721 1793
1722MODULE = urxvt PACKAGE = urxvt::iow 1794MODULE = urxvt PACKAGE = urxvt::iow
1723 1795
1724SV * 1796SV *
1725iow::new () 1797iow::new ()
1726 CODE: 1798 CODE:
1727 iow *w = new iow; 1799 iow *w = new iow;
1728 RETVAL = newSVptr ((void *)w, "urxvt::iow"); 1800 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iow");
1729 w->self = (HV *)SvRV (RETVAL); 1801 w->self = (HV *)SvRV (RETVAL);
1730 OUTPUT: 1802 OUTPUT:
1731 RETVAL 1803 RETVAL
1732 1804
1733iow * 1805CHAINED
1734iow::cb (SV *cb)
1735 CODE:
1736 THIS->cb (cb);
1737 RETVAL = THIS;
1738 OUTPUT:
1739 RETVAL
1740
1741iow *
1742iow::fd (int fd) 1806iow::fd (int fd)
1743 CODE: 1807 CODE:
1744 THIS->fd = fd; 1808 THIS->fd = fd;
1809 OUTPUT:
1745 RETVAL = THIS; 1810 RETVAL
1746 OUTPUT:
1747 RETVAL
1748 1811
1749iow * 1812CHAINED
1750iow::events (short events) 1813iow::events (short events)
1751 CODE: 1814 CODE:
1752 THIS->events = events; 1815 THIS->events = events;
1816 OUTPUT:
1753 RETVAL = THIS; 1817 RETVAL
1754 OUTPUT:
1755 RETVAL
1756 1818
1757iow * 1819CHAINED
1758iow::start () 1820iow::start ()
1759 CODE: 1821 CODE:
1760 THIS->start (); 1822 THIS->start ();
1823 OUTPUT:
1761 RETVAL = THIS; 1824 RETVAL
1762 OUTPUT:
1763 RETVAL
1764 1825
1765iow * 1826CHAINED
1766iow::stop () 1827iow::stop ()
1767 CODE: 1828 CODE:
1768 THIS->stop (); 1829 THIS->stop ();
1769 RETVAL = THIS;
1770 OUTPUT: 1830 OUTPUT:
1771 RETVAL 1831 RETVAL
1772 1832
1773void 1833void
1774iow::DESTROY () 1834iow::DESTROY ()
1775 1835
1836#############################################################################
1837# urxvt::iw
1838#############################################################################
1776 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