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