ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtperl.xs
(Generate patch)

Comparing rxvt-unicode/src/rxvtperl.xs (file contents):
Revision 1.136 by root, Fri Jan 7 21:17:08 2011 UTC vs.
Revision 1.154 by sf-exg, Wed Apr 11 11:32:21 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines