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.115 by ayin, Wed Oct 31 09:55:24 2007 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)]
111 107
112///////////////////////////////////////////////////////////////////////////// 108/////////////////////////////////////////////////////////////////////////////
113 109
114#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 110#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
115 111
116class overlay { 112class overlay : overlay_base
113{
117 rxvt_term *THIS; 114 rxvt_term *THIS;
118 AV *overlay_av; 115 AV *overlay_av;
119 int x, y, w, h;
120 int border; 116 int border;
121 text_t **text;
122 rend_t **rend;
123 117
124public: 118public:
125 HV *self; 119 HV *self;
126 120
127 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);
134 128
135 void set (int x, int y, SV *str, SV *rend); 129 void set (int x, int y, SV *str, SV *rend);
136}; 130};
137 131
138overlay::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)
139: 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)
140{ 134{
135 x = x_;
136 y = y_;
137 w = w_;
138 h = h_;
139
141 if (w < 0) w = 0; 140 if (w < 0) w = 0;
142 if (h < 0) h = 0; 141 if (h < 0) h = 0;
143 142
144 if (border == 2) 143 if (border == 2)
145 { 144 {
214 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) 213 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
215 )); 214 ));
216 av_push (overlay_av, newSViv ((long)this)); 215 av_push (overlay_av, newSViv ((long)this));
217 216
218 THIS->want_refresh = 1; 217 THIS->want_refresh = 1;
218 THIS->refresh_check ();
219} 219}
220 220
221void 221void
222overlay::hide () 222overlay::hide ()
223{ 223{
237 237
238 SvREFCNT_dec (overlay_av); 238 SvREFCNT_dec (overlay_av);
239 overlay_av = 0; 239 overlay_av = 0;
240 240
241 THIS->want_refresh = 1; 241 THIS->want_refresh = 1;
242 THIS->refresh_check ();
242} 243}
243 244
244void overlay::swap () 245void overlay::swap ()
245{ 246{
246 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));
247 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));
248 249
249 int ov_w = min (w, THIS->ncol - ov_x); 250 int ov_w = min (w, THIS->ncol - ov_x);
250 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;
251 257
252 for (int y = ov_h; y--; ) 258 for (int y = ov_h; y--; )
253 { 259 {
254 text_t *t1 = text [y]; 260 text_t *t1 = text [y];
255 rend_t *r1 = rend [y]; 261 rend_t *r1 = rend [y];
291 for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) 297 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
292 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 298 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
293 } 299 }
294 300
295 THIS->want_refresh = 1; 301 THIS->want_refresh = 1;
302 THIS->refresh_check ();
296} 303}
297 304
298///////////////////////////////////////////////////////////////////////////// 305/////////////////////////////////////////////////////////////////////////////
299 306
300#define IOM_CLASS "urxvt" 307#define IOM_CLASS "urxvt"
301#define IOM_WARN rxvt_warn 308#define IOM_WARN rxvt_warn
302#include <iom_perl.h> 309#include "iom_perl.h"
303 310
304///////////////////////////////////////////////////////////////////////////// 311/////////////////////////////////////////////////////////////////////////////
305 312
306struct rxvt_perl_interp rxvt_perl; 313struct rxvt_perl_interp rxvt_perl;
307 314
311{ 318{
312 if (perl) 319 if (perl)
313 { 320 {
314 perl_destruct (perl); 321 perl_destruct (perl);
315 perl_free (perl); 322 perl_free (perl);
323 PERL_SYS_TERM ();
316 } 324 }
317} 325}
318 326
319void 327void
320rxvt_perl_interp::init (rxvt_term *term) 328rxvt_perl_interp::init (rxvt_term *term)
324 rxvt_push_locale (""); // perl init destroys current locale 332 rxvt_push_locale (""); // perl init destroys current locale
325 333
326 perl_environ = rxvt_environ; 334 perl_environ = rxvt_environ;
327 swap (perl_environ, environ); 335 swap (perl_environ, environ);
328 336
329 char *argv[] = { 337 char *args[] = {
330 "", 338 "",
331 "-e" 339 "-e"
332 "BEGIN {" 340 "BEGIN {"
333 " urxvt->bootstrap;" 341 " urxvt->bootstrap;"
334 " unshift @INC, '" LIBDIR "';" 342 " unshift @INC, '" LIBDIR "';"
335 "}" 343 "}"
336 "" 344 ""
337 "use urxvt;" 345 "use urxvt;"
338 }; 346 };
347 int argc = sizeof (args) / sizeof (args[0]);
348 char **argv = args;
339 349
350 PERL_SYS_INIT3 (&argc, &argv, &environ);
340 perl = perl_alloc (); 351 perl = perl_alloc ();
341 perl_construct (perl); 352 perl_construct (perl);
342 353
343 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 354 if (perl_parse (perl, xs_init, argc, argv, (char **)NULL)
344 || perl_run (perl)) 355 || perl_run (perl))
345 { 356 {
346 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 357 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
347 358
348 perl_destruct (perl); 359 perl_destruct (perl);
640 static const struct { 651 static const struct {
641 const char *name; 652 const char *name;
642 IV iv; 653 IV iv;
643 } *civ, const_iv[] = { 654 } *civ, const_iv[] = {
644# define const_iv(name) { # name, (IV)name } 655# define const_iv(name) { # name, (IV)name }
656 const_iv (NUM_RESOURCES),
645 const_iv (DEFAULT_RSTYLE), 657 const_iv (DEFAULT_RSTYLE),
646 const_iv (OVERLAY_RSTYLE), 658 const_iv (OVERLAY_RSTYLE),
647 const_iv (RS_Bold), 659 const_iv (RS_Bold),
648 const_iv (RS_Italic), 660 const_iv (RS_Italic),
649 const_iv (RS_Blink), 661 const_iv (RS_Blink),
775_exit (int status) 787_exit (int status)
776 788
777NV 789NV
778NOW () 790NOW ()
779 CODE: 791 CODE:
780 RETVAL = NOW; 792 RETVAL = ev::now ();
781 OUTPUT: 793 OUTPUT:
782 RETVAL 794 RETVAL
783 795
784int 796int
785GET_BASEFG (int rend) 797GET_BASEFG (int rend)
857 for (int i = AvFILL (env) + 1; i--; ) 869 for (int i = AvFILL (env) + 1; i--; )
858 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 870 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
859 871
860 envv->push_back (0); 872 envv->push_back (0);
861 873
862 bool success;
863
864 try 874 try
865 { 875 {
866 success = term->init (argv, envv); 876 term->init (argv, envv);
867 } 877 }
868 catch (const class rxvt_failure_exception &e) 878 catch (const class rxvt_failure_exception &e)
869 {
870 success = false;
871 }
872
873 if (!success)
874 { 879 {
875 term->destroy (); 880 term->destroy ();
876 croak ("error while initializing new terminal instance"); 881 croak ("error while initializing new terminal instance");
877 } 882 }
878 883
1104 { 1109 {
1105 case 0: RETVAL = THIS->ModLevel3Mask; break; 1110 case 0: RETVAL = THIS->ModLevel3Mask; break;
1106 case 1: RETVAL = THIS->ModMetaMask; break; 1111 case 1: RETVAL = THIS->ModMetaMask; break;
1107 case 2: RETVAL = THIS->ModNumLockMask; break; 1112 case 2: RETVAL = THIS->ModNumLockMask; break;
1108 case 3: RETVAL = THIS->current_screen; break; 1113 case 3: RETVAL = THIS->current_screen; break;
1114#ifdef CURSOR_BLINK
1109 case 4: RETVAL = THIS->hidden_cursor; break; 1115 case 4: RETVAL = THIS->hidden_cursor; break;
1116#endif
1110 } 1117 }
1111 OUTPUT: 1118 OUTPUT:
1112 RETVAL 1119 RETVAL
1113 1120
1114char * 1121char *
1139 if (*i) 1146 if (*i)
1140 PUSHs (sv_2mortal (newSVpv (*i, 0))); 1147 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1141} 1148}
1142 1149
1143int 1150int
1144rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1151rxvt_term::pty_ev_events (int events = ev::UNDEF)
1145 CODE: 1152 CODE:
1146 RETVAL = THIS->pty_ev.events; 1153 RETVAL = THIS->pty_ev.events;
1147 if (events != EVENT_UNDEF) 1154 if (events != ev::UNDEF)
1148 THIS->pty_ev.set (events); 1155 THIS->pty_ev.set (events);
1149 OUTPUT: 1156 OUTPUT:
1150 RETVAL 1157 RETVAL
1151 1158
1152int 1159int
1231 1238
1232void 1239void
1233rxvt_term::want_refresh () 1240rxvt_term::want_refresh ()
1234 CODE: 1241 CODE:
1235 THIS->want_refresh = 1; 1242 THIS->want_refresh = 1;
1243 THIS->refresh_check ();
1236 1244
1237void 1245void
1238rxvt_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)
1239 PPCODE: 1247 PPCODE:
1240{ 1248{
1437# undef reserve 1445# undef reserve
1438 }; 1446 };
1439 1447
1440 rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1448 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1441 1449
1450 if (*name)
1442 do { 1451 {
1452 do {
1443 if (rs-- == rslist) 1453 if (rs-- == rslist)
1444 croak ("no such resource '%s', requested", name); 1454 croak ("no such resource '%s', requested", name);
1445 } while (strcmp (name, rs->name)); 1455 } while (strcmp (name, rs->name));
1446 1456
1447 index += rs->value; 1457 index += rs->value;
1458 }
1459 else
1460 {
1461 --rs;
1462 name = "";
1463 }
1448 1464
1449 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1465 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1450 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);
1451 1467
1452 if (GIMME_V != G_VOID) 1468 if (GIMME_V != G_VOID)
1476 1492
1477 if (set >= 0) 1493 if (set >= 0)
1478 { 1494 {
1479 THIS->set_option (optval, set); 1495 THIS->set_option (optval, set);
1480 1496
1481 if (THIS->check_ev.is_active ()) // avoid doing this before START 1497 if (THIS->env_colorfgbg [0]) // avoid doing this before START
1482 switch (optval) 1498 switch (optval)
1483 { 1499 {
1484 case Opt_skipBuiltinGlyphs: 1500 case Opt_skipBuiltinGlyphs:
1485 THIS->set_fonts (); 1501 THIS->set_fonts ();
1486 THIS->scr_remap_chars (); 1502 THIS->scr_remap_chars ();
1487 THIS->scr_touch (true); 1503 THIS->scr_touch (true);
1488 THIS->want_refresh = 1; 1504 THIS->want_refresh = 1;
1505 THIS->refresh_check ();
1489 break; 1506 break;
1490 1507
1491 case Opt_cursorUnderline: 1508 case Opt_cursorUnderline:
1492 THIS->want_refresh = 1; 1509 THIS->want_refresh = 1;
1510 THIS->refresh_check ();
1493 break; 1511 break;
1494 1512
1495# case Opt_scrollBar_floating: 1513# case Opt_scrollBar_floating:
1496# case Opt_scrollBar_right: 1514# case Opt_scrollBar_right:
1497# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1515# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1555 1573
1556 clamp_it (rc.col, 0, THIS->ncol); 1574 clamp_it (rc.col, 0, THIS->ncol);
1557 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1575 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1558 1576
1559 if (ix) 1577 if (ix)
1578 {
1560 THIS->want_refresh = 1; 1579 THIS->want_refresh = 1;
1580 THIS->refresh_check ();
1581 }
1561 } 1582 }
1562} 1583}
1563 1584
1564char 1585char
1565rxvt_term::cur_charset () 1586rxvt_term::cur_charset ()
1705 XFree (prop); 1726 XFree (prop);
1706 } 1727 }
1707} 1728}
1708 1729
1709void 1730void
1710rxvt_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)
1711 CODE: 1732 CODE:
1712{ 1733{
1713 STRLEN len; 1734 STRLEN len;
1714 char *data_ = SvPVbyte (data, len); 1735 char *data_ = SvPVbyte (data, len);
1715 1736

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines