… | |
… | |
26 | #include <XSUB.h> |
26 | #include <XSUB.h> |
27 | #undef line_t |
27 | #undef line_t |
28 | |
28 | |
29 | #include "../config.h" |
29 | #include "../config.h" |
30 | |
30 | |
|
|
31 | #include <cstddef> |
31 | #include <cstdarg> |
32 | #include <cstdarg> |
32 | |
33 | |
|
|
34 | #include "unistd.h" |
|
|
35 | |
|
|
36 | #include "iom.h" |
33 | #include "rxvt.h" |
37 | #include "rxvt.h" |
34 | #include "iom.h" |
38 | #include "keyboard.h" |
35 | #include "rxvtutil.h" |
39 | #include "rxvtutil.h" |
36 | #include "rxvtperl.h" |
40 | #include "rxvtperl.h" |
37 | |
41 | |
38 | #include "perlxsi.c" |
42 | #include "perlxsi.c" |
|
|
43 | |
|
|
44 | #ifdef HAVE_SCROLLBARS |
|
|
45 | # define GRAB_CURSOR THIS->leftptr_cursor |
|
|
46 | #else |
|
|
47 | # define GRAB_CURSOR None |
|
|
48 | #endif |
39 | |
49 | |
40 | #undef LINENO |
50 | #undef LINENO |
41 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
51 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
42 | #undef ROW |
52 | #undef ROW |
43 | #define ROW(n) THIS->row_buf [LINENO (n)] |
53 | #define ROW(n) THIS->row_buf [LINENO (n)] |
44 | |
54 | |
|
|
55 | #define ENABLE_PERL_FRILLS 1 |
|
|
56 | |
45 | ///////////////////////////////////////////////////////////////////////////// |
57 | ///////////////////////////////////////////////////////////////////////////// |
46 | |
58 | |
47 | static wchar_t * |
59 | static wchar_t * |
48 | sv2wcs (SV *sv) |
60 | sv2wcs (SV *sv) |
49 | { |
61 | { |
… | |
… | |
101 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
113 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
102 | |
114 | |
103 | return (long)mg->mg_ptr; |
115 | return (long)mg->mg_ptr; |
104 | } |
116 | } |
105 | |
117 | |
106 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
118 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
107 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
119 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
108 | |
120 | |
109 | ///////////////////////////////////////////////////////////////////////////// |
121 | ///////////////////////////////////////////////////////////////////////////// |
110 | |
122 | |
111 | struct perl_watcher |
123 | struct perl_watcher |
… | |
… | |
290 | void |
302 | void |
291 | overlay::show () |
303 | overlay::show () |
292 | { |
304 | { |
293 | char key[33]; sprintf (key, "%32lx", (long)this); |
305 | char key[33]; sprintf (key, "%32lx", (long)this); |
294 | |
306 | |
295 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
307 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
296 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
308 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
297 | } |
309 | } |
298 | |
310 | |
299 | void |
311 | void |
300 | overlay::hide () |
312 | overlay::hide () |
301 | { |
313 | { |
302 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); |
314 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
303 | |
315 | |
304 | if (ovs) |
316 | if (ovs) |
305 | { |
317 | { |
306 | char key[33]; sprintf (key, "%32lx", (long)this); |
318 | char key[33]; sprintf (key, "%32lx", (long)this); |
307 | |
319 | |
… | |
… | |
321 | for (int y = ov_h; y--; ) |
333 | for (int y = ov_h; y--; ) |
322 | { |
334 | { |
323 | text_t *t1 = text [y]; |
335 | text_t *t1 = text [y]; |
324 | rend_t *r1 = rend [y]; |
336 | rend_t *r1 = rend [y]; |
325 | |
337 | |
326 | text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
338 | text_t *t2 = ROW(y + ov_y + THIS->view_start).t + ov_x; |
327 | rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
339 | rend_t *r2 = ROW(y + ov_y + THIS->view_start).r + ov_x; |
328 | |
340 | |
329 | for (int x = ov_w; x--; ) |
341 | for (int x = ov_w; x--; ) |
330 | { |
342 | { |
331 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
343 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
332 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
344 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
… | |
… | |
369 | |
381 | |
370 | struct rxvt_perl_interp rxvt_perl; |
382 | struct rxvt_perl_interp rxvt_perl; |
371 | |
383 | |
372 | static PerlInterpreter *perl; |
384 | static PerlInterpreter *perl; |
373 | |
385 | |
374 | rxvt_perl_interp::rxvt_perl_interp () |
|
|
375 | { |
|
|
376 | } |
|
|
377 | |
|
|
378 | rxvt_perl_interp::~rxvt_perl_interp () |
386 | rxvt_perl_interp::~rxvt_perl_interp () |
379 | { |
387 | { |
380 | if (perl) |
388 | if (perl) |
381 | { |
389 | { |
382 | perl_destruct (perl); |
390 | perl_destruct (perl); |
383 | perl_free (perl); |
391 | perl_free (perl); |
384 | } |
392 | } |
385 | } |
393 | } |
386 | |
394 | |
387 | void |
395 | void |
388 | rxvt_perl_interp::init () |
396 | rxvt_perl_interp::init (rxvt_term *term) |
389 | { |
397 | { |
390 | if (!perl) |
398 | if (!perl) |
391 | { |
399 | { |
|
|
400 | rxvt_push_locale (""); // perl init destroys current locale |
|
|
401 | |
|
|
402 | perl_environ = rxvt_environ; |
|
|
403 | swap (perl_environ, environ); |
|
|
404 | |
392 | char *argv[] = { |
405 | char *argv[] = { |
393 | "", |
406 | "", |
394 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
407 | "-e" |
|
|
408 | "BEGIN {" |
|
|
409 | " urxvt->bootstrap;" |
|
|
410 | " unshift @INC, '" LIBDIR "';" |
|
|
411 | "}" |
|
|
412 | "" |
|
|
413 | "use urxvt;" |
395 | }; |
414 | }; |
396 | |
415 | |
397 | perl = perl_alloc (); |
416 | perl = perl_alloc (); |
398 | perl_construct (perl); |
417 | perl_construct (perl); |
399 | |
418 | |
… | |
… | |
404 | |
423 | |
405 | perl_destruct (perl); |
424 | perl_destruct (perl); |
406 | perl_free (perl); |
425 | perl_free (perl); |
407 | perl = 0; |
426 | perl = 0; |
408 | } |
427 | } |
|
|
428 | |
|
|
429 | swap (perl_environ, environ); |
|
|
430 | |
|
|
431 | rxvt_pop_locale (); |
|
|
432 | } |
|
|
433 | |
|
|
434 | if (perl) |
|
|
435 | { |
|
|
436 | // runs outside of perls ENV |
|
|
437 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
|
|
438 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
|
|
439 | } |
|
|
440 | } |
|
|
441 | |
|
|
442 | static void |
|
|
443 | ungrab (rxvt_term *THIS) |
|
|
444 | { |
|
|
445 | if (THIS->perl.grabtime) |
|
|
446 | { |
|
|
447 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
448 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
449 | THIS->perl.grabtime = 0; |
|
|
450 | } |
|
|
451 | } |
|
|
452 | |
|
|
453 | static void |
|
|
454 | swap_overlays (rxvt_term *term) |
|
|
455 | { |
|
|
456 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
457 | |
|
|
458 | if (HvKEYS (hv)) |
|
|
459 | { |
|
|
460 | hv_iterinit (hv); |
|
|
461 | |
|
|
462 | while (HE *he = hv_iternext (hv)) |
|
|
463 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
409 | } |
464 | } |
410 | } |
465 | } |
411 | |
466 | |
412 | bool |
467 | bool |
413 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
468 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
414 | { |
469 | { |
415 | if (!perl) |
470 | if (!perl || !term->perl.self) |
416 | return false; |
471 | return false; |
417 | |
472 | |
418 | if (htype == HOOK_INIT) // first hook ever called |
473 | // pre-handling of some events |
|
|
474 | if (htype == HOOK_REFRESH_END) |
|
|
475 | swap_overlays (term); |
|
|
476 | |
|
|
477 | swap (perl_environ, environ); |
|
|
478 | |
|
|
479 | bool event_consumed; |
|
|
480 | |
|
|
481 | if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always |
|
|
482 | || term->perl.should_invoke [htype]) |
|
|
483 | try |
419 | { |
484 | { |
420 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
485 | dSP; |
421 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
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 (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 (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 (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 | # define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) |
|
|
541 | # undef set |
|
|
542 | |
|
|
543 | setiv (type, xe->type); |
|
|
544 | setiv (send_event, xe->xany.send_event); |
|
|
545 | setiv (serial, xe->xany.serial); |
|
|
546 | |
|
|
547 | switch (xe->type) |
|
|
548 | { |
|
|
549 | case KeyPress: |
|
|
550 | case KeyRelease: |
|
|
551 | case ButtonPress: |
|
|
552 | case ButtonRelease: |
|
|
553 | case MotionNotify: |
|
|
554 | setuv (window, xe->xmotion.window); |
|
|
555 | setuv (root, xe->xmotion.root); |
|
|
556 | setuv (subwindow, xe->xmotion.subwindow); |
|
|
557 | setuv (time, xe->xmotion.time); |
|
|
558 | setiv (x, xe->xmotion.x); |
|
|
559 | setiv (y, xe->xmotion.y); |
|
|
560 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
561 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
562 | setiv (x_root, xe->xmotion.x_root); |
|
|
563 | setiv (y_root, xe->xmotion.y_root); |
|
|
564 | setuv (state, xe->xmotion.state); |
|
|
565 | |
|
|
566 | switch (xe->type) |
|
|
567 | { |
|
|
568 | case KeyPress: |
|
|
569 | case KeyRelease: |
|
|
570 | setuv (keycode, xe->xkey.keycode); |
|
|
571 | break; |
|
|
572 | |
|
|
573 | case ButtonPress: |
|
|
574 | case ButtonRelease: |
|
|
575 | setuv (button, xe->xbutton.button); |
|
|
576 | break; |
|
|
577 | |
|
|
578 | case MotionNotify: |
|
|
579 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
580 | break; |
|
|
581 | } |
|
|
582 | |
|
|
583 | break; |
|
|
584 | |
|
|
585 | case MapNotify: |
|
|
586 | case UnmapNotify: |
|
|
587 | case ConfigureNotify: |
|
|
588 | setuv (event, xe->xconfigure.event); |
|
|
589 | setuv (window, xe->xconfigure.window); |
|
|
590 | |
|
|
591 | switch (xe->type) |
|
|
592 | { |
|
|
593 | case ConfigureNotify: |
|
|
594 | setiv (x, xe->xconfigure.x); |
|
|
595 | setiv (y, xe->xconfigure.y); |
|
|
596 | setiv (width, xe->xconfigure.width); |
|
|
597 | setiv (height, xe->xconfigure.height); |
|
|
598 | setuv (above, xe->xconfigure.above); |
|
|
599 | break; |
|
|
600 | } |
|
|
601 | |
|
|
602 | break; |
|
|
603 | } |
|
|
604 | |
|
|
605 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
606 | } |
|
|
607 | break; |
|
|
608 | |
|
|
609 | case DT_END: |
|
|
610 | goto call; |
|
|
611 | |
|
|
612 | default: |
|
|
613 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
614 | } |
|
|
615 | } |
|
|
616 | |
|
|
617 | call: |
|
|
618 | va_end (ap); |
|
|
619 | |
|
|
620 | PUTBACK; |
|
|
621 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
622 | SPAGAIN; |
|
|
623 | |
|
|
624 | if (count) |
|
|
625 | { |
|
|
626 | SV *status = POPs; |
|
|
627 | count = SvTRUE (status); |
|
|
628 | } |
|
|
629 | |
|
|
630 | PUTBACK; |
|
|
631 | FREETMPS; |
|
|
632 | LEAVE; |
|
|
633 | |
|
|
634 | if (SvTRUE (ERRSV)) |
|
|
635 | { |
|
|
636 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
637 | ungrab (term); // better lose the grab than the session |
|
|
638 | } |
|
|
639 | |
|
|
640 | event_consumed = !!count; |
422 | } |
641 | } |
423 | else if (!term->self) |
642 | catch (...) |
424 | return false; // perl not initialized for this instance |
643 | { |
|
|
644 | swap (perl_environ, environ); |
|
|
645 | throw; |
|
|
646 | } |
|
|
647 | else |
|
|
648 | event_consumed = false; |
|
|
649 | |
|
|
650 | // post-handling of some events |
|
|
651 | if (htype == HOOK_REFRESH_BEGIN) |
|
|
652 | swap_overlays (term); |
425 | else if (htype == HOOK_DESTROY) |
653 | else if (htype == HOOK_DESTROY) |
426 | { |
654 | { |
427 | // handled later |
655 | clearSVptr ((SV *)term->perl.self); |
|
|
656 | SvREFCNT_dec ((SV *)term->perl.self); |
428 | } |
657 | } |
429 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
|
|
430 | { |
|
|
431 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
|
|
432 | |
658 | |
433 | if (HvKEYS (hv)) |
659 | swap (perl_environ, environ); |
434 | { |
|
|
435 | hv_iterinit (hv); |
|
|
436 | |
660 | |
437 | while (HE *he = hv_iternext (hv)) |
661 | return event_consumed; |
438 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
439 | } |
|
|
440 | } |
|
|
441 | else if (!should_invoke [htype]) |
|
|
442 | return false; |
|
|
443 | |
|
|
444 | dSP; |
|
|
445 | va_list ap; |
|
|
446 | |
|
|
447 | va_start (ap, htype); |
|
|
448 | |
|
|
449 | ENTER; |
|
|
450 | SAVETMPS; |
|
|
451 | |
|
|
452 | PUSHMARK (SP); |
|
|
453 | |
|
|
454 | XPUSHs (sv_2mortal (newSVterm (term))); |
|
|
455 | XPUSHs (sv_2mortal (newSViv (htype))); |
|
|
456 | |
|
|
457 | for (;;) { |
|
|
458 | data_type dt = (data_type)va_arg (ap, int); |
|
|
459 | |
|
|
460 | switch (dt) |
|
|
461 | { |
|
|
462 | case DT_INT: |
|
|
463 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
|
|
464 | break; |
|
|
465 | |
|
|
466 | case DT_LONG: |
|
|
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
|
|
468 | break; |
|
|
469 | |
|
|
470 | case DT_STRING: |
|
|
471 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
|
|
472 | break; |
|
|
473 | |
|
|
474 | case DT_STRING_LEN: |
|
|
475 | { |
|
|
476 | char *str = va_arg (ap, char *); |
|
|
477 | int len = va_arg (ap, int); |
|
|
478 | |
|
|
479 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
|
|
480 | } |
|
|
481 | break; |
|
|
482 | |
|
|
483 | case DT_XEVENT: |
|
|
484 | { |
|
|
485 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
486 | HV *hv = newHV (); |
|
|
487 | |
|
|
488 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
489 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
490 | # undef set |
|
|
491 | |
|
|
492 | setiv (type, xe->type); |
|
|
493 | setiv (send_event, xe->xany.send_event); |
|
|
494 | setiv (serial, xe->xany.serial); |
|
|
495 | |
|
|
496 | switch (xe->type) |
|
|
497 | { |
|
|
498 | case KeyPress: |
|
|
499 | case KeyRelease: |
|
|
500 | case ButtonPress: |
|
|
501 | case ButtonRelease: |
|
|
502 | case MotionNotify: |
|
|
503 | setiv (time, xe->xmotion.time); |
|
|
504 | setiv (x, xe->xmotion.x); |
|
|
505 | setiv (y, xe->xmotion.y); |
|
|
506 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
507 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
508 | setiv (x_root, xe->xmotion.x_root); |
|
|
509 | setiv (y_root, xe->xmotion.y_root); |
|
|
510 | setiv (state, xe->xmotion.state); |
|
|
511 | break; |
|
|
512 | } |
|
|
513 | |
|
|
514 | switch (xe->type) |
|
|
515 | { |
|
|
516 | case KeyPress: |
|
|
517 | case KeyRelease: |
|
|
518 | setiv (keycode, xe->xkey.keycode); |
|
|
519 | break; |
|
|
520 | |
|
|
521 | case ButtonPress: |
|
|
522 | case ButtonRelease: |
|
|
523 | setiv (button, xe->xbutton.button); |
|
|
524 | break; |
|
|
525 | |
|
|
526 | case MotionNotify: |
|
|
527 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
528 | break; |
|
|
529 | } |
|
|
530 | |
|
|
531 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
532 | } |
|
|
533 | break; |
|
|
534 | |
|
|
535 | case DT_USTRING_LEN: |
|
|
536 | { |
|
|
537 | unicode_t *ustr = va_arg (ap, unicode_t *); |
|
|
538 | int ulen = va_arg (ap, int); |
|
|
539 | wchar_t *wstr = new wchar_t [ulen]; |
|
|
540 | |
|
|
541 | for (int i = ulen; i--; ) |
|
|
542 | wstr [i] = ustr [i]; |
|
|
543 | |
|
|
544 | XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); |
|
|
545 | |
|
|
546 | delete [] wstr; |
|
|
547 | } |
|
|
548 | |
|
|
549 | case DT_END: |
|
|
550 | { |
|
|
551 | va_end (ap); |
|
|
552 | |
|
|
553 | PUTBACK; |
|
|
554 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
555 | SPAGAIN; |
|
|
556 | |
|
|
557 | if (count) |
|
|
558 | { |
|
|
559 | SV *status = POPs; |
|
|
560 | count = SvTRUE (status); |
|
|
561 | } |
|
|
562 | |
|
|
563 | PUTBACK; |
|
|
564 | FREETMPS; |
|
|
565 | LEAVE; |
|
|
566 | |
|
|
567 | if (SvTRUE (ERRSV)) |
|
|
568 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
569 | |
|
|
570 | if (htype == HOOK_DESTROY) |
|
|
571 | { |
|
|
572 | clearSVptr ((SV *)term->self); |
|
|
573 | SvREFCNT_dec ((SV *)term->self); |
|
|
574 | } |
|
|
575 | |
|
|
576 | return count; |
|
|
577 | } |
|
|
578 | |
|
|
579 | default: |
|
|
580 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
581 | } |
|
|
582 | } |
|
|
583 | } |
662 | } |
584 | |
663 | |
585 | ///////////////////////////////////////////////////////////////////////////// |
664 | ///////////////////////////////////////////////////////////////////////////// |
586 | |
665 | |
587 | MODULE = urxvt PACKAGE = urxvt |
666 | MODULE = urxvt PACKAGE = urxvt |
588 | |
667 | |
589 | PROTOTYPES: ENABLE |
668 | PROTOTYPES: ENABLE |
590 | |
669 | |
591 | BOOT: |
670 | BOOT: |
592 | { |
671 | { |
593 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
672 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
|
|
673 | sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1)); |
|
|
674 | sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1)); |
|
|
675 | sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1)); |
|
|
676 | |
594 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
677 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
595 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
678 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
596 | # include "hookinc.h" |
679 | # include "hookinc.h" |
597 | # undef def |
680 | # undef def |
598 | |
681 | |
|
|
682 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
683 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
684 | # define nodef(name) |
|
|
685 | # include "optinc.h" |
|
|
686 | # undef nodef |
|
|
687 | # undef def |
|
|
688 | |
|
|
689 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
690 | struct { |
|
|
691 | const char *name; |
|
|
692 | IV iv; |
|
|
693 | } *civ, const_iv[] = { |
|
|
694 | # define const_iv(name) { # name, (IV)name } |
599 | export_const (DEFAULT_RSTYLE); |
695 | const_iv (DEFAULT_RSTYLE), |
600 | export_const (OVERLAY_RSTYLE); |
696 | const_iv (OVERLAY_RSTYLE), |
601 | export_const (RS_Bold); |
697 | const_iv (RS_Bold), |
602 | export_const (RS_Italic); |
698 | const_iv (RS_Italic), |
603 | export_const (RS_Blink); |
699 | const_iv (RS_Blink), |
604 | export_const (RS_RVid); |
700 | const_iv (RS_RVid), |
605 | export_const (RS_Uline); |
701 | const_iv (RS_Uline), |
606 | |
702 | |
607 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
703 | const_iv (CurrentTime), |
608 | } |
704 | const_iv (ShiftMask), |
|
|
705 | const_iv (LockMask), |
|
|
706 | const_iv (ControlMask), |
|
|
707 | const_iv (Mod1Mask), |
|
|
708 | const_iv (Mod2Mask), |
|
|
709 | const_iv (Mod3Mask), |
|
|
710 | const_iv (Mod4Mask), |
|
|
711 | const_iv (Mod5Mask), |
|
|
712 | const_iv (Button1Mask), |
|
|
713 | const_iv (Button2Mask), |
|
|
714 | const_iv (Button3Mask), |
|
|
715 | const_iv (Button4Mask), |
|
|
716 | const_iv (Button5Mask), |
|
|
717 | const_iv (AnyModifier), |
609 | |
718 | |
610 | SV * |
719 | const_iv (EVENT_NONE), |
611 | new (...) |
720 | const_iv (EVENT_READ), |
612 | CODE: |
721 | const_iv (EVENT_WRITE), |
613 | { |
|
|
614 | stringvec *argv = new stringvec; |
|
|
615 | bool success; |
|
|
616 | |
722 | |
617 | for (int i = 0; i < items ;i++) |
723 | const_iv (NoEventMask), |
618 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
724 | const_iv (KeyPressMask), |
|
|
725 | const_iv (KeyReleaseMask), |
|
|
726 | const_iv (ButtonPressMask), |
|
|
727 | const_iv (ButtonReleaseMask), |
|
|
728 | const_iv (EnterWindowMask), |
|
|
729 | const_iv (LeaveWindowMask), |
|
|
730 | const_iv (PointerMotionMask), |
|
|
731 | const_iv (PointerMotionHintMask), |
|
|
732 | const_iv (Button1MotionMask), |
|
|
733 | const_iv (Button2MotionMask), |
|
|
734 | const_iv (Button3MotionMask), |
|
|
735 | const_iv (Button4MotionMask), |
|
|
736 | const_iv (Button5MotionMask), |
|
|
737 | const_iv (ButtonMotionMask), |
|
|
738 | const_iv (KeymapStateMask), |
|
|
739 | const_iv (ExposureMask), |
|
|
740 | const_iv (VisibilityChangeMask), |
|
|
741 | const_iv (StructureNotifyMask), |
|
|
742 | const_iv (ResizeRedirectMask), |
|
|
743 | const_iv (SubstructureNotifyMask), |
|
|
744 | const_iv (SubstructureRedirectMask), |
|
|
745 | const_iv (FocusChangeMask), |
|
|
746 | const_iv (PropertyChangeMask), |
|
|
747 | const_iv (ColormapChangeMask), |
|
|
748 | const_iv (OwnerGrabButtonMask), |
619 | |
749 | |
620 | rxvt_term *term = new rxvt_term; |
750 | const_iv (KeyPress), |
|
|
751 | const_iv (KeyRelease), |
|
|
752 | const_iv (ButtonPress), |
|
|
753 | const_iv (ButtonRelease), |
|
|
754 | const_iv (MotionNotify), |
|
|
755 | const_iv (EnterNotify), |
|
|
756 | const_iv (LeaveNotify), |
|
|
757 | const_iv (FocusIn), |
|
|
758 | const_iv (FocusOut), |
|
|
759 | const_iv (KeymapNotify), |
|
|
760 | const_iv (Expose), |
|
|
761 | const_iv (GraphicsExpose), |
|
|
762 | const_iv (NoExpose), |
|
|
763 | const_iv (VisibilityNotify), |
|
|
764 | const_iv (CreateNotify), |
|
|
765 | const_iv (DestroyNotify), |
|
|
766 | const_iv (UnmapNotify), |
|
|
767 | const_iv (MapNotify), |
|
|
768 | const_iv (MapRequest), |
|
|
769 | const_iv (ReparentNotify), |
|
|
770 | const_iv (ConfigureNotify), |
|
|
771 | const_iv (ConfigureRequest), |
|
|
772 | const_iv (GravityNotify), |
|
|
773 | const_iv (ResizeRequest), |
|
|
774 | const_iv (CirculateNotify), |
|
|
775 | const_iv (CirculateRequest), |
|
|
776 | const_iv (PropertyNotify), |
|
|
777 | const_iv (SelectionClear), |
|
|
778 | const_iv (SelectionRequest), |
|
|
779 | const_iv (SelectionNotify), |
|
|
780 | const_iv (ColormapNotify), |
|
|
781 | const_iv (ClientMessage), |
|
|
782 | const_iv (MappingNotify), |
|
|
783 | }; |
621 | |
784 | |
622 | term->argv = argv; |
785 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); |
623 | |
786 | civ-- > const_iv; ) |
624 | try |
787 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
625 | { |
|
|
626 | if (!term->init (argv->size (), argv->begin ())) |
|
|
627 | term = 0; |
|
|
628 | } |
|
|
629 | catch (const class rxvt_failure_exception &e) |
|
|
630 | { |
|
|
631 | term->destroy (); |
|
|
632 | croak ("exception caught while initializing new terminal instance"); |
|
|
633 | } |
|
|
634 | |
|
|
635 | RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
|
|
636 | } |
788 | } |
637 | OUTPUT: |
|
|
638 | RETVAL |
|
|
639 | |
|
|
640 | void |
|
|
641 | set_should_invoke (int htype, int value) |
|
|
642 | CODE: |
|
|
643 | rxvt_perl.should_invoke [htype] = value; |
|
|
644 | |
789 | |
645 | void |
790 | void |
646 | warn (const char *msg) |
791 | warn (const char *msg) |
647 | CODE: |
792 | CODE: |
648 | rxvt_warn ("%s", msg); |
793 | rxvt_warn ("%s", msg); |
649 | |
794 | |
650 | void |
795 | void |
651 | fatal (const char *msg) |
796 | fatal (const char *msg) |
652 | CODE: |
797 | CODE: |
653 | rxvt_fatal ("%s", msg); |
798 | rxvt_fatal ("%s", msg); |
|
|
799 | |
|
|
800 | void |
|
|
801 | _exit (int status) |
654 | |
802 | |
655 | NV |
803 | NV |
656 | NOW () |
804 | NOW () |
657 | CODE: |
805 | CODE: |
658 | RETVAL = NOW; |
806 | RETVAL = NOW; |
… | |
… | |
707 | OUTPUT: |
855 | OUTPUT: |
708 | RETVAL |
856 | RETVAL |
709 | |
857 | |
710 | MODULE = urxvt PACKAGE = urxvt::term |
858 | MODULE = urxvt PACKAGE = urxvt::term |
711 | |
859 | |
|
|
860 | SV * |
|
|
861 | _new (...) |
|
|
862 | CODE: |
|
|
863 | { |
|
|
864 | if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) |
|
|
865 | croak ("first argument to urxvt::term->_new must be arrayref"); |
|
|
866 | |
|
|
867 | rxvt_term *term = new rxvt_term; |
|
|
868 | |
|
|
869 | term->argv = new stringvec; |
|
|
870 | term->envv = new stringvec; |
|
|
871 | |
|
|
872 | for (int i = 1; i < items; i++) |
|
|
873 | term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
874 | |
|
|
875 | AV *envv = (AV *)SvRV (ST (0)); |
|
|
876 | for (int i = av_len (envv) + 1; i--; ) |
|
|
877 | term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); |
|
|
878 | |
|
|
879 | term->envv->push_back (0); |
|
|
880 | |
|
|
881 | bool success; |
|
|
882 | |
|
|
883 | try |
|
|
884 | { |
|
|
885 | success = term->init (term->argv->size (), term->argv->begin ()); |
|
|
886 | } |
|
|
887 | catch (const class rxvt_failure_exception &e) |
|
|
888 | { |
|
|
889 | success = false; |
|
|
890 | } |
|
|
891 | |
|
|
892 | if (!success) |
|
|
893 | { |
|
|
894 | term->destroy (); |
|
|
895 | croak ("error while initializing new terminal instance"); |
|
|
896 | } |
|
|
897 | |
|
|
898 | RETVAL = term && term->perl.self |
|
|
899 | ? newSVterm (term) : &PL_sv_undef; |
|
|
900 | } |
|
|
901 | OUTPUT: |
|
|
902 | RETVAL |
|
|
903 | |
712 | void |
904 | void |
713 | rxvt_term::destroy () |
905 | rxvt_term::destroy () |
|
|
906 | |
|
|
907 | #if ENABLE_PERL_FRILLS |
|
|
908 | |
|
|
909 | void |
|
|
910 | rxvt_term::XListProperties (U32 window) |
|
|
911 | PPCODE: |
|
|
912 | { |
|
|
913 | int count; |
|
|
914 | Atom *props = XListProperties (THIS->display->display, (Window)window, &count); |
|
|
915 | |
|
|
916 | EXTEND (SP, count); |
|
|
917 | while (count--) |
|
|
918 | PUSHs (newSVuv ((U32)props [count])); |
|
|
919 | |
|
|
920 | XFree (props); |
|
|
921 | } |
|
|
922 | |
|
|
923 | void |
|
|
924 | rxvt_term::XGetWindowProperty (U32 window, U32 property) |
|
|
925 | PPCODE: |
|
|
926 | { |
|
|
927 | Atom type; |
|
|
928 | int format; |
|
|
929 | unsigned long nitems; |
|
|
930 | unsigned long bytes_after; |
|
|
931 | unsigned char *prop; |
|
|
932 | XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property, |
|
|
933 | 0, 1<<30, 0, AnyPropertyType, |
|
|
934 | &type, &format, &nitems, &bytes_after, &prop); |
|
|
935 | if (type != None) |
|
|
936 | { |
|
|
937 | EXTEND (SP, 3); |
|
|
938 | PUSHs (newSVuv ((U32)type)); |
|
|
939 | PUSHs (newSViv (format)); |
|
|
940 | PUSHs (newSVpvn ((char *)prop, nitems * format / 8)); |
|
|
941 | XFree (prop); |
|
|
942 | } |
|
|
943 | } |
|
|
944 | |
|
|
945 | void |
|
|
946 | rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data) |
|
|
947 | CODE: |
|
|
948 | { |
|
|
949 | STRLEN len; |
|
|
950 | char *data_ = SvPVbyte (data, len); |
|
|
951 | |
|
|
952 | XChangeProperty (THIS->display->display, (Window)window, (Atom)property, |
|
|
953 | type, format, PropModeReplace, |
|
|
954 | (unsigned char *)data, len * 8 / format); |
|
|
955 | } |
|
|
956 | |
|
|
957 | void |
|
|
958 | rxvt_term::XDeleteProperty (U32 window, U32 property) |
|
|
959 | CODE: |
|
|
960 | XDeleteProperty (THIS->display->display, (Window)window, (Atom)property); |
|
|
961 | |
|
|
962 | U32 |
|
|
963 | rxvt_term::DefaultRootWindow () |
|
|
964 | CODE: |
|
|
965 | RETVAL = (U32)THIS->display->root; |
|
|
966 | OUTPUT: |
|
|
967 | RETVAL |
|
|
968 | |
|
|
969 | U32 |
|
|
970 | rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height) |
|
|
971 | CODE: |
|
|
972 | RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent, |
|
|
973 | x, y, width, height, 0, |
|
|
974 | THIS->pix_colors_focused[Color_border], |
|
|
975 | THIS->pix_colors_focused[Color_border]); |
|
|
976 | OUTPUT: |
|
|
977 | RETVAL |
|
|
978 | |
|
|
979 | void |
|
|
980 | rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0) |
|
|
981 | CODE: |
|
|
982 | XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y); |
|
|
983 | |
|
|
984 | void |
|
|
985 | rxvt_term::XMapWindow (U32 window) |
|
|
986 | CODE: |
|
|
987 | XMapWindow (THIS->display->display, (Window)window); |
|
|
988 | |
|
|
989 | void |
|
|
990 | rxvt_term::XUnmapWindow (U32 window) |
|
|
991 | CODE: |
|
|
992 | XUnmapWindow (THIS->display->display, (Window)window); |
|
|
993 | |
|
|
994 | #endif |
|
|
995 | |
|
|
996 | void |
|
|
997 | rxvt_term::set_should_invoke (int htype, int inc) |
|
|
998 | CODE: |
|
|
999 | THIS->perl.should_invoke [htype] += inc; |
|
|
1000 | |
|
|
1001 | void |
|
|
1002 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
1003 | CODE: |
|
|
1004 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
1005 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
1006 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
|
|
1007 | |
|
|
1008 | bool |
|
|
1009 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
1010 | CODE: |
|
|
1011 | { |
|
|
1012 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
1013 | |
|
|
1014 | THIS->perl.grabtime = 0; |
|
|
1015 | |
|
|
1016 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
1017 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
1018 | mode, mode, None, GRAB_CURSOR, eventtime)) |
|
|
1019 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
1020 | THIS->perl.grabtime = eventtime; |
|
|
1021 | else |
|
|
1022 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
1023 | |
|
|
1024 | RETVAL = !!THIS->perl.grabtime; |
|
|
1025 | } |
|
|
1026 | OUTPUT: |
|
|
1027 | RETVAL |
|
|
1028 | |
|
|
1029 | void |
|
|
1030 | rxvt_term::allow_events_async () |
|
|
1031 | CODE: |
|
|
1032 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
|
|
1033 | |
|
|
1034 | void |
|
|
1035 | rxvt_term::allow_events_sync () |
|
|
1036 | CODE: |
|
|
1037 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
|
|
1038 | |
|
|
1039 | void |
|
|
1040 | rxvt_term::allow_events_replay () |
|
|
1041 | CODE: |
|
|
1042 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
|
|
1043 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
|
|
1044 | |
|
|
1045 | void |
|
|
1046 | rxvt_term::ungrab () |
|
|
1047 | CODE: |
|
|
1048 | ungrab (THIS); |
714 | |
1049 | |
715 | int |
1050 | int |
716 | rxvt_term::strwidth (SV *str) |
1051 | rxvt_term::strwidth (SV *str) |
717 | CODE: |
1052 | CODE: |
718 | { |
1053 | { |
… | |
… | |
760 | free (wstr); |
1095 | free (wstr); |
761 | } |
1096 | } |
762 | OUTPUT: |
1097 | OUTPUT: |
763 | RETVAL |
1098 | RETVAL |
764 | |
1099 | |
765 | # very portable, especially on objects as opposed to pods |
1100 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
766 | #define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
|
|
767 | |
1101 | |
768 | #define TERM_OFFSET_width TERM_OFFSET(width) |
1102 | #define TERM_OFFSET_width TERM_OFFSET(width) |
769 | #define TERM_OFFSET_height TERM_OFFSET(height) |
1103 | #define TERM_OFFSET_height TERM_OFFSET(height) |
770 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
1104 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
771 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
1105 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
… | |
… | |
774 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
1108 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
775 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
1109 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
776 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
1110 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
777 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
1111 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
778 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
1112 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
779 | #define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) |
1113 | #define TERM_OFFSET_top_row TERM_OFFSET(top_row) |
780 | |
1114 | |
781 | int |
1115 | int |
782 | rxvt_term::width () |
1116 | rxvt_term::width () |
783 | ALIAS: |
1117 | ALIAS: |
784 | width = TERM_OFFSET_width |
1118 | width = TERM_OFFSET_width |
… | |
… | |
790 | ncol = TERM_OFFSET_ncol |
1124 | ncol = TERM_OFFSET_ncol |
791 | focus = TERM_OFFSET_focus |
1125 | focus = TERM_OFFSET_focus |
792 | mapped = TERM_OFFSET_mapped |
1126 | mapped = TERM_OFFSET_mapped |
793 | saveLines = TERM_OFFSET_saveLines |
1127 | saveLines = TERM_OFFSET_saveLines |
794 | total_rows = TERM_OFFSET_total_rows |
1128 | total_rows = TERM_OFFSET_total_rows |
795 | nsaved = TERM_OFFSET_nsaved |
1129 | top_row = TERM_OFFSET_top_row |
796 | CODE: |
1130 | CODE: |
797 | RETVAL = *(int *)((char *)THIS + ix); |
1131 | RETVAL = *(int *)((char *)THIS + ix); |
798 | OUTPUT: |
1132 | OUTPUT: |
|
|
1133 | RETVAL |
|
|
1134 | |
|
|
1135 | unsigned int |
|
|
1136 | rxvt_term::ModLevel3Mask () |
|
|
1137 | ALIAS: |
|
|
1138 | ModLevel3Mask = 0 |
|
|
1139 | ModMetaMask = 1 |
|
|
1140 | ModNumLockMask = 2 |
|
|
1141 | CODE: |
|
|
1142 | switch (ix) |
|
|
1143 | { |
|
|
1144 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
1145 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
1146 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
1147 | } |
|
|
1148 | OUTPUT: |
|
|
1149 | RETVAL |
|
|
1150 | |
|
|
1151 | char * |
|
|
1152 | rxvt_term::display_id () |
|
|
1153 | ALIAS: |
|
|
1154 | display_id = 0 |
|
|
1155 | locale = 1 |
|
|
1156 | CODE: |
|
|
1157 | switch (ix) |
|
|
1158 | { |
|
|
1159 | case 0: RETVAL = THIS->display->id; break; |
|
|
1160 | case 1: RETVAL = THIS->locale; break; |
|
|
1161 | } |
|
|
1162 | OUTPUT: |
|
|
1163 | RETVAL |
|
|
1164 | |
|
|
1165 | SV * |
|
|
1166 | rxvt_term::_env () |
|
|
1167 | CODE: |
|
|
1168 | { |
|
|
1169 | if (THIS->envv) |
|
|
1170 | { |
|
|
1171 | AV *av = newAV (); |
|
|
1172 | |
|
|
1173 | for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) |
|
|
1174 | if (*i) |
|
|
1175 | av_push (av, newSVpv (*i, 0)); |
|
|
1176 | |
|
|
1177 | RETVAL = newRV_noinc ((SV *)av); |
|
|
1178 | } |
|
|
1179 | else |
|
|
1180 | RETVAL = &PL_sv_undef; |
|
|
1181 | } |
|
|
1182 | OUTPUT: |
|
|
1183 | RETVAL |
|
|
1184 | |
|
|
1185 | int |
|
|
1186 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
|
|
1187 | CODE: |
|
|
1188 | RETVAL = THIS->pty_ev.events; |
|
|
1189 | if (events != EVENT_UNDEF) |
|
|
1190 | THIS->pty_ev.set (events); |
|
|
1191 | OUTPUT: |
799 | RETVAL |
1192 | RETVAL |
800 | |
1193 | |
801 | U32 |
1194 | U32 |
802 | rxvt_term::parent () |
1195 | rxvt_term::parent () |
803 | CODE: |
1196 | CODE: |
… | |
… | |
810 | CODE: |
1203 | CODE: |
811 | RETVAL = (U32)THIS->vt; |
1204 | RETVAL = (U32)THIS->vt; |
812 | OUTPUT: |
1205 | OUTPUT: |
813 | RETVAL |
1206 | RETVAL |
814 | |
1207 | |
|
|
1208 | void |
|
|
1209 | rxvt_term::vt_emask_add (U32 emask) |
|
|
1210 | CODE: |
|
|
1211 | THIS->vt_emask_perl |= emask; |
|
|
1212 | THIS->vt_select_input (); |
|
|
1213 | |
815 | U32 |
1214 | U32 |
816 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
1215 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
817 | CODE: |
1216 | CODE: |
818 | { |
|
|
819 | RETVAL = THIS->rstyle; |
1217 | RETVAL = THIS->rstyle; |
820 | THIS->rstyle = new_rstyle; |
1218 | THIS->rstyle = new_rstyle; |
821 | } |
|
|
822 | OUTPUT: |
1219 | OUTPUT: |
823 | RETVAL |
1220 | RETVAL |
824 | |
1221 | |
825 | int |
1222 | int |
826 | rxvt_term::view_start (int newval = -1) |
1223 | rxvt_term::view_start (int newval = 1) |
|
|
1224 | PROTOTYPE: $;$ |
827 | CODE: |
1225 | CODE: |
828 | { |
1226 | { |
829 | RETVAL = THIS->view_start; |
1227 | RETVAL = THIS->view_start; |
830 | |
1228 | |
831 | if (newval >= 0) |
1229 | if (newval <= 0) |
832 | { |
1230 | THIS->scr_changeview (max (newval, THIS->top_row)); |
833 | THIS->view_start = min (newval, THIS->nsaved); |
|
|
834 | THIS->scr_changeview (RETVAL); |
|
|
835 | } |
|
|
836 | } |
1231 | } |
837 | OUTPUT: |
1232 | OUTPUT: |
838 | RETVAL |
1233 | RETVAL |
839 | |
1234 | |
840 | void |
1235 | void |
… | |
… | |
844 | |
1239 | |
845 | void |
1240 | void |
846 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1241 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
847 | PPCODE: |
1242 | PPCODE: |
848 | { |
1243 | { |
849 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1244 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
850 | XSRETURN_EMPTY; |
1245 | XSRETURN_EMPTY; |
851 | |
1246 | |
852 | line_t &l = ROW(row_number); |
1247 | line_t &l = ROW(row_number); |
853 | |
1248 | |
854 | if (GIMME_V != G_VOID) |
1249 | if (GIMME_V != G_VOID) |
855 | { |
1250 | { |
856 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1251 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
857 | |
1252 | |
858 | for (int col = 0; col <THIS->ncol; col++) |
1253 | for (int col = 0; col < THIS->ncol; col++) |
859 | wstr [col] = l.t [col]; |
1254 | wstr [col] = l.t [col]; |
860 | |
1255 | |
861 | XPUSHs (sv_2mortal (wcs2sv (wstr))); |
1256 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
862 | |
1257 | |
863 | delete [] wstr; |
1258 | delete [] wstr; |
864 | } |
1259 | } |
865 | |
1260 | |
866 | if (new_text) |
1261 | if (new_text) |
… | |
… | |
887 | |
1282 | |
888 | void |
1283 | void |
889 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
1284 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
890 | PPCODE: |
1285 | PPCODE: |
891 | { |
1286 | { |
892 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1287 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
893 | XSRETURN_EMPTY; |
1288 | XSRETURN_EMPTY; |
894 | |
1289 | |
895 | line_t &l = ROW(row_number); |
1290 | line_t &l = ROW(row_number); |
896 | |
1291 | |
897 | if (GIMME_V != G_VOID) |
1292 | if (GIMME_V != G_VOID) |
… | |
… | |
927 | |
1322 | |
928 | int |
1323 | int |
929 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
1324 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
930 | CODE: |
1325 | CODE: |
931 | { |
1326 | { |
932 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1327 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
933 | XSRETURN_EMPTY; |
1328 | XSRETURN_EMPTY; |
934 | |
1329 | |
935 | line_t &l = ROW(row_number); |
1330 | line_t &l = ROW(row_number); |
936 | RETVAL = l.l; |
1331 | RETVAL = l.l; |
937 | |
1332 | |
… | |
… | |
943 | |
1338 | |
944 | bool |
1339 | bool |
945 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
1340 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
946 | CODE: |
1341 | CODE: |
947 | { |
1342 | { |
948 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1343 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
949 | XSRETURN_EMPTY; |
1344 | XSRETURN_EMPTY; |
950 | |
1345 | |
951 | line_t &l = ROW(row_number); |
1346 | line_t &l = ROW(row_number); |
952 | RETVAL = l.is_longer (); |
1347 | RETVAL = l.is_longer (); |
953 | |
1348 | |
… | |
… | |
956 | } |
1351 | } |
957 | OUTPUT: |
1352 | OUTPUT: |
958 | RETVAL |
1353 | RETVAL |
959 | |
1354 | |
960 | SV * |
1355 | SV * |
961 | rxvt_term::special_encode (SV *str) |
1356 | rxvt_term::special_encode (SV *string) |
962 | CODE: |
1357 | CODE: |
963 | abort ();//TODO |
1358 | { |
|
|
1359 | wchar_t *wstr = sv2wcs (string); |
|
|
1360 | int wlen = wcslen (wstr); |
|
|
1361 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1362 | |
|
|
1363 | rxvt_push_locale (THIS->locale); |
|
|
1364 | |
|
|
1365 | wchar_t *r = rstr; |
|
|
1366 | for (wchar_t *s = wstr; *s; s++) |
|
|
1367 | if (wcwidth (*s) == 0) |
|
|
1368 | { |
|
|
1369 | if (r == rstr) |
|
|
1370 | croak ("leading combining character unencodable"); |
|
|
1371 | |
|
|
1372 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1373 | if (n == NOCHAR) |
|
|
1374 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1375 | |
|
|
1376 | r[-1] = n; |
|
|
1377 | } |
|
|
1378 | #if !UNICODE_3 |
|
|
1379 | else if (*s >= 0x10000) |
|
|
1380 | *r++ = rxvt_composite.compose (*s); |
|
|
1381 | #endif |
|
|
1382 | else |
|
|
1383 | *r++ = *s; |
|
|
1384 | |
|
|
1385 | rxvt_pop_locale (); |
|
|
1386 | |
|
|
1387 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1388 | |
|
|
1389 | delete [] rstr; |
|
|
1390 | } |
|
|
1391 | OUTPUT: |
|
|
1392 | RETVAL |
964 | |
1393 | |
965 | SV * |
1394 | SV * |
966 | rxvt_term::special_decode (SV *str) |
1395 | rxvt_term::special_decode (SV *text) |
967 | CODE: |
1396 | CODE: |
968 | abort ();//TODO |
1397 | { |
|
|
1398 | wchar_t *wstr = sv2wcs (text); |
|
|
1399 | int wlen = wcslen (wstr); |
|
|
1400 | int dlen = 0; |
|
|
1401 | |
|
|
1402 | // find length |
|
|
1403 | for (wchar_t *s = wstr; *s; s++) |
|
|
1404 | if (*s == NOCHAR) |
|
|
1405 | ; |
|
|
1406 | else if (IS_COMPOSE (*s)) |
|
|
1407 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1408 | else |
|
|
1409 | dlen++; |
|
|
1410 | |
|
|
1411 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1412 | |
|
|
1413 | // decode |
|
|
1414 | wchar_t *r = rstr; |
|
|
1415 | for (wchar_t *s = wstr; *s; s++) |
|
|
1416 | if (*s == NOCHAR) |
|
|
1417 | ; |
|
|
1418 | else if (IS_COMPOSE (*s)) |
|
|
1419 | r += rxvt_composite.expand (*s, r); |
|
|
1420 | else |
|
|
1421 | *r++ = *s; |
|
|
1422 | |
|
|
1423 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1424 | |
|
|
1425 | delete [] rstr; |
|
|
1426 | } |
|
|
1427 | OUTPUT: |
|
|
1428 | RETVAL |
969 | |
1429 | |
970 | void |
1430 | void |
971 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1431 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
972 | PPCODE: |
1432 | PPCODE: |
973 | { |
1433 | { |
… | |
… | |
1005 | else |
1465 | else |
1006 | THIS->rs [index] = 0; |
1466 | THIS->rs [index] = 0; |
1007 | } |
1467 | } |
1008 | } |
1468 | } |
1009 | |
1469 | |
|
|
1470 | const char * |
|
|
1471 | rxvt_term::x_resource (const char *name) |
|
|
1472 | |
|
|
1473 | bool |
|
|
1474 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1475 | CODE: |
|
|
1476 | { |
|
|
1477 | RETVAL = THIS->options & optval; |
|
|
1478 | |
|
|
1479 | if (set >= 0) |
|
|
1480 | { |
|
|
1481 | if (set) |
|
|
1482 | THIS->options |= optval; |
|
|
1483 | else |
|
|
1484 | THIS->options &= ~optval; |
|
|
1485 | |
|
|
1486 | switch (optval) |
|
|
1487 | { |
|
|
1488 | case Opt_skipBuiltinGlyphs: |
|
|
1489 | THIS->set_fonts (); |
|
|
1490 | THIS->scr_remap_chars (); |
|
|
1491 | THIS->scr_touch (true); |
|
|
1492 | THIS->want_refresh = 1; |
|
|
1493 | break; |
|
|
1494 | |
|
|
1495 | case Opt_cursorUnderline: |
|
|
1496 | THIS->want_refresh = 1; |
|
|
1497 | break; |
|
|
1498 | |
|
|
1499 | # case Opt_scrollBar_floating: |
|
|
1500 | # case Opt_scrollBar_right: |
|
|
1501 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1502 | # break; |
|
|
1503 | } |
|
|
1504 | } |
|
|
1505 | } |
|
|
1506 | OUTPUT: |
|
|
1507 | RETVAL |
|
|
1508 | |
|
|
1509 | bool |
|
|
1510 | rxvt_term::parse_keysym (char *keysym, char *str) |
|
|
1511 | CODE: |
|
|
1512 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
|
|
1513 | THIS->keyboard->register_done (); |
|
|
1514 | OUTPUT: |
|
|
1515 | RETVAL |
|
|
1516 | |
1010 | void |
1517 | void |
1011 | rxvt_term::cur (...) |
1518 | rxvt_term::screen_cur (...) |
1012 | PROTOTYPE: $;$$ |
1519 | PROTOTYPE: $;$$ |
1013 | ALIAS: |
1520 | ALIAS: |
1014 | screen_cur = 0 |
1521 | screen_cur = 0 |
1015 | selection_beg = 1 |
1522 | selection_beg = 1 |
1016 | selection_end = 2 |
1523 | selection_end = 2 |
… | |
… | |
1029 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1536 | PUSHs (sv_2mortal (newSViv (rc.col))); |
1030 | } |
1537 | } |
1031 | |
1538 | |
1032 | if (items == 3) |
1539 | if (items == 3) |
1033 | { |
1540 | { |
1034 | rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
1541 | rc.row = SvIV (ST (1)); |
1035 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
1542 | rc.col = SvIV (ST (2)); |
|
|
1543 | |
|
|
1544 | if (ix == 2 && rc.col == 0) |
|
|
1545 | { |
|
|
1546 | rc.row--; |
|
|
1547 | rc.col = THIS->ncol; |
|
|
1548 | } |
|
|
1549 | |
|
|
1550 | clamp_it (rc.col, 0, THIS->ncol); |
|
|
1551 | clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); |
1036 | |
1552 | |
1037 | if (ix) |
1553 | if (ix) |
1038 | THIS->want_refresh = 1; |
1554 | THIS->want_refresh = 1; |
1039 | } |
1555 | } |
1040 | } |
1556 | } |
1041 | |
1557 | |
|
|
1558 | char |
|
|
1559 | rxvt_term::cur_charset () |
|
|
1560 | CODE: |
|
|
1561 | RETVAL = THIS->charsets [THIS->screen.charset]; |
|
|
1562 | OUTPUT: |
|
|
1563 | RETVAL |
|
|
1564 | |
|
|
1565 | #void |
|
|
1566 | #rxvt_term::selection_clear () |
|
|
1567 | |
|
|
1568 | void |
|
|
1569 | rxvt_term::selection_make (U32 eventtime, bool rect = false) |
|
|
1570 | CODE: |
|
|
1571 | THIS->selection.op = SELECTION_CONT; |
|
|
1572 | THIS->selection.rect = rect; |
|
|
1573 | THIS->selection_make (eventtime); |
|
|
1574 | |
1042 | int |
1575 | int |
1043 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1576 | rxvt_term::selection_grab (U32 eventtime) |
1044 | |
1577 | |
1045 | void |
1578 | void |
1046 | rxvt_term::selection (SV *newtext = 0) |
1579 | rxvt_term::selection (SV *newtext = 0) |
1047 | PPCODE: |
1580 | PPCODE: |
1048 | { |
1581 | { |
1049 | if (GIMME_V != G_VOID) |
1582 | if (GIMME_V != G_VOID) |
|
|
1583 | XPUSHs (THIS->selection.text |
1050 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1584 | ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)) |
|
|
1585 | : &PL_sv_undef); |
1051 | |
1586 | |
1052 | if (newtext) |
1587 | if (newtext) |
1053 | { |
1588 | { |
1054 | free (THIS->selection.text); |
1589 | free (THIS->selection.text); |
1055 | |
1590 | |
… | |
… | |
1057 | THIS->selection.len = wcslen (THIS->selection.text); |
1592 | THIS->selection.len = wcslen (THIS->selection.text); |
1058 | } |
1593 | } |
1059 | } |
1594 | } |
1060 | |
1595 | |
1061 | void |
1596 | void |
|
|
1597 | rxvt_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) |
|
|
1598 | |
|
|
1599 | void |
|
|
1600 | rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) |
|
|
1601 | |
|
|
1602 | void |
|
|
1603 | rxvt_term::scr_bell () |
|
|
1604 | |
|
|
1605 | void |
1062 | rxvt_term::scr_add_lines (SV *string) |
1606 | rxvt_term::scr_add_lines (SV *string) |
1063 | CODE: |
1607 | CODE: |
1064 | { |
1608 | { |
1065 | wchar_t *wstr = sv2wcs (string); |
1609 | wchar_t *wstr = sv2wcs (string); |
1066 | int wlen = wcslen (wstr); |
|
|
1067 | unicode_t *ustr = new unicode_t [wlen]; |
|
|
1068 | int nlines = 0; |
|
|
1069 | |
|
|
1070 | for (int i = wlen; i--; ) |
|
|
1071 | { |
|
|
1072 | ustr [i] = wstr [i]; |
|
|
1073 | nlines += ustr [i] == '\012'; |
|
|
1074 | } |
|
|
1075 | |
|
|
1076 | THIS->scr_add_lines (ustr, nlines, wlen); |
1610 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
1077 | |
|
|
1078 | free (wstr); |
1611 | free (wstr); |
1079 | delete [] ustr; |
|
|
1080 | } |
1612 | } |
1081 | |
1613 | |
1082 | void |
1614 | void |
1083 | rxvt_term::tt_write (SV *octets) |
1615 | rxvt_term::tt_write (SV *octets) |
1084 | INIT: |
1616 | INIT: |
… | |
… | |
1098 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1630 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1099 | |
1631 | |
1100 | THIS->cmdbuf_ptr = str; |
1632 | THIS->cmdbuf_ptr = str; |
1101 | THIS->cmdbuf_endp = str + len; |
1633 | THIS->cmdbuf_endp = str + len; |
1102 | |
1634 | |
|
|
1635 | rxvt_push_locale (THIS->locale); |
1103 | THIS->cmd_parse (); |
1636 | THIS->cmd_parse (); |
|
|
1637 | rxvt_pop_locale (); |
1104 | |
1638 | |
1105 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1639 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1106 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1640 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
1107 | } |
1641 | } |
1108 | |
1642 | |
… | |
… | |
1181 | RETVAL = THIS; |
1715 | RETVAL = THIS; |
1182 | OUTPUT: |
1716 | OUTPUT: |
1183 | RETVAL |
1717 | RETVAL |
1184 | |
1718 | |
1185 | timer * |
1719 | timer * |
|
|
1720 | timer::after (NV delay) |
|
|
1721 | CODE: |
|
|
1722 | THIS->start (NOW + delay); |
|
|
1723 | OUTPUT: |
|
|
1724 | RETVAL |
|
|
1725 | |
|
|
1726 | timer * |
1186 | timer::stop () |
1727 | timer::stop () |
1187 | CODE: |
1728 | CODE: |
1188 | THIS->stop (); |
1729 | THIS->stop (); |
1189 | RETVAL = THIS; |
1730 | RETVAL = THIS; |
1190 | OUTPUT: |
1731 | OUTPUT: |