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.120 by root, Fri Jan 25 16:04:57 2008 UTC vs.
Revision 1.153 by sf-exg, Wed Apr 11 10:20:00 2012 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-2008 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.
23#define line_t perl_line_t 23#define line_t perl_line_t
24#include <EXTERN.h> 24#include <EXTERN.h>
25#include <perl.h> 25#include <perl.h>
26#include <XSUB.h> 26#include <XSUB.h>
27#undef line_t 27#undef line_t
28#undef bool // perl defines it's own bool type, except with g++... what a trap
28 29
29#include "../config.h" 30#include "../config.h"
30 31
31#include <cstddef> 32#include <stddef.h>
32#include <cstdarg> 33#include <stdarg.h>
33 34
34#include "unistd.h" 35#include "unistd.h"
35 36
36#include "ev_cpp.h" 37#include "ev_cpp.h"
37#include "rxvt.h" 38#include "rxvt.h"
39#include "rxvtutil.h" 40#include "rxvtutil.h"
40#include "rxvtperl.h" 41#include "rxvtperl.h"
41 42
42#include "perlxsi.c" 43#include "perlxsi.c"
43 44
44#ifdef HAVE_SCROLLBARS
45# define GRAB_CURSOR THIS->scrollBar.leftptr_cursor 45#define GRAB_CURSOR THIS->scrollBar.leftptr_cursor
46#else
47# define GRAB_CURSOR None
48#endif
49 46
50#undef LINENO 47#undef LINENO
51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 48#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
52#undef ROW 49#undef ROW
53#define ROW(n) THIS->row_buf [LINENO (n)] 50#define ROW(n) THIS->row_buf [LINENO (n)]
111 108
112///////////////////////////////////////////////////////////////////////////// 109/////////////////////////////////////////////////////////////////////////////
113 110
114#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 111#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
115 112
116class overlay { 113class overlay : overlay_base
114{
117 rxvt_term *THIS; 115 rxvt_term *THIS;
118 AV *overlay_av; 116 AV *overlay_av;
119 int x, y, w, h;
120 int border; 117 int border;
121 text_t **text;
122 rend_t **rend;
123 118
124public: 119public:
125 HV *self; 120 HV *self;
126 121
127 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); 122 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
134 129
135 void set (int x, int y, SV *str, SV *rend); 130 void set (int x, int y, SV *str, SV *rend);
136}; 131};
137 132
138overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 133overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
139: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0) 134: THIS(THIS), border(border == 2), overlay_av (0)
140{ 135{
136 x = x_;
137 y = y_;
138 w = w_;
139 h = h_;
140
141 if (w < 0) w = 0; 141 if (w < 0) w = 0;
142 if (h < 0) h = 0; 142 if (h < 0) h = 0;
143 143
144 if (border == 2) 144 if (border == 2)
145 { 145 {
249 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); 249 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
250 250
251 int ov_w = min (w, THIS->ncol - ov_x); 251 int ov_w = min (w, THIS->ncol - ov_x);
252 int ov_h = min (h, THIS->nrow - ov_y); 252 int ov_h = min (h, THIS->nrow - ov_y);
253 253
254 // hide cursor if it is within the overlay area
255 if (IN_RANGE_EXC (THIS->screen.cur.col - ov_x, 0, ov_w)
256 && IN_RANGE_EXC (THIS->screen.cur.row - ov_y, 0, ov_h))
257 THIS->screen.flags &= ~Screen_VisibleCursor;
258
254 for (int y = ov_h; y--; ) 259 for (int y = ov_h; y--; )
255 { 260 {
256 text_t *t1 = text [y]; 261 text_t *t1 = text [y];
257 rend_t *r1 = rend [y]; 262 rend_t *r1 = rend [y];
258 263
298 THIS->refresh_check (); 303 THIS->refresh_check ();
299} 304}
300 305
301///////////////////////////////////////////////////////////////////////////// 306/////////////////////////////////////////////////////////////////////////////
302 307
303#define IOM_CLASS "urxvt"
304#define IOM_WARN rxvt_warn
305#include "iom_perl.h" 308#include "iom_perl.h"
306 309
307///////////////////////////////////////////////////////////////////////////// 310/////////////////////////////////////////////////////////////////////////////
308 311
309struct rxvt_perl_interp rxvt_perl; 312struct rxvt_perl_interp rxvt_perl;
314{ 317{
315 if (perl) 318 if (perl)
316 { 319 {
317 perl_destruct (perl); 320 perl_destruct (perl);
318 perl_free (perl); 321 perl_free (perl);
322 PERL_SYS_TERM ();
319 } 323 }
320} 324}
321 325
322void 326void
323rxvt_perl_interp::init (rxvt_term *term) 327rxvt_perl_interp::init (rxvt_term *term)
324{ 328{
325 if (!perl) 329 if (!perl)
326 { 330 {
327 rxvt_push_locale (""); // perl init destroys current locale 331 rxvt_push_locale (""); // perl init destroys current locale
328 332
333 {
329 perl_environ = rxvt_environ; 334 perl_environ = rxvt_environ;
330 swap (perl_environ, environ); 335 localise_env set_environ (perl_environ);
331 336
332 char *argv[] = { 337 char *args[] = {
333 "", 338 "",
334 "-e" 339 "-e"
335 "BEGIN {" 340 "BEGIN {"
336 " urxvt->bootstrap;" 341 " urxvt->bootstrap;"
337 " unshift @INC, '" LIBDIR "';" 342 " unshift @INC, '" LIBDIR "';"
338 "}" 343 "}"
339 "" 344 ""
340 "use urxvt;" 345 "use urxvt;"
341 }; 346 };
347 int argc = ecb_array_length (args);
348 char **argv = args;
342 349
350 PERL_SYS_INIT3 (&argc, &argv, &environ);
343 perl = perl_alloc (); 351 perl = perl_alloc ();
344 perl_construct (perl); 352 perl_construct (perl);
345 353
346 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 354 if (perl_parse (perl, xs_init, argc, argv, (char **)NULL)
347 || perl_run (perl)) 355 || perl_run (perl))
348 { 356 {
349 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 357 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
350 358
351 perl_destruct (perl); 359 perl_destruct (perl);
352 perl_free (perl); 360 perl_free (perl);
353 perl = 0; 361 perl = 0;
354 } 362 }
355 363 }
356 swap (perl_environ, environ);
357 364
358 rxvt_pop_locale (); 365 rxvt_pop_locale ();
359 } 366 }
360 367
361 if (perl) 368 if (perl)
362 { 369 {
363 // runs outside of perls ENV 370 // runs outside of perls ENV
364 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 371 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
365 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0); 372 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0);
373 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, newRV_noinc ((SV *)newAV ()), 0);
366 } 374 }
367} 375}
368 376
369static void 377static void
370ungrab (rxvt_term *THIS) 378ungrab (rxvt_term *THIS)
381rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) 389rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
382{ 390{
383 if (!perl || !term->perl.self) 391 if (!perl || !term->perl.self)
384 return false; 392 return false;
385 393
394 localise_env set_environ (perl_environ);
395
386 // pre-handling of some events 396 // pre-handling of some events
387 if (htype == HOOK_REFRESH_END) 397 if (htype == HOOK_REFRESH_END)
388 { 398 {
389 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 399 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
390 400
391 for (int i = 0; i <= AvFILL (av); i++) 401 for (int i = 0; i <= AvFILL (av); i++)
392 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 402 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
393 } 403 }
404 else if (htype == HOOK_DESTROY)
405 {
406 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
394 407
395 swap (perl_environ, environ); 408 for (int i = AvFILL (av); i >= 0; i--)
409 {
410 rxvt_selection *req = (rxvt_selection *)SvIV (*av_fetch (av, i, 0));
411 delete req;
412 }
413 }
396 414
397 bool event_consumed; 415 bool event_consumed;
398 416
399 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always 417 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
400 || term->perl.should_invoke [htype]) 418 || term->perl.should_invoke [htype])
401 try
402 { 419 {
403 dSP; 420 dSP;
404 va_list ap; 421 va_list ap;
405 422
406 va_start (ap, htype); 423 va_start (ap, htype);
407 424
408 ENTER; 425 ENTER;
409 SAVETMPS; 426 SAVETMPS;
410 427
411 PUSHMARK (SP); 428 PUSHMARK (SP);
412 429
430 EXTEND (SP, 2);
413 XPUSHs (sv_2mortal (newSVterm (term))); 431 PUSHs (sv_2mortal (newSVterm (term)));
414 XPUSHs (sv_2mortal (newSViv (htype))); 432 PUSHs (sv_2mortal (newSViv (htype)));
415 433
416 for (;;) { 434 for (;;) {
417 data_type dt = (data_type)va_arg (ap, int); 435 data_type dt = (data_type)va_arg (ap, int);
418 436
419 switch (dt) 437 switch (dt)
420 { 438 {
421 case DT_INT: 439 case DT_INT:
422 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); 440 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
423 break; 441 break;
424 442
425 case DT_LONG: 443 case DT_LONG:
426 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); 444 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
427 break; 445 break;
428 446
429 case DT_STR: 447 case DT_STR:
430 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); 448 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
431 break; 449 break;
432 450
433 case DT_STR_LEN: 451 case DT_STR_LEN:
434 { 452 {
435 char *str = va_arg (ap, char *); 453 char *str = va_arg (ap, char *);
436 int len = va_arg (ap, int); 454 int len = va_arg (ap, int);
437 455
438 XPUSHs (sv_2mortal (newSVpvn (str, len))); 456 XPUSHs (sv_2mortal (newSVpvn (str, len)));
439 } 457 }
440 break; 458 break;
441 459
442 case DT_WCS_LEN: 460 case DT_WCS_LEN:
443 { 461 {
444 wchar_t *wstr = va_arg (ap, wchar_t *); 462 wchar_t *wstr = va_arg (ap, wchar_t *);
445 int wlen = va_arg (ap, int); 463 int wlen = va_arg (ap, int);
446 464
447 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 465 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
448 } 466 }
449 break; 467 break;
450 468
451 case DT_LCS_LEN: 469 case DT_LCS_LEN:
452 { 470 {
453 long *lstr = va_arg (ap, long *); 471 long *lstr = va_arg (ap, long *);
454 int llen = va_arg (ap, int); 472 int llen = va_arg (ap, int);
455 473
456 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long)))); 474 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long))));
457 } 475 }
458 break; 476 break;
459 477
460 case DT_XEVENT: 478 case DT_XEVENT:
461 { 479 {
462 XEvent *xe = va_arg (ap, XEvent *); 480 XEvent *xe = va_arg (ap, XEvent *);
463 HV *hv = newHV (); 481 HV *hv = newHV ();
464 482
465# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 483# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
466# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) 484# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
467# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) 485# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
468# undef set 486# undef set
469 487
470 setiv (type, xe->type); 488 setiv (type, xe->type);
471 setiv (send_event, xe->xany.send_event); 489 setiv (send_event, xe->xany.send_event);
472 setiv (serial, xe->xany.serial); 490 setiv (serial, xe->xany.serial);
473 491
474 switch (xe->type) 492 switch (xe->type)
475 { 493 {
476 case KeyPress: 494 case KeyPress:
477 case KeyRelease: 495 case KeyRelease:
478 case ButtonPress: 496 case ButtonPress:
479 case ButtonRelease: 497 case ButtonRelease:
480 case MotionNotify: 498 case MotionNotify:
481 setuv (window, xe->xmotion.window); 499 setuv (window, xe->xmotion.window);
482 setuv (root, xe->xmotion.root); 500 setuv (root, xe->xmotion.root);
483 setuv (subwindow, xe->xmotion.subwindow); 501 setuv (subwindow, xe->xmotion.subwindow);
484 setuv (time, xe->xmotion.time); 502 setuv (time, xe->xmotion.time);
485 setiv (x, xe->xmotion.x); 503 setiv (x, xe->xmotion.x);
486 setiv (y, xe->xmotion.y); 504 setiv (y, xe->xmotion.y);
487 setiv (row, xe->xmotion.y / term->fheight + term->view_start); 505 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
488 setiv (col, xe->xmotion.x / term->fwidth); 506 setiv (col, xe->xmotion.x / term->fwidth);
489 setiv (x_root, xe->xmotion.x_root); 507 setiv (x_root, xe->xmotion.x_root);
490 setiv (y_root, xe->xmotion.y_root); 508 setiv (y_root, xe->xmotion.y_root);
491 setuv (state, xe->xmotion.state); 509 setuv (state, xe->xmotion.state);
492 510
493 switch (xe->type) 511 switch (xe->type)
494 { 512 {
495 case KeyPress: 513 case KeyPress:
496 case KeyRelease: 514 case KeyRelease:
497 setuv (keycode, xe->xkey.keycode); 515 setuv (keycode, xe->xkey.keycode);
498 break; 516 break;
499 517
500 case ButtonPress: 518 case ButtonPress:
501 case ButtonRelease: 519 case ButtonRelease:
502 setuv (button, xe->xbutton.button); 520 setuv (button, xe->xbutton.button);
503 break; 521 break;
504 522
505 case MotionNotify: 523 case MotionNotify:
506 setiv (is_hint, xe->xmotion.is_hint); 524 setiv (is_hint, xe->xmotion.is_hint);
507 break; 525 break;
508 } 526 }
509 527
510 break; 528 break;
511 529
512 case MapNotify: 530 case MapNotify:
513 case UnmapNotify: 531 case UnmapNotify:
514 case ConfigureNotify: 532 case ConfigureNotify:
515 setuv (event, xe->xconfigure.event); 533 setuv (event, xe->xconfigure.event);
516 setuv (window, xe->xconfigure.window); 534 setuv (window, xe->xconfigure.window);
517 535
518 switch (xe->type) 536 switch (xe->type)
519 { 537 {
520 case ConfigureNotify: 538 case ConfigureNotify:
521 setiv (x, xe->xconfigure.x); 539 setiv (x, xe->xconfigure.x);
522 setiv (y, xe->xconfigure.y); 540 setiv (y, xe->xconfigure.y);
523 setiv (width, xe->xconfigure.width); 541 setiv (width, xe->xconfigure.width);
524 setiv (height, xe->xconfigure.height); 542 setiv (height, xe->xconfigure.height);
525 setuv (above, xe->xconfigure.above); 543 setuv (above, xe->xconfigure.above);
526 break; 544 break;
527 } 545 }
528 546
529 break; 547 break;
530 548
531 case PropertyNotify: 549 case PropertyNotify:
532 setuv (window, xe->xproperty.window); 550 setuv (window, xe->xproperty.window);
533 setuv (atom, xe->xproperty.atom); 551 setuv (atom, xe->xproperty.atom);
534 setuv (time, xe->xproperty.time); 552 setuv (time, xe->xproperty.time);
535 setiv (state, xe->xproperty.state); 553 setiv (state, xe->xproperty.state);
536 break; 554 break;
537 555
538 case ClientMessage: 556 case ClientMessage:
539 setuv (window, xe->xclient.window); 557 setuv (window, xe->xclient.window);
540 setuv (message_type, xe->xclient.message_type); 558 setuv (message_type, xe->xclient.message_type);
541 setuv (format, xe->xclient.format); 559 setuv (format, xe->xclient.format);
542 setuv (l0, xe->xclient.data.l[0]); 560 setuv (l0, xe->xclient.data.l[0]);
543 setuv (l1, xe->xclient.data.l[1]); 561 setuv (l1, xe->xclient.data.l[1]);
544 setuv (l2, xe->xclient.data.l[2]); 562 setuv (l2, xe->xclient.data.l[2]);
545 setuv (l3, xe->xclient.data.l[3]); 563 setuv (l3, xe->xclient.data.l[3]);
546 setuv (l4, xe->xclient.data.l[4]); 564 setuv (l4, xe->xclient.data.l[4]);
547 break; 565 break;
548 } 566 }
549 567
550 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 568 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
551 } 569 }
552 break; 570 break;
553 571
554 case DT_END: 572 case DT_END:
555 goto call; 573 goto call;
556 574
557 default: 575 default:
558 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); 576 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
559 } 577 }
578 }
579
580 call:
581 va_end (ap);
582
583 PUTBACK;
584 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
585 SPAGAIN;
586
587 if (count)
588 {
589 SV *status = POPs;
590 count = SvTRUE (status);
560 } 591 }
561 592
562 call:
563 va_end (ap);
564
565 PUTBACK; 593 PUTBACK;
566 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
567 SPAGAIN;
568
569 if (count)
570 {
571 SV *status = POPs;
572 count = SvTRUE (status);
573 }
574
575 PUTBACK;
576 FREETMPS; 594 FREETMPS;
577 LEAVE; 595 LEAVE;
578 596
579 if (SvTRUE (ERRSV)) 597 if (SvTRUE (ERRSV))
580 { 598 {
581 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 599 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPVbyte_nolen (ERRSV));
582 ungrab (term); // better lose the grab than the session 600 ungrab (term); // better lose the grab than the session
583 } 601 }
584 602
585 event_consumed = !!count; 603 event_consumed = !!count;
586 } 604 }
587 catch (...)
588 {
589 swap (perl_environ, environ);
590 throw;
591 }
592 else 605 else
593 event_consumed = false; 606 event_consumed = false;
594 607
595 // post-handling of some events 608 // post-handling of some events
596 if (htype == HOOK_REFRESH_BEGIN) 609 if (htype == HOOK_REFRESH_BEGIN)
607 620
608 // don't allow further calls 621 // don't allow further calls
609 term->perl.self = 0; 622 term->perl.self = 0;
610 } 623 }
611 624
612 swap (perl_environ, environ);
613
614 return event_consumed; 625 return event_consumed;
626}
627
628void
629rxvt_perl_interp::selection_finish (rxvt_selection *sel, char *data, unsigned int len)
630{
631 localise_env set_environ (perl_environ);
632
633 ENTER;
634 SAVETMPS;
635
636 dSP;
637 XPUSHs (sv_2mortal (newSVpvn (data, len)));
638 call_sv ((SV *)sel->cb_sv, G_VOID | G_DISCARD | G_EVAL);
639
640 if (SvTRUE (ERRSV))
641 rxvt_warn ("perl selection callback evaluation error: %s", SvPVbyte_nolen (ERRSV));
642
643 FREETMPS;
644 LEAVE;
615} 645}
616 646
617///////////////////////////////////////////////////////////////////////////// 647/////////////////////////////////////////////////////////////////////////////
618 648
619MODULE = urxvt PACKAGE = urxvt 649MODULE = urxvt PACKAGE = urxvt
631# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); 661# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
632# include "hookinc.h" 662# include "hookinc.h"
633# undef def 663# undef def
634 664
635 HV *option = get_hv ("urxvt::OPTION", 1); 665 HV *option = get_hv ("urxvt::OPTION", 1);
636# define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); 666# define def(name) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
637# define nodef(name) 667# define nodef(name)
638# include "optinc.h" 668# include "optinc.h"
639# undef nodef 669# undef nodef
640# undef def 670# undef def
641 671
643 static const struct { 673 static const struct {
644 const char *name; 674 const char *name;
645 IV iv; 675 IV iv;
646 } *civ, const_iv[] = { 676 } *civ, const_iv[] = {
647# define const_iv(name) { # name, (IV)name } 677# define const_iv(name) { # name, (IV)name }
678 const_iv (NUM_RESOURCES),
648 const_iv (DEFAULT_RSTYLE), 679 const_iv (DEFAULT_RSTYLE),
649 const_iv (OVERLAY_RSTYLE), 680 const_iv (OVERLAY_RSTYLE),
681 const_iv (Color_Bits),
682 const_iv (RS_bgShift), const_iv (RS_bgMask),
683 const_iv (RS_fgShift), const_iv (RS_fgMask),
684 const_iv (RS_Careful),
685 const_iv (RS_fontCount),
686 const_iv (RS_fontShift),
687 const_iv (RS_fontMask),
688 const_iv (RS_baseattrMask),
689 const_iv (RS_attrMask),
690 const_iv (RS_redraw),
691 const_iv (RS_Sel),
650 const_iv (RS_Bold), 692 const_iv (RS_Bold),
651 const_iv (RS_Italic), 693 const_iv (RS_Italic),
652 const_iv (RS_Blink), 694 const_iv (RS_Blink),
653 const_iv (RS_RVid), 695 const_iv (RS_RVid),
654 const_iv (RS_Uline), 696 const_iv (RS_Uline),
758 const_iv (XIMDontChange), 800 const_iv (XIMDontChange),
759# endif 801# endif
760# endif 802# endif
761 }; 803 };
762 804
763 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 805 for (civ = const_iv + ecb_array_length (const_iv); civ > const_iv; civ--)
764 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 806 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
765} 807}
766 808
767void 809void
768warn (const char *msg) 810warn (const char *msg)
769 CODE: 811 CODE:
841 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) 883 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
842 if ((*t)->perl.self) 884 if ((*t)->perl.self)
843 PUSHs (sv_2mortal (newSVterm (*t))); 885 PUSHs (sv_2mortal (newSVterm (*t)));
844} 886}
845 887
888IV
889_new_selection_request (rxvt_term *term, int selnum, Time tm, Window win, Atom prop, SV *cb)
890 CODE:
891 rxvt_selection *req = new rxvt_selection (term->display, selnum, tm, win, prop, term);
892 req->cb_sv = newSVsv (cb);
893 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
894 av_push (av, newSViv ((IV)req));
895 RETVAL = (IV)req;
896 OUTPUT:
897 RETVAL
898
899void
900_delete_selection_request (IV req_)
901 CODE:
902 rxvt_selection *req = (rxvt_selection *)req_;
903 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)req->term->perl.self), "_selection", 10, 0));
904 int i;
905
906 for (i = AvFILL (av); i >= 0; i--)
907 if (SvIV (*av_fetch (av, i, 1)) == req_)
908 break;
909
910 for (; i < AvFILL (av); i++)
911 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0)));
912
913 av_pop (av);
914
915 delete req;
916
846MODULE = urxvt PACKAGE = urxvt::term 917MODULE = urxvt PACKAGE = urxvt::term
847 918
848SV * 919SV *
849_new (AV *env, AV *arg) 920_new (AV *env, AV *arg)
850 CODE: 921 CODE:
851{ 922{
852 rxvt_term *term = new rxvt_term; 923 rxvt_term *term = new rxvt_term;
853 924
854 stringvec *argv = new stringvec; 925 stringvec *argv = new stringvec;
855 stringvec *envv = new stringvec;
856
857 for (int i = 0; i <= AvFILL (arg); i++) 926 for (int i = 0; i <= AvFILL (arg); i++)
858 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1)))); 927 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
859 928
929 stringvec *envv = new stringvec;
860 for (int i = AvFILL (env) + 1; i--; ) 930 for (int i = AvFILL (env) + 1; i--; )
861 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 931 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
862
863 envv->push_back (0);
864 932
865 try 933 try
866 { 934 {
867 term->init (argv, envv); 935 term->init (argv, envv);
868 } 936 }
908 976
909void 977void
910rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt) 978rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt)
911 CODE: 979 CODE:
912 XUngrabKey (THIS->dpy, keycode, modifiers, window); 980 XUngrabKey (THIS->dpy, keycode, modifiers, window);
913
914void
915rxvt_term::XUngrabKeyboard (Time eventtime)
916 CODE:
917 XUngrabKeyboard (THIS->dpy, eventtime);
918 981
919bool 982bool
920rxvt_term::grab (Time eventtime, int sync = 0) 983rxvt_term::grab (Time eventtime, int sync = 0)
921 CODE: 984 CODE:
922{ 985{
1037 free (wstr); 1100 free (wstr);
1038} 1101}
1039 OUTPUT: 1102 OUTPUT:
1040 RETVAL 1103 RETVAL
1041 1104
1042char *
1043rxvt_term::locale ()
1044 CODE:
1045 RETVAL = THIS->locale;
1046 OUTPUT:
1047 RETVAL
1048
1049#define TERM_OFFSET(sym) offsetof (TermWin_t, sym) 1105#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
1050 1106
1051#define TERM_OFFSET_width TERM_OFFSET(width) 1107#define TERM_OFFSET_width TERM_OFFSET(width)
1052#define TERM_OFFSET_height TERM_OFFSET(height) 1108#define TERM_OFFSET_height TERM_OFFSET(height)
1053#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 1109#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
1054#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 1110#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
1055#define TERM_OFFSET_fbase TERM_OFFSET(fbase) 1111#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1056#define TERM_OFFSET_nrow TERM_OFFSET(nrow) 1112#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1057#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1113#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1058#define TERM_OFFSET_focus TERM_OFFSET(focus) 1114#define TERM_OFFSET_focus TERM_OFFSET(focus)
1059#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1115#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
1060#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth) 1116#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth)
1061#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth) 1117#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth)
1062#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace) 1118#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace)
1119#define TERM_OFFSET_letterSpace TERM_OFFSET(letterSpace)
1063#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1120#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1064#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1121#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1065#define TERM_OFFSET_top_row TERM_OFFSET(top_row) 1122#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1066 1123
1067int 1124int
1068rxvt_term::width () 1125rxvt_term::width ()
1069 ALIAS: 1126 ALIAS:
1070 width = TERM_OFFSET_width 1127 width = TERM_OFFSET_width
1071 height = TERM_OFFSET_height 1128 height = TERM_OFFSET_height
1072 fwidth = TERM_OFFSET_fwidth 1129 fwidth = TERM_OFFSET_fwidth
1073 fheight = TERM_OFFSET_fheight 1130 fheight = TERM_OFFSET_fheight
1074 fbase = TERM_OFFSET_fbase 1131 fbase = TERM_OFFSET_fbase
1075 nrow = TERM_OFFSET_nrow 1132 nrow = TERM_OFFSET_nrow
1076 ncol = TERM_OFFSET_ncol 1133 ncol = TERM_OFFSET_ncol
1077 focus = TERM_OFFSET_focus 1134 focus = TERM_OFFSET_focus
1078 mapped = TERM_OFFSET_mapped 1135 mapped = TERM_OFFSET_mapped
1079 int_bwidth = TERM_OFFSET_int_bwidth 1136 int_bwidth = TERM_OFFSET_int_bwidth
1080 ext_bwidth = TERM_OFFSET_ext_bwidth 1137 ext_bwidth = TERM_OFFSET_ext_bwidth
1081 lineSpace = TERM_OFFSET_lineSpace 1138 lineSpace = TERM_OFFSET_lineSpace
1139 letterSpace = TERM_OFFSET_letterSpace
1082 saveLines = TERM_OFFSET_saveLines 1140 saveLines = TERM_OFFSET_saveLines
1083 total_rows = TERM_OFFSET_total_rows 1141 total_rows = TERM_OFFSET_total_rows
1084 top_row = TERM_OFFSET_top_row 1142 top_row = TERM_OFFSET_top_row
1085 CODE: 1143 CODE:
1086 RETVAL = *(int *)((char *)THIS + ix); 1144 RETVAL = *(int *)((char *)THIS + ix);
1087 OUTPUT: 1145 OUTPUT:
1088 RETVAL 1146 RETVAL
1089 1147
1100 { 1158 {
1101 case 0: RETVAL = THIS->ModLevel3Mask; break; 1159 case 0: RETVAL = THIS->ModLevel3Mask; break;
1102 case 1: RETVAL = THIS->ModMetaMask; break; 1160 case 1: RETVAL = THIS->ModMetaMask; break;
1103 case 2: RETVAL = THIS->ModNumLockMask; break; 1161 case 2: RETVAL = THIS->ModNumLockMask; break;
1104 case 3: RETVAL = THIS->current_screen; break; 1162 case 3: RETVAL = THIS->current_screen; break;
1163#ifdef CURSOR_BLINK
1105 case 4: RETVAL = THIS->hidden_cursor; break; 1164 case 4: RETVAL = THIS->hidden_cursor; break;
1165#endif
1106 } 1166 }
1107 OUTPUT: 1167 OUTPUT:
1108 RETVAL 1168 RETVAL
1109 1169
1110char * 1170char *
1153 RETVAL 1213 RETVAL
1154 1214
1155Window 1215Window
1156rxvt_term::parent () 1216rxvt_term::parent ()
1157 CODE: 1217 CODE:
1158 RETVAL = THIS->parent [0]; 1218 RETVAL = THIS->parent;
1159 OUTPUT: 1219 OUTPUT:
1160 RETVAL 1220 RETVAL
1161 1221
1162Window 1222Window
1163rxvt_term::vt () 1223rxvt_term::vt ()
1190 if (newval <= 0) 1250 if (newval <= 0)
1191 THIS->scr_changeview (max (newval, THIS->top_row)); 1251 THIS->scr_changeview (max (newval, THIS->top_row));
1192} 1252}
1193 OUTPUT: 1253 OUTPUT:
1194 RETVAL 1254 RETVAL
1255
1256void
1257rxvt_term::set_urgency (bool enable)
1195 1258
1196void 1259void
1197rxvt_term::focus_in () 1260rxvt_term::focus_in ()
1198 1261
1199void 1262void
1432# include "rsinc.h" 1495# include "rsinc.h"
1433# undef def 1496# undef def
1434# undef reserve 1497# undef reserve
1435 }; 1498 };
1436 1499
1437 rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1500 rs = rslist + ecb_array_length (rslist);
1438 1501
1502 if (*name)
1439 do { 1503 {
1504 do {
1440 if (rs-- == rslist) 1505 if (rs-- == rslist)
1441 croak ("no such resource '%s', requested", name); 1506 croak ("no such resource '%s', requested", name);
1442 } while (strcmp (name, rs->name)); 1507 } while (strcmp (name, rs->name));
1443 1508
1444 index += rs->value; 1509 index += rs->value;
1510 }
1511 else
1512 {
1513 --rs;
1514 name = "";
1515 }
1445 1516
1446 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1517 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1447 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1518 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1448 1519
1449 if (GIMME_V != G_VOID) 1520 if (GIMME_V != G_VOID)
1473 1544
1474 if (set >= 0) 1545 if (set >= 0)
1475 { 1546 {
1476 THIS->set_option (optval, set); 1547 THIS->set_option (optval, set);
1477 1548
1478 if (THIS->env_colorfgbg [0]) // avoid doing this before START 1549 if (THIS->init_done) // avoid doing this before START
1479 switch (optval) 1550 switch (optval)
1480 { 1551 {
1481 case Opt_skipBuiltinGlyphs: 1552 case Opt_skipBuiltinGlyphs:
1482 THIS->set_fonts (); 1553 THIS->set_fonts ();
1483 THIS->scr_remap_chars (); 1554 THIS->scr_remap_chars ();
1484 THIS->scr_touch (true); 1555 THIS->scr_touch (true);
1485 THIS->want_refresh = 1; 1556 THIS->want_refresh = 1;
1486 THIS->refresh_check (); 1557 THIS->refresh_check ();
1487 break; 1558 break;
1488 1559
1560#ifdef CURSOR_BLINK
1561 case Opt_cursorBlink:
1562 THIS->cursor_blink_reset ();
1563 break;
1564#endif
1565
1489 case Opt_cursorUnderline: 1566 case Opt_cursorUnderline:
1490 THIS->want_refresh = 1; 1567 THIS->want_refresh = 1;
1491 THIS->refresh_check (); 1568 THIS->refresh_check ();
1492 break; 1569 break;
1493 1570
1506 CODE: 1583 CODE:
1507 RETVAL = 0 < THIS->parse_keysym (keysym, str); 1584 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1508 THIS->keyboard->register_done (); 1585 THIS->keyboard->register_done ();
1509 OUTPUT: 1586 OUTPUT:
1510 RETVAL 1587 RETVAL
1588
1589void
1590rxvt_term::register_command (int keysym, unsigned int state, SV *str)
1591 CODE:
1592 wchar_t *wstr = sv2wcs (str);
1593 THIS->keyboard->register_user_translation (keysym, state, wstr);
1594 free (wstr);
1511 1595
1512void 1596void
1513rxvt_term::screen_cur (...) 1597rxvt_term::screen_cur (...)
1514 PROTOTYPE: $;$$ 1598 PROTOTYPE: $;$$
1515 ALIAS: 1599 ALIAS:
1529 EXTEND (SP, 2); 1613 EXTEND (SP, 2);
1530 PUSHs (sv_2mortal (newSViv (rc.row))); 1614 PUSHs (sv_2mortal (newSViv (rc.row)));
1531 PUSHs (sv_2mortal (newSViv (rc.col))); 1615 PUSHs (sv_2mortal (newSViv (rc.col)));
1532 } 1616 }
1533 1617
1534 if (items == 3) 1618 if (items >= 3)
1535 { 1619 {
1536 rc.row = SvIV (ST (1)); 1620 rc.row = SvIV (ST (1));
1537 rc.col = SvIV (ST (2)); 1621 rc.col = SvIV (ST (2));
1538 1622
1539 if (ix == 2) 1623 if (ix == 2)
1555 clamp_it (rc.col, 0, THIS->ncol); 1639 clamp_it (rc.col, 0, THIS->ncol);
1556 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1640 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1557 1641
1558 if (ix) 1642 if (ix)
1559 { 1643 {
1644 THIS->selection.screen = THIS->current_screen;
1645
1560 THIS->want_refresh = 1; 1646 THIS->want_refresh = 1;
1561 THIS->refresh_check (); 1647 THIS->refresh_check ();
1562 } 1648 }
1563 } 1649 }
1564} 1650}
1565 1651
1566char 1652int
1567rxvt_term::cur_charset () 1653rxvt_term::selection_screen (int screen = -1)
1568 CODE: 1654 CODE:
1569 RETVAL = THIS->charsets [THIS->screen.charset]; 1655 RETVAL = THIS->selection.screen;
1570 OUTPUT: 1656 if (screen >= 0)
1657 THIS->selection.screen = screen;
1658 OUTPUT:
1571 RETVAL 1659 RETVAL
1572 1660
1573void 1661void
1574rxvt_term::selection_clear () 1662rxvt_term::selection_clear (bool clipboard = false)
1575 1663
1576void 1664void
1577rxvt_term::selection_make (Time eventtime, bool rect = false) 1665rxvt_term::selection_make (Time eventtime, bool rect = false)
1578 CODE: 1666 CODE:
1579 THIS->selection.op = SELECTION_CONT; 1667 THIS->selection.op = SELECTION_CONT;
1580 THIS->selection.rect = rect; 1668 THIS->selection.rect = rect;
1581 THIS->selection_make (eventtime); 1669 THIS->selection_make (eventtime);
1582 1670
1583int 1671int
1584rxvt_term::selection_grab (Time eventtime) 1672rxvt_term::selection_grab (Time eventtime, bool clipboard = false)
1585 1673
1586void 1674void
1587rxvt_term::selection (SV *newtext = 0) 1675rxvt_term::selection (SV *newtext = 0, bool clipboard = false)
1588 PPCODE: 1676 PPCODE:
1589{ 1677{
1678 wchar_t * &text = clipboard ? THIS->selection.clip_text : THIS->selection.text;
1679 unsigned int &len = clipboard ? THIS->selection.clip_len : THIS->selection.len;
1680
1590 if (GIMME_V != G_VOID) 1681 if (GIMME_V != G_VOID)
1591 XPUSHs (THIS->selection.text 1682 XPUSHs (text
1592 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) 1683 ? sv_2mortal (wcs2sv (text, len))
1593 : &PL_sv_undef); 1684 : &PL_sv_undef);
1594 1685
1595 if (newtext) 1686 if (newtext)
1596 { 1687 {
1597 free (THIS->selection.text); 1688 free (text);
1598 1689
1599 THIS->selection.text = sv2wcs (newtext); 1690 text = sv2wcs (newtext);
1600 THIS->selection.len = wcslen (THIS->selection.text); 1691 len = wcslen (text);
1601 } 1692 }
1602} 1693}
1694
1695char
1696rxvt_term::cur_charset ()
1697 CODE:
1698 RETVAL = THIS->charsets [THIS->screen.charset];
1699 OUTPUT:
1700 RETVAL
1603 1701
1604void 1702void
1605rxvt_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) 1703rxvt_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)
1606 1704
1607void 1705void
1629 char *str = SvPVbyte (octets, len); 1727 char *str = SvPVbyte (octets, len);
1630 C_ARGS: 1728 C_ARGS:
1631 str, len 1729 str, len
1632 1730
1633void 1731void
1732rxvt_term::tt_paste (SV *octets)
1733 INIT:
1734 STRLEN len;
1735 char *str = SvPVbyte (octets, len);
1736 C_ARGS:
1737 str, len
1738
1739void
1634rxvt_term::cmd_parse (SV *octets) 1740rxvt_term::cmd_parse (SV *octets)
1635 CODE: 1741 CODE:
1636{ 1742{
1637 STRLEN len; 1743 STRLEN len;
1638 char *str = SvPVbyte (octets, len); 1744 char *str = SvPVbyte (octets, len);
1707 XFree (prop); 1813 XFree (prop);
1708 } 1814 }
1709} 1815}
1710 1816
1711void 1817void
1712rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data) 1818rxvt_term::XChangeProperty (Window window, Atom property, Atom type, int format, SV *data)
1713 CODE: 1819 CODE:
1714{ 1820{
1715 STRLEN len; 1821 STRLEN len;
1716 char *data_ = SvPVbyte (data, len); 1822 char *data_ = SvPVbyte (data, len);
1717 1823

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines