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