… | |
… | |
29 | #include "../config.h" |
29 | #include "../config.h" |
30 | |
30 | |
31 | #include <cstddef> |
31 | #include <cstddef> |
32 | #include <cstdarg> |
32 | #include <cstdarg> |
33 | |
33 | |
|
|
34 | #include "unistd.h" |
|
|
35 | |
34 | #include "iom.h" |
36 | #include "iom.h" |
35 | #include "rxvt.h" |
37 | #include "rxvt.h" |
36 | #include "keyboard.h" |
38 | #include "keyboard.h" |
37 | #include "rxvtutil.h" |
39 | #include "rxvtutil.h" |
38 | #include "rxvtperl.h" |
40 | #include "rxvtperl.h" |
39 | |
41 | |
40 | #include "perlxsi.c" |
42 | #include "perlxsi.c" |
41 | |
43 | |
42 | #if defined(HAVE_SCROLLBARS) || defined(MENUBAR) |
44 | #ifdef HAVE_SCROLLBARS |
43 | # define GRAB_CURSOR THIS->leftptr_cursor |
45 | # define GRAB_CURSOR THIS->leftptr_cursor |
44 | #else |
46 | #else |
45 | # define GRAB_CURSOR None |
47 | # define GRAB_CURSOR None |
46 | #endif |
48 | #endif |
47 | |
49 | |
48 | #undef LINENO |
50 | #undef LINENO |
49 | #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) |
50 | #undef ROW |
52 | #undef ROW |
51 | #define ROW(n) THIS->row_buf [LINENO (n)] |
53 | #define ROW(n) THIS->row_buf [LINENO (n)] |
52 | |
54 | |
|
|
55 | #define ENABLE_PERL_FRILLS 1 |
|
|
56 | |
53 | ///////////////////////////////////////////////////////////////////////////// |
57 | ///////////////////////////////////////////////////////////////////////////// |
54 | |
|
|
55 | static SV * |
|
|
56 | taint (SV *sv) |
|
|
57 | { |
|
|
58 | SvTAINT (sv); |
|
|
59 | return sv; |
|
|
60 | } |
|
|
61 | |
|
|
62 | static SV * |
|
|
63 | taint_if (SV *sv, SV *src) |
|
|
64 | { |
|
|
65 | if (SvTAINTED (src)) |
|
|
66 | SvTAINT (sv); |
|
|
67 | |
|
|
68 | return sv; |
|
|
69 | } |
|
|
70 | |
58 | |
71 | static wchar_t * |
59 | static wchar_t * |
72 | sv2wcs (SV *sv) |
60 | sv2wcs (SV *sv) |
73 | { |
61 | { |
74 | STRLEN len; |
62 | STRLEN len; |
… | |
… | |
223 | |
211 | |
224 | #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") |
212 | #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") |
225 | |
213 | |
226 | struct overlay { |
214 | struct overlay { |
227 | HV *self; |
215 | HV *self; |
|
|
216 | bool visible; |
228 | rxvt_term *THIS; |
217 | rxvt_term *THIS; |
229 | int x, y, w, h; |
218 | int x, y, w, h; |
230 | int border; |
219 | int border; |
231 | text_t **text; |
220 | text_t **text; |
232 | rend_t **rend; |
221 | rend_t **rend; |
… | |
… | |
241 | |
230 | |
242 | void set (int x, int y, SV *str, SV *rend); |
231 | void set (int x, int y, SV *str, SV *rend); |
243 | }; |
232 | }; |
244 | |
233 | |
245 | overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) |
234 | overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) |
246 | : THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2) |
235 | : THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), visible(false) |
247 | { |
236 | { |
248 | if (border == 2) |
237 | if (border == 2) |
249 | { |
238 | { |
250 | w += 2; |
239 | w += 2; |
251 | h += 2; |
240 | h += 2; |
… | |
… | |
312 | } |
301 | } |
313 | |
302 | |
314 | void |
303 | void |
315 | overlay::show () |
304 | overlay::show () |
316 | { |
305 | { |
317 | char key[33]; sprintf (key, "%32lx", (long)this); |
306 | if (visible) |
|
|
307 | return; |
318 | |
308 | |
|
|
309 | visible = true; |
|
|
310 | |
319 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
311 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
320 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
312 | av_push (av, newSViv ((long)this)); |
321 | } |
313 | } |
322 | |
314 | |
323 | void |
315 | void |
324 | overlay::hide () |
316 | overlay::hide () |
325 | { |
317 | { |
|
|
318 | if (!visible) |
|
|
319 | return; |
|
|
320 | |
|
|
321 | visible = false; |
|
|
322 | |
326 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
323 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
327 | |
324 | |
328 | if (ovs) |
325 | int i; |
|
|
326 | |
|
|
327 | for (i = AvFILL (av); i >= 0; i--) |
|
|
328 | if (SvIV (*av_fetch (av, i, 1)) == (long)this) |
329 | { |
329 | { |
330 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
331 | |
|
|
332 | HV *hv = (HV *)SvRV (*ovs); |
|
|
333 | hv_delete (hv, key, 32, G_DISCARD); |
330 | av_delete (av, i, G_DISCARD); |
|
|
331 | break; |
334 | } |
332 | } |
|
|
333 | |
|
|
334 | for (; i < AvFILL (av); i++) |
|
|
335 | av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0))); |
|
|
336 | |
|
|
337 | av_pop (av); |
335 | } |
338 | } |
336 | |
339 | |
337 | void overlay::swap () |
340 | void overlay::swap () |
338 | { |
341 | { |
339 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
342 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
… | |
… | |
345 | for (int y = ov_h; y--; ) |
348 | for (int y = ov_h; y--; ) |
346 | { |
349 | { |
347 | text_t *t1 = text [y]; |
350 | text_t *t1 = text [y]; |
348 | rend_t *r1 = rend [y]; |
351 | rend_t *r1 = rend [y]; |
349 | |
352 | |
350 | text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
353 | text_t *t2 = ROW(y + ov_y + THIS->view_start).t + ov_x; |
351 | rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
354 | rend_t *r2 = ROW(y + ov_y + THIS->view_start).r + ov_x; |
352 | |
355 | |
353 | for (int x = ov_w; x--; ) |
356 | for (int x = ov_w; x--; ) |
354 | { |
357 | { |
355 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
358 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
356 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
359 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
… | |
… | |
379 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
382 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
380 | croak ("rend must be arrayref"); |
383 | croak ("rend must be arrayref"); |
381 | |
384 | |
382 | AV *av = (AV *)SvRV (rend); |
385 | AV *av = (AV *)SvRV (rend); |
383 | |
386 | |
384 | for (int col = min (av_len (av) + 1, w - x - border); col--; ) |
387 | for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) |
385 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
388 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
386 | } |
389 | } |
387 | |
390 | |
388 | THIS->want_refresh = 1; |
391 | THIS->want_refresh = 1; |
389 | } |
392 | } |
… | |
… | |
392 | ///////////////////////////////////////////////////////////////////////////// |
395 | ///////////////////////////////////////////////////////////////////////////// |
393 | |
396 | |
394 | struct rxvt_perl_interp rxvt_perl; |
397 | struct rxvt_perl_interp rxvt_perl; |
395 | |
398 | |
396 | static PerlInterpreter *perl; |
399 | static PerlInterpreter *perl; |
397 | |
|
|
398 | rxvt_perl_interp::rxvt_perl_interp () |
|
|
399 | { |
|
|
400 | } |
|
|
401 | |
400 | |
402 | rxvt_perl_interp::~rxvt_perl_interp () |
401 | rxvt_perl_interp::~rxvt_perl_interp () |
403 | { |
402 | { |
404 | if (perl) |
403 | if (perl) |
405 | { |
404 | { |
… | |
… | |
407 | perl_free (perl); |
406 | perl_free (perl); |
408 | } |
407 | } |
409 | } |
408 | } |
410 | |
409 | |
411 | void |
410 | void |
412 | rxvt_perl_interp::init () |
411 | rxvt_perl_interp::init (rxvt_term *term) |
413 | { |
412 | { |
414 | if (!perl) |
413 | if (!perl) |
415 | { |
414 | { |
|
|
415 | rxvt_push_locale (""); // perl init destroys current locale |
|
|
416 | |
|
|
417 | perl_environ = rxvt_environ; |
|
|
418 | swap (perl_environ, environ); |
|
|
419 | |
416 | char *argv[] = { |
420 | char *argv[] = { |
417 | "", |
421 | "", |
418 | "-T", |
422 | "-e" |
419 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
423 | "BEGIN {" |
|
|
424 | " urxvt->bootstrap;" |
|
|
425 | " unshift @INC, '" LIBDIR "';" |
|
|
426 | "}" |
|
|
427 | "" |
|
|
428 | "use urxvt;" |
420 | }; |
429 | }; |
421 | |
430 | |
422 | perl = perl_alloc (); |
431 | perl = perl_alloc (); |
423 | perl_construct (perl); |
432 | perl_construct (perl); |
424 | |
433 | |
425 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
434 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
426 | || perl_run (perl)) |
435 | || perl_run (perl)) |
427 | { |
436 | { |
428 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
437 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
429 | |
438 | |
430 | perl_destruct (perl); |
439 | perl_destruct (perl); |
431 | perl_free (perl); |
440 | perl_free (perl); |
432 | perl = 0; |
441 | perl = 0; |
433 | } |
442 | } |
|
|
443 | |
|
|
444 | swap (perl_environ, environ); |
|
|
445 | |
|
|
446 | rxvt_pop_locale (); |
|
|
447 | } |
|
|
448 | |
|
|
449 | if (perl) |
|
|
450 | { |
|
|
451 | // runs outside of perls ENV |
|
|
452 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
|
|
453 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0); |
434 | } |
454 | } |
435 | } |
455 | } |
436 | |
456 | |
437 | static void |
457 | static void |
438 | ungrab (rxvt_term *THIS) |
458 | ungrab (rxvt_term *THIS) |
… | |
… | |
446 | } |
466 | } |
447 | |
467 | |
448 | bool |
468 | bool |
449 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
469 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
450 | { |
470 | { |
451 | if (!perl) |
471 | if (!perl || !term->perl.self) |
452 | return false; |
472 | return false; |
453 | |
473 | |
454 | if (htype == HOOK_INIT) // first hook ever called |
474 | // pre-handling of some events |
|
|
475 | if (htype == HOOK_REFRESH_END) |
455 | { |
476 | { |
456 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
477 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
457 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
478 | |
|
|
479 | for (int i = 0; i <= AvFILL (av); i++) |
|
|
480 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
458 | } |
481 | } |
459 | else if (!term->perl.self) |
482 | |
460 | return false; // perl not initialized for this instance |
483 | swap (perl_environ, environ); |
|
|
484 | |
|
|
485 | bool event_consumed; |
|
|
486 | |
|
|
487 | if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always |
|
|
488 | || term->perl.should_invoke [htype]) |
|
|
489 | try |
|
|
490 | { |
|
|
491 | dSP; |
|
|
492 | va_list ap; |
|
|
493 | |
|
|
494 | va_start (ap, htype); |
|
|
495 | |
|
|
496 | ENTER; |
|
|
497 | SAVETMPS; |
|
|
498 | |
|
|
499 | PUSHMARK (SP); |
|
|
500 | |
|
|
501 | XPUSHs (sv_2mortal (newSVterm (term))); |
|
|
502 | XPUSHs (sv_2mortal (newSViv (htype))); |
|
|
503 | |
|
|
504 | for (;;) { |
|
|
505 | data_type dt = (data_type)va_arg (ap, int); |
|
|
506 | |
|
|
507 | switch (dt) |
|
|
508 | { |
|
|
509 | case DT_INT: |
|
|
510 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
|
|
511 | break; |
|
|
512 | |
|
|
513 | case DT_LONG: |
|
|
514 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
|
|
515 | break; |
|
|
516 | |
|
|
517 | case DT_STR: |
|
|
518 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
|
|
519 | break; |
|
|
520 | |
|
|
521 | case DT_STR_LEN: |
|
|
522 | { |
|
|
523 | char *str = va_arg (ap, char *); |
|
|
524 | int len = va_arg (ap, int); |
|
|
525 | |
|
|
526 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
|
|
527 | } |
|
|
528 | break; |
|
|
529 | |
|
|
530 | case DT_WCS_LEN: |
|
|
531 | { |
|
|
532 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
533 | int wlen = va_arg (ap, int); |
|
|
534 | |
|
|
535 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
|
|
536 | } |
|
|
537 | break; |
|
|
538 | |
|
|
539 | case DT_XEVENT: |
|
|
540 | { |
|
|
541 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
542 | HV *hv = newHV (); |
|
|
543 | |
|
|
544 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
545 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
546 | # define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) |
|
|
547 | # undef set |
|
|
548 | |
|
|
549 | setiv (type, xe->type); |
|
|
550 | setiv (send_event, xe->xany.send_event); |
|
|
551 | setiv (serial, xe->xany.serial); |
|
|
552 | |
|
|
553 | switch (xe->type) |
|
|
554 | { |
|
|
555 | case KeyPress: |
|
|
556 | case KeyRelease: |
|
|
557 | case ButtonPress: |
|
|
558 | case ButtonRelease: |
|
|
559 | case MotionNotify: |
|
|
560 | setuv (window, xe->xmotion.window); |
|
|
561 | setuv (root, xe->xmotion.root); |
|
|
562 | setuv (subwindow, xe->xmotion.subwindow); |
|
|
563 | setuv (time, xe->xmotion.time); |
|
|
564 | setiv (x, xe->xmotion.x); |
|
|
565 | setiv (y, xe->xmotion.y); |
|
|
566 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
567 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
568 | setiv (x_root, xe->xmotion.x_root); |
|
|
569 | setiv (y_root, xe->xmotion.y_root); |
|
|
570 | setuv (state, xe->xmotion.state); |
|
|
571 | |
|
|
572 | switch (xe->type) |
|
|
573 | { |
|
|
574 | case KeyPress: |
|
|
575 | case KeyRelease: |
|
|
576 | setuv (keycode, xe->xkey.keycode); |
|
|
577 | break; |
|
|
578 | |
|
|
579 | case ButtonPress: |
|
|
580 | case ButtonRelease: |
|
|
581 | setuv (button, xe->xbutton.button); |
|
|
582 | break; |
|
|
583 | |
|
|
584 | case MotionNotify: |
|
|
585 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
586 | break; |
|
|
587 | } |
|
|
588 | |
|
|
589 | break; |
|
|
590 | |
|
|
591 | case MapNotify: |
|
|
592 | case UnmapNotify: |
|
|
593 | case ConfigureNotify: |
|
|
594 | setuv (event, xe->xconfigure.event); |
|
|
595 | setuv (window, xe->xconfigure.window); |
|
|
596 | |
|
|
597 | switch (xe->type) |
|
|
598 | { |
|
|
599 | case ConfigureNotify: |
|
|
600 | setiv (x, xe->xconfigure.x); |
|
|
601 | setiv (y, xe->xconfigure.y); |
|
|
602 | setiv (width, xe->xconfigure.width); |
|
|
603 | setiv (height, xe->xconfigure.height); |
|
|
604 | setuv (above, xe->xconfigure.above); |
|
|
605 | break; |
|
|
606 | } |
|
|
607 | |
|
|
608 | break; |
|
|
609 | } |
|
|
610 | |
|
|
611 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
612 | } |
|
|
613 | break; |
|
|
614 | |
|
|
615 | case DT_END: |
|
|
616 | goto call; |
|
|
617 | |
|
|
618 | default: |
|
|
619 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
620 | } |
|
|
621 | } |
|
|
622 | |
|
|
623 | call: |
|
|
624 | va_end (ap); |
|
|
625 | |
|
|
626 | PUTBACK; |
|
|
627 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
628 | SPAGAIN; |
|
|
629 | |
|
|
630 | if (count) |
|
|
631 | { |
|
|
632 | SV *status = POPs; |
|
|
633 | count = SvTRUE (status); |
|
|
634 | } |
|
|
635 | |
|
|
636 | PUTBACK; |
|
|
637 | FREETMPS; |
|
|
638 | LEAVE; |
|
|
639 | |
|
|
640 | if (SvTRUE (ERRSV)) |
|
|
641 | { |
|
|
642 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
643 | ungrab (term); // better lose the grab than the session |
|
|
644 | } |
|
|
645 | |
|
|
646 | event_consumed = !!count; |
|
|
647 | } |
|
|
648 | catch (...) |
|
|
649 | { |
|
|
650 | swap (perl_environ, environ); |
|
|
651 | throw; |
|
|
652 | } |
|
|
653 | else |
|
|
654 | event_consumed = false; |
|
|
655 | |
|
|
656 | // post-handling of some events |
|
|
657 | if (htype == HOOK_REFRESH_BEGIN) |
|
|
658 | { |
|
|
659 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
660 | |
|
|
661 | for (int i = AvFILL (av); i >= 0; i--) |
|
|
662 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
|
|
663 | } |
461 | else if (htype == HOOK_DESTROY) |
664 | else if (htype == HOOK_DESTROY) |
462 | { |
665 | { |
463 | // handled later |
666 | clearSVptr ((SV *)term->perl.self); |
|
|
667 | SvREFCNT_dec ((SV *)term->perl.self); |
464 | } |
668 | } |
465 | else |
|
|
466 | { |
|
|
467 | if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
|
|
468 | { |
|
|
469 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
470 | |
669 | |
471 | if (HvKEYS (hv)) |
670 | swap (perl_environ, environ); |
472 | { |
|
|
473 | hv_iterinit (hv); |
|
|
474 | |
671 | |
475 | while (HE *he = hv_iternext (hv)) |
672 | return event_consumed; |
476 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
477 | } |
|
|
478 | |
|
|
479 | } |
|
|
480 | |
|
|
481 | if (!should_invoke [htype]) |
|
|
482 | return false; |
|
|
483 | } |
|
|
484 | |
|
|
485 | dSP; |
|
|
486 | va_list ap; |
|
|
487 | |
|
|
488 | va_start (ap, htype); |
|
|
489 | |
|
|
490 | ENTER; |
|
|
491 | SAVETMPS; |
|
|
492 | |
|
|
493 | PUSHMARK (SP); |
|
|
494 | |
|
|
495 | XPUSHs (sv_2mortal (newSVterm (term))); |
|
|
496 | XPUSHs (sv_2mortal (newSViv (htype))); |
|
|
497 | |
|
|
498 | for (;;) { |
|
|
499 | data_type dt = (data_type)va_arg (ap, int); |
|
|
500 | |
|
|
501 | switch (dt) |
|
|
502 | { |
|
|
503 | case DT_INT: |
|
|
504 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
|
|
505 | break; |
|
|
506 | |
|
|
507 | case DT_LONG: |
|
|
508 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
|
|
509 | break; |
|
|
510 | |
|
|
511 | case DT_STR: |
|
|
512 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
|
|
513 | break; |
|
|
514 | |
|
|
515 | case DT_STR_LEN: |
|
|
516 | { |
|
|
517 | char *str = va_arg (ap, char *); |
|
|
518 | int len = va_arg (ap, int); |
|
|
519 | |
|
|
520 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
|
|
521 | } |
|
|
522 | break; |
|
|
523 | |
|
|
524 | case DT_WCS_LEN: |
|
|
525 | { |
|
|
526 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
527 | int wlen = va_arg (ap, int); |
|
|
528 | |
|
|
529 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
|
|
530 | } |
|
|
531 | break; |
|
|
532 | |
|
|
533 | case DT_XEVENT: |
|
|
534 | { |
|
|
535 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
536 | HV *hv = newHV (); |
|
|
537 | |
|
|
538 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
539 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
540 | # undef set |
|
|
541 | |
|
|
542 | setiv (type, xe->type); |
|
|
543 | setiv (send_event, xe->xany.send_event); |
|
|
544 | setiv (serial, xe->xany.serial); |
|
|
545 | |
|
|
546 | switch (xe->type) |
|
|
547 | { |
|
|
548 | case KeyPress: |
|
|
549 | case KeyRelease: |
|
|
550 | case ButtonPress: |
|
|
551 | case ButtonRelease: |
|
|
552 | case MotionNotify: |
|
|
553 | setiv (time, xe->xmotion.time); |
|
|
554 | setiv (x, xe->xmotion.x); |
|
|
555 | setiv (y, xe->xmotion.y); |
|
|
556 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
557 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
558 | setiv (x_root, xe->xmotion.x_root); |
|
|
559 | setiv (y_root, xe->xmotion.y_root); |
|
|
560 | setiv (state, xe->xmotion.state); |
|
|
561 | break; |
|
|
562 | } |
|
|
563 | |
|
|
564 | switch (xe->type) |
|
|
565 | { |
|
|
566 | case KeyPress: |
|
|
567 | case KeyRelease: |
|
|
568 | setiv (keycode, xe->xkey.keycode); |
|
|
569 | break; |
|
|
570 | |
|
|
571 | case ButtonPress: |
|
|
572 | case ButtonRelease: |
|
|
573 | setiv (button, xe->xbutton.button); |
|
|
574 | break; |
|
|
575 | |
|
|
576 | case MotionNotify: |
|
|
577 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
578 | break; |
|
|
579 | } |
|
|
580 | |
|
|
581 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
582 | } |
|
|
583 | break; |
|
|
584 | |
|
|
585 | case DT_END: |
|
|
586 | { |
|
|
587 | va_end (ap); |
|
|
588 | |
|
|
589 | PUTBACK; |
|
|
590 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
591 | SPAGAIN; |
|
|
592 | |
|
|
593 | if (count) |
|
|
594 | { |
|
|
595 | SV *status = POPs; |
|
|
596 | count = SvTRUE (status); |
|
|
597 | } |
|
|
598 | |
|
|
599 | PUTBACK; |
|
|
600 | FREETMPS; |
|
|
601 | LEAVE; |
|
|
602 | |
|
|
603 | if (SvTRUE (ERRSV)) |
|
|
604 | { |
|
|
605 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
606 | ungrab (term); // better lose the grab than the session |
|
|
607 | } |
|
|
608 | |
|
|
609 | if (htype == HOOK_DESTROY) |
|
|
610 | { |
|
|
611 | clearSVptr ((SV *)term->perl.self); |
|
|
612 | SvREFCNT_dec ((SV *)term->perl.self); |
|
|
613 | } |
|
|
614 | |
|
|
615 | return count; |
|
|
616 | } |
|
|
617 | |
|
|
618 | default: |
|
|
619 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
620 | } |
|
|
621 | } |
|
|
622 | } |
673 | } |
623 | |
674 | |
624 | ///////////////////////////////////////////////////////////////////////////// |
675 | ///////////////////////////////////////////////////////////////////////////// |
625 | |
676 | |
626 | MODULE = urxvt PACKAGE = urxvt |
677 | MODULE = urxvt PACKAGE = urxvt |
627 | |
678 | |
628 | PROTOTYPES: ENABLE |
679 | PROTOTYPES: ENABLE |
629 | |
680 | |
630 | BOOT: |
681 | BOOT: |
631 | { |
682 | { |
632 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
683 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
|
|
684 | sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1)); |
|
|
685 | sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1)); |
|
|
686 | sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1)); |
633 | |
687 | |
634 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
688 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
635 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
689 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
636 | # include "hookinc.h" |
690 | # include "hookinc.h" |
637 | # undef def |
691 | # undef def |
… | |
… | |
642 | # include "optinc.h" |
696 | # include "optinc.h" |
643 | # undef nodef |
697 | # undef nodef |
644 | # undef def |
698 | # undef def |
645 | |
699 | |
646 | HV *stash = gv_stashpv ("urxvt", 1); |
700 | HV *stash = gv_stashpv ("urxvt", 1); |
647 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
701 | struct { |
|
|
702 | const char *name; |
|
|
703 | IV iv; |
|
|
704 | } *civ, const_iv[] = { |
|
|
705 | # define const_iv(name) { # name, (IV)name } |
648 | export_const_iv (DEFAULT_RSTYLE); |
706 | const_iv (DEFAULT_RSTYLE), |
649 | export_const_iv (OVERLAY_RSTYLE); |
707 | const_iv (OVERLAY_RSTYLE), |
650 | export_const_iv (RS_Bold); |
708 | const_iv (RS_Bold), |
651 | export_const_iv (RS_Italic); |
709 | const_iv (RS_Italic), |
652 | export_const_iv (RS_Blink); |
710 | const_iv (RS_Blink), |
653 | export_const_iv (RS_RVid); |
711 | const_iv (RS_RVid), |
654 | export_const_iv (RS_Uline); |
712 | const_iv (RS_Uline), |
655 | |
713 | |
656 | export_const_iv (CurrentTime); |
714 | const_iv (CurrentTime), |
657 | export_const_iv (ShiftMask); |
715 | const_iv (ShiftMask), |
658 | export_const_iv (LockMask); |
716 | const_iv (LockMask), |
659 | export_const_iv (ControlMask); |
717 | const_iv (ControlMask), |
660 | export_const_iv (Mod1Mask); |
718 | const_iv (Mod1Mask), |
661 | export_const_iv (Mod2Mask); |
719 | const_iv (Mod2Mask), |
662 | export_const_iv (Mod3Mask); |
720 | const_iv (Mod3Mask), |
663 | export_const_iv (Mod4Mask); |
721 | const_iv (Mod4Mask), |
664 | export_const_iv (Mod5Mask); |
722 | const_iv (Mod5Mask), |
665 | export_const_iv (Button1Mask); |
723 | const_iv (Button1Mask), |
666 | export_const_iv (Button2Mask); |
724 | const_iv (Button2Mask), |
667 | export_const_iv (Button3Mask); |
725 | const_iv (Button3Mask), |
668 | export_const_iv (Button4Mask); |
726 | const_iv (Button4Mask), |
669 | export_const_iv (Button5Mask); |
727 | const_iv (Button5Mask), |
670 | export_const_iv (AnyModifier); |
728 | const_iv (AnyModifier), |
671 | |
729 | |
672 | export_const_iv (EVENT_NONE); |
730 | const_iv (EVENT_NONE), |
673 | export_const_iv (EVENT_READ); |
731 | const_iv (EVENT_READ), |
674 | export_const_iv (EVENT_WRITE); |
732 | const_iv (EVENT_WRITE), |
|
|
733 | |
|
|
734 | const_iv (NoEventMask), |
|
|
735 | const_iv (KeyPressMask), |
|
|
736 | const_iv (KeyReleaseMask), |
|
|
737 | const_iv (ButtonPressMask), |
|
|
738 | const_iv (ButtonReleaseMask), |
|
|
739 | const_iv (EnterWindowMask), |
|
|
740 | const_iv (LeaveWindowMask), |
|
|
741 | const_iv (PointerMotionMask), |
|
|
742 | const_iv (PointerMotionHintMask), |
|
|
743 | const_iv (Button1MotionMask), |
|
|
744 | const_iv (Button2MotionMask), |
|
|
745 | const_iv (Button3MotionMask), |
|
|
746 | const_iv (Button4MotionMask), |
|
|
747 | const_iv (Button5MotionMask), |
|
|
748 | const_iv (ButtonMotionMask), |
|
|
749 | const_iv (KeymapStateMask), |
|
|
750 | const_iv (ExposureMask), |
|
|
751 | const_iv (VisibilityChangeMask), |
|
|
752 | const_iv (StructureNotifyMask), |
|
|
753 | const_iv (ResizeRedirectMask), |
|
|
754 | const_iv (SubstructureNotifyMask), |
|
|
755 | const_iv (SubstructureRedirectMask), |
|
|
756 | const_iv (FocusChangeMask), |
|
|
757 | const_iv (PropertyChangeMask), |
|
|
758 | const_iv (ColormapChangeMask), |
|
|
759 | const_iv (OwnerGrabButtonMask), |
|
|
760 | |
|
|
761 | const_iv (KeyPress), |
|
|
762 | const_iv (KeyRelease), |
|
|
763 | const_iv (ButtonPress), |
|
|
764 | const_iv (ButtonRelease), |
|
|
765 | const_iv (MotionNotify), |
|
|
766 | const_iv (EnterNotify), |
|
|
767 | const_iv (LeaveNotify), |
|
|
768 | const_iv (FocusIn), |
|
|
769 | const_iv (FocusOut), |
|
|
770 | const_iv (KeymapNotify), |
|
|
771 | const_iv (Expose), |
|
|
772 | const_iv (GraphicsExpose), |
|
|
773 | const_iv (NoExpose), |
|
|
774 | const_iv (VisibilityNotify), |
|
|
775 | const_iv (CreateNotify), |
|
|
776 | const_iv (DestroyNotify), |
|
|
777 | const_iv (UnmapNotify), |
|
|
778 | const_iv (MapNotify), |
|
|
779 | const_iv (MapRequest), |
|
|
780 | const_iv (ReparentNotify), |
|
|
781 | const_iv (ConfigureNotify), |
|
|
782 | const_iv (ConfigureRequest), |
|
|
783 | const_iv (GravityNotify), |
|
|
784 | const_iv (ResizeRequest), |
|
|
785 | const_iv (CirculateNotify), |
|
|
786 | const_iv (CirculateRequest), |
|
|
787 | const_iv (PropertyNotify), |
|
|
788 | const_iv (SelectionClear), |
|
|
789 | const_iv (SelectionRequest), |
|
|
790 | const_iv (SelectionNotify), |
|
|
791 | const_iv (ColormapNotify), |
|
|
792 | const_iv (ClientMessage), |
|
|
793 | const_iv (MappingNotify), |
|
|
794 | }; |
|
|
795 | |
|
|
796 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); |
|
|
797 | civ-- > const_iv; ) |
|
|
798 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
675 | } |
799 | } |
|
|
800 | |
|
|
801 | void |
|
|
802 | warn (const char *msg) |
|
|
803 | CODE: |
|
|
804 | rxvt_warn ("%s", msg); |
|
|
805 | |
|
|
806 | void |
|
|
807 | fatal (const char *msg) |
|
|
808 | CODE: |
|
|
809 | rxvt_fatal ("%s", msg); |
|
|
810 | |
|
|
811 | void |
|
|
812 | _exit (int status) |
|
|
813 | |
|
|
814 | NV |
|
|
815 | NOW () |
|
|
816 | CODE: |
|
|
817 | RETVAL = NOW; |
|
|
818 | OUTPUT: |
|
|
819 | RETVAL |
|
|
820 | |
|
|
821 | int |
|
|
822 | GET_BASEFG (int rend) |
|
|
823 | CODE: |
|
|
824 | RETVAL = GET_BASEFG (rend); |
|
|
825 | OUTPUT: |
|
|
826 | RETVAL |
|
|
827 | |
|
|
828 | int |
|
|
829 | GET_BASEBG (int rend) |
|
|
830 | CODE: |
|
|
831 | RETVAL = GET_BASEBG (rend); |
|
|
832 | OUTPUT: |
|
|
833 | RETVAL |
|
|
834 | |
|
|
835 | int |
|
|
836 | SET_FGCOLOR (int rend, int new_color) |
|
|
837 | CODE: |
|
|
838 | RETVAL = SET_FGCOLOR (rend, new_color); |
|
|
839 | OUTPUT: |
|
|
840 | RETVAL |
|
|
841 | |
|
|
842 | int |
|
|
843 | SET_BGCOLOR (int rend, int new_color) |
|
|
844 | CODE: |
|
|
845 | RETVAL = SET_BGCOLOR (rend, new_color); |
|
|
846 | OUTPUT: |
|
|
847 | RETVAL |
|
|
848 | |
|
|
849 | int |
|
|
850 | GET_CUSTOM (int rend) |
|
|
851 | CODE: |
|
|
852 | RETVAL = (rend && RS_customMask) >> RS_customShift; |
|
|
853 | OUTPUT: |
|
|
854 | RETVAL |
|
|
855 | |
|
|
856 | int |
|
|
857 | SET_CUSTOM (int rend, int new_value) |
|
|
858 | CODE: |
|
|
859 | { |
|
|
860 | if (!IN_RANGE_EXC (new_value, 0, RS_customCount)) |
|
|
861 | croak ("custom value out of range, must be 0..%d", RS_customCount - 1); |
|
|
862 | |
|
|
863 | RETVAL = (rend & ~RS_customMask) |
|
|
864 | | ((new_value << RS_customShift) & RS_customMask); |
|
|
865 | } |
|
|
866 | OUTPUT: |
|
|
867 | RETVAL |
|
|
868 | |
|
|
869 | MODULE = urxvt PACKAGE = urxvt::term |
676 | |
870 | |
677 | SV * |
871 | SV * |
678 | new (...) |
872 | _new (...) |
679 | CODE: |
873 | CODE: |
680 | { |
874 | { |
|
|
875 | if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) |
|
|
876 | croak ("first argument to urxvt::term->_new must be arrayref"); |
|
|
877 | |
|
|
878 | rxvt_term *term = new rxvt_term; |
|
|
879 | |
681 | stringvec *argv = new stringvec; |
880 | term->argv = new stringvec; |
|
|
881 | term->envv = new stringvec; |
|
|
882 | |
|
|
883 | for (int i = 1; i < items; i++) |
|
|
884 | term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
885 | |
|
|
886 | AV *envv = (AV *)SvRV (ST (0)); |
|
|
887 | for (int i = AvFILL (envv) + 1; i--; ) |
|
|
888 | term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); |
|
|
889 | |
|
|
890 | term->envv->push_back (0); |
|
|
891 | |
682 | bool success; |
892 | bool success; |
683 | |
|
|
684 | for (int i = 0; i < items ;i++) |
|
|
685 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
686 | |
|
|
687 | rxvt_term *term = new rxvt_term; |
|
|
688 | |
|
|
689 | term->argv = argv; |
|
|
690 | |
893 | |
691 | try |
894 | try |
692 | { |
895 | { |
693 | if (!term->init (argv->size (), argv->begin ())) |
896 | success = term->init (term->argv->size (), term->argv->begin ()); |
694 | term = 0; |
|
|
695 | } |
897 | } |
696 | catch (const class rxvt_failure_exception &e) |
898 | catch (const class rxvt_failure_exception &e) |
697 | { |
899 | { |
|
|
900 | success = false; |
|
|
901 | } |
|
|
902 | |
|
|
903 | if (!success) |
|
|
904 | { |
698 | term->destroy (); |
905 | term->destroy (); |
699 | croak ("exception caught while initializing new terminal instance"); |
906 | croak ("error while initializing new terminal instance"); |
700 | } |
907 | } |
701 | |
908 | |
702 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
909 | RETVAL = term && term->perl.self |
|
|
910 | ? newSVterm (term) : &PL_sv_undef; |
703 | } |
911 | } |
704 | OUTPUT: |
912 | OUTPUT: |
705 | RETVAL |
913 | RETVAL |
706 | |
914 | |
707 | void |
915 | void |
708 | set_should_invoke (int htype, int value) |
916 | rxvt_term::destroy () |
|
|
917 | |
|
|
918 | #if ENABLE_PERL_FRILLS |
|
|
919 | |
|
|
920 | void |
|
|
921 | rxvt_term::XListProperties (U32 window) |
709 | CODE: |
922 | PPCODE: |
710 | rxvt_perl.should_invoke [htype] = value; |
923 | { |
|
|
924 | int count; |
|
|
925 | Atom *props = XListProperties (THIS->display->display, (Window)window, &count); |
711 | |
926 | |
|
|
927 | EXTEND (SP, count); |
|
|
928 | while (count--) |
|
|
929 | PUSHs (newSVuv ((U32)props [count])); |
|
|
930 | |
|
|
931 | XFree (props); |
|
|
932 | } |
|
|
933 | |
712 | void |
934 | void |
713 | warn (const char *msg) |
935 | rxvt_term::XGetWindowProperty (U32 window, U32 property) |
714 | CODE: |
936 | PPCODE: |
715 | rxvt_warn ("%s", msg); |
937 | { |
|
|
938 | Atom type; |
|
|
939 | int format; |
|
|
940 | unsigned long nitems; |
|
|
941 | unsigned long bytes_after; |
|
|
942 | unsigned char *prop; |
|
|
943 | XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property, |
|
|
944 | 0, 1<<30, 0, AnyPropertyType, |
|
|
945 | &type, &format, &nitems, &bytes_after, &prop); |
|
|
946 | if (type != None) |
|
|
947 | { |
|
|
948 | EXTEND (SP, 3); |
|
|
949 | PUSHs (newSVuv ((U32)type)); |
|
|
950 | PUSHs (newSViv (format)); |
|
|
951 | PUSHs (newSVpvn ((char *)prop, nitems * format / 8)); |
|
|
952 | XFree (prop); |
|
|
953 | } |
|
|
954 | } |
716 | |
955 | |
717 | void |
956 | void |
718 | fatal (const char *msg) |
957 | rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data) |
719 | CODE: |
958 | CODE: |
720 | rxvt_fatal ("%s", msg); |
959 | { |
|
|
960 | STRLEN len; |
|
|
961 | char *data_ = SvPVbyte (data, len); |
721 | |
962 | |
722 | SV * |
963 | XChangeProperty (THIS->display->display, (Window)window, (Atom)property, |
723 | untaint (SV *sv) |
964 | type, format, PropModeReplace, |
724 | CODE: |
965 | (unsigned char *)data, len * 8 / format); |
725 | RETVAL = newSVsv (sv); |
966 | } |
726 | SvTAINTED_off (RETVAL); |
|
|
727 | OUTPUT: |
|
|
728 | RETVAL |
|
|
729 | |
967 | |
730 | bool |
968 | void |
731 | safe () |
969 | rxvt_term::XDeleteProperty (U32 window, U32 property) |
732 | CODE: |
970 | CODE: |
733 | RETVAL = !rxvt_tainted (); |
971 | XDeleteProperty (THIS->display->display, (Window)window, (Atom)property); |
734 | OUTPUT: |
|
|
735 | RETVAL |
|
|
736 | |
972 | |
737 | NV |
973 | U32 |
738 | NOW () |
974 | rxvt_term::DefaultRootWindow () |
739 | CODE: |
975 | CODE: |
|
|
976 | RETVAL = (U32)THIS->display->root; |
|
|
977 | OUTPUT: |
740 | RETVAL = NOW; |
978 | RETVAL |
741 | OUTPUT: |
|
|
742 | RETVAL |
|
|
743 | |
979 | |
744 | int |
980 | U32 |
745 | GET_BASEFG (int rend) |
981 | rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height) |
746 | CODE: |
982 | CODE: |
747 | RETVAL = GET_BASEFG (rend); |
983 | RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent, |
|
|
984 | x, y, width, height, 0, |
|
|
985 | THIS->pix_colors_focused[Color_border], |
|
|
986 | THIS->pix_colors_focused[Color_border]); |
748 | OUTPUT: |
987 | OUTPUT: |
749 | RETVAL |
988 | RETVAL |
750 | |
989 | |
751 | int |
|
|
752 | GET_BASEBG (int rend) |
|
|
753 | CODE: |
|
|
754 | RETVAL = GET_BASEBG (rend); |
|
|
755 | OUTPUT: |
|
|
756 | RETVAL |
|
|
757 | |
|
|
758 | int |
|
|
759 | SET_FGCOLOR (int rend, int new_color) |
|
|
760 | CODE: |
|
|
761 | RETVAL = SET_FGCOLOR (rend, new_color); |
|
|
762 | OUTPUT: |
|
|
763 | RETVAL |
|
|
764 | |
|
|
765 | int |
|
|
766 | SET_BGCOLOR (int rend, int new_color) |
|
|
767 | CODE: |
|
|
768 | RETVAL = SET_BGCOLOR (rend, new_color); |
|
|
769 | OUTPUT: |
|
|
770 | RETVAL |
|
|
771 | |
|
|
772 | int |
|
|
773 | GET_CUSTOM (int rend) |
|
|
774 | CODE: |
|
|
775 | RETVAL = (rend && RS_customMask) >> RS_customShift; |
|
|
776 | OUTPUT: |
|
|
777 | RETVAL |
|
|
778 | |
|
|
779 | int |
|
|
780 | SET_CUSTOM (int rend, int new_value) |
|
|
781 | CODE: |
|
|
782 | { |
|
|
783 | if (!IN_RANGE_EXC (new_value, 0, RS_customCount)) |
|
|
784 | croak ("custom value out of range, must be 0..%d", RS_customCount - 1); |
|
|
785 | |
|
|
786 | RETVAL = (rend & ~RS_customMask) |
|
|
787 | | ((new_value << RS_customShift) & RS_customMask); |
|
|
788 | } |
|
|
789 | OUTPUT: |
|
|
790 | RETVAL |
|
|
791 | |
|
|
792 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
793 | |
|
|
794 | void |
990 | void |
795 | rxvt_term::destroy () |
991 | rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0) |
|
|
992 | CODE: |
|
|
993 | XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y); |
|
|
994 | |
|
|
995 | void |
|
|
996 | rxvt_term::XMapWindow (U32 window) |
|
|
997 | CODE: |
|
|
998 | XMapWindow (THIS->display->display, (Window)window); |
|
|
999 | |
|
|
1000 | void |
|
|
1001 | rxvt_term::XUnmapWindow (U32 window) |
|
|
1002 | CODE: |
|
|
1003 | XUnmapWindow (THIS->display->display, (Window)window); |
|
|
1004 | |
|
|
1005 | #endif |
|
|
1006 | |
|
|
1007 | void |
|
|
1008 | rxvt_term::set_should_invoke (int htype, int inc) |
|
|
1009 | CODE: |
|
|
1010 | THIS->perl.should_invoke [htype] += inc; |
796 | |
1011 | |
797 | void |
1012 | void |
798 | rxvt_term::grab_button (int button, U32 modifiers) |
1013 | rxvt_term::grab_button (int button, U32 modifiers) |
799 | CODE: |
1014 | CODE: |
800 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
1015 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
… | |
… | |
868 | char *mbstr = rxvt_wcstombs (wstr); |
1083 | char *mbstr = rxvt_wcstombs (wstr); |
869 | rxvt_pop_locale (); |
1084 | rxvt_pop_locale (); |
870 | |
1085 | |
871 | free (wstr); |
1086 | free (wstr); |
872 | |
1087 | |
873 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
1088 | RETVAL = newSVpv (mbstr, 0); |
874 | free (mbstr); |
1089 | free (mbstr); |
875 | } |
1090 | } |
876 | OUTPUT: |
1091 | OUTPUT: |
877 | RETVAL |
1092 | RETVAL |
878 | |
1093 | |
… | |
… | |
885 | |
1100 | |
886 | rxvt_push_locale (THIS->locale); |
1101 | rxvt_push_locale (THIS->locale); |
887 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1102 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
888 | rxvt_pop_locale (); |
1103 | rxvt_pop_locale (); |
889 | |
1104 | |
890 | RETVAL = taint_if (wcs2sv (wstr), octets); |
1105 | RETVAL = wcs2sv (wstr); |
891 | free (wstr); |
1106 | free (wstr); |
892 | } |
1107 | } |
893 | OUTPUT: |
1108 | OUTPUT: |
894 | RETVAL |
1109 | RETVAL |
895 | |
1110 | |
… | |
… | |
904 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
1119 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
905 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
1120 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
906 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
1121 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
907 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
1122 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
908 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
1123 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
909 | #define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) |
1124 | #define TERM_OFFSET_top_row TERM_OFFSET(top_row) |
910 | |
1125 | |
911 | int |
1126 | int |
912 | rxvt_term::width () |
1127 | rxvt_term::width () |
913 | ALIAS: |
1128 | ALIAS: |
914 | width = TERM_OFFSET_width |
1129 | width = TERM_OFFSET_width |
… | |
… | |
920 | ncol = TERM_OFFSET_ncol |
1135 | ncol = TERM_OFFSET_ncol |
921 | focus = TERM_OFFSET_focus |
1136 | focus = TERM_OFFSET_focus |
922 | mapped = TERM_OFFSET_mapped |
1137 | mapped = TERM_OFFSET_mapped |
923 | saveLines = TERM_OFFSET_saveLines |
1138 | saveLines = TERM_OFFSET_saveLines |
924 | total_rows = TERM_OFFSET_total_rows |
1139 | total_rows = TERM_OFFSET_total_rows |
925 | nsaved = TERM_OFFSET_nsaved |
1140 | top_row = TERM_OFFSET_top_row |
926 | CODE: |
1141 | CODE: |
927 | RETVAL = *(int *)((char *)THIS + ix); |
1142 | RETVAL = *(int *)((char *)THIS + ix); |
928 | OUTPUT: |
1143 | OUTPUT: |
929 | RETVAL |
1144 | RETVAL |
930 | |
1145 | |
… | |
… | |
956 | case 1: RETVAL = THIS->locale; break; |
1171 | case 1: RETVAL = THIS->locale; break; |
957 | } |
1172 | } |
958 | OUTPUT: |
1173 | OUTPUT: |
959 | RETVAL |
1174 | RETVAL |
960 | |
1175 | |
|
|
1176 | SV * |
|
|
1177 | rxvt_term::_env () |
|
|
1178 | CODE: |
|
|
1179 | { |
|
|
1180 | if (THIS->envv) |
|
|
1181 | { |
|
|
1182 | AV *av = newAV (); |
|
|
1183 | |
|
|
1184 | for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) |
|
|
1185 | if (*i) |
|
|
1186 | av_push (av, newSVpv (*i, 0)); |
|
|
1187 | |
|
|
1188 | RETVAL = newRV_noinc ((SV *)av); |
|
|
1189 | } |
|
|
1190 | else |
|
|
1191 | RETVAL = &PL_sv_undef; |
|
|
1192 | } |
|
|
1193 | OUTPUT: |
|
|
1194 | RETVAL |
|
|
1195 | |
961 | int |
1196 | int |
962 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
1197 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
963 | CODE: |
1198 | CODE: |
964 | RETVAL = THIS->pty_ev.events; |
1199 | RETVAL = THIS->pty_ev.events; |
965 | if (events != EVENT_UNDEF) |
1200 | if (events != EVENT_UNDEF) |
… | |
… | |
979 | CODE: |
1214 | CODE: |
980 | RETVAL = (U32)THIS->vt; |
1215 | RETVAL = (U32)THIS->vt; |
981 | OUTPUT: |
1216 | OUTPUT: |
982 | RETVAL |
1217 | RETVAL |
983 | |
1218 | |
|
|
1219 | void |
|
|
1220 | rxvt_term::vt_emask_add (U32 emask) |
|
|
1221 | CODE: |
|
|
1222 | THIS->vt_emask_perl |= emask; |
|
|
1223 | THIS->vt_select_input (); |
|
|
1224 | |
984 | U32 |
1225 | U32 |
985 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
1226 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
986 | CODE: |
1227 | CODE: |
987 | { |
|
|
988 | RETVAL = THIS->rstyle; |
1228 | RETVAL = THIS->rstyle; |
989 | THIS->rstyle = new_rstyle; |
1229 | THIS->rstyle = new_rstyle; |
990 | } |
|
|
991 | OUTPUT: |
1230 | OUTPUT: |
992 | RETVAL |
1231 | RETVAL |
993 | |
1232 | |
994 | int |
1233 | int |
995 | rxvt_term::view_start (int newval = -1) |
1234 | rxvt_term::view_start (int newval = 1) |
|
|
1235 | PROTOTYPE: $;$ |
996 | CODE: |
1236 | CODE: |
997 | { |
1237 | { |
998 | RETVAL = THIS->view_start; |
1238 | RETVAL = THIS->view_start; |
999 | |
1239 | |
1000 | if (newval >= 0) |
1240 | if (newval <= 0) |
1001 | { |
1241 | THIS->scr_changeview (max (newval, THIS->top_row)); |
1002 | THIS->view_start = min (newval, THIS->nsaved); |
|
|
1003 | THIS->scr_changeview (RETVAL); |
|
|
1004 | } |
|
|
1005 | } |
1242 | } |
1006 | OUTPUT: |
1243 | OUTPUT: |
1007 | RETVAL |
1244 | RETVAL |
1008 | |
1245 | |
1009 | void |
1246 | void |
… | |
… | |
1013 | |
1250 | |
1014 | void |
1251 | void |
1015 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1252 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1016 | PPCODE: |
1253 | PPCODE: |
1017 | { |
1254 | { |
1018 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1255 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
1019 | XSRETURN_EMPTY; |
1256 | XSRETURN_EMPTY; |
1020 | |
1257 | |
1021 | line_t &l = ROW(row_number); |
1258 | line_t &l = ROW(row_number); |
1022 | |
1259 | |
1023 | if (GIMME_V != G_VOID) |
1260 | if (GIMME_V != G_VOID) |
… | |
… | |
1025 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1262 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1026 | |
1263 | |
1027 | for (int col = 0; col < THIS->ncol; col++) |
1264 | for (int col = 0; col < THIS->ncol; col++) |
1028 | wstr [col] = l.t [col]; |
1265 | wstr [col] = l.t [col]; |
1029 | |
1266 | |
1030 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
1267 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1031 | |
1268 | |
1032 | delete [] wstr; |
1269 | delete [] wstr; |
1033 | } |
1270 | } |
1034 | |
1271 | |
1035 | if (new_text) |
1272 | if (new_text) |
… | |
… | |
1056 | |
1293 | |
1057 | void |
1294 | void |
1058 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1295 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1059 | PPCODE: |
1296 | PPCODE: |
1060 | { |
1297 | { |
1061 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1298 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
1062 | XSRETURN_EMPTY; |
1299 | XSRETURN_EMPTY; |
1063 | |
1300 | |
1064 | line_t &l = ROW(row_number); |
1301 | line_t &l = ROW(row_number); |
1065 | |
1302 | |
1066 | if (GIMME_V != G_VOID) |
1303 | if (GIMME_V != G_VOID) |
… | |
… | |
1078 | { |
1315 | { |
1079 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
1316 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
1080 | croak ("new_rend must be arrayref"); |
1317 | croak ("new_rend must be arrayref"); |
1081 | |
1318 | |
1082 | AV *av = (AV *)SvRV (new_rend); |
1319 | AV *av = (AV *)SvRV (new_rend); |
1083 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
1320 | int len = min (AvFILL (av) + 1 - start_ofs, max_len); |
1084 | |
1321 | |
1085 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
1322 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
1086 | croak ("new_rend array extends beyond horizontal margins"); |
1323 | croak ("new_rend array extends beyond horizontal margins"); |
1087 | |
1324 | |
1088 | for (int col = start_col; col < start_col + len; col++) |
1325 | for (int col = start_col; col < start_col + len; col++) |
… | |
… | |
1096 | |
1333 | |
1097 | int |
1334 | int |
1098 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
1335 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
1099 | CODE: |
1336 | CODE: |
1100 | { |
1337 | { |
1101 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1338 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
1102 | XSRETURN_EMPTY; |
1339 | XSRETURN_EMPTY; |
1103 | |
1340 | |
1104 | line_t &l = ROW(row_number); |
1341 | line_t &l = ROW(row_number); |
1105 | RETVAL = l.l; |
1342 | RETVAL = l.l; |
1106 | |
1343 | |
… | |
… | |
1112 | |
1349 | |
1113 | bool |
1350 | bool |
1114 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
1351 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
1115 | CODE: |
1352 | CODE: |
1116 | { |
1353 | { |
1117 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1354 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
1118 | XSRETURN_EMPTY; |
1355 | XSRETURN_EMPTY; |
1119 | |
1356 | |
1120 | line_t &l = ROW(row_number); |
1357 | line_t &l = ROW(row_number); |
1121 | RETVAL = l.is_longer (); |
1358 | RETVAL = l.is_longer (); |
1122 | |
1359 | |
… | |
… | |
1156 | else |
1393 | else |
1157 | *r++ = *s; |
1394 | *r++ = *s; |
1158 | |
1395 | |
1159 | rxvt_pop_locale (); |
1396 | rxvt_pop_locale (); |
1160 | |
1397 | |
1161 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1398 | RETVAL = wcs2sv (rstr, r - rstr); |
1162 | |
1399 | |
1163 | delete [] rstr; |
1400 | delete [] rstr; |
1164 | } |
1401 | } |
1165 | OUTPUT: |
1402 | OUTPUT: |
1166 | RETVAL |
1403 | RETVAL |
… | |
… | |
1192 | else if (IS_COMPOSE (*s)) |
1429 | else if (IS_COMPOSE (*s)) |
1193 | r += rxvt_composite.expand (*s, r); |
1430 | r += rxvt_composite.expand (*s, r); |
1194 | else |
1431 | else |
1195 | *r++ = *s; |
1432 | *r++ = *s; |
1196 | |
1433 | |
1197 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1434 | RETVAL = wcs2sv (rstr, r - rstr); |
1198 | |
1435 | |
1199 | delete [] rstr; |
1436 | delete [] rstr; |
1200 | } |
1437 | } |
1201 | OUTPUT: |
1438 | OUTPUT: |
1202 | RETVAL |
1439 | RETVAL |
… | |
… | |
1224 | |
1461 | |
1225 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1462 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1226 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1463 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1227 | |
1464 | |
1228 | if (GIMME_V != G_VOID) |
1465 | if (GIMME_V != G_VOID) |
1229 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1466 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1230 | |
1467 | |
1231 | if (newval) |
1468 | if (newval) |
1232 | { |
1469 | { |
1233 | if (SvOK (newval)) |
1470 | if (SvOK (newval)) |
1234 | { |
1471 | { |
… | |
… | |
1239 | else |
1476 | else |
1240 | THIS->rs [index] = 0; |
1477 | THIS->rs [index] = 0; |
1241 | } |
1478 | } |
1242 | } |
1479 | } |
1243 | |
1480 | |
|
|
1481 | const char * |
|
|
1482 | rxvt_term::x_resource (const char *name) |
|
|
1483 | |
1244 | bool |
1484 | bool |
1245 | rxvt_term::option (U32 optval, int set = -1) |
1485 | rxvt_term::option (U32 optval, int set = -1) |
1246 | CODE: |
1486 | CODE: |
1247 | { |
1487 | { |
1248 | RETVAL = THIS->options & optval; |
1488 | RETVAL = THIS->options & optval; |
… | |
… | |
1252 | if (set) |
1492 | if (set) |
1253 | THIS->options |= optval; |
1493 | THIS->options |= optval; |
1254 | else |
1494 | else |
1255 | THIS->options &= ~optval; |
1495 | THIS->options &= ~optval; |
1256 | |
1496 | |
|
|
1497 | if (THIS->check_ev.is_active ()) // avoid doing this before START |
1257 | switch (optval) |
1498 | switch (optval) |
1258 | { |
1499 | { |
1259 | case Opt_skipBuiltinGlyphs: |
1500 | case Opt_skipBuiltinGlyphs: |
1260 | THIS->set_fonts (); |
1501 | THIS->set_fonts (); |
1261 | THIS->scr_remap_chars (); |
1502 | THIS->scr_remap_chars (); |
1262 | THIS->scr_touch (true); |
1503 | THIS->scr_touch (true); |
1263 | THIS->want_refresh = 1; |
1504 | THIS->want_refresh = 1; |
1264 | break; |
1505 | break; |
1265 | |
1506 | |
1266 | case Opt_cursorUnderline: |
1507 | case Opt_cursorUnderline: |
1267 | THIS->want_refresh = 1; |
1508 | THIS->want_refresh = 1; |
1268 | break; |
1509 | break; |
1269 | |
1510 | |
1270 | # case Opt_scrollBar_floating: |
1511 | # case Opt_scrollBar_floating: |
1271 | # case Opt_scrollBar_right: |
1512 | # case Opt_scrollBar_right: |
1272 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
1513 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
1273 | # break; |
1514 | # break; |
1274 | } |
1515 | } |
1275 | } |
1516 | } |
1276 | } |
1517 | } |
1277 | OUTPUT: |
1518 | OUTPUT: |
1278 | RETVAL |
1519 | RETVAL |
1279 | |
1520 | |
… | |
… | |
1307 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1548 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1308 | } |
1549 | } |
1309 | |
1550 | |
1310 | if (items == 3) |
1551 | if (items == 3) |
1311 | { |
1552 | { |
1312 | rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
1553 | rc.row = SvIV (ST (1)); |
1313 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
1554 | rc.col = SvIV (ST (2)); |
|
|
1555 | |
|
|
1556 | if (ix == 2 && rc.col == 0) |
|
|
1557 | { |
|
|
1558 | rc.row--; |
|
|
1559 | rc.col = THIS->ncol; |
|
|
1560 | } |
|
|
1561 | |
|
|
1562 | clamp_it (rc.col, 0, THIS->ncol); |
|
|
1563 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1314 | |
1564 | |
1315 | if (ix) |
1565 | if (ix) |
1316 | THIS->want_refresh = 1; |
1566 | THIS->want_refresh = 1; |
1317 | } |
1567 | } |
1318 | } |
1568 | } |
1319 | |
1569 | |
|
|
1570 | char |
|
|
1571 | rxvt_term::cur_charset () |
|
|
1572 | CODE: |
|
|
1573 | RETVAL = THIS->charsets [THIS->screen.charset]; |
|
|
1574 | OUTPUT: |
|
|
1575 | RETVAL |
|
|
1576 | |
|
|
1577 | #void |
|
|
1578 | #rxvt_term::selection_clear () |
|
|
1579 | |
|
|
1580 | void |
|
|
1581 | rxvt_term::selection_make (U32 eventtime, bool rect = false) |
|
|
1582 | CODE: |
|
|
1583 | THIS->selection.op = SELECTION_CONT; |
|
|
1584 | THIS->selection.rect = rect; |
|
|
1585 | THIS->selection_make (eventtime); |
|
|
1586 | |
1320 | int |
1587 | int |
1321 | rxvt_term::selection_grab (U32 eventtime) |
1588 | rxvt_term::selection_grab (U32 eventtime) |
1322 | |
1589 | |
1323 | void |
1590 | void |
1324 | rxvt_term::selection (SV *newtext = 0) |
1591 | rxvt_term::selection (SV *newtext = 0) |
1325 | PPCODE: |
1592 | PPCODE: |
1326 | { |
1593 | { |
1327 | if (GIMME_V != G_VOID) |
1594 | if (GIMME_V != G_VOID) |
1328 | XPUSHs (THIS->selection.text |
1595 | XPUSHs (THIS->selection.text |
1329 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
1596 | ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) |
1330 | : &PL_sv_undef); |
1597 | : &PL_sv_undef); |
1331 | |
1598 | |
1332 | if (newtext) |
1599 | if (newtext) |
1333 | { |
1600 | { |
1334 | free (THIS->selection.text); |
1601 | free (THIS->selection.text); |
… | |
… | |
1460 | RETVAL = THIS; |
1727 | RETVAL = THIS; |
1461 | OUTPUT: |
1728 | OUTPUT: |
1462 | RETVAL |
1729 | RETVAL |
1463 | |
1730 | |
1464 | timer * |
1731 | timer * |
|
|
1732 | timer::after (NV delay) |
|
|
1733 | CODE: |
|
|
1734 | THIS->start (NOW + delay); |
|
|
1735 | RETVAL = THIS; |
|
|
1736 | OUTPUT: |
|
|
1737 | RETVAL |
|
|
1738 | |
|
|
1739 | timer * |
1465 | timer::stop () |
1740 | timer::stop () |
1466 | CODE: |
1741 | CODE: |
1467 | THIS->stop (); |
1742 | THIS->stop (); |
1468 | RETVAL = THIS; |
1743 | RETVAL = THIS; |
1469 | OUTPUT: |
1744 | OUTPUT: |