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.109 by root, Thu Dec 14 15:19:31 2006 UTC vs.
Revision 1.125 by root, Fri Aug 22 15:36:45 2008 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-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com>
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.
31#include <cstddef> 31#include <cstddef>
32#include <cstdarg> 32#include <cstdarg>
33 33
34#include "unistd.h" 34#include "unistd.h"
35 35
36#include "iom.h" 36#include "ev_cpp.h"
37#include "rxvt.h" 37#include "rxvt.h"
38#include "keyboard.h" 38#include "keyboard.h"
39#include "rxvtutil.h" 39#include "rxvtutil.h"
40#include "rxvtperl.h" 40#include "rxvtperl.h"
41 41
42#include "perlxsi.c" 42#include "perlxsi.c"
43 43
44#ifdef HAVE_SCROLLBARS
45# define GRAB_CURSOR THIS->leftptr_cursor 44#define GRAB_CURSOR THIS->scrollBar.leftptr_cursor
46#else
47# define GRAB_CURSOR None
48#endif
49 45
50#undef LINENO 46#undef LINENO
51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 47#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
52#undef ROW 48#undef ROW
53#define ROW(n) THIS->row_buf [LINENO (n)] 49#define ROW(n) THIS->row_buf [LINENO (n)]
54 50
55typedef int CHAINED UNUSED;
56
57///////////////////////////////////////////////////////////////////////////// 51/////////////////////////////////////////////////////////////////////////////
58 52
59static wchar_t * 53static wchar_t *
60sv2wcs (SV *sv) 54sv2wcs (SV *sv)
61{ 55{
72 SV *sv = newSVpv (str, 0); 66 SV *sv = newSVpv (str, 0);
73 SvUTF8_on (sv); 67 SvUTF8_on (sv);
74 free (str); 68 free (str);
75 69
76 return sv; 70 return sv;
77}
78
79static SV *
80new_ref (HV *hv, const char *klass)
81{
82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
83} 71}
84 72
85static SV * 73static SV *
86newSVptr (void *ptr, const char *klass) 74newSVptr (void *ptr, const char *klass)
87{ 75{
222 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) 210 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
223 )); 211 ));
224 av_push (overlay_av, newSViv ((long)this)); 212 av_push (overlay_av, newSViv ((long)this));
225 213
226 THIS->want_refresh = 1; 214 THIS->want_refresh = 1;
215 THIS->refresh_check ();
227} 216}
228 217
229void 218void
230overlay::hide () 219overlay::hide ()
231{ 220{
245 234
246 SvREFCNT_dec (overlay_av); 235 SvREFCNT_dec (overlay_av);
247 overlay_av = 0; 236 overlay_av = 0;
248 237
249 THIS->want_refresh = 1; 238 THIS->want_refresh = 1;
239 THIS->refresh_check ();
250} 240}
251 241
252void overlay::swap () 242void overlay::swap ()
253{ 243{
254 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 244 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
299 for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) 289 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
300 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 290 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
301 } 291 }
302 292
303 THIS->want_refresh = 1; 293 THIS->want_refresh = 1;
294 THIS->refresh_check ();
304} 295}
305 296
306///////////////////////////////////////////////////////////////////////////// 297/////////////////////////////////////////////////////////////////////////////
307 298
308#define IOM_CLASS "urxvt" 299#define IOM_CLASS "urxvt"
300#define IOM_WARN rxvt_warn
309#include <iom_perl.h> 301#include "iom_perl.h"
310 302
311///////////////////////////////////////////////////////////////////////////// 303/////////////////////////////////////////////////////////////////////////////
312 304
313struct rxvt_perl_interp rxvt_perl; 305struct rxvt_perl_interp rxvt_perl;
314 306
318{ 310{
319 if (perl) 311 if (perl)
320 { 312 {
321 perl_destruct (perl); 313 perl_destruct (perl);
322 perl_free (perl); 314 perl_free (perl);
315 PERL_SYS_TERM ();
323 } 316 }
324} 317}
325 318
326void 319void
327rxvt_perl_interp::init (rxvt_term *term) 320rxvt_perl_interp::init (rxvt_term *term)
331 rxvt_push_locale (""); // perl init destroys current locale 324 rxvt_push_locale (""); // perl init destroys current locale
332 325
333 perl_environ = rxvt_environ; 326 perl_environ = rxvt_environ;
334 swap (perl_environ, environ); 327 swap (perl_environ, environ);
335 328
336 char *argv[] = { 329 char *args[] = {
337 "", 330 "",
338 "-e" 331 "-e"
339 "BEGIN {" 332 "BEGIN {"
340 " urxvt->bootstrap;" 333 " urxvt->bootstrap;"
341 " unshift @INC, '" LIBDIR "';" 334 " unshift @INC, '" LIBDIR "';"
342 "}" 335 "}"
343 "" 336 ""
344 "use urxvt;" 337 "use urxvt;"
345 }; 338 };
339 int argc = sizeof (args) / sizeof (args[0]);
340 char **argv = args;
346 341
342 PERL_SYS_INIT3 (&argc, &argv, &environ);
347 perl = perl_alloc (); 343 perl = perl_alloc ();
348 perl_construct (perl); 344 perl_construct (perl);
349 345
350 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 346 if (perl_parse (perl, xs_init, argc, argv, (char **)NULL)
351 || perl_run (perl)) 347 || perl_run (perl))
352 { 348 {
353 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 349 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
354 350
355 perl_destruct (perl); 351 perl_destruct (perl);
389 385
390 // pre-handling of some events 386 // pre-handling of some events
391 if (htype == HOOK_REFRESH_END) 387 if (htype == HOOK_REFRESH_END)
392 { 388 {
393 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 389 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
394 390
395 for (int i = 0; i <= AvFILL (av); i++) 391 for (int i = 0; i <= AvFILL (av); i++)
396 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 392 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
397 } 393 }
398 394
399 swap (perl_environ, environ); 395 swap (perl_environ, environ);
598 594
599 // post-handling of some events 595 // post-handling of some events
600 if (htype == HOOK_REFRESH_BEGIN) 596 if (htype == HOOK_REFRESH_BEGIN)
601 { 597 {
602 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 598 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
603 599
604 for (int i = AvFILL (av); i >= 0; i--) 600 for (int i = AvFILL (av); i >= 0; i--)
605 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 601 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
606 } 602 }
607 else if (htype == HOOK_DESTROY) 603 else if (htype == HOOK_DESTROY)
608 { 604 {
609 clearSVptr ((SV *)term->perl.self); 605 clearSVptr ((SV *)term->perl.self);
610 SvREFCNT_dec ((SV *)term->perl.self); 606 SvREFCNT_dec ((SV *)term->perl.self);
611 607
612 // don't allow further calls 608 // don't allow further calls
613 term->perl.self = 0; 609 term->perl.self = 0;
614 } 610 }
615 611
616 swap (perl_environ, environ); 612 swap (perl_environ, environ);
647 static const struct { 643 static const struct {
648 const char *name; 644 const char *name;
649 IV iv; 645 IV iv;
650 } *civ, const_iv[] = { 646 } *civ, const_iv[] = {
651# define const_iv(name) { # name, (IV)name } 647# define const_iv(name) { # name, (IV)name }
648 const_iv (NUM_RESOURCES),
652 const_iv (DEFAULT_RSTYLE), 649 const_iv (DEFAULT_RSTYLE),
653 const_iv (OVERLAY_RSTYLE), 650 const_iv (OVERLAY_RSTYLE),
654 const_iv (RS_Bold), 651 const_iv (RS_Bold),
655 const_iv (RS_Italic), 652 const_iv (RS_Italic),
656 const_iv (RS_Blink), 653 const_iv (RS_Blink),
674 const_iv (AnyModifier), 671 const_iv (AnyModifier),
675 672
676 const_iv (NoSymbol), 673 const_iv (NoSymbol),
677 const_iv (GrabModeSync), 674 const_iv (GrabModeSync),
678 const_iv (GrabModeAsync), 675 const_iv (GrabModeAsync),
679
680 const_iv (EVENT_NONE),
681 const_iv (EVENT_READ),
682 const_iv (EVENT_WRITE),
683 676
684 const_iv (NoEventMask), 677 const_iv (NoEventMask),
685 const_iv (KeyPressMask), 678 const_iv (KeyPressMask),
686 const_iv (KeyReleaseMask), 679 const_iv (KeyReleaseMask),
687 const_iv (ButtonPressMask), 680 const_iv (ButtonPressMask),
786_exit (int status) 779_exit (int status)
787 780
788NV 781NV
789NOW () 782NOW ()
790 CODE: 783 CODE:
791 RETVAL = NOW; 784 RETVAL = ev::now ();
792 OUTPUT: 785 OUTPUT:
793 RETVAL 786 RETVAL
794 787
795int 788int
796GET_BASEFG (int rend) 789GET_BASEFG (int rend)
868 for (int i = AvFILL (env) + 1; i--; ) 861 for (int i = AvFILL (env) + 1; i--; )
869 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 862 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
870 863
871 envv->push_back (0); 864 envv->push_back (0);
872 865
873 bool success;
874
875 try 866 try
876 { 867 {
877 success = term->init (argv, envv); 868 term->init (argv, envv);
878 } 869 }
879 catch (const class rxvt_failure_exception &e) 870 catch (const class rxvt_failure_exception &e)
880 {
881 success = false;
882 }
883
884 if (!success)
885 { 871 {
886 term->destroy (); 872 term->destroy ();
887 croak ("error while initializing new terminal instance"); 873 croak ("error while initializing new terminal instance");
888 } 874 }
889 875
1115 { 1101 {
1116 case 0: RETVAL = THIS->ModLevel3Mask; break; 1102 case 0: RETVAL = THIS->ModLevel3Mask; break;
1117 case 1: RETVAL = THIS->ModMetaMask; break; 1103 case 1: RETVAL = THIS->ModMetaMask; break;
1118 case 2: RETVAL = THIS->ModNumLockMask; break; 1104 case 2: RETVAL = THIS->ModNumLockMask; break;
1119 case 3: RETVAL = THIS->current_screen; break; 1105 case 3: RETVAL = THIS->current_screen; break;
1106#ifdef CURSOR_BLINK
1120 case 4: RETVAL = THIS->hidden_cursor; break; 1107 case 4: RETVAL = THIS->hidden_cursor; break;
1108#endif
1121 } 1109 }
1122 OUTPUT: 1110 OUTPUT:
1123 RETVAL 1111 RETVAL
1124 1112
1125char * 1113char *
1150 if (*i) 1138 if (*i)
1151 PUSHs (sv_2mortal (newSVpv (*i, 0))); 1139 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1152} 1140}
1153 1141
1154int 1142int
1155rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1143rxvt_term::pty_ev_events (int events = ev::UNDEF)
1156 CODE: 1144 CODE:
1157 RETVAL = THIS->pty_ev.events; 1145 RETVAL = THIS->pty_ev.events;
1158 if (events != EVENT_UNDEF) 1146 if (events != ev::UNDEF)
1159 THIS->pty_ev.set (events); 1147 THIS->pty_ev.set (events);
1160 OUTPUT: 1148 OUTPUT:
1161 RETVAL 1149 RETVAL
1162 1150
1163int 1151int
1242 1230
1243void 1231void
1244rxvt_term::want_refresh () 1232rxvt_term::want_refresh ()
1245 CODE: 1233 CODE:
1246 THIS->want_refresh = 1; 1234 THIS->want_refresh = 1;
1235 THIS->refresh_check ();
1247 1236
1248void 1237void
1249rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1238rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1250 PPCODE: 1239 PPCODE:
1251{ 1240{
1406SV * 1395SV *
1407rxvt_term::special_decode (SV *text) 1396rxvt_term::special_decode (SV *text)
1408 CODE: 1397 CODE:
1409{ 1398{
1410 wchar_t *wstr = sv2wcs (text); 1399 wchar_t *wstr = sv2wcs (text);
1411 int wlen = wcslen (wstr);
1412 int dlen = 0; 1400 int dlen = 0;
1413 1401
1414 // find length 1402 // find length
1415 for (wchar_t *s = wstr; *s; s++) 1403 for (wchar_t *s = wstr; *s; s++)
1416 if (*s == NOCHAR) 1404 if (*s == NOCHAR)
1449# undef reserve 1437# undef reserve
1450 }; 1438 };
1451 1439
1452 rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1440 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1453 1441
1442 if (*name)
1454 do { 1443 {
1444 do {
1455 if (rs-- == rslist) 1445 if (rs-- == rslist)
1456 croak ("no such resource '%s', requested", name); 1446 croak ("no such resource '%s', requested", name);
1457 } while (strcmp (name, rs->name)); 1447 } while (strcmp (name, rs->name));
1458 1448
1459 index += rs->value; 1449 index += rs->value;
1450 }
1451 else
1452 {
1453 --rs;
1454 name = "";
1455 }
1460 1456
1461 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1457 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1462 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1458 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1463 1459
1464 if (GIMME_V != G_VOID) 1460 if (GIMME_V != G_VOID)
1479 1475
1480const char * 1476const char *
1481rxvt_term::x_resource (const char *name) 1477rxvt_term::x_resource (const char *name)
1482 1478
1483bool 1479bool
1484rxvt_term::option (U32 optval, int set = -1) 1480rxvt_term::option (U8 optval, int set = -1)
1485 CODE: 1481 CODE:
1486{ 1482{
1487 RETVAL = THIS->options & optval; 1483 RETVAL = THIS->option (optval);
1488 1484
1489 if (set >= 0) 1485 if (set >= 0)
1490 { 1486 {
1491 if (set)
1492 THIS->options |= optval; 1487 THIS->set_option (optval, set);
1493 else
1494 THIS->options &= ~optval;
1495 1488
1496 if (THIS->check_ev.is_active ()) // avoid doing this before START 1489 if (THIS->env_colorfgbg [0]) // avoid doing this before START
1497 switch (optval) 1490 switch (optval)
1498 { 1491 {
1499 case Opt_skipBuiltinGlyphs: 1492 case Opt_skipBuiltinGlyphs:
1500 THIS->set_fonts (); 1493 THIS->set_fonts ();
1501 THIS->scr_remap_chars (); 1494 THIS->scr_remap_chars ();
1502 THIS->scr_touch (true); 1495 THIS->scr_touch (true);
1503 THIS->want_refresh = 1; 1496 THIS->want_refresh = 1;
1497 THIS->refresh_check ();
1504 break; 1498 break;
1505 1499
1506 case Opt_cursorUnderline: 1500 case Opt_cursorUnderline:
1507 THIS->want_refresh = 1; 1501 THIS->want_refresh = 1;
1502 THIS->refresh_check ();
1508 break; 1503 break;
1509 1504
1510# case Opt_scrollBar_floating: 1505# case Opt_scrollBar_floating:
1511# case Opt_scrollBar_right: 1506# case Opt_scrollBar_right:
1512# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1507# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1570 1565
1571 clamp_it (rc.col, 0, THIS->ncol); 1566 clamp_it (rc.col, 0, THIS->ncol);
1572 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1567 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1573 1568
1574 if (ix) 1569 if (ix)
1570 {
1575 THIS->want_refresh = 1; 1571 THIS->want_refresh = 1;
1572 THIS->refresh_check ();
1573 }
1576 } 1574 }
1577} 1575}
1578 1576
1579char 1577char
1580rxvt_term::cur_charset () 1578rxvt_term::cur_charset ()
1687 Atom *props = XListProperties (THIS->dpy, window, &count); 1685 Atom *props = XListProperties (THIS->dpy, window, &count);
1688 1686
1689 EXTEND (SP, count); 1687 EXTEND (SP, count);
1690 while (count--) 1688 while (count--)
1691 PUSHs (newSVuv ((U32)props [count])); 1689 PUSHs (newSVuv ((U32)props [count]));
1692 1690
1693 XFree (props); 1691 XFree (props);
1694} 1692}
1695 1693
1696void 1694void
1697rxvt_term::XGetWindowProperty (Window window, Atom property) 1695rxvt_term::XGetWindowProperty (Window window, Atom property)
1720 XFree (prop); 1718 XFree (prop);
1721 } 1719 }
1722} 1720}
1723 1721
1724void 1722void
1725rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data) 1723rxvt_term::XChangeProperty (Window window, Atom property, Atom type, int format, SV *data)
1726 CODE: 1724 CODE:
1727{ 1725{
1728 STRLEN len; 1726 STRLEN len;
1729 char *data_ = SvPVbyte (data, len); 1727 char *data_ = SvPVbyte (data, len);
1730 1728

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines