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.17 by root, Tue Jan 3 18:11:34 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"
43
44#if defined(HAVE_SCROLLBARS) || defined(MENUBAR)
45# define GRAB_CURSOR THIS->leftptr_cursor
46#else
47# define GRAB_CURSOR None
48#endif
39 49
40#undef LINENO 50#undef LINENO
41#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
42#undef ROW 52#undef ROW
43#define ROW(n) THIS->row_buf [LINENO (n)] 53#define ROW(n) THIS->row_buf [LINENO (n)]
44 54
55#define ENABLE_PERL_FRILLS 1
56
45///////////////////////////////////////////////////////////////////////////// 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}
46 74
47static wchar_t * 75static wchar_t *
48sv2wcs (SV *sv) 76sv2wcs (SV *sv)
49{ 77{
50 STRLEN len; 78 STRLEN len;
51 char *str = SvPVutf8 (sv, len); 79 char *str = SvPVutf8 (sv, len);
52 return rxvt_utf8towcs (str, len); 80 return rxvt_utf8towcs (str, len);
53} 81}
54 82
55static 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 *
56new_ref (HV *hv, const char *klass) 96new_ref (HV *hv, const char *klass)
57{ 97{
58 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 98 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
59} 99}
60 100
61//TODO: use magic 101//TODO: use magic
62static SV * 102static SV *
63newSVptr (void *ptr, const char *klass) 103newSVptr (void *ptr, const char *klass)
64{ 104{
65 HV *hv = newHV (); 105 HV *hv = newHV ();
66 hv_store (hv, "_ptr", 4, newSViv ((long)ptr), 0); 106 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
67 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);
68} 118}
69 119
70static long 120static long
71SvPTR (SV *sv, const char *klass) 121SvPTR (SV *sv, const char *klass)
72{ 122{
73 if (!sv_derived_from (sv, klass)) 123 if (!sv_derived_from (sv, klass))
74 croak ("object of type %s expected", klass); 124 croak ("object of type %s expected", klass);
75 125
76 IV iv = SvIV (*hv_fetch ((HV *)SvRV (sv), "_ptr", 4, 1)); 126 MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
77 127
78 if (!iv) 128 if (!mg)
79 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);
80 130
81 return (long)iv; 131 return (long)mg->mg_ptr;
82} 132}
83 133
84#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) 134#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
85#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 135#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
86 136
87///////////////////////////////////////////////////////////////////////////// 137/////////////////////////////////////////////////////////////////////////////
88 138
89struct perl_watcher 139struct perl_watcher
186 rend_t **rend; 236 rend_t **rend;
187 237
188 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); 238 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
189 ~overlay (); 239 ~overlay ();
190 240
241 void show ();
242 void hide ();
243
191 void swap (); 244 void swap ();
192 245
193 void set (int x, int y, SV *str, SV *rend); 246 void set (int x, int y, SV *str, SV *rend);
194}; 247};
195 248
202 h += 2; 255 h += 2;
203 } 256 }
204 257
205 text = new text_t *[h]; 258 text = new text_t *[h];
206 rend = new rend_t *[h]; 259 rend = new rend_t *[h];
207 260
208 for (int y = 0; y < h; y++) 261 for (int y = 0; y < h; y++)
209 { 262 {
210 text_t *tp = text[y] = new text_t[w]; 263 text_t *tp = text[y] = new text_t[w];
211 rend_t *rp = rend[y] = new rend_t[w]; 264 rend_t *rp = rend[y] = new rend_t[w];
212 265
213 text_t t0, t1, t2; 266 text_t t0, t1, t2;
214 rend_t r = rstyle; 267 rend_t r = rstyle;
215 268
216 if (border == 2) 269 if (border == 2)
217 { 270 {
218 if (y == 0) 271 if (y == 0)
219 t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; 272 t0 = 0x2554, t1 = 0x2550, t2 = 0x2557;
220 else if (y < h - 1) 273 else if (y < h - 1)
221 t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; 274 t0 = 0x2551, t1 = 0x0020, t2 = 0x2551;
222 else 275 else
223 t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; 276 t0 = 0x255a, t1 = 0x2550, t2 = 0x255d;
224 277
225 *tp++ = t0; 278 *tp++ = t0;
226 *rp++ = r; 279 *rp++ = r;
227 280
228 for (int x = w - 2; x-- > 0; ) 281 for (int x = w - 2; x-- > 0; )
229 { 282 {
230 *tp++ = t1; 283 *tp++ = t1;
231 *rp++ = r; 284 *rp++ = r;
232 } 285 }
233 286
234 *tp = t2; 287 *tp = t2;
235 *rp = r; 288 *rp = r;
236 } 289 }
237 else 290 else
238 for (int x = w; x-- > 0; ) 291 for (int x = w; x-- > 0; )
239 { 292 {
240 *tp++ = 0x0020; 293 *tp++ = 0x0020;
241 *rp++ = r; 294 *rp++ = r;
242 } 295 }
243 } 296 }
244 297
298 show ();
245 THIS->want_refresh = 1; 299 THIS->want_refresh = 1;
246} 300}
247 301
248overlay::~overlay () 302overlay::~overlay ()
249{ 303{
304 hide ();
305
250 for (int y = h; y--; ) 306 for (int y = h; y--; )
251 { 307 {
252 delete [] text[y]; 308 delete [] text[y];
253 delete [] rend[y]; 309 delete [] rend[y];
254 } 310 }
257 delete [] rend; 313 delete [] rend;
258 314
259 THIS->want_refresh = 1; 315 THIS->want_refresh = 1;
260} 316}
261 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
262void overlay::swap () 341void overlay::swap ()
263{ 342{
264 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 343 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)); 344 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
266 345
269 348
270 for (int y = ov_h; y--; ) 349 for (int y = ov_h; y--; )
271 { 350 {
272 text_t *t1 = text [y]; 351 text_t *t1 = text [y];
273 rend_t *r1 = rend [y]; 352 rend_t *r1 = rend [y];
274 353
275 text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; 354 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; 355 rend_t *r2 = ROW(y + ov_y + THIS->view_start).r + ov_x;
277 356
278 for (int x = ov_w; x--; ) 357 for (int x = ov_w; x--; )
279 { 358 {
280 text_t t = *t1; *t1++ = *t2; *t2++ = t; 359 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)); 360 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t));
282 } 361 }
283 } 362 }
284 363
294 373
295 wchar_t *wtext = sv2wcs (text); 374 wchar_t *wtext = sv2wcs (text);
296 375
297 for (int col = min (wcslen (wtext), w - x - border); col--; ) 376 for (int col = min (wcslen (wtext), w - x - border); col--; )
298 this->text [y][x + col] = wtext [col]; 377 this->text [y][x + col] = wtext [col];
299 378
300 free (wtext); 379 free (wtext);
301 380
302 if (rend) 381 if (rend)
303 { 382 {
304 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) 383 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
317///////////////////////////////////////////////////////////////////////////// 396/////////////////////////////////////////////////////////////////////////////
318 397
319struct rxvt_perl_interp rxvt_perl; 398struct rxvt_perl_interp rxvt_perl;
320 399
321static PerlInterpreter *perl; 400static PerlInterpreter *perl;
322
323rxvt_perl_interp::rxvt_perl_interp ()
324{
325}
326 401
327rxvt_perl_interp::~rxvt_perl_interp () 402rxvt_perl_interp::~rxvt_perl_interp ()
328{ 403{
329 if (perl) 404 if (perl)
330 { 405 {
336void 411void
337rxvt_perl_interp::init () 412rxvt_perl_interp::init ()
338{ 413{
339 if (!perl) 414 if (!perl)
340 { 415 {
416 perl_environ = rxvt_environ;
417 swap (perl_environ, environ);
418
341 char *argv[] = { 419 char *argv[] = {
342 "", 420 "",
421 "-T",
343 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", 422 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
344 }; 423 };
345 424
346 perl = perl_alloc (); 425 perl = perl_alloc ();
347 perl_construct (perl); 426 perl_construct (perl);
348 427
349 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 428 if (perl_parse (perl, xs_init, 3, argv, (char **)NULL)
350 || perl_run (perl)) 429 || perl_run (perl))
351 { 430 {
352 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 431 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
353 432
354 perl_destruct (perl); 433 perl_destruct (perl);
355 perl_free (perl); 434 perl_free (perl);
356 perl = 0; 435 perl = 0;
357 } 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 ();
358 } 464 }
359} 465}
360 466
361bool 467bool
362rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 468rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
363{ 469{
364 if (!perl) 470 if (!perl)
365 return false; 471 return false;
366 472
367 if (htype == HOOK_INIT) // first hook ever called 473 if (htype == HOOK_INIT) // first hook ever called
368 { 474 {
369 term->self = (void *)newSVptr ((void *)term, "urxvt::term"); 475 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
370 hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); 476 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
371 } 477 }
372 else if (!term->self) 478 else if (!term->perl.self)
373 return false; // perl not initialized for this instance 479 return false; // perl not initialized for this instance
374 else if (htype == HOOK_DESTROY) 480 else if (htype == HOOK_DESTROY)
375 { 481 {
376 // handled later 482 // handled later
377 } 483 }
378 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) 484 else
379 { 485 {
380 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); 486 if (htype == HOOK_REFRESH_END)
487 swap_overlays (term);
381 488
382 if (HvKEYS (hv)) 489 if (!term->perl.should_invoke [htype])
383 { 490 {
384 hv_iterinit (hv); 491 if (htype == HOOK_REFRESH_BEGIN)
492 swap_overlays (term);
385 493
386 while (HE *he = hv_iternext (hv)) 494 return false;
387 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
388 } 495 }
389 } 496 }
390 else if (!should_invoke [htype])
391 return false;
392 497
498 swap (perl_environ, environ);
499
500 try
501 {
393 dSP; 502 dSP;
394 va_list ap; 503 va_list ap;
395 504
396 va_start (ap, htype); 505 va_start (ap, htype);
397 506
398 ENTER; 507 ENTER;
399 SAVETMPS; 508 SAVETMPS;
400 509
401 PUSHMARK (SP); 510 PUSHMARK (SP);
402 511
403 XPUSHs (sv_2mortal (newSVterm (term))); 512 XPUSHs (sv_2mortal (newSVterm (term)));
404 XPUSHs (sv_2mortal (newSViv (htype))); 513 XPUSHs (sv_2mortal (newSViv (htype)));
405 514
406 for (;;) { 515 for (;;) {
407 data_type dt = (data_type)va_arg (ap, int); 516 data_type dt = (data_type)va_arg (ap, int);
408 517
409 switch (dt) 518 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 { 519 {
425 va_end (ap); 520 case DT_INT:
521 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
522 break;
426 523
427 PUTBACK; 524 case DT_LONG:
428 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); 525 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
429 SPAGAIN; 526 break;
430 527
431 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:
432 { 533 {
433 SV *status = POPs; 534 char *str = va_arg (ap, char *);
434 count = SvTRUE (status); 535 int len = va_arg (ap, int);
536
537 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
435 } 538 }
539 break;
436 540
437 PUTBACK; 541 case DT_WCS_LEN:
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 { 542 {
446 // TODO: clear magic 543 wchar_t *wstr = va_arg (ap, wchar_t *);
447 hv_clear ((HV *)SvRV ((SV *)term->self)); 544 int wlen = va_arg (ap, int);
448 SvREFCNT_dec ((SV *)term->self); 545
546 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
449 } 547 }
548 break;
450 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);
451 return count; 635 return count;
636 }
637
638 default:
639 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
452 } 640 }
453
454 default:
455 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
456 } 641 }
457 } 642 }
643 catch (...)
644 {
645 swap (perl_environ, environ);
646 throw;
647 }
458} 648}
459 649
460///////////////////////////////////////////////////////////////////////////// 650/////////////////////////////////////////////////////////////////////////////
461 651
462MODULE = urxvt PACKAGE = urxvt 652MODULE = urxvt PACKAGE = urxvt
463 653
464PROTOTYPES: ENABLE 654PROTOTYPES: ENABLE
465 655
466BOOT: 656BOOT:
467{ 657{
468# 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));
469# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), #name, newSViv (name)); 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
470 AV *hookname = get_av ("urxvt::HOOKNAME", 1); 663 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
471 set_hookname (INIT); 664# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
472 set_hookname (RESET); 665# include "hookinc.h"
473 set_hookname (START); 666# undef def
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 667
668 HV *option = get_hv ("urxvt::OPTION", 1);
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
674
675 HV *stash = gv_stashpv ("urxvt", 1);
676 struct {
677 const char *name;
678 IV iv;
679 } *civ, const_iv[] = {
680# define const_iv(name) { # name, (IV)name }
488 export_const (DEFAULT_RSTYLE); 681 const_iv (DEFAULT_RSTYLE),
489 export_const (OVERLAY_RSTYLE); 682 const_iv (OVERLAY_RSTYLE),
490 export_const (RS_Bold); 683 const_iv (RS_Bold),
491 export_const (RS_Italic); 684 const_iv (RS_Italic),
492 export_const (RS_Blink); 685 const_iv (RS_Blink),
493 export_const (RS_RVid); 686 const_iv (RS_RVid),
494 export_const (RS_Uline); 687 const_iv (RS_Uline),
495 688
496 sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); 689 const_iv (CurrentTime),
497} 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),
498 704
499void 705 const_iv (EVENT_NONE),
500set_should_invoke (int htype, int value) 706 const_iv (EVENT_READ),
501 CODE: 707 const_iv (EVENT_WRITE),
502 rxvt_perl.should_invoke [htype] = value; 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}
503 775
504void 776void
505warn (const char *msg) 777warn (const char *msg)
506 CODE: 778 CODE:
507 rxvt_warn ("%s", msg); 779 rxvt_warn ("%s", msg);
508 780
509void 781void
510fatal (const char *msg) 782fatal (const char *msg)
511 CODE: 783 CODE:
512 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
513 803
514NV 804NV
515NOW () 805NOW ()
516 CODE: 806 CODE:
517 RETVAL = NOW; 807 RETVAL = NOW;
565} 855}
566 OUTPUT: 856 OUTPUT:
567 RETVAL 857 RETVAL
568 858
569MODULE = 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);
570 1050
571int 1051int
572rxvt_term::strwidth (SV *str) 1052rxvt_term::strwidth (SV *str)
573 CODE: 1053 CODE:
574{ 1054{
593 char *mbstr = rxvt_wcstombs (wstr); 1073 char *mbstr = rxvt_wcstombs (wstr);
594 rxvt_pop_locale (); 1074 rxvt_pop_locale ();
595 1075
596 free (wstr); 1076 free (wstr);
597 1077
598 RETVAL = newSVpv (mbstr, 0); 1078 RETVAL = taint_if (newSVpv (mbstr, 0), str);
599 free (mbstr); 1079 free (mbstr);
600} 1080}
601 OUTPUT: 1081 OUTPUT:
602 RETVAL 1082 RETVAL
603 1083
610 1090
611 rxvt_push_locale (THIS->locale); 1091 rxvt_push_locale (THIS->locale);
612 wchar_t *wstr = rxvt_mbstowcs (data, len); 1092 wchar_t *wstr = rxvt_mbstowcs (data, len);
613 rxvt_pop_locale (); 1093 rxvt_pop_locale ();
614 1094
615 char *str = rxvt_wcstoutf8 (wstr); 1095 RETVAL = taint_if (wcs2sv (wstr), octets);
616 free (wstr); 1096 free (wstr);
617
618 RETVAL = newSVpv (str, 0);
619 SvUTF8_on (RETVAL);
620 free (str);
621} 1097}
622 OUTPUT: 1098 OUTPUT:
623 RETVAL 1099 RETVAL
624 1100
1101#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
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
625int 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 *
626rxvt_term::nsaved () 1167rxvt_term::_env ()
627 CODE: 1168 CODE:
628 RETVAL = THIS->nsaved; 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}
629 OUTPUT: 1183 OUTPUT:
630 RETVAL 1184 RETVAL
631 1185
632int 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
633rxvt_term::view_start (int newval = -1) 1224rxvt_term::view_start (int newval = 1)
1225 PROTOTYPE: $;$
634 CODE: 1226 CODE:
635{ 1227{
636 RETVAL = THIS->view_start; 1228 RETVAL = THIS->view_start;
637 1229
638 if (newval >= 0) 1230 if (newval <= 0)
639 { 1231 THIS->scr_changeview (max (newval, THIS->top_row));
640 THIS->view_start = min (newval, THIS->nsaved);
641 THIS->scr_changeview (RETVAL);
642 }
643} 1232}
644 OUTPUT: 1233 OUTPUT:
645 RETVAL 1234 RETVAL
646 1235
647int
648rxvt_term::nrow ()
649 CODE:
650 RETVAL = THIS->nrow;
651 OUTPUT:
652 RETVAL
653
654int
655rxvt_term::ncol ()
656 CODE:
657 RETVAL = THIS->ncol;
658 OUTPUT:
659 RETVAL
660
661void 1236void
662rxvt_term::want_refresh () 1237rxvt_term::want_refresh ()
663 CODE: 1238 CODE:
664 THIS->want_refresh = 1; 1239 THIS->want_refresh = 1;
665 1240
666void 1241void
667rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) 1242rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
668 PPCODE: 1243 PPCODE:
669{ 1244{
670 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1245 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
671 croak ("row_number number of out range"); 1246 XSRETURN_EMPTY;
672 1247
673 line_t &l = ROW(row_number); 1248 line_t &l = ROW(row_number);
674 1249
675 if (GIMME_V != G_VOID) 1250 if (GIMME_V != G_VOID)
676 { 1251 {
677 wchar_t *wstr = new wchar_t [THIS->ncol]; 1252 wchar_t *wstr = new wchar_t [THIS->ncol];
678 1253
679 for (int col = 0; col <THIS->ncol; col++) 1254 for (int col = 0; col < THIS->ncol; col++)
680 wstr [col] = l.t [col]; 1255 wstr [col] = l.t [col];
681 1256
682 char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); 1257 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
683 free (wstr);
684 1258
685 SV *sv = newSVpv (str, 0); 1259 delete [] wstr;
686 SvUTF8_on (sv);
687 XPUSHs (sv_2mortal (sv));
688 free (str);
689 } 1260 }
690 1261
691 if (new_text) 1262 if (new_text)
692 { 1263 {
693 wchar_t *wstr = sv2wcs (new_text); 1264 wchar_t *wstr = sv2wcs (new_text);
694 1265
695 int len = wcslen (wstr); 1266 int len = min (wcslen (wstr) - start_ofs, max_len);
696 1267
697 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1268 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
698 { 1269 {
699 free (wstr); 1270 free (wstr);
700 croak ("new_text extends beyond horizontal margins"); 1271 croak ("new_text extends beyond horizontal margins");
701 } 1272 }
702 1273
703 for (int col = start_col; col < start_col + len; col++) 1274 for (int col = start_col; col < start_col + len; col++)
704 { 1275 {
705 l.t [col] = wstr [col - start_col]; 1276 l.t [col] = wstr [start_ofs + col - start_col];
706 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); 1277 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
707 } 1278 }
708 1279
709 free (wstr); 1280 free (wstr);
710 } 1281 }
711} 1282}
712 1283
713void 1284void
714rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) 1285rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
715 PPCODE: 1286 PPCODE:
716{ 1287{
717 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1288 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
718 croak ("row_number number of out range"); 1289 XSRETURN_EMPTY;
719 1290
720 line_t &l = ROW(row_number); 1291 line_t &l = ROW(row_number);
721 1292
722 if (GIMME_V != G_VOID) 1293 if (GIMME_V != G_VOID)
723 { 1294 {
734 { 1305 {
735 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) 1306 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
736 croak ("new_rend must be arrayref"); 1307 croak ("new_rend must be arrayref");
737 1308
738 AV *av = (AV *)SvRV (new_rend); 1309 AV *av = (AV *)SvRV (new_rend);
739 int len = av_len (av) + 1; 1310 int len = min (av_len (av) + 1 - start_ofs, max_len);
740 1311
741 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1312 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
742 croak ("new_rend array extends beyond horizontal margins"); 1313 croak ("new_rend array extends beyond horizontal margins");
743 1314
744 for (int col = start_col; col < start_col + len; col++) 1315 for (int col = start_col; col < start_col + len; col++)
745 { 1316 {
746 rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; 1317 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
747 1318
748 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); 1319 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
749 } 1320 }
750 } 1321 }
751} 1322}
752 1323
753int 1324int
754rxvt_term::ROW_l (int row_number, int new_length = -2) 1325rxvt_term::ROW_l (int row_number, int new_length = -1)
755 CODE: 1326 CODE:
756{ 1327{
757 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) 1328 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
758 croak ("row_number number of out range"); 1329 XSRETURN_EMPTY;
759 1330
760 line_t &l = ROW(row_number); 1331 line_t &l = ROW(row_number);
761 RETVAL = l.l; 1332 RETVAL = l.l;
762 1333
763 if (new_length >= -1) 1334 if (new_length >= 0)
764 l.l = new_length; 1335 l.l = new_length;
765} 1336}
766 OUTPUT: 1337 OUTPUT:
767 RETVAL 1338 RETVAL
768 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
769SV * 1356SV *
770rxvt_term::special_encode (SV *str) 1357rxvt_term::special_encode (SV *string)
771 CODE: 1358 CODE:
772 abort ();//TODO 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
773 1394
774SV * 1395SV *
775rxvt_term::special_decode (SV *str) 1396rxvt_term::special_decode (SV *text)
776 CODE: 1397 CODE:
777 abort ();//TODO 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;
1427}
1428 OUTPUT:
1429 RETVAL
778 1430
779void 1431void
780rxvt_term::_resource (char *name, int index, SV *newval = 0) 1432rxvt_term::_resource (char *name, int index, SV *newval = 0)
781 PPCODE: 1433 PPCODE:
782{ 1434{
783 struct resval { const char *name; int value; } rslist [] = { 1435 struct resval { const char *name; int value; } rslist [] = {
784# define Rs_def(name) { # name, Rs_ ## name }, 1436# define def(name) { # name, Rs_ ## name },
785# define Rs_reserve(name,count) 1437# define reserve(name,count)
786# include "rsinc.h" 1438# include "rsinc.h"
787# undef Rs_def 1439# undef def
788# undef Rs_reserve 1440# undef reserve
789 }; 1441 };
790 1442
791 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1443 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
792 1444
793 do { 1445 do {
799 1451
800 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1452 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
801 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);
802 1454
803 if (GIMME_V != G_VOID) 1455 if (GIMME_V != G_VOID)
804 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);
805 1457
806 if (newval) 1458 if (newval)
807 { 1459 {
808 if (SvOK (newval)) 1460 if (SvOK (newval))
809 { 1461 {
814 else 1466 else
815 THIS->rs [index] = 0; 1467 THIS->rs [index] = 0;
816 } 1468 }
817} 1469}
818 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
819void 1520void
820rxvt_term::selection_mark (...) 1521rxvt_term::screen_cur (...)
821 PROTOTYPE: $;$$ 1522 PROTOTYPE: $;$$
822 ALIAS: 1523 ALIAS:
1524 screen_cur = 0
823 selection_beg = 1 1525 selection_beg = 1
824 selection_end = 2 1526 selection_end = 2
1527 selection_mark = 3
825 PPCODE: 1528 PPCODE:
826{ 1529{
827 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
828 : ix == 2 ? THIS->selection.end 1532 : ix == 2 ? THIS->selection.end
829 : THIS->selection.mark; 1533 : THIS->selection.mark;
830 1534
831 if (GIMME_V != G_VOID) 1535 if (GIMME_V != G_VOID)
832 { 1536 {
833 EXTEND (SP, 2); 1537 EXTEND (SP, 2);
834 PUSHs (sv_2mortal (newSViv (sel.row))); 1538 PUSHs (sv_2mortal (newSViv (rc.row)));
835 PUSHs (sv_2mortal (newSViv (sel.col))); 1539 PUSHs (sv_2mortal (newSViv (rc.col)));
836 } 1540 }
837 1541
838 if (items == 3) 1542 if (items == 3)
839 { 1543 {
840 sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); 1544 rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1);
841 sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); 1545 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
842 1546
843 if (ix) 1547 if (ix)
844 THIS->want_refresh = 1; 1548 THIS->want_refresh = 1;
845 } 1549 }
846} 1550}
847 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
848int 1569int
849rxvt_term::selection_grab (int eventtime = CurrentTime) 1570rxvt_term::selection_grab (U32 eventtime)
850 1571
851void 1572void
852rxvt_term::selection (SV *newtext = 0) 1573rxvt_term::selection (SV *newtext = 0)
853 PPCODE: 1574 PPCODE:
854{ 1575{
855 if (GIMME_V != G_VOID) 1576 if (GIMME_V != G_VOID)
856 { 1577 XPUSHs (THIS->selection.text
857 char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); 1578 ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))
858 SV *sv = newSVpv (sel, 0); 1579 : &PL_sv_undef);
859 SvUTF8_on (sv);
860 free (sel);
861 XPUSHs (sv_2mortal (sv));
862 }
863 1580
864 if (newtext) 1581 if (newtext)
865 { 1582 {
866 free (THIS->selection.text); 1583 free (THIS->selection.text);
867 1584
868 THIS->selection.text = sv2wcs (newtext); 1585 THIS->selection.text = sv2wcs (newtext);
869 THIS->selection.len = wcslen (THIS->selection.text); 1586 THIS->selection.len = wcslen (THIS->selection.text);
870 } 1587 }
871} 1588}
872 1589
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
1597rxvt_term::scr_bell ()
1598
1599void
1600rxvt_term::scr_add_lines (SV *string)
1601 CODE:
1602{
1603 wchar_t *wstr = sv2wcs (string);
1604 THIS->scr_add_lines (wstr, wcslen (wstr));
1605 free (wstr);
1606}
1607
873void 1608void
874rxvt_term::tt_write (SV *octets) 1609rxvt_term::tt_write (SV *octets)
875 INIT: 1610 INIT:
876 STRLEN len; 1611 STRLEN len;
877 char *str = SvPVbyte (octets, len); 1612 char *str = SvPVbyte (octets, len);
878 C_ARGS: 1613 C_ARGS:
879 (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}
880 1636
881SV * 1637SV *
882rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) 1638rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
883 CODE: 1639 CODE:
884{ 1640{
885 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); 1641 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);
886 RETVAL = newSVptr ((void *)o, "urxvt::overlay"); 1642 RETVAL = newSVptr ((void *)o, "urxvt::overlay");
887 o->self = (HV *)SvRV (RETVAL); 1643 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} 1644}
893 OUTPUT: 1645 OUTPUT:
894 RETVAL 1646 RETVAL
895 1647
896MODULE = urxvt PACKAGE = urxvt::overlay 1648MODULE = urxvt PACKAGE = urxvt::overlay
897 1649
898void 1650void
899overlay::set (int x, int y, SV *text, SV *rend = 0) 1651overlay::set (int x, int y, SV *text, SV *rend = 0)
900 1652
901void 1653void
1654overlay::show ()
1655
1656void
1657overlay::hide ()
1658
1659void
902overlay::DESTROY () 1660overlay::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 1661
916MODULE = urxvt PACKAGE = urxvt::timer 1662MODULE = urxvt PACKAGE = urxvt::timer
917 1663
918SV * 1664SV *
919timer::new () 1665timer::new ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines