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.109 by root, Thu Dec 14 15:19:31 2006 UTC vs.
Revision 1.138 by root, Mon Feb 21 08:10:10 2011 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-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2008,2011 Marc Lehmann <schmorp@schmorp.de>
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.
31#include <cstddef> 31#include <cstddef>
32#include <cstdarg> 32#include <cstdarg>
33 33
34#include "unistd.h" 34#include "unistd.h"
35 35
36#include "iom.h" 36#include "ev_cpp.h"
37#include "rxvt.h" 37#include "rxvt.h"
38#include "keyboard.h" 38#include "keyboard.h"
39#include "rxvtutil.h" 39#include "rxvtutil.h"
40#include "rxvtperl.h" 40#include "rxvtperl.h"
41 41
42#include "perlxsi.c" 42#include "perlxsi.c"
43 43
44#ifdef HAVE_SCROLLBARS
45# define GRAB_CURSOR THIS->leftptr_cursor 44#define GRAB_CURSOR THIS->scrollBar.leftptr_cursor
46#else
47# define GRAB_CURSOR None
48#endif
49 45
50#undef LINENO 46#undef LINENO
51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 47#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
52#undef ROW 48#undef ROW
53#define ROW(n) THIS->row_buf [LINENO (n)] 49#define ROW(n) THIS->row_buf [LINENO (n)]
54 50
55typedef int CHAINED UNUSED;
56
57///////////////////////////////////////////////////////////////////////////// 51/////////////////////////////////////////////////////////////////////////////
58 52
59static wchar_t * 53static wchar_t *
60sv2wcs (SV *sv) 54sv2wcs (SV *sv)
61{ 55{
75 69
76 return sv; 70 return sv;
77} 71}
78 72
79static SV * 73static SV *
80new_ref (HV *hv, const char *klass)
81{
82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
83}
84
85static SV *
86newSVptr (void *ptr, const char *klass) 74newSVptr (void *ptr, const char *klass)
87{ 75{
88 HV *hv = newHV (); 76 HV *hv = newHV ();
89 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 77 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
90 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 78 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
119 107
120///////////////////////////////////////////////////////////////////////////// 108/////////////////////////////////////////////////////////////////////////////
121 109
122#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 110#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
123 111
124class overlay { 112class overlay : overlay_base
113{
125 rxvt_term *THIS; 114 rxvt_term *THIS;
126 AV *overlay_av; 115 AV *overlay_av;
127 int x, y, w, h;
128 int border; 116 int border;
129 text_t **text;
130 rend_t **rend;
131 117
132public: 118public:
133 HV *self; 119 HV *self;
134 120
135 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); 121 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
142 128
143 void set (int x, int y, SV *str, SV *rend); 129 void set (int x, int y, SV *str, SV *rend);
144}; 130};
145 131
146overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 132overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
147: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0) 133: THIS(THIS), border(border == 2), overlay_av (0)
148{ 134{
135 x = x_;
136 y = y_;
137 w = w_;
138 h = h_;
139
149 if (w < 0) w = 0; 140 if (w < 0) w = 0;
150 if (h < 0) h = 0; 141 if (h < 0) h = 0;
151 142
152 if (border == 2) 143 if (border == 2)
153 { 144 {
222 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) 213 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
223 )); 214 ));
224 av_push (overlay_av, newSViv ((long)this)); 215 av_push (overlay_av, newSViv ((long)this));
225 216
226 THIS->want_refresh = 1; 217 THIS->want_refresh = 1;
218 THIS->refresh_check ();
227} 219}
228 220
229void 221void
230overlay::hide () 222overlay::hide ()
231{ 223{
245 237
246 SvREFCNT_dec (overlay_av); 238 SvREFCNT_dec (overlay_av);
247 overlay_av = 0; 239 overlay_av = 0;
248 240
249 THIS->want_refresh = 1; 241 THIS->want_refresh = 1;
242 THIS->refresh_check ();
250} 243}
251 244
252void overlay::swap () 245void overlay::swap ()
253{ 246{
254 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 247 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
255 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); 248 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
256 249
257 int ov_w = min (w, THIS->ncol - ov_x); 250 int ov_w = min (w, THIS->ncol - ov_x);
258 int ov_h = min (h, THIS->nrow - ov_y); 251 int ov_h = min (h, THIS->nrow - ov_y);
252
253 // hide cursor if it is within the overlay area
254 if (IN_RANGE_EXC (THIS->screen.cur.col - ov_x, 0, ov_w)
255 && IN_RANGE_EXC (THIS->screen.cur.row - ov_y, 0, ov_h))
256 THIS->screen.flags &= ~Screen_VisibleCursor;
259 257
260 for (int y = ov_h; y--; ) 258 for (int y = ov_h; y--; )
261 { 259 {
262 text_t *t1 = text [y]; 260 text_t *t1 = text [y];
263 rend_t *r1 = rend [y]; 261 rend_t *r1 = rend [y];
299 for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) 297 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
300 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 298 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
301 } 299 }
302 300
303 THIS->want_refresh = 1; 301 THIS->want_refresh = 1;
302 THIS->refresh_check ();
304} 303}
305 304
306///////////////////////////////////////////////////////////////////////////// 305/////////////////////////////////////////////////////////////////////////////
307 306
308#define IOM_CLASS "urxvt"
309#include <iom_perl.h> 307#include "iom_perl.h"
310 308
311///////////////////////////////////////////////////////////////////////////// 309/////////////////////////////////////////////////////////////////////////////
312 310
313struct rxvt_perl_interp rxvt_perl; 311struct rxvt_perl_interp rxvt_perl;
314 312
318{ 316{
319 if (perl) 317 if (perl)
320 { 318 {
321 perl_destruct (perl); 319 perl_destruct (perl);
322 perl_free (perl); 320 perl_free (perl);
321 PERL_SYS_TERM ();
323 } 322 }
324} 323}
325 324
326void 325void
327rxvt_perl_interp::init (rxvt_term *term) 326rxvt_perl_interp::init (rxvt_term *term)
328{ 327{
329 if (!perl) 328 if (!perl)
330 { 329 {
331 rxvt_push_locale (""); // perl init destroys current locale 330 rxvt_push_locale (""); // perl init destroys current locale
332 331
332 {
333 perl_environ = rxvt_environ; 333 perl_environ = rxvt_environ;
334 swap (perl_environ, environ); 334 localise_env set_environ (perl_environ);
335 335
336 char *argv[] = { 336 char *args[] = {
337 "", 337 "",
338 "-e" 338 "-e"
339 "BEGIN {" 339 "BEGIN {"
340 " urxvt->bootstrap;" 340 " urxvt->bootstrap;"
341 " unshift @INC, '" LIBDIR "';" 341 " unshift @INC, '" LIBDIR "';"
342 "}" 342 "}"
343 "" 343 ""
344 "use urxvt;" 344 "use urxvt;"
345 }; 345 };
346 int argc = ARRAY_LENGTH(args);
347 char **argv = args;
346 348
349 PERL_SYS_INIT3 (&argc, &argv, &environ);
347 perl = perl_alloc (); 350 perl = perl_alloc ();
348 perl_construct (perl); 351 perl_construct (perl);
349 352
350 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 353 if (perl_parse (perl, xs_init, argc, argv, (char **)NULL)
351 || perl_run (perl)) 354 || perl_run (perl))
352 { 355 {
353 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 356 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
354 357
355 perl_destruct (perl); 358 perl_destruct (perl);
356 perl_free (perl); 359 perl_free (perl);
357 perl = 0; 360 perl = 0;
358 } 361 }
359 362 }
360 swap (perl_environ, environ);
361 363
362 rxvt_pop_locale (); 364 rxvt_pop_locale ();
363 } 365 }
364 366
365 if (perl) 367 if (perl)
385rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 387rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
386{ 388{
387 if (!perl || !term->perl.self) 389 if (!perl || !term->perl.self)
388 return false; 390 return false;
389 391
392 localise_env set_environ (perl_environ);
393
390 // pre-handling of some events 394 // pre-handling of some events
391 if (htype == HOOK_REFRESH_END) 395 if (htype == HOOK_REFRESH_END)
392 { 396 {
393 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 397 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
394 398
395 for (int i = 0; i <= AvFILL (av); i++) 399 for (int i = 0; i <= AvFILL (av); i++)
396 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 400 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
397 } 401 }
398 402
399 swap (perl_environ, environ);
400
401 bool event_consumed; 403 bool event_consumed;
402 404
403 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always 405 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
404 || term->perl.should_invoke [htype]) 406 || term->perl.should_invoke [htype])
405 try
406 { 407 {
407 dSP; 408 dSP;
408 va_list ap; 409 va_list ap;
409 410
410 va_start (ap, htype); 411 va_start (ap, htype);
411 412
412 ENTER; 413 ENTER;
413 SAVETMPS; 414 SAVETMPS;
414 415
415 PUSHMARK (SP); 416 PUSHMARK (SP);
416 417
418 EXTEND (SP, 2);
417 XPUSHs (sv_2mortal (newSVterm (term))); 419 PUSHs (sv_2mortal (newSVterm (term)));
418 XPUSHs (sv_2mortal (newSViv (htype))); 420 PUSHs (sv_2mortal (newSViv (htype)));
419 421
420 for (;;) { 422 for (;;) {
421 data_type dt = (data_type)va_arg (ap, int); 423 data_type dt = (data_type)va_arg (ap, int);
422 424
423 switch (dt) 425 switch (dt)
424 { 426 {
425 case DT_INT: 427 case DT_INT:
426 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); 428 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
427 break; 429 break;
428 430
429 case DT_LONG: 431 case DT_LONG:
430 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 432 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
431 break; 433 break;
432 434
433 case DT_STR: 435 case DT_STR:
434 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 436 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
435 break; 437 break;
436 438
437 case DT_STR_LEN: 439 case DT_STR_LEN:
438 { 440 {
439 char *str = va_arg (ap, char *); 441 char *str = va_arg (ap, char *);
440 int len = va_arg (ap, int); 442 int len = va_arg (ap, int);
441 443
442 XPUSHs (sv_2mortal (newSVpvn (str, len))); 444 XPUSHs (sv_2mortal (newSVpvn (str, len)));
443 } 445 }
444 break; 446 break;
445 447
446 case DT_WCS_LEN: 448 case DT_WCS_LEN:
447 { 449 {
448 wchar_t *wstr = va_arg (ap, wchar_t *); 450 wchar_t *wstr = va_arg (ap, wchar_t *);
449 int wlen = va_arg (ap, int); 451 int wlen = va_arg (ap, int);
450 452
451 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 453 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
452 } 454 }
453 break; 455 break;
454 456
455 case DT_LCS_LEN: 457 case DT_LCS_LEN:
456 { 458 {
457 long *lstr = va_arg (ap, long *); 459 long *lstr = va_arg (ap, long *);
458 int llen = va_arg (ap, int); 460 int llen = va_arg (ap, int);
459 461
460 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long)))); 462 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long))));
461 } 463 }
462 break; 464 break;
463 465
464 case DT_XEVENT: 466 case DT_XEVENT:
465 { 467 {
466 XEvent *xe = va_arg (ap, XEvent *); 468 XEvent *xe = va_arg (ap, XEvent *);
467 HV *hv = newHV (); 469 HV *hv = newHV ();
468 470
469# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 471# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
470# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) 472# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
471# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) 473# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
472# undef set 474# undef set
473 475
474 setiv (type, xe->type); 476 setiv (type, xe->type);
475 setiv (send_event, xe->xany.send_event); 477 setiv (send_event, xe->xany.send_event);
476 setiv (serial, xe->xany.serial); 478 setiv (serial, xe->xany.serial);
477 479
478 switch (xe->type) 480 switch (xe->type)
479 { 481 {
480 case KeyPress: 482 case KeyPress:
481 case KeyRelease: 483 case KeyRelease:
482 case ButtonPress: 484 case ButtonPress:
483 case ButtonRelease: 485 case ButtonRelease:
484 case MotionNotify: 486 case MotionNotify:
485 setuv (window, xe->xmotion.window); 487 setuv (window, xe->xmotion.window);
486 setuv (root, xe->xmotion.root); 488 setuv (root, xe->xmotion.root);
487 setuv (subwindow, xe->xmotion.subwindow); 489 setuv (subwindow, xe->xmotion.subwindow);
488 setuv (time, xe->xmotion.time); 490 setuv (time, xe->xmotion.time);
489 setiv (x, xe->xmotion.x); 491 setiv (x, xe->xmotion.x);
490 setiv (y, xe->xmotion.y); 492 setiv (y, xe->xmotion.y);
491 setiv (row, xe->xmotion.y / term->fheight + term->view_start); 493 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
492 setiv (col, xe->xmotion.x / term->fwidth); 494 setiv (col, xe->xmotion.x / term->fwidth);
493 setiv (x_root, xe->xmotion.x_root); 495 setiv (x_root, xe->xmotion.x_root);
494 setiv (y_root, xe->xmotion.y_root); 496 setiv (y_root, xe->xmotion.y_root);
495 setuv (state, xe->xmotion.state); 497 setuv (state, xe->xmotion.state);
496 498
497 switch (xe->type) 499 switch (xe->type)
498 { 500 {
499 case KeyPress: 501 case KeyPress:
500 case KeyRelease: 502 case KeyRelease:
501 setuv (keycode, xe->xkey.keycode); 503 setuv (keycode, xe->xkey.keycode);
502 break; 504 break;
503 505
504 case ButtonPress: 506 case ButtonPress:
505 case ButtonRelease: 507 case ButtonRelease:
506 setuv (button, xe->xbutton.button); 508 setuv (button, xe->xbutton.button);
507 break; 509 break;
508 510
509 case MotionNotify: 511 case MotionNotify:
510 setiv (is_hint, xe->xmotion.is_hint); 512 setiv (is_hint, xe->xmotion.is_hint);
511 break; 513 break;
512 } 514 }
513 515
514 break; 516 break;
515 517
516 case MapNotify: 518 case MapNotify:
517 case UnmapNotify: 519 case UnmapNotify:
518 case ConfigureNotify: 520 case ConfigureNotify:
519 setuv (event, xe->xconfigure.event); 521 setuv (event, xe->xconfigure.event);
520 setuv (window, xe->xconfigure.window); 522 setuv (window, xe->xconfigure.window);
521 523
522 switch (xe->type) 524 switch (xe->type)
523 { 525 {
524 case ConfigureNotify: 526 case ConfigureNotify:
525 setiv (x, xe->xconfigure.x); 527 setiv (x, xe->xconfigure.x);
526 setiv (y, xe->xconfigure.y); 528 setiv (y, xe->xconfigure.y);
527 setiv (width, xe->xconfigure.width); 529 setiv (width, xe->xconfigure.width);
528 setiv (height, xe->xconfigure.height); 530 setiv (height, xe->xconfigure.height);
529 setuv (above, xe->xconfigure.above); 531 setuv (above, xe->xconfigure.above);
530 break; 532 break;
531 } 533 }
532 534
533 break; 535 break;
534 536
535 case PropertyNotify: 537 case PropertyNotify:
536 setuv (window, xe->xproperty.window); 538 setuv (window, xe->xproperty.window);
537 setuv (atom, xe->xproperty.atom); 539 setuv (atom, xe->xproperty.atom);
538 setuv (time, xe->xproperty.time); 540 setuv (time, xe->xproperty.time);
539 setiv (state, xe->xproperty.state); 541 setiv (state, xe->xproperty.state);
540 break; 542 break;
541 543
542 case ClientMessage: 544 case ClientMessage:
543 setuv (window, xe->xclient.window); 545 setuv (window, xe->xclient.window);
544 setuv (message_type, xe->xclient.message_type); 546 setuv (message_type, xe->xclient.message_type);
545 setuv (format, xe->xclient.format); 547 setuv (format, xe->xclient.format);
546 setuv (l0, xe->xclient.data.l[0]); 548 setuv (l0, xe->xclient.data.l[0]);
547 setuv (l1, xe->xclient.data.l[1]); 549 setuv (l1, xe->xclient.data.l[1]);
548 setuv (l2, xe->xclient.data.l[2]); 550 setuv (l2, xe->xclient.data.l[2]);
549 setuv (l3, xe->xclient.data.l[3]); 551 setuv (l3, xe->xclient.data.l[3]);
550 setuv (l4, xe->xclient.data.l[4]); 552 setuv (l4, xe->xclient.data.l[4]);
551 break; 553 break;
552 } 554 }
553 555
554 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 556 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
555 } 557 }
556 break; 558 break;
557 559
558 case DT_END: 560 case DT_END:
559 goto call; 561 goto call;
560 562
561 default: 563 default:
562 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); 564 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
563 } 565 }
566 }
567
568 call:
569 va_end (ap);
570
571 PUTBACK;
572 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
573 SPAGAIN;
574
575 if (count)
576 {
577 SV *status = POPs;
578 count = SvTRUE (status);
564 } 579 }
565 580
566 call:
567 va_end (ap);
568
569 PUTBACK; 581 PUTBACK;
570 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
571 SPAGAIN;
572
573 if (count)
574 {
575 SV *status = POPs;
576 count = SvTRUE (status);
577 }
578
579 PUTBACK;
580 FREETMPS; 582 FREETMPS;
581 LEAVE; 583 LEAVE;
582 584
583 if (SvTRUE (ERRSV)) 585 if (SvTRUE (ERRSV))
584 { 586 {
585 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 587 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPVbyte_nolen (ERRSV));
586 ungrab (term); // better lose the grab than the session 588 ungrab (term); // better lose the grab than the session
587 } 589 }
588 590
589 event_consumed = !!count; 591 event_consumed = !!count;
590 } 592 }
591 catch (...)
592 {
593 swap (perl_environ, environ);
594 throw;
595 }
596 else 593 else
597 event_consumed = false; 594 event_consumed = false;
598 595
599 // post-handling of some events 596 // post-handling of some events
600 if (htype == HOOK_REFRESH_BEGIN) 597 if (htype == HOOK_REFRESH_BEGIN)
601 { 598 {
602 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 599 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
603 600
604 for (int i = AvFILL (av); i >= 0; i--) 601 for (int i = AvFILL (av); i >= 0; i--)
605 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 602 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
606 } 603 }
607 else if (htype == HOOK_DESTROY) 604 else if (htype == HOOK_DESTROY)
608 { 605 {
609 clearSVptr ((SV *)term->perl.self); 606 clearSVptr ((SV *)term->perl.self);
610 SvREFCNT_dec ((SV *)term->perl.self); 607 SvREFCNT_dec ((SV *)term->perl.self);
611 608
612 // don't allow further calls 609 // don't allow further calls
613 term->perl.self = 0; 610 term->perl.self = 0;
614 } 611 }
615 612
616 swap (perl_environ, environ);
617
618 return event_consumed; 613 return event_consumed;
614}
615
616void
617rxvt_perl_interp::selection_finish (rxvt_selection *sel, char *data, unsigned int len)
618{
619 localise_env set_environ (perl_environ);
620
621 ENTER;
622 SAVETMPS;
623
624 dSP;
625 XPUSHs (sv_2mortal (newSVpvn (data, len)));
626 call_sv ((SV *)sel->cb_sv, G_VOID | G_DISCARD | G_EVAL);
627
628 if (SvTRUE (ERRSV))
629 rxvt_warn ("perl selection callback evaluation error: %s", SvPVbyte_nolen (ERRSV));
630
631 FREETMPS;
632 LEAVE;
619} 633}
620 634
621///////////////////////////////////////////////////////////////////////////// 635/////////////////////////////////////////////////////////////////////////////
622 636
623MODULE = urxvt PACKAGE = urxvt 637MODULE = urxvt PACKAGE = urxvt
635# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 649# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
636# include "hookinc.h" 650# include "hookinc.h"
637# undef def 651# undef def
638 652
639 HV *option = get_hv ("urxvt::OPTION", 1); 653 HV *option = get_hv ("urxvt::OPTION", 1);
640# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); 654# define def(name) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
641# define nodef(name) 655# define nodef(name)
642# include "optinc.h" 656# include "optinc.h"
643# undef nodef 657# undef nodef
644# undef def 658# undef def
645 659
647 static const struct { 661 static const struct {
648 const char *name; 662 const char *name;
649 IV iv; 663 IV iv;
650 } *civ, const_iv[] = { 664 } *civ, const_iv[] = {
651# define const_iv(name) { # name, (IV)name } 665# define const_iv(name) { # name, (IV)name }
666 const_iv (NUM_RESOURCES),
652 const_iv (DEFAULT_RSTYLE), 667 const_iv (DEFAULT_RSTYLE),
653 const_iv (OVERLAY_RSTYLE), 668 const_iv (OVERLAY_RSTYLE),
669 const_iv (Color_Bits),
670 const_iv (RS_bgShift), const_iv (RS_bgMask),
671 const_iv (RS_fgShift), const_iv (RS_fgMask),
672 const_iv (RS_Careful),
673 const_iv (RS_fontCount),
674 const_iv (RS_fontShift),
675 const_iv (RS_fontMask),
676 const_iv (RS_baseattrMask),
677 const_iv (RS_attrMask),
678 const_iv (RS_redraw),
679 const_iv (RS_Sel),
654 const_iv (RS_Bold), 680 const_iv (RS_Bold),
655 const_iv (RS_Italic), 681 const_iv (RS_Italic),
656 const_iv (RS_Blink), 682 const_iv (RS_Blink),
657 const_iv (RS_RVid), 683 const_iv (RS_RVid),
658 const_iv (RS_Uline), 684 const_iv (RS_Uline),
674 const_iv (AnyModifier), 700 const_iv (AnyModifier),
675 701
676 const_iv (NoSymbol), 702 const_iv (NoSymbol),
677 const_iv (GrabModeSync), 703 const_iv (GrabModeSync),
678 const_iv (GrabModeAsync), 704 const_iv (GrabModeAsync),
679
680 const_iv (EVENT_NONE),
681 const_iv (EVENT_READ),
682 const_iv (EVENT_WRITE),
683 705
684 const_iv (NoEventMask), 706 const_iv (NoEventMask),
685 const_iv (KeyPressMask), 707 const_iv (KeyPressMask),
686 const_iv (KeyReleaseMask), 708 const_iv (KeyReleaseMask),
687 const_iv (ButtonPressMask), 709 const_iv (ButtonPressMask),
766 const_iv (XIMDontChange), 788 const_iv (XIMDontChange),
767# endif 789# endif
768# endif 790# endif
769 }; 791 };
770 792
771 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 793 for (civ = const_iv + ARRAY_LENGTH(const_iv); civ-- > const_iv; )
772 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 794 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
773} 795}
774 796
775void 797void
776warn (const char *msg) 798warn (const char *msg)
786_exit (int status) 808_exit (int status)
787 809
788NV 810NV
789NOW () 811NOW ()
790 CODE: 812 CODE:
791 RETVAL = NOW; 813 RETVAL = ev::now ();
792 OUTPUT: 814 OUTPUT:
793 RETVAL 815 RETVAL
794 816
795int 817int
796GET_BASEFG (int rend) 818GET_BASEFG (int rend)
868 for (int i = AvFILL (env) + 1; i--; ) 890 for (int i = AvFILL (env) + 1; i--; )
869 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 891 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
870 892
871 envv->push_back (0); 893 envv->push_back (0);
872 894
873 bool success;
874
875 try 895 try
876 { 896 {
877 success = term->init (argv, envv); 897 term->init (argv, envv);
878 } 898 }
879 catch (const class rxvt_failure_exception &e) 899 catch (const class rxvt_failure_exception &e)
880 {
881 success = false;
882 }
883
884 if (!success)
885 { 900 {
886 term->destroy (); 901 term->destroy ();
887 croak ("error while initializing new terminal instance"); 902 croak ("error while initializing new terminal instance");
888 } 903 }
889 904
1061 OUTPUT: 1076 OUTPUT:
1062 RETVAL 1077 RETVAL
1063 1078
1064#define TERM_OFFSET(sym) offsetof (TermWin_t, sym) 1079#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
1065 1080
1066#define TERM_OFFSET_width TERM_OFFSET(width) 1081#define TERM_OFFSET_width TERM_OFFSET(width)
1067#define TERM_OFFSET_height TERM_OFFSET(height) 1082#define TERM_OFFSET_height TERM_OFFSET(height)
1068#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 1083#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
1069#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 1084#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
1070#define TERM_OFFSET_fbase TERM_OFFSET(fbase) 1085#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1071#define TERM_OFFSET_nrow TERM_OFFSET(nrow) 1086#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1072#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1087#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1073#define TERM_OFFSET_focus TERM_OFFSET(focus) 1088#define TERM_OFFSET_focus TERM_OFFSET(focus)
1074#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1089#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
1075#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth) 1090#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth)
1076#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth) 1091#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth)
1077#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace) 1092#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace)
1093#define TERM_OFFSET_letterSpace TERM_OFFSET(letterSpace)
1078#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1094#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1079#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1095#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1080#define TERM_OFFSET_top_row TERM_OFFSET(top_row) 1096#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1081 1097
1082int 1098int
1083rxvt_term::width () 1099rxvt_term::width ()
1084 ALIAS: 1100 ALIAS:
1085 width = TERM_OFFSET_width 1101 width = TERM_OFFSET_width
1086 height = TERM_OFFSET_height 1102 height = TERM_OFFSET_height
1087 fwidth = TERM_OFFSET_fwidth 1103 fwidth = TERM_OFFSET_fwidth
1088 fheight = TERM_OFFSET_fheight 1104 fheight = TERM_OFFSET_fheight
1089 fbase = TERM_OFFSET_fbase 1105 fbase = TERM_OFFSET_fbase
1090 nrow = TERM_OFFSET_nrow 1106 nrow = TERM_OFFSET_nrow
1091 ncol = TERM_OFFSET_ncol 1107 ncol = TERM_OFFSET_ncol
1092 focus = TERM_OFFSET_focus 1108 focus = TERM_OFFSET_focus
1093 mapped = TERM_OFFSET_mapped 1109 mapped = TERM_OFFSET_mapped
1094 int_bwidth = TERM_OFFSET_int_bwidth 1110 int_bwidth = TERM_OFFSET_int_bwidth
1095 ext_bwidth = TERM_OFFSET_ext_bwidth 1111 ext_bwidth = TERM_OFFSET_ext_bwidth
1096 lineSpace = TERM_OFFSET_lineSpace 1112 lineSpace = TERM_OFFSET_lineSpace
1113 letterSpace = TERM_OFFSET_letterSpace
1097 saveLines = TERM_OFFSET_saveLines 1114 saveLines = TERM_OFFSET_saveLines
1098 total_rows = TERM_OFFSET_total_rows 1115 total_rows = TERM_OFFSET_total_rows
1099 top_row = TERM_OFFSET_top_row 1116 top_row = TERM_OFFSET_top_row
1100 CODE: 1117 CODE:
1101 RETVAL = *(int *)((char *)THIS + ix); 1118 RETVAL = *(int *)((char *)THIS + ix);
1102 OUTPUT: 1119 OUTPUT:
1103 RETVAL 1120 RETVAL
1104 1121
1115 { 1132 {
1116 case 0: RETVAL = THIS->ModLevel3Mask; break; 1133 case 0: RETVAL = THIS->ModLevel3Mask; break;
1117 case 1: RETVAL = THIS->ModMetaMask; break; 1134 case 1: RETVAL = THIS->ModMetaMask; break;
1118 case 2: RETVAL = THIS->ModNumLockMask; break; 1135 case 2: RETVAL = THIS->ModNumLockMask; break;
1119 case 3: RETVAL = THIS->current_screen; break; 1136 case 3: RETVAL = THIS->current_screen; break;
1137#ifdef CURSOR_BLINK
1120 case 4: RETVAL = THIS->hidden_cursor; break; 1138 case 4: RETVAL = THIS->hidden_cursor; break;
1139#endif
1121 } 1140 }
1122 OUTPUT: 1141 OUTPUT:
1123 RETVAL 1142 RETVAL
1124 1143
1125char * 1144char *
1150 if (*i) 1169 if (*i)
1151 PUSHs (sv_2mortal (newSVpv (*i, 0))); 1170 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1152} 1171}
1153 1172
1154int 1173int
1155rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1174rxvt_term::pty_ev_events (int events = ev::UNDEF)
1156 CODE: 1175 CODE:
1157 RETVAL = THIS->pty_ev.events; 1176 RETVAL = THIS->pty_ev.events;
1158 if (events != EVENT_UNDEF) 1177 if (events != ev::UNDEF)
1159 THIS->pty_ev.set (events); 1178 THIS->pty_ev.set (events);
1160 OUTPUT: 1179 OUTPUT:
1161 RETVAL 1180 RETVAL
1162 1181
1163int 1182int
1242 1261
1243void 1262void
1244rxvt_term::want_refresh () 1263rxvt_term::want_refresh ()
1245 CODE: 1264 CODE:
1246 THIS->want_refresh = 1; 1265 THIS->want_refresh = 1;
1266 THIS->refresh_check ();
1247 1267
1248void 1268void
1249rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1269rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1250 PPCODE: 1270 PPCODE:
1251{ 1271{
1406SV * 1426SV *
1407rxvt_term::special_decode (SV *text) 1427rxvt_term::special_decode (SV *text)
1408 CODE: 1428 CODE:
1409{ 1429{
1410 wchar_t *wstr = sv2wcs (text); 1430 wchar_t *wstr = sv2wcs (text);
1411 int wlen = wcslen (wstr);
1412 int dlen = 0; 1431 int dlen = 0;
1413 1432
1414 // find length 1433 // find length
1415 for (wchar_t *s = wstr; *s; s++) 1434 for (wchar_t *s = wstr; *s; s++)
1416 if (*s == NOCHAR) 1435 if (*s == NOCHAR)
1447# include "rsinc.h" 1466# include "rsinc.h"
1448# undef def 1467# undef def
1449# undef reserve 1468# undef reserve
1450 }; 1469 };
1451 1470
1452 rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1471 rs = rslist + ARRAY_LENGTH(rslist);
1453 1472
1473 if (*name)
1454 do { 1474 {
1475 do {
1455 if (rs-- == rslist) 1476 if (rs-- == rslist)
1456 croak ("no such resource '%s', requested", name); 1477 croak ("no such resource '%s', requested", name);
1457 } while (strcmp (name, rs->name)); 1478 } while (strcmp (name, rs->name));
1458 1479
1459 index += rs->value; 1480 index += rs->value;
1481 }
1482 else
1483 {
1484 --rs;
1485 name = "";
1486 }
1460 1487
1461 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1488 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1462 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1489 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1463 1490
1464 if (GIMME_V != G_VOID) 1491 if (GIMME_V != G_VOID)
1479 1506
1480const char * 1507const char *
1481rxvt_term::x_resource (const char *name) 1508rxvt_term::x_resource (const char *name)
1482 1509
1483bool 1510bool
1484rxvt_term::option (U32 optval, int set = -1) 1511rxvt_term::option (U8 optval, int set = -1)
1485 CODE: 1512 CODE:
1486{ 1513{
1487 RETVAL = THIS->options & optval; 1514 RETVAL = THIS->option (optval);
1488 1515
1489 if (set >= 0) 1516 if (set >= 0)
1490 { 1517 {
1491 if (set)
1492 THIS->options |= optval; 1518 THIS->set_option (optval, set);
1493 else
1494 THIS->options &= ~optval;
1495 1519
1496 if (THIS->check_ev.is_active ()) // avoid doing this before START 1520 if (THIS->env_colorfgbg [0]) // avoid doing this before START
1497 switch (optval) 1521 switch (optval)
1498 { 1522 {
1499 case Opt_skipBuiltinGlyphs: 1523 case Opt_skipBuiltinGlyphs:
1500 THIS->set_fonts (); 1524 THIS->set_fonts ();
1501 THIS->scr_remap_chars (); 1525 THIS->scr_remap_chars ();
1502 THIS->scr_touch (true); 1526 THIS->scr_touch (true);
1503 THIS->want_refresh = 1; 1527 THIS->want_refresh = 1;
1528 THIS->refresh_check ();
1504 break; 1529 break;
1505 1530
1506 case Opt_cursorUnderline: 1531 case Opt_cursorUnderline:
1507 THIS->want_refresh = 1; 1532 THIS->want_refresh = 1;
1533 THIS->refresh_check ();
1508 break; 1534 break;
1509 1535
1510# case Opt_scrollBar_floating: 1536# case Opt_scrollBar_floating:
1511# case Opt_scrollBar_right: 1537# case Opt_scrollBar_right:
1512# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1538# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1545 EXTEND (SP, 2); 1571 EXTEND (SP, 2);
1546 PUSHs (sv_2mortal (newSViv (rc.row))); 1572 PUSHs (sv_2mortal (newSViv (rc.row)));
1547 PUSHs (sv_2mortal (newSViv (rc.col))); 1573 PUSHs (sv_2mortal (newSViv (rc.col)));
1548 } 1574 }
1549 1575
1550 if (items == 3) 1576 if (items >= 3)
1551 { 1577 {
1552 rc.row = SvIV (ST (1)); 1578 rc.row = SvIV (ST (1));
1553 rc.col = SvIV (ST (2)); 1579 rc.col = SvIV (ST (2));
1554 1580
1555 if (ix == 2) 1581 if (ix == 2)
1570 1596
1571 clamp_it (rc.col, 0, THIS->ncol); 1597 clamp_it (rc.col, 0, THIS->ncol);
1572 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1598 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1573 1599
1574 if (ix) 1600 if (ix)
1601 {
1602 THIS->selection.screen = THIS->current_screen;
1603
1575 THIS->want_refresh = 1; 1604 THIS->want_refresh = 1;
1605 THIS->refresh_check ();
1576 } 1606 }
1607 }
1577} 1608}
1578 1609
1579char 1610int
1580rxvt_term::cur_charset () 1611rxvt_term::selection_screen (int screen = -1)
1581 CODE: 1612 CODE:
1582 RETVAL = THIS->charsets [THIS->screen.charset]; 1613 RETVAL = THIS->selection.screen;
1583 OUTPUT: 1614 if (screen >= 0)
1615 THIS->selection.screen = screen;
1616 OUTPUT:
1584 RETVAL 1617 RETVAL
1585 1618
1586void 1619void
1587rxvt_term::selection_clear () 1620rxvt_term::selection_clear (bool clipboard = false)
1588 1621
1589void 1622void
1590rxvt_term::selection_make (Time eventtime, bool rect = false) 1623rxvt_term::selection_make (Time eventtime, bool rect = false)
1591 CODE: 1624 CODE:
1592 THIS->selection.op = SELECTION_CONT; 1625 THIS->selection.op = SELECTION_CONT;
1593 THIS->selection.rect = rect; 1626 THIS->selection.rect = rect;
1594 THIS->selection_make (eventtime); 1627 THIS->selection_make (eventtime);
1595 1628
1596int 1629int
1597rxvt_term::selection_grab (Time eventtime) 1630rxvt_term::selection_grab (Time eventtime, bool clipboard = false)
1598 1631
1599void 1632void
1600rxvt_term::selection (SV *newtext = 0) 1633rxvt_term::selection (SV *newtext = 0, bool clipboard = false)
1601 PPCODE: 1634 PPCODE:
1602{ 1635{
1636 wchar_t * &text = clipboard ? THIS->selection.clip_text : THIS->selection.text;
1637 unsigned int &len = clipboard ? THIS->selection.clip_len : THIS->selection.len;
1638
1603 if (GIMME_V != G_VOID) 1639 if (GIMME_V != G_VOID)
1604 XPUSHs (THIS->selection.text 1640 XPUSHs (text
1605 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) 1641 ? sv_2mortal (wcs2sv (text, len))
1606 : &PL_sv_undef); 1642 : &PL_sv_undef);
1607 1643
1608 if (newtext) 1644 if (newtext)
1609 { 1645 {
1610 free (THIS->selection.text); 1646 free (text);
1611 1647
1612 THIS->selection.text = sv2wcs (newtext); 1648 text = sv2wcs (newtext);
1613 THIS->selection.len = wcslen (THIS->selection.text); 1649 len = wcslen (text);
1614 } 1650 }
1615} 1651}
1652
1653char
1654rxvt_term::cur_charset ()
1655 CODE:
1656 RETVAL = THIS->charsets [THIS->screen.charset];
1657 OUTPUT:
1658 RETVAL
1616 1659
1617void 1660void
1618rxvt_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) 1661rxvt_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)
1619 1662
1620void 1663void
1642 char *str = SvPVbyte (octets, len); 1685 char *str = SvPVbyte (octets, len);
1643 C_ARGS: 1686 C_ARGS:
1644 str, len 1687 str, len
1645 1688
1646void 1689void
1690rxvt_term::tt_paste (SV *octets)
1691 INIT:
1692 STRLEN len;
1693 char *str = SvPVbyte (octets, len);
1694 C_ARGS:
1695 str, len
1696
1697void
1647rxvt_term::cmd_parse (SV *octets) 1698rxvt_term::cmd_parse (SV *octets)
1648 CODE: 1699 CODE:
1649{ 1700{
1650 STRLEN len; 1701 STRLEN len;
1651 char *str = SvPVbyte (octets, len); 1702 char *str = SvPVbyte (octets, len);
1687 Atom *props = XListProperties (THIS->dpy, window, &count); 1738 Atom *props = XListProperties (THIS->dpy, window, &count);
1688 1739
1689 EXTEND (SP, count); 1740 EXTEND (SP, count);
1690 while (count--) 1741 while (count--)
1691 PUSHs (newSVuv ((U32)props [count])); 1742 PUSHs (newSVuv ((U32)props [count]));
1692 1743
1693 XFree (props); 1744 XFree (props);
1694} 1745}
1695 1746
1696void 1747void
1697rxvt_term::XGetWindowProperty (Window window, Atom property) 1748rxvt_term::XGetWindowProperty (Window window, Atom property)
1720 XFree (prop); 1771 XFree (prop);
1721 } 1772 }
1722} 1773}
1723 1774
1724void 1775void
1725rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data) 1776rxvt_term::XChangeProperty (Window window, Atom property, Atom type, int format, SV *data)
1726 CODE: 1777 CODE:
1727{ 1778{
1728 STRLEN len; 1779 STRLEN len;
1729 char *data_ = SvPVbyte (data, len); 1780 char *data_ = SvPVbyte (data, len);
1730 1781

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines