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.111 by root, Thu Dec 14 17:33:53 2006 UTC vs.
Revision 1.123 by root, Sun Jun 15 14:54:44 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)]
70 SV *sv = newSVpv (str, 0); 66 SV *sv = newSVpv (str, 0);
71 SvUTF8_on (sv); 67 SvUTF8_on (sv);
72 free (str); 68 free (str);
73 69
74 return sv; 70 return sv;
75}
76
77static SV *
78new_ref (HV *hv, const char *klass)
79{
80 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
81} 71}
82 72
83static SV * 73static SV *
84newSVptr (void *ptr, const char *klass) 74newSVptr (void *ptr, const char *klass)
85{ 75{
220 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) 210 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
221 )); 211 ));
222 av_push (overlay_av, newSViv ((long)this)); 212 av_push (overlay_av, newSViv ((long)this));
223 213
224 THIS->want_refresh = 1; 214 THIS->want_refresh = 1;
215 THIS->refresh_check ();
225} 216}
226 217
227void 218void
228overlay::hide () 219overlay::hide ()
229{ 220{
243 234
244 SvREFCNT_dec (overlay_av); 235 SvREFCNT_dec (overlay_av);
245 overlay_av = 0; 236 overlay_av = 0;
246 237
247 THIS->want_refresh = 1; 238 THIS->want_refresh = 1;
239 THIS->refresh_check ();
248} 240}
249 241
250void overlay::swap () 242void overlay::swap ()
251{ 243{
252 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));
297 for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) 289 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
298 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 290 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
299 } 291 }
300 292
301 THIS->want_refresh = 1; 293 THIS->want_refresh = 1;
294 THIS->refresh_check ();
302} 295}
303 296
304///////////////////////////////////////////////////////////////////////////// 297/////////////////////////////////////////////////////////////////////////////
305 298
306#define IOM_CLASS "urxvt" 299#define IOM_CLASS "urxvt"
300#define IOM_WARN rxvt_warn
307#include <iom_perl.h> 301#include "iom_perl.h"
308 302
309///////////////////////////////////////////////////////////////////////////// 303/////////////////////////////////////////////////////////////////////////////
310 304
311struct rxvt_perl_interp rxvt_perl; 305struct rxvt_perl_interp rxvt_perl;
312 306
387 381
388 // pre-handling of some events 382 // pre-handling of some events
389 if (htype == HOOK_REFRESH_END) 383 if (htype == HOOK_REFRESH_END)
390 { 384 {
391 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 385 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
392 386
393 for (int i = 0; i <= AvFILL (av); i++) 387 for (int i = 0; i <= AvFILL (av); i++)
394 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 388 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
395 } 389 }
396 390
397 swap (perl_environ, environ); 391 swap (perl_environ, environ);
596 590
597 // post-handling of some events 591 // post-handling of some events
598 if (htype == HOOK_REFRESH_BEGIN) 592 if (htype == HOOK_REFRESH_BEGIN)
599 { 593 {
600 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 594 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
601 595
602 for (int i = AvFILL (av); i >= 0; i--) 596 for (int i = AvFILL (av); i >= 0; i--)
603 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 597 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
604 } 598 }
605 else if (htype == HOOK_DESTROY) 599 else if (htype == HOOK_DESTROY)
606 { 600 {
607 clearSVptr ((SV *)term->perl.self); 601 clearSVptr ((SV *)term->perl.self);
608 SvREFCNT_dec ((SV *)term->perl.self); 602 SvREFCNT_dec ((SV *)term->perl.self);
609 603
610 // don't allow further calls 604 // don't allow further calls
611 term->perl.self = 0; 605 term->perl.self = 0;
612 } 606 }
613 607
614 swap (perl_environ, environ); 608 swap (perl_environ, environ);
645 static const struct { 639 static const struct {
646 const char *name; 640 const char *name;
647 IV iv; 641 IV iv;
648 } *civ, const_iv[] = { 642 } *civ, const_iv[] = {
649# define const_iv(name) { # name, (IV)name } 643# define const_iv(name) { # name, (IV)name }
644 const_iv (NUM_RESOURCES),
650 const_iv (DEFAULT_RSTYLE), 645 const_iv (DEFAULT_RSTYLE),
651 const_iv (OVERLAY_RSTYLE), 646 const_iv (OVERLAY_RSTYLE),
652 const_iv (RS_Bold), 647 const_iv (RS_Bold),
653 const_iv (RS_Italic), 648 const_iv (RS_Italic),
654 const_iv (RS_Blink), 649 const_iv (RS_Blink),
780_exit (int status) 775_exit (int status)
781 776
782NV 777NV
783NOW () 778NOW ()
784 CODE: 779 CODE:
785 RETVAL = NOW; 780 RETVAL = ev::now ();
786 OUTPUT: 781 OUTPUT:
787 RETVAL 782 RETVAL
788 783
789int 784int
790GET_BASEFG (int rend) 785GET_BASEFG (int rend)
862 for (int i = AvFILL (env) + 1; i--; ) 857 for (int i = AvFILL (env) + 1; i--; )
863 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 858 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
864 859
865 envv->push_back (0); 860 envv->push_back (0);
866 861
867 bool success;
868
869 try 862 try
870 { 863 {
871 success = term->init (argv, envv); 864 term->init (argv, envv);
872 } 865 }
873 catch (const class rxvt_failure_exception &e) 866 catch (const class rxvt_failure_exception &e)
874 {
875 success = false;
876 }
877
878 if (!success)
879 { 867 {
880 term->destroy (); 868 term->destroy ();
881 croak ("error while initializing new terminal instance"); 869 croak ("error while initializing new terminal instance");
882 } 870 }
883 871
1144 if (*i) 1132 if (*i)
1145 PUSHs (sv_2mortal (newSVpv (*i, 0))); 1133 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1146} 1134}
1147 1135
1148int 1136int
1149rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1137rxvt_term::pty_ev_events (int events = ev::UNDEF)
1150 CODE: 1138 CODE:
1151 RETVAL = THIS->pty_ev.events; 1139 RETVAL = THIS->pty_ev.events;
1152 if (events != EVENT_UNDEF) 1140 if (events != ev::UNDEF)
1153 THIS->pty_ev.set (events); 1141 THIS->pty_ev.set (events);
1154 OUTPUT: 1142 OUTPUT:
1155 RETVAL 1143 RETVAL
1156 1144
1157int 1145int
1236 1224
1237void 1225void
1238rxvt_term::want_refresh () 1226rxvt_term::want_refresh ()
1239 CODE: 1227 CODE:
1240 THIS->want_refresh = 1; 1228 THIS->want_refresh = 1;
1229 THIS->refresh_check ();
1241 1230
1242void 1231void
1243rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1232rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1244 PPCODE: 1233 PPCODE:
1245{ 1234{
1400SV * 1389SV *
1401rxvt_term::special_decode (SV *text) 1390rxvt_term::special_decode (SV *text)
1402 CODE: 1391 CODE:
1403{ 1392{
1404 wchar_t *wstr = sv2wcs (text); 1393 wchar_t *wstr = sv2wcs (text);
1405 int wlen = wcslen (wstr);
1406 int dlen = 0; 1394 int dlen = 0;
1407 1395
1408 // find length 1396 // find length
1409 for (wchar_t *s = wstr; *s; s++) 1397 for (wchar_t *s = wstr; *s; s++)
1410 if (*s == NOCHAR) 1398 if (*s == NOCHAR)
1443# undef reserve 1431# undef reserve
1444 }; 1432 };
1445 1433
1446 rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1434 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1447 1435
1436 if (*name)
1448 do { 1437 {
1438 do {
1449 if (rs-- == rslist) 1439 if (rs-- == rslist)
1450 croak ("no such resource '%s', requested", name); 1440 croak ("no such resource '%s', requested", name);
1451 } while (strcmp (name, rs->name)); 1441 } while (strcmp (name, rs->name));
1452 1442
1453 index += rs->value; 1443 index += rs->value;
1444 }
1445 else
1446 {
1447 --rs;
1448 name = "";
1449 }
1454 1450
1455 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1451 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1456 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1452 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1457 1453
1458 if (GIMME_V != G_VOID) 1454 if (GIMME_V != G_VOID)
1473 1469
1474const char * 1470const char *
1475rxvt_term::x_resource (const char *name) 1471rxvt_term::x_resource (const char *name)
1476 1472
1477bool 1473bool
1478rxvt_term::option (U32 optval, int set = -1) 1474rxvt_term::option (U8 optval, int set = -1)
1479 CODE: 1475 CODE:
1480{ 1476{
1481 RETVAL = THIS->options & optval; 1477 RETVAL = THIS->option (optval);
1482 1478
1483 if (set >= 0) 1479 if (set >= 0)
1484 { 1480 {
1485 if (set)
1486 THIS->options |= optval; 1481 THIS->set_option (optval, set);
1487 else
1488 THIS->options &= ~optval;
1489 1482
1490 if (THIS->check_ev.is_active ()) // avoid doing this before START 1483 if (THIS->env_colorfgbg [0]) // avoid doing this before START
1491 switch (optval) 1484 switch (optval)
1492 { 1485 {
1493 case Opt_skipBuiltinGlyphs: 1486 case Opt_skipBuiltinGlyphs:
1494 THIS->set_fonts (); 1487 THIS->set_fonts ();
1495 THIS->scr_remap_chars (); 1488 THIS->scr_remap_chars ();
1496 THIS->scr_touch (true); 1489 THIS->scr_touch (true);
1497 THIS->want_refresh = 1; 1490 THIS->want_refresh = 1;
1491 THIS->refresh_check ();
1498 break; 1492 break;
1499 1493
1500 case Opt_cursorUnderline: 1494 case Opt_cursorUnderline:
1501 THIS->want_refresh = 1; 1495 THIS->want_refresh = 1;
1496 THIS->refresh_check ();
1502 break; 1497 break;
1503 1498
1504# case Opt_scrollBar_floating: 1499# case Opt_scrollBar_floating:
1505# case Opt_scrollBar_right: 1500# case Opt_scrollBar_right:
1506# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1501# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1564 1559
1565 clamp_it (rc.col, 0, THIS->ncol); 1560 clamp_it (rc.col, 0, THIS->ncol);
1566 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1561 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1567 1562
1568 if (ix) 1563 if (ix)
1564 {
1569 THIS->want_refresh = 1; 1565 THIS->want_refresh = 1;
1566 THIS->refresh_check ();
1567 }
1570 } 1568 }
1571} 1569}
1572 1570
1573char 1571char
1574rxvt_term::cur_charset () 1572rxvt_term::cur_charset ()
1681 Atom *props = XListProperties (THIS->dpy, window, &count); 1679 Atom *props = XListProperties (THIS->dpy, window, &count);
1682 1680
1683 EXTEND (SP, count); 1681 EXTEND (SP, count);
1684 while (count--) 1682 while (count--)
1685 PUSHs (newSVuv ((U32)props [count])); 1683 PUSHs (newSVuv ((U32)props [count]));
1686 1684
1687 XFree (props); 1685 XFree (props);
1688} 1686}
1689 1687
1690void 1688void
1691rxvt_term::XGetWindowProperty (Window window, Atom property) 1689rxvt_term::XGetWindowProperty (Window window, Atom property)
1714 XFree (prop); 1712 XFree (prop);
1715 } 1713 }
1716} 1714}
1717 1715
1718void 1716void
1719rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data) 1717rxvt_term::XChangeProperty (Window window, Atom property, Atom type, int format, SV *data)
1720 CODE: 1718 CODE:
1721{ 1719{
1722 STRLEN len; 1720 STRLEN len;
1723 char *data_ = SvPVbyte (data, len); 1721 char *data_ = SvPVbyte (data, len);
1724 1722

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines