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.134 by root, Thu Dec 16 23:03:50 2010 UTC vs.
Revision 1.147 by sf-exg, Tue Dec 6 11:29:52 2011 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.
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
313struct rxvt_perl_interp rxvt_perl; 311struct 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 = sizeof (args) / sizeof (args[0]); 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
377static void 376static void
378ungrab (rxvt_term *THIS) 377ungrab (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
627void
628rxvt_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
619MODULE = urxvt PACKAGE = urxvt 648MODULE = 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 + sizeof (const_iv) / sizeof (const_iv [0]); 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
779void 808void
780warn (const char *msg) 809warn (const char *msg)
781 CODE: 810 CODE:
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}
857 886
887IV
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
898void
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;
915
858MODULE = urxvt PACKAGE = urxvt::term 916MODULE = urxvt PACKAGE = urxvt::term
859 917
860SV * 918SV *
861_new (AV *env, AV *arg) 919_new (AV *env, AV *arg)
862 CODE: 920 CODE:
869 for (int i = 0; i <= AvFILL (arg); i++) 927 for (int i = 0; i <= AvFILL (arg); i++)
870 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1)))); 928 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
871 929
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
921void 977void
922rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt) 978rxvt_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
926void
927rxvt_term::XUngrabKeyboard (Time eventtime)
928 CODE:
929 XUngrabKeyboard (THIS->dpy, eventtime);
930 981
931bool 982bool
932rxvt_term::grab (Time eventtime, int sync = 0) 983rxvt_term::grab (Time eventtime, int sync = 0)
933 CODE: 984 CODE:
934{ 985{
1169 RETVAL 1220 RETVAL
1170 1221
1171Window 1222Window
1172rxvt_term::parent () 1223rxvt_term::parent ()
1173 CODE: 1224 CODE:
1174 RETVAL = THIS->parent [0]; 1225 RETVAL = THIS->parent;
1175 OUTPUT: 1226 OUTPUT:
1176 RETVAL 1227 RETVAL
1177 1228
1178Window 1229Window
1179rxvt_term::vt () 1230rxvt_term::vt ()
1206 if (newval <= 0) 1257 if (newval <= 0)
1207 THIS->scr_changeview (max (newval, THIS->top_row)); 1258 THIS->scr_changeview (max (newval, THIS->top_row));
1208} 1259}
1209 OUTPUT: 1260 OUTPUT:
1210 RETVAL 1261 RETVAL
1262
1263void
1264rxvt_term::set_urgency (bool enable)
1211 1265
1212void 1266void
1213rxvt_term::focus_in () 1267rxvt_term::focus_in ()
1214 1268
1215void 1269void
1448# include "rsinc.h" 1502# include "rsinc.h"
1449# undef def 1503# undef def
1450# undef reserve 1504# undef reserve
1451 }; 1505 };
1452 1506
1453 rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1507 rs = rslist + ecb_array_length (rslist);
1454 1508
1455 if (*name) 1509 if (*name)
1456 { 1510 {
1457 do { 1511 do {
1458 if (rs-- == rslist) 1512 if (rs-- == rslist)
1530 CODE: 1584 CODE:
1531 RETVAL = 0 < THIS->parse_keysym (keysym, str); 1585 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1532 THIS->keyboard->register_done (); 1586 THIS->keyboard->register_done ();
1533 OUTPUT: 1587 OUTPUT:
1534 RETVAL 1588 RETVAL
1589
1590void
1591rxvt_term::register_command (int keysym, unsigned int state, SV *str)
1592 CODE:
1593 wchar_t *wstr = sv2wcs (str);
1594 THIS->keyboard->register_user_translation (keysym, state, wstr);
1595 free (wstr);
1535 1596
1536void 1597void
1537rxvt_term::screen_cur (...) 1598rxvt_term::screen_cur (...)
1538 PROTOTYPE: $;$$ 1599 PROTOTYPE: $;$$
1539 ALIAS: 1600 ALIAS:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines