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.100 by root, Mon Feb 20 20:44:22 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;
357
358 for (i = AvFILL (overlay_av); i >= 0; i--)
359 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this)
317 { 360 {
318 char key[33]; sprintf (key, "%32lx", (long)this); 361 av_delete (overlay_av, i, G_DISCARD);
319 362 break;
320 HV *hv = (HV *)SvRV (*ovs);
321 hv_delete (hv, key, 32, G_DISCARD);
322 } 363 }
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),
748 const_iv (SelectionRequest), 855 const_iv (SelectionRequest),
749 const_iv (SelectionNotify), 856 const_iv (SelectionNotify),
750 const_iv (ColormapNotify), 857 const_iv (ColormapNotify),
751 const_iv (ClientMessage), 858 const_iv (ClientMessage),
752 const_iv (MappingNotify), 859 const_iv (MappingNotify),
860# if ENABLE_XIM_ONTHESPOT
861 const_iv (XIMReverse),
862 const_iv (XIMUnderline),
863 const_iv (XIMHighlight),
864 const_iv (XIMPrimary),
865 const_iv (XIMSecondary),
866 const_iv (XIMTertiary),
867 const_iv (XIMVisibleToForward),
868 const_iv (XIMVisibleToBackword),
869 const_iv (XIMVisibleToCenter),
870# if 0
871 const_iv (XIMForwardChar),
872 const_iv (XIMBackwardChar),
873 const_iv (XIMForwardWord),
874 const_iv (XIMBackwardWord),
875 const_iv (XIMCaretUp),
876 const_iv (XIMCaretDown),
877 const_iv (XIMNextLine),
878 const_iv (XIMPreviousLine),
879 const_iv (XIMLineStart),
880 const_iv (XIMLineEnd),
881 const_iv (XIMAbsolutePosition),
882 const_iv (XIMDontChange),
883# endif
884# endif
753 }; 885 };
754 886
755 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); 887 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)); 888 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
758} 889}
759 890
760void 891void
761warn (const char *msg) 892warn (const char *msg)
792 RETVAL 923 RETVAL
793 924
794int 925int
795SET_FGCOLOR (int rend, int new_color) 926SET_FGCOLOR (int rend, int new_color)
796 CODE: 927 CODE:
797 RETVAL = SET_FGCOLOR (rend, new_color); 928 RETVAL = SET_FGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
798 OUTPUT: 929 OUTPUT:
799 RETVAL 930 RETVAL
800 931
801int 932int
802SET_BGCOLOR (int rend, int new_color) 933SET_BGCOLOR (int rend, int new_color)
803 CODE: 934 CODE:
804 RETVAL = SET_BGCOLOR (rend, new_color); 935 RETVAL = SET_BGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
805 OUTPUT: 936 OUTPUT:
806 RETVAL 937 RETVAL
807 938
808int 939int
809GET_CUSTOM (int rend) 940GET_CUSTOM (int rend)
823 | ((new_value << RS_customShift) & RS_customMask); 954 | ((new_value << RS_customShift) & RS_customMask);
824} 955}
825 OUTPUT: 956 OUTPUT:
826 RETVAL 957 RETVAL
827 958
959void
960termlist ()
961 PPCODE:
962{
963 EXTEND (SP, rxvt_term::termlist.size ());
964
965 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
966 if ((*t)->perl.self)
967 PUSHs (sv_2mortal (newSVterm (*t)));
968}
969
828MODULE = urxvt PACKAGE = urxvt::term 970MODULE = urxvt PACKAGE = urxvt::term
829 971
830SV * 972SV *
831_new (...) 973_new (AV *env, AV *arg)
832 CODE: 974 CODE:
833{ 975{
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; 976 rxvt_term *term = new rxvt_term;
838 977
839 term->argv = new stringvec; 978 stringvec *argv = new stringvec;
840 term->envv = new stringvec; 979 stringvec *envv = new stringvec;
841 980
842 for (int i = 1; i < items; i++) 981 for (int i = 0; i <= AvFILL (arg); i++)
843 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 982 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
844 983
845 AV *envv = (AV *)SvRV (ST (0));
846 for (int i = av_len (envv) + 1; i--; ) 984 for (int i = AvFILL (env) + 1; i--; )
847 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 985 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
848 986
849 term->envv->push_back (0); 987 envv->push_back (0);
850 988
851 bool success; 989 bool success;
852 990
853 try 991 try
854 { 992 {
855 success = term->init (term->argv->size (), term->argv->begin ()); 993 success = term->init (argv, envv);
856 } 994 }
857 catch (const class rxvt_failure_exception &e) 995 catch (const class rxvt_failure_exception &e)
858 { 996 {
859 success = false; 997 success = false;
860 } 998 }
872 RETVAL 1010 RETVAL
873 1011
874void 1012void
875rxvt_term::destroy () 1013rxvt_term::destroy ()
876 1014
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 1015void
967rxvt_term::set_should_invoke (int htype, int inc) 1016rxvt_term::set_should_invoke (int htype, int inc)
968 CODE: 1017 CODE:
969 THIS->perl.should_invoke [htype] += inc; 1018 THIS->perl.should_invoke [htype] += inc;
970 1019
971void 1020void
972rxvt_term::grab_button (int button, U32 modifiers) 1021rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt)
973 CODE: 1022 CODE:
974 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 1023 XGrabButton (THIS->dpy, button, modifiers, window, 1,
975 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1024 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
976 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 1025 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
977 1026
1027void
1028rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt)
1029 CODE:
1030 XUngrabButton (THIS->dpy, button, modifiers, window);
1031
1032#if 0
1033
1034void
1035XGrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt)
1036 C_ARGS:
1037 THIS->dpy, keycode, modifiers, window, 1,
1038 GrabModeSync, GrabModeSync
1039
1040void
1041XUngrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt)
1042 C_ARGS: THIS->dpy, keycode, modifiers, window
1043
1044#endif
1045
978bool 1046bool
979rxvt_term::grab (U32 eventtime, int sync = 0) 1047rxvt_term::grab (Time eventtime, int sync = 0)
980 CODE: 1048 CODE:
981{ 1049{
982 int mode = sync ? GrabModeSync : GrabModeAsync; 1050 int mode = sync ? GrabModeSync : GrabModeAsync;
983 1051
984 THIS->perl.grabtime = 0; 1052 THIS->perl.grabtime = 0;
985 1053
986 if (!XGrabPointer (THIS->display->display, THIS->vt, 0, 1054 if (!XGrabPointer (THIS->dpy, THIS->vt, 0,
987 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 1055 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
988 mode, mode, None, GRAB_CURSOR, eventtime)) 1056 mode, mode, None, GRAB_CURSOR, eventtime))
989 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) 1057 if (!XGrabKeyboard (THIS->dpy, THIS->vt, 0, mode, mode, eventtime))
990 THIS->perl.grabtime = eventtime; 1058 THIS->perl.grabtime = eventtime;
991 else 1059 else
992 XUngrabPointer (THIS->display->display, eventtime); 1060 XUngrabPointer (THIS->dpy, eventtime);
993 1061
994 RETVAL = !!THIS->perl.grabtime; 1062 RETVAL = !!THIS->perl.grabtime;
995} 1063}
996 OUTPUT: 1064 OUTPUT:
997 RETVAL 1065 RETVAL
998 1066
999void 1067void
1000rxvt_term::allow_events_async () 1068rxvt_term::allow_events_async ()
1001 CODE: 1069 CODE:
1002 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); 1070 XAllowEvents (THIS->dpy, AsyncBoth, THIS->perl.grabtime);
1003 1071
1004void 1072void
1005rxvt_term::allow_events_sync () 1073rxvt_term::allow_events_sync ()
1006 CODE: 1074 CODE:
1007 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); 1075 XAllowEvents (THIS->dpy, SyncBoth, THIS->perl.grabtime);
1008 1076
1009void 1077void
1010rxvt_term::allow_events_replay () 1078rxvt_term::allow_events_replay ()
1011 CODE: 1079 CODE:
1012 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); 1080 XAllowEvents (THIS->dpy, ReplayPointer, THIS->perl.grabtime);
1013 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); 1081 XAllowEvents (THIS->dpy, ReplayKeyboard, THIS->perl.grabtime);
1014 1082
1015void 1083void
1016rxvt_term::ungrab () 1084rxvt_term::ungrab ()
1017 CODE: 1085 CODE:
1018 ungrab (THIS); 1086 ungrab (THIS);
1076#define TERM_OFFSET_fbase TERM_OFFSET(fbase) 1144#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1077#define TERM_OFFSET_nrow TERM_OFFSET(nrow) 1145#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1078#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1146#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1079#define TERM_OFFSET_focus TERM_OFFSET(focus) 1147#define TERM_OFFSET_focus TERM_OFFSET(focus)
1080#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1148#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
1149#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth)
1150#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth)
1151#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace)
1081#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1152#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1082#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1153#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1083#define TERM_OFFSET_top_row TERM_OFFSET(top_row) 1154#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1084 1155
1085int 1156int
1092 fbase = TERM_OFFSET_fbase 1163 fbase = TERM_OFFSET_fbase
1093 nrow = TERM_OFFSET_nrow 1164 nrow = TERM_OFFSET_nrow
1094 ncol = TERM_OFFSET_ncol 1165 ncol = TERM_OFFSET_ncol
1095 focus = TERM_OFFSET_focus 1166 focus = TERM_OFFSET_focus
1096 mapped = TERM_OFFSET_mapped 1167 mapped = TERM_OFFSET_mapped
1168 int_bwidth = TERM_OFFSET_int_bwidth
1169 ext_bwidth = TERM_OFFSET_ext_bwidth
1170 lineSpace = TERM_OFFSET_lineSpace
1097 saveLines = TERM_OFFSET_saveLines 1171 saveLines = TERM_OFFSET_saveLines
1098 total_rows = TERM_OFFSET_total_rows 1172 total_rows = TERM_OFFSET_total_rows
1099 top_row = TERM_OFFSET_top_row 1173 top_row = TERM_OFFSET_top_row
1100 CODE: 1174 CODE:
1101 RETVAL = *(int *)((char *)THIS + ix); 1175 RETVAL = *(int *)((char *)THIS + ix);
1106rxvt_term::ModLevel3Mask () 1180rxvt_term::ModLevel3Mask ()
1107 ALIAS: 1181 ALIAS:
1108 ModLevel3Mask = 0 1182 ModLevel3Mask = 0
1109 ModMetaMask = 1 1183 ModMetaMask = 1
1110 ModNumLockMask = 2 1184 ModNumLockMask = 2
1185 current_screen = 3
1186 hidden_cursor = 4
1111 CODE: 1187 CODE:
1112 switch (ix) 1188 switch (ix)
1113 { 1189 {
1114 case 0: RETVAL = THIS->ModLevel3Mask; break; 1190 case 0: RETVAL = THIS->ModLevel3Mask; break;
1115 case 1: RETVAL = THIS->ModMetaMask; break; 1191 case 1: RETVAL = THIS->ModMetaMask; break;
1116 case 2: RETVAL = THIS->ModNumLockMask; break; 1192 case 2: RETVAL = THIS->ModNumLockMask; break;
1193 case 3: RETVAL = THIS->current_screen; break;
1194 case 4: RETVAL = THIS->hidden_cursor; break;
1117 } 1195 }
1118 OUTPUT: 1196 OUTPUT:
1119 RETVAL 1197 RETVAL
1120 1198
1121char * 1199char *
1131 } 1209 }
1132 OUTPUT: 1210 OUTPUT:
1133 RETVAL 1211 RETVAL
1134 1212
1135SV * 1213SV *
1136rxvt_term::_env () 1214rxvt_term::envv ()
1215 ALIAS:
1216 argv = 1
1137 CODE: 1217 PPCODE:
1138{ 1218{
1139 if (THIS->envv) 1219 stringvec *vec = ix ? THIS->argv : THIS->envv;
1140 {
1141 AV *av = newAV ();
1142 1220
1221 EXTEND (SP, vec->size ());
1222
1143 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) 1223 for (char **i = vec->begin (); i != vec->end (); ++i)
1144 if (*i) 1224 if (*i)
1145 av_push (av, newSVpv (*i, 0)); 1225 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1146
1147 RETVAL = newRV_noinc ((SV *)av);
1148 }
1149 else
1150 RETVAL = &PL_sv_undef;
1151} 1226}
1152 OUTPUT:
1153 RETVAL
1154 1227
1155int 1228int
1156rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1229rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1157 CODE: 1230 CODE:
1158 RETVAL = THIS->pty_ev.events; 1231 RETVAL = THIS->pty_ev.events;
1159 if (events != EVENT_UNDEF) 1232 if (events != EVENT_UNDEF)
1160 THIS->pty_ev.set (events); 1233 THIS->pty_ev.set (events);
1161 OUTPUT: 1234 OUTPUT:
1162 RETVAL 1235 RETVAL
1163 1236
1164U32 1237int
1238rxvt_term::pty_fd ()
1239 CODE:
1240 RETVAL = THIS->pty->pty;
1241 OUTPUT:
1242 RETVAL
1243
1244Window
1165rxvt_term::parent () 1245rxvt_term::parent ()
1166 CODE: 1246 CODE:
1167 RETVAL = (U32)THIS->parent [0]; 1247 RETVAL = THIS->parent [0];
1168 OUTPUT: 1248 OUTPUT:
1169 RETVAL 1249 RETVAL
1170 1250
1171U32 1251Window
1172rxvt_term::vt () 1252rxvt_term::vt ()
1173 CODE: 1253 CODE:
1174 RETVAL = (U32)THIS->vt; 1254 RETVAL = THIS->vt;
1175 OUTPUT: 1255 OUTPUT:
1176 RETVAL 1256 RETVAL
1177 1257
1178void 1258void
1179rxvt_term::vt_emask_add (U32 emask) 1259rxvt_term::vt_emask_add (U32 emask)
1201} 1281}
1202 OUTPUT: 1282 OUTPUT:
1203 RETVAL 1283 RETVAL
1204 1284
1205void 1285void
1286rxvt_term::focus_in ()
1287
1288void
1289rxvt_term::focus_out ()
1290
1291void
1292rxvt_term::key_press (unsigned int state, unsigned int keycode, Time time = CurrentTime)
1293 ALIAS:
1294 key_release = 1
1295 CODE:
1296{
1297 XKeyEvent xkey;
1298
1299 memset (&xkey, 0, sizeof (xkey));
1300
1301 xkey.time = time;
1302 xkey.state = state;
1303 xkey.keycode = keycode;
1304
1305 xkey.type = ix ? KeyRelease : KeyPress;
1306 xkey.display = THIS->dpy;
1307 xkey.window = THIS->vt;
1308 xkey.root = THIS->display->root;
1309 xkey.subwindow = THIS->vt;
1310
1311 if (ix)
1312 THIS->key_release (xkey);
1313 else
1314 THIS->key_press (xkey);
1315}
1316
1317void
1206rxvt_term::want_refresh () 1318rxvt_term::want_refresh ()
1207 CODE: 1319 CODE:
1208 THIS->want_refresh = 1; 1320 THIS->want_refresh = 1;
1209 1321
1210void 1322void
1216 1328
1217 line_t &l = ROW(row_number); 1329 line_t &l = ROW(row_number);
1218 1330
1219 if (GIMME_V != G_VOID) 1331 if (GIMME_V != G_VOID)
1220 { 1332 {
1221 wchar_t *wstr = new wchar_t [THIS->ncol]; 1333 wchar_t *wstr = rxvt_temp_buf<wchar_t> (THIS->ncol);
1222 1334
1223 for (int col = 0; col < THIS->ncol; col++) 1335 for (int col = 0; col < THIS->ncol; col++)
1224 wstr [col] = l.t [col]; 1336 wstr [col] = l.t [col];
1225 1337
1226 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1338 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1227
1228 delete [] wstr;
1229 } 1339 }
1230 1340
1231 if (new_text) 1341 if (new_text)
1232 { 1342 {
1233 wchar_t *wstr = sv2wcs (new_text); 1343 wchar_t *wstr = sv2wcs (new_text);
1234 1344
1235 int len = min (wcslen (wstr) - start_ofs, max_len); 1345 int len = min (wcslen (wstr) - start_ofs, max_len);
1236 1346
1237 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1347 if (start_col < 0 || start_col + len > THIS->ncol)
1238 { 1348 {
1239 free (wstr); 1349 free (wstr);
1240 croak ("new_text extends beyond horizontal margins"); 1350 croak ("new_text extends beyond horizontal margins");
1241 } 1351 }
1242 1352
1274 { 1384 {
1275 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1385 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1276 croak ("new_rend must be arrayref"); 1386 croak ("new_rend must be arrayref");
1277 1387
1278 AV *av = (AV *)SvRV (new_rend); 1388 AV *av = (AV *)SvRV (new_rend);
1279 int len = min (av_len (av) + 1 - start_ofs, max_len); 1389 int len = min (AvFILL (av) + 1 - start_ofs, max_len);
1280 1390
1281 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1391 if (start_col < 0 || start_col + len > THIS->ncol)
1282 croak ("new_rend array extends beyond horizontal margins"); 1392 croak ("new_rend array extends beyond horizontal margins");
1283 1393
1284 for (int col = start_col; col < start_col + len; col++) 1394 for (int col = start_col; col < start_col + len; col++)
1285 { 1395 {
1286 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; 1396 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1326rxvt_term::special_encode (SV *string) 1436rxvt_term::special_encode (SV *string)
1327 CODE: 1437 CODE:
1328{ 1438{
1329 wchar_t *wstr = sv2wcs (string); 1439 wchar_t *wstr = sv2wcs (string);
1330 int wlen = wcslen (wstr); 1440 int wlen = wcslen (wstr);
1331 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer 1441 wchar_t *rstr = rxvt_temp_buf<wchar_t> (wlen * 2); // cannot become longer
1332 1442
1333 rxvt_push_locale (THIS->locale); 1443 rxvt_push_locale (THIS->locale);
1334 1444
1335 wchar_t *r = rstr; 1445 wchar_t *r = rstr;
1336 for (wchar_t *s = wstr; *s; s++) 1446 for (wchar_t *s = wstr; *s; s++)
1447 {
1448 int w = WCWIDTH (*s);
1449
1337 if (wcwidth (*s) == 0) 1450 if (w == 0)
1338 { 1451 {
1339 if (r == rstr) 1452 if (r == rstr)
1340 croak ("leading combining character unencodable"); 1453 croak ("leading combining character unencodable");
1341 1454
1342 unicode_t n = rxvt_compose (r[-1], *s); 1455 unicode_t n = rxvt_compose (r[-1], *s);
1343 if (n == NOCHAR) 1456 if (n == NOCHAR)
1344 n = rxvt_composite.compose (r[-1], *s); 1457 n = rxvt_composite.compose (r[-1], *s);
1345 1458
1346 r[-1] = n; 1459 r[-1] = n;
1347 } 1460 }
1348#if !UNICODE_3 1461#if !UNICODE_3
1349 else if (*s >= 0x10000) 1462 else if (*s >= 0x10000)
1350 *r++ = rxvt_composite.compose (*s); 1463 *r++ = rxvt_composite.compose (*s);
1351#endif 1464#endif
1352 else 1465 else
1353 *r++ = *s; 1466 *r++ = *s;
1467
1468 // the *2 above only allows wcwidth <= 2
1469 if (w > 1)
1470 *r++ = NOCHAR;
1471 }
1354 1472
1355 rxvt_pop_locale (); 1473 rxvt_pop_locale ();
1356 1474
1357 RETVAL = wcs2sv (rstr, r - rstr); 1475 RETVAL = wcs2sv (rstr, r - rstr);
1358
1359 delete [] rstr;
1360} 1476}
1361 OUTPUT: 1477 OUTPUT:
1362 RETVAL 1478 RETVAL
1363 1479
1364SV * 1480SV *
1376 else if (IS_COMPOSE (*s)) 1492 else if (IS_COMPOSE (*s))
1377 dlen += rxvt_composite.expand (*s, 0); 1493 dlen += rxvt_composite.expand (*s, 0);
1378 else 1494 else
1379 dlen++; 1495 dlen++;
1380 1496
1381 wchar_t *rstr = new wchar_t [dlen]; 1497 wchar_t *rstr = rxvt_temp_buf<wchar_t> (dlen);
1382 1498
1383 // decode 1499 // decode
1384 wchar_t *r = rstr; 1500 wchar_t *r = rstr;
1385 for (wchar_t *s = wstr; *s; s++) 1501 for (wchar_t *s = wstr; *s; s++)
1386 if (*s == NOCHAR) 1502 if (*s == NOCHAR)
1389 r += rxvt_composite.expand (*s, r); 1505 r += rxvt_composite.expand (*s, r);
1390 else 1506 else
1391 *r++ = *s; 1507 *r++ = *s;
1392 1508
1393 RETVAL = wcs2sv (rstr, r - rstr); 1509 RETVAL = wcs2sv (rstr, r - rstr);
1394
1395 delete [] rstr;
1396} 1510}
1397 OUTPUT: 1511 OUTPUT:
1398 RETVAL 1512 RETVAL
1399 1513
1400void 1514void
1401rxvt_term::_resource (char *name, int index, SV *newval = 0) 1515rxvt_term::_resource (char *name, int index, SV *newval = 0)
1402 PPCODE: 1516 PPCODE:
1403{ 1517{
1404 struct resval { const char *name; int value; } rslist [] = { 1518 static const struct resval { const char *name; int value; } *rs, rslist [] = {
1405# define def(name) { # name, Rs_ ## name }, 1519# define def(name) { # name, Rs_ ## name },
1406# define reserve(name,count) 1520# define reserve(name,count)
1407# include "rsinc.h" 1521# include "rsinc.h"
1408# undef def 1522# undef def
1409# undef reserve 1523# undef reserve
1410 }; 1524 };
1411 1525
1412 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1526 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1413 1527
1414 do { 1528 do {
1415 if (rs-- == rslist) 1529 if (rs-- == rslist)
1416 croak ("no such resource '%s', requested", name); 1530 croak ("no such resource '%s', requested", name);
1417 } while (strcmp (name, rs->name)); 1531 } while (strcmp (name, rs->name));
1451 if (set) 1565 if (set)
1452 THIS->options |= optval; 1566 THIS->options |= optval;
1453 else 1567 else
1454 THIS->options &= ~optval; 1568 THIS->options &= ~optval;
1455 1569
1570 if (THIS->check_ev.is_active ()) // avoid doing this before START
1456 switch (optval) 1571 switch (optval)
1457 { 1572 {
1458 case Opt_skipBuiltinGlyphs: 1573 case Opt_skipBuiltinGlyphs:
1459 THIS->set_fonts (); 1574 THIS->set_fonts ();
1460 THIS->scr_remap_chars (); 1575 THIS->scr_remap_chars ();
1461 THIS->scr_touch (true); 1576 THIS->scr_touch (true);
1462 THIS->want_refresh = 1; 1577 THIS->want_refresh = 1;
1463 break; 1578 break;
1464 1579
1465 case Opt_cursorUnderline: 1580 case Opt_cursorUnderline:
1466 THIS->want_refresh = 1; 1581 THIS->want_refresh = 1;
1467 break; 1582 break;
1468 1583
1469# case Opt_scrollBar_floating: 1584# case Opt_scrollBar_floating:
1470# case Opt_scrollBar_right: 1585# case Opt_scrollBar_right:
1471# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1586# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1472# break; 1587# break;
1473 } 1588 }
1474 } 1589 }
1475} 1590}
1476 OUTPUT: 1591 OUTPUT:
1477 RETVAL 1592 RETVAL
1478 1593
1506 PUSHs (sv_2mortal (newSViv (rc.col))); 1621 PUSHs (sv_2mortal (newSViv (rc.col)));
1507 } 1622 }
1508 1623
1509 if (items == 3) 1624 if (items == 3)
1510 { 1625 {
1626 rc.row = SvIV (ST (1));
1627 rc.col = SvIV (ST (2));
1628
1629 if (ix == 2)
1630 {
1631 if (rc.col == 0)
1632 {
1633 // col == 0 means end of previous line
1634 rc.row--;
1635 rc.col = THIS->ncol;
1636 }
1637 else if (IN_RANGE_EXC (rc.row, THIS->top_row, THIS->nrow)
1638 && rc.col > ROW(rc.row).l)
1639 {
1640 // col >= length means while line and add newline
1641 rc.col = THIS->ncol;
1642 }
1643 }
1644
1645 clamp_it (rc.col, 0, THIS->ncol);
1511 rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1); 1646 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1512 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
1513 1647
1514 if (ix) 1648 if (ix)
1515 THIS->want_refresh = 1; 1649 THIS->want_refresh = 1;
1516 } 1650 }
1517} 1651}
1521 CODE: 1655 CODE:
1522 RETVAL = THIS->charsets [THIS->screen.charset]; 1656 RETVAL = THIS->charsets [THIS->screen.charset];
1523 OUTPUT: 1657 OUTPUT:
1524 RETVAL 1658 RETVAL
1525 1659
1526#void 1660void
1527#rxvt_term::selection_clear () 1661rxvt_term::selection_clear ()
1528 1662
1529void 1663void
1530rxvt_term::selection_make (U32 eventtime, bool rect = false) 1664rxvt_term::selection_make (Time eventtime, bool rect = false)
1531 CODE: 1665 CODE:
1532 THIS->selection.op = SELECTION_CONT; 1666 THIS->selection.op = SELECTION_CONT;
1533 THIS->selection.rect = rect; 1667 THIS->selection.rect = rect;
1534 THIS->selection_make (eventtime); 1668 THIS->selection_make (eventtime);
1535 1669
1536int 1670int
1537rxvt_term::selection_grab (U32 eventtime) 1671rxvt_term::selection_grab (Time eventtime)
1538 1672
1539void 1673void
1540rxvt_term::selection (SV *newtext = 0) 1674rxvt_term::selection (SV *newtext = 0)
1541 PPCODE: 1675 PPCODE:
1542{ 1676{
1560void 1694void
1561rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) 1695rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1562 1696
1563void 1697void
1564rxvt_term::scr_bell () 1698rxvt_term::scr_bell ()
1699
1700void
1701rxvt_term::scr_change_screen (int screen)
1565 1702
1566void 1703void
1567rxvt_term::scr_add_lines (SV *string) 1704rxvt_term::scr_add_lines (SV *string)
1568 CODE: 1705 CODE:
1569{ 1706{
1610 o->self = (HV *)SvRV (RETVAL); 1747 o->self = (HV *)SvRV (RETVAL);
1611} 1748}
1612 OUTPUT: 1749 OUTPUT:
1613 RETVAL 1750 RETVAL
1614 1751
1752#############################################################################
1753# Various X Utility Functions
1754#############################################################################
1755
1756void
1757rxvt_term::XListProperties (Window window)
1758 PPCODE:
1759{
1760 int count;
1761 Atom *props = XListProperties (THIS->dpy, window, &count);
1762
1763 EXTEND (SP, count);
1764 while (count--)
1765 PUSHs (newSVuv ((U32)props [count]));
1766
1767 XFree (props);
1768}
1769
1770void
1771rxvt_term::XGetWindowProperty (Window window, Atom property)
1772 PPCODE:
1773{
1774 Atom type;
1775 int format;
1776 unsigned long nitems;
1777 unsigned long bytes_after;
1778 unsigned char *prop;
1779
1780 XGetWindowProperty (THIS->dpy, window, property,
1781 0, 1<<24, 0, AnyPropertyType,
1782 &type, &format, &nitems, &bytes_after, &prop);
1783
1784 if (type != None)
1785 {
1786 int elemsize = format == 16 ? sizeof (short)
1787 : format == 32 ? sizeof (long)
1788 : 1;
1789
1790 EXTEND (SP, 3);
1791 PUSHs (newSVuv ((U32)type));
1792 PUSHs (newSViv (format));
1793 PUSHs (newSVpvn ((char *)prop, nitems * elemsize));
1794 XFree (prop);
1795 }
1796}
1797
1798void
1799rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data)
1800 CODE:
1801{
1802 STRLEN len;
1803 char *data_ = SvPVbyte (data, len);
1804
1805 int elemsize = format == 16 ? sizeof (short)
1806 : format == 32 ? sizeof (long)
1807 : 1;
1808
1809 XChangeProperty (THIS->dpy, window, property,
1810 type, format, PropModeReplace,
1811 (unsigned char *)data_, len / elemsize);
1812}
1813
1814Atom
1815XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1816 C_ARGS: term->dpy, atom_name, only_if_exists
1817
1818char *
1819XGetAtomName (rxvt_term *term, Atom atom)
1820 C_ARGS: term->dpy, atom
1821 CLEANUP:
1822 XFree (RETVAL);
1823
1824void
1825XDeleteProperty (rxvt_term *term, Window window, Atom property)
1826 C_ARGS: term->dpy, window, property
1827
1828Window
1829rxvt_term::DefaultRootWindow ()
1830 CODE:
1831 RETVAL = THIS->display->root;
1832 OUTPUT:
1833 RETVAL
1834
1835#if 0
1836
1837Window
1838XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1839 C_ARGS: term->dpy, (Window)parent,
1840 x, y, width, height, 0,
1841 term->pix_colors_focused[Color_border],
1842 term->pix_colors_focused[Color_border]
1843
1844#endif
1845
1846void
1847XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1848 C_ARGS: term->dpy, window, parent, x, y
1849
1850void
1851XMapWindow (rxvt_term *term, Window window)
1852 C_ARGS: term->dpy, window
1853
1854void
1855XUnmapWindow (rxvt_term *term, Window window)
1856 C_ARGS: term->dpy, window
1857
1858void
1859XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1860 C_ARGS: term->dpy, window, x, y, width, height
1861
1862void
1863rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0)
1864 CODE:
1865{
1866 XWindowAttributes attr;
1867 XGetWindowAttributes (THIS->dpy, window, &attr);
1868 XSelectInput (THIS->dpy, window, attr.your_event_mask | add_events & ~del_events);
1869}
1870
1871void
1872rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y)
1873 PPCODE:
1874{
1875 int dx, dy;
1876 Window child;
1877
1878 if (XTranslateCoordinates (THIS->dpy, src, dst, x, y, &dx, &dy, &child))
1879 {
1880 EXTEND (SP, 3);
1881 PUSHs (newSViv (dx));
1882 PUSHs (newSViv (dy));
1883 PUSHs (newSVuv (child));
1884 }
1885}
1886
1887#############################################################################
1888# urxvt::overlay
1889#############################################################################
1890
1615MODULE = urxvt PACKAGE = urxvt::overlay 1891MODULE = urxvt PACKAGE = urxvt::overlay
1616 1892
1617void 1893void
1618overlay::set (int x, int y, SV *text, SV *rend = 0) 1894overlay::set (int x, int y, SV *text, SV *rend = 0)
1619 1895
1623void 1899void
1624overlay::hide () 1900overlay::hide ()
1625 1901
1626void 1902void
1627overlay::DESTROY () 1903overlay::DESTROY ()
1904
1905#############################################################################
1906# urxvt::watcher
1907#############################################################################
1908
1909MODULE = urxvt PACKAGE = urxvt::watcher
1910
1911CHAINED
1912perl_watcher::cb (SV *cb)
1913 CODE:
1914 THIS->cb (cb);
1915 OUTPUT:
1916 RETVAL
1917
1918#############################################################################
1919# urxvt::timer
1920#############################################################################
1628 1921
1629MODULE = urxvt PACKAGE = urxvt::timer 1922MODULE = urxvt PACKAGE = urxvt::timer
1630 1923
1631SV * 1924SV *
1632timer::new () 1925timer::new ()
1633 CODE: 1926 CODE:
1634 timer *w = new timer; 1927 timer *w = new timer;
1635 w->start (NOW); 1928 w->start (NOW);
1636 RETVAL = newSVptr ((void *)w, "urxvt::timer"); 1929 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::timer");
1637 w->self = (HV *)SvRV (RETVAL); 1930 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: 1931 OUTPUT:
1647 RETVAL 1932 RETVAL
1648 1933
1649NV 1934NV
1650timer::at () 1935timer::at ()
1651 CODE: 1936 CODE:
1652 RETVAL = THIS->at; 1937 RETVAL = THIS->at;
1653 OUTPUT: 1938 OUTPUT:
1654 RETVAL 1939 RETVAL
1655 1940
1656timer * 1941CHAINED
1657timer::interval (NV interval) 1942timer::interval (NV interval)
1658 CODE: 1943 CODE:
1659 THIS->interval = interval; 1944 THIS->interval = interval;
1945 OUTPUT:
1660 RETVAL = THIS; 1946 RETVAL
1661 OUTPUT:
1662 RETVAL
1663 1947
1664timer * 1948CHAINED
1665timer::set (NV tstamp) 1949timer::set (NV tstamp)
1666 CODE: 1950 CODE:
1667 THIS->set (tstamp); 1951 THIS->set (tstamp);
1952 OUTPUT:
1668 RETVAL = THIS; 1953 RETVAL
1669 OUTPUT:
1670 RETVAL
1671 1954
1672timer * 1955CHAINED
1673timer::start (NV tstamp = THIS->at) 1956timer::start (NV tstamp = THIS->at)
1674 CODE: 1957 CODE:
1675 THIS->start (tstamp); 1958 THIS->start (tstamp);
1959 OUTPUT:
1676 RETVAL = THIS; 1960 RETVAL
1677 OUTPUT:
1678 RETVAL
1679 1961
1680timer * 1962CHAINED
1963timer::after (NV delay)
1964 CODE:
1965 THIS->start (NOW + delay);
1966 OUTPUT:
1967 RETVAL
1968
1969CHAINED
1681timer::stop () 1970timer::stop ()
1682 CODE: 1971 CODE:
1683 THIS->stop (); 1972 THIS->stop ();
1684 RETVAL = THIS;
1685 OUTPUT: 1973 OUTPUT:
1686 RETVAL 1974 RETVAL
1687 1975
1688void 1976void
1689timer::DESTROY () 1977timer::DESTROY ()
1978
1979#############################################################################
1980# urxvt::iow
1981#############################################################################
1690 1982
1691MODULE = urxvt PACKAGE = urxvt::iow 1983MODULE = urxvt PACKAGE = urxvt::iow
1692 1984
1693SV * 1985SV *
1694iow::new () 1986iow::new ()
1695 CODE: 1987 CODE:
1696 iow *w = new iow; 1988 iow *w = new iow;
1697 RETVAL = newSVptr ((void *)w, "urxvt::iow"); 1989 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iow");
1698 w->self = (HV *)SvRV (RETVAL); 1990 w->self = (HV *)SvRV (RETVAL);
1699 OUTPUT: 1991 OUTPUT:
1700 RETVAL 1992 RETVAL
1701 1993
1702iow * 1994CHAINED
1703iow::cb (SV *cb)
1704 CODE:
1705 THIS->cb (cb);
1706 RETVAL = THIS;
1707 OUTPUT:
1708 RETVAL
1709
1710iow *
1711iow::fd (int fd) 1995iow::fd (int fd)
1712 CODE: 1996 CODE:
1713 THIS->fd = fd; 1997 THIS->fd = fd;
1998 OUTPUT:
1714 RETVAL = THIS; 1999 RETVAL
1715 OUTPUT:
1716 RETVAL
1717 2000
1718iow * 2001CHAINED
1719iow::events (short events) 2002iow::events (short events)
1720 CODE: 2003 CODE:
1721 THIS->events = events; 2004 THIS->events = events;
2005 OUTPUT:
1722 RETVAL = THIS; 2006 RETVAL
1723 OUTPUT:
1724 RETVAL
1725 2007
1726iow * 2008CHAINED
1727iow::start () 2009iow::start ()
1728 CODE: 2010 CODE:
1729 THIS->start (); 2011 THIS->start ();
2012 OUTPUT:
1730 RETVAL = THIS; 2013 RETVAL
1731 OUTPUT:
1732 RETVAL
1733 2014
1734iow * 2015CHAINED
1735iow::stop () 2016iow::stop ()
1736 CODE: 2017 CODE:
1737 THIS->stop (); 2018 THIS->stop ();
1738 RETVAL = THIS;
1739 OUTPUT: 2019 OUTPUT:
1740 RETVAL 2020 RETVAL
1741 2021
1742void 2022void
1743iow::DESTROY () 2023iow::DESTROY ()
1744 2024
2025#############################################################################
2026# urxvt::iw
2027#############################################################################
1745 2028
2029MODULE = urxvt PACKAGE = urxvt::iw
2030
2031SV *
2032iw::new ()
2033 CODE:
2034 iw *w = new iw;
2035 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iw");
2036 w->self = (HV *)SvRV (RETVAL);
2037 OUTPUT:
2038 RETVAL
2039
2040CHAINED
2041iw::start ()
2042 CODE:
2043 THIS->start ();
2044 OUTPUT:
2045 RETVAL
2046
2047CHAINED
2048iw::stop ()
2049 CODE:
2050 THIS->stop ();
2051 OUTPUT:
2052 RETVAL
2053
2054void
2055iw::DESTROY ()
2056
2057#############################################################################
2058# urxvt::pw
2059#############################################################################
2060
2061MODULE = urxvt PACKAGE = urxvt::pw
2062
2063SV *
2064pw::new ()
2065 CODE:
2066 pw *w = new pw;
2067 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::pw");
2068 w->self = (HV *)SvRV (RETVAL);
2069 OUTPUT:
2070 RETVAL
2071
2072CHAINED
2073pw::start (int pid)
2074 CODE:
2075 THIS->start (pid);
2076 OUTPUT:
2077 RETVAL
2078
2079CHAINED
2080pw::stop ()
2081 CODE:
2082 THIS->stop ();
2083 OUTPUT:
2084 RETVAL
2085
2086void
2087pw::DESTROY ()
2088
2089

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines