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"
44 #ifdef HAVE_SCROLLBARS
45 # define GRAB_CURSOR THIS->leftptr_cursor
47 # define GRAB_CURSOR None
51 #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
53 #define ROW(n) THIS->row_buf [LINENO (n)]
55 #define ENABLE_PERL_FRILLS 1
57 /////////////////////////////////////////////////////////////////////////////
63 char *str = SvPVutf8 (sv, len);
64 return rxvt_utf8towcs (str, len);
68 wcs2sv (wchar_t *wstr, int len = -1)
70 char *str = rxvt_wcstoutf8 (wstr, len);
72 SV *sv = newSVpv (str, 0);
80 new_ref (HV *hv, const char *klass)
82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
87 newSVptr (void *ptr, const char *klass)
90 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
91 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
101 sv_unmagic (sv, PERL_MAGIC_ext);
105 SvPTR (SV *sv, const char *klass)
107 if (!sv_derived_from (sv, klass))
108 croak ("object of type %s expected", klass);
110 MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
113 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
115 return (long)mg->mg_ptr;
118 #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
119 #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
121 /////////////////////////////////////////////////////////////////////////////
143 void invoke (const char *type, SV *self, int arg = -1);
147 perl_watcher::invoke (const char *type, SV *self, int arg)
156 XPUSHs (sv_2mortal (self));
159 XPUSHs (sv_2mortal (newSViv (arg)));
162 call_sv (cbsv, G_VOID | G_EVAL | G_DISCARD);
170 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
173 #define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
174 #define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer")
176 struct timer : time_watcher, perl_watcher
181 : time_watcher (this, &timer::execute)
185 void execute (time_watcher &w)
188 start (at + interval);
190 invoke ("urxvt::timer", newSVtimer (this));
194 #define newSViow(iow) new_ref (iow->self, "urxvt::iow")
195 #define SvIOW(sv) (iow *)SvPTR (sv, "urxvt::iow")
197 struct iow : io_watcher, perl_watcher
200 : io_watcher (this, &iow::execute)
204 void execute (io_watcher &w, short revents)
206 invoke ("urxvt::iow", newSViow (this), revents);
210 /////////////////////////////////////////////////////////////////////////////
212 #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
222 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
230 void set (int x, int y, SV *str, SV *rend);
233 overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
234 : THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2)
242 text = new text_t *[h];
243 rend = new rend_t *[h];
245 for (int y = 0; y < h; y++)
247 text_t *tp = text[y] = new text_t[w];
248 rend_t *rp = rend[y] = new rend_t[w];
256 t0 = 0x2554, t1 = 0x2550, t2 = 0x2557;
258 t0 = 0x2551, t1 = 0x0020, t2 = 0x2551;
260 t0 = 0x255a, t1 = 0x2550, t2 = 0x255d;
265 for (int x = w - 2; x-- > 0; )
275 for (int x = w; x-- > 0; )
283 THIS->want_refresh = 1;
290 for (int y = h; y--; )
299 THIS->want_refresh = 1;
305 char key[33]; sprintf (key, "%32lx", (long)this);
307 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
308 hv_store (hv, key, 32, newSViv ((long)this), 0);
314 SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0);
318 char key[33]; sprintf (key, "%32lx", (long)this);
320 HV *hv = (HV *)SvRV (*ovs);
321 hv_delete (hv, key, 32, G_DISCARD);
325 void overlay::swap ()
327 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
328 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
330 int ov_w = min (w, THIS->ncol - ov_x);
331 int ov_h = min (h, THIS->nrow - ov_y);
333 for (int y = ov_h; y--; )
335 text_t *t1 = text [y];
336 rend_t *r1 = rend [y];
338 text_t *t2 = ROW(y + ov_y + THIS->view_start).t + ov_x;
339 rend_t *r2 = ROW(y + ov_y + THIS->view_start).r + ov_x;
341 for (int x = ov_w; x--; )
343 text_t t = *t1; *t1++ = *t2; *t2++ = t;
344 rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t));
350 void overlay::set (int x, int y, SV *text, SV *rend)
355 if (!IN_RANGE_EXC (y, 0, h - border))
358 wchar_t *wtext = sv2wcs (text);
360 for (int col = min (wcslen (wtext), w - x - border); col--; )
361 this->text [y][x + col] = wtext [col];
367 if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV)
368 croak ("rend must be arrayref");
370 AV *av = (AV *)SvRV (rend);
372 for (int col = min (av_len (av) + 1, w - x - border); col--; )
373 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
376 THIS->want_refresh = 1;
380 /////////////////////////////////////////////////////////////////////////////
382 struct rxvt_perl_interp rxvt_perl;
384 static PerlInterpreter *perl;
386 rxvt_perl_interp::~rxvt_perl_interp ()
390 perl_destruct (perl);
396 rxvt_perl_interp::init (rxvt_term *term)
400 rxvt_push_locale (""); // perl init destroys current locale
402 perl_environ = rxvt_environ;
403 swap (perl_environ, environ);
407 "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1",
410 perl = perl_alloc ();
411 perl_construct (perl);
413 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL)
416 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
418 perl_destruct (perl);
423 swap (perl_environ, environ);
430 // runs outside of perls ENV
431 term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
432 hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
437 ungrab (rxvt_term *THIS)
439 if (THIS->perl.grabtime)
441 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime);
442 XUngrabPointer (THIS->display->display, THIS->perl.grabtime);
443 THIS->perl.grabtime = 0;
448 swap_overlays (rxvt_term *term)
450 HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
456 while (HE *he = hv_iternext (hv))
457 ((overlay *)SvIV (hv_iterval (hv, he)))->swap ();
462 rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...)
464 if (!perl || !term->perl.self)
467 // pre-handling of some events
468 if (htype == HOOK_REFRESH_END)
469 swap_overlays (term);
471 swap (perl_environ, environ);
475 if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always
476 || term->perl.should_invoke [htype])
482 va_start (ap, htype);
489 XPUSHs (sv_2mortal (newSVterm (term)));
490 XPUSHs (sv_2mortal (newSViv (htype)));
493 data_type dt = (data_type)va_arg (ap, int);
498 XPUSHs (sv_2mortal (newSViv (va_arg (ap, int))));
502 XPUSHs (sv_2mortal (newSViv (va_arg (ap, long))));
506 XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0)));
511 char *str = va_arg (ap, char *);
512 int len = va_arg (ap, int);
514 XPUSHs (sv_2mortal (newSVpvn (str, len)));
520 wchar_t *wstr = va_arg (ap, wchar_t *);
521 int wlen = va_arg (ap, int);
523 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
529 XEvent *xe = va_arg (ap, XEvent *);
532 # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
533 # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
536 setiv (type, xe->type);
537 setiv (send_event, xe->xany.send_event);
538 setiv (serial, xe->xany.serial);
547 setiv (time, xe->xmotion.time);
548 setiv (x, xe->xmotion.x);
549 setiv (y, xe->xmotion.y);
550 setiv (row, xe->xmotion.y / term->fheight);
551 setiv (col, xe->xmotion.x / term->fwidth);
552 setiv (x_root, xe->xmotion.x_root);
553 setiv (y_root, xe->xmotion.y_root);
554 setiv (state, xe->xmotion.state);
562 setiv (keycode, xe->xkey.keycode);
567 setiv (button, xe->xbutton.button);
571 setiv (is_hint, xe->xmotion.is_hint);
575 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
583 rxvt_fatal ("FATAL: unable to pass data type %d\n", dt);
591 int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL);
597 count = SvTRUE (status);
606 rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV));
607 ungrab (term); // better lose the grab than the session
610 event_consumed = !!count;
614 swap (perl_environ, environ);
618 event_consumed = false;
620 // post-handling of some events
621 if (htype == HOOK_REFRESH_BEGIN)
622 swap_overlays (term);
623 else if (htype == HOOK_DESTROY)
625 clearSVptr ((SV *)term->perl.self);
626 SvREFCNT_dec ((SV *)term->perl.self);
629 swap (perl_environ, environ);
631 return event_consumed;
634 /////////////////////////////////////////////////////////////////////////////
636 MODULE = urxvt PACKAGE = urxvt
642 sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1));
643 sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1));
644 sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1));
645 sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1));
647 AV *hookname = get_av ("urxvt::HOOKNAME", 1);
648 # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0));
649 # include "hookinc.h"
652 HV *option = get_hv ("urxvt::OPTION", 1);
653 # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0);
659 HV *stash = gv_stashpv ("urxvt", 1);
663 } *civ, const_iv[] = {
664 # define const_iv(name) { # name, (IV)name }
665 const_iv (DEFAULT_RSTYLE),
666 const_iv (OVERLAY_RSTYLE),
668 const_iv (RS_Italic),
673 const_iv (CurrentTime),
674 const_iv (ShiftMask),
676 const_iv (ControlMask),
682 const_iv (Button1Mask),
683 const_iv (Button2Mask),
684 const_iv (Button3Mask),
685 const_iv (Button4Mask),
686 const_iv (Button5Mask),
687 const_iv (AnyModifier),
689 const_iv (EVENT_NONE),
690 const_iv (EVENT_READ),
691 const_iv (EVENT_WRITE),
693 const_iv (NoEventMask),
694 const_iv (KeyPressMask),
695 const_iv (KeyReleaseMask),
696 const_iv (ButtonPressMask),
697 const_iv (ButtonReleaseMask),
698 const_iv (EnterWindowMask),
699 const_iv (LeaveWindowMask),
700 const_iv (PointerMotionMask),
701 const_iv (PointerMotionHintMask),
702 const_iv (Button1MotionMask),
703 const_iv (Button2MotionMask),
704 const_iv (Button3MotionMask),
705 const_iv (Button4MotionMask),
706 const_iv (Button5MotionMask),
707 const_iv (ButtonMotionMask),
708 const_iv (KeymapStateMask),
709 const_iv (ExposureMask),
710 const_iv (VisibilityChangeMask),
711 const_iv (StructureNotifyMask),
712 const_iv (ResizeRedirectMask),
713 const_iv (SubstructureNotifyMask),
714 const_iv (SubstructureRedirectMask),
715 const_iv (FocusChangeMask),
716 const_iv (PropertyChangeMask),
717 const_iv (ColormapChangeMask),
718 const_iv (OwnerGrabButtonMask),
721 const_iv (KeyRelease),
722 const_iv (ButtonPress),
723 const_iv (ButtonRelease),
724 const_iv (MotionNotify),
725 const_iv (EnterNotify),
726 const_iv (LeaveNotify),
729 const_iv (KeymapNotify),
731 const_iv (GraphicsExpose),
733 const_iv (VisibilityNotify),
734 const_iv (CreateNotify),
735 const_iv (DestroyNotify),
736 const_iv (UnmapNotify),
737 const_iv (MapNotify),
738 const_iv (MapRequest),
739 const_iv (ReparentNotify),
740 const_iv (ConfigureNotify),
741 const_iv (ConfigureRequest),
742 const_iv (GravityNotify),
743 const_iv (ResizeRequest),
744 const_iv (CirculateNotify),
745 const_iv (CirculateRequest),
746 const_iv (PropertyNotify),
747 const_iv (SelectionClear),
748 const_iv (SelectionRequest),
749 const_iv (SelectionNotify),
750 const_iv (ColormapNotify),
751 const_iv (ClientMessage),
752 const_iv (MappingNotify),
755 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]);
757 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
761 warn (const char *msg)
763 rxvt_warn ("%s", msg);
766 fatal (const char *msg)
768 rxvt_fatal ("%s", msg);
781 GET_BASEFG (int rend)
783 RETVAL = GET_BASEFG (rend);
788 GET_BASEBG (int rend)
790 RETVAL = GET_BASEBG (rend);
795 SET_FGCOLOR (int rend, int new_color)
797 RETVAL = SET_FGCOLOR (rend, new_color);
802 SET_BGCOLOR (int rend, int new_color)
804 RETVAL = SET_BGCOLOR (rend, new_color);
809 GET_CUSTOM (int rend)
811 RETVAL = (rend && RS_customMask) >> RS_customShift;
816 SET_CUSTOM (int rend, int new_value)
819 if (!IN_RANGE_EXC (new_value, 0, RS_customCount))
820 croak ("custom value out of range, must be 0..%d", RS_customCount - 1);
822 RETVAL = (rend & ~RS_customMask)
823 | ((new_value << RS_customShift) & RS_customMask);
828 MODULE = urxvt PACKAGE = urxvt::term
834 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
835 croak ("first argument to urxvt::term->_new must be arrayref");
837 rxvt_term *term = new rxvt_term;
839 term->argv = new stringvec;
840 term->envv = new stringvec;
842 for (int i = 1; i < items; i++)
843 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i))));
845 AV *envv = (AV *)SvRV (ST (0));
846 for (int i = av_len (envv) + 1; i--; )
847 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1))));
849 term->envv->push_back (0);
855 success = term->init (term->argv->size (), term->argv->begin ());
857 catch (const class rxvt_failure_exception &e)
865 croak ("error while initializing new terminal instance");
868 RETVAL = term && term->perl.self
869 ? newSVterm (term) : &PL_sv_undef;
875 rxvt_term::destroy ()
877 #if ENABLE_PERL_FRILLS
880 rxvt_term::XListProperties (U32 window)
884 Atom *props = XListProperties (THIS->display->display, (Window)window, &count);
888 PUSHs (newSVuv ((U32)props [count]));
894 rxvt_term::XGetWindowProperty (U32 window, U32 property)
899 unsigned long nitems;
900 unsigned long bytes_after;
902 XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property,
903 0, 1<<30, 0, AnyPropertyType,
904 &type, &format, &nitems, &bytes_after, &prop);
908 PUSHs (newSVuv ((U32)type));
909 PUSHs (newSViv (format));
910 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
916 rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data)
920 char *data_ = SvPVbyte (data, len);
922 XChangeProperty (THIS->display->display, (Window)window, (Atom)property,
923 type, format, PropModeReplace,
924 (unsigned char *)data, len * 8 / format);
928 rxvt_term::XDeleteProperty (U32 window, U32 property)
930 XDeleteProperty (THIS->display->display, (Window)window, (Atom)property);
933 rxvt_term::DefaultRootWindow ()
935 RETVAL = (U32)THIS->display->root;
940 rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height)
942 RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent,
943 x, y, width, height, 0,
944 THIS->pix_colors_focused[Color_border],
945 THIS->pix_colors_focused[Color_border]);
950 rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0)
952 XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y);
955 rxvt_term::XMapWindow (U32 window)
957 XMapWindow (THIS->display->display, (Window)window);
960 rxvt_term::XUnmapWindow (U32 window)
962 XUnmapWindow (THIS->display->display, (Window)window);
967 rxvt_term::set_should_invoke (int htype, int inc)
969 THIS->perl.should_invoke [htype] += inc;
972 rxvt_term::grab_button (int button, U32 modifiers)
974 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
975 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
976 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
979 rxvt_term::grab (U32 eventtime, int sync = 0)
982 int mode = sync ? GrabModeSync : GrabModeAsync;
984 THIS->perl.grabtime = 0;
986 if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
987 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
988 mode, mode, None, GRAB_CURSOR, eventtime))
989 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
990 THIS->perl.grabtime = eventtime;
992 XUngrabPointer (THIS->display->display, eventtime);
994 RETVAL = !!THIS->perl.grabtime;
1000 rxvt_term::allow_events_async ()
1002 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime);
1005 rxvt_term::allow_events_sync ()
1007 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime);
1010 rxvt_term::allow_events_replay ()
1012 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime);
1013 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime);
1016 rxvt_term::ungrab ()
1021 rxvt_term::strwidth (SV *str)
1024 wchar_t *wstr = sv2wcs (str);
1026 rxvt_push_locale (THIS->locale);
1027 RETVAL = wcswidth (wstr, wcslen (wstr));
1036 rxvt_term::locale_encode (SV *str)
1039 wchar_t *wstr = sv2wcs (str);
1041 rxvt_push_locale (THIS->locale);
1042 char *mbstr = rxvt_wcstombs (wstr);
1047 RETVAL = newSVpv (mbstr, 0);
1054 rxvt_term::locale_decode (SV *octets)
1058 char *data = SvPVbyte (octets, len);
1060 rxvt_push_locale (THIS->locale);
1061 wchar_t *wstr = rxvt_mbstowcs (data, len);
1064 RETVAL = wcs2sv (wstr);
1070 #define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
1072 #define TERM_OFFSET_width TERM_OFFSET(width)
1073 #define TERM_OFFSET_height TERM_OFFSET(height)
1074 #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
1075 #define TERM_OFFSET_fheight TERM_OFFSET(fheight)
1076 #define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1077 #define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1078 #define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1079 #define TERM_OFFSET_focus TERM_OFFSET(focus)
1080 #define TERM_OFFSET_mapped TERM_OFFSET(mapped)
1081 #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1082 #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1083 #define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1088 width = TERM_OFFSET_width
1089 height = TERM_OFFSET_height
1090 fwidth = TERM_OFFSET_fwidth
1091 fheight = TERM_OFFSET_fheight
1092 fbase = TERM_OFFSET_fbase
1093 nrow = TERM_OFFSET_nrow
1094 ncol = TERM_OFFSET_ncol
1095 focus = TERM_OFFSET_focus
1096 mapped = TERM_OFFSET_mapped
1097 saveLines = TERM_OFFSET_saveLines
1098 total_rows = TERM_OFFSET_total_rows
1099 top_row = TERM_OFFSET_top_row
1101 RETVAL = *(int *)((char *)THIS + ix);
1106 rxvt_term::ModLevel3Mask ()
1114 case 0: RETVAL = THIS->ModLevel3Mask; break;
1115 case 1: RETVAL = THIS->ModMetaMask; break;
1116 case 2: RETVAL = THIS->ModNumLockMask; break;
1122 rxvt_term::display_id ()
1129 case 0: RETVAL = THIS->display->id; break;
1130 case 1: RETVAL = THIS->locale; break;
1143 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i)
1145 av_push (av, newSVpv (*i, 0));
1147 RETVAL = newRV_noinc ((SV *)av);
1150 RETVAL = &PL_sv_undef;
1156 rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1158 RETVAL = THIS->pty_ev.events;
1159 if (events != EVENT_UNDEF)
1160 THIS->pty_ev.set (events);
1165 rxvt_term::parent ()
1167 RETVAL = (U32)THIS->parent [0];
1174 RETVAL = (U32)THIS->vt;
1179 rxvt_term::vt_emask_add (U32 emask)
1181 THIS->vt_emask_perl |= emask;
1182 THIS->vt_select_input ();
1185 rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle)
1187 RETVAL = THIS->rstyle;
1188 THIS->rstyle = new_rstyle;
1193 rxvt_term::view_start (int newval = 1)
1197 RETVAL = THIS->view_start;
1200 THIS->scr_changeview (max (newval, THIS->top_row));
1206 rxvt_term::want_refresh ()
1208 THIS->want_refresh = 1;
1211 rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1214 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1217 line_t &l = ROW(row_number);
1219 if (GIMME_V != G_VOID)
1221 wchar_t *wstr = new wchar_t [THIS->ncol];
1223 for (int col = 0; col < THIS->ncol; col++)
1224 wstr [col] = l.t [col];
1226 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1233 wchar_t *wstr = sv2wcs (new_text);
1235 int len = min (wcslen (wstr) - start_ofs, max_len);
1237 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
1240 croak ("new_text extends beyond horizontal margins");
1243 for (int col = start_col; col < start_col + len; col++)
1245 l.t [col] = wstr [start_ofs + col - start_col];
1246 l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col]));
1254 rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1257 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1260 line_t &l = ROW(row_number);
1262 if (GIMME_V != G_VOID)
1266 av_extend (av, THIS->ncol - 1);
1267 for (int col = 0; col < THIS->ncol; col++)
1268 av_store (av, col, newSViv (l.r [col]));
1270 XPUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
1275 if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV)
1276 croak ("new_rend must be arrayref");
1278 AV *av = (AV *)SvRV (new_rend);
1279 int len = min (av_len (av) + 1 - start_ofs, max_len);
1281 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len))
1282 croak ("new_rend array extends beyond horizontal margins");
1284 for (int col = start_col; col < start_col + len; col++)
1286 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1288 l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col]));
1294 rxvt_term::ROW_l (int row_number, int new_length = -1)
1297 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1300 line_t &l = ROW(row_number);
1303 if (new_length >= 0)
1310 rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1)
1313 if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow))
1316 line_t &l = ROW(row_number);
1317 RETVAL = l.is_longer ();
1319 if (new_is_longer >= 0)
1320 l.is_longer (new_is_longer);
1326 rxvt_term::special_encode (SV *string)
1329 wchar_t *wstr = sv2wcs (string);
1330 int wlen = wcslen (wstr);
1331 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer
1333 rxvt_push_locale (THIS->locale);
1336 for (wchar_t *s = wstr; *s; s++)
1337 if (wcwidth (*s) == 0)
1340 croak ("leading combining character unencodable");
1342 unicode_t n = rxvt_compose (r[-1], *s);
1344 n = rxvt_composite.compose (r[-1], *s);
1349 else if (*s >= 0x10000)
1350 *r++ = rxvt_composite.compose (*s);
1357 RETVAL = wcs2sv (rstr, r - rstr);
1365 rxvt_term::special_decode (SV *text)
1368 wchar_t *wstr = sv2wcs (text);
1369 int wlen = wcslen (wstr);
1373 for (wchar_t *s = wstr; *s; s++)
1376 else if (IS_COMPOSE (*s))
1377 dlen += rxvt_composite.expand (*s, 0);
1381 wchar_t *rstr = new wchar_t [dlen];
1385 for (wchar_t *s = wstr; *s; s++)
1388 else if (IS_COMPOSE (*s))
1389 r += rxvt_composite.expand (*s, r);
1393 RETVAL = wcs2sv (rstr, r - rstr);
1401 rxvt_term::_resource (char *name, int index, SV *newval = 0)
1404 struct resval { const char *name; int value; } rslist [] = {
1405 # define def(name) { # name, Rs_ ## name },
1406 # define reserve(name,count)
1412 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1416 croak ("no such resource '%s', requested", name);
1417 } while (strcmp (name, rs->name));
1421 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1422 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1424 if (GIMME_V != G_VOID)
1425 XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef);
1431 char *str = strdup (SvPVbyte_nolen (newval));
1432 THIS->rs [index] = str;
1433 THIS->allocated.push_back (str);
1436 THIS->rs [index] = 0;
1441 rxvt_term::x_resource (const char *name)
1444 rxvt_term::option (U32 optval, int set = -1)
1447 RETVAL = THIS->options & optval;
1452 THIS->options |= optval;
1454 THIS->options &= ~optval;
1458 case Opt_skipBuiltinGlyphs:
1460 THIS->scr_remap_chars ();
1461 THIS->scr_touch (true);
1462 THIS->want_refresh = 1;
1465 case Opt_cursorUnderline:
1466 THIS->want_refresh = 1;
1469 # case Opt_scrollBar_floating:
1470 # case Opt_scrollBar_right:
1471 # THIS->resize_all_windows (THIS->width, THIS->height, 1);
1480 rxvt_term::parse_keysym (char *keysym, char *str)
1482 RETVAL = 0 < THIS->parse_keysym (keysym, str);
1483 THIS->keyboard->register_done ();
1488 rxvt_term::screen_cur (...)
1497 row_col_t &rc = ix == 0 ? THIS->screen.cur
1498 : ix == 1 ? THIS->selection.beg
1499 : ix == 2 ? THIS->selection.end
1500 : THIS->selection.mark;
1502 if (GIMME_V != G_VOID)
1505 PUSHs (sv_2mortal (newSViv (rc.row)));
1506 PUSHs (sv_2mortal (newSViv (rc.col)));
1511 rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1);
1512 rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1);
1515 THIS->want_refresh = 1;
1520 rxvt_term::cur_charset ()
1522 RETVAL = THIS->charsets [THIS->screen.charset];
1527 #rxvt_term::selection_clear ()
1530 rxvt_term::selection_make (U32 eventtime, bool rect = false)
1532 THIS->selection.op = SELECTION_CONT;
1533 THIS->selection.rect = rect;
1534 THIS->selection_make (eventtime);
1537 rxvt_term::selection_grab (U32 eventtime)
1540 rxvt_term::selection (SV *newtext = 0)
1543 if (GIMME_V != G_VOID)
1544 XPUSHs (THIS->selection.text
1545 ? sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))
1550 free (THIS->selection.text);
1552 THIS->selection.text = sv2wcs (newtext);
1553 THIS->selection.len = wcslen (THIS->selection.text);
1558 rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle1 = RS_RVid, U32 rstyle2 = RS_RVid | RS_Uline)
1561 rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1564 rxvt_term::scr_bell ()
1567 rxvt_term::scr_add_lines (SV *string)
1570 wchar_t *wstr = sv2wcs (string);
1571 THIS->scr_add_lines (wstr, wcslen (wstr));
1576 rxvt_term::tt_write (SV *octets)
1579 char *str = SvPVbyte (octets, len);
1584 rxvt_term::cmd_parse (SV *octets)
1588 char *str = SvPVbyte (octets, len);
1590 char *old_cmdbuf_ptr = THIS->cmdbuf_ptr;
1591 char *old_cmdbuf_endp = THIS->cmdbuf_endp;
1593 THIS->cmdbuf_ptr = str;
1594 THIS->cmdbuf_endp = str + len;
1596 rxvt_push_locale (THIS->locale);
1600 THIS->cmdbuf_ptr = old_cmdbuf_ptr;
1601 THIS->cmdbuf_endp = old_cmdbuf_endp;
1605 rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2)
1608 overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);
1609 RETVAL = newSVptr ((void *)o, "urxvt::overlay");
1610 o->self = (HV *)SvRV (RETVAL);
1615 MODULE = urxvt PACKAGE = urxvt::overlay
1618 overlay::set (int x, int y, SV *text, SV *rend = 0)
1629 MODULE = urxvt PACKAGE = urxvt::timer
1634 timer *w = new timer;
1636 RETVAL = newSVptr ((void *)w, "urxvt::timer");
1637 w->self = (HV *)SvRV (RETVAL);
1657 timer::interval (NV interval)
1659 THIS->interval = interval;
1665 timer::set (NV tstamp)
1673 timer::start (NV tstamp = THIS->at)
1675 THIS->start (tstamp);
1691 MODULE = urxvt PACKAGE = urxvt::iow
1697 RETVAL = newSVptr ((void *)w, "urxvt::iow");
1698 w->self = (HV *)SvRV (RETVAL);
1719 iow::events (short events)
1721 THIS->events = events;