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. |
… | |
… | |
302 | THIS->refresh_check (); |
302 | THIS->refresh_check (); |
303 | } |
303 | } |
304 | |
304 | |
305 | ///////////////////////////////////////////////////////////////////////////// |
305 | ///////////////////////////////////////////////////////////////////////////// |
306 | |
306 | |
307 | #define IOM_CLASS "urxvt" |
|
|
308 | #define IOM_WARN rxvt_warn |
|
|
309 | #include "iom_perl.h" |
307 | #include "iom_perl.h" |
310 | |
308 | |
311 | ///////////////////////////////////////////////////////////////////////////// |
309 | ///////////////////////////////////////////////////////////////////////////// |
312 | |
310 | |
313 | struct rxvt_perl_interp rxvt_perl; |
311 | struct rxvt_perl_interp rxvt_perl; |
… | |
… | |
343 | " unshift @INC, '" LIBDIR "';" |
341 | " unshift @INC, '" LIBDIR "';" |
344 | "}" |
342 | "}" |
345 | "" |
343 | "" |
346 | "use urxvt;" |
344 | "use urxvt;" |
347 | }; |
345 | }; |
348 | int argc = ARRAY_LENGTH(args); |
346 | int argc = ecb_array_length (args); |
349 | char **argv = args; |
347 | char **argv = args; |
350 | |
348 | |
351 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
349 | PERL_SYS_INIT3 (&argc, &argv, &environ); |
352 | perl = perl_alloc (); |
350 | perl = perl_alloc (); |
353 | perl_construct (perl); |
351 | perl_construct (perl); |
… | |
… | |
369 | if (perl) |
367 | if (perl) |
370 | { |
368 | { |
371 | // runs outside of perls ENV |
369 | // runs outside of perls ENV |
372 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
370 | 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); |
371 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0); |
|
|
372 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, newRV_noinc ((SV *)newAV ()), 0); |
374 | } |
373 | } |
375 | } |
374 | } |
376 | |
375 | |
377 | static void |
376 | static void |
378 | ungrab (rxvt_term *THIS) |
377 | ungrab (rxvt_term *THIS) |
… | |
… | |
399 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
398 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
400 | |
399 | |
401 | for (int i = 0; i <= AvFILL (av); i++) |
400 | for (int i = 0; i <= AvFILL (av); i++) |
402 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
401 | ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); |
403 | } |
402 | } |
|
|
403 | else if (htype == HOOK_DESTROY) |
|
|
404 | { |
|
|
405 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0)); |
|
|
406 | |
|
|
407 | for (int i = AvFILL (av); i >= 0; i--) |
|
|
408 | { |
|
|
409 | rxvt_selection *req = (rxvt_selection *)SvIV (*av_fetch (av, i, 0)); |
|
|
410 | delete req; |
|
|
411 | } |
|
|
412 | } |
404 | |
413 | |
405 | bool event_consumed; |
414 | bool event_consumed; |
406 | |
415 | |
407 | if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always |
416 | if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always |
408 | || term->perl.should_invoke [htype]) |
417 | || term->perl.should_invoke [htype]) |
… | |
… | |
415 | ENTER; |
424 | ENTER; |
416 | SAVETMPS; |
425 | SAVETMPS; |
417 | |
426 | |
418 | PUSHMARK (SP); |
427 | PUSHMARK (SP); |
419 | |
428 | |
|
|
429 | EXTEND (SP, 2); |
420 | XPUSHs (sv_2mortal (newSVterm (term))); |
430 | PUSHs (sv_2mortal (newSVterm (term))); |
421 | XPUSHs (sv_2mortal (newSViv (htype))); |
431 | PUSHs (sv_2mortal (newSViv (htype))); |
422 | |
432 | |
423 | for (;;) { |
433 | for (;;) { |
424 | data_type dt = (data_type)va_arg (ap, int); |
434 | data_type dt = (data_type)va_arg (ap, int); |
425 | |
435 | |
426 | switch (dt) |
436 | switch (dt) |
… | |
… | |
583 | FREETMPS; |
593 | FREETMPS; |
584 | LEAVE; |
594 | LEAVE; |
585 | |
595 | |
586 | if (SvTRUE (ERRSV)) |
596 | if (SvTRUE (ERRSV)) |
587 | { |
597 | { |
588 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
598 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPVbyte_nolen (ERRSV)); |
589 | ungrab (term); // better lose the grab than the session |
599 | ungrab (term); // better lose the grab than the session |
590 | } |
600 | } |
591 | |
601 | |
592 | event_consumed = !!count; |
602 | event_consumed = !!count; |
593 | } |
603 | } |
… | |
… | |
610 | // don't allow further calls |
620 | // don't allow further calls |
611 | term->perl.self = 0; |
621 | term->perl.self = 0; |
612 | } |
622 | } |
613 | |
623 | |
614 | return event_consumed; |
624 | return event_consumed; |
|
|
625 | } |
|
|
626 | |
|
|
627 | void |
|
|
628 | rxvt_perl_interp::selection_finish (rxvt_selection *sel, char *data, unsigned int len) |
|
|
629 | { |
|
|
630 | localise_env set_environ (perl_environ); |
|
|
631 | |
|
|
632 | ENTER; |
|
|
633 | SAVETMPS; |
|
|
634 | |
|
|
635 | dSP; |
|
|
636 | XPUSHs (sv_2mortal (newSVpvn (data, len))); |
|
|
637 | call_sv ((SV *)sel->cb_sv, G_VOID | G_DISCARD | G_EVAL); |
|
|
638 | |
|
|
639 | if (SvTRUE (ERRSV)) |
|
|
640 | rxvt_warn ("perl selection callback evaluation error: %s", SvPVbyte_nolen (ERRSV)); |
|
|
641 | |
|
|
642 | FREETMPS; |
|
|
643 | LEAVE; |
615 | } |
644 | } |
616 | |
645 | |
617 | ///////////////////////////////////////////////////////////////////////////// |
646 | ///////////////////////////////////////////////////////////////////////////// |
618 | |
647 | |
619 | MODULE = urxvt PACKAGE = urxvt |
648 | MODULE = urxvt PACKAGE = urxvt |
… | |
… | |
770 | const_iv (XIMDontChange), |
799 | const_iv (XIMDontChange), |
771 | # endif |
800 | # endif |
772 | # endif |
801 | # endif |
773 | }; |
802 | }; |
774 | |
803 | |
775 | for (civ = const_iv + ARRAY_LENGTH(const_iv); civ-- > const_iv; ) |
804 | for (civ = const_iv + ecb_array_length (const_iv); civ > const_iv; civ--) |
776 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
805 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
777 | } |
806 | } |
778 | |
807 | |
779 | void |
808 | void |
780 | warn (const char *msg) |
809 | warn (const char *msg) |
781 | CODE: |
810 | CODE: |
… | |
… | |
852 | |
881 | |
853 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
882 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
854 | if ((*t)->perl.self) |
883 | if ((*t)->perl.self) |
855 | PUSHs (sv_2mortal (newSVterm (*t))); |
884 | PUSHs (sv_2mortal (newSVterm (*t))); |
856 | } |
885 | } |
|
|
886 | |
|
|
887 | IV |
|
|
888 | _new_selection_request (rxvt_term *term, int selnum, Time tm, Window win, Atom prop, SV *cb) |
|
|
889 | CODE: |
|
|
890 | rxvt_selection *req = new rxvt_selection (term->display, selnum, tm, win, prop, term); |
|
|
891 | req->cb_sv = newSVsv (cb); |
|
|
892 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0)); |
|
|
893 | av_push (av, newSViv ((IV)req)); |
|
|
894 | RETVAL = (IV)req; |
|
|
895 | OUTPUT: |
|
|
896 | RETVAL |
|
|
897 | |
|
|
898 | void |
|
|
899 | _delete_selection_request (IV req_) |
|
|
900 | CODE: |
|
|
901 | rxvt_selection *req = (rxvt_selection *)req_; |
|
|
902 | AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)req->term->perl.self), "_selection", 10, 0)); |
|
|
903 | int i; |
|
|
904 | |
|
|
905 | for (i = AvFILL (av); i >= 0; i--) |
|
|
906 | if (SvIV (*av_fetch (av, i, 1)) == req_) |
|
|
907 | break; |
|
|
908 | |
|
|
909 | for (; i < AvFILL (av); i++) |
|
|
910 | av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0))); |
|
|
911 | |
|
|
912 | av_pop (av); |
|
|
913 | |
|
|
914 | delete req; |
857 | |
915 | |
858 | MODULE = urxvt PACKAGE = urxvt::term |
916 | MODULE = urxvt PACKAGE = urxvt::term |
859 | |
917 | |
860 | SV * |
918 | SV * |
861 | _new (AV *env, AV *arg) |
919 | _new (AV *env, AV *arg) |
… | |
… | |
920 | |
978 | |
921 | void |
979 | void |
922 | rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt) |
980 | rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt) |
923 | CODE: |
981 | CODE: |
924 | XUngrabKey (THIS->dpy, keycode, modifiers, window); |
982 | XUngrabKey (THIS->dpy, keycode, modifiers, window); |
925 | |
|
|
926 | void |
|
|
927 | rxvt_term::XUngrabKeyboard (Time eventtime) |
|
|
928 | CODE: |
|
|
929 | XUngrabKeyboard (THIS->dpy, eventtime); |
|
|
930 | |
983 | |
931 | bool |
984 | bool |
932 | rxvt_term::grab (Time eventtime, int sync = 0) |
985 | rxvt_term::grab (Time eventtime, int sync = 0) |
933 | CODE: |
986 | CODE: |
934 | { |
987 | { |
… | |
… | |
1169 | RETVAL |
1222 | RETVAL |
1170 | |
1223 | |
1171 | Window |
1224 | Window |
1172 | rxvt_term::parent () |
1225 | rxvt_term::parent () |
1173 | CODE: |
1226 | CODE: |
1174 | RETVAL = THIS->parent [0]; |
1227 | RETVAL = THIS->parent; |
1175 | OUTPUT: |
1228 | OUTPUT: |
1176 | RETVAL |
1229 | RETVAL |
1177 | |
1230 | |
1178 | Window |
1231 | Window |
1179 | rxvt_term::vt () |
1232 | rxvt_term::vt () |
… | |
… | |
1206 | if (newval <= 0) |
1259 | if (newval <= 0) |
1207 | THIS->scr_changeview (max (newval, THIS->top_row)); |
1260 | THIS->scr_changeview (max (newval, THIS->top_row)); |
1208 | } |
1261 | } |
1209 | OUTPUT: |
1262 | OUTPUT: |
1210 | RETVAL |
1263 | RETVAL |
|
|
1264 | |
|
|
1265 | void |
|
|
1266 | rxvt_term::set_urgency (bool enable) |
1211 | |
1267 | |
1212 | void |
1268 | void |
1213 | rxvt_term::focus_in () |
1269 | rxvt_term::focus_in () |
1214 | |
1270 | |
1215 | void |
1271 | void |
… | |
… | |
1448 | # include "rsinc.h" |
1504 | # include "rsinc.h" |
1449 | # undef def |
1505 | # undef def |
1450 | # undef reserve |
1506 | # undef reserve |
1451 | }; |
1507 | }; |
1452 | |
1508 | |
1453 | rs = rslist + ARRAY_LENGTH(rslist); |
1509 | rs = rslist + ecb_array_length (rslist); |
1454 | |
1510 | |
1455 | if (*name) |
1511 | if (*name) |
1456 | { |
1512 | { |
1457 | do { |
1513 | do { |
1458 | if (rs-- == rslist) |
1514 | if (rs-- == rslist) |
… | |
… | |
1530 | CODE: |
1586 | CODE: |
1531 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
1587 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
1532 | THIS->keyboard->register_done (); |
1588 | THIS->keyboard->register_done (); |
1533 | OUTPUT: |
1589 | OUTPUT: |
1534 | RETVAL |
1590 | RETVAL |
|
|
1591 | |
|
|
1592 | void |
|
|
1593 | rxvt_term::register_command (int keysym, unsigned int state, SV *str) |
|
|
1594 | CODE: |
|
|
1595 | wchar_t *wstr = sv2wcs (str); |
|
|
1596 | THIS->keyboard->register_user_translation (keysym, state, wstr); |
|
|
1597 | free (wstr); |
1535 | |
1598 | |
1536 | void |
1599 | void |
1537 | rxvt_term::screen_cur (...) |
1600 | rxvt_term::screen_cur (...) |
1538 | PROTOTYPE: $;$$ |
1601 | PROTOTYPE: $;$$ |
1539 | ALIAS: |
1602 | ALIAS: |