ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtperl.xs
Revision: 1.58
Committed: Thu Jan 12 01:38:37 2006 UTC (18 years, 5 months ago) by root
Branch: MAIN
Changes since 1.57: +0 -4 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 /*----------------------------------------------------------------------*
2     * File: rxvtperl.xs
3     *----------------------------------------------------------------------*
4     *
5     * All portions of code are copyright by their respective author/s.
6 root 1.31 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com>
7 root 1.1 *
8     * This program is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation; either version 2 of the License, or
11     * (at your option) any later version.
12     *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with this program; if not, write to the Free Software
20     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21     *----------------------------------------------------------------------*/
22    
23     #define line_t perl_line_t
24     #include <EXTERN.h>
25     #include <perl.h>
26     #include <XSUB.h>
27     #undef line_t
28    
29     #include "../config.h"
30    
31 root 1.38 #include <cstddef>
32 root 1.1 #include <cstdarg>
33    
34 root 1.50 #include "iom.h"
35 root 1.1 #include "rxvt.h"
36 root 1.50 #include "keyboard.h"
37 root 1.1 #include "rxvtutil.h"
38     #include "rxvtperl.h"
39    
40     #include "perlxsi.c"
41    
42 root 1.41 #if defined(HAVE_SCROLLBARS) || defined(MENUBAR)
43     # define GRAB_CURSOR THIS->leftptr_cursor
44     #else
45     # define GRAB_CURSOR None
46     #endif
47    
48 root 1.8 #undef LINENO
49     #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
50     #undef ROW
51     #define ROW(n) THIS->row_buf [LINENO (n)]
52    
53 root 1.1 /////////////////////////////////////////////////////////////////////////////
54    
55 root 1.42 static SV *
56     taint (SV *sv)
57     {
58     SvTAINT (sv);
59     return sv;
60     }
61    
62     static SV *
63     taint_if (SV *sv, SV *src)
64     {
65     if (SvTAINTED (src))
66     SvTAINT (sv);
67    
68     return sv;
69     }
70    
71 root 1.1 static wchar_t *
72     sv2wcs (SV *sv)
73     {
74     STRLEN len;
75     char *str = SvPVutf8 (sv, len);
76     return rxvt_utf8towcs (str, len);
77     }
78    
79     static SV *
80 root 1.25 wcs2sv (wchar_t *wstr, int len = -1)
81     {
82     char *str = rxvt_wcstoutf8 (wstr, len);
83    
84     SV *sv = newSVpv (str, 0);
85     SvUTF8_on (sv);
86     free (str);
87    
88     return sv;
89     }
90    
91     static SV *
92 root 1.1 new_ref (HV *hv, const char *klass)
93     {
94     return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
95     }
96    
97     //TODO: use magic
98     static SV *
99     newSVptr (void *ptr, const char *klass)
100     {
101     HV *hv = newHV ();
102 root 1.18 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
103 root 1.1 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
104     }
105    
106 root 1.18 static void
107     clearSVptr (SV *sv)
108     {
109     if (SvROK (sv))
110     sv = SvRV (sv);
111    
112     hv_clear ((HV *)sv);
113     sv_unmagic (sv, PERL_MAGIC_ext);
114     }
115    
116 root 1.1 static long
117     SvPTR (SV *sv, const char *klass)
118     {
119     if (!sv_derived_from (sv, klass))
120     croak ("object of type %s expected", klass);
121    
122 root 1.18 MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
123 root 1.1
124 root 1.18 if (!mg)
125 root 1.1 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
126    
127 root 1.18 return (long)mg->mg_ptr;
128 root 1.1 }
129    
130 root 1.36 #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
131 root 1.1 #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
132    
133     /////////////////////////////////////////////////////////////////////////////
134    
135     struct perl_watcher
136     {
137     SV *cbsv;
138     HV *self;
139    
140     perl_watcher ()
141     : cbsv (newSV (0))
142     {
143     }
144    
145     ~perl_watcher ()
146     {
147     SvREFCNT_dec (cbsv);
148     }
149    
150     void cb (SV *cb)
151     {
152     sv_setsv (cbsv, cb);
153     }
154    
155     void invoke (const char *type, SV *self, int arg = -1);
156     };
157    
158     void
159     perl_watcher::invoke (const char *type, SV *self, int arg)
160     {
161     dSP;
162    
163     ENTER;
164     SAVETMPS;
165    
166     PUSHMARK (SP);
167    
168     XPUSHs (sv_2mortal (self));
169    
170     if (arg >= 0)
171     XPUSHs (sv_2mortal (newSViv (arg)));
172    
173     PUTBACK;
174     call_sv (cbsv, G_VOID | G_EVAL | G_DISCARD);
175     SPAGAIN;
176    
177     PUTBACK;
178     FREETMPS;
179     LEAVE;
180    
181     if (SvTRUE (ERRSV))
182     rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
183     }
184    
185     #define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
186     #define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer")
187    
188     struct timer : time_watcher, perl_watcher
189     {
190 root 1.13 tstamp interval;
191    
192 root 1.1 timer ()
193     : time_watcher (this, &timer::execute)
194     {
195     }
196    
197     void execute (time_watcher &w)
198     {
199 root 1.13 if (interval)
200     start (at + interval);
201    
202 root 1.1 invoke ("urxvt::timer", newSVtimer (this));
203     }
204     };
205    
206     #define newSViow(iow) new_ref (iow->self, "urxvt::iow")
207     #define SvIOW(sv) (iow *)SvPTR (sv, "urxvt::iow")
208    
209     struct iow : io_watcher, perl_watcher
210     {
211     iow ()
212     : io_watcher (this, &iow::execute)
213     {
214     }
215    
216     void execute (io_watcher &w, short revents)
217     {
218     invoke ("urxvt::iow", newSViow (this), revents);
219     }
220     };
221    
222     /////////////////////////////////////////////////////////////////////////////
223    
224 root 1.13 #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
225    
226     struct overlay {
227     HV *self;
228     rxvt_term *THIS;
229     int x, y, w, h;
230     int border;
231     text_t **text;
232     rend_t **rend;
233    
234     overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
235     ~overlay ();
236    
237 root 1.18 void show ();
238     void hide ();
239    
240 root 1.13 void swap ();
241    
242     void set (int x, int y, SV *str, SV *rend);
243     };
244    
245     overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
246     : THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2)
247     {
248     if (border == 2)
249     {
250     w += 2;
251     h += 2;
252     }
253    
254     text = new text_t *[h];
255     rend = new rend_t *[h];
256 root 1.24
257 root 1.13 for (int y = 0; y < h; y++)
258 root 1.24 {
259 root 1.13 text_t *tp = text[y] = new text_t[w];
260     rend_t *rp = rend[y] = new rend_t[w];
261 root 1.24
262 root 1.13 text_t t0, t1, t2;
263     rend_t r = rstyle;
264 root 1.24
265 root 1.13 if (border == 2)
266     {
267     if (y == 0)
268     t0 = 0x2554, t1 = 0x2550, t2 = 0x2557;
269     else if (y < h - 1)
270     t0 = 0x2551, t1 = 0x0020, t2 = 0x2551;
271     else
272     t0 = 0x255a, t1 = 0x2550, t2 = 0x255d;
273 root 1.24
274     *tp++ = t0;
275 root 1.13 *rp++ = r;
276 root 1.24
277 root 1.13 for (int x = w - 2; x-- > 0; )
278     {
279     *tp++ = t1;
280     *rp++ = r;
281 root 1.24 }
282 root 1.13
283     *tp = t2;
284 root 1.24 *rp = r;
285 root 1.13 }
286     else
287     for (int x = w; x-- > 0; )
288     {
289     *tp++ = 0x0020;
290     *rp++ = r;
291 root 1.24 }
292     }
293 root 1.13
294 root 1.18 show ();
295 root 1.13 THIS->want_refresh = 1;
296     }
297    
298     overlay::~overlay ()
299     {
300 root 1.18 hide ();
301    
302 root 1.13 for (int y = h; y--; )
303     {
304     delete [] text[y];
305     delete [] rend[y];
306     }
307    
308     delete [] text;
309     delete [] rend;
310    
311     THIS->want_refresh = 1;
312     }
313    
314 root 1.18 void
315     overlay::show ()
316     {
317     char key[33]; sprintf (key, "%32lx", (long)this);
318    
319 root 1.36 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
320 root 1.18 hv_store (hv, key, 32, newSViv ((long)this), 0);
321     }
322    
323     void
324     overlay::hide ()
325     {
326 root 1.36 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0);
327 root 1.18
328     if (ovs)
329     {
330     char key[33]; sprintf (key, "%32lx", (long)this);
331    
332     HV *hv = (HV *)SvRV (*ovs);
333     hv_delete (hv, key, 32, G_DISCARD);
334     }
335     }
336    
337 root 1.13 void overlay::swap ()
338     {
339     int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
340     int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
341    
342     int ov_w = min (w, THIS->ncol - ov_x);
343     int ov_h = min (h, THIS->nrow - ov_y);
344    
345     for (int y = ov_h; y--; )
346     {
347     text_t *t1 = text [y];
348     rend_t *r1 = rend [y];
349 root 1.24
350 root 1.13 text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x;
351     rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x;
352    
353     for (int x = ov_w; x--; )
354 root 1.24 {
355 root 1.13 text_t t = *t1; *t1++ = *t2; *t2++ = t;
356     rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t));
357     }
358     }
359    
360     }
361    
362 root 1.14 void overlay::set (int x, int y, SV *text, SV *rend)
363 root 1.13 {
364     x += border;
365     y += border;
366    
367     if (!IN_RANGE_EXC (y, 0, h - border))
368     return;
369    
370 root 1.14 wchar_t *wtext = sv2wcs (text);
371 root 1.13
372 root 1.14 for (int col = min (wcslen (wtext), w - x - border); col--; )
373     this->text [y][x + col] = wtext [col];
374 root 1.24
375 root 1.14 free (wtext);
376    
377     if (rend)
378     {
379     if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
380     croak ("rend must be arrayref");
381    
382     AV *av = (AV *)SvRV (rend);
383    
384     for (int col = min (av_len (av) + 1, w - x - border); col--; )
385     this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
386     }
387 root 1.13
388     THIS->want_refresh = 1;
389     }
390    
391    
392     /////////////////////////////////////////////////////////////////////////////
393    
394 root 1.1 struct rxvt_perl_interp rxvt_perl;
395    
396     static PerlInterpreter *perl;
397    
398     rxvt_perl_interp::~rxvt_perl_interp ()
399     {
400     if (perl)
401     {
402     perl_destruct (perl);
403     perl_free (perl);
404     }
405     }
406    
407     void
408 root 1.43 rxvt_perl_interp::init ()
409 root 1.1 {
410     if (!perl)
411     {
412 root 1.57 perl_environ = rxvt_environ;
413     swap (perl_environ, environ);
414 root 1.56
415 root 1.1 char *argv[] = {
416     "",
417 root 1.43 "-T",
418 root 1.1 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
419     };
420    
421     perl = perl_alloc ();
422     perl_construct (perl);
423    
424 root 1.43 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL)
425 root 1.1 || perl_run (perl))
426     {
427     rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
428    
429     perl_destruct (perl);
430     perl_free (perl);
431     perl = 0;
432     }
433 root 1.57
434     swap (perl_environ, environ);
435 root 1.1 }
436     }
437    
438 root 1.45 static void
439     ungrab (rxvt_term *THIS)
440     {
441     if (THIS->perl.grabtime)
442     {
443     XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
444     XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
445     THIS->perl.grabtime = 0;
446     }
447     }
448    
449 root 1.1 bool
450     rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
451     {
452 root 1.13 if (!perl)
453 root 1.1 return false;
454 root 1.24
455 root 1.1 if (htype == HOOK_INIT) // first hook ever called
456 root 1.13 {
457 root 1.36 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
458     hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
459 root 1.13 }
460 root 1.36 else if (!term->perl.self)
461 root 1.17 return false; // perl not initialized for this instance
462 root 1.13 else if (htype == HOOK_DESTROY)
463     {
464     // handled later
465     }
466 root 1.50 else
467 root 1.13 {
468 root 1.50 if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
469     {
470     HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
471 root 1.13
472 root 1.50 if (HvKEYS (hv))
473     {
474     hv_iterinit (hv);
475    
476     while (HE *he = hv_iternext (hv))
477     ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
478     }
479 root 1.13
480     }
481 root 1.50
482     if (!should_invoke [htype])
483     return false;
484 root 1.13 }
485 root 1.1
486 root 1.57 swap (perl_environ, environ);
487 root 1.56
488 root 1.57 try
489     {
490     dSP;
491     va_list ap;
492 root 1.1
493 root 1.57 va_start (ap, htype);
494 root 1.1
495 root 1.57 ENTER;
496     SAVETMPS;
497 root 1.1
498 root 1.57 PUSHMARK (SP);
499 root 1.1
500 root 1.57 XPUSHs (sv_2mortal (newSVterm (term)));
501     XPUSHs (sv_2mortal (newSViv (htype)));
502 root 1.1
503 root 1.57 for (;;) {
504     data_type dt = (data_type)va_arg (ap, int);
505 root 1.1
506 root 1.57 switch (dt)
507     {
508     case DT_INT:
509     XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
510     break;
511    
512     case DT_LONG:
513     XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
514     break;
515    
516     case DT_STR:
517     XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
518     break;
519 root 1.1
520 root 1.57 case DT_STR_LEN:
521     {
522     char *str = va_arg (ap, char *);
523     int len = va_arg (ap, int);
524 root 1.1
525 root 1.57 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
526     }
527     break;
528 root 1.6
529 root 1.57 case DT_WCS_LEN:
530     {
531     wchar_t *wstr = va_arg (ap, wchar_t *);
532     int wlen = va_arg (ap, int);
533 root 1.29
534 root 1.57 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
535     }
536     break;
537 root 1.29
538 root 1.57 case DT_XEVENT:
539     {
540     XEvent *xe = va_arg (ap, XEvent *);
541     HV *hv = newHV ();
542 root 1.29
543     # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
544     # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
545     # undef set
546    
547 root 1.57 setiv (type, xe->type);
548     setiv (send_event, xe->xany.send_event);
549     setiv (serial, xe->xany.serial);
550    
551     switch (xe->type)
552     {
553     case KeyPress:
554     case KeyRelease:
555     case ButtonPress:
556     case ButtonRelease:
557     case MotionNotify:
558     setiv (time, xe->xmotion.time);
559     setiv (x, xe->xmotion.x);
560     setiv (y, xe->xmotion.y);
561     setiv (row, xe->xmotion.y / term->fheight);
562     setiv (col, xe->xmotion.x / term->fwidth);
563     setiv (x_root, xe->xmotion.x_root);
564     setiv (y_root, xe->xmotion.y_root);
565     setiv (state, xe->xmotion.state);
566     break;
567     }
568    
569     switch (xe->type)
570     {
571     case KeyPress:
572     case KeyRelease:
573     setiv (keycode, xe->xkey.keycode);
574     break;
575    
576     case ButtonPress:
577     case ButtonRelease:
578     setiv (button, xe->xbutton.button);
579     break;
580    
581     case MotionNotify:
582     setiv (is_hint, xe->xmotion.is_hint);
583     break;
584     }
585 root 1.29
586 root 1.57 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
587 root 1.29 }
588 root 1.57 break;
589 root 1.29
590 root 1.57 case DT_END:
591 root 1.29 {
592 root 1.57 va_end (ap);
593 root 1.29
594 root 1.57 PUTBACK;
595     int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
596     SPAGAIN;
597    
598     if (count)
599     {
600     SV *status = POPs;
601     count = SvTRUE (status);
602     }
603    
604     PUTBACK;
605     FREETMPS;
606     LEAVE;
607    
608     if (SvTRUE (ERRSV))
609     {
610     rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
611     ungrab (term); // better lose the grab than the session
612     }
613    
614     if (htype == HOOK_DESTROY)
615     {
616     clearSVptr ((SV *)term->perl.self);
617     SvREFCNT_dec ((SV *)term->perl.self);
618     }
619 root 1.29
620 root 1.57 swap (perl_environ, environ);
621     return count;
622 root 1.29 }
623    
624 root 1.57 default:
625     rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
626 root 1.29 }
627 root 1.1 }
628 root 1.57 }
629     catch (...)
630     {
631     swap (perl_environ, environ);
632     throw;
633     }
634 root 1.1 }
635    
636     /////////////////////////////////////////////////////////////////////////////
637    
638     MODULE = urxvt PACKAGE = urxvt
639    
640     PROTOTYPES: ENABLE
641    
642     BOOT:
643     {
644 root 1.52 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
645     sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1));
646     sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1));
647     sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1));
648 root 1.37
649 root 1.1 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
650 root 1.21 # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
651     # include "hookinc.h"
652     # undef def
653 root 1.1
654 root 1.39 HV *option = get_hv ("urxvt::OPTION", 1);
655     # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
656     # define nodef(name)
657     # include "optinc.h"
658     # undef nodef
659     # undef def
660    
661     HV *stash = gv_stashpv ("urxvt", 1);
662     # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
663 root 1.37 export_const_iv (DEFAULT_RSTYLE);
664     export_const_iv (OVERLAY_RSTYLE);
665     export_const_iv (RS_Bold);
666     export_const_iv (RS_Italic);
667     export_const_iv (RS_Blink);
668     export_const_iv (RS_RVid);
669     export_const_iv (RS_Uline);
670 root 1.38
671 root 1.37 export_const_iv (CurrentTime);
672 root 1.38 export_const_iv (ShiftMask);
673     export_const_iv (LockMask);
674     export_const_iv (ControlMask);
675     export_const_iv (Mod1Mask);
676     export_const_iv (Mod2Mask);
677     export_const_iv (Mod3Mask);
678     export_const_iv (Mod4Mask);
679     export_const_iv (Mod5Mask);
680     export_const_iv (Button1Mask);
681     export_const_iv (Button2Mask);
682     export_const_iv (Button3Mask);
683     export_const_iv (Button4Mask);
684     export_const_iv (Button5Mask);
685     export_const_iv (AnyModifier);
686 root 1.50
687     export_const_iv (EVENT_NONE);
688     export_const_iv (EVENT_READ);
689     export_const_iv (EVENT_WRITE);
690 root 1.1 }
691    
692     void
693     set_should_invoke (int htype, int value)
694     CODE:
695     rxvt_perl.should_invoke [htype] = value;
696    
697     void
698     warn (const char *msg)
699     CODE:
700     rxvt_warn ("%s", msg);
701    
702     void
703     fatal (const char *msg)
704     CODE:
705     rxvt_fatal ("%s", msg);
706    
707 root 1.45 SV *
708     untaint (SV *sv)
709     CODE:
710     RETVAL = newSVsv (sv);
711     SvTAINTED_off (RETVAL);
712     OUTPUT:
713     RETVAL
714    
715 root 1.47 bool
716     safe ()
717     CODE:
718     RETVAL = !rxvt_tainted ();
719     OUTPUT:
720     RETVAL
721    
722 root 1.3 NV
723     NOW ()
724     CODE:
725     RETVAL = NOW;
726     OUTPUT:
727     RETVAL
728    
729 root 1.11 int
730     GET_BASEFG (int rend)
731     CODE:
732     RETVAL = GET_BASEFG (rend);
733     OUTPUT:
734     RETVAL
735    
736     int
737     GET_BASEBG (int rend)
738     CODE:
739     RETVAL = GET_BASEBG (rend);
740     OUTPUT:
741     RETVAL
742    
743     int
744 root 1.12 SET_FGCOLOR (int rend, int new_color)
745 root 1.11 CODE:
746 root 1.12 RETVAL = SET_FGCOLOR (rend, new_color);
747 root 1.11 OUTPUT:
748     RETVAL
749    
750     int
751 root 1.12 SET_BGCOLOR (int rend, int new_color)
752 root 1.11 CODE:
753 root 1.12 RETVAL = SET_BGCOLOR (rend, new_color);
754     OUTPUT:
755     RETVAL
756    
757     int
758     GET_CUSTOM (int rend)
759     CODE:
760     RETVAL = (rend && RS_customMask) >> RS_customShift;
761     OUTPUT:
762     RETVAL
763    
764     int
765     SET_CUSTOM (int rend, int new_value)
766     CODE:
767     {
768     if (!IN_RANGE_EXC (new_value, 0, RS_customCount))
769     croak ("custom value out of range, must be 0..%d", RS_customCount - 1);
770    
771     RETVAL = (rend & ~RS_customMask)
772     | ((new_value << RS_customShift) & RS_customMask);
773     }
774 root 1.11 OUTPUT:
775     RETVAL
776    
777 root 1.3 MODULE = urxvt PACKAGE = urxvt::term
778    
779 root 1.54 SV *
780     _new (...)
781     CODE:
782     {
783     if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
784     croak ("first argument to urxvt::term->_new must be arrayref");
785    
786     rxvt_term *term = new rxvt_term;
787    
788     term->argv = new stringvec;
789     term->envv = new stringvec;
790    
791     for (int i = 1; i < items; i++)
792     term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
793    
794     AV *envv = (AV *)SvRV (ST (0));
795     for (int i = av_len (envv) + 1; i--; )
796     term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
797    
798     term->envv->push_back (0);
799    
800     bool success;
801    
802     try
803     {
804     success = term->init (term->argv->size (), term->argv->begin ());
805     }
806     catch (const class rxvt_failure_exception &e)
807     {
808     success = false;
809     }
810    
811     if (!success)
812     {
813     term->destroy ();
814     croak ("error while initializing new terminal instance");
815     }
816    
817     RETVAL = term && term->perl.self
818     ? newSVterm (term) : &PL_sv_undef;
819     }
820     OUTPUT:
821     RETVAL
822    
823 root 1.28 void
824     rxvt_term::destroy ()
825    
826 root 1.35 void
827 root 1.36 rxvt_term::grab_button (int button, U32 modifiers)
828     CODE:
829     XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
830     ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
831 root 1.41 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
832 root 1.36
833     bool
834     rxvt_term::grab (U32 eventtime, int sync = 0)
835 root 1.35 CODE:
836     {
837 root 1.36 int mode = sync ? GrabModeSync : GrabModeAsync;
838    
839     THIS->perl.grabtime = 0;
840    
841     if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
842     ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
843 root 1.41 mode, mode, None, GRAB_CURSOR, eventtime))
844 root 1.36 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
845     THIS->perl.grabtime = eventtime;
846     else
847     XUngrabPointer (THIS->display->display, eventtime);
848    
849     RETVAL = !!THIS->perl.grabtime;
850 root 1.35 }
851 root 1.36 OUTPUT:
852     RETVAL
853    
854     void
855 root 1.44 rxvt_term::allow_events_async ()
856 root 1.36 CODE:
857 root 1.44 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
858 root 1.36
859     void
860 root 1.44 rxvt_term::allow_events_sync ()
861 root 1.36 CODE:
862 root 1.44 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
863 root 1.36
864     void
865 root 1.44 rxvt_term::allow_events_replay ()
866 root 1.36 CODE:
867 root 1.44 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
868     XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
869 root 1.36
870     void
871 root 1.44 rxvt_term::ungrab ()
872 root 1.36 CODE:
873 root 1.45 ungrab (THIS);
874 root 1.35
875 root 1.1 int
876 root 1.3 rxvt_term::strwidth (SV *str)
877 root 1.1 CODE:
878     {
879     wchar_t *wstr = sv2wcs (str);
880 root 1.3
881     rxvt_push_locale (THIS->locale);
882 root 1.1 RETVAL = wcswidth (wstr, wcslen (wstr));
883 root 1.3 rxvt_pop_locale ();
884    
885 root 1.1 free (wstr);
886     }
887     OUTPUT:
888     RETVAL
889    
890 root 1.3 SV *
891     rxvt_term::locale_encode (SV *str)
892 root 1.1 CODE:
893 root 1.3 {
894     wchar_t *wstr = sv2wcs (str);
895    
896     rxvt_push_locale (THIS->locale);
897     char *mbstr = rxvt_wcstombs (wstr);
898     rxvt_pop_locale ();
899    
900     free (wstr);
901    
902 root 1.42 RETVAL = taint_if (newSVpv (mbstr, 0), str);
903 root 1.3 free (mbstr);
904     }
905     OUTPUT:
906 root 1.1 RETVAL
907    
908 root 1.3 SV *
909     rxvt_term::locale_decode (SV *octets)
910     CODE:
911     {
912     STRLEN len;
913     char *data = SvPVbyte (octets, len);
914    
915     rxvt_push_locale (THIS->locale);
916     wchar_t *wstr = rxvt_mbstowcs (data, len);
917     rxvt_pop_locale ();
918    
919 root 1.42 RETVAL = taint_if (wcs2sv (wstr), octets);
920 root 1.3 free (wstr);
921     }
922     OUTPUT:
923     RETVAL
924 root 1.1
925 root 1.38 #define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
926 root 1.24
927     #define TERM_OFFSET_width TERM_OFFSET(width)
928     #define TERM_OFFSET_height TERM_OFFSET(height)
929     #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
930     #define TERM_OFFSET_fheight TERM_OFFSET(fheight)
931     #define TERM_OFFSET_fbase TERM_OFFSET(fbase)
932     #define TERM_OFFSET_nrow TERM_OFFSET(nrow)
933     #define TERM_OFFSET_ncol TERM_OFFSET(ncol)
934     #define TERM_OFFSET_focus TERM_OFFSET(focus)
935     #define TERM_OFFSET_mapped TERM_OFFSET(mapped)
936     #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
937     #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
938     #define TERM_OFFSET_nsaved TERM_OFFSET(nsaved)
939    
940     int
941     rxvt_term::width ()
942     ALIAS:
943     width = TERM_OFFSET_width
944     height = TERM_OFFSET_height
945     fwidth = TERM_OFFSET_fwidth
946     fheight = TERM_OFFSET_fheight
947     fbase = TERM_OFFSET_fbase
948     nrow = TERM_OFFSET_nrow
949     ncol = TERM_OFFSET_ncol
950     focus = TERM_OFFSET_focus
951     mapped = TERM_OFFSET_mapped
952     saveLines = TERM_OFFSET_saveLines
953     total_rows = TERM_OFFSET_total_rows
954     nsaved = TERM_OFFSET_nsaved
955     CODE:
956     RETVAL = *(int *)((char *)THIS + ix);
957     OUTPUT:
958     RETVAL
959    
960 root 1.38 unsigned int
961     rxvt_term::ModLevel3Mask ()
962     ALIAS:
963     ModLevel3Mask = 0
964     ModMetaMask = 1
965     ModNumLockMask = 2
966     CODE:
967     switch (ix)
968     {
969     case 0: RETVAL = THIS->ModLevel3Mask; break;
970     case 1: RETVAL = THIS->ModMetaMask; break;
971     case 2: RETVAL = THIS->ModNumLockMask; break;
972     }
973     OUTPUT:
974     RETVAL
975    
976 root 1.48 char *
977     rxvt_term::display_id ()
978 root 1.49 ALIAS:
979     display_id = 0
980     locale = 1
981 root 1.48 CODE:
982 root 1.49 switch (ix)
983     {
984     case 0: RETVAL = THIS->display->id; break;
985     case 1: RETVAL = THIS->locale; break;
986     }
987 root 1.48 OUTPUT:
988     RETVAL
989    
990 root 1.54 SV *
991     rxvt_term::_env ()
992     CODE:
993     {
994     if (THIS->envv)
995     {
996     AV *av = newAV ();
997    
998     for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i)
999     if (*i)
1000     av_push (av, newSVpv (*i, 0));
1001    
1002     RETVAL = newRV_noinc ((SV *)av);
1003     }
1004     else
1005     RETVAL = &PL_sv_undef;
1006     }
1007     OUTPUT:
1008     RETVAL
1009    
1010 root 1.50 int
1011     rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1012     CODE:
1013     RETVAL = THIS->pty_ev.events;
1014     if (events != EVENT_UNDEF)
1015     THIS->pty_ev.set (events);
1016     OUTPUT:
1017     RETVAL
1018    
1019 root 1.24 U32
1020 root 1.31 rxvt_term::parent ()
1021     CODE:
1022     RETVAL = (U32)THIS->parent [0];
1023     OUTPUT:
1024     RETVAL
1025    
1026     U32
1027 root 1.30 rxvt_term::vt ()
1028     CODE:
1029 root 1.31 RETVAL = (U32)THIS->vt;
1030 root 1.30 OUTPUT:
1031     RETVAL
1032    
1033     U32
1034 root 1.25 rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
1035 root 1.7 CODE:
1036 root 1.24 {
1037 root 1.25 RETVAL = THIS->rstyle;
1038     THIS->rstyle = new_rstyle;
1039 root 1.24 }
1040 root 1.7 OUTPUT:
1041 root 1.24 RETVAL
1042 root 1.7
1043     int
1044     rxvt_term::view_start (int newval = -1)
1045     CODE:
1046     {
1047     RETVAL = THIS->view_start;
1048    
1049     if (newval >= 0)
1050     {
1051     THIS->view_start = min (newval, THIS->nsaved);
1052     THIS->scr_changeview (RETVAL);
1053     }
1054     }
1055     OUTPUT:
1056     RETVAL
1057    
1058 root 1.8 void
1059 root 1.9 rxvt_term::want_refresh ()
1060     CODE:
1061     THIS->want_refresh = 1;
1062    
1063     void
1064 root 1.27 rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1065 root 1.8 PPCODE:
1066     {
1067     if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
1068 root 1.19 XSRETURN_EMPTY;
1069 root 1.8
1070     line_t &l = ROW(row_number);
1071    
1072     if (GIMME_V != G_VOID)
1073     {
1074     wchar_t *wstr = new wchar_t [THIS->ncol];
1075    
1076 root 1.33 for (int col = 0; col < THIS->ncol; col++)
1077 root 1.8 wstr [col] = l.t [col];
1078    
1079 root 1.42 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
1080 root 1.8
1081 root 1.25 delete [] wstr;
1082 root 1.8 }
1083    
1084     if (new_text)
1085     {
1086 root 1.13 wchar_t *wstr = sv2wcs (new_text);
1087 root 1.8
1088 root 1.27 int len = min (wcslen (wstr) - start_ofs, max_len);
1089 root 1.8
1090 root 1.10 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
1091 root 1.8 {
1092     free (wstr);
1093 root 1.10 croak ("new_text extends beyond horizontal margins");
1094 root 1.8 }
1095    
1096     for (int col = start_col; col < start_col + len; col++)
1097     {
1098 root 1.27 l.t [col] = wstr [start_ofs + col - start_col];
1099 root 1.8 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
1100     }
1101 root 1.9
1102     free (wstr);
1103 root 1.8 }
1104     }
1105    
1106     void
1107 root 1.27 rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1108 root 1.8 PPCODE:
1109     {
1110     if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
1111 root 1.19 XSRETURN_EMPTY;
1112 root 1.8
1113     line_t &l = ROW(row_number);
1114    
1115     if (GIMME_V != G_VOID)
1116     {
1117     AV *av = newAV ();
1118    
1119     av_extend (av, THIS->ncol - 1);
1120     for (int col = 0; col < THIS->ncol; col++)
1121     av_store (av, col, newSViv (l.r [col]));
1122    
1123     XPUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
1124     }
1125    
1126     if (new_rend)
1127     {
1128     if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1129     croak ("new_rend must be arrayref");
1130    
1131     AV *av = (AV *)SvRV (new_rend);
1132 root 1.27 int len = min (av_len (av) + 1 - start_ofs, max_len);
1133 root 1.8
1134 root 1.10 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
1135     croak ("new_rend array extends beyond horizontal margins");
1136 root 1.8
1137     for (int col = start_col; col < start_col + len; col++)
1138     {
1139 root 1.27 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1140 root 1.8
1141     l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
1142     }
1143     }
1144     }
1145    
1146     int
1147 root 1.26 rxvt_term::ROW_l (int row_number, int new_length = -1)
1148 root 1.8 CODE:
1149     {
1150     if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
1151 root 1.19 XSRETURN_EMPTY;
1152 root 1.8
1153     line_t &l = ROW(row_number);
1154 root 1.26 RETVAL = l.l;
1155 root 1.8
1156 root 1.26 if (new_length >= 0)
1157 root 1.8 l.l = new_length;
1158     }
1159     OUTPUT:
1160     RETVAL
1161    
1162 root 1.19 bool
1163 root 1.26 rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
1164 root 1.19 CODE:
1165     {
1166     if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
1167     XSRETURN_EMPTY;
1168    
1169     line_t &l = ROW(row_number);
1170 root 1.26 RETVAL = l.is_longer ();
1171    
1172     if (new_is_longer >= 0)
1173     l.is_longer (new_is_longer);
1174 root 1.19 }
1175     OUTPUT:
1176     RETVAL
1177    
1178 root 1.8 SV *
1179 root 1.33 rxvt_term::special_encode (SV *string)
1180 root 1.8 CODE:
1181 root 1.33 {
1182     wchar_t *wstr = sv2wcs (string);
1183     int wlen = wcslen (wstr);
1184     wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1185    
1186     rxvt_push_locale (THIS->locale);
1187    
1188     wchar_t *r = rstr;
1189     for (wchar_t *s = wstr; *s; s++)
1190     if (wcwidth (*s) == 0)
1191     {
1192     if (r == rstr)
1193     croak ("leading combining character unencodable");
1194    
1195     unicode_t n = rxvt_compose (r[-1], *s);
1196     if (n == NOCHAR)
1197     n = rxvt_composite.compose (r[-1], *s);
1198    
1199     r[-1] = n;
1200     }
1201     #if !UNICODE_3
1202     else if (*s >= 0x10000)
1203     *r++ = rxvt_composite.compose (*s);
1204     #endif
1205     else
1206     *r++ = *s;
1207    
1208     rxvt_pop_locale ();
1209    
1210 root 1.42 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string);
1211 root 1.33
1212     delete [] rstr;
1213     }
1214     OUTPUT:
1215     RETVAL
1216 root 1.8
1217     SV *
1218 root 1.33 rxvt_term::special_decode (SV *text)
1219 root 1.8 CODE:
1220 root 1.33 {
1221     wchar_t *wstr = sv2wcs (text);
1222     int wlen = wcslen (wstr);
1223     int dlen = 0;
1224    
1225     // find length
1226     for (wchar_t *s = wstr; *s; s++)
1227     if (*s == NOCHAR)
1228     ;
1229     else if (IS_COMPOSE (*s))
1230     dlen += rxvt_composite.expand (*s, 0);
1231     else
1232     dlen++;
1233    
1234     wchar_t *rstr = new wchar_t [dlen];
1235    
1236     // decode
1237     wchar_t *r = rstr;
1238     for (wchar_t *s = wstr; *s; s++)
1239     if (*s == NOCHAR)
1240     ;
1241     else if (IS_COMPOSE (*s))
1242     r += rxvt_composite.expand (*s, r);
1243     else
1244     *r++ = *s;
1245    
1246 root 1.42 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text);
1247 root 1.33
1248     delete [] rstr;
1249     }
1250     OUTPUT:
1251     RETVAL
1252 root 1.8
1253 root 1.1 void
1254 root 1.2 rxvt_term::_resource (char *name, int index, SV *newval = 0)
1255     PPCODE:
1256     {
1257     struct resval { const char *name; int value; } rslist [] = {
1258 root 1.21 # define def(name) { # name, Rs_ ## name },
1259     # define reserve(name,count)
1260 root 1.2 # include "rsinc.h"
1261 root 1.21 # undef def
1262     # undef reserve
1263 root 1.2 };
1264    
1265     struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1266    
1267     do {
1268     if (rs-- == rslist)
1269     croak ("no such resource '%s', requested", name);
1270     } while (strcmp (name, rs->name));
1271    
1272     index += rs->value;
1273    
1274     if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1275     croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1276    
1277     if (GIMME_V != G_VOID)
1278 root 1.42 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef);
1279 root 1.2
1280     if (newval)
1281     {
1282     if (SvOK (newval))
1283     {
1284     char *str = strdup (SvPVbyte_nolen (newval));
1285     THIS->rs [index] = str;
1286     THIS->allocated.push_back (str);
1287     }
1288     else
1289     THIS->rs [index] = 0;
1290     }
1291     }
1292    
1293 root 1.55 const char *
1294     rxvt_term::x_resource (const char *name)
1295     CLEANUP:
1296     SvTAINTED_on (ST (0));
1297    
1298 root 1.40 bool
1299     rxvt_term::option (U32 optval, int set = -1)
1300     CODE:
1301     {
1302     RETVAL = THIS->options & optval;
1303    
1304     if (set >= 0)
1305     {
1306     if (set)
1307     THIS->options |= optval;
1308     else
1309     THIS->options &= ~optval;
1310    
1311     switch (optval)
1312     {
1313     case Opt_skipBuiltinGlyphs:
1314     THIS->set_fonts ();
1315     THIS->scr_remap_chars ();
1316     THIS->scr_touch (true);
1317     THIS->want_refresh = 1;
1318     break;
1319    
1320     case Opt_cursorUnderline:
1321     THIS->want_refresh = 1;
1322     break;
1323    
1324     # case Opt_scrollBar_floating:
1325     # case Opt_scrollBar_right:
1326     # THIS->resize_all_windows (THIS->width, THIS->height, 1);
1327     # break;
1328     }
1329     }
1330     }
1331     OUTPUT:
1332     RETVAL
1333    
1334 root 1.50 bool
1335     rxvt_term::parse_keysym (char *keysym, char *str)
1336     CODE:
1337     RETVAL = 0 < THIS->parse_keysym (keysym, str);
1338     THIS->keyboard->register_done ();
1339     OUTPUT:
1340     RETVAL
1341    
1342 root 1.2 void
1343 root 1.46 rxvt_term::screen_cur (...)
1344 root 1.1 PROTOTYPE: $;$$
1345     ALIAS:
1346 root 1.24 screen_cur = 0
1347     selection_beg = 1
1348     selection_end = 2
1349     selection_mark = 3
1350 root 1.1 PPCODE:
1351     {
1352 root 1.24 row_col_t &rc = ix == 0 ? THIS->screen.cur
1353     : ix == 1 ? THIS->selection.beg
1354     : ix == 2 ? THIS->selection.end
1355     : THIS->selection.mark;
1356 root 1.1
1357     if (GIMME_V != G_VOID)
1358     {
1359     EXTEND (SP, 2);
1360 root 1.24 PUSHs (sv_2mortal (newSViv (rc.row)));
1361     PUSHs (sv_2mortal (newSViv (rc.col)));
1362 root 1.1 }
1363    
1364     if (items == 3)
1365     {
1366 root 1.24 rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1);
1367     rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
1368 root 1.1
1369     if (ix)
1370     THIS->want_refresh = 1;
1371     }
1372     }
1373    
1374 root 1.53 char
1375     rxvt_term::cur_charset ()
1376     CODE:
1377     RETVAL = THIS->charsets [THIS->screen.charset];
1378     OUTPUT:
1379     RETVAL
1380    
1381 root 1.1 int
1382 root 1.36 rxvt_term::selection_grab (U32 eventtime)
1383 root 1.1
1384     void
1385     rxvt_term::selection (SV *newtext = 0)
1386     PPCODE:
1387     {
1388     if (GIMME_V != G_VOID)
1389 root 1.45 XPUSHs (THIS->selection.text
1390     ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
1391     : &PL_sv_undef);
1392 root 1.1
1393     if (newtext)
1394     {
1395     free (THIS->selection.text);
1396    
1397     THIS->selection.text = sv2wcs (newtext);
1398     THIS->selection.len = wcslen (THIS->selection.text);
1399     }
1400     }
1401 root 1.24
1402 root 1.1 void
1403 root 1.51 rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle1 = RS_RVid, U32 rstyle2 = RS_RVid | RS_Uline)
1404    
1405     void
1406     rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1407    
1408     void
1409 root 1.50 rxvt_term::scr_bell ()
1410    
1411     void
1412 root 1.25 rxvt_term::scr_add_lines (SV *string)
1413     CODE:
1414     {
1415     wchar_t *wstr = sv2wcs (string);
1416 root 1.32 THIS->scr_add_lines (wstr, wcslen (wstr));
1417 root 1.25 free (wstr);
1418     }
1419    
1420     void
1421 root 1.13 rxvt_term::tt_write (SV *octets)
1422     INIT:
1423     STRLEN len;
1424     char *str = SvPVbyte (octets, len);
1425     C_ARGS:
1426 root 1.23 str, len
1427 root 1.13
1428 root 1.28 void
1429     rxvt_term::cmd_parse (SV *octets)
1430     CODE:
1431     {
1432     STRLEN len;
1433     char *str = SvPVbyte (octets, len);
1434    
1435     char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1436     char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1437    
1438     THIS->cmdbuf_ptr = str;
1439     THIS->cmdbuf_endp = str + len;
1440    
1441 root 1.35 rxvt_push_locale (THIS->locale);
1442 root 1.28 THIS->cmd_parse ();
1443 root 1.35 rxvt_pop_locale ();
1444 root 1.28
1445     THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1446     THIS->cmdbuf_endp = old_cmdbuf_endp;
1447     }
1448    
1449 root 1.13 SV *
1450     rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
1451     CODE:
1452     {
1453     overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);
1454     RETVAL = newSVptr ((void *)o, "urxvt::overlay");
1455     o->self = (HV *)SvRV (RETVAL);
1456     }
1457     OUTPUT:
1458     RETVAL
1459    
1460     MODULE = urxvt PACKAGE = urxvt::overlay
1461 root 1.1
1462     void
1463 root 1.13 overlay::set (int x, int y, SV *text, SV *rend = 0)
1464 root 1.1
1465     void
1466 root 1.18 overlay::show ()
1467    
1468     void
1469     overlay::hide ()
1470    
1471     void
1472 root 1.13 overlay::DESTROY ()
1473 root 1.1
1474     MODULE = urxvt PACKAGE = urxvt::timer
1475    
1476     SV *
1477     timer::new ()
1478     CODE:
1479     timer *w = new timer;
1480 root 1.13 w->start (NOW);
1481 root 1.1 RETVAL = newSVptr ((void *)w, "urxvt::timer");
1482     w->self = (HV *)SvRV (RETVAL);
1483     OUTPUT:
1484     RETVAL
1485    
1486     timer *
1487     timer::cb (SV *cb)
1488     CODE:
1489     THIS->cb (cb);
1490     RETVAL = THIS;
1491     OUTPUT:
1492     RETVAL
1493    
1494     NV
1495     timer::at ()
1496     CODE:
1497     RETVAL = THIS->at;
1498     OUTPUT:
1499     RETVAL
1500    
1501     timer *
1502 root 1.13 timer::interval (NV interval)
1503     CODE:
1504     THIS->interval = interval;
1505     RETVAL = THIS;
1506     OUTPUT:
1507     RETVAL
1508    
1509     timer *
1510 root 1.1 timer::set (NV tstamp)
1511     CODE:
1512     THIS->set (tstamp);
1513     RETVAL = THIS;
1514     OUTPUT:
1515     RETVAL
1516    
1517     timer *
1518     timer::start (NV tstamp = THIS->at)
1519     CODE:
1520     THIS->start (tstamp);
1521     RETVAL = THIS;
1522     OUTPUT:
1523     RETVAL
1524    
1525     timer *
1526     timer::stop ()
1527     CODE:
1528     THIS->stop ();
1529     RETVAL = THIS;
1530     OUTPUT:
1531     RETVAL
1532    
1533     void
1534     timer::DESTROY ()
1535    
1536     MODULE = urxvt PACKAGE = urxvt::iow
1537    
1538     SV *
1539     iow::new ()
1540     CODE:
1541     iow *w = new iow;
1542     RETVAL = newSVptr ((void *)w, "urxvt::iow");
1543     w->self = (HV *)SvRV (RETVAL);
1544     OUTPUT:
1545     RETVAL
1546    
1547     iow *
1548     iow::cb (SV *cb)
1549     CODE:
1550     THIS->cb (cb);
1551     RETVAL = THIS;
1552     OUTPUT:
1553     RETVAL
1554    
1555     iow *
1556     iow::fd (int fd)
1557     CODE:
1558     THIS->fd = fd;
1559     RETVAL = THIS;
1560     OUTPUT:
1561     RETVAL
1562    
1563     iow *
1564     iow::events (short events)
1565     CODE:
1566     THIS->events = events;
1567     RETVAL = THIS;
1568     OUTPUT:
1569     RETVAL
1570    
1571     iow *
1572     iow::start ()
1573     CODE:
1574     THIS->start ();
1575     RETVAL = THIS;
1576     OUTPUT:
1577     RETVAL
1578    
1579     iow *
1580     iow::stop ()
1581     CODE:
1582     THIS->stop ();
1583     RETVAL = THIS;
1584     OUTPUT:
1585     RETVAL
1586    
1587     void
1588     iow::DESTROY ()
1589    
1590