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.135 by sf-exg, Sat Dec 18 18:17:38 2010 UTC vs.
Revision 1.155 by root, Sun Jun 3 10:38:22 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"
45 46
46#undef LINENO 47#undef LINENO
47#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 48#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
48#undef ROW 49#undef ROW
49#define ROW(n) THIS->row_buf [LINENO (n)] 50#define ROW(n) THIS->row_buf [LINENO (n)]
51
52/////////////////////////////////////////////////////////////////////////////
53
54typedef char * octet_string;
55typedef char * utf8_string;
56
57typedef GdkPixbuf * urxvt__pixbuf;
58typedef rxvt_img * urxvt__img;
50 59
51///////////////////////////////////////////////////////////////////////////// 60/////////////////////////////////////////////////////////////////////////////
52 61
53static wchar_t * 62static wchar_t *
54sv2wcs (SV *sv) 63sv2wcs (SV *sv)
302 THIS->refresh_check (); 311 THIS->refresh_check ();
303} 312}
304 313
305///////////////////////////////////////////////////////////////////////////// 314/////////////////////////////////////////////////////////////////////////////
306 315
307#define IOM_CLASS "urxvt"
308#define IOM_WARN rxvt_warn
309#include "iom_perl.h" 316#include "iom_perl.h"
310 317
311///////////////////////////////////////////////////////////////////////////// 318/////////////////////////////////////////////////////////////////////////////
312 319
313struct rxvt_perl_interp rxvt_perl; 320struct rxvt_perl_interp rxvt_perl;
343 " unshift @INC, '" LIBDIR "';" 350 " unshift @INC, '" LIBDIR "';"
344 "}" 351 "}"
345 "" 352 ""
346 "use urxvt;" 353 "use urxvt;"
347 }; 354 };
348 int argc = ARRAY_LENGTH(args); 355 int argc = ecb_array_length (args);
349 char **argv = args; 356 char **argv = args;
350 357
351 PERL_SYS_INIT3 (&argc, &argv, &environ); 358 PERL_SYS_INIT3 (&argc, &argv, &environ);
352 perl = perl_alloc (); 359 perl = perl_alloc ();
353 perl_construct (perl); 360 perl_construct (perl);
369 if (perl) 376 if (perl)
370 { 377 {
371 // runs outside of perls ENV 378 // runs outside of perls ENV
372 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 379 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); 380 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0);
381 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, newRV_noinc ((SV *)newAV ()), 0);
374 } 382 }
375} 383}
376 384
377static void 385static void
378ungrab (rxvt_term *THIS) 386ungrab (rxvt_term *THIS)
399 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 407 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
400 408
401 for (int i = 0; i <= AvFILL (av); i++) 409 for (int i = 0; i <= AvFILL (av); i++)
402 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 410 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
403 } 411 }
412 else if (htype == HOOK_DESTROY)
413 {
414 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
415
416 for (int i = AvFILL (av); i >= 0; i--)
417 {
418 rxvt_selection *req = (rxvt_selection *)SvIV (*av_fetch (av, i, 0));
419 delete req;
420 }
421 }
404 422
405 bool event_consumed; 423 bool event_consumed;
406 424
407 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always 425 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
408 || term->perl.should_invoke [htype]) 426 || term->perl.should_invoke [htype])
415 ENTER; 433 ENTER;
416 SAVETMPS; 434 SAVETMPS;
417 435
418 PUSHMARK (SP); 436 PUSHMARK (SP);
419 437
438 EXTEND (SP, 2);
420 XPUSHs (sv_2mortal (newSVterm (term))); 439 PUSHs (sv_2mortal (newSVterm (term)));
421 XPUSHs (sv_2mortal (newSViv (htype))); 440 PUSHs (sv_2mortal (newSViv (htype)));
422 441
423 for (;;) { 442 for (;;) {
424 data_type dt = (data_type)va_arg (ap, int); 443 data_type dt = (data_type)va_arg (ap, int);
425 444
426 switch (dt) 445 switch (dt)
583 FREETMPS; 602 FREETMPS;
584 LEAVE; 603 LEAVE;
585 604
586 if (SvTRUE (ERRSV)) 605 if (SvTRUE (ERRSV))
587 { 606 {
588 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 607 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPVbyte_nolen (ERRSV));
589 ungrab (term); // better lose the grab than the session 608 ungrab (term); // better lose the grab than the session
590 } 609 }
591 610
592 event_consumed = !!count; 611 event_consumed = !!count;
593 } 612 }
610 // don't allow further calls 629 // don't allow further calls
611 term->perl.self = 0; 630 term->perl.self = 0;
612 } 631 }
613 632
614 return event_consumed; 633 return event_consumed;
634}
635
636void
637rxvt_perl_interp::selection_finish (rxvt_selection *sel, char *data, unsigned int len)
638{
639 localise_env set_environ (perl_environ);
640
641 ENTER;
642 SAVETMPS;
643
644 dSP;
645 XPUSHs (sv_2mortal (newSVpvn (data, len)));
646 call_sv ((SV *)sel->cb_sv, G_VOID | G_DISCARD | G_EVAL);
647
648 if (SvTRUE (ERRSV))
649 rxvt_warn ("perl selection callback evaluation error: %s", SvPVbyte_nolen (ERRSV));
650
651 FREETMPS;
652 LEAVE;
615} 653}
616 654
617///////////////////////////////////////////////////////////////////////////// 655/////////////////////////////////////////////////////////////////////////////
618 656
619MODULE = urxvt PACKAGE = urxvt 657MODULE = urxvt PACKAGE = urxvt
770 const_iv (XIMDontChange), 808 const_iv (XIMDontChange),
771# endif 809# endif
772# endif 810# endif
773 }; 811 };
774 812
775 for (civ = const_iv + ARRAY_LENGTH(const_iv); civ-- > const_iv; ) 813 for (civ = const_iv + ecb_array_length (const_iv); civ > const_iv; civ--)
776 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 814 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
777} 815}
778 816
779void 817void
780warn (const char *msg) 818warn (const char *msg)
781 CODE: 819 CODE:
853 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) 891 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
854 if ((*t)->perl.self) 892 if ((*t)->perl.self)
855 PUSHs (sv_2mortal (newSVterm (*t))); 893 PUSHs (sv_2mortal (newSVterm (*t)));
856} 894}
857 895
896IV
897_new_selection_request (rxvt_term *term, int selnum, Time tm, Window win, Atom prop, SV *cb)
898 CODE:
899 rxvt_selection *req = new rxvt_selection (term->display, selnum, tm, win, prop, term);
900 req->cb_sv = newSVsv (cb);
901 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
902 av_push (av, newSViv ((IV)req));
903 RETVAL = (IV)req;
904 OUTPUT:
905 RETVAL
906
907void
908_delete_selection_request (IV req_)
909 CODE:
910 rxvt_selection *req = (rxvt_selection *)req_;
911 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)req->term->perl.self), "_selection", 10, 0));
912 int i;
913
914 for (i = AvFILL (av); i >= 0; i--)
915 if (SvIV (*av_fetch (av, i, 1)) == req_)
916 break;
917
918 for (; i < AvFILL (av); i++)
919 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0)));
920
921 av_pop (av);
922
923 delete req;
924
858MODULE = urxvt PACKAGE = urxvt::term 925MODULE = urxvt PACKAGE = urxvt::term
859 926
860SV * 927SV *
861_new (AV *env, AV *arg) 928_new (AV *env, AV *arg)
862 CODE: 929 CODE:
863{ 930{
864 rxvt_term *term = new rxvt_term; 931 rxvt_term *term = new rxvt_term;
865 932
866 stringvec *argv = new stringvec; 933 stringvec *argv = new stringvec;
867 stringvec *envv = new stringvec;
868
869 for (int i = 0; i <= AvFILL (arg); i++) 934 for (int i = 0; i <= AvFILL (arg); i++)
870 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1)))); 935 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
871 936
937 stringvec *envv = new stringvec;
872 for (int i = AvFILL (env) + 1; i--; ) 938 for (int i = AvFILL (env) + 1; i--; )
873 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 939 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
874
875 envv->push_back (0);
876 940
877 try 941 try
878 { 942 {
879 term->init (argv, envv); 943 term->init (argv, envv);
880 } 944 }
920 984
921void 985void
922rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt) 986rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt)
923 CODE: 987 CODE:
924 XUngrabKey (THIS->dpy, keycode, modifiers, window); 988 XUngrabKey (THIS->dpy, keycode, modifiers, window);
925
926void
927rxvt_term::XUngrabKeyboard (Time eventtime)
928 CODE:
929 XUngrabKeyboard (THIS->dpy, eventtime);
930 989
931bool 990bool
932rxvt_term::grab (Time eventtime, int sync = 0) 991rxvt_term::grab (Time eventtime, int sync = 0)
933 CODE: 992 CODE:
934{ 993{
1046 rxvt_pop_locale (); 1105 rxvt_pop_locale ();
1047 1106
1048 RETVAL = wcs2sv (wstr); 1107 RETVAL = wcs2sv (wstr);
1049 free (wstr); 1108 free (wstr);
1050} 1109}
1051 OUTPUT:
1052 RETVAL
1053
1054char *
1055rxvt_term::locale ()
1056 CODE:
1057 RETVAL = THIS->locale;
1058 OUTPUT: 1110 OUTPUT:
1059 RETVAL 1111 RETVAL
1060 1112
1061#define TERM_OFFSET(sym) offsetof (TermWin_t, sym) 1113#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
1062 1114
1169 RETVAL 1221 RETVAL
1170 1222
1171Window 1223Window
1172rxvt_term::parent () 1224rxvt_term::parent ()
1173 CODE: 1225 CODE:
1174 RETVAL = THIS->parent [0]; 1226 RETVAL = THIS->parent;
1175 OUTPUT: 1227 OUTPUT:
1176 RETVAL 1228 RETVAL
1177 1229
1178Window 1230Window
1179rxvt_term::vt () 1231rxvt_term::vt ()
1206 if (newval <= 0) 1258 if (newval <= 0)
1207 THIS->scr_changeview (max (newval, THIS->top_row)); 1259 THIS->scr_changeview (max (newval, THIS->top_row));
1208} 1260}
1209 OUTPUT: 1261 OUTPUT:
1210 RETVAL 1262 RETVAL
1263
1264void
1265rxvt_term::set_urgency (bool enable)
1211 1266
1212void 1267void
1213rxvt_term::focus_in () 1268rxvt_term::focus_in ()
1214 1269
1215void 1270void
1448# include "rsinc.h" 1503# include "rsinc.h"
1449# undef def 1504# undef def
1450# undef reserve 1505# undef reserve
1451 }; 1506 };
1452 1507
1453 rs = rslist + ARRAY_LENGTH(rslist); 1508 rs = rslist + ecb_array_length (rslist);
1454 1509
1455 if (*name) 1510 if (*name)
1456 { 1511 {
1457 do { 1512 do {
1458 if (rs-- == rslist) 1513 if (rs-- == rslist)
1497 1552
1498 if (set >= 0) 1553 if (set >= 0)
1499 { 1554 {
1500 THIS->set_option (optval, set); 1555 THIS->set_option (optval, set);
1501 1556
1502 if (THIS->env_colorfgbg [0]) // avoid doing this before START 1557 if (THIS->init_done) // avoid doing this before START
1503 switch (optval) 1558 switch (optval)
1504 { 1559 {
1505 case Opt_skipBuiltinGlyphs: 1560 case Opt_skipBuiltinGlyphs:
1506 THIS->set_fonts (); 1561 THIS->set_fonts ();
1507 THIS->scr_remap_chars (); 1562 THIS->scr_remap_chars ();
1508 THIS->scr_touch (true); 1563 THIS->scr_touch (true);
1509 THIS->want_refresh = 1; 1564 THIS->want_refresh = 1;
1510 THIS->refresh_check (); 1565 THIS->refresh_check ();
1511 break; 1566 break;
1567#ifdef CURSOR_BLINK
1568 case Opt_cursorBlink:
1569 THIS->cursor_blink_reset ();
1570 break;
1571#endif
1512 1572
1513 case Opt_cursorUnderline: 1573 case Opt_cursorUnderline:
1514 THIS->want_refresh = 1; 1574 THIS->want_refresh = 1;
1515 THIS->refresh_check (); 1575 THIS->refresh_check ();
1516 break; 1576 break;
1530 CODE: 1590 CODE:
1531 RETVAL = 0 < THIS->parse_keysym (keysym, str); 1591 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1532 THIS->keyboard->register_done (); 1592 THIS->keyboard->register_done ();
1533 OUTPUT: 1593 OUTPUT:
1534 RETVAL 1594 RETVAL
1595
1596void
1597rxvt_term::register_command (int keysym, unsigned int state, SV *str)
1598 CODE:
1599 wchar_t *wstr = sv2wcs (str);
1600 THIS->keyboard->register_user_translation (keysym, state, wstr);
1601 free (wstr);
1535 1602
1536void 1603void
1537rxvt_term::screen_cur (...) 1604rxvt_term::screen_cur (...)
1538 PROTOTYPE: $;$$ 1605 PROTOTYPE: $;$$
1539 ALIAS: 1606 ALIAS:
1861void 1928void
1862overlay::DESTROY () 1929overlay::DESTROY ()
1863 1930
1864INCLUDE: $PERL <iom_perl.xs -pe s/IOM_MODULE/urxvt/g,s/IOM_CLASS/urxvt/g | 1931INCLUDE: $PERL <iom_perl.xs -pe s/IOM_MODULE/urxvt/g,s/IOM_CLASS/urxvt/g |
1865 1932
1933MODULE = urxvt PACKAGE = urxvt::pixbuf PREFIX = gdk_pixbuf_
1934
1935urxvt::pixbuf gdk_pixbuf_new_from_file (octet_string filename, GError **error = 0)
1936
1937void
1938DESTROY (urxvt::pixbuf self)
1939 CODE:
1940 gdk_pixbuf_unref (self);
1941

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines