1 /*----------------------------------------------------------------------*
3 *----------------------------------------------------------------------*
5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com>
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
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *----------------------------------------------------------------------*/
23 #define line_t perl_line_t
29 #include "../config.h"
41 #if defined(HAVE_SCROLLBARS) || defined(MENUBAR)
42 # define GRAB_CURSOR THIS->leftptr_cursor
44 # define GRAB_CURSOR None
48 #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
50 #define ROW(n) THIS->row_buf [LINENO (n)]
52 /////////////////////////////////////////////////////////////////////////////
62 taint_if (SV *sv, SV *src)
74 char *str = SvPVutf8 (sv, len);
75 return rxvt_utf8towcs (str, len);
79 wcs2sv (wchar_t *wstr, int len = -1)
81 char *str = rxvt_wcstoutf8 (wstr, len);
83 SV *sv = newSVpv (str, 0);
91 new_ref (HV *hv, const char *klass)
93 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
98 newSVptr (void *ptr, const char *klass)
101 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
102 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
112 sv_unmagic (sv, PERL_MAGIC_ext);
116 SvPTR (SV *sv, const char *klass)
118 if (!sv_derived_from (sv, klass))
119 croak ("object of type %s expected", klass);
121 MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
124 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
126 return (long)mg->mg_ptr;
129 #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
130 #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
132 /////////////////////////////////////////////////////////////////////////////
154 void invoke (const char *type, SV *self, int arg = -1);
158 perl_watcher::invoke (const char *type, SV *self, int arg)
167 XPUSHs (sv_2mortal (self));
170 XPUSHs (sv_2mortal (newSViv (arg)));
173 call_sv (cbsv, G_VOID | G_EVAL | G_DISCARD);
181 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
184 #define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
185 #define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer")
187 struct timer : time_watcher, perl_watcher
192 : time_watcher (this, &timer::execute)
196 void execute (time_watcher &w)
199 start (at + interval);
201 invoke ("urxvt::timer", newSVtimer (this));
205 #define newSViow(iow) new_ref (iow->self, "urxvt::iow")
206 #define SvIOW(sv) (iow *)SvPTR (sv, "urxvt::iow")
208 struct iow : io_watcher, perl_watcher
211 : io_watcher (this, &iow::execute)
215 void execute (io_watcher &w, short revents)
217 invoke ("urxvt::iow", newSViow (this), revents);
221 /////////////////////////////////////////////////////////////////////////////
223 #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
233 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
241 void set (int x, int y, SV *str, SV *rend);
244 overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
245 : THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2)
253 text = new text_t *[h];
254 rend = new rend_t *[h];
256 for (int y = 0; y < h; y++)
258 text_t *tp = text[y] = new text_t[w];
259 rend_t *rp = rend[y] = new rend_t[w];
267 t0 = 0x2554, t1 = 0x2550, t2 = 0x2557;
269 t0 = 0x2551, t1 = 0x0020, t2 = 0x2551;
271 t0 = 0x255a, t1 = 0x2550, t2 = 0x255d;
276 for (int x = w - 2; x-- > 0; )
286 for (int x = w; x-- > 0; )
294 THIS->want_refresh = 1;
301 for (int y = h; y--; )
310 THIS->want_refresh = 1;
316 char key[33]; sprintf (key, "%32lx", (long)this);
318 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
319 hv_store (hv, key, 32, newSViv ((long)this), 0);
325 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0);
329 char key[33]; sprintf (key, "%32lx", (long)this);
331 HV *hv = (HV *)SvRV (*ovs);
332 hv_delete (hv, key, 32, G_DISCARD);
336 void overlay::swap ()
338 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
339 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
341 int ov_w = min (w, THIS->ncol - ov_x);
342 int ov_h = min (h, THIS->nrow - ov_y);
344 for (int y = ov_h; y--; )
346 text_t *t1 = text [y];
347 rend_t *r1 = rend [y];
349 text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x;
350 rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x;
352 for (int x = ov_w; x--; )
354 text_t t = *t1; *t1++ = *t2; *t2++ = t;
355 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t));
361 void overlay::set (int x, int y, SV *text, SV *rend)
366 if (!IN_RANGE_EXC (y, 0, h - border))
369 wchar_t *wtext = sv2wcs (text);
371 for (int col = min (wcslen (wtext), w - x - border); col--; )
372 this->text [y][x + col] = wtext [col];
378 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
379 croak ("rend must be arrayref");
381 AV *av = (AV *)SvRV (rend);
383 for (int col = min (av_len (av) + 1, w - x - border); col--; )
384 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
387 THIS->want_refresh = 1;
391 /////////////////////////////////////////////////////////////////////////////
393 struct rxvt_perl_interp rxvt_perl;
395 static PerlInterpreter *perl;
397 rxvt_perl_interp::rxvt_perl_interp ()
401 rxvt_perl_interp::~rxvt_perl_interp ()
405 perl_destruct (perl);
411 rxvt_perl_interp::init (bool tainted)
417 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
421 perl = perl_alloc ();
422 perl_construct (perl);
424 if (perl_parse (perl, xs_init, 2 + !!tainted, argv, (char **)NULL)
427 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
429 perl_destruct (perl);
437 rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
442 if (htype == HOOK_INIT) // first hook ever called
444 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
445 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
447 else if (!term->perl.self)
448 return false; // perl not initialized for this instance
449 else if (htype == HOOK_DESTROY)
453 else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
455 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
461 while (HE *he = hv_iternext (hv))
462 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
465 else if (!should_invoke [htype])
471 va_start (ap, htype);
478 XPUSHs (sv_2mortal (newSVterm (term)));
479 XPUSHs (sv_2mortal (newSViv (htype)));
482 data_type dt = (data_type)va_arg (ap, int);
487 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
491 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
495 XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0))));
500 char *str = va_arg (ap, char *);
501 int len = va_arg (ap, int);
503 XPUSHs (taint (sv_2mortal (newSVpvn (str, len))));
509 wchar_t *wstr = va_arg (ap, wchar_t *);
510 int wlen = va_arg (ap, int);
512 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen))));
518 XEvent *xe = va_arg (ap, XEvent *);
521 # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
522 # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
525 setiv (type, xe->type);
526 setiv (send_event, xe->xany.send_event);
527 setiv (serial, xe->xany.serial);
536 setiv (time, xe->xmotion.time);
537 setiv (x, xe->xmotion.x);
538 setiv (y, xe->xmotion.y);
539 setiv (row, xe->xmotion.y / term->fheight);
540 setiv (col, xe->xmotion.x / term->fwidth);
541 setiv (x_root, xe->xmotion.x_root);
542 setiv (y_root, xe->xmotion.y_root);
543 setiv (state, xe->xmotion.state);
551 setiv (keycode, xe->xkey.keycode);
556 setiv (button, xe->xbutton.button);
560 setiv (is_hint, xe->xmotion.is_hint);
564 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
573 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
579 count = SvTRUE (status);
587 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
589 if (htype == HOOK_DESTROY)
591 clearSVptr ((SV *)term->perl.self);
592 SvREFCNT_dec ((SV *)term->perl.self);
599 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
604 /////////////////////////////////////////////////////////////////////////////
606 MODULE = urxvt PACKAGE = urxvt
612 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
614 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
615 # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
616 # include "hookinc.h"
619 HV *option = get_hv ("urxvt::OPTION", 1);
620 # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
626 HV *stash = gv_stashpv ("urxvt", 1);
627 # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name));
628 export_const_iv (DEFAULT_RSTYLE);
629 export_const_iv (OVERLAY_RSTYLE);
630 export_const_iv (RS_Bold);
631 export_const_iv (RS_Italic);
632 export_const_iv (RS_Blink);
633 export_const_iv (RS_RVid);
634 export_const_iv (RS_Uline);
636 export_const_iv (CurrentTime);
637 export_const_iv (ShiftMask);
638 export_const_iv (LockMask);
639 export_const_iv (ControlMask);
640 export_const_iv (Mod1Mask);
641 export_const_iv (Mod2Mask);
642 export_const_iv (Mod3Mask);
643 export_const_iv (Mod4Mask);
644 export_const_iv (Mod5Mask);
645 export_const_iv (Button1Mask);
646 export_const_iv (Button2Mask);
647 export_const_iv (Button3Mask);
648 export_const_iv (Button4Mask);
649 export_const_iv (Button5Mask);
650 export_const_iv (AnyModifier);
657 stringvec *argv = new stringvec;
660 for (int i = 0; i < items ;i++)
661 argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
663 rxvt_term *term = new rxvt_term;
669 if (!term->init (argv->size (), argv->begin ()))
672 catch (const class rxvt_failure_exception &e)
675 croak ("exception caught while initializing new terminal instance");
678 RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
684 set_should_invoke (int htype, int value)
686 rxvt_perl.should_invoke [htype] = value;
689 warn (const char *msg)
691 rxvt_warn ("%s", msg);
694 fatal (const char *msg)
696 rxvt_fatal ("%s", msg);
706 GET_BASEFG (int rend)
708 RETVAL = GET_BASEFG (rend);
713 GET_BASEBG (int rend)
715 RETVAL = GET_BASEBG (rend);
720 SET_FGCOLOR (int rend, int new_color)
722 RETVAL = SET_FGCOLOR (rend, new_color);
727 SET_BGCOLOR (int rend, int new_color)
729 RETVAL = SET_BGCOLOR (rend, new_color);
734 GET_CUSTOM (int rend)
736 RETVAL = (rend && RS_customMask) >> RS_customShift;
741 SET_CUSTOM (int rend, int new_value)
744 if (!IN_RANGE_EXC (new_value, 0, RS_customCount))
745 croak ("custom value out of range, must be 0..%d", RS_customCount - 1);
747 RETVAL = (rend & ~RS_customMask)
748 | ((new_value << RS_customShift) & RS_customMask);
753 MODULE = urxvt PACKAGE = urxvt::term
756 rxvt_term::destroy ()
759 rxvt_term::grab_button (int button, U32 modifiers)
761 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
762 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
763 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
766 rxvt_term::grab (U32 eventtime, int sync = 0)
769 int mode = sync ? GrabModeSync : GrabModeAsync;
771 THIS->perl.grabtime = 0;
773 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
774 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
775 mode, mode, None, GRAB_CURSOR, eventtime))
776 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
777 THIS->perl.grabtime = eventtime;
779 XUngrabPointer (THIS->display->display, eventtime);
781 RETVAL = !!THIS->perl.grabtime;
787 rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime)
789 XAllowEvents (THIS->display->display, AsyncBoth, eventtime);
792 rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime)
794 XAllowEvents (THIS->display->display, SyncBoth, eventtime);
797 rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime)
799 XAllowEvents (THIS->display->display, ReplayPointer, eventtime);
800 XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime);
803 rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime)
805 THIS->perl.grabtime = 0;
806 XUngrabKeyboard (THIS->display->display, eventtime);
807 XUngrabPointer (THIS->display->display, eventtime);
810 rxvt_term::strwidth (SV *str)
813 wchar_t *wstr = sv2wcs (str);
815 rxvt_push_locale (THIS->locale);
816 RETVAL = wcswidth (wstr, wcslen (wstr));
825 rxvt_term::locale_encode (SV *str)
828 wchar_t *wstr = sv2wcs (str);
830 rxvt_push_locale (THIS->locale);
831 char *mbstr = rxvt_wcstombs (wstr);
836 RETVAL = taint_if (newSVpv (mbstr, 0), str);
843 rxvt_term::locale_decode (SV *octets)
847 char *data = SvPVbyte (octets, len);
849 rxvt_push_locale (THIS->locale);
850 wchar_t *wstr = rxvt_mbstowcs (data, len);
853 RETVAL = taint_if (wcs2sv (wstr), octets);
859 #define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
861 #define TERM_OFFSET_width TERM_OFFSET(width)
862 #define TERM_OFFSET_height TERM_OFFSET(height)
863 #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
864 #define TERM_OFFSET_fheight TERM_OFFSET(fheight)
865 #define TERM_OFFSET_fbase TERM_OFFSET(fbase)
866 #define TERM_OFFSET_nrow TERM_OFFSET(nrow)
867 #define TERM_OFFSET_ncol TERM_OFFSET(ncol)
868 #define TERM_OFFSET_focus TERM_OFFSET(focus)
869 #define TERM_OFFSET_mapped TERM_OFFSET(mapped)
870 #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
871 #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
872 #define TERM_OFFSET_nsaved TERM_OFFSET(nsaved)
877 width = TERM_OFFSET_width
878 height = TERM_OFFSET_height
879 fwidth = TERM_OFFSET_fwidth
880 fheight = TERM_OFFSET_fheight
881 fbase = TERM_OFFSET_fbase
882 nrow = TERM_OFFSET_nrow
883 ncol = TERM_OFFSET_ncol
884 focus = TERM_OFFSET_focus
885 mapped = TERM_OFFSET_mapped
886 saveLines = TERM_OFFSET_saveLines
887 total_rows = TERM_OFFSET_total_rows
888 nsaved = TERM_OFFSET_nsaved
890 RETVAL = *(int *)((char *)THIS + ix);
895 rxvt_term::ModLevel3Mask ()
903 case 0: RETVAL = THIS->ModLevel3Mask; break;
904 case 1: RETVAL = THIS->ModMetaMask; break;
905 case 2: RETVAL = THIS->ModNumLockMask; break;
913 RETVAL = (U32)THIS->parent [0];
920 RETVAL = (U32)THIS->vt;
925 rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
928 RETVAL = THIS->rstyle;
929 THIS->rstyle = new_rstyle;
935 rxvt_term::view_start (int newval = -1)
938 RETVAL = THIS->view_start;
942 THIS->view_start = min (newval, THIS->nsaved);
943 THIS->scr_changeview (RETVAL);
950 rxvt_term::want_refresh ()
952 THIS->want_refresh = 1;
955 rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
958 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
961 line_t &l = ROW(row_number);
963 if (GIMME_V != G_VOID)
965 wchar_t *wstr = new wchar_t [THIS->ncol];
967 for (int col = 0; col < THIS->ncol; col++)
968 wstr [col] = l.t [col];
970 XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol))));
977 wchar_t *wstr = sv2wcs (new_text);
979 int len = min (wcslen (wstr) - start_ofs, max_len);
981 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
984 croak ("new_text extends beyond horizontal margins");
987 for (int col = start_col; col < start_col + len; col++)
989 l.t [col] = wstr [start_ofs + col - start_col];
990 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
998 rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1001 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
1004 line_t &l = ROW(row_number);
1006 if (GIMME_V != G_VOID)
1010 av_extend (av, THIS->ncol - 1);
1011 for (int col = 0; col < THIS->ncol; col++)
1012 av_store (av, col, newSViv (l.r [col]));
1014 XPUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
1019 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1020 croak ("new_rend must be arrayref");
1022 AV *av = (AV *)SvRV (new_rend);
1023 int len = min (av_len (av) + 1 - start_ofs, max_len);
1025 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
1026 croak ("new_rend array extends beyond horizontal margins");
1028 for (int col = start_col; col < start_col + len; col++)
1030 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1032 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
1038 rxvt_term::ROW_l (int row_number, int new_length = -1)
1041 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
1044 line_t &l = ROW(row_number);
1047 if (new_length >= 0)
1054 rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
1057 if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow))
1060 line_t &l = ROW(row_number);
1061 RETVAL = l.is_longer ();
1063 if (new_is_longer >= 0)
1064 l.is_longer (new_is_longer);
1070 rxvt_term::special_encode (SV *string)
1073 wchar_t *wstr = sv2wcs (string);
1074 int wlen = wcslen (wstr);
1075 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1077 rxvt_push_locale (THIS->locale);
1080 for (wchar_t *s = wstr; *s; s++)
1081 if (wcwidth (*s) == 0)
1084 croak ("leading combining character unencodable");
1086 unicode_t n = rxvt_compose (r[-1], *s);
1088 n = rxvt_composite.compose (r[-1], *s);
1093 else if (*s >= 0x10000)
1094 *r++ = rxvt_composite.compose (*s);
1101 RETVAL = taint_if (wcs2sv (rstr, r - rstr), string);
1109 rxvt_term::special_decode (SV *text)
1112 wchar_t *wstr = sv2wcs (text);
1113 int wlen = wcslen (wstr);
1117 for (wchar_t *s = wstr; *s; s++)
1120 else if (IS_COMPOSE (*s))
1121 dlen += rxvt_composite.expand (*s, 0);
1125 wchar_t *rstr = new wchar_t [dlen];
1129 for (wchar_t *s = wstr; *s; s++)
1132 else if (IS_COMPOSE (*s))
1133 r += rxvt_composite.expand (*s, r);
1137 RETVAL = taint_if (wcs2sv (rstr, r - rstr), text);
1145 rxvt_term::_resource (char *name, int index, SV *newval = 0)
1148 struct resval { const char *name; int value; } rslist [] = {
1149 # define def(name) { # name, Rs_ ## name },
1150 # define reserve(name,count)
1156 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1160 croak ("no such resource '%s', requested", name);
1161 } while (strcmp (name, rs->name));
1165 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1166 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1168 if (GIMME_V != G_VOID)
1169 XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef);
1175 char *str = strdup (SvPVbyte_nolen (newval));
1176 THIS->rs [index] = str;
1177 THIS->allocated.push_back (str);
1180 THIS->rs [index] = 0;
1185 rxvt_term::option (U32 optval, int set = -1)
1188 RETVAL = THIS->options & optval;
1193 THIS->options |= optval;
1195 THIS->options &= ~optval;
1199 case Opt_skipBuiltinGlyphs:
1201 THIS->scr_remap_chars ();
1202 THIS->scr_touch (true);
1203 THIS->want_refresh = 1;
1206 case Opt_cursorUnderline:
1207 THIS->want_refresh = 1;
1210 # case Opt_scrollBar_floating:
1211 # case Opt_scrollBar_right:
1212 # THIS->resize_all_windows (THIS->width, THIS->height, 1);
1221 rxvt_term::cur (...)
1230 row_col_t &rc = ix == 0 ? THIS->screen.cur
1231 : ix == 1 ? THIS->selection.beg
1232 : ix == 2 ? THIS->selection.end
1233 : THIS->selection.mark;
1235 if (GIMME_V != G_VOID)
1238 PUSHs (sv_2mortal (newSViv (rc.row)));
1239 PUSHs (sv_2mortal (newSViv (rc.col)));
1244 rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1);
1245 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
1248 THIS->want_refresh = 1;
1253 rxvt_term::selection_grab (U32 eventtime)
1256 rxvt_term::selection (SV *newtext = 0)
1259 if (GIMME_V != G_VOID)
1260 XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))));
1264 free (THIS->selection.text);
1266 THIS->selection.text = sv2wcs (newtext);
1267 THIS->selection.len = wcslen (THIS->selection.text);
1272 rxvt_term::scr_add_lines (SV *string)
1275 wchar_t *wstr = sv2wcs (string);
1276 THIS->scr_add_lines (wstr, wcslen (wstr));
1281 rxvt_term::tt_write (SV *octets)
1284 char *str = SvPVbyte (octets, len);
1289 rxvt_term::cmd_parse (SV *octets)
1293 char *str = SvPVbyte (octets, len);
1295 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1296 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1298 THIS->cmdbuf_ptr = str;
1299 THIS->cmdbuf_endp = str + len;
1301 rxvt_push_locale (THIS->locale);
1305 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1306 THIS->cmdbuf_endp = old_cmdbuf_endp;
1310 rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
1313 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);
1314 RETVAL = newSVptr ((void *)o, "urxvt::overlay");
1315 o->self = (HV *)SvRV (RETVAL);
1320 MODULE = urxvt PACKAGE = urxvt::overlay
1323 overlay::set (int x, int y, SV *text, SV *rend = 0)
1334 MODULE = urxvt PACKAGE = urxvt::timer
1339 timer *w = new timer;
1341 RETVAL = newSVptr ((void *)w, "urxvt::timer");
1342 w->self = (HV *)SvRV (RETVAL);
1362 timer::interval (NV interval)
1364 THIS->interval = interval;
1370 timer::set (NV tstamp)
1378 timer::start (NV tstamp = THIS->at)
1380 THIS->start (tstamp);
1396 MODULE = urxvt PACKAGE = urxvt::iow
1402 RETVAL = newSVptr ((void *)w, "urxvt::iow");
1403 w->self = (HV *)SvRV (RETVAL);
1424 iow::events (short events)
1426 THIS->events = events;