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.106 by root, Tue Oct 3 12:13:57 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)
80new_ref (HV *hv, const char *klass) 80new_ref (HV *hv, const char *klass)
81{ 81{
82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
83} 83}
84 84
85//TODO: use magic
86static SV * 85static SV *
87newSVptr (void *ptr, const char *klass) 86newSVptr (void *ptr, const char *klass)
88{ 87{
89 HV *hv = newHV (); 88 HV *hv = newHV ();
90 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 89 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
113 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 112 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
114 113
115 return (long)mg->mg_ptr; 114 return (long)mg->mg_ptr;
116} 115}
117 116
118#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) 117#define newSVterm(term) SvREFCNT_inc ((SV *)(term)->perl.self)
119#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 118#define SvTERM(sv) (rxvt_term *)SvPTR ((sv), "urxvt::term")
120 119
121///////////////////////////////////////////////////////////////////////////// 120/////////////////////////////////////////////////////////////////////////////
121
122#define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, "urxvt::watcher")
122 123
123struct perl_watcher 124struct perl_watcher
124{ 125{
125 SV *cbsv; 126 SV *cbsv;
126 HV *self; 127 HV *self;
127 128
128 perl_watcher () 129 perl_watcher ()
129 : cbsv (newSV (0)) 130 : cbsv (0)
130 { 131 {
131 } 132 }
132 133
133 ~perl_watcher () 134 ~perl_watcher ()
134 { 135 {
135 SvREFCNT_dec (cbsv); 136 SvREFCNT_dec (cbsv);
136 } 137 }
137 138
138 void cb (SV *cb) 139 void cb (SV *cb)
139 { 140 {
140 sv_setsv (cbsv, cb); 141 SvREFCNT_dec (cbsv);
142 cbsv = newSVsv (cb);
141 } 143 }
142 144
143 void invoke (const char *type, SV *self, int arg = -1); 145 void invoke (const char *type, SV *self, int arg = -1);
144}; 146};
145 147
168 170
169 if (SvTRUE (ERRSV)) 171 if (SvTRUE (ERRSV))
170 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV)); 172 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
171} 173}
172 174
173#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") 175#define newSVtimer(timer) new_ref ((timer)->self, "urxvt::timer")
174#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") 176#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR ((sv), "urxvt::timer")
175 177
176struct timer : time_watcher, perl_watcher 178struct timer : perl_watcher, time_watcher
177{ 179{
178 tstamp interval; 180 tstamp interval;
179 181
180 timer () 182 timer ()
181 : time_watcher (this, &timer::execute) 183 : time_watcher (this, &timer::execute)
189 191
190 invoke ("urxvt::timer", newSVtimer (this)); 192 invoke ("urxvt::timer", newSVtimer (this));
191 } 193 }
192}; 194};
193 195
194#define newSViow(iow) new_ref (iow->self, "urxvt::iow") 196#define newSViow(iow) new_ref ((iow)->self, "urxvt::iow")
195#define SvIOW(sv) (iow *)SvPTR (sv, "urxvt::iow") 197#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR ((sv), "urxvt::iow")
196 198
197struct iow : io_watcher, perl_watcher 199struct iow : perl_watcher, io_watcher
198{ 200{
199 iow () 201 iow ()
200 : io_watcher (this, &iow::execute) 202 : io_watcher (this, &iow::execute)
201 { 203 {
202 } 204 }
205 { 207 {
206 invoke ("urxvt::iow", newSViow (this), revents); 208 invoke ("urxvt::iow", newSViow (this), revents);
207 } 209 }
208}; 210};
209 211
212#define newSViw(iw) new_ref ((iw)->self, "urxvt::iw")
213#define SvIW(sv) (iw *)(perl_watcher *)SvPTR ((sv), "urxvt::iw")
214
215struct iw : perl_watcher, idle_watcher
216{
217 iw ()
218 : idle_watcher (this, &iw::execute)
219 {
220 }
221
222 void execute (idle_watcher &w)
223 {
224 invoke ("urxvt::iw", newSViw (this));
225 }
226};
227
228#define newSVpw(pw) new_ref ((pw)->self, "urxvt::pw")
229#define SvPW(sv) (pw *)(perl_watcher *)SvPTR ((sv), "urxvt::pw")
230
231struct pw : perl_watcher, child_watcher
232{
233 pw ()
234 : child_watcher (this, &pw::execute)
235 {
236 }
237
238 void execute (child_watcher &w, int status)
239 {
240 invoke ("urxvt::pw", newSVpw (this), status);
241 }
242};
243
210///////////////////////////////////////////////////////////////////////////// 244/////////////////////////////////////////////////////////////////////////////
211 245
212#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 246#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
213 247
214struct overlay { 248class overlay {
215 HV *self;
216 rxvt_term *THIS; 249 rxvt_term *THIS;
250 AV *overlay_av;
217 int x, y, w, h; 251 int x, y, w, h;
218 int border; 252 int border;
219 text_t **text; 253 text_t **text;
220 rend_t **rend; 254 rend_t **rend;
221 255
256public:
257 HV *self;
258
222 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); 259 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
223 ~overlay (); 260 ~overlay ();
224 261
225 void show (); 262 void show ();
226 void hide (); 263 void hide ();
229 266
230 void set (int x, int y, SV *str, SV *rend); 267 void set (int x, int y, SV *str, SV *rend);
231}; 268};
232 269
233overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 270overlay::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) 271: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0)
235{ 272{
273 if (w < 0) w = 0;
274 if (h < 0) h = 0;
275
236 if (border == 2) 276 if (border == 2)
237 { 277 {
238 w += 2; 278 w += 2;
239 h += 2; 279 h += 2;
240 } 280 }
278 *rp++ = r; 318 *rp++ = r;
279 } 319 }
280 } 320 }
281 321
282 show (); 322 show ();
283 THIS->want_refresh = 1;
284} 323}
285 324
286overlay::~overlay () 325overlay::~overlay ()
287{ 326{
288 hide (); 327 hide ();
293 delete [] rend[y]; 332 delete [] rend[y];
294 } 333 }
295 334
296 delete [] text; 335 delete [] text;
297 delete [] rend; 336 delete [] rend;
337}
338
339void
340overlay::show ()
341{
342 if (overlay_av)
343 return;
344
345 overlay_av = (AV *)SvREFCNT_inc (SvRV (
346 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
347 ));
348 av_push (overlay_av, newSViv ((long)this));
298 349
299 THIS->want_refresh = 1; 350 THIS->want_refresh = 1;
300} 351}
301 352
302void 353void
303overlay::show ()
304{
305 char key[33]; sprintf (key, "%32lx", (long)this);
306
307 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
308 hv_store (hv, key, 32, newSViv ((long)this), 0);
309}
310
311void
312overlay::hide () 354overlay::hide ()
313{ 355{
314 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); 356 if (!overlay_av)
357 return;
315 358
316 if (ovs) 359 int i;
317 {
318 char key[33]; sprintf (key, "%32lx", (long)this);
319 360
320 HV *hv = (HV *)SvRV (*ovs); 361 for (i = AvFILL (overlay_av); i >= 0; i--)
321 hv_delete (hv, key, 32, G_DISCARD); 362 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this)
322 } 363 break;
364
365 for (; i < AvFILL (overlay_av); i++)
366 av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0)));
367
368 av_pop (overlay_av);
369
370 SvREFCNT_dec (overlay_av);
371 overlay_av = 0;
372
373 THIS->want_refresh = 1;
323} 374}
324 375
325void overlay::swap () 376void overlay::swap ()
326{ 377{
327 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 378 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
367 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) 418 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
368 croak ("rend must be arrayref"); 419 croak ("rend must be arrayref");
369 420
370 AV *av = (AV *)SvRV (rend); 421 AV *av = (AV *)SvRV (rend);
371 422
372 for (int col = min (av_len (av) + 1, w - x - border); col--; ) 423 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
373 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 424 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
374 } 425 }
375 426
376 THIS->want_refresh = 1; 427 THIS->want_refresh = 1;
377} 428}
402 perl_environ = rxvt_environ; 453 perl_environ = rxvt_environ;
403 swap (perl_environ, environ); 454 swap (perl_environ, environ);
404 455
405 char *argv[] = { 456 char *argv[] = {
406 "", 457 "",
407 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 458 "-e"
459 "BEGIN {"
460 " urxvt->bootstrap;"
461 " unshift @INC, '" LIBDIR "';"
462 "}"
463 ""
464 "use urxvt;"
408 }; 465 };
409 466
410 perl = perl_alloc (); 467 perl = perl_alloc ();
411 perl_construct (perl); 468 perl_construct (perl);
412 469
427 484
428 if (perl) 485 if (perl)
429 { 486 {
430 // runs outside of perls ENV 487 // runs outside of perls ENV
431 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 488 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); 489 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0);
433 } 490 }
434} 491}
435 492
436static void 493static void
437ungrab (rxvt_term *THIS) 494ungrab (rxvt_term *THIS)
438{ 495{
439 if (THIS->perl.grabtime) 496 if (THIS->perl.grabtime)
440 { 497 {
441 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); 498 XUngrabKeyboard (THIS->dpy, THIS->perl.grabtime);
442 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 499 XUngrabPointer (THIS->dpy, THIS->perl.grabtime);
443 THIS->perl.grabtime = 0; 500 THIS->perl.grabtime = 0;
444 } 501 }
445} 502}
446 503
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 504bool
462rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 505rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
463{ 506{
464 if (!perl || !term->perl.self) 507 if (!perl || !term->perl.self)
465 return false; 508 return false;
466 509
467 // pre-handling of some events 510 // pre-handling of some events
468 if (htype == HOOK_REFRESH_END) 511 if (htype == HOOK_REFRESH_END)
469 swap_overlays (term); 512 {
513 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
514
515 for (int i = 0; i <= AvFILL (av); i++)
516 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
517 }
470 518
471 swap (perl_environ, environ); 519 swap (perl_environ, environ);
472 520
473 bool event_consumed; 521 bool event_consumed;
474 522
507 break; 555 break;
508 556
509 case DT_STR_LEN: 557 case DT_STR_LEN:
510 { 558 {
511 char *str = va_arg (ap, char *); 559 char *str = va_arg (ap, char *);
512 int len = va_arg (ap, int); 560 int len = va_arg (ap, int);
513 561
514 XPUSHs (sv_2mortal (newSVpvn (str, len))); 562 XPUSHs (sv_2mortal (newSVpvn (str, len)));
515 } 563 }
516 break; 564 break;
517 565
518 case DT_WCS_LEN: 566 case DT_WCS_LEN:
519 { 567 {
520 wchar_t *wstr = va_arg (ap, wchar_t *); 568 wchar_t *wstr = va_arg (ap, wchar_t *);
521 int wlen = va_arg (ap, int); 569 int wlen = va_arg (ap, int);
522 570
523 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 571 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
572 }
573 break;
574
575 case DT_LCS_LEN:
576 {
577 long *lstr = va_arg (ap, long *);
578 int llen = va_arg (ap, int);
579
580 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long))));
524 } 581 }
525 break; 582 break;
526 583
527 case DT_XEVENT: 584 case DT_XEVENT:
528 { 585 {
529 XEvent *xe = va_arg (ap, XEvent *); 586 XEvent *xe = va_arg (ap, XEvent *);
530 HV *hv = newHV (); 587 HV *hv = newHV ();
531 588
532# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 589# 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) 590# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
591# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
534# undef set 592# undef set
535 593
536 setiv (type, xe->type); 594 setiv (type, xe->type);
537 setiv (send_event, xe->xany.send_event); 595 setiv (send_event, xe->xany.send_event);
538 setiv (serial, xe->xany.serial); 596 setiv (serial, xe->xany.serial);
539 597
542 case KeyPress: 600 case KeyPress:
543 case KeyRelease: 601 case KeyRelease:
544 case ButtonPress: 602 case ButtonPress:
545 case ButtonRelease: 603 case ButtonRelease:
546 case MotionNotify: 604 case MotionNotify:
605 setuv (window, xe->xmotion.window);
606 setuv (root, xe->xmotion.root);
607 setuv (subwindow, xe->xmotion.subwindow);
547 setiv (time, xe->xmotion.time); 608 setuv (time, xe->xmotion.time);
548 setiv (x, xe->xmotion.x); 609 setiv (x, xe->xmotion.x);
549 setiv (y, xe->xmotion.y); 610 setiv (y, xe->xmotion.y);
550 setiv (row, xe->xmotion.y / term->fheight); 611 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
551 setiv (col, xe->xmotion.x / term->fwidth); 612 setiv (col, xe->xmotion.x / term->fwidth);
552 setiv (x_root, xe->xmotion.x_root); 613 setiv (x_root, xe->xmotion.x_root);
553 setiv (y_root, xe->xmotion.y_root); 614 setiv (y_root, xe->xmotion.y_root);
554 setiv (state, xe->xmotion.state); 615 setuv (state, xe->xmotion.state);
616
617 switch (xe->type)
618 {
619 case KeyPress:
620 case KeyRelease:
621 setuv (keycode, xe->xkey.keycode);
622 break;
623
624 case ButtonPress:
625 case ButtonRelease:
626 setuv (button, xe->xbutton.button);
627 break;
628
629 case MotionNotify:
630 setiv (is_hint, xe->xmotion.is_hint);
631 break;
632 }
633
555 break; 634 break;
556 }
557 635
636 case MapNotify:
637 case UnmapNotify:
638 case ConfigureNotify:
639 setuv (event, xe->xconfigure.event);
640 setuv (window, xe->xconfigure.window);
641
558 switch (xe->type) 642 switch (xe->type)
559 { 643 {
560 case KeyPress: 644 case ConfigureNotify:
561 case KeyRelease: 645 setiv (x, xe->xconfigure.x);
562 setiv (keycode, xe->xkey.keycode); 646 setiv (y, xe->xconfigure.y);
647 setiv (width, xe->xconfigure.width);
648 setiv (height, xe->xconfigure.height);
649 setuv (above, xe->xconfigure.above);
650 break;
651 }
652
563 break; 653 break;
564 654
565 case ButtonPress: 655 case PropertyNotify:
566 case ButtonRelease: 656 setuv (window, xe->xproperty.window);
567 setiv (button, xe->xbutton.button); 657 setuv (atom, xe->xproperty.atom);
658 setuv (time, xe->xproperty.time);
659 setiv (state, xe->xproperty.state);
568 break; 660 break;
569 661
570 case MotionNotify: 662 case ClientMessage:
571 setiv (is_hint, xe->xmotion.is_hint); 663 setuv (window, xe->xclient.window);
664 setuv (message_type, xe->xclient.message_type);
665 setuv (format, xe->xclient.format);
666 setuv (l0, xe->xclient.data.l[0]);
667 setuv (l1, xe->xclient.data.l[1]);
668 setuv (l2, xe->xclient.data.l[2]);
669 setuv (l3, xe->xclient.data.l[3]);
670 setuv (l4, xe->xclient.data.l[4]);
572 break; 671 break;
573 } 672 }
574 673
575 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 674 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
576 } 675 }
617 else 716 else
618 event_consumed = false; 717 event_consumed = false;
619 718
620 // post-handling of some events 719 // post-handling of some events
621 if (htype == HOOK_REFRESH_BEGIN) 720 if (htype == HOOK_REFRESH_BEGIN)
622 swap_overlays (term); 721 {
722 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
723
724 for (int i = AvFILL (av); i >= 0; i--)
725 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
726 }
623 else if (htype == HOOK_DESTROY) 727 else if (htype == HOOK_DESTROY)
624 { 728 {
625 clearSVptr ((SV *)term->perl.self); 729 clearSVptr ((SV *)term->perl.self);
626 SvREFCNT_dec ((SV *)term->perl.self); 730 SvREFCNT_dec ((SV *)term->perl.self);
731
732 // don't allow further calls
733 term->perl.self = 0;
627 } 734 }
628 735
629 swap (perl_environ, environ); 736 swap (perl_environ, environ);
630 737
631 return event_consumed; 738 return event_consumed;
655# include "optinc.h" 762# include "optinc.h"
656# undef nodef 763# undef nodef
657# undef def 764# undef def
658 765
659 HV *stash = gv_stashpv ("urxvt", 1); 766 HV *stash = gv_stashpv ("urxvt", 1);
660 struct { 767 static const struct {
661 const char *name; 768 const char *name;
662 IV iv; 769 IV iv;
663 } *civ, const_iv[] = { 770 } *civ, const_iv[] = {
664# define const_iv(name) { # name, (IV)name } 771# define const_iv(name) { # name, (IV)name }
665 const_iv (DEFAULT_RSTYLE), 772 const_iv (DEFAULT_RSTYLE),
683 const_iv (Button2Mask), 790 const_iv (Button2Mask),
684 const_iv (Button3Mask), 791 const_iv (Button3Mask),
685 const_iv (Button4Mask), 792 const_iv (Button4Mask),
686 const_iv (Button5Mask), 793 const_iv (Button5Mask),
687 const_iv (AnyModifier), 794 const_iv (AnyModifier),
795
796 const_iv (NoSymbol),
797 const_iv (GrabModeSync),
798 const_iv (GrabModeAsync),
688 799
689 const_iv (EVENT_NONE), 800 const_iv (EVENT_NONE),
690 const_iv (EVENT_READ), 801 const_iv (EVENT_READ),
691 const_iv (EVENT_WRITE), 802 const_iv (EVENT_WRITE),
692 803
748 const_iv (SelectionRequest), 859 const_iv (SelectionRequest),
749 const_iv (SelectionNotify), 860 const_iv (SelectionNotify),
750 const_iv (ColormapNotify), 861 const_iv (ColormapNotify),
751 const_iv (ClientMessage), 862 const_iv (ClientMessage),
752 const_iv (MappingNotify), 863 const_iv (MappingNotify),
864# if ENABLE_XIM_ONTHESPOT
865 const_iv (XIMReverse),
866 const_iv (XIMUnderline),
867 const_iv (XIMHighlight),
868 const_iv (XIMPrimary),
869 const_iv (XIMSecondary),
870 const_iv (XIMTertiary),
871 const_iv (XIMVisibleToForward),
872 const_iv (XIMVisibleToBackword),
873 const_iv (XIMVisibleToCenter),
874# if 0
875 const_iv (XIMForwardChar),
876 const_iv (XIMBackwardChar),
877 const_iv (XIMForwardWord),
878 const_iv (XIMBackwardWord),
879 const_iv (XIMCaretUp),
880 const_iv (XIMCaretDown),
881 const_iv (XIMNextLine),
882 const_iv (XIMPreviousLine),
883 const_iv (XIMLineStart),
884 const_iv (XIMLineEnd),
885 const_iv (XIMAbsolutePosition),
886 const_iv (XIMDontChange),
887# endif
888# endif
753 }; 889 };
754 890
755 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); 891 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
756 civ-- > const_iv; )
757 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 892 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
758} 893}
759 894
760void 895void
761warn (const char *msg) 896warn (const char *msg)
792 RETVAL 927 RETVAL
793 928
794int 929int
795SET_FGCOLOR (int rend, int new_color) 930SET_FGCOLOR (int rend, int new_color)
796 CODE: 931 CODE:
797 RETVAL = SET_FGCOLOR (rend, new_color); 932 RETVAL = SET_FGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
798 OUTPUT: 933 OUTPUT:
799 RETVAL 934 RETVAL
800 935
801int 936int
802SET_BGCOLOR (int rend, int new_color) 937SET_BGCOLOR (int rend, int new_color)
803 CODE: 938 CODE:
804 RETVAL = SET_BGCOLOR (rend, new_color); 939 RETVAL = SET_BGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
805 OUTPUT: 940 OUTPUT:
806 RETVAL 941 RETVAL
807 942
808int 943int
809GET_CUSTOM (int rend) 944GET_CUSTOM (int rend)
823 | ((new_value << RS_customShift) & RS_customMask); 958 | ((new_value << RS_customShift) & RS_customMask);
824} 959}
825 OUTPUT: 960 OUTPUT:
826 RETVAL 961 RETVAL
827 962
963void
964termlist ()
965 PPCODE:
966{
967 EXTEND (SP, rxvt_term::termlist.size ());
968
969 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
970 if ((*t)->perl.self)
971 PUSHs (sv_2mortal (newSVterm (*t)));
972}
973
828MODULE = urxvt PACKAGE = urxvt::term 974MODULE = urxvt PACKAGE = urxvt::term
829 975
830SV * 976SV *
831_new (...) 977_new (AV *env, AV *arg)
832 CODE: 978 CODE:
833{ 979{
834 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
835 croak ("first argument to urxvt::term->_new must be arrayref");
836
837 rxvt_term *term = new rxvt_term; 980 rxvt_term *term = new rxvt_term;
838 981
839 term->argv = new stringvec; 982 stringvec *argv = new stringvec;
840 term->envv = new stringvec; 983 stringvec *envv = new stringvec;
841 984
842 for (int i = 1; i < items; i++) 985 for (int i = 0; i <= AvFILL (arg); i++)
843 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 986 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
844 987
845 AV *envv = (AV *)SvRV (ST (0));
846 for (int i = av_len (envv) + 1; i--; ) 988 for (int i = AvFILL (env) + 1; i--; )
847 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 989 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
848 990
849 term->envv->push_back (0); 991 envv->push_back (0);
850 992
851 bool success; 993 bool success;
852 994
853 try 995 try
854 { 996 {
855 success = term->init (term->argv->size (), term->argv->begin ()); 997 success = term->init (argv, envv);
856 } 998 }
857 catch (const class rxvt_failure_exception &e) 999 catch (const class rxvt_failure_exception &e)
858 { 1000 {
859 success = false; 1001 success = false;
860 } 1002 }
872 RETVAL 1014 RETVAL
873 1015
874void 1016void
875rxvt_term::destroy () 1017rxvt_term::destroy ()
876 1018
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 1019void
967rxvt_term::set_should_invoke (int htype, int inc) 1020rxvt_term::set_should_invoke (int htype, int inc)
968 CODE: 1021 CODE:
969 THIS->perl.should_invoke [htype] += inc; 1022 THIS->perl.should_invoke [htype] += inc;
970 1023
971void 1024int
972rxvt_term::grab_button (int button, U32 modifiers) 1025rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt)
973 CODE: 1026 CODE:
974 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 1027 RETVAL = XGrabButton (THIS->dpy, button, modifiers, window, 1,
975 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1028 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
976 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 1029 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
1030 OUTPUT: RETVAL
1031
1032int
1033rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt)
1034 CODE:
1035 RETVAL = XUngrabButton (THIS->dpy, button, modifiers, window);
1036 OUTPUT: RETVAL
1037
1038void
1039rxvt_term::XGrabKey (int keycode, U32 modifiers, Window window = THIS->vt, \
1040 int owner_events = 1, int pointer_mode = GrabModeAsync, int keyboard_mode = GrabModeAsync)
1041 CODE:
1042 XGrabKey (THIS->dpy, keycode, modifiers, window, owner_events, pointer_mode, keyboard_mode);
1043
1044void
1045rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt)
1046 CODE:
1047 XUngrabKey (THIS->dpy, keycode, modifiers, window);
1048
1049void
1050rxvt_term::XUngrabKeyboard (Time eventtime)
1051 CODE:
1052 XUngrabKeyboard (THIS->dpy, eventtime);
977 1053
978bool 1054bool
979rxvt_term::grab (U32 eventtime, int sync = 0) 1055rxvt_term::grab (Time eventtime, int sync = 0)
980 CODE: 1056 CODE:
981{ 1057{
982 int mode = sync ? GrabModeSync : GrabModeAsync; 1058 int mode = sync ? GrabModeSync : GrabModeAsync;
983 1059
984 THIS->perl.grabtime = 0; 1060 THIS->perl.grabtime = 0;
985 1061
986 if (!XGrabPointer (THIS->display->display, THIS->vt, 0, 1062 if (!XGrabPointer (THIS->dpy, THIS->vt, 0,
987 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1063 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
988 mode, mode, None, GRAB_CURSOR, eventtime)) 1064 mode, mode, None, GRAB_CURSOR, eventtime))
989 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) 1065 if (!XGrabKeyboard (THIS->dpy, THIS->vt, 0, mode, mode, eventtime))
990 THIS->perl.grabtime = eventtime; 1066 THIS->perl.grabtime = eventtime;
991 else 1067 else
992 XUngrabPointer (THIS->display->display, eventtime); 1068 XUngrabPointer (THIS->dpy, eventtime);
993 1069
994 RETVAL = !!THIS->perl.grabtime; 1070 RETVAL = !!THIS->perl.grabtime;
995} 1071}
996 OUTPUT: 1072 OUTPUT:
997 RETVAL 1073 RETVAL
998 1074
999void 1075void
1000rxvt_term::allow_events_async () 1076rxvt_term::allow_events_async ()
1001 CODE: 1077 CODE:
1002 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); 1078 XAllowEvents (THIS->dpy, AsyncBoth, THIS->perl.grabtime);
1003 1079
1004void 1080void
1005rxvt_term::allow_events_sync () 1081rxvt_term::allow_events_sync ()
1006 CODE: 1082 CODE:
1007 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); 1083 XAllowEvents (THIS->dpy, SyncBoth, THIS->perl.grabtime);
1008 1084
1009void 1085void
1010rxvt_term::allow_events_replay () 1086rxvt_term::allow_events_replay ()
1011 CODE: 1087 CODE:
1012 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); 1088 XAllowEvents (THIS->dpy, ReplayPointer, THIS->perl.grabtime);
1013 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); 1089 XAllowEvents (THIS->dpy, ReplayKeyboard, THIS->perl.grabtime);
1014 1090
1015void 1091void
1016rxvt_term::ungrab () 1092rxvt_term::ungrab ()
1017 CODE: 1093 CODE:
1018 ungrab (THIS); 1094 ungrab (THIS);
1095
1096int
1097rxvt_term::XStringToKeysym (char *string)
1098 CODE:
1099 RETVAL = XStringToKeysym (string);
1100 OUTPUT: RETVAL
1101
1102char *
1103rxvt_term::XKeysymToString (int sym)
1104 CODE:
1105 RETVAL = XKeysymToString (sym);
1106 OUTPUT: RETVAL
1107
1108int
1109rxvt_term::XKeysymToKeycode (int sym)
1110 CODE:
1111 RETVAL = XKeysymToKeycode (THIS->dpy, sym);
1112 OUTPUT: RETVAL
1113
1114int
1115rxvt_term::XKeycodeToKeysym (int code, int index)
1116 CODE:
1117 RETVAL = XKeycodeToKeysym (THIS->dpy, code, index);
1118 OUTPUT: RETVAL
1019 1119
1020int 1120int
1021rxvt_term::strwidth (SV *str) 1121rxvt_term::strwidth (SV *str)
1022 CODE: 1122 CODE:
1023{ 1123{
1024 wchar_t *wstr = sv2wcs (str); 1124 wchar_t *wstr = sv2wcs (str);
1025 1125
1026 rxvt_push_locale (THIS->locale); 1126 rxvt_push_locale (THIS->locale);
1027 RETVAL = wcswidth (wstr, wcslen (wstr)); 1127 RETVAL = 0;
1128 for (wchar_t *wc = wstr; *wc; wc++)
1129 {
1130 int w = WCWIDTH (*wc);
1131
1132 if (w)
1133 RETVAL += min (w, 1);
1134 }
1028 rxvt_pop_locale (); 1135 rxvt_pop_locale ();
1029 1136
1030 free (wstr); 1137 free (wstr);
1031} 1138}
1032 OUTPUT: 1139 OUTPUT:
1062 rxvt_pop_locale (); 1169 rxvt_pop_locale ();
1063 1170
1064 RETVAL = wcs2sv (wstr); 1171 RETVAL = wcs2sv (wstr);
1065 free (wstr); 1172 free (wstr);
1066} 1173}
1174 OUTPUT:
1175 RETVAL
1176
1177char *
1178rxvt_term::locale ()
1179 CODE:
1180 RETVAL = THIS->locale;
1067 OUTPUT: 1181 OUTPUT:
1068 RETVAL 1182 RETVAL
1069 1183
1070#define TERM_OFFSET(sym) offsetof (TermWin_t, sym) 1184#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
1071 1185
1076#define TERM_OFFSET_fbase TERM_OFFSET(fbase) 1190#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1077#define TERM_OFFSET_nrow TERM_OFFSET(nrow) 1191#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1078#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1192#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1079#define TERM_OFFSET_focus TERM_OFFSET(focus) 1193#define TERM_OFFSET_focus TERM_OFFSET(focus)
1080#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1194#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
1195#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth)
1196#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth)
1197#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace)
1081#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1198#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1082#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1199#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1083#define TERM_OFFSET_top_row TERM_OFFSET(top_row) 1200#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1084 1201
1085int 1202int
1092 fbase = TERM_OFFSET_fbase 1209 fbase = TERM_OFFSET_fbase
1093 nrow = TERM_OFFSET_nrow 1210 nrow = TERM_OFFSET_nrow
1094 ncol = TERM_OFFSET_ncol 1211 ncol = TERM_OFFSET_ncol
1095 focus = TERM_OFFSET_focus 1212 focus = TERM_OFFSET_focus
1096 mapped = TERM_OFFSET_mapped 1213 mapped = TERM_OFFSET_mapped
1214 int_bwidth = TERM_OFFSET_int_bwidth
1215 ext_bwidth = TERM_OFFSET_ext_bwidth
1216 lineSpace = TERM_OFFSET_lineSpace
1097 saveLines = TERM_OFFSET_saveLines 1217 saveLines = TERM_OFFSET_saveLines
1098 total_rows = TERM_OFFSET_total_rows 1218 total_rows = TERM_OFFSET_total_rows
1099 top_row = TERM_OFFSET_top_row 1219 top_row = TERM_OFFSET_top_row
1100 CODE: 1220 CODE:
1101 RETVAL = *(int *)((char *)THIS + ix); 1221 RETVAL = *(int *)((char *)THIS + ix);
1106rxvt_term::ModLevel3Mask () 1226rxvt_term::ModLevel3Mask ()
1107 ALIAS: 1227 ALIAS:
1108 ModLevel3Mask = 0 1228 ModLevel3Mask = 0
1109 ModMetaMask = 1 1229 ModMetaMask = 1
1110 ModNumLockMask = 2 1230 ModNumLockMask = 2
1231 current_screen = 3
1232 hidden_cursor = 4
1111 CODE: 1233 CODE:
1112 switch (ix) 1234 switch (ix)
1113 { 1235 {
1114 case 0: RETVAL = THIS->ModLevel3Mask; break; 1236 case 0: RETVAL = THIS->ModLevel3Mask; break;
1115 case 1: RETVAL = THIS->ModMetaMask; break; 1237 case 1: RETVAL = THIS->ModMetaMask; break;
1116 case 2: RETVAL = THIS->ModNumLockMask; break; 1238 case 2: RETVAL = THIS->ModNumLockMask; break;
1239 case 3: RETVAL = THIS->current_screen; break;
1240 case 4: RETVAL = THIS->hidden_cursor; break;
1117 } 1241 }
1118 OUTPUT: 1242 OUTPUT:
1119 RETVAL 1243 RETVAL
1120 1244
1121char * 1245char *
1131 } 1255 }
1132 OUTPUT: 1256 OUTPUT:
1133 RETVAL 1257 RETVAL
1134 1258
1135SV * 1259SV *
1136rxvt_term::_env () 1260rxvt_term::envv ()
1261 ALIAS:
1262 argv = 1
1137 CODE: 1263 PPCODE:
1138{ 1264{
1139 if (THIS->envv) 1265 stringvec *vec = ix ? THIS->argv : THIS->envv;
1140 {
1141 AV *av = newAV ();
1142 1266
1267 EXTEND (SP, vec->size ());
1268
1143 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) 1269 for (char **i = vec->begin (); i != vec->end (); ++i)
1144 if (*i) 1270 if (*i)
1145 av_push (av, newSVpv (*i, 0)); 1271 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1146
1147 RETVAL = newRV_noinc ((SV *)av);
1148 }
1149 else
1150 RETVAL = &PL_sv_undef;
1151} 1272}
1152 OUTPUT:
1153 RETVAL
1154 1273
1155int 1274int
1156rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1275rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1157 CODE: 1276 CODE:
1158 RETVAL = THIS->pty_ev.events; 1277 RETVAL = THIS->pty_ev.events;
1159 if (events != EVENT_UNDEF) 1278 if (events != EVENT_UNDEF)
1160 THIS->pty_ev.set (events); 1279 THIS->pty_ev.set (events);
1161 OUTPUT: 1280 OUTPUT:
1162 RETVAL 1281 RETVAL
1163 1282
1164U32 1283int
1284rxvt_term::pty_fd ()
1285 CODE:
1286 RETVAL = THIS->pty->pty;
1287 OUTPUT:
1288 RETVAL
1289
1290Window
1165rxvt_term::parent () 1291rxvt_term::parent ()
1166 CODE: 1292 CODE:
1167 RETVAL = (U32)THIS->parent [0]; 1293 RETVAL = THIS->parent [0];
1168 OUTPUT: 1294 OUTPUT:
1169 RETVAL 1295 RETVAL
1170 1296
1171U32 1297Window
1172rxvt_term::vt () 1298rxvt_term::vt ()
1173 CODE: 1299 CODE:
1174 RETVAL = (U32)THIS->vt; 1300 RETVAL = THIS->vt;
1175 OUTPUT: 1301 OUTPUT:
1176 RETVAL 1302 RETVAL
1177 1303
1178void 1304void
1179rxvt_term::vt_emask_add (U32 emask) 1305rxvt_term::vt_emask_add (U32 emask)
1201} 1327}
1202 OUTPUT: 1328 OUTPUT:
1203 RETVAL 1329 RETVAL
1204 1330
1205void 1331void
1332rxvt_term::focus_in ()
1333
1334void
1335rxvt_term::focus_out ()
1336
1337void
1338rxvt_term::key_press (unsigned int state, unsigned int keycode, Time time = CurrentTime)
1339 ALIAS:
1340 key_release = 1
1341 CODE:
1342{
1343 XKeyEvent xkey;
1344
1345 memset (&xkey, 0, sizeof (xkey));
1346
1347 xkey.time = time;
1348 xkey.state = state;
1349 xkey.keycode = keycode;
1350
1351 xkey.type = ix ? KeyRelease : KeyPress;
1352 xkey.display = THIS->dpy;
1353 xkey.window = THIS->vt;
1354 xkey.root = THIS->display->root;
1355 xkey.subwindow = THIS->vt;
1356
1357 if (ix)
1358 THIS->key_release (xkey);
1359 else
1360 THIS->key_press (xkey);
1361}
1362
1363void
1206rxvt_term::want_refresh () 1364rxvt_term::want_refresh ()
1207 CODE: 1365 CODE:
1208 THIS->want_refresh = 1; 1366 THIS->want_refresh = 1;
1209 1367
1210void 1368void
1216 1374
1217 line_t &l = ROW(row_number); 1375 line_t &l = ROW(row_number);
1218 1376
1219 if (GIMME_V != G_VOID) 1377 if (GIMME_V != G_VOID)
1220 { 1378 {
1221 wchar_t *wstr = new wchar_t [THIS->ncol]; 1379 wchar_t *wstr = rxvt_temp_buf<wchar_t> (THIS->ncol);
1222 1380
1223 for (int col = 0; col < THIS->ncol; col++) 1381 for (int col = 0; col < THIS->ncol; col++)
1224 wstr [col] = l.t [col]; 1382 wstr [col] = l.t [col];
1225 1383
1226 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1384 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1227
1228 delete [] wstr;
1229 } 1385 }
1230 1386
1231 if (new_text) 1387 if (new_text)
1232 { 1388 {
1233 wchar_t *wstr = sv2wcs (new_text); 1389 wchar_t *wstr = sv2wcs (new_text);
1234 1390
1235 int len = min (wcslen (wstr) - start_ofs, max_len); 1391 int len = min (wcslen (wstr) - start_ofs, max_len);
1236 1392
1237 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1393 if (start_col < 0 || start_col + len > THIS->ncol)
1238 { 1394 {
1239 free (wstr); 1395 free (wstr);
1240 croak ("new_text extends beyond horizontal margins"); 1396 croak ("new_text extends beyond horizontal margins");
1241 } 1397 }
1242 1398
1274 { 1430 {
1275 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1431 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1276 croak ("new_rend must be arrayref"); 1432 croak ("new_rend must be arrayref");
1277 1433
1278 AV *av = (AV *)SvRV (new_rend); 1434 AV *av = (AV *)SvRV (new_rend);
1279 int len = min (av_len (av) + 1 - start_ofs, max_len); 1435 int len = min (AvFILL (av) + 1 - start_ofs, max_len);
1280 1436
1281 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1437 if (start_col < 0 || start_col + len > THIS->ncol)
1282 croak ("new_rend array extends beyond horizontal margins"); 1438 croak ("new_rend array extends beyond horizontal margins");
1283 1439
1284 for (int col = start_col; col < start_col + len; col++) 1440 for (int col = start_col; col < start_col + len; col++)
1285 { 1441 {
1286 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; 1442 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1326rxvt_term::special_encode (SV *string) 1482rxvt_term::special_encode (SV *string)
1327 CODE: 1483 CODE:
1328{ 1484{
1329 wchar_t *wstr = sv2wcs (string); 1485 wchar_t *wstr = sv2wcs (string);
1330 int wlen = wcslen (wstr); 1486 int wlen = wcslen (wstr);
1331 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer 1487 wchar_t *rstr = rxvt_temp_buf<wchar_t> (wlen * 2); // cannot become longer
1332 1488
1333 rxvt_push_locale (THIS->locale); 1489 rxvt_push_locale (THIS->locale);
1334 1490
1335 wchar_t *r = rstr; 1491 wchar_t *r = rstr;
1336 for (wchar_t *s = wstr; *s; s++) 1492 for (wchar_t *s = wstr; *s; s++)
1493 {
1494 int w = WCWIDTH (*s);
1495
1337 if (wcwidth (*s) == 0) 1496 if (w == 0)
1338 { 1497 {
1339 if (r == rstr) 1498 if (r == rstr)
1340 croak ("leading combining character unencodable"); 1499 croak ("leading combining character unencodable");
1341 1500
1342 unicode_t n = rxvt_compose (r[-1], *s); 1501 unicode_t n = rxvt_compose (r[-1], *s);
1343 if (n == NOCHAR) 1502 if (n == NOCHAR)
1344 n = rxvt_composite.compose (r[-1], *s); 1503 n = rxvt_composite.compose (r[-1], *s);
1345 1504
1346 r[-1] = n; 1505 r[-1] = n;
1347 } 1506 }
1348#if !UNICODE_3 1507#if !UNICODE_3
1349 else if (*s >= 0x10000) 1508 else if (*s >= 0x10000)
1350 *r++ = rxvt_composite.compose (*s); 1509 *r++ = rxvt_composite.compose (*s);
1351#endif 1510#endif
1352 else 1511 else
1353 *r++ = *s; 1512 *r++ = *s;
1513
1514 // the *2 above only allows wcwidth <= 2
1515 if (w > 1)
1516 *r++ = NOCHAR;
1517 }
1354 1518
1355 rxvt_pop_locale (); 1519 rxvt_pop_locale ();
1356 1520
1357 RETVAL = wcs2sv (rstr, r - rstr); 1521 RETVAL = wcs2sv (rstr, r - rstr);
1358
1359 delete [] rstr;
1360} 1522}
1361 OUTPUT: 1523 OUTPUT:
1362 RETVAL 1524 RETVAL
1363 1525
1364SV * 1526SV *
1376 else if (IS_COMPOSE (*s)) 1538 else if (IS_COMPOSE (*s))
1377 dlen += rxvt_composite.expand (*s, 0); 1539 dlen += rxvt_composite.expand (*s, 0);
1378 else 1540 else
1379 dlen++; 1541 dlen++;
1380 1542
1381 wchar_t *rstr = new wchar_t [dlen]; 1543 wchar_t *rstr = rxvt_temp_buf<wchar_t> (dlen);
1382 1544
1383 // decode 1545 // decode
1384 wchar_t *r = rstr; 1546 wchar_t *r = rstr;
1385 for (wchar_t *s = wstr; *s; s++) 1547 for (wchar_t *s = wstr; *s; s++)
1386 if (*s == NOCHAR) 1548 if (*s == NOCHAR)
1389 r += rxvt_composite.expand (*s, r); 1551 r += rxvt_composite.expand (*s, r);
1390 else 1552 else
1391 *r++ = *s; 1553 *r++ = *s;
1392 1554
1393 RETVAL = wcs2sv (rstr, r - rstr); 1555 RETVAL = wcs2sv (rstr, r - rstr);
1394
1395 delete [] rstr;
1396} 1556}
1397 OUTPUT: 1557 OUTPUT:
1398 RETVAL 1558 RETVAL
1399 1559
1400void 1560void
1401rxvt_term::_resource (char *name, int index, SV *newval = 0) 1561rxvt_term::_resource (char *name, int index, SV *newval = 0)
1402 PPCODE: 1562 PPCODE:
1403{ 1563{
1404 struct resval { const char *name; int value; } rslist [] = { 1564 static const struct resval { const char *name; int value; } *rs, rslist [] = {
1405# define def(name) { # name, Rs_ ## name }, 1565# define def(name) { # name, Rs_ ## name },
1406# define reserve(name,count) 1566# define reserve(name,count)
1407# include "rsinc.h" 1567# include "rsinc.h"
1408# undef def 1568# undef def
1409# undef reserve 1569# undef reserve
1410 }; 1570 };
1411 1571
1412 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1572 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1413 1573
1414 do { 1574 do {
1415 if (rs-- == rslist) 1575 if (rs-- == rslist)
1416 croak ("no such resource '%s', requested", name); 1576 croak ("no such resource '%s', requested", name);
1417 } while (strcmp (name, rs->name)); 1577 } while (strcmp (name, rs->name));
1451 if (set) 1611 if (set)
1452 THIS->options |= optval; 1612 THIS->options |= optval;
1453 else 1613 else
1454 THIS->options &= ~optval; 1614 THIS->options &= ~optval;
1455 1615
1616 if (THIS->check_ev.is_active ()) // avoid doing this before START
1456 switch (optval) 1617 switch (optval)
1457 { 1618 {
1458 case Opt_skipBuiltinGlyphs: 1619 case Opt_skipBuiltinGlyphs:
1459 THIS->set_fonts (); 1620 THIS->set_fonts ();
1460 THIS->scr_remap_chars (); 1621 THIS->scr_remap_chars ();
1461 THIS->scr_touch (true); 1622 THIS->scr_touch (true);
1462 THIS->want_refresh = 1; 1623 THIS->want_refresh = 1;
1463 break; 1624 break;
1464 1625
1465 case Opt_cursorUnderline: 1626 case Opt_cursorUnderline:
1466 THIS->want_refresh = 1; 1627 THIS->want_refresh = 1;
1467 break; 1628 break;
1468 1629
1469# case Opt_scrollBar_floating: 1630# case Opt_scrollBar_floating:
1470# case Opt_scrollBar_right: 1631# case Opt_scrollBar_right:
1471# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1632# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1472# break; 1633# break;
1473 } 1634 }
1474 } 1635 }
1475} 1636}
1476 OUTPUT: 1637 OUTPUT:
1477 RETVAL 1638 RETVAL
1478 1639
1506 PUSHs (sv_2mortal (newSViv (rc.col))); 1667 PUSHs (sv_2mortal (newSViv (rc.col)));
1507 } 1668 }
1508 1669
1509 if (items == 3) 1670 if (items == 3)
1510 { 1671 {
1672 rc.row = SvIV (ST (1));
1673 rc.col = SvIV (ST (2));
1674
1675 if (ix == 2)
1676 {
1677 if (rc.col == 0)
1678 {
1679 // col == 0 means end of previous line
1680 rc.row--;
1681 rc.col = THIS->ncol;
1682 }
1683 else if (IN_RANGE_EXC (rc.row, THIS->top_row, THIS->nrow)
1684 && rc.col > ROW(rc.row).l)
1685 {
1686 // col >= length means while line and add newline
1687 rc.col = THIS->ncol;
1688 }
1689 }
1690
1691 clamp_it (rc.col, 0, THIS->ncol);
1511 rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1); 1692 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1512 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
1513 1693
1514 if (ix) 1694 if (ix)
1515 THIS->want_refresh = 1; 1695 THIS->want_refresh = 1;
1516 } 1696 }
1517} 1697}
1521 CODE: 1701 CODE:
1522 RETVAL = THIS->charsets [THIS->screen.charset]; 1702 RETVAL = THIS->charsets [THIS->screen.charset];
1523 OUTPUT: 1703 OUTPUT:
1524 RETVAL 1704 RETVAL
1525 1705
1526#void 1706void
1527#rxvt_term::selection_clear () 1707rxvt_term::selection_clear ()
1528 1708
1529void 1709void
1530rxvt_term::selection_make (U32 eventtime, bool rect = false) 1710rxvt_term::selection_make (Time eventtime, bool rect = false)
1531 CODE: 1711 CODE:
1532 THIS->selection.op = SELECTION_CONT; 1712 THIS->selection.op = SELECTION_CONT;
1533 THIS->selection.rect = rect; 1713 THIS->selection.rect = rect;
1534 THIS->selection_make (eventtime); 1714 THIS->selection_make (eventtime);
1535 1715
1536int 1716int
1537rxvt_term::selection_grab (U32 eventtime) 1717rxvt_term::selection_grab (Time eventtime)
1538 1718
1539void 1719void
1540rxvt_term::selection (SV *newtext = 0) 1720rxvt_term::selection (SV *newtext = 0)
1541 PPCODE: 1721 PPCODE:
1542{ 1722{
1560void 1740void
1561rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) 1741rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1562 1742
1563void 1743void
1564rxvt_term::scr_bell () 1744rxvt_term::scr_bell ()
1745
1746void
1747rxvt_term::scr_change_screen (int screen)
1565 1748
1566void 1749void
1567rxvt_term::scr_add_lines (SV *string) 1750rxvt_term::scr_add_lines (SV *string)
1568 CODE: 1751 CODE:
1569{ 1752{
1610 o->self = (HV *)SvRV (RETVAL); 1793 o->self = (HV *)SvRV (RETVAL);
1611} 1794}
1612 OUTPUT: 1795 OUTPUT:
1613 RETVAL 1796 RETVAL
1614 1797
1798#############################################################################
1799# Various X Utility Functions
1800#############################################################################
1801
1802void
1803rxvt_term::XListProperties (Window window)
1804 PPCODE:
1805{
1806 int count;
1807 Atom *props = XListProperties (THIS->dpy, window, &count);
1808
1809 EXTEND (SP, count);
1810 while (count--)
1811 PUSHs (newSVuv ((U32)props [count]));
1812
1813 XFree (props);
1814}
1815
1816void
1817rxvt_term::XGetWindowProperty (Window window, Atom property)
1818 PPCODE:
1819{
1820 Atom type;
1821 int format;
1822 unsigned long nitems;
1823 unsigned long bytes_after;
1824 unsigned char *prop;
1825
1826 XGetWindowProperty (THIS->dpy, window, property,
1827 0, 1<<24, 0, AnyPropertyType,
1828 &type, &format, &nitems, &bytes_after, &prop);
1829
1830 if (type != None)
1831 {
1832 int elemsize = format == 16 ? sizeof (short)
1833 : format == 32 ? sizeof (long)
1834 : 1;
1835
1836 EXTEND (SP, 3);
1837 PUSHs (newSVuv ((U32)type));
1838 PUSHs (newSViv (format));
1839 PUSHs (newSVpvn ((char *)prop, nitems * elemsize));
1840 XFree (prop);
1841 }
1842}
1843
1844void
1845rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data)
1846 CODE:
1847{
1848 STRLEN len;
1849 char *data_ = SvPVbyte (data, len);
1850
1851 int elemsize = format == 16 ? sizeof (short)
1852 : format == 32 ? sizeof (long)
1853 : 1;
1854
1855 XChangeProperty (THIS->dpy, window, property,
1856 type, format, PropModeReplace,
1857 (unsigned char *)data_, len / elemsize);
1858}
1859
1860Atom
1861XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1862 C_ARGS: term->dpy, atom_name, only_if_exists
1863
1864char *
1865XGetAtomName (rxvt_term *term, Atom atom)
1866 C_ARGS: term->dpy, atom
1867 CLEANUP:
1868 XFree (RETVAL);
1869
1870void
1871XDeleteProperty (rxvt_term *term, Window window, Atom property)
1872 C_ARGS: term->dpy, window, property
1873
1874Window
1875rxvt_term::DefaultRootWindow ()
1876 CODE:
1877 RETVAL = THIS->display->root;
1878 OUTPUT:
1879 RETVAL
1880
1881#if 0
1882
1883Window
1884XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1885 C_ARGS: term->dpy, (Window)parent,
1886 x, y, width, height, 0,
1887 term->pix_colors_focused[Color_border],
1888 term->pix_colors_focused[Color_border]
1889
1890#endif
1891
1892void
1893XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1894 C_ARGS: term->dpy, window, parent, x, y
1895
1896void
1897XMapWindow (rxvt_term *term, Window window)
1898 C_ARGS: term->dpy, window
1899
1900void
1901XUnmapWindow (rxvt_term *term, Window window)
1902 C_ARGS: term->dpy, window
1903
1904void
1905XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1906 C_ARGS: term->dpy, window, x, y, width, height
1907
1908void
1909rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0)
1910 CODE:
1911{
1912 XWindowAttributes attr;
1913 XGetWindowAttributes (THIS->dpy, window, &attr);
1914 XSelectInput (THIS->dpy, window, attr.your_event_mask | add_events & ~del_events);
1915}
1916
1917void
1918rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y)
1919 PPCODE:
1920{
1921 int dx, dy;
1922 Window child;
1923
1924 if (XTranslateCoordinates (THIS->dpy, src, dst, x, y, &dx, &dy, &child))
1925 {
1926 EXTEND (SP, 3);
1927 PUSHs (newSViv (dx));
1928 PUSHs (newSViv (dy));
1929 PUSHs (newSVuv (child));
1930 }
1931}
1932
1933#############################################################################
1934# urxvt::overlay
1935#############################################################################
1936
1615MODULE = urxvt PACKAGE = urxvt::overlay 1937MODULE = urxvt PACKAGE = urxvt::overlay
1616 1938
1617void 1939void
1618overlay::set (int x, int y, SV *text, SV *rend = 0) 1940overlay::set (int x, int y, SV *text, SV *rend = 0)
1619 1941
1623void 1945void
1624overlay::hide () 1946overlay::hide ()
1625 1947
1626void 1948void
1627overlay::DESTROY () 1949overlay::DESTROY ()
1950
1951#############################################################################
1952# urxvt::watcher
1953#############################################################################
1954
1955MODULE = urxvt PACKAGE = urxvt::watcher
1956
1957CHAINED
1958perl_watcher::cb (SV *cb)
1959 CODE:
1960 THIS->cb (cb);
1961 OUTPUT:
1962 RETVAL
1963
1964#############################################################################
1965# urxvt::timer
1966#############################################################################
1628 1967
1629MODULE = urxvt PACKAGE = urxvt::timer 1968MODULE = urxvt PACKAGE = urxvt::timer
1630 1969
1631SV * 1970SV *
1632timer::new () 1971timer::new ()
1633 CODE: 1972 CODE:
1634 timer *w = new timer; 1973 timer *w = new timer;
1635 w->start (NOW); 1974 w->start (NOW);
1636 RETVAL = newSVptr ((void *)w, "urxvt::timer"); 1975 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::timer");
1637 w->self = (HV *)SvRV (RETVAL); 1976 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: 1977 OUTPUT:
1647 RETVAL 1978 RETVAL
1648 1979
1649NV 1980NV
1650timer::at () 1981timer::at ()
1651 CODE: 1982 CODE:
1652 RETVAL = THIS->at; 1983 RETVAL = THIS->at;
1653 OUTPUT: 1984 OUTPUT:
1654 RETVAL 1985 RETVAL
1655 1986
1656timer * 1987CHAINED
1657timer::interval (NV interval) 1988timer::interval (NV interval)
1658 CODE: 1989 CODE:
1659 THIS->interval = interval; 1990 THIS->interval = interval;
1991 OUTPUT:
1660 RETVAL = THIS; 1992 RETVAL
1661 OUTPUT:
1662 RETVAL
1663 1993
1664timer * 1994CHAINED
1665timer::set (NV tstamp) 1995timer::set (NV tstamp)
1666 CODE: 1996 CODE:
1667 THIS->set (tstamp); 1997 THIS->set (tstamp);
1998 OUTPUT:
1668 RETVAL = THIS; 1999 RETVAL
1669 OUTPUT:
1670 RETVAL
1671 2000
1672timer * 2001CHAINED
1673timer::start (NV tstamp = THIS->at) 2002timer::start (NV tstamp = THIS->at)
1674 CODE: 2003 CODE:
1675 THIS->start (tstamp); 2004 THIS->start (tstamp);
2005 OUTPUT:
1676 RETVAL = THIS; 2006 RETVAL
1677 OUTPUT:
1678 RETVAL
1679 2007
1680timer * 2008CHAINED
2009timer::after (NV delay)
2010 CODE:
2011 THIS->start (NOW + delay);
2012 OUTPUT:
2013 RETVAL
2014
2015CHAINED
1681timer::stop () 2016timer::stop ()
1682 CODE: 2017 CODE:
1683 THIS->stop (); 2018 THIS->stop ();
1684 RETVAL = THIS;
1685 OUTPUT: 2019 OUTPUT:
1686 RETVAL 2020 RETVAL
1687 2021
1688void 2022void
1689timer::DESTROY () 2023timer::DESTROY ()
2024
2025#############################################################################
2026# urxvt::iow
2027#############################################################################
1690 2028
1691MODULE = urxvt PACKAGE = urxvt::iow 2029MODULE = urxvt PACKAGE = urxvt::iow
1692 2030
1693SV * 2031SV *
1694iow::new () 2032iow::new ()
1695 CODE: 2033 CODE:
1696 iow *w = new iow; 2034 iow *w = new iow;
1697 RETVAL = newSVptr ((void *)w, "urxvt::iow"); 2035 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iow");
1698 w->self = (HV *)SvRV (RETVAL); 2036 w->self = (HV *)SvRV (RETVAL);
1699 OUTPUT: 2037 OUTPUT:
1700 RETVAL 2038 RETVAL
1701 2039
1702iow * 2040CHAINED
1703iow::cb (SV *cb)
1704 CODE:
1705 THIS->cb (cb);
1706 RETVAL = THIS;
1707 OUTPUT:
1708 RETVAL
1709
1710iow *
1711iow::fd (int fd) 2041iow::fd (int fd)
1712 CODE: 2042 CODE:
1713 THIS->fd = fd; 2043 THIS->fd = fd;
2044 OUTPUT:
1714 RETVAL = THIS; 2045 RETVAL
1715 OUTPUT:
1716 RETVAL
1717 2046
1718iow * 2047CHAINED
1719iow::events (short events) 2048iow::events (short events)
1720 CODE: 2049 CODE:
1721 THIS->events = events; 2050 THIS->events = events;
2051 OUTPUT:
1722 RETVAL = THIS; 2052 RETVAL
1723 OUTPUT:
1724 RETVAL
1725 2053
1726iow * 2054CHAINED
1727iow::start () 2055iow::start ()
1728 CODE: 2056 CODE:
1729 THIS->start (); 2057 THIS->start ();
2058 OUTPUT:
1730 RETVAL = THIS; 2059 RETVAL
1731 OUTPUT:
1732 RETVAL
1733 2060
1734iow * 2061CHAINED
1735iow::stop () 2062iow::stop ()
1736 CODE: 2063 CODE:
1737 THIS->stop (); 2064 THIS->stop ();
1738 RETVAL = THIS;
1739 OUTPUT: 2065 OUTPUT:
1740 RETVAL 2066 RETVAL
1741 2067
1742void 2068void
1743iow::DESTROY () 2069iow::DESTROY ()
1744 2070
2071#############################################################################
2072# urxvt::iw
2073#############################################################################
1745 2074
2075MODULE = urxvt PACKAGE = urxvt::iw
2076
2077SV *
2078iw::new ()
2079 CODE:
2080 iw *w = new iw;
2081 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iw");
2082 w->self = (HV *)SvRV (RETVAL);
2083 OUTPUT:
2084 RETVAL
2085
2086CHAINED
2087iw::start ()
2088 CODE:
2089 THIS->start ();
2090 OUTPUT:
2091 RETVAL
2092
2093CHAINED
2094iw::stop ()
2095 CODE:
2096 THIS->stop ();
2097 OUTPUT:
2098 RETVAL
2099
2100void
2101iw::DESTROY ()
2102
2103#############################################################################
2104# urxvt::pw
2105#############################################################################
2106
2107MODULE = urxvt PACKAGE = urxvt::pw
2108
2109SV *
2110pw::new ()
2111 CODE:
2112 pw *w = new pw;
2113 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::pw");
2114 w->self = (HV *)SvRV (RETVAL);
2115 OUTPUT:
2116 RETVAL
2117
2118CHAINED
2119pw::start (int pid)
2120 CODE:
2121 THIS->start (pid);
2122 OUTPUT:
2123 RETVAL
2124
2125CHAINED
2126pw::stop ()
2127 CODE:
2128 THIS->stop ();
2129 OUTPUT:
2130 RETVAL
2131
2132void
2133pw::DESTROY ()
2134
2135

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines