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.101 by root, Wed Jul 5 23:34:14 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{
236 if (border == 2) 273 if (border == 2)
237 { 274 {
238 w += 2; 275 w += 2;
239 h += 2; 276 h += 2;
278 *rp++ = r; 315 *rp++ = r;
279 } 316 }
280 } 317 }
281 318
282 show (); 319 show ();
283 THIS->want_refresh = 1;
284} 320}
285 321
286overlay::~overlay () 322overlay::~overlay ()
287{ 323{
288 hide (); 324 hide ();
293 delete [] rend[y]; 329 delete [] rend[y];
294 } 330 }
295 331
296 delete [] text; 332 delete [] text;
297 delete [] rend; 333 delete [] rend;
334}
335
336void
337overlay::show ()
338{
339 if (overlay_av)
340 return;
341
342 overlay_av = (AV *)SvREFCNT_inc (SvRV (
343 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
344 ));
345 av_push (overlay_av, newSViv ((long)this));
298 346
299 THIS->want_refresh = 1; 347 THIS->want_refresh = 1;
300} 348}
301 349
302void 350void
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 () 351overlay::hide ()
313{ 352{
314 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); 353 if (!overlay_av)
354 return;
315 355
316 if (ovs) 356 int i;
317 {
318 char key[33]; sprintf (key, "%32lx", (long)this);
319 357
320 HV *hv = (HV *)SvRV (*ovs); 358 for (i = AvFILL (overlay_av); i >= 0; i--)
321 hv_delete (hv, key, 32, G_DISCARD); 359 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this)
322 } 360 break;
361
362 for (; i < AvFILL (overlay_av); i++)
363 av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0)));
364
365 av_pop (overlay_av);
366
367 SvREFCNT_dec (overlay_av);
368 overlay_av = 0;
369
370 THIS->want_refresh = 1;
323} 371}
324 372
325void overlay::swap () 373void overlay::swap ()
326{ 374{
327 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 375 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
367 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) 415 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
368 croak ("rend must be arrayref"); 416 croak ("rend must be arrayref");
369 417
370 AV *av = (AV *)SvRV (rend); 418 AV *av = (AV *)SvRV (rend);
371 419
372 for (int col = min (av_len (av) + 1, w - x - border); col--; ) 420 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
373 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 421 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
374 } 422 }
375 423
376 THIS->want_refresh = 1; 424 THIS->want_refresh = 1;
377} 425}
402 perl_environ = rxvt_environ; 450 perl_environ = rxvt_environ;
403 swap (perl_environ, environ); 451 swap (perl_environ, environ);
404 452
405 char *argv[] = { 453 char *argv[] = {
406 "", 454 "",
407 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 455 "-e"
456 "BEGIN {"
457 " urxvt->bootstrap;"
458 " unshift @INC, '" LIBDIR "';"
459 "}"
460 ""
461 "use urxvt;"
408 }; 462 };
409 463
410 perl = perl_alloc (); 464 perl = perl_alloc ();
411 perl_construct (perl); 465 perl_construct (perl);
412 466
427 481
428 if (perl) 482 if (perl)
429 { 483 {
430 // runs outside of perls ENV 484 // runs outside of perls ENV
431 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 485 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); 486 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0);
433 } 487 }
434} 488}
435 489
436static void 490static void
437ungrab (rxvt_term *THIS) 491ungrab (rxvt_term *THIS)
438{ 492{
439 if (THIS->perl.grabtime) 493 if (THIS->perl.grabtime)
440 { 494 {
441 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); 495 XUngrabKeyboard (THIS->dpy, THIS->perl.grabtime);
442 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 496 XUngrabPointer (THIS->dpy, THIS->perl.grabtime);
443 THIS->perl.grabtime = 0; 497 THIS->perl.grabtime = 0;
444 } 498 }
445} 499}
446 500
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 501bool
462rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 502rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
463{ 503{
464 if (!perl || !term->perl.self) 504 if (!perl || !term->perl.self)
465 return false; 505 return false;
466 506
467 // pre-handling of some events 507 // pre-handling of some events
468 if (htype == HOOK_REFRESH_END) 508 if (htype == HOOK_REFRESH_END)
469 swap_overlays (term); 509 {
510 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
511
512 for (int i = 0; i <= AvFILL (av); i++)
513 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
514 }
470 515
471 swap (perl_environ, environ); 516 swap (perl_environ, environ);
472 517
473 bool event_consumed; 518 bool event_consumed;
474 519
507 break; 552 break;
508 553
509 case DT_STR_LEN: 554 case DT_STR_LEN:
510 { 555 {
511 char *str = va_arg (ap, char *); 556 char *str = va_arg (ap, char *);
512 int len = va_arg (ap, int); 557 int len = va_arg (ap, int);
513 558
514 XPUSHs (sv_2mortal (newSVpvn (str, len))); 559 XPUSHs (sv_2mortal (newSVpvn (str, len)));
515 } 560 }
516 break; 561 break;
517 562
518 case DT_WCS_LEN: 563 case DT_WCS_LEN:
519 { 564 {
520 wchar_t *wstr = va_arg (ap, wchar_t *); 565 wchar_t *wstr = va_arg (ap, wchar_t *);
521 int wlen = va_arg (ap, int); 566 int wlen = va_arg (ap, int);
522 567
523 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 568 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
569 }
570 break;
571
572 case DT_LCS_LEN:
573 {
574 long *lstr = va_arg (ap, long *);
575 int llen = va_arg (ap, int);
576
577 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long))));
524 } 578 }
525 break; 579 break;
526 580
527 case DT_XEVENT: 581 case DT_XEVENT:
528 { 582 {
529 XEvent *xe = va_arg (ap, XEvent *); 583 XEvent *xe = va_arg (ap, XEvent *);
530 HV *hv = newHV (); 584 HV *hv = newHV ();
531 585
532# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 586# 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) 587# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
588# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
534# undef set 589# undef set
535 590
536 setiv (type, xe->type); 591 setiv (type, xe->type);
537 setiv (send_event, xe->xany.send_event); 592 setiv (send_event, xe->xany.send_event);
538 setiv (serial, xe->xany.serial); 593 setiv (serial, xe->xany.serial);
539 594
542 case KeyPress: 597 case KeyPress:
543 case KeyRelease: 598 case KeyRelease:
544 case ButtonPress: 599 case ButtonPress:
545 case ButtonRelease: 600 case ButtonRelease:
546 case MotionNotify: 601 case MotionNotify:
602 setuv (window, xe->xmotion.window);
603 setuv (root, xe->xmotion.root);
604 setuv (subwindow, xe->xmotion.subwindow);
547 setiv (time, xe->xmotion.time); 605 setuv (time, xe->xmotion.time);
548 setiv (x, xe->xmotion.x); 606 setiv (x, xe->xmotion.x);
549 setiv (y, xe->xmotion.y); 607 setiv (y, xe->xmotion.y);
550 setiv (row, xe->xmotion.y / term->fheight); 608 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
551 setiv (col, xe->xmotion.x / term->fwidth); 609 setiv (col, xe->xmotion.x / term->fwidth);
552 setiv (x_root, xe->xmotion.x_root); 610 setiv (x_root, xe->xmotion.x_root);
553 setiv (y_root, xe->xmotion.y_root); 611 setiv (y_root, xe->xmotion.y_root);
554 setiv (state, xe->xmotion.state); 612 setuv (state, xe->xmotion.state);
613
614 switch (xe->type)
615 {
616 case KeyPress:
617 case KeyRelease:
618 setuv (keycode, xe->xkey.keycode);
619 break;
620
621 case ButtonPress:
622 case ButtonRelease:
623 setuv (button, xe->xbutton.button);
624 break;
625
626 case MotionNotify:
627 setiv (is_hint, xe->xmotion.is_hint);
628 break;
629 }
630
555 break; 631 break;
556 }
557 632
633 case MapNotify:
634 case UnmapNotify:
635 case ConfigureNotify:
636 setuv (event, xe->xconfigure.event);
637 setuv (window, xe->xconfigure.window);
638
558 switch (xe->type) 639 switch (xe->type)
559 { 640 {
560 case KeyPress: 641 case ConfigureNotify:
561 case KeyRelease: 642 setiv (x, xe->xconfigure.x);
562 setiv (keycode, xe->xkey.keycode); 643 setiv (y, xe->xconfigure.y);
644 setiv (width, xe->xconfigure.width);
645 setiv (height, xe->xconfigure.height);
646 setuv (above, xe->xconfigure.above);
647 break;
648 }
649
563 break; 650 break;
564 651
565 case ButtonPress: 652 case PropertyNotify:
566 case ButtonRelease: 653 setuv (window, xe->xproperty.window);
567 setiv (button, xe->xbutton.button); 654 setuv (atom, xe->xproperty.atom);
655 setuv (time, xe->xproperty.time);
656 setiv (state, xe->xproperty.state);
568 break; 657 break;
569 658
570 case MotionNotify: 659 case ClientMessage:
571 setiv (is_hint, xe->xmotion.is_hint); 660 setuv (window, xe->xclient.window);
661 setuv (message_type, xe->xclient.message_type);
662 setuv (format, xe->xclient.format);
663 setuv (l0, xe->xclient.data.l[0]);
664 setuv (l1, xe->xclient.data.l[1]);
665 setuv (l2, xe->xclient.data.l[2]);
666 setuv (l3, xe->xclient.data.l[3]);
667 setuv (l4, xe->xclient.data.l[4]);
572 break; 668 break;
573 } 669 }
574 670
575 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 671 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
576 } 672 }
617 else 713 else
618 event_consumed = false; 714 event_consumed = false;
619 715
620 // post-handling of some events 716 // post-handling of some events
621 if (htype == HOOK_REFRESH_BEGIN) 717 if (htype == HOOK_REFRESH_BEGIN)
622 swap_overlays (term); 718 {
719 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
720
721 for (int i = AvFILL (av); i >= 0; i--)
722 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
723 }
623 else if (htype == HOOK_DESTROY) 724 else if (htype == HOOK_DESTROY)
624 { 725 {
625 clearSVptr ((SV *)term->perl.self); 726 clearSVptr ((SV *)term->perl.self);
626 SvREFCNT_dec ((SV *)term->perl.self); 727 SvREFCNT_dec ((SV *)term->perl.self);
728
729 // don't allow further calls
730 term->perl.self = 0;
627 } 731 }
628 732
629 swap (perl_environ, environ); 733 swap (perl_environ, environ);
630 734
631 return event_consumed; 735 return event_consumed;
655# include "optinc.h" 759# include "optinc.h"
656# undef nodef 760# undef nodef
657# undef def 761# undef def
658 762
659 HV *stash = gv_stashpv ("urxvt", 1); 763 HV *stash = gv_stashpv ("urxvt", 1);
660 struct { 764 static const struct {
661 const char *name; 765 const char *name;
662 IV iv; 766 IV iv;
663 } *civ, const_iv[] = { 767 } *civ, const_iv[] = {
664# define const_iv(name) { # name, (IV)name } 768# define const_iv(name) { # name, (IV)name }
665 const_iv (DEFAULT_RSTYLE), 769 const_iv (DEFAULT_RSTYLE),
748 const_iv (SelectionRequest), 852 const_iv (SelectionRequest),
749 const_iv (SelectionNotify), 853 const_iv (SelectionNotify),
750 const_iv (ColormapNotify), 854 const_iv (ColormapNotify),
751 const_iv (ClientMessage), 855 const_iv (ClientMessage),
752 const_iv (MappingNotify), 856 const_iv (MappingNotify),
857# if ENABLE_XIM_ONTHESPOT
858 const_iv (XIMReverse),
859 const_iv (XIMUnderline),
860 const_iv (XIMHighlight),
861 const_iv (XIMPrimary),
862 const_iv (XIMSecondary),
863 const_iv (XIMTertiary),
864 const_iv (XIMVisibleToForward),
865 const_iv (XIMVisibleToBackword),
866 const_iv (XIMVisibleToCenter),
867# if 0
868 const_iv (XIMForwardChar),
869 const_iv (XIMBackwardChar),
870 const_iv (XIMForwardWord),
871 const_iv (XIMBackwardWord),
872 const_iv (XIMCaretUp),
873 const_iv (XIMCaretDown),
874 const_iv (XIMNextLine),
875 const_iv (XIMPreviousLine),
876 const_iv (XIMLineStart),
877 const_iv (XIMLineEnd),
878 const_iv (XIMAbsolutePosition),
879 const_iv (XIMDontChange),
880# endif
881# endif
753 }; 882 };
754 883
755 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); 884 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)); 885 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
758} 886}
759 887
760void 888void
761warn (const char *msg) 889warn (const char *msg)
792 RETVAL 920 RETVAL
793 921
794int 922int
795SET_FGCOLOR (int rend, int new_color) 923SET_FGCOLOR (int rend, int new_color)
796 CODE: 924 CODE:
797 RETVAL = SET_FGCOLOR (rend, new_color); 925 RETVAL = SET_FGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
798 OUTPUT: 926 OUTPUT:
799 RETVAL 927 RETVAL
800 928
801int 929int
802SET_BGCOLOR (int rend, int new_color) 930SET_BGCOLOR (int rend, int new_color)
803 CODE: 931 CODE:
804 RETVAL = SET_BGCOLOR (rend, new_color); 932 RETVAL = SET_BGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
805 OUTPUT: 933 OUTPUT:
806 RETVAL 934 RETVAL
807 935
808int 936int
809GET_CUSTOM (int rend) 937GET_CUSTOM (int rend)
823 | ((new_value << RS_customShift) & RS_customMask); 951 | ((new_value << RS_customShift) & RS_customMask);
824} 952}
825 OUTPUT: 953 OUTPUT:
826 RETVAL 954 RETVAL
827 955
956void
957termlist ()
958 PPCODE:
959{
960 EXTEND (SP, rxvt_term::termlist.size ());
961
962 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
963 if ((*t)->perl.self)
964 PUSHs (sv_2mortal (newSVterm (*t)));
965}
966
828MODULE = urxvt PACKAGE = urxvt::term 967MODULE = urxvt PACKAGE = urxvt::term
829 968
830SV * 969SV *
831_new (...) 970_new (AV *env, AV *arg)
832 CODE: 971 CODE:
833{ 972{
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; 973 rxvt_term *term = new rxvt_term;
838 974
839 term->argv = new stringvec; 975 stringvec *argv = new stringvec;
840 term->envv = new stringvec; 976 stringvec *envv = new stringvec;
841 977
842 for (int i = 1; i < items; i++) 978 for (int i = 0; i <= AvFILL (arg); i++)
843 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 979 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
844 980
845 AV *envv = (AV *)SvRV (ST (0));
846 for (int i = av_len (envv) + 1; i--; ) 981 for (int i = AvFILL (env) + 1; i--; )
847 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 982 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
848 983
849 term->envv->push_back (0); 984 envv->push_back (0);
850 985
851 bool success; 986 bool success;
852 987
853 try 988 try
854 { 989 {
855 success = term->init (term->argv->size (), term->argv->begin ()); 990 success = term->init (argv, envv);
856 } 991 }
857 catch (const class rxvt_failure_exception &e) 992 catch (const class rxvt_failure_exception &e)
858 { 993 {
859 success = false; 994 success = false;
860 } 995 }
872 RETVAL 1007 RETVAL
873 1008
874void 1009void
875rxvt_term::destroy () 1010rxvt_term::destroy ()
876 1011
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 1012void
967rxvt_term::set_should_invoke (int htype, int inc) 1013rxvt_term::set_should_invoke (int htype, int inc)
968 CODE: 1014 CODE:
969 THIS->perl.should_invoke [htype] += inc; 1015 THIS->perl.should_invoke [htype] += inc;
970 1016
971void 1017void
972rxvt_term::grab_button (int button, U32 modifiers) 1018rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt)
973 CODE: 1019 CODE:
974 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 1020 XGrabButton (THIS->dpy, button, modifiers, window, 1,
975 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1021 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
976 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 1022 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
977 1023
1024void
1025rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt)
1026 CODE:
1027 XUngrabButton (THIS->dpy, button, modifiers, window);
1028
1029#if 0
1030
1031void
1032XGrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt)
1033 C_ARGS:
1034 THIS->dpy, keycode, modifiers, window, 1,
1035 GrabModeSync, GrabModeSync
1036
1037void
1038XUngrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt)
1039 C_ARGS: THIS->dpy, keycode, modifiers, window
1040
1041#endif
1042
978bool 1043bool
979rxvt_term::grab (U32 eventtime, int sync = 0) 1044rxvt_term::grab (Time eventtime, int sync = 0)
980 CODE: 1045 CODE:
981{ 1046{
982 int mode = sync ? GrabModeSync : GrabModeAsync; 1047 int mode = sync ? GrabModeSync : GrabModeAsync;
983 1048
984 THIS->perl.grabtime = 0; 1049 THIS->perl.grabtime = 0;
985 1050
986 if (!XGrabPointer (THIS->display->display, THIS->vt, 0, 1051 if (!XGrabPointer (THIS->dpy, THIS->vt, 0,
987 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1052 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
988 mode, mode, None, GRAB_CURSOR, eventtime)) 1053 mode, mode, None, GRAB_CURSOR, eventtime))
989 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) 1054 if (!XGrabKeyboard (THIS->dpy, THIS->vt, 0, mode, mode, eventtime))
990 THIS->perl.grabtime = eventtime; 1055 THIS->perl.grabtime = eventtime;
991 else 1056 else
992 XUngrabPointer (THIS->display->display, eventtime); 1057 XUngrabPointer (THIS->dpy, eventtime);
993 1058
994 RETVAL = !!THIS->perl.grabtime; 1059 RETVAL = !!THIS->perl.grabtime;
995} 1060}
996 OUTPUT: 1061 OUTPUT:
997 RETVAL 1062 RETVAL
998 1063
999void 1064void
1000rxvt_term::allow_events_async () 1065rxvt_term::allow_events_async ()
1001 CODE: 1066 CODE:
1002 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); 1067 XAllowEvents (THIS->dpy, AsyncBoth, THIS->perl.grabtime);
1003 1068
1004void 1069void
1005rxvt_term::allow_events_sync () 1070rxvt_term::allow_events_sync ()
1006 CODE: 1071 CODE:
1007 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); 1072 XAllowEvents (THIS->dpy, SyncBoth, THIS->perl.grabtime);
1008 1073
1009void 1074void
1010rxvt_term::allow_events_replay () 1075rxvt_term::allow_events_replay ()
1011 CODE: 1076 CODE:
1012 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); 1077 XAllowEvents (THIS->dpy, ReplayPointer, THIS->perl.grabtime);
1013 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); 1078 XAllowEvents (THIS->dpy, ReplayKeyboard, THIS->perl.grabtime);
1014 1079
1015void 1080void
1016rxvt_term::ungrab () 1081rxvt_term::ungrab ()
1017 CODE: 1082 CODE:
1018 ungrab (THIS); 1083 ungrab (THIS);
1076#define TERM_OFFSET_fbase TERM_OFFSET(fbase) 1141#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1077#define TERM_OFFSET_nrow TERM_OFFSET(nrow) 1142#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1078#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1143#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1079#define TERM_OFFSET_focus TERM_OFFSET(focus) 1144#define TERM_OFFSET_focus TERM_OFFSET(focus)
1080#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1145#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
1146#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth)
1147#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth)
1148#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace)
1081#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1149#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1082#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1150#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1083#define TERM_OFFSET_top_row TERM_OFFSET(top_row) 1151#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1084 1152
1085int 1153int
1092 fbase = TERM_OFFSET_fbase 1160 fbase = TERM_OFFSET_fbase
1093 nrow = TERM_OFFSET_nrow 1161 nrow = TERM_OFFSET_nrow
1094 ncol = TERM_OFFSET_ncol 1162 ncol = TERM_OFFSET_ncol
1095 focus = TERM_OFFSET_focus 1163 focus = TERM_OFFSET_focus
1096 mapped = TERM_OFFSET_mapped 1164 mapped = TERM_OFFSET_mapped
1165 int_bwidth = TERM_OFFSET_int_bwidth
1166 ext_bwidth = TERM_OFFSET_ext_bwidth
1167 lineSpace = TERM_OFFSET_lineSpace
1097 saveLines = TERM_OFFSET_saveLines 1168 saveLines = TERM_OFFSET_saveLines
1098 total_rows = TERM_OFFSET_total_rows 1169 total_rows = TERM_OFFSET_total_rows
1099 top_row = TERM_OFFSET_top_row 1170 top_row = TERM_OFFSET_top_row
1100 CODE: 1171 CODE:
1101 RETVAL = *(int *)((char *)THIS + ix); 1172 RETVAL = *(int *)((char *)THIS + ix);
1106rxvt_term::ModLevel3Mask () 1177rxvt_term::ModLevel3Mask ()
1107 ALIAS: 1178 ALIAS:
1108 ModLevel3Mask = 0 1179 ModLevel3Mask = 0
1109 ModMetaMask = 1 1180 ModMetaMask = 1
1110 ModNumLockMask = 2 1181 ModNumLockMask = 2
1182 current_screen = 3
1183 hidden_cursor = 4
1111 CODE: 1184 CODE:
1112 switch (ix) 1185 switch (ix)
1113 { 1186 {
1114 case 0: RETVAL = THIS->ModLevel3Mask; break; 1187 case 0: RETVAL = THIS->ModLevel3Mask; break;
1115 case 1: RETVAL = THIS->ModMetaMask; break; 1188 case 1: RETVAL = THIS->ModMetaMask; break;
1116 case 2: RETVAL = THIS->ModNumLockMask; break; 1189 case 2: RETVAL = THIS->ModNumLockMask; break;
1190 case 3: RETVAL = THIS->current_screen; break;
1191 case 4: RETVAL = THIS->hidden_cursor; break;
1117 } 1192 }
1118 OUTPUT: 1193 OUTPUT:
1119 RETVAL 1194 RETVAL
1120 1195
1121char * 1196char *
1131 } 1206 }
1132 OUTPUT: 1207 OUTPUT:
1133 RETVAL 1208 RETVAL
1134 1209
1135SV * 1210SV *
1136rxvt_term::_env () 1211rxvt_term::envv ()
1212 ALIAS:
1213 argv = 1
1137 CODE: 1214 PPCODE:
1138{ 1215{
1139 if (THIS->envv) 1216 stringvec *vec = ix ? THIS->argv : THIS->envv;
1140 {
1141 AV *av = newAV ();
1142 1217
1218 EXTEND (SP, vec->size ());
1219
1143 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) 1220 for (char **i = vec->begin (); i != vec->end (); ++i)
1144 if (*i) 1221 if (*i)
1145 av_push (av, newSVpv (*i, 0)); 1222 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1146
1147 RETVAL = newRV_noinc ((SV *)av);
1148 }
1149 else
1150 RETVAL = &PL_sv_undef;
1151} 1223}
1152 OUTPUT:
1153 RETVAL
1154 1224
1155int 1225int
1156rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1226rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1157 CODE: 1227 CODE:
1158 RETVAL = THIS->pty_ev.events; 1228 RETVAL = THIS->pty_ev.events;
1159 if (events != EVENT_UNDEF) 1229 if (events != EVENT_UNDEF)
1160 THIS->pty_ev.set (events); 1230 THIS->pty_ev.set (events);
1161 OUTPUT: 1231 OUTPUT:
1162 RETVAL 1232 RETVAL
1163 1233
1164U32 1234int
1235rxvt_term::pty_fd ()
1236 CODE:
1237 RETVAL = THIS->pty->pty;
1238 OUTPUT:
1239 RETVAL
1240
1241Window
1165rxvt_term::parent () 1242rxvt_term::parent ()
1166 CODE: 1243 CODE:
1167 RETVAL = (U32)THIS->parent [0]; 1244 RETVAL = THIS->parent [0];
1168 OUTPUT: 1245 OUTPUT:
1169 RETVAL 1246 RETVAL
1170 1247
1171U32 1248Window
1172rxvt_term::vt () 1249rxvt_term::vt ()
1173 CODE: 1250 CODE:
1174 RETVAL = (U32)THIS->vt; 1251 RETVAL = THIS->vt;
1175 OUTPUT: 1252 OUTPUT:
1176 RETVAL 1253 RETVAL
1177 1254
1178void 1255void
1179rxvt_term::vt_emask_add (U32 emask) 1256rxvt_term::vt_emask_add (U32 emask)
1201} 1278}
1202 OUTPUT: 1279 OUTPUT:
1203 RETVAL 1280 RETVAL
1204 1281
1205void 1282void
1283rxvt_term::focus_in ()
1284
1285void
1286rxvt_term::focus_out ()
1287
1288void
1289rxvt_term::key_press (unsigned int state, unsigned int keycode, Time time = CurrentTime)
1290 ALIAS:
1291 key_release = 1
1292 CODE:
1293{
1294 XKeyEvent xkey;
1295
1296 memset (&xkey, 0, sizeof (xkey));
1297
1298 xkey.time = time;
1299 xkey.state = state;
1300 xkey.keycode = keycode;
1301
1302 xkey.type = ix ? KeyRelease : KeyPress;
1303 xkey.display = THIS->dpy;
1304 xkey.window = THIS->vt;
1305 xkey.root = THIS->display->root;
1306 xkey.subwindow = THIS->vt;
1307
1308 if (ix)
1309 THIS->key_release (xkey);
1310 else
1311 THIS->key_press (xkey);
1312}
1313
1314void
1206rxvt_term::want_refresh () 1315rxvt_term::want_refresh ()
1207 CODE: 1316 CODE:
1208 THIS->want_refresh = 1; 1317 THIS->want_refresh = 1;
1209 1318
1210void 1319void
1216 1325
1217 line_t &l = ROW(row_number); 1326 line_t &l = ROW(row_number);
1218 1327
1219 if (GIMME_V != G_VOID) 1328 if (GIMME_V != G_VOID)
1220 { 1329 {
1221 wchar_t *wstr = new wchar_t [THIS->ncol]; 1330 wchar_t *wstr = rxvt_temp_buf<wchar_t> (THIS->ncol);
1222 1331
1223 for (int col = 0; col < THIS->ncol; col++) 1332 for (int col = 0; col < THIS->ncol; col++)
1224 wstr [col] = l.t [col]; 1333 wstr [col] = l.t [col];
1225 1334
1226 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1335 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1227
1228 delete [] wstr;
1229 } 1336 }
1230 1337
1231 if (new_text) 1338 if (new_text)
1232 { 1339 {
1233 wchar_t *wstr = sv2wcs (new_text); 1340 wchar_t *wstr = sv2wcs (new_text);
1234 1341
1235 int len = min (wcslen (wstr) - start_ofs, max_len); 1342 int len = min (wcslen (wstr) - start_ofs, max_len);
1236 1343
1237 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1344 if (start_col < 0 || start_col + len > THIS->ncol)
1238 { 1345 {
1239 free (wstr); 1346 free (wstr);
1240 croak ("new_text extends beyond horizontal margins"); 1347 croak ("new_text extends beyond horizontal margins");
1241 } 1348 }
1242 1349
1274 { 1381 {
1275 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1382 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1276 croak ("new_rend must be arrayref"); 1383 croak ("new_rend must be arrayref");
1277 1384
1278 AV *av = (AV *)SvRV (new_rend); 1385 AV *av = (AV *)SvRV (new_rend);
1279 int len = min (av_len (av) + 1 - start_ofs, max_len); 1386 int len = min (AvFILL (av) + 1 - start_ofs, max_len);
1280 1387
1281 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1388 if (start_col < 0 || start_col + len > THIS->ncol)
1282 croak ("new_rend array extends beyond horizontal margins"); 1389 croak ("new_rend array extends beyond horizontal margins");
1283 1390
1284 for (int col = start_col; col < start_col + len; col++) 1391 for (int col = start_col; col < start_col + len; col++)
1285 { 1392 {
1286 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; 1393 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1326rxvt_term::special_encode (SV *string) 1433rxvt_term::special_encode (SV *string)
1327 CODE: 1434 CODE:
1328{ 1435{
1329 wchar_t *wstr = sv2wcs (string); 1436 wchar_t *wstr = sv2wcs (string);
1330 int wlen = wcslen (wstr); 1437 int wlen = wcslen (wstr);
1331 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer 1438 wchar_t *rstr = rxvt_temp_buf<wchar_t> (wlen * 2); // cannot become longer
1332 1439
1333 rxvt_push_locale (THIS->locale); 1440 rxvt_push_locale (THIS->locale);
1334 1441
1335 wchar_t *r = rstr; 1442 wchar_t *r = rstr;
1336 for (wchar_t *s = wstr; *s; s++) 1443 for (wchar_t *s = wstr; *s; s++)
1444 {
1445 int w = WCWIDTH (*s);
1446
1337 if (wcwidth (*s) == 0) 1447 if (w == 0)
1338 { 1448 {
1339 if (r == rstr) 1449 if (r == rstr)
1340 croak ("leading combining character unencodable"); 1450 croak ("leading combining character unencodable");
1341 1451
1342 unicode_t n = rxvt_compose (r[-1], *s); 1452 unicode_t n = rxvt_compose (r[-1], *s);
1343 if (n == NOCHAR) 1453 if (n == NOCHAR)
1344 n = rxvt_composite.compose (r[-1], *s); 1454 n = rxvt_composite.compose (r[-1], *s);
1345 1455
1346 r[-1] = n; 1456 r[-1] = n;
1347 } 1457 }
1348#if !UNICODE_3 1458#if !UNICODE_3
1349 else if (*s >= 0x10000) 1459 else if (*s >= 0x10000)
1350 *r++ = rxvt_composite.compose (*s); 1460 *r++ = rxvt_composite.compose (*s);
1351#endif 1461#endif
1352 else 1462 else
1353 *r++ = *s; 1463 *r++ = *s;
1464
1465 // the *2 above only allows wcwidth <= 2
1466 if (w > 1)
1467 *r++ = NOCHAR;
1468 }
1354 1469
1355 rxvt_pop_locale (); 1470 rxvt_pop_locale ();
1356 1471
1357 RETVAL = wcs2sv (rstr, r - rstr); 1472 RETVAL = wcs2sv (rstr, r - rstr);
1358
1359 delete [] rstr;
1360} 1473}
1361 OUTPUT: 1474 OUTPUT:
1362 RETVAL 1475 RETVAL
1363 1476
1364SV * 1477SV *
1376 else if (IS_COMPOSE (*s)) 1489 else if (IS_COMPOSE (*s))
1377 dlen += rxvt_composite.expand (*s, 0); 1490 dlen += rxvt_composite.expand (*s, 0);
1378 else 1491 else
1379 dlen++; 1492 dlen++;
1380 1493
1381 wchar_t *rstr = new wchar_t [dlen]; 1494 wchar_t *rstr = rxvt_temp_buf<wchar_t> (dlen);
1382 1495
1383 // decode 1496 // decode
1384 wchar_t *r = rstr; 1497 wchar_t *r = rstr;
1385 for (wchar_t *s = wstr; *s; s++) 1498 for (wchar_t *s = wstr; *s; s++)
1386 if (*s == NOCHAR) 1499 if (*s == NOCHAR)
1389 r += rxvt_composite.expand (*s, r); 1502 r += rxvt_composite.expand (*s, r);
1390 else 1503 else
1391 *r++ = *s; 1504 *r++ = *s;
1392 1505
1393 RETVAL = wcs2sv (rstr, r - rstr); 1506 RETVAL = wcs2sv (rstr, r - rstr);
1394
1395 delete [] rstr;
1396} 1507}
1397 OUTPUT: 1508 OUTPUT:
1398 RETVAL 1509 RETVAL
1399 1510
1400void 1511void
1401rxvt_term::_resource (char *name, int index, SV *newval = 0) 1512rxvt_term::_resource (char *name, int index, SV *newval = 0)
1402 PPCODE: 1513 PPCODE:
1403{ 1514{
1404 struct resval { const char *name; int value; } rslist [] = { 1515 static const struct resval { const char *name; int value; } *rs, rslist [] = {
1405# define def(name) { # name, Rs_ ## name }, 1516# define def(name) { # name, Rs_ ## name },
1406# define reserve(name,count) 1517# define reserve(name,count)
1407# include "rsinc.h" 1518# include "rsinc.h"
1408# undef def 1519# undef def
1409# undef reserve 1520# undef reserve
1410 }; 1521 };
1411 1522
1412 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1523 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1413 1524
1414 do { 1525 do {
1415 if (rs-- == rslist) 1526 if (rs-- == rslist)
1416 croak ("no such resource '%s', requested", name); 1527 croak ("no such resource '%s', requested", name);
1417 } while (strcmp (name, rs->name)); 1528 } while (strcmp (name, rs->name));
1451 if (set) 1562 if (set)
1452 THIS->options |= optval; 1563 THIS->options |= optval;
1453 else 1564 else
1454 THIS->options &= ~optval; 1565 THIS->options &= ~optval;
1455 1566
1567 if (THIS->check_ev.is_active ()) // avoid doing this before START
1456 switch (optval) 1568 switch (optval)
1457 { 1569 {
1458 case Opt_skipBuiltinGlyphs: 1570 case Opt_skipBuiltinGlyphs:
1459 THIS->set_fonts (); 1571 THIS->set_fonts ();
1460 THIS->scr_remap_chars (); 1572 THIS->scr_remap_chars ();
1461 THIS->scr_touch (true); 1573 THIS->scr_touch (true);
1462 THIS->want_refresh = 1; 1574 THIS->want_refresh = 1;
1463 break; 1575 break;
1464 1576
1465 case Opt_cursorUnderline: 1577 case Opt_cursorUnderline:
1466 THIS->want_refresh = 1; 1578 THIS->want_refresh = 1;
1467 break; 1579 break;
1468 1580
1469# case Opt_scrollBar_floating: 1581# case Opt_scrollBar_floating:
1470# case Opt_scrollBar_right: 1582# case Opt_scrollBar_right:
1471# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1583# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1472# break; 1584# break;
1473 } 1585 }
1474 } 1586 }
1475} 1587}
1476 OUTPUT: 1588 OUTPUT:
1477 RETVAL 1589 RETVAL
1478 1590
1506 PUSHs (sv_2mortal (newSViv (rc.col))); 1618 PUSHs (sv_2mortal (newSViv (rc.col)));
1507 } 1619 }
1508 1620
1509 if (items == 3) 1621 if (items == 3)
1510 { 1622 {
1623 rc.row = SvIV (ST (1));
1624 rc.col = SvIV (ST (2));
1625
1626 if (ix == 2)
1627 {
1628 if (rc.col == 0)
1629 {
1630 // col == 0 means end of previous line
1631 rc.row--;
1632 rc.col = THIS->ncol;
1633 }
1634 else if (IN_RANGE_EXC (rc.row, THIS->top_row, THIS->nrow)
1635 && rc.col > ROW(rc.row).l)
1636 {
1637 // col >= length means while line and add newline
1638 rc.col = THIS->ncol;
1639 }
1640 }
1641
1642 clamp_it (rc.col, 0, THIS->ncol);
1511 rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1); 1643 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1512 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
1513 1644
1514 if (ix) 1645 if (ix)
1515 THIS->want_refresh = 1; 1646 THIS->want_refresh = 1;
1516 } 1647 }
1517} 1648}
1521 CODE: 1652 CODE:
1522 RETVAL = THIS->charsets [THIS->screen.charset]; 1653 RETVAL = THIS->charsets [THIS->screen.charset];
1523 OUTPUT: 1654 OUTPUT:
1524 RETVAL 1655 RETVAL
1525 1656
1526#void 1657void
1527#rxvt_term::selection_clear () 1658rxvt_term::selection_clear ()
1528 1659
1529void 1660void
1530rxvt_term::selection_make (U32 eventtime, bool rect = false) 1661rxvt_term::selection_make (Time eventtime, bool rect = false)
1531 CODE: 1662 CODE:
1532 THIS->selection.op = SELECTION_CONT; 1663 THIS->selection.op = SELECTION_CONT;
1533 THIS->selection.rect = rect; 1664 THIS->selection.rect = rect;
1534 THIS->selection_make (eventtime); 1665 THIS->selection_make (eventtime);
1535 1666
1536int 1667int
1537rxvt_term::selection_grab (U32 eventtime) 1668rxvt_term::selection_grab (Time eventtime)
1538 1669
1539void 1670void
1540rxvt_term::selection (SV *newtext = 0) 1671rxvt_term::selection (SV *newtext = 0)
1541 PPCODE: 1672 PPCODE:
1542{ 1673{
1560void 1691void
1561rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) 1692rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1562 1693
1563void 1694void
1564rxvt_term::scr_bell () 1695rxvt_term::scr_bell ()
1696
1697void
1698rxvt_term::scr_change_screen (int screen)
1565 1699
1566void 1700void
1567rxvt_term::scr_add_lines (SV *string) 1701rxvt_term::scr_add_lines (SV *string)
1568 CODE: 1702 CODE:
1569{ 1703{
1610 o->self = (HV *)SvRV (RETVAL); 1744 o->self = (HV *)SvRV (RETVAL);
1611} 1745}
1612 OUTPUT: 1746 OUTPUT:
1613 RETVAL 1747 RETVAL
1614 1748
1749#############################################################################
1750# Various X Utility Functions
1751#############################################################################
1752
1753void
1754rxvt_term::XListProperties (Window window)
1755 PPCODE:
1756{
1757 int count;
1758 Atom *props = XListProperties (THIS->dpy, window, &count);
1759
1760 EXTEND (SP, count);
1761 while (count--)
1762 PUSHs (newSVuv ((U32)props [count]));
1763
1764 XFree (props);
1765}
1766
1767void
1768rxvt_term::XGetWindowProperty (Window window, Atom property)
1769 PPCODE:
1770{
1771 Atom type;
1772 int format;
1773 unsigned long nitems;
1774 unsigned long bytes_after;
1775 unsigned char *prop;
1776
1777 XGetWindowProperty (THIS->dpy, window, property,
1778 0, 1<<24, 0, AnyPropertyType,
1779 &type, &format, &nitems, &bytes_after, &prop);
1780
1781 if (type != None)
1782 {
1783 int elemsize = format == 16 ? sizeof (short)
1784 : format == 32 ? sizeof (long)
1785 : 1;
1786
1787 EXTEND (SP, 3);
1788 PUSHs (newSVuv ((U32)type));
1789 PUSHs (newSViv (format));
1790 PUSHs (newSVpvn ((char *)prop, nitems * elemsize));
1791 XFree (prop);
1792 }
1793}
1794
1795void
1796rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data)
1797 CODE:
1798{
1799 STRLEN len;
1800 char *data_ = SvPVbyte (data, len);
1801
1802 int elemsize = format == 16 ? sizeof (short)
1803 : format == 32 ? sizeof (long)
1804 : 1;
1805
1806 XChangeProperty (THIS->dpy, window, property,
1807 type, format, PropModeReplace,
1808 (unsigned char *)data_, len / elemsize);
1809}
1810
1811Atom
1812XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1813 C_ARGS: term->dpy, atom_name, only_if_exists
1814
1815char *
1816XGetAtomName (rxvt_term *term, Atom atom)
1817 C_ARGS: term->dpy, atom
1818 CLEANUP:
1819 XFree (RETVAL);
1820
1821void
1822XDeleteProperty (rxvt_term *term, Window window, Atom property)
1823 C_ARGS: term->dpy, window, property
1824
1825Window
1826rxvt_term::DefaultRootWindow ()
1827 CODE:
1828 RETVAL = THIS->display->root;
1829 OUTPUT:
1830 RETVAL
1831
1832#if 0
1833
1834Window
1835XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1836 C_ARGS: term->dpy, (Window)parent,
1837 x, y, width, height, 0,
1838 term->pix_colors_focused[Color_border],
1839 term->pix_colors_focused[Color_border]
1840
1841#endif
1842
1843void
1844XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1845 C_ARGS: term->dpy, window, parent, x, y
1846
1847void
1848XMapWindow (rxvt_term *term, Window window)
1849 C_ARGS: term->dpy, window
1850
1851void
1852XUnmapWindow (rxvt_term *term, Window window)
1853 C_ARGS: term->dpy, window
1854
1855void
1856XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1857 C_ARGS: term->dpy, window, x, y, width, height
1858
1859void
1860rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0)
1861 CODE:
1862{
1863 XWindowAttributes attr;
1864 XGetWindowAttributes (THIS->dpy, window, &attr);
1865 XSelectInput (THIS->dpy, window, attr.your_event_mask | add_events & ~del_events);
1866}
1867
1868void
1869rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y)
1870 PPCODE:
1871{
1872 int dx, dy;
1873 Window child;
1874
1875 if (XTranslateCoordinates (THIS->dpy, src, dst, x, y, &dx, &dy, &child))
1876 {
1877 EXTEND (SP, 3);
1878 PUSHs (newSViv (dx));
1879 PUSHs (newSViv (dy));
1880 PUSHs (newSVuv (child));
1881 }
1882}
1883
1884#############################################################################
1885# urxvt::overlay
1886#############################################################################
1887
1615MODULE = urxvt PACKAGE = urxvt::overlay 1888MODULE = urxvt PACKAGE = urxvt::overlay
1616 1889
1617void 1890void
1618overlay::set (int x, int y, SV *text, SV *rend = 0) 1891overlay::set (int x, int y, SV *text, SV *rend = 0)
1619 1892
1623void 1896void
1624overlay::hide () 1897overlay::hide ()
1625 1898
1626void 1899void
1627overlay::DESTROY () 1900overlay::DESTROY ()
1901
1902#############################################################################
1903# urxvt::watcher
1904#############################################################################
1905
1906MODULE = urxvt PACKAGE = urxvt::watcher
1907
1908CHAINED
1909perl_watcher::cb (SV *cb)
1910 CODE:
1911 THIS->cb (cb);
1912 OUTPUT:
1913 RETVAL
1914
1915#############################################################################
1916# urxvt::timer
1917#############################################################################
1628 1918
1629MODULE = urxvt PACKAGE = urxvt::timer 1919MODULE = urxvt PACKAGE = urxvt::timer
1630 1920
1631SV * 1921SV *
1632timer::new () 1922timer::new ()
1633 CODE: 1923 CODE:
1634 timer *w = new timer; 1924 timer *w = new timer;
1635 w->start (NOW); 1925 w->start (NOW);
1636 RETVAL = newSVptr ((void *)w, "urxvt::timer"); 1926 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::timer");
1637 w->self = (HV *)SvRV (RETVAL); 1927 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: 1928 OUTPUT:
1647 RETVAL 1929 RETVAL
1648 1930
1649NV 1931NV
1650timer::at () 1932timer::at ()
1651 CODE: 1933 CODE:
1652 RETVAL = THIS->at; 1934 RETVAL = THIS->at;
1653 OUTPUT: 1935 OUTPUT:
1654 RETVAL 1936 RETVAL
1655 1937
1656timer * 1938CHAINED
1657timer::interval (NV interval) 1939timer::interval (NV interval)
1658 CODE: 1940 CODE:
1659 THIS->interval = interval; 1941 THIS->interval = interval;
1942 OUTPUT:
1660 RETVAL = THIS; 1943 RETVAL
1661 OUTPUT:
1662 RETVAL
1663 1944
1664timer * 1945CHAINED
1665timer::set (NV tstamp) 1946timer::set (NV tstamp)
1666 CODE: 1947 CODE:
1667 THIS->set (tstamp); 1948 THIS->set (tstamp);
1949 OUTPUT:
1668 RETVAL = THIS; 1950 RETVAL
1669 OUTPUT:
1670 RETVAL
1671 1951
1672timer * 1952CHAINED
1673timer::start (NV tstamp = THIS->at) 1953timer::start (NV tstamp = THIS->at)
1674 CODE: 1954 CODE:
1675 THIS->start (tstamp); 1955 THIS->start (tstamp);
1956 OUTPUT:
1676 RETVAL = THIS; 1957 RETVAL
1677 OUTPUT:
1678 RETVAL
1679 1958
1680timer * 1959CHAINED
1960timer::after (NV delay)
1961 CODE:
1962 THIS->start (NOW + delay);
1963 OUTPUT:
1964 RETVAL
1965
1966CHAINED
1681timer::stop () 1967timer::stop ()
1682 CODE: 1968 CODE:
1683 THIS->stop (); 1969 THIS->stop ();
1684 RETVAL = THIS;
1685 OUTPUT: 1970 OUTPUT:
1686 RETVAL 1971 RETVAL
1687 1972
1688void 1973void
1689timer::DESTROY () 1974timer::DESTROY ()
1975
1976#############################################################################
1977# urxvt::iow
1978#############################################################################
1690 1979
1691MODULE = urxvt PACKAGE = urxvt::iow 1980MODULE = urxvt PACKAGE = urxvt::iow
1692 1981
1693SV * 1982SV *
1694iow::new () 1983iow::new ()
1695 CODE: 1984 CODE:
1696 iow *w = new iow; 1985 iow *w = new iow;
1697 RETVAL = newSVptr ((void *)w, "urxvt::iow"); 1986 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iow");
1698 w->self = (HV *)SvRV (RETVAL); 1987 w->self = (HV *)SvRV (RETVAL);
1699 OUTPUT: 1988 OUTPUT:
1700 RETVAL 1989 RETVAL
1701 1990
1702iow * 1991CHAINED
1703iow::cb (SV *cb)
1704 CODE:
1705 THIS->cb (cb);
1706 RETVAL = THIS;
1707 OUTPUT:
1708 RETVAL
1709
1710iow *
1711iow::fd (int fd) 1992iow::fd (int fd)
1712 CODE: 1993 CODE:
1713 THIS->fd = fd; 1994 THIS->fd = fd;
1995 OUTPUT:
1714 RETVAL = THIS; 1996 RETVAL
1715 OUTPUT:
1716 RETVAL
1717 1997
1718iow * 1998CHAINED
1719iow::events (short events) 1999iow::events (short events)
1720 CODE: 2000 CODE:
1721 THIS->events = events; 2001 THIS->events = events;
2002 OUTPUT:
1722 RETVAL = THIS; 2003 RETVAL
1723 OUTPUT:
1724 RETVAL
1725 2004
1726iow * 2005CHAINED
1727iow::start () 2006iow::start ()
1728 CODE: 2007 CODE:
1729 THIS->start (); 2008 THIS->start ();
2009 OUTPUT:
1730 RETVAL = THIS; 2010 RETVAL
1731 OUTPUT:
1732 RETVAL
1733 2011
1734iow * 2012CHAINED
1735iow::stop () 2013iow::stop ()
1736 CODE: 2014 CODE:
1737 THIS->stop (); 2015 THIS->stop ();
1738 RETVAL = THIS;
1739 OUTPUT: 2016 OUTPUT:
1740 RETVAL 2017 RETVAL
1741 2018
1742void 2019void
1743iow::DESTROY () 2020iow::DESTROY ()
1744 2021
2022#############################################################################
2023# urxvt::iw
2024#############################################################################
1745 2025
2026MODULE = urxvt PACKAGE = urxvt::iw
2027
2028SV *
2029iw::new ()
2030 CODE:
2031 iw *w = new iw;
2032 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iw");
2033 w->self = (HV *)SvRV (RETVAL);
2034 OUTPUT:
2035 RETVAL
2036
2037CHAINED
2038iw::start ()
2039 CODE:
2040 THIS->start ();
2041 OUTPUT:
2042 RETVAL
2043
2044CHAINED
2045iw::stop ()
2046 CODE:
2047 THIS->stop ();
2048 OUTPUT:
2049 RETVAL
2050
2051void
2052iw::DESTROY ()
2053
2054#############################################################################
2055# urxvt::pw
2056#############################################################################
2057
2058MODULE = urxvt PACKAGE = urxvt::pw
2059
2060SV *
2061pw::new ()
2062 CODE:
2063 pw *w = new pw;
2064 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::pw");
2065 w->self = (HV *)SvRV (RETVAL);
2066 OUTPUT:
2067 RETVAL
2068
2069CHAINED
2070pw::start (int pid)
2071 CODE:
2072 THIS->start (pid);
2073 OUTPUT:
2074 RETVAL
2075
2076CHAINED
2077pw::stop ()
2078 CODE:
2079 THIS->stop ();
2080 OUTPUT:
2081 RETVAL
2082
2083void
2084pw::DESTROY ()
2085
2086

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines