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.112 by root, Thu Dec 14 17:40:03 2006 UTC vs.
Revision 1.126 by root, Wed Nov 5 14:43:54 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)]
73 69
74 return sv; 70 return sv;
75} 71}
76 72
77static SV * 73static SV *
78new_ref (HV *hv, const char *klass)
79{
80 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
81}
82
83static SV *
84newSVptr (void *ptr, const char *klass) 74newSVptr (void *ptr, const char *klass)
85{ 75{
86 HV *hv = newHV (); 76 HV *hv = newHV ();
87 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 77 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
88 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 78 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
117 107
118///////////////////////////////////////////////////////////////////////////// 108/////////////////////////////////////////////////////////////////////////////
119 109
120#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 110#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
121 111
122class overlay { 112class overlay : overlay_base
113{
123 rxvt_term *THIS; 114 rxvt_term *THIS;
124 AV *overlay_av; 115 AV *overlay_av;
125 int x, y, w, h;
126 int border; 116 int border;
127 text_t **text;
128 rend_t **rend;
129 117
130public: 118public:
131 HV *self; 119 HV *self;
132 120
133 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); 121 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
140 128
141 void set (int x, int y, SV *str, SV *rend); 129 void set (int x, int y, SV *str, SV *rend);
142}; 130};
143 131
144overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 132overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
145: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0) 133: THIS(THIS), border(border == 2), overlay_av (0)
146{ 134{
135 x = x_;
136 y = y_;
137 w = w_;
138 h = h_;
139
147 if (w < 0) w = 0; 140 if (w < 0) w = 0;
148 if (h < 0) h = 0; 141 if (h < 0) h = 0;
149 142
150 if (border == 2) 143 if (border == 2)
151 { 144 {
220 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) 213 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
221 )); 214 ));
222 av_push (overlay_av, newSViv ((long)this)); 215 av_push (overlay_av, newSViv ((long)this));
223 216
224 THIS->want_refresh = 1; 217 THIS->want_refresh = 1;
218 THIS->refresh_check ();
225} 219}
226 220
227void 221void
228overlay::hide () 222overlay::hide ()
229{ 223{
243 237
244 SvREFCNT_dec (overlay_av); 238 SvREFCNT_dec (overlay_av);
245 overlay_av = 0; 239 overlay_av = 0;
246 240
247 THIS->want_refresh = 1; 241 THIS->want_refresh = 1;
242 THIS->refresh_check ();
248} 243}
249 244
250void overlay::swap () 245void overlay::swap ()
251{ 246{
252 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 247 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
253 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); 248 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
254 249
255 int ov_w = min (w, THIS->ncol - ov_x); 250 int ov_w = min (w, THIS->ncol - ov_x);
256 int ov_h = min (h, THIS->nrow - ov_y); 251 int ov_h = min (h, THIS->nrow - ov_y);
252
253 // hide cursor if it is within the overlay area
254 if (IN_RANGE_EXC (THIS->screen.cur.col - ov_x, 0, ov_w)
255 && IN_RANGE_EXC (THIS->screen.cur.row - ov_y, 0, ov_h))
256 THIS->screen.flags &= ~Screen_VisibleCursor;
257 257
258 for (int y = ov_h; y--; ) 258 for (int y = ov_h; y--; )
259 { 259 {
260 text_t *t1 = text [y]; 260 text_t *t1 = text [y];
261 rend_t *r1 = rend [y]; 261 rend_t *r1 = rend [y];
297 for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) 297 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
298 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 298 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
299 } 299 }
300 300
301 THIS->want_refresh = 1; 301 THIS->want_refresh = 1;
302 THIS->refresh_check ();
302} 303}
303 304
304///////////////////////////////////////////////////////////////////////////// 305/////////////////////////////////////////////////////////////////////////////
305 306
306#define IOM_CLASS "urxvt" 307#define IOM_CLASS "urxvt"
307#define IOM_WARN rxvt_warn 308#define IOM_WARN rxvt_warn
308#include <iom_perl.h> 309#include "iom_perl.h"
309 310
310///////////////////////////////////////////////////////////////////////////// 311/////////////////////////////////////////////////////////////////////////////
311 312
312struct rxvt_perl_interp rxvt_perl; 313struct rxvt_perl_interp rxvt_perl;
313 314
317{ 318{
318 if (perl) 319 if (perl)
319 { 320 {
320 perl_destruct (perl); 321 perl_destruct (perl);
321 perl_free (perl); 322 perl_free (perl);
323 PERL_SYS_TERM ();
322 } 324 }
323} 325}
324 326
325void 327void
326rxvt_perl_interp::init (rxvt_term *term) 328rxvt_perl_interp::init (rxvt_term *term)
330 rxvt_push_locale (""); // perl init destroys current locale 332 rxvt_push_locale (""); // perl init destroys current locale
331 333
332 perl_environ = rxvt_environ; 334 perl_environ = rxvt_environ;
333 swap (perl_environ, environ); 335 swap (perl_environ, environ);
334 336
335 char *argv[] = { 337 char *args[] = {
336 "", 338 "",
337 "-e" 339 "-e"
338 "BEGIN {" 340 "BEGIN {"
339 " urxvt->bootstrap;" 341 " urxvt->bootstrap;"
340 " unshift @INC, '" LIBDIR "';" 342 " unshift @INC, '" LIBDIR "';"
341 "}" 343 "}"
342 "" 344 ""
343 "use urxvt;" 345 "use urxvt;"
344 }; 346 };
347 int argc = sizeof (args) / sizeof (args[0]);
348 char **argv = args;
345 349
350 PERL_SYS_INIT3 (&argc, &argv, &environ);
346 perl = perl_alloc (); 351 perl = perl_alloc ();
347 perl_construct (perl); 352 perl_construct (perl);
348 353
349 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 354 if (perl_parse (perl, xs_init, argc, argv, (char **)NULL)
350 || perl_run (perl)) 355 || perl_run (perl))
351 { 356 {
352 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 357 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
353 358
354 perl_destruct (perl); 359 perl_destruct (perl);
388 393
389 // pre-handling of some events 394 // pre-handling of some events
390 if (htype == HOOK_REFRESH_END) 395 if (htype == HOOK_REFRESH_END)
391 { 396 {
392 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 397 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
393 398
394 for (int i = 0; i <= AvFILL (av); i++) 399 for (int i = 0; i <= AvFILL (av); i++)
395 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 400 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
396 } 401 }
397 402
398 swap (perl_environ, environ); 403 swap (perl_environ, environ);
597 602
598 // post-handling of some events 603 // post-handling of some events
599 if (htype == HOOK_REFRESH_BEGIN) 604 if (htype == HOOK_REFRESH_BEGIN)
600 { 605 {
601 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 606 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
602 607
603 for (int i = AvFILL (av); i >= 0; i--) 608 for (int i = AvFILL (av); i >= 0; i--)
604 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 609 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
605 } 610 }
606 else if (htype == HOOK_DESTROY) 611 else if (htype == HOOK_DESTROY)
607 { 612 {
608 clearSVptr ((SV *)term->perl.self); 613 clearSVptr ((SV *)term->perl.self);
609 SvREFCNT_dec ((SV *)term->perl.self); 614 SvREFCNT_dec ((SV *)term->perl.self);
610 615
611 // don't allow further calls 616 // don't allow further calls
612 term->perl.self = 0; 617 term->perl.self = 0;
613 } 618 }
614 619
615 swap (perl_environ, environ); 620 swap (perl_environ, environ);
646 static const struct { 651 static const struct {
647 const char *name; 652 const char *name;
648 IV iv; 653 IV iv;
649 } *civ, const_iv[] = { 654 } *civ, const_iv[] = {
650# define const_iv(name) { # name, (IV)name } 655# define const_iv(name) { # name, (IV)name }
656 const_iv (NUM_RESOURCES),
651 const_iv (DEFAULT_RSTYLE), 657 const_iv (DEFAULT_RSTYLE),
652 const_iv (OVERLAY_RSTYLE), 658 const_iv (OVERLAY_RSTYLE),
653 const_iv (RS_Bold), 659 const_iv (RS_Bold),
654 const_iv (RS_Italic), 660 const_iv (RS_Italic),
655 const_iv (RS_Blink), 661 const_iv (RS_Blink),
781_exit (int status) 787_exit (int status)
782 788
783NV 789NV
784NOW () 790NOW ()
785 CODE: 791 CODE:
786 RETVAL = NOW; 792 RETVAL = ev::now ();
787 OUTPUT: 793 OUTPUT:
788 RETVAL 794 RETVAL
789 795
790int 796int
791GET_BASEFG (int rend) 797GET_BASEFG (int rend)
863 for (int i = AvFILL (env) + 1; i--; ) 869 for (int i = AvFILL (env) + 1; i--; )
864 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 870 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
865 871
866 envv->push_back (0); 872 envv->push_back (0);
867 873
868 bool success;
869
870 try 874 try
871 { 875 {
872 success = term->init (argv, envv); 876 term->init (argv, envv);
873 } 877 }
874 catch (const class rxvt_failure_exception &e) 878 catch (const class rxvt_failure_exception &e)
875 {
876 success = false;
877 }
878
879 if (!success)
880 { 879 {
881 term->destroy (); 880 term->destroy ();
882 croak ("error while initializing new terminal instance"); 881 croak ("error while initializing new terminal instance");
883 } 882 }
884 883
1110 { 1109 {
1111 case 0: RETVAL = THIS->ModLevel3Mask; break; 1110 case 0: RETVAL = THIS->ModLevel3Mask; break;
1112 case 1: RETVAL = THIS->ModMetaMask; break; 1111 case 1: RETVAL = THIS->ModMetaMask; break;
1113 case 2: RETVAL = THIS->ModNumLockMask; break; 1112 case 2: RETVAL = THIS->ModNumLockMask; break;
1114 case 3: RETVAL = THIS->current_screen; break; 1113 case 3: RETVAL = THIS->current_screen; break;
1114#ifdef CURSOR_BLINK
1115 case 4: RETVAL = THIS->hidden_cursor; break; 1115 case 4: RETVAL = THIS->hidden_cursor; break;
1116#endif
1116 } 1117 }
1117 OUTPUT: 1118 OUTPUT:
1118 RETVAL 1119 RETVAL
1119 1120
1120char * 1121char *
1145 if (*i) 1146 if (*i)
1146 PUSHs (sv_2mortal (newSVpv (*i, 0))); 1147 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1147} 1148}
1148 1149
1149int 1150int
1150rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1151rxvt_term::pty_ev_events (int events = ev::UNDEF)
1151 CODE: 1152 CODE:
1152 RETVAL = THIS->pty_ev.events; 1153 RETVAL = THIS->pty_ev.events;
1153 if (events != EVENT_UNDEF) 1154 if (events != ev::UNDEF)
1154 THIS->pty_ev.set (events); 1155 THIS->pty_ev.set (events);
1155 OUTPUT: 1156 OUTPUT:
1156 RETVAL 1157 RETVAL
1157 1158
1158int 1159int
1237 1238
1238void 1239void
1239rxvt_term::want_refresh () 1240rxvt_term::want_refresh ()
1240 CODE: 1241 CODE:
1241 THIS->want_refresh = 1; 1242 THIS->want_refresh = 1;
1243 THIS->refresh_check ();
1242 1244
1243void 1245void
1244rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1246rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1245 PPCODE: 1247 PPCODE:
1246{ 1248{
1401SV * 1403SV *
1402rxvt_term::special_decode (SV *text) 1404rxvt_term::special_decode (SV *text)
1403 CODE: 1405 CODE:
1404{ 1406{
1405 wchar_t *wstr = sv2wcs (text); 1407 wchar_t *wstr = sv2wcs (text);
1406 int wlen = wcslen (wstr);
1407 int dlen = 0; 1408 int dlen = 0;
1408 1409
1409 // find length 1410 // find length
1410 for (wchar_t *s = wstr; *s; s++) 1411 for (wchar_t *s = wstr; *s; s++)
1411 if (*s == NOCHAR) 1412 if (*s == NOCHAR)
1444# undef reserve 1445# undef reserve
1445 }; 1446 };
1446 1447
1447 rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1448 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1448 1449
1450 if (*name)
1449 do { 1451 {
1452 do {
1450 if (rs-- == rslist) 1453 if (rs-- == rslist)
1451 croak ("no such resource '%s', requested", name); 1454 croak ("no such resource '%s', requested", name);
1452 } while (strcmp (name, rs->name)); 1455 } while (strcmp (name, rs->name));
1453 1456
1454 index += rs->value; 1457 index += rs->value;
1458 }
1459 else
1460 {
1461 --rs;
1462 name = "";
1463 }
1455 1464
1456 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1465 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1457 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1466 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1458 1467
1459 if (GIMME_V != G_VOID) 1468 if (GIMME_V != G_VOID)
1474 1483
1475const char * 1484const char *
1476rxvt_term::x_resource (const char *name) 1485rxvt_term::x_resource (const char *name)
1477 1486
1478bool 1487bool
1479rxvt_term::option (U32 optval, int set = -1) 1488rxvt_term::option (U8 optval, int set = -1)
1480 CODE: 1489 CODE:
1481{ 1490{
1482 RETVAL = THIS->options & optval; 1491 RETVAL = THIS->option (optval);
1483 1492
1484 if (set >= 0) 1493 if (set >= 0)
1485 { 1494 {
1486 if (set)
1487 THIS->options |= optval; 1495 THIS->set_option (optval, set);
1488 else
1489 THIS->options &= ~optval;
1490 1496
1491 if (THIS->check_ev.is_active ()) // avoid doing this before START 1497 if (THIS->env_colorfgbg [0]) // avoid doing this before START
1492 switch (optval) 1498 switch (optval)
1493 { 1499 {
1494 case Opt_skipBuiltinGlyphs: 1500 case Opt_skipBuiltinGlyphs:
1495 THIS->set_fonts (); 1501 THIS->set_fonts ();
1496 THIS->scr_remap_chars (); 1502 THIS->scr_remap_chars ();
1497 THIS->scr_touch (true); 1503 THIS->scr_touch (true);
1498 THIS->want_refresh = 1; 1504 THIS->want_refresh = 1;
1505 THIS->refresh_check ();
1499 break; 1506 break;
1500 1507
1501 case Opt_cursorUnderline: 1508 case Opt_cursorUnderline:
1502 THIS->want_refresh = 1; 1509 THIS->want_refresh = 1;
1510 THIS->refresh_check ();
1503 break; 1511 break;
1504 1512
1505# case Opt_scrollBar_floating: 1513# case Opt_scrollBar_floating:
1506# case Opt_scrollBar_right: 1514# case Opt_scrollBar_right:
1507# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1515# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1565 1573
1566 clamp_it (rc.col, 0, THIS->ncol); 1574 clamp_it (rc.col, 0, THIS->ncol);
1567 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1575 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1568 1576
1569 if (ix) 1577 if (ix)
1578 {
1570 THIS->want_refresh = 1; 1579 THIS->want_refresh = 1;
1580 THIS->refresh_check ();
1581 }
1571 } 1582 }
1572} 1583}
1573 1584
1574char 1585char
1575rxvt_term::cur_charset () 1586rxvt_term::cur_charset ()
1682 Atom *props = XListProperties (THIS->dpy, window, &count); 1693 Atom *props = XListProperties (THIS->dpy, window, &count);
1683 1694
1684 EXTEND (SP, count); 1695 EXTEND (SP, count);
1685 while (count--) 1696 while (count--)
1686 PUSHs (newSVuv ((U32)props [count])); 1697 PUSHs (newSVuv ((U32)props [count]));
1687 1698
1688 XFree (props); 1699 XFree (props);
1689} 1700}
1690 1701
1691void 1702void
1692rxvt_term::XGetWindowProperty (Window window, Atom property) 1703rxvt_term::XGetWindowProperty (Window window, Atom property)
1715 XFree (prop); 1726 XFree (prop);
1716 } 1727 }
1717} 1728}
1718 1729
1719void 1730void
1720rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data) 1731rxvt_term::XChangeProperty (Window window, Atom property, Atom type, int format, SV *data)
1721 CODE: 1732 CODE:
1722{ 1733{
1723 STRLEN len; 1734 STRLEN len;
1724 char *data_ = SvPVbyte (data, len); 1735 char *data_ = SvPVbyte (data, len);
1725 1736

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines