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

File Contents

# Content
1 /*----------------------------------------------------------------------*
2 * File: rxvtperl.xs
3 *----------------------------------------------------------------------*
4 *
5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2005 Marc Lehmann <pcg@goof.com>
7 *
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 #include <cstdarg>
32
33 #include "rxvt.h"
34 #include "iom.h"
35 #include "rxvtutil.h"
36 #include "rxvtperl.h"
37
38 #include "perlxsi.c"
39
40 #undef LINENO
41 #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
42 #undef ROW
43 #define ROW(n) THIS->row_buf [LINENO (n)]
44
45 /////////////////////////////////////////////////////////////////////////////
46
47 static wchar_t *
48 sv2wcs (SV *sv)
49 {
50 STRLEN len;
51 char *str = SvPVutf8 (sv, len);
52 return rxvt_utf8towcs (str, len);
53 }
54
55 static SV *
56 new_ref (HV *hv, const char *klass)
57 {
58 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
59 }
60
61 //TODO: use magic
62 static SV *
63 newSVptr (void *ptr, const char *klass)
64 {
65 HV *hv = newHV ();
66 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
67 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
68 }
69
70 static void
71 clearSVptr (SV *sv)
72 {
73 if (SvROK (sv))
74 sv = SvRV (sv);
75
76 hv_clear ((HV *)sv);
77 sv_unmagic (sv, PERL_MAGIC_ext);
78 }
79
80 static long
81 SvPTR (SV *sv, const char *klass)
82 {
83 if (!sv_derived_from (sv, klass))
84 croak ("object of type %s expected", klass);
85
86 MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
87
88 if (!mg)
89 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
90
91 return (long)mg->mg_ptr;
92 }
93
94 #define newSVterm(term) SvREFCNT_inc ((SV *)term->self)
95 #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
96
97 /////////////////////////////////////////////////////////////////////////////
98
99 struct perl_watcher
100 {
101 SV *cbsv;
102 HV *self;
103
104 perl_watcher ()
105 : cbsv (newSV (0))
106 {
107 }
108
109 ~perl_watcher ()
110 {
111 SvREFCNT_dec (cbsv);
112 }
113
114 void cb (SV *cb)
115 {
116 sv_setsv (cbsv, cb);
117 }
118
119 void invoke (const char *type, SV *self, int arg = -1);
120 };
121
122 void
123 perl_watcher::invoke (const char *type, SV *self, int arg)
124 {
125 dSP;
126
127 ENTER;
128 SAVETMPS;
129
130 PUSHMARK (SP);
131
132 XPUSHs (sv_2mortal (self));
133
134 if (arg >= 0)
135 XPUSHs (sv_2mortal (newSViv (arg)));
136
137 PUTBACK;
138 call_sv (cbsv, G_VOID | G_EVAL | G_DISCARD);
139 SPAGAIN;
140
141 PUTBACK;
142 FREETMPS;
143 LEAVE;
144
145 if (SvTRUE (ERRSV))
146 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
147 }
148
149 #define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
150 #define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer")
151
152 struct timer : time_watcher, perl_watcher
153 {
154 tstamp interval;
155
156 timer ()
157 : time_watcher (this, &timer::execute)
158 {
159 }
160
161 void execute (time_watcher &w)
162 {
163 if (interval)
164 start (at + interval);
165
166 invoke ("urxvt::timer", newSVtimer (this));
167 }
168 };
169
170 #define newSViow(iow) new_ref (iow->self, "urxvt::iow")
171 #define SvIOW(sv) (iow *)SvPTR (sv, "urxvt::iow")
172
173 struct iow : io_watcher, perl_watcher
174 {
175 iow ()
176 : io_watcher (this, &iow::execute)
177 {
178 }
179
180 void execute (io_watcher &w, short revents)
181 {
182 invoke ("urxvt::iow", newSViow (this), revents);
183 }
184 };
185
186 /////////////////////////////////////////////////////////////////////////////
187
188 #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
189
190 struct overlay {
191 HV *self;
192 rxvt_term *THIS;
193 int x, y, w, h;
194 int border;
195 text_t **text;
196 rend_t **rend;
197
198 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
199 ~overlay ();
200
201 void show ();
202 void hide ();
203
204 void swap ();
205
206 void set (int x, int y, SV *str, SV *rend);
207 };
208
209 overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
210 : THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2)
211 {
212 if (border == 2)
213 {
214 w += 2;
215 h += 2;
216 }
217
218 text = new text_t *[h];
219 rend = new rend_t *[h];
220
221 for (int y = 0; y < h; y++)
222 {
223 text_t *tp = text[y] = new text_t[w];
224 rend_t *rp = rend[y] = new rend_t[w];
225
226 text_t t0, t1, t2;
227 rend_t r = rstyle;
228
229 if (border == 2)
230 {
231 if (y == 0)
232 t0 = 0x2554, t1 = 0x2550, t2 = 0x2557;
233 else if (y < h - 1)
234 t0 = 0x2551, t1 = 0x0020, t2 = 0x2551;
235 else
236 t0 = 0x255a, t1 = 0x2550, t2 = 0x255d;
237
238 *tp++ = t0;
239 *rp++ = r;
240
241 for (int x = w - 2; x-- > 0; )
242 {
243 *tp++ = t1;
244 *rp++ = r;
245 }
246
247 *tp = t2;
248 *rp = r;
249 }
250 else
251 for (int x = w; x-- > 0; )
252 {
253 *tp++ = 0x0020;
254 *rp++ = r;
255 }
256 }
257
258 show ();
259 THIS->want_refresh = 1;
260 }
261
262 overlay::~overlay ()
263 {
264 hide ();
265
266 for (int y = h; y--; )
267 {
268 delete [] text[y];
269 delete [] rend[y];
270 }
271
272 delete [] text;
273 delete [] rend;
274
275 THIS->want_refresh = 1;
276 }
277
278 void
279 overlay::show ()
280 {
281 char key[33]; sprintf (key, "%32lx", (long)this);
282
283 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0));
284 hv_store (hv, key, 32, newSViv ((long)this), 0);
285 }
286
287 void
288 overlay::hide ()
289 {
290 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0);
291
292 if (ovs)
293 {
294 char key[33]; sprintf (key, "%32lx", (long)this);
295
296 HV *hv = (HV *)SvRV (*ovs);
297 hv_delete (hv, key, 32, G_DISCARD);
298 }
299 }
300
301 void overlay::swap ()
302 {
303 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
304 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
305
306 int ov_w = min (w, THIS->ncol - ov_x);
307 int ov_h = min (h, THIS->nrow - ov_y);
308
309 for (int y = ov_h; y--; )
310 {
311 text_t *t1 = text [y];
312 rend_t *r1 = rend [y];
313
314 text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x;
315 rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x;
316
317 for (int x = ov_w; x--; )
318 {
319 text_t t = *t1; *t1++ = *t2; *t2++ = t;
320 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t));
321 }
322 }
323
324 }
325
326 void overlay::set (int x, int y, SV *text, SV *rend)
327 {
328 x += border;
329 y += border;
330
331 if (!IN_RANGE_EXC (y, 0, h - border))
332 return;
333
334 wchar_t *wtext = sv2wcs (text);
335
336 for (int col = min (wcslen (wtext), w - x - border); col--; )
337 this->text [y][x + col] = wtext [col];
338
339 free (wtext);
340
341 if (rend)
342 {
343 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
344 croak ("rend must be arrayref");
345
346 AV *av = (AV *)SvRV (rend);
347
348 for (int col = min (av_len (av) + 1, w - x - border); col--; )
349 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
350 }
351
352 THIS->want_refresh = 1;
353 }
354
355
356 /////////////////////////////////////////////////////////////////////////////
357
358 struct rxvt_perl_interp rxvt_perl;
359
360 static PerlInterpreter *perl;
361
362 rxvt_perl_interp::rxvt_perl_interp ()
363 {
364 }
365
366 rxvt_perl_interp::~rxvt_perl_interp ()
367 {
368 if (perl)
369 {
370 perl_destruct (perl);
371 perl_free (perl);
372 }
373 }
374
375 void
376 rxvt_perl_interp::init ()
377 {
378 if (!perl)
379 {
380 char *argv[] = {
381 "",
382 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
383 };
384
385 perl = perl_alloc ();
386 perl_construct (perl);
387
388 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL)
389 || perl_run (perl))
390 {
391 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
392
393 perl_destruct (perl);
394 perl_free (perl);
395 perl = 0;
396 }
397 }
398 }
399
400 bool
401 rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
402 {
403 if (!perl)
404 return false;
405
406 if (htype == HOOK_INIT) // first hook ever called
407 {
408 term->self = (void *)newSVptr ((void *)term, "urxvt::term");
409 hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
410 }
411 else if (!term->self)
412 return false; // perl not initialized for this instance
413 else if (htype == HOOK_DESTROY)
414 {
415 // handled later
416 }
417 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
418 {
419 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0));
420
421 if (HvKEYS (hv))
422 {
423 hv_iterinit (hv);
424
425 while (HE *he = hv_iternext (hv))
426 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
427 }
428 }
429 else if (!should_invoke [htype])
430 return false;
431
432 dSP;
433 va_list ap;
434
435 va_start (ap, htype);
436
437 ENTER;
438 SAVETMPS;
439
440 PUSHMARK (SP);
441
442 XPUSHs (sv_2mortal (newSVterm (term)));
443 XPUSHs (sv_2mortal (newSViv (htype)));
444
445 for (;;) {
446 data_type dt = (data_type)va_arg (ap, int);
447
448 switch (dt)
449 {
450 case DT_INT:
451 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
452 break;
453
454 case DT_LONG:
455 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
456 break;
457
458 case DT_STRING:
459 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
460 break;
461
462 case DT_END:
463 {
464 va_end (ap);
465
466 PUTBACK;
467 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
468 SPAGAIN;
469
470 if (count)
471 {
472 SV *status = POPs;
473 count = SvTRUE (status);
474 }
475
476 PUTBACK;
477 FREETMPS;
478 LEAVE;
479
480 if (SvTRUE (ERRSV))
481 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
482
483 if (htype == HOOK_DESTROY)
484 {
485 clearSVptr ((SV *)term->self);
486 SvREFCNT_dec ((SV *)term->self);
487 }
488
489 return count;
490 }
491
492 default:
493 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
494 }
495 }
496 }
497
498 /////////////////////////////////////////////////////////////////////////////
499
500 MODULE = urxvt PACKAGE = urxvt
501
502 PROTOTYPES: ENABLE
503
504 BOOT:
505 {
506 # define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0))
507 # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), #name, newSViv (name));
508 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
509 set_hookname (INIT);
510 set_hookname (RESET);
511 set_hookname (START);
512 set_hookname (DESTROY);
513 set_hookname (SEL_BEGIN);
514 set_hookname (SEL_EXTEND);
515 set_hookname (SEL_MAKE);
516 set_hookname (SEL_GRAB);
517 set_hookname (FOCUS_IN);
518 set_hookname (FOCUS_OUT);
519 set_hookname (VIEW_CHANGE);
520 set_hookname (SCROLL_BACK);
521 set_hookname (TTY_ACTIVITY);
522 set_hookname (OSC_SEQ);
523 set_hookname (REFRESH_BEGIN);
524 set_hookname (REFRESH_END);
525 set_hookname (KEYBOARD_COMMAND);
526
527 export_const (DEFAULT_RSTYLE);
528 export_const (OVERLAY_RSTYLE);
529 export_const (RS_Bold);
530 export_const (RS_Italic);
531 export_const (RS_Blink);
532 export_const (RS_RVid);
533 export_const (RS_Uline);
534
535 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR);
536 }
537
538 void
539 set_should_invoke (int htype, int value)
540 CODE:
541 rxvt_perl.should_invoke [htype] = value;
542
543 void
544 warn (const char *msg)
545 CODE:
546 rxvt_warn ("%s", msg);
547
548 void
549 fatal (const char *msg)
550 CODE:
551 rxvt_fatal ("%s", msg);
552
553 NV
554 NOW ()
555 CODE:
556 RETVAL = NOW;
557 OUTPUT:
558 RETVAL
559
560 int
561 GET_BASEFG (int rend)
562 CODE:
563 RETVAL = GET_BASEFG (rend);
564 OUTPUT:
565 RETVAL
566
567 int
568 GET_BASEBG (int rend)
569 CODE:
570 RETVAL = GET_BASEBG (rend);
571 OUTPUT:
572 RETVAL
573
574 int
575 SET_FGCOLOR (int rend, int new_color)
576 CODE:
577 RETVAL = SET_FGCOLOR (rend, new_color);
578 OUTPUT:
579 RETVAL
580
581 int
582 SET_BGCOLOR (int rend, int new_color)
583 CODE:
584 RETVAL = SET_BGCOLOR (rend, new_color);
585 OUTPUT:
586 RETVAL
587
588 int
589 GET_CUSTOM (int rend)
590 CODE:
591 RETVAL = (rend && RS_customMask) >> RS_customShift;
592 OUTPUT:
593 RETVAL
594
595 int
596 SET_CUSTOM (int rend, int new_value)
597 CODE:
598 {
599 if (!IN_RANGE_EXC (new_value, 0, RS_customCount))
600 croak ("custom value out of range, must be 0..%d", RS_customCount - 1);
601
602 RETVAL = (rend & ~RS_customMask)
603 | ((new_value << RS_customShift) & RS_customMask);
604 }
605 OUTPUT:
606 RETVAL
607
608 MODULE = urxvt PACKAGE = urxvt::term
609
610 int
611 rxvt_term::strwidth (SV *str)
612 CODE:
613 {
614 wchar_t *wstr = sv2wcs (str);
615
616 rxvt_push_locale (THIS->locale);
617 RETVAL = wcswidth (wstr, wcslen (wstr));
618 rxvt_pop_locale ();
619
620 free (wstr);
621 }
622 OUTPUT:
623 RETVAL
624
625 SV *
626 rxvt_term::locale_encode (SV *str)
627 CODE:
628 {
629 wchar_t *wstr = sv2wcs (str);
630
631 rxvt_push_locale (THIS->locale);
632 char *mbstr = rxvt_wcstombs (wstr);
633 rxvt_pop_locale ();
634
635 free (wstr);
636
637 RETVAL = newSVpv (mbstr, 0);
638 free (mbstr);
639 }
640 OUTPUT:
641 RETVAL
642
643 SV *
644 rxvt_term::locale_decode (SV *octets)
645 CODE:
646 {
647 STRLEN len;
648 char *data = SvPVbyte (octets, len);
649
650 rxvt_push_locale (THIS->locale);
651 wchar_t *wstr = rxvt_mbstowcs (data, len);
652 rxvt_pop_locale ();
653
654 char *str = rxvt_wcstoutf8 (wstr);
655 free (wstr);
656
657 RETVAL = newSVpv (str, 0);
658 SvUTF8_on (RETVAL);
659 free (str);
660 }
661 OUTPUT:
662 RETVAL
663
664 int
665 rxvt_term::nsaved ()
666 CODE:
667 RETVAL = THIS->nsaved;
668 OUTPUT:
669 RETVAL
670
671 int
672 rxvt_term::view_start (int newval = -1)
673 CODE:
674 {
675 RETVAL = THIS->view_start;
676
677 if (newval >= 0)
678 {
679 THIS->view_start = min (newval, THIS->nsaved);
680 THIS->scr_changeview (RETVAL);
681 }
682 }
683 OUTPUT:
684 RETVAL
685
686 int
687 rxvt_term::nrow ()
688 CODE:
689 RETVAL = THIS->nrow;
690 OUTPUT:
691 RETVAL
692
693 int
694 rxvt_term::ncol ()
695 CODE:
696 RETVAL = THIS->ncol;
697 OUTPUT:
698 RETVAL
699
700 void
701 rxvt_term::want_refresh ()
702 CODE:
703 THIS->want_refresh = 1;
704
705 void
706 rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0)
707 PPCODE:
708 {
709 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
710 XSRETURN_EMPTY;
711
712 line_t &l = ROW(row_number);
713
714 if (GIMME_V != G_VOID)
715 {
716 wchar_t *wstr = new wchar_t [THIS->ncol];
717
718 for (int col = 0; col <THIS->ncol; col++)
719 wstr [col] = l.t [col];
720
721 char *str = rxvt_wcstoutf8 (wstr, THIS->ncol);
722 free (wstr);
723
724 SV *sv = newSVpv (str, 0);
725 SvUTF8_on (sv);
726 XPUSHs (sv_2mortal (sv));
727 free (str);
728 }
729
730 if (new_text)
731 {
732 wchar_t *wstr = sv2wcs (new_text);
733
734 int len = wcslen (wstr);
735
736 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
737 {
738 free (wstr);
739 croak ("new_text extends beyond horizontal margins");
740 }
741
742 for (int col = start_col; col < start_col + len; col++)
743 {
744 l.t [col] = wstr [col - start_col];
745 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
746 }
747
748 free (wstr);
749 }
750 }
751
752 void
753 rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0)
754 PPCODE:
755 {
756 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
757 XSRETURN_EMPTY;
758
759 line_t &l = ROW(row_number);
760
761 if (GIMME_V != G_VOID)
762 {
763 AV *av = newAV ();
764
765 av_extend (av, THIS->ncol - 1);
766 for (int col = 0; col < THIS->ncol; col++)
767 av_store (av, col, newSViv (l.r [col]));
768
769 XPUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
770 }
771
772 if (new_rend)
773 {
774 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
775 croak ("new_rend must be arrayref");
776
777 AV *av = (AV *)SvRV (new_rend);
778 int len = av_len (av) + 1;
779
780 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
781 croak ("new_rend array extends beyond horizontal margins");
782
783 for (int col = start_col; col < start_col + len; col++)
784 {
785 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask;
786
787 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
788 }
789 }
790 }
791
792 int
793 rxvt_term::ROW_l (int row_number, int new_length = -2)
794 CODE:
795 {
796 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
797 XSRETURN_EMPTY;
798
799 line_t &l = ROW(row_number);
800 RETVAL = l.l < 0 ? THIS->ncol : l.l;
801
802 if (new_length >= -1)
803 l.l = new_length;
804 }
805 OUTPUT:
806 RETVAL
807
808 bool
809 rxvt_term::ROW_is_longer (int row_number)
810 CODE:
811 {
812 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
813 XSRETURN_EMPTY;
814
815 line_t &l = ROW(row_number);
816 RETVAL = l.l < 0;
817 }
818 OUTPUT:
819 RETVAL
820
821 SV *
822 rxvt_term::special_encode (SV *str)
823 CODE:
824 abort ();//TODO
825
826 SV *
827 rxvt_term::special_decode (SV *str)
828 CODE:
829 abort ();//TODO
830
831 void
832 rxvt_term::_resource (char *name, int index, SV *newval = 0)
833 PPCODE:
834 {
835 struct resval { const char *name; int value; } rslist [] = {
836 # define Rs_def(name) { # name, Rs_ ## name },
837 # define Rs_reserve(name,count)
838 # include "rsinc.h"
839 # undef Rs_def
840 # undef Rs_reserve
841 };
842
843 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
844
845 do {
846 if (rs-- == rslist)
847 croak ("no such resource '%s', requested", name);
848 } while (strcmp (name, rs->name));
849
850 index += rs->value;
851
852 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
853 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
854
855 if (GIMME_V != G_VOID)
856 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef);
857
858 if (newval)
859 {
860 if (SvOK (newval))
861 {
862 char *str = strdup (SvPVbyte_nolen (newval));
863 THIS->rs [index] = str;
864 THIS->allocated.push_back (str);
865 }
866 else
867 THIS->rs [index] = 0;
868 }
869 }
870
871 void
872 rxvt_term::selection_mark (...)
873 PROTOTYPE: $;$$
874 ALIAS:
875 selection_beg = 1
876 selection_end = 2
877 PPCODE:
878 {
879 row_col_t &sel = ix == 1 ? THIS->selection.beg
880 : ix == 2 ? THIS->selection.end
881 : THIS->selection.mark;
882
883 if (GIMME_V != G_VOID)
884 {
885 EXTEND (SP, 2);
886 PUSHs (sv_2mortal (newSViv (sel.row)));
887 PUSHs (sv_2mortal (newSViv (sel.col)));
888 }
889
890 if (items == 3)
891 {
892 sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1);
893 sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
894
895 if (ix)
896 THIS->want_refresh = 1;
897 }
898 }
899
900 int
901 rxvt_term::selection_grab (int eventtime = CurrentTime)
902
903 void
904 rxvt_term::selection (SV *newtext = 0)
905 PPCODE:
906 {
907 if (GIMME_V != G_VOID)
908 {
909 char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len);
910 SV *sv = newSVpv (sel, 0);
911 SvUTF8_on (sv);
912 free (sel);
913 XPUSHs (sv_2mortal (sv));
914 }
915
916 if (newtext)
917 {
918 free (THIS->selection.text);
919
920 THIS->selection.text = sv2wcs (newtext);
921 THIS->selection.len = wcslen (THIS->selection.text);
922 }
923 }
924
925 void
926 rxvt_term::tt_write (SV *octets)
927 INIT:
928 STRLEN len;
929 char *str = SvPVbyte (octets, len);
930 C_ARGS:
931 (unsigned char *)str, len
932
933 SV *
934 rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
935 CODE:
936 {
937 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);
938 RETVAL = newSVptr ((void *)o, "urxvt::overlay");
939 o->self = (HV *)SvRV (RETVAL);
940 }
941 OUTPUT:
942 RETVAL
943
944 MODULE = urxvt PACKAGE = urxvt::overlay
945
946 void
947 overlay::set (int x, int y, SV *text, SV *rend = 0)
948
949 void
950 overlay::show ()
951
952 void
953 overlay::hide ()
954
955 void
956 overlay::DESTROY ()
957
958 MODULE = urxvt PACKAGE = urxvt::timer
959
960 SV *
961 timer::new ()
962 CODE:
963 timer *w = new timer;
964 w->start (NOW);
965 RETVAL = newSVptr ((void *)w, "urxvt::timer");
966 w->self = (HV *)SvRV (RETVAL);
967 OUTPUT:
968 RETVAL
969
970 timer *
971 timer::cb (SV *cb)
972 CODE:
973 THIS->cb (cb);
974 RETVAL = THIS;
975 OUTPUT:
976 RETVAL
977
978 NV
979 timer::at ()
980 CODE:
981 RETVAL = THIS->at;
982 OUTPUT:
983 RETVAL
984
985 timer *
986 timer::interval (NV interval)
987 CODE:
988 THIS->interval = interval;
989 RETVAL = THIS;
990 OUTPUT:
991 RETVAL
992
993 timer *
994 timer::set (NV tstamp)
995 CODE:
996 THIS->set (tstamp);
997 RETVAL = THIS;
998 OUTPUT:
999 RETVAL
1000
1001 timer *
1002 timer::start (NV tstamp = THIS->at)
1003 CODE:
1004 THIS->start (tstamp);
1005 RETVAL = THIS;
1006 OUTPUT:
1007 RETVAL
1008
1009 timer *
1010 timer::stop ()
1011 CODE:
1012 THIS->stop ();
1013 RETVAL = THIS;
1014 OUTPUT:
1015 RETVAL
1016
1017 void
1018 timer::DESTROY ()
1019
1020 MODULE = urxvt PACKAGE = urxvt::iow
1021
1022 SV *
1023 iow::new ()
1024 CODE:
1025 iow *w = new iow;
1026 RETVAL = newSVptr ((void *)w, "urxvt::iow");
1027 w->self = (HV *)SvRV (RETVAL);
1028 OUTPUT:
1029 RETVAL
1030
1031 iow *
1032 iow::cb (SV *cb)
1033 CODE:
1034 THIS->cb (cb);
1035 RETVAL = THIS;
1036 OUTPUT:
1037 RETVAL
1038
1039 iow *
1040 iow::fd (int fd)
1041 CODE:
1042 THIS->fd = fd;
1043 RETVAL = THIS;
1044 OUTPUT:
1045 RETVAL
1046
1047 iow *
1048 iow::events (short events)
1049 CODE:
1050 THIS->events = events;
1051 RETVAL = THIS;
1052 OUTPUT:
1053 RETVAL
1054
1055 iow *
1056 iow::start ()
1057 CODE:
1058 THIS->start ();
1059 RETVAL = THIS;
1060 OUTPUT:
1061 RETVAL
1062
1063 iow *
1064 iow::stop ()
1065 CODE:
1066 THIS->stop ();
1067 RETVAL = THIS;
1068 OUTPUT:
1069 RETVAL
1070
1071 void
1072 iow::DESTROY ()
1073
1074