1 | /*----------------------------------------------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: rxvtperl.xs |
2 | * File: rxvtperl.xs |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2008,2011 Marc Lehmann <schmorp@schmorp.de> |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
… | |
… | |
23 | #define line_t perl_line_t |
23 | #define line_t perl_line_t |
24 | #include <EXTERN.h> |
24 | #include <EXTERN.h> |
25 | #include <perl.h> |
25 | #include <perl.h> |
26 | #include <XSUB.h> |
26 | #include <XSUB.h> |
27 | #undef line_t |
27 | #undef line_t |
|
|
28 | #undef bool // perl defines it's own bool type, except with g++... what a trap |
28 | |
29 | |
29 | #include "../config.h" |
30 | #include "../config.h" |
30 | |
31 | |
31 | #include <cstddef> |
32 | #include <cstddef> |
32 | #include <cstdarg> |
33 | #include <cstdarg> |
… | |
… | |
302 | THIS->refresh_check (); |
303 | THIS->refresh_check (); |
303 | } |
304 | } |
304 | |
305 | |
305 | ///////////////////////////////////////////////////////////////////////////// |
306 | ///////////////////////////////////////////////////////////////////////////// |
306 | |
307 | |
307 | #define IOM_CLASS "urxvt" |
|
|
308 | #define IOM_WARN rxvt_warn |
|
|
309 | #include "iom_perl.h" |
308 | #include "iom_perl.h" |
310 | |
309 | |
311 | ///////////////////////////////////////////////////////////////////////////// |
310 | ///////////////////////////////////////////////////////////////////////////// |
312 | |
311 | |
313 | struct rxvt_perl_interp rxvt_perl; |
312 | struct rxvt_perl_interp rxvt_perl; |
… | |
… | |
343 | " unshift @INC, '" LIBDIR "';" |
342 | " unshift @INC, '" LIBDIR "';" |
344 | "}" |
343 | "}" |
345 | "" |
344 | "" |
346 | "use urxvt;" |
345 | "use urxvt;" |
347 | }; |
346 | }; |
348 | int argc = sizeof (args) / sizeof (args[0]); |
347 | int argc = ecb_array_length (args); |
349 | char **argv = args; |
348 | char **argv = args; |
350 | |
349 | |
351 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
350 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
352 | perl = perl_alloc (); |
351 | perl = perl_alloc (); |
353 | perl_construct (perl); |
352 | perl_construct (perl); |
… | |
… | |
369 | if (perl) |
368 | if (perl) |
370 | { |
369 | { |
371 | // runs outside of perls ENV |
370 | // runs outside of perls ENV |
372 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
371 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
373 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0); |
372 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0); |
|
|
373 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, newRV_noinc ((SV *)newAV ()), 0); |
374 | } |
374 | } |
375 | } |
375 | } |
376 | |
376 | |
377 | static void |
377 | static void |
378 | ungrab (rxvt_term *THIS) |
378 | ungrab (rxvt_term *THIS) |
… | |
… | |
399 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
399 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
400 | |
400 | |
401 | for (int i = 0; i <= AvFILL (av); i++) |
401 | for (int i = 0; i <= AvFILL (av); i++) |
402 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
402 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
403 | } |
403 | } |
|
|
404 | else if (htype == HOOK_DESTROY) |
|
|
405 | { |
|
|
406 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0)); |
|
|
407 | |
|
|
408 | for (int i = AvFILL (av); i >= 0; i--) |
|
|
409 | { |
|
|
410 | rxvt_selection *req = (rxvt_selection *)SvIV (*av_fetch (av, i, 0)); |
|
|
411 | delete req; |
|
|
412 | } |
|
|
413 | } |
404 | |
414 | |
405 | bool event_consumed; |
415 | bool event_consumed; |
406 | |
416 | |
407 | if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always |
417 | if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always |
408 | || term->perl.should_invoke [htype]) |
418 | || term->perl.should_invoke [htype]) |
… | |
… | |
415 | ENTER; |
425 | ENTER; |
416 | SAVETMPS; |
426 | SAVETMPS; |
417 | |
427 | |
418 | PUSHMARK (SP); |
428 | PUSHMARK (SP); |
419 | |
429 | |
|
|
430 | EXTEND (SP, 2); |
420 | XPUSHs (sv_2mortal (newSVterm (term))); |
431 | PUSHs (sv_2mortal (newSVterm (term))); |
421 | XPUSHs (sv_2mortal (newSViv (htype))); |
432 | PUSHs (sv_2mortal (newSViv (htype))); |
422 | |
433 | |
423 | for (;;) { |
434 | for (;;) { |
424 | data_type dt = (data_type)va_arg (ap, int); |
435 | data_type dt = (data_type)va_arg (ap, int); |
425 | |
436 | |
426 | switch (dt) |
437 | switch (dt) |
… | |
… | |
583 | FREETMPS; |
594 | FREETMPS; |
584 | LEAVE; |
595 | LEAVE; |
585 | |
596 | |
586 | if (SvTRUE (ERRSV)) |
597 | if (SvTRUE (ERRSV)) |
587 | { |
598 | { |
588 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
599 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPVbyte_nolen (ERRSV)); |
589 | ungrab (term); // better lose the grab than the session |
600 | ungrab (term); // better lose the grab than the session |
590 | } |
601 | } |
591 | |
602 | |
592 | event_consumed = !!count; |
603 | event_consumed = !!count; |
593 | } |
604 | } |
… | |
… | |
610 | // don't allow further calls |
621 | // don't allow further calls |
611 | term->perl.self = 0; |
622 | term->perl.self = 0; |
612 | } |
623 | } |
613 | |
624 | |
614 | return event_consumed; |
625 | return event_consumed; |
|
|
626 | } |
|
|
627 | |
|
|
628 | void |
|
|
629 | rxvt_perl_interp::selection_finish (rxvt_selection *sel, char *data, unsigned int len) |
|
|
630 | { |
|
|
631 | localise_env set_environ (perl_environ); |
|
|
632 | |
|
|
633 | ENTER; |
|
|
634 | SAVETMPS; |
|
|
635 | |
|
|
636 | dSP; |
|
|
637 | XPUSHs (sv_2mortal (newSVpvn (data, len))); |
|
|
638 | call_sv ((SV *)sel->cb_sv, G_VOID | G_DISCARD | G_EVAL); |
|
|
639 | |
|
|
640 | if (SvTRUE (ERRSV)) |
|
|
641 | rxvt_warn ("perl selection callback evaluation error: %s", SvPVbyte_nolen (ERRSV)); |
|
|
642 | |
|
|
643 | FREETMPS; |
|
|
644 | LEAVE; |
615 | } |
645 | } |
616 | |
646 | |
617 | ///////////////////////////////////////////////////////////////////////////// |
647 | ///////////////////////////////////////////////////////////////////////////// |
618 | |
648 | |
619 | MODULE = urxvt PACKAGE = urxvt |
649 | MODULE = urxvt PACKAGE = urxvt |
… | |
… | |
770 | const_iv (XIMDontChange), |
800 | const_iv (XIMDontChange), |
771 | # endif |
801 | # endif |
772 | # endif |
802 | # endif |
773 | }; |
803 | }; |
774 | |
804 | |
775 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
805 | for (civ = const_iv + ecb_array_length (const_iv); civ > const_iv; civ--) |
776 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
806 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
777 | } |
807 | } |
778 | |
808 | |
779 | void |
809 | void |
780 | warn (const char *msg) |
810 | warn (const char *msg) |
781 | CODE: |
811 | CODE: |
… | |
… | |
853 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
883 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
854 | if ((*t)->perl.self) |
884 | if ((*t)->perl.self) |
855 | PUSHs (sv_2mortal (newSVterm (*t))); |
885 | PUSHs (sv_2mortal (newSVterm (*t))); |
856 | } |
886 | } |
857 | |
887 | |
|
|
888 | IV |
|
|
889 | _new_selection_request (rxvt_term *term, int selnum, Time tm, Window win, Atom prop, SV *cb) |
|
|
890 | CODE: |
|
|
891 | rxvt_selection *req = new rxvt_selection (term->display, selnum, tm, win, prop, term); |
|
|
892 | req->cb_sv = newSVsv (cb); |
|
|
893 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0)); |
|
|
894 | av_push (av, newSViv ((IV)req)); |
|
|
895 | RETVAL = (IV)req; |
|
|
896 | OUTPUT: |
|
|
897 | RETVAL |
|
|
898 | |
|
|
899 | void |
|
|
900 | _delete_selection_request (IV req_) |
|
|
901 | CODE: |
|
|
902 | rxvt_selection *req = (rxvt_selection *)req_; |
|
|
903 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)req->term->perl.self), "_selection", 10, 0)); |
|
|
904 | int i; |
|
|
905 | |
|
|
906 | for (i = AvFILL (av); i >= 0; i--) |
|
|
907 | if (SvIV (*av_fetch (av, i, 1)) == req_) |
|
|
908 | break; |
|
|
909 | |
|
|
910 | for (; i < AvFILL (av); i++) |
|
|
911 | av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0))); |
|
|
912 | |
|
|
913 | av_pop (av); |
|
|
914 | |
|
|
915 | delete req; |
|
|
916 | |
858 | MODULE = urxvt PACKAGE = urxvt::term |
917 | MODULE = urxvt PACKAGE = urxvt::term |
859 | |
918 | |
860 | SV * |
919 | SV * |
861 | _new (AV *env, AV *arg) |
920 | _new (AV *env, AV *arg) |
862 | CODE: |
921 | CODE: |
863 | { |
922 | { |
864 | rxvt_term *term = new rxvt_term; |
923 | rxvt_term *term = new rxvt_term; |
865 | |
924 | |
866 | stringvec *argv = new stringvec; |
925 | stringvec *argv = new stringvec; |
867 | stringvec *envv = new stringvec; |
|
|
868 | |
|
|
869 | for (int i = 0; i <= AvFILL (arg); i++) |
926 | for (int i = 0; i <= AvFILL (arg); i++) |
870 | argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1)))); |
927 | argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1)))); |
871 | |
928 | |
|
|
929 | stringvec *envv = new stringvec; |
872 | for (int i = AvFILL (env) + 1; i--; ) |
930 | for (int i = AvFILL (env) + 1; i--; ) |
873 | envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); |
931 | envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); |
874 | |
|
|
875 | envv->push_back (0); |
|
|
876 | |
932 | |
877 | try |
933 | try |
878 | { |
934 | { |
879 | term->init (argv, envv); |
935 | term->init (argv, envv); |
880 | } |
936 | } |
… | |
… | |
920 | |
976 | |
921 | void |
977 | void |
922 | rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt) |
978 | rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt) |
923 | CODE: |
979 | CODE: |
924 | XUngrabKey (THIS->dpy, keycode, modifiers, window); |
980 | XUngrabKey (THIS->dpy, keycode, modifiers, window); |
925 | |
|
|
926 | void |
|
|
927 | rxvt_term::XUngrabKeyboard (Time eventtime) |
|
|
928 | CODE: |
|
|
929 | XUngrabKeyboard (THIS->dpy, eventtime); |
|
|
930 | |
981 | |
931 | bool |
982 | bool |
932 | rxvt_term::grab (Time eventtime, int sync = 0) |
983 | rxvt_term::grab (Time eventtime, int sync = 0) |
933 | CODE: |
984 | CODE: |
934 | { |
985 | { |
… | |
… | |
1046 | rxvt_pop_locale (); |
1097 | rxvt_pop_locale (); |
1047 | |
1098 | |
1048 | RETVAL = wcs2sv (wstr); |
1099 | RETVAL = wcs2sv (wstr); |
1049 | free (wstr); |
1100 | free (wstr); |
1050 | } |
1101 | } |
1051 | OUTPUT: |
|
|
1052 | RETVAL |
|
|
1053 | |
|
|
1054 | char * |
|
|
1055 | rxvt_term::locale () |
|
|
1056 | CODE: |
|
|
1057 | RETVAL = THIS->locale; |
|
|
1058 | OUTPUT: |
1102 | OUTPUT: |
1059 | RETVAL |
1103 | RETVAL |
1060 | |
1104 | |
1061 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
1105 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
1062 | |
1106 | |
… | |
… | |
1169 | RETVAL |
1213 | RETVAL |
1170 | |
1214 | |
1171 | Window |
1215 | Window |
1172 | rxvt_term::parent () |
1216 | rxvt_term::parent () |
1173 | CODE: |
1217 | CODE: |
1174 | RETVAL = THIS->parent [0]; |
1218 | RETVAL = THIS->parent; |
1175 | OUTPUT: |
1219 | OUTPUT: |
1176 | RETVAL |
1220 | RETVAL |
1177 | |
1221 | |
1178 | Window |
1222 | Window |
1179 | rxvt_term::vt () |
1223 | rxvt_term::vt () |
… | |
… | |
1206 | if (newval <= 0) |
1250 | if (newval <= 0) |
1207 | THIS->scr_changeview (max (newval, THIS->top_row)); |
1251 | THIS->scr_changeview (max (newval, THIS->top_row)); |
1208 | } |
1252 | } |
1209 | OUTPUT: |
1253 | OUTPUT: |
1210 | RETVAL |
1254 | RETVAL |
|
|
1255 | |
|
|
1256 | void |
|
|
1257 | rxvt_term::set_urgency (bool enable) |
1211 | |
1258 | |
1212 | void |
1259 | void |
1213 | rxvt_term::focus_in () |
1260 | rxvt_term::focus_in () |
1214 | |
1261 | |
1215 | void |
1262 | void |
… | |
… | |
1448 | # include "rsinc.h" |
1495 | # include "rsinc.h" |
1449 | # undef def |
1496 | # undef def |
1450 | # undef reserve |
1497 | # undef reserve |
1451 | }; |
1498 | }; |
1452 | |
1499 | |
1453 | rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1500 | rs = rslist + ecb_array_length (rslist); |
1454 | |
1501 | |
1455 | if (*name) |
1502 | if (*name) |
1456 | { |
1503 | { |
1457 | do { |
1504 | do { |
1458 | if (rs-- == rslist) |
1505 | if (rs-- == rslist) |
… | |
… | |
1497 | |
1544 | |
1498 | if (set >= 0) |
1545 | if (set >= 0) |
1499 | { |
1546 | { |
1500 | THIS->set_option (optval, set); |
1547 | THIS->set_option (optval, set); |
1501 | |
1548 | |
1502 | if (THIS->env_colorfgbg [0]) // avoid doing this before START |
1549 | if (THIS->init_done) // avoid doing this before START |
1503 | switch (optval) |
1550 | switch (optval) |
1504 | { |
1551 | { |
1505 | case Opt_skipBuiltinGlyphs: |
1552 | case Opt_skipBuiltinGlyphs: |
1506 | THIS->set_fonts (); |
1553 | THIS->set_fonts (); |
1507 | THIS->scr_remap_chars (); |
1554 | THIS->scr_remap_chars (); |
… | |
… | |
1530 | CODE: |
1577 | CODE: |
1531 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
1578 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
1532 | THIS->keyboard->register_done (); |
1579 | THIS->keyboard->register_done (); |
1533 | OUTPUT: |
1580 | OUTPUT: |
1534 | RETVAL |
1581 | RETVAL |
|
|
1582 | |
|
|
1583 | void |
|
|
1584 | rxvt_term::register_command (int keysym, unsigned int state, SV *str) |
|
|
1585 | CODE: |
|
|
1586 | wchar_t *wstr = sv2wcs (str); |
|
|
1587 | THIS->keyboard->register_user_translation (keysym, state, wstr); |
|
|
1588 | free (wstr); |
1535 | |
1589 | |
1536 | void |
1590 | void |
1537 | rxvt_term::screen_cur (...) |
1591 | rxvt_term::screen_cur (...) |
1538 | PROTOTYPE: $;$$ |
1592 | PROTOTYPE: $;$$ |
1539 | ALIAS: |
1593 | ALIAS: |