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.156 by root, Sun Jun 3 15:54:05 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;
56typedef SV * urxvt_color;
57
58typedef GdkPixbuf * urxvt__pixbuf;
59typedef rxvt_img * urxvt__img;
60
61/////////////////////////////////////////////////////////////////////////////
62
63static void
64parse_color (rxvt_screen *s, rxvt_color &c, SV *sv)
65{
66 //TODO: support component stuff
67 c.set (s, SvPVbyte_nolen (sv));
68}
50 69
51///////////////////////////////////////////////////////////////////////////// 70/////////////////////////////////////////////////////////////////////////////
52 71
53static wchar_t * 72static wchar_t *
54sv2wcs (SV *sv) 73sv2wcs (SV *sv)
302 THIS->refresh_check (); 321 THIS->refresh_check ();
303} 322}
304 323
305///////////////////////////////////////////////////////////////////////////// 324/////////////////////////////////////////////////////////////////////////////
306 325
307#define IOM_CLASS "urxvt"
308#define IOM_WARN rxvt_warn
309#include "iom_perl.h" 326#include "iom_perl.h"
310 327
311///////////////////////////////////////////////////////////////////////////// 328/////////////////////////////////////////////////////////////////////////////
312 329
313struct rxvt_perl_interp rxvt_perl; 330struct rxvt_perl_interp rxvt_perl;
343 " unshift @INC, '" LIBDIR "';" 360 " unshift @INC, '" LIBDIR "';"
344 "}" 361 "}"
345 "" 362 ""
346 "use urxvt;" 363 "use urxvt;"
347 }; 364 };
348 int argc = ARRAY_LENGTH(args); 365 int argc = ecb_array_length (args);
349 char **argv = args; 366 char **argv = args;
350 367
351 PERL_SYS_INIT3 (&argc, &argv, &environ); 368 PERL_SYS_INIT3 (&argc, &argv, &environ);
352 perl = perl_alloc (); 369 perl = perl_alloc ();
353 perl_construct (perl); 370 perl_construct (perl);
369 if (perl) 386 if (perl)
370 { 387 {
371 // runs outside of perls ENV 388 // runs outside of perls ENV
372 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); 389 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); 390 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newAV ()), 0);
391 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, newRV_noinc ((SV *)newAV ()), 0);
374 } 392 }
375} 393}
376 394
377static void 395static void
378ungrab (rxvt_term *THIS) 396ungrab (rxvt_term *THIS)
399 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 417 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
400 418
401 for (int i = 0; i <= AvFILL (av); i++) 419 for (int i = 0; i <= AvFILL (av); i++)
402 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 420 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
403 } 421 }
422 else if (htype == HOOK_DESTROY)
423 {
424 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
425
426 for (int i = AvFILL (av); i >= 0; i--)
427 {
428 rxvt_selection *req = (rxvt_selection *)SvIV (*av_fetch (av, i, 0));
429 delete req;
430 }
431 }
404 432
405 bool event_consumed; 433 bool event_consumed;
406 434
407 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always 435 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
408 || term->perl.should_invoke [htype]) 436 || term->perl.should_invoke [htype])
415 ENTER; 443 ENTER;
416 SAVETMPS; 444 SAVETMPS;
417 445
418 PUSHMARK (SP); 446 PUSHMARK (SP);
419 447
448 EXTEND (SP, 2);
420 XPUSHs (sv_2mortal (newSVterm (term))); 449 PUSHs (sv_2mortal (newSVterm (term)));
421 XPUSHs (sv_2mortal (newSViv (htype))); 450 PUSHs (sv_2mortal (newSViv (htype)));
422 451
423 for (;;) { 452 for (;;) {
424 data_type dt = (data_type)va_arg (ap, int); 453 data_type dt = (data_type)va_arg (ap, int);
425 454
426 switch (dt) 455 switch (dt)
583 FREETMPS; 612 FREETMPS;
584 LEAVE; 613 LEAVE;
585 614
586 if (SvTRUE (ERRSV)) 615 if (SvTRUE (ERRSV))
587 { 616 {
588 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); 617 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPVbyte_nolen (ERRSV));
589 ungrab (term); // better lose the grab than the session 618 ungrab (term); // better lose the grab than the session
590 } 619 }
591 620
592 event_consumed = !!count; 621 event_consumed = !!count;
593 } 622 }
610 // don't allow further calls 639 // don't allow further calls
611 term->perl.self = 0; 640 term->perl.self = 0;
612 } 641 }
613 642
614 return event_consumed; 643 return event_consumed;
644}
645
646void
647rxvt_perl_interp::selection_finish (rxvt_selection *sel, char *data, unsigned int len)
648{
649 localise_env set_environ (perl_environ);
650
651 ENTER;
652 SAVETMPS;
653
654 dSP;
655 XPUSHs (sv_2mortal (newSVpvn (data, len)));
656 call_sv ((SV *)sel->cb_sv, G_VOID | G_DISCARD | G_EVAL);
657
658 if (SvTRUE (ERRSV))
659 rxvt_warn ("perl selection callback evaluation error: %s", SvPVbyte_nolen (ERRSV));
660
661 FREETMPS;
662 LEAVE;
615} 663}
616 664
617///////////////////////////////////////////////////////////////////////////// 665/////////////////////////////////////////////////////////////////////////////
618 666
619MODULE = urxvt PACKAGE = urxvt 667MODULE = urxvt PACKAGE = urxvt
770 const_iv (XIMDontChange), 818 const_iv (XIMDontChange),
771# endif 819# endif
772# endif 820# endif
773 }; 821 };
774 822
775 for (civ = const_iv + ARRAY_LENGTH(const_iv); civ-- > const_iv; ) 823 for (civ = const_iv + ecb_array_length (const_iv); civ > const_iv; civ--)
776 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 824 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
777} 825}
778 826
779void 827void
780warn (const char *msg) 828warn (const char *msg)
781 CODE: 829 CODE:
853 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) 901 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
854 if ((*t)->perl.self) 902 if ((*t)->perl.self)
855 PUSHs (sv_2mortal (newSVterm (*t))); 903 PUSHs (sv_2mortal (newSVterm (*t)));
856} 904}
857 905
906IV
907_new_selection_request (rxvt_term *term, int selnum, Time tm, Window win, Atom prop, SV *cb)
908 CODE:
909 rxvt_selection *req = new rxvt_selection (term->display, selnum, tm, win, prop, term);
910 req->cb_sv = newSVsv (cb);
911 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_selection", 10, 0));
912 av_push (av, newSViv ((IV)req));
913 RETVAL = (IV)req;
914 OUTPUT:
915 RETVAL
916
917void
918_delete_selection_request (IV req_)
919 CODE:
920 rxvt_selection *req = (rxvt_selection *)req_;
921 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)req->term->perl.self), "_selection", 10, 0));
922 int i;
923
924 for (i = AvFILL (av); i >= 0; i--)
925 if (SvIV (*av_fetch (av, i, 1)) == req_)
926 break;
927
928 for (; i < AvFILL (av); i++)
929 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0)));
930
931 av_pop (av);
932
933 delete req;
934
858MODULE = urxvt PACKAGE = urxvt::term 935MODULE = urxvt PACKAGE = urxvt::term
859 936
860SV * 937SV *
861_new (AV *env, AV *arg) 938_new (AV *env, AV *arg)
862 CODE: 939 CODE:
863{ 940{
864 rxvt_term *term = new rxvt_term; 941 rxvt_term *term = new rxvt_term;
865 942
866 stringvec *argv = new stringvec; 943 stringvec *argv = new stringvec;
867 stringvec *envv = new stringvec;
868
869 for (int i = 0; i <= AvFILL (arg); i++) 944 for (int i = 0; i <= AvFILL (arg); i++)
870 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1)))); 945 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
871 946
947 stringvec *envv = new stringvec;
872 for (int i = AvFILL (env) + 1; i--; ) 948 for (int i = AvFILL (env) + 1; i--; )
873 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 949 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
874
875 envv->push_back (0);
876 950
877 try 951 try
878 { 952 {
879 term->init (argv, envv); 953 term->init (argv, envv);
880 } 954 }
920 994
921void 995void
922rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt) 996rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt)
923 CODE: 997 CODE:
924 XUngrabKey (THIS->dpy, keycode, modifiers, window); 998 XUngrabKey (THIS->dpy, keycode, modifiers, window);
925
926void
927rxvt_term::XUngrabKeyboard (Time eventtime)
928 CODE:
929 XUngrabKeyboard (THIS->dpy, eventtime);
930 999
931bool 1000bool
932rxvt_term::grab (Time eventtime, int sync = 0) 1001rxvt_term::grab (Time eventtime, int sync = 0)
933 CODE: 1002 CODE:
934{ 1003{
1046 rxvt_pop_locale (); 1115 rxvt_pop_locale ();
1047 1116
1048 RETVAL = wcs2sv (wstr); 1117 RETVAL = wcs2sv (wstr);
1049 free (wstr); 1118 free (wstr);
1050} 1119}
1051 OUTPUT:
1052 RETVAL
1053
1054char *
1055rxvt_term::locale ()
1056 CODE:
1057 RETVAL = THIS->locale;
1058 OUTPUT: 1120 OUTPUT:
1059 RETVAL 1121 RETVAL
1060 1122
1061#define TERM_OFFSET(sym) offsetof (TermWin_t, sym) 1123#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
1062 1124
1169 RETVAL 1231 RETVAL
1170 1232
1171Window 1233Window
1172rxvt_term::parent () 1234rxvt_term::parent ()
1173 CODE: 1235 CODE:
1174 RETVAL = THIS->parent [0]; 1236 RETVAL = THIS->parent;
1175 OUTPUT: 1237 OUTPUT:
1176 RETVAL 1238 RETVAL
1177 1239
1178Window 1240Window
1179rxvt_term::vt () 1241rxvt_term::vt ()
1206 if (newval <= 0) 1268 if (newval <= 0)
1207 THIS->scr_changeview (max (newval, THIS->top_row)); 1269 THIS->scr_changeview (max (newval, THIS->top_row));
1208} 1270}
1209 OUTPUT: 1271 OUTPUT:
1210 RETVAL 1272 RETVAL
1273
1274void
1275rxvt_term::set_urgency (bool enable)
1211 1276
1212void 1277void
1213rxvt_term::focus_in () 1278rxvt_term::focus_in ()
1214 1279
1215void 1280void
1448# include "rsinc.h" 1513# include "rsinc.h"
1449# undef def 1514# undef def
1450# undef reserve 1515# undef reserve
1451 }; 1516 };
1452 1517
1453 rs = rslist + ARRAY_LENGTH(rslist); 1518 rs = rslist + ecb_array_length (rslist);
1454 1519
1455 if (*name) 1520 if (*name)
1456 { 1521 {
1457 do { 1522 do {
1458 if (rs-- == rslist) 1523 if (rs-- == rslist)
1497 1562
1498 if (set >= 0) 1563 if (set >= 0)
1499 { 1564 {
1500 THIS->set_option (optval, set); 1565 THIS->set_option (optval, set);
1501 1566
1502 if (THIS->env_colorfgbg [0]) // avoid doing this before START 1567 if (THIS->init_done) // avoid doing this before START
1503 switch (optval) 1568 switch (optval)
1504 { 1569 {
1505 case Opt_skipBuiltinGlyphs: 1570 case Opt_skipBuiltinGlyphs:
1506 THIS->set_fonts (); 1571 THIS->set_fonts ();
1507 THIS->scr_remap_chars (); 1572 THIS->scr_remap_chars ();
1508 THIS->scr_touch (true); 1573 THIS->scr_touch (true);
1509 THIS->want_refresh = 1; 1574 THIS->want_refresh = 1;
1510 THIS->refresh_check (); 1575 THIS->refresh_check ();
1511 break; 1576 break;
1577#ifdef CURSOR_BLINK
1578 case Opt_cursorBlink:
1579 THIS->cursor_blink_reset ();
1580 break;
1581#endif
1512 1582
1513 case Opt_cursorUnderline: 1583 case Opt_cursorUnderline:
1514 THIS->want_refresh = 1; 1584 THIS->want_refresh = 1;
1515 THIS->refresh_check (); 1585 THIS->refresh_check ();
1516 break; 1586 break;
1530 CODE: 1600 CODE:
1531 RETVAL = 0 < THIS->parse_keysym (keysym, str); 1601 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1532 THIS->keyboard->register_done (); 1602 THIS->keyboard->register_done ();
1533 OUTPUT: 1603 OUTPUT:
1534 RETVAL 1604 RETVAL
1605
1606void
1607rxvt_term::register_command (int keysym, unsigned int state, SV *str)
1608 CODE:
1609 wchar_t *wstr = sv2wcs (str);
1610 THIS->keyboard->register_user_translation (keysym, state, wstr);
1611 free (wstr);
1535 1612
1536void 1613void
1537rxvt_term::screen_cur (...) 1614rxvt_term::screen_cur (...)
1538 PROTOTYPE: $;$$ 1615 PROTOTYPE: $;$$
1539 ALIAS: 1616 ALIAS:
1861void 1938void
1862overlay::DESTROY () 1939overlay::DESTROY ()
1863 1940
1864INCLUDE: $PERL <iom_perl.xs -pe s/IOM_MODULE/urxvt/g,s/IOM_CLASS/urxvt/g | 1941INCLUDE: $PERL <iom_perl.xs -pe s/IOM_MODULE/urxvt/g,s/IOM_CLASS/urxvt/g |
1865 1942
1943MODULE = urxvt PACKAGE = urxvt::pixbuf PREFIX = gdk_pixbuf_
1944
1945#if HAVE_PIXBUF
1946
1947urxvt::pixbuf gdk_pixbuf_new_from_file (SV *klass, octet_string filename)
1948 C_ARGS: filename, 0
1949
1950void
1951DESTROY (urxvt::pixbuf self)
1952 CODE:
1953 gdk_pixbuf_unref (self);
1954
1955#endif
1956
1957MODULE = urxvt PACKAGE = urxvt::img
1958
1959#if HAVE_IMG
1960
1961# rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height);
1962# rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap);
1963
1964void fill (urxvt::img self, SV *c)
1965 CODE:
1966 rxvt_color rc;
1967 parse_color (self->s, rc, c);
1968 self->fill (rc);
1969
1970void blur (urxvt::img self, int rh, int rv)
1971 CODE:
1972 self->blur (rh, rv);
1973
1974void brightness (urxvt::img self, double r, double g, double b, double a = 1.)
1975 CODE:
1976 self->brightness (r, g, b, a);
1977
1978void contrast (urxvt::img self, double r, double g, double b, double a = 1.)
1979 CODE:
1980 self->contrast (r, g, b, a);
1981
1982urxvt::img copy (urxvt::img self)
1983 CODE:
1984 RETVAL = self->copy ();
1985 OUTPUT:
1986 RETVAL
1987
1988urxvt::img scale (urxvt::img self, int new_width, int new_height)
1989 CODE:
1990 RETVAL = self->scale (new_width, new_height);
1991 OUTPUT:
1992 RETVAL
1993
1994# rxvt_img *transform (urxvt::img self, int new_width, int new_height, double matrix[16]);
1995
1996#endif
1997

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines