ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtperl.xs
(Generate patch)

Comparing rxvt-unicode/src/rxvtperl.xs (file contents):
Revision 1.5 by root, Mon Jan 2 20:35:39 2006 UTC vs.
Revision 1.67 by root, Sun Jan 15 06:02:41 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines