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.78 by root, Thu Jan 19 20:30:36 2006 UTC vs.
Revision 1.111 by root, Thu Dec 14 17:33:53 2006 UTC

50#undef LINENO 50#undef LINENO
51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
52#undef ROW 52#undef ROW
53#define ROW(n) THIS->row_buf [LINENO (n)] 53#define ROW(n) THIS->row_buf [LINENO (n)]
54 54
55#define ENABLE_PERL_FRILLS 1
56
57///////////////////////////////////////////////////////////////////////////// 55/////////////////////////////////////////////////////////////////////////////
58 56
59static wchar_t * 57static wchar_t *
60sv2wcs (SV *sv) 58sv2wcs (SV *sv)
61{ 59{
80new_ref (HV *hv, const char *klass) 78new_ref (HV *hv, const char *klass)
81{ 79{
82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); 80 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
83} 81}
84 82
85//TODO: use magic
86static SV * 83static SV *
87newSVptr (void *ptr, const char *klass) 84newSVptr (void *ptr, const char *klass)
88{ 85{
89 HV *hv = newHV (); 86 HV *hv = newHV ();
90 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 87 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
113 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 110 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
114 111
115 return (long)mg->mg_ptr; 112 return (long)mg->mg_ptr;
116} 113}
117 114
118#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) 115#define newSVterm(term) SvREFCNT_inc ((SV *)(term)->perl.self)
119#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 116#define SvTERM(sv) (rxvt_term *)SvPTR ((sv), "urxvt::term")
120 117
121///////////////////////////////////////////////////////////////////////////// 118/////////////////////////////////////////////////////////////////////////////
122 119
123struct perl_watcher
124{
125 SV *cbsv;
126 HV *self;
127
128 perl_watcher ()
129 : cbsv (newSV (0))
130 {
131 }
132
133 ~perl_watcher ()
134 {
135 SvREFCNT_dec (cbsv);
136 }
137
138 void cb (SV *cb)
139 {
140 sv_setsv (cbsv, cb);
141 }
142
143 void invoke (const char *type, SV *self, int arg = -1);
144};
145
146void
147perl_watcher::invoke (const char *type, SV *self, int arg)
148{
149 dSP;
150
151 ENTER;
152 SAVETMPS;
153
154 PUSHMARK (SP);
155
156 XPUSHs (sv_2mortal (self));
157
158 if (arg >= 0)
159 XPUSHs (sv_2mortal (newSViv (arg)));
160
161 PUTBACK;
162 call_sv (cbsv, G_VOID | G_EVAL | G_DISCARD);
163 SPAGAIN;
164
165 PUTBACK;
166 FREETMPS;
167 LEAVE;
168
169 if (SvTRUE (ERRSV))
170 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
171}
172
173#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
174#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer")
175
176struct timer : time_watcher, perl_watcher
177{
178 tstamp interval;
179
180 timer ()
181 : time_watcher (this, &timer::execute)
182 {
183 }
184
185 void execute (time_watcher &w)
186 {
187 if (interval)
188 start (at + interval);
189
190 invoke ("urxvt::timer", newSVtimer (this));
191 }
192};
193
194#define newSViow(iow) new_ref (iow->self, "urxvt::iow")
195#define SvIOW(sv) (iow *)SvPTR (sv, "urxvt::iow")
196
197struct iow : io_watcher, perl_watcher
198{
199 iow ()
200 : io_watcher (this, &iow::execute)
201 {
202 }
203
204 void execute (io_watcher &w, short revents)
205 {
206 invoke ("urxvt::iow", newSViow (this), revents);
207 }
208};
209
210/////////////////////////////////////////////////////////////////////////////
211
212#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 120#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
213 121
214struct overlay { 122class overlay {
215 HV *self;
216 bool visible;
217 rxvt_term *THIS; 123 rxvt_term *THIS;
124 AV *overlay_av;
218 int x, y, w, h; 125 int x, y, w, h;
219 int border; 126 int border;
220 text_t **text; 127 text_t **text;
221 rend_t **rend; 128 rend_t **rend;
222 129
130public:
131 HV *self;
132
223 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); 133 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
224 ~overlay (); 134 ~overlay ();
225 135
226 void show (); 136 void show ();
227 void hide (); 137 void hide ();
230 140
231 void set (int x, int y, SV *str, SV *rend); 141 void set (int x, int y, SV *str, SV *rend);
232}; 142};
233 143
234overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 144overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
235: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), visible(false) 145: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0)
236{ 146{
147 if (w < 0) w = 0;
148 if (h < 0) h = 0;
149
237 if (border == 2) 150 if (border == 2)
238 { 151 {
239 w += 2; 152 w += 2;
240 h += 2; 153 h += 2;
241 } 154 }
279 *rp++ = r; 192 *rp++ = r;
280 } 193 }
281 } 194 }
282 195
283 show (); 196 show ();
284 THIS->want_refresh = 1;
285} 197}
286 198
287overlay::~overlay () 199overlay::~overlay ()
288{ 200{
289 hide (); 201 hide ();
294 delete [] rend[y]; 206 delete [] rend[y];
295 } 207 }
296 208
297 delete [] text; 209 delete [] text;
298 delete [] rend; 210 delete [] rend;
211}
212
213void
214overlay::show ()
215{
216 if (overlay_av)
217 return;
218
219 overlay_av = (AV *)SvREFCNT_inc (SvRV (
220 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
221 ));
222 av_push (overlay_av, newSViv ((long)this));
299 223
300 THIS->want_refresh = 1; 224 THIS->want_refresh = 1;
301} 225}
302 226
303void 227void
304overlay::show () 228overlay::hide ()
305{ 229{
306 if (visible) 230 if (!overlay_av)
307 return; 231 return;
308 232
309 visible = true;
310
311 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
312 av_push (av, newSViv ((long)this));
313}
314
315void
316overlay::hide ()
317{
318 if (!visible)
319 return;
320
321 visible = false;
322
323 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
324
325 int i; 233 int i;
326 234
327 for (i = AvFILL (av); i >= 0; i--) 235 for (i = AvFILL (overlay_av); i >= 0; i--)
328 if (SvIV (*av_fetch (av, i, 1)) == (long)this) 236 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this)
329 {
330 av_delete (av, i, G_DISCARD);
331 break; 237 break;
332 }
333 238
334 for (; i < AvFILL (av); i++) 239 for (; i < AvFILL (overlay_av); i++)
335 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0))); 240 av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0)));
336 241
337 av_pop (av); 242 av_pop (overlay_av);
243
244 SvREFCNT_dec (overlay_av);
245 overlay_av = 0;
246
247 THIS->want_refresh = 1;
338} 248}
339 249
340void overlay::swap () 250void overlay::swap ()
341{ 251{
342 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 252 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
389 } 299 }
390 300
391 THIS->want_refresh = 1; 301 THIS->want_refresh = 1;
392} 302}
393 303
304/////////////////////////////////////////////////////////////////////////////
305
306#define IOM_CLASS "urxvt"
307#include <iom_perl.h>
394 308
395///////////////////////////////////////////////////////////////////////////// 309/////////////////////////////////////////////////////////////////////////////
396 310
397struct rxvt_perl_interp rxvt_perl; 311struct rxvt_perl_interp rxvt_perl;
398 312
457static void 371static void
458ungrab (rxvt_term *THIS) 372ungrab (rxvt_term *THIS)
459{ 373{
460 if (THIS->perl.grabtime) 374 if (THIS->perl.grabtime)
461 { 375 {
462 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); 376 XUngrabKeyboard (THIS->dpy, THIS->perl.grabtime);
463 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 377 XUngrabPointer (THIS->dpy, THIS->perl.grabtime);
464 THIS->perl.grabtime = 0; 378 THIS->perl.grabtime = 0;
465 } 379 }
466} 380}
467 381
468bool 382bool
519 break; 433 break;
520 434
521 case DT_STR_LEN: 435 case DT_STR_LEN:
522 { 436 {
523 char *str = va_arg (ap, char *); 437 char *str = va_arg (ap, char *);
524 int len = va_arg (ap, int); 438 int len = va_arg (ap, int);
525 439
526 XPUSHs (sv_2mortal (newSVpvn (str, len))); 440 XPUSHs (sv_2mortal (newSVpvn (str, len)));
527 } 441 }
528 break; 442 break;
529 443
530 case DT_WCS_LEN: 444 case DT_WCS_LEN:
531 { 445 {
532 wchar_t *wstr = va_arg (ap, wchar_t *); 446 wchar_t *wstr = va_arg (ap, wchar_t *);
533 int wlen = va_arg (ap, int); 447 int wlen = va_arg (ap, int);
534 448
535 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 449 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
450 }
451 break;
452
453 case DT_LCS_LEN:
454 {
455 long *lstr = va_arg (ap, long *);
456 int llen = va_arg (ap, int);
457
458 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long))));
536 } 459 }
537 break; 460 break;
538 461
539 case DT_XEVENT: 462 case DT_XEVENT:
540 { 463 {
541 XEvent *xe = va_arg (ap, XEvent *); 464 XEvent *xe = va_arg (ap, XEvent *);
542 HV *hv = newHV (); 465 HV *hv = newHV ();
543 466
544# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 467# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
545# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) 468# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
546# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) 469# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
547# undef set 470# undef set
548 471
549 setiv (type, xe->type); 472 setiv (type, xe->type);
550 setiv (send_event, xe->xany.send_event); 473 setiv (send_event, xe->xany.send_event);
551 setiv (serial, xe->xany.serial); 474 setiv (serial, xe->xany.serial);
552 475
561 setuv (root, xe->xmotion.root); 484 setuv (root, xe->xmotion.root);
562 setuv (subwindow, xe->xmotion.subwindow); 485 setuv (subwindow, xe->xmotion.subwindow);
563 setuv (time, xe->xmotion.time); 486 setuv (time, xe->xmotion.time);
564 setiv (x, xe->xmotion.x); 487 setiv (x, xe->xmotion.x);
565 setiv (y, xe->xmotion.y); 488 setiv (y, xe->xmotion.y);
566 setiv (row, xe->xmotion.y / term->fheight); 489 setiv (row, xe->xmotion.y / term->fheight + term->view_start);
567 setiv (col, xe->xmotion.x / term->fwidth); 490 setiv (col, xe->xmotion.x / term->fwidth);
568 setiv (x_root, xe->xmotion.x_root); 491 setiv (x_root, xe->xmotion.x_root);
569 setiv (y_root, xe->xmotion.y_root); 492 setiv (y_root, xe->xmotion.y_root);
570 setuv (state, xe->xmotion.state); 493 setuv (state, xe->xmotion.state);
571 494
603 setiv (height, xe->xconfigure.height); 526 setiv (height, xe->xconfigure.height);
604 setuv (above, xe->xconfigure.above); 527 setuv (above, xe->xconfigure.above);
605 break; 528 break;
606 } 529 }
607 530
531 break;
532
533 case PropertyNotify:
534 setuv (window, xe->xproperty.window);
535 setuv (atom, xe->xproperty.atom);
536 setuv (time, xe->xproperty.time);
537 setiv (state, xe->xproperty.state);
538 break;
539
540 case ClientMessage:
541 setuv (window, xe->xclient.window);
542 setuv (message_type, xe->xclient.message_type);
543 setuv (format, xe->xclient.format);
544 setuv (l0, xe->xclient.data.l[0]);
545 setuv (l1, xe->xclient.data.l[1]);
546 setuv (l2, xe->xclient.data.l[2]);
547 setuv (l3, xe->xclient.data.l[3]);
548 setuv (l4, xe->xclient.data.l[4]);
608 break; 549 break;
609 } 550 }
610 551
611 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); 552 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
612 } 553 }
663 } 604 }
664 else if (htype == HOOK_DESTROY) 605 else if (htype == HOOK_DESTROY)
665 { 606 {
666 clearSVptr ((SV *)term->perl.self); 607 clearSVptr ((SV *)term->perl.self);
667 SvREFCNT_dec ((SV *)term->perl.self); 608 SvREFCNT_dec ((SV *)term->perl.self);
609
610 // don't allow further calls
611 term->perl.self = 0;
668 } 612 }
669 613
670 swap (perl_environ, environ); 614 swap (perl_environ, environ);
671 615
672 return event_consumed; 616 return event_consumed;
696# include "optinc.h" 640# include "optinc.h"
697# undef nodef 641# undef nodef
698# undef def 642# undef def
699 643
700 HV *stash = gv_stashpv ("urxvt", 1); 644 HV *stash = gv_stashpv ("urxvt", 1);
701 struct { 645 static const struct {
702 const char *name; 646 const char *name;
703 IV iv; 647 IV iv;
704 } *civ, const_iv[] = { 648 } *civ, const_iv[] = {
705# define const_iv(name) { # name, (IV)name } 649# define const_iv(name) { # name, (IV)name }
706 const_iv (DEFAULT_RSTYLE), 650 const_iv (DEFAULT_RSTYLE),
725 const_iv (Button3Mask), 669 const_iv (Button3Mask),
726 const_iv (Button4Mask), 670 const_iv (Button4Mask),
727 const_iv (Button5Mask), 671 const_iv (Button5Mask),
728 const_iv (AnyModifier), 672 const_iv (AnyModifier),
729 673
730 const_iv (EVENT_NONE), 674 const_iv (NoSymbol),
731 const_iv (EVENT_READ), 675 const_iv (GrabModeSync),
732 const_iv (EVENT_WRITE), 676 const_iv (GrabModeAsync),
733 677
734 const_iv (NoEventMask), 678 const_iv (NoEventMask),
735 const_iv (KeyPressMask), 679 const_iv (KeyPressMask),
736 const_iv (KeyReleaseMask), 680 const_iv (KeyReleaseMask),
737 const_iv (ButtonPressMask), 681 const_iv (ButtonPressMask),
789 const_iv (SelectionRequest), 733 const_iv (SelectionRequest),
790 const_iv (SelectionNotify), 734 const_iv (SelectionNotify),
791 const_iv (ColormapNotify), 735 const_iv (ColormapNotify),
792 const_iv (ClientMessage), 736 const_iv (ClientMessage),
793 const_iv (MappingNotify), 737 const_iv (MappingNotify),
738# if ENABLE_XIM_ONTHESPOT
739 const_iv (XIMReverse),
740 const_iv (XIMUnderline),
741 const_iv (XIMHighlight),
742 const_iv (XIMPrimary),
743 const_iv (XIMSecondary),
744 const_iv (XIMTertiary),
745 const_iv (XIMVisibleToForward),
746 const_iv (XIMVisibleToBackword),
747 const_iv (XIMVisibleToCenter),
748# if 0
749 const_iv (XIMForwardChar),
750 const_iv (XIMBackwardChar),
751 const_iv (XIMForwardWord),
752 const_iv (XIMBackwardWord),
753 const_iv (XIMCaretUp),
754 const_iv (XIMCaretDown),
755 const_iv (XIMNextLine),
756 const_iv (XIMPreviousLine),
757 const_iv (XIMLineStart),
758 const_iv (XIMLineEnd),
759 const_iv (XIMAbsolutePosition),
760 const_iv (XIMDontChange),
761# endif
762# endif
794 }; 763 };
795 764
796 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); 765 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
797 civ-- > const_iv; )
798 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 766 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
799} 767}
800 768
801void 769void
802warn (const char *msg) 770warn (const char *msg)
833 RETVAL 801 RETVAL
834 802
835int 803int
836SET_FGCOLOR (int rend, int new_color) 804SET_FGCOLOR (int rend, int new_color)
837 CODE: 805 CODE:
838 RETVAL = SET_FGCOLOR (rend, new_color); 806 RETVAL = SET_FGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
839 OUTPUT: 807 OUTPUT:
840 RETVAL 808 RETVAL
841 809
842int 810int
843SET_BGCOLOR (int rend, int new_color) 811SET_BGCOLOR (int rend, int new_color)
844 CODE: 812 CODE:
845 RETVAL = SET_BGCOLOR (rend, new_color); 813 RETVAL = SET_BGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
846 OUTPUT: 814 OUTPUT:
847 RETVAL 815 RETVAL
848 816
849int 817int
850GET_CUSTOM (int rend) 818GET_CUSTOM (int rend)
851 CODE: 819 CODE:
852 RETVAL = (rend && RS_customMask) >> RS_customShift; 820 RETVAL = (rend & RS_customMask) >> RS_customShift;
853 OUTPUT: 821 OUTPUT:
854 RETVAL 822 RETVAL
855 823
856int 824int
857SET_CUSTOM (int rend, int new_value) 825SET_CUSTOM (int rend, int new_value)
864 | ((new_value << RS_customShift) & RS_customMask); 832 | ((new_value << RS_customShift) & RS_customMask);
865} 833}
866 OUTPUT: 834 OUTPUT:
867 RETVAL 835 RETVAL
868 836
837void
838termlist ()
839 PPCODE:
840{
841 EXTEND (SP, rxvt_term::termlist.size ());
842
843 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
844 if ((*t)->perl.self)
845 PUSHs (sv_2mortal (newSVterm (*t)));
846}
847
869MODULE = urxvt PACKAGE = urxvt::term 848MODULE = urxvt PACKAGE = urxvt::term
870 849
871SV * 850SV *
872_new (...) 851_new (AV *env, AV *arg)
873 CODE: 852 CODE:
874{ 853{
875 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
876 croak ("first argument to urxvt::term->_new must be arrayref");
877
878 rxvt_term *term = new rxvt_term; 854 rxvt_term *term = new rxvt_term;
879 855
880 term->argv = new stringvec; 856 stringvec *argv = new stringvec;
881 term->envv = new stringvec; 857 stringvec *envv = new stringvec;
882 858
883 for (int i = 1; i < items; i++) 859 for (int i = 0; i <= AvFILL (arg); i++)
884 term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 860 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
885 861
886 AV *envv = (AV *)SvRV (ST (0));
887 for (int i = AvFILL (envv) + 1; i--; ) 862 for (int i = AvFILL (env) + 1; i--; )
888 term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); 863 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
889 864
890 term->envv->push_back (0); 865 envv->push_back (0);
891 866
892 bool success; 867 bool success;
893 868
894 try 869 try
895 { 870 {
896 success = term->init (term->argv->size (), term->argv->begin ()); 871 success = term->init (argv, envv);
897 } 872 }
898 catch (const class rxvt_failure_exception &e) 873 catch (const class rxvt_failure_exception &e)
899 { 874 {
900 success = false; 875 success = false;
901 } 876 }
913 RETVAL 888 RETVAL
914 889
915void 890void
916rxvt_term::destroy () 891rxvt_term::destroy ()
917 892
918#if ENABLE_PERL_FRILLS
919
920void
921rxvt_term::XListProperties (U32 window)
922 PPCODE:
923{
924 int count;
925 Atom *props = XListProperties (THIS->display->display, (Window)window, &count);
926
927 EXTEND (SP, count);
928 while (count--)
929 PUSHs (newSVuv ((U32)props [count]));
930
931 XFree (props);
932}
933
934void
935rxvt_term::XGetWindowProperty (U32 window, U32 property)
936 PPCODE:
937{
938 Atom type;
939 int format;
940 unsigned long nitems;
941 unsigned long bytes_after;
942 unsigned char *prop;
943 XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property,
944 0, 1<<30, 0, AnyPropertyType,
945 &type, &format, &nitems, &bytes_after, &prop);
946 if (type != None)
947 {
948 EXTEND (SP, 3);
949 PUSHs (newSVuv ((U32)type));
950 PUSHs (newSViv (format));
951 PUSHs (newSVpvn ((char *)prop, nitems * format / 8));
952 XFree (prop);
953 }
954}
955
956void
957rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data)
958 CODE:
959{
960 STRLEN len;
961 char *data_ = SvPVbyte (data, len);
962
963 XChangeProperty (THIS->display->display, (Window)window, (Atom)property,
964 type, format, PropModeReplace,
965 (unsigned char *)data, len * 8 / format);
966}
967
968void
969rxvt_term::XDeleteProperty (U32 window, U32 property)
970 CODE:
971 XDeleteProperty (THIS->display->display, (Window)window, (Atom)property);
972
973U32
974rxvt_term::DefaultRootWindow ()
975 CODE:
976 RETVAL = (U32)THIS->display->root;
977 OUTPUT:
978 RETVAL
979
980U32
981rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height)
982 CODE:
983 RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent,
984 x, y, width, height, 0,
985 THIS->pix_colors_focused[Color_border],
986 THIS->pix_colors_focused[Color_border]);
987 OUTPUT:
988 RETVAL
989
990void
991rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0)
992 CODE:
993 XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y);
994
995void
996rxvt_term::XMapWindow (U32 window)
997 CODE:
998 XMapWindow (THIS->display->display, (Window)window);
999
1000void
1001rxvt_term::XUnmapWindow (U32 window)
1002 CODE:
1003 XUnmapWindow (THIS->display->display, (Window)window);
1004
1005#endif
1006
1007void 893void
1008rxvt_term::set_should_invoke (int htype, int inc) 894rxvt_term::set_should_invoke (int htype, int inc)
1009 CODE: 895 CODE:
1010 THIS->perl.should_invoke [htype] += inc; 896 THIS->perl.should_invoke [htype] += inc;
1011 897
1012void 898int
1013rxvt_term::grab_button (int button, U32 modifiers) 899rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt)
1014 CODE: 900 CODE:
1015 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 901 RETVAL = XGrabButton (THIS->dpy, button, modifiers, window, 1,
1016 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 902 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1017 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 903 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
904 OUTPUT: RETVAL
905
906int
907rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt)
908 CODE:
909 RETVAL = XUngrabButton (THIS->dpy, button, modifiers, window);
910 OUTPUT: RETVAL
911
912void
913rxvt_term::XGrabKey (int keycode, U32 modifiers, Window window = THIS->vt, \
914 int owner_events = 1, int pointer_mode = GrabModeAsync, int keyboard_mode = GrabModeAsync)
915 CODE:
916 XGrabKey (THIS->dpy, keycode, modifiers, window, owner_events, pointer_mode, keyboard_mode);
917
918void
919rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt)
920 CODE:
921 XUngrabKey (THIS->dpy, keycode, modifiers, window);
922
923void
924rxvt_term::XUngrabKeyboard (Time eventtime)
925 CODE:
926 XUngrabKeyboard (THIS->dpy, eventtime);
1018 927
1019bool 928bool
1020rxvt_term::grab (U32 eventtime, int sync = 0) 929rxvt_term::grab (Time eventtime, int sync = 0)
1021 CODE: 930 CODE:
1022{ 931{
1023 int mode = sync ? GrabModeSync : GrabModeAsync; 932 int mode = sync ? GrabModeSync : GrabModeAsync;
1024 933
1025 THIS->perl.grabtime = 0; 934 THIS->perl.grabtime = 0;
1026 935
1027 if (!XGrabPointer (THIS->display->display, THIS->vt, 0, 936 if (!XGrabPointer (THIS->dpy, THIS->vt, 0,
1028 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 937 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1029 mode, mode, None, GRAB_CURSOR, eventtime)) 938 mode, mode, None, GRAB_CURSOR, eventtime))
1030 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) 939 if (!XGrabKeyboard (THIS->dpy, THIS->vt, 0, mode, mode, eventtime))
1031 THIS->perl.grabtime = eventtime; 940 THIS->perl.grabtime = eventtime;
1032 else 941 else
1033 XUngrabPointer (THIS->display->display, eventtime); 942 XUngrabPointer (THIS->dpy, eventtime);
1034 943
1035 RETVAL = !!THIS->perl.grabtime; 944 RETVAL = !!THIS->perl.grabtime;
1036} 945}
1037 OUTPUT: 946 OUTPUT:
1038 RETVAL 947 RETVAL
1039 948
1040void 949void
1041rxvt_term::allow_events_async () 950rxvt_term::allow_events_async ()
1042 CODE: 951 CODE:
1043 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); 952 XAllowEvents (THIS->dpy, AsyncBoth, THIS->perl.grabtime);
1044 953
1045void 954void
1046rxvt_term::allow_events_sync () 955rxvt_term::allow_events_sync ()
1047 CODE: 956 CODE:
1048 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); 957 XAllowEvents (THIS->dpy, SyncBoth, THIS->perl.grabtime);
1049 958
1050void 959void
1051rxvt_term::allow_events_replay () 960rxvt_term::allow_events_replay ()
1052 CODE: 961 CODE:
1053 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); 962 XAllowEvents (THIS->dpy, ReplayPointer, THIS->perl.grabtime);
1054 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); 963 XAllowEvents (THIS->dpy, ReplayKeyboard, THIS->perl.grabtime);
1055 964
1056void 965void
1057rxvt_term::ungrab () 966rxvt_term::ungrab ()
1058 CODE: 967 CODE:
1059 ungrab (THIS); 968 ungrab (THIS);
969
970int
971rxvt_term::XStringToKeysym (char *string)
972 CODE:
973 RETVAL = XStringToKeysym (string);
974 OUTPUT: RETVAL
975
976char *
977rxvt_term::XKeysymToString (int sym)
978 CODE:
979 RETVAL = XKeysymToString (sym);
980 OUTPUT: RETVAL
981
982int
983rxvt_term::XKeysymToKeycode (int sym)
984 CODE:
985 RETVAL = XKeysymToKeycode (THIS->dpy, sym);
986 OUTPUT: RETVAL
987
988int
989rxvt_term::XKeycodeToKeysym (int code, int index)
990 CODE:
991 RETVAL = XKeycodeToKeysym (THIS->dpy, code, index);
992 OUTPUT: RETVAL
1060 993
1061int 994int
1062rxvt_term::strwidth (SV *str) 995rxvt_term::strwidth (SV *str)
1063 CODE: 996 CODE:
1064{ 997{
1065 wchar_t *wstr = sv2wcs (str); 998 wchar_t *wstr = sv2wcs (str);
1066 999
1067 rxvt_push_locale (THIS->locale); 1000 rxvt_push_locale (THIS->locale);
1068 RETVAL = wcswidth (wstr, wcslen (wstr)); 1001 RETVAL = 0;
1002 for (wchar_t *wc = wstr; *wc; wc++)
1003 {
1004 int w = WCWIDTH (*wc);
1005
1006 if (w)
1007 RETVAL += max (w, 1);
1008 }
1069 rxvt_pop_locale (); 1009 rxvt_pop_locale ();
1070 1010
1071 free (wstr); 1011 free (wstr);
1072} 1012}
1073 OUTPUT: 1013 OUTPUT:
1103 rxvt_pop_locale (); 1043 rxvt_pop_locale ();
1104 1044
1105 RETVAL = wcs2sv (wstr); 1045 RETVAL = wcs2sv (wstr);
1106 free (wstr); 1046 free (wstr);
1107} 1047}
1048 OUTPUT:
1049 RETVAL
1050
1051char *
1052rxvt_term::locale ()
1053 CODE:
1054 RETVAL = THIS->locale;
1108 OUTPUT: 1055 OUTPUT:
1109 RETVAL 1056 RETVAL
1110 1057
1111#define TERM_OFFSET(sym) offsetof (TermWin_t, sym) 1058#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
1112 1059
1117#define TERM_OFFSET_fbase TERM_OFFSET(fbase) 1064#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1118#define TERM_OFFSET_nrow TERM_OFFSET(nrow) 1065#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1119#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1066#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1120#define TERM_OFFSET_focus TERM_OFFSET(focus) 1067#define TERM_OFFSET_focus TERM_OFFSET(focus)
1121#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1068#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
1069#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth)
1070#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth)
1071#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace)
1122#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1072#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1123#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1073#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1124#define TERM_OFFSET_top_row TERM_OFFSET(top_row) 1074#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1125 1075
1126int 1076int
1133 fbase = TERM_OFFSET_fbase 1083 fbase = TERM_OFFSET_fbase
1134 nrow = TERM_OFFSET_nrow 1084 nrow = TERM_OFFSET_nrow
1135 ncol = TERM_OFFSET_ncol 1085 ncol = TERM_OFFSET_ncol
1136 focus = TERM_OFFSET_focus 1086 focus = TERM_OFFSET_focus
1137 mapped = TERM_OFFSET_mapped 1087 mapped = TERM_OFFSET_mapped
1088 int_bwidth = TERM_OFFSET_int_bwidth
1089 ext_bwidth = TERM_OFFSET_ext_bwidth
1090 lineSpace = TERM_OFFSET_lineSpace
1138 saveLines = TERM_OFFSET_saveLines 1091 saveLines = TERM_OFFSET_saveLines
1139 total_rows = TERM_OFFSET_total_rows 1092 total_rows = TERM_OFFSET_total_rows
1140 top_row = TERM_OFFSET_top_row 1093 top_row = TERM_OFFSET_top_row
1141 CODE: 1094 CODE:
1142 RETVAL = *(int *)((char *)THIS + ix); 1095 RETVAL = *(int *)((char *)THIS + ix);
1147rxvt_term::ModLevel3Mask () 1100rxvt_term::ModLevel3Mask ()
1148 ALIAS: 1101 ALIAS:
1149 ModLevel3Mask = 0 1102 ModLevel3Mask = 0
1150 ModMetaMask = 1 1103 ModMetaMask = 1
1151 ModNumLockMask = 2 1104 ModNumLockMask = 2
1105 current_screen = 3
1106 hidden_cursor = 4
1152 CODE: 1107 CODE:
1153 switch (ix) 1108 switch (ix)
1154 { 1109 {
1155 case 0: RETVAL = THIS->ModLevel3Mask; break; 1110 case 0: RETVAL = THIS->ModLevel3Mask; break;
1156 case 1: RETVAL = THIS->ModMetaMask; break; 1111 case 1: RETVAL = THIS->ModMetaMask; break;
1157 case 2: RETVAL = THIS->ModNumLockMask; break; 1112 case 2: RETVAL = THIS->ModNumLockMask; break;
1113 case 3: RETVAL = THIS->current_screen; break;
1114 case 4: RETVAL = THIS->hidden_cursor; break;
1158 } 1115 }
1159 OUTPUT: 1116 OUTPUT:
1160 RETVAL 1117 RETVAL
1161 1118
1162char * 1119char *
1172 } 1129 }
1173 OUTPUT: 1130 OUTPUT:
1174 RETVAL 1131 RETVAL
1175 1132
1176SV * 1133SV *
1177rxvt_term::_env () 1134rxvt_term::envv ()
1135 ALIAS:
1136 argv = 1
1178 CODE: 1137 PPCODE:
1179{ 1138{
1180 if (THIS->envv) 1139 stringvec *vec = ix ? THIS->argv : THIS->envv;
1181 {
1182 AV *av = newAV ();
1183 1140
1141 EXTEND (SP, vec->size ());
1142
1184 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) 1143 for (char **i = vec->begin (); i != vec->end (); ++i)
1185 if (*i) 1144 if (*i)
1186 av_push (av, newSVpv (*i, 0)); 1145 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1187
1188 RETVAL = newRV_noinc ((SV *)av);
1189 }
1190 else
1191 RETVAL = &PL_sv_undef;
1192} 1146}
1193 OUTPUT:
1194 RETVAL
1195 1147
1196int 1148int
1197rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1149rxvt_term::pty_ev_events (int events = EVENT_UNDEF)
1198 CODE: 1150 CODE:
1199 RETVAL = THIS->pty_ev.events; 1151 RETVAL = THIS->pty_ev.events;
1200 if (events != EVENT_UNDEF) 1152 if (events != EVENT_UNDEF)
1201 THIS->pty_ev.set (events); 1153 THIS->pty_ev.set (events);
1202 OUTPUT: 1154 OUTPUT:
1203 RETVAL 1155 RETVAL
1204 1156
1205U32 1157int
1158rxvt_term::pty_fd ()
1159 CODE:
1160 RETVAL = THIS->pty->pty;
1161 OUTPUT:
1162 RETVAL
1163
1164Window
1206rxvt_term::parent () 1165rxvt_term::parent ()
1207 CODE: 1166 CODE:
1208 RETVAL = (U32)THIS->parent [0]; 1167 RETVAL = THIS->parent [0];
1209 OUTPUT: 1168 OUTPUT:
1210 RETVAL 1169 RETVAL
1211 1170
1212U32 1171Window
1213rxvt_term::vt () 1172rxvt_term::vt ()
1214 CODE: 1173 CODE:
1215 RETVAL = (U32)THIS->vt; 1174 RETVAL = THIS->vt;
1216 OUTPUT: 1175 OUTPUT:
1217 RETVAL 1176 RETVAL
1218 1177
1219void 1178void
1220rxvt_term::vt_emask_add (U32 emask) 1179rxvt_term::vt_emask_add (U32 emask)
1242} 1201}
1243 OUTPUT: 1202 OUTPUT:
1244 RETVAL 1203 RETVAL
1245 1204
1246void 1205void
1206rxvt_term::focus_in ()
1207
1208void
1209rxvt_term::focus_out ()
1210
1211void
1212rxvt_term::key_press (unsigned int state, unsigned int keycode, Time time = CurrentTime)
1213 ALIAS:
1214 key_release = 1
1215 CODE:
1216{
1217 XKeyEvent xkey;
1218
1219 memset (&xkey, 0, sizeof (xkey));
1220
1221 xkey.time = time;
1222 xkey.state = state;
1223 xkey.keycode = keycode;
1224
1225 xkey.type = ix ? KeyRelease : KeyPress;
1226 xkey.display = THIS->dpy;
1227 xkey.window = THIS->vt;
1228 xkey.root = THIS->display->root;
1229 xkey.subwindow = THIS->vt;
1230
1231 if (ix)
1232 THIS->key_release (xkey);
1233 else
1234 THIS->key_press (xkey);
1235}
1236
1237void
1247rxvt_term::want_refresh () 1238rxvt_term::want_refresh ()
1248 CODE: 1239 CODE:
1249 THIS->want_refresh = 1; 1240 THIS->want_refresh = 1;
1250 1241
1251void 1242void
1257 1248
1258 line_t &l = ROW(row_number); 1249 line_t &l = ROW(row_number);
1259 1250
1260 if (GIMME_V != G_VOID) 1251 if (GIMME_V != G_VOID)
1261 { 1252 {
1262 wchar_t *wstr = new wchar_t [THIS->ncol]; 1253 wchar_t *wstr = rxvt_temp_buf<wchar_t> (THIS->ncol);
1263 1254
1264 for (int col = 0; col < THIS->ncol; col++) 1255 for (int col = 0; col < THIS->ncol; col++)
1265 wstr [col] = l.t [col]; 1256 wstr [col] = l.t [col];
1266 1257
1267 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1258 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1268
1269 delete [] wstr;
1270 } 1259 }
1271 1260
1272 if (new_text) 1261 if (new_text)
1273 { 1262 {
1274 wchar_t *wstr = sv2wcs (new_text); 1263 wchar_t *wstr = sv2wcs (new_text);
1275 1264
1276 int len = min (wcslen (wstr) - start_ofs, max_len); 1265 int len = min (wcslen (wstr) - start_ofs, max_len);
1277 1266
1278 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1267 if (start_col < 0 || start_col + len > THIS->ncol)
1279 { 1268 {
1280 free (wstr); 1269 free (wstr);
1281 croak ("new_text extends beyond horizontal margins"); 1270 croak ("new_text extends beyond horizontal margins");
1282 } 1271 }
1283 1272
1317 croak ("new_rend must be arrayref"); 1306 croak ("new_rend must be arrayref");
1318 1307
1319 AV *av = (AV *)SvRV (new_rend); 1308 AV *av = (AV *)SvRV (new_rend);
1320 int len = min (AvFILL (av) + 1 - start_ofs, max_len); 1309 int len = min (AvFILL (av) + 1 - start_ofs, max_len);
1321 1310
1322 if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) 1311 if (start_col < 0 || start_col + len > THIS->ncol)
1323 croak ("new_rend array extends beyond horizontal margins"); 1312 croak ("new_rend array extends beyond horizontal margins");
1324 1313
1325 for (int col = start_col; col < start_col + len; col++) 1314 for (int col = start_col; col < start_col + len; col++)
1326 { 1315 {
1327 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; 1316 rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask;
1367rxvt_term::special_encode (SV *string) 1356rxvt_term::special_encode (SV *string)
1368 CODE: 1357 CODE:
1369{ 1358{
1370 wchar_t *wstr = sv2wcs (string); 1359 wchar_t *wstr = sv2wcs (string);
1371 int wlen = wcslen (wstr); 1360 int wlen = wcslen (wstr);
1372 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer 1361 wchar_t *rstr = rxvt_temp_buf<wchar_t> (wlen * 2); // cannot become longer
1373 1362
1374 rxvt_push_locale (THIS->locale); 1363 rxvt_push_locale (THIS->locale);
1375 1364
1376 wchar_t *r = rstr; 1365 wchar_t *r = rstr;
1377 for (wchar_t *s = wstr; *s; s++) 1366 for (wchar_t *s = wstr; *s; s++)
1367 {
1368 int w = WCWIDTH (*s);
1369
1378 if (wcwidth (*s) == 0) 1370 if (w == 0)
1379 { 1371 {
1380 if (r == rstr) 1372 if (r == rstr)
1381 croak ("leading combining character unencodable"); 1373 croak ("leading combining character unencodable");
1382 1374
1383 unicode_t n = rxvt_compose (r[-1], *s); 1375 unicode_t n = rxvt_compose (r[-1], *s);
1384 if (n == NOCHAR) 1376 if (n == NOCHAR)
1385 n = rxvt_composite.compose (r[-1], *s); 1377 n = rxvt_composite.compose (r[-1], *s);
1386 1378
1387 r[-1] = n; 1379 r[-1] = n;
1388 } 1380 }
1389#if !UNICODE_3 1381#if !UNICODE_3
1390 else if (*s >= 0x10000) 1382 else if (*s >= 0x10000)
1391 *r++ = rxvt_composite.compose (*s); 1383 *r++ = rxvt_composite.compose (*s);
1392#endif 1384#endif
1393 else 1385 else
1394 *r++ = *s; 1386 *r++ = *s;
1387
1388 // the *2 above only allows wcwidth <= 2
1389 if (w > 1)
1390 *r++ = NOCHAR;
1391 }
1395 1392
1396 rxvt_pop_locale (); 1393 rxvt_pop_locale ();
1397 1394
1398 RETVAL = wcs2sv (rstr, r - rstr); 1395 RETVAL = wcs2sv (rstr, r - rstr);
1399
1400 delete [] rstr;
1401} 1396}
1402 OUTPUT: 1397 OUTPUT:
1403 RETVAL 1398 RETVAL
1404 1399
1405SV * 1400SV *
1417 else if (IS_COMPOSE (*s)) 1412 else if (IS_COMPOSE (*s))
1418 dlen += rxvt_composite.expand (*s, 0); 1413 dlen += rxvt_composite.expand (*s, 0);
1419 else 1414 else
1420 dlen++; 1415 dlen++;
1421 1416
1422 wchar_t *rstr = new wchar_t [dlen]; 1417 wchar_t *rstr = rxvt_temp_buf<wchar_t> (dlen);
1423 1418
1424 // decode 1419 // decode
1425 wchar_t *r = rstr; 1420 wchar_t *r = rstr;
1426 for (wchar_t *s = wstr; *s; s++) 1421 for (wchar_t *s = wstr; *s; s++)
1427 if (*s == NOCHAR) 1422 if (*s == NOCHAR)
1430 r += rxvt_composite.expand (*s, r); 1425 r += rxvt_composite.expand (*s, r);
1431 else 1426 else
1432 *r++ = *s; 1427 *r++ = *s;
1433 1428
1434 RETVAL = wcs2sv (rstr, r - rstr); 1429 RETVAL = wcs2sv (rstr, r - rstr);
1435
1436 delete [] rstr;
1437} 1430}
1438 OUTPUT: 1431 OUTPUT:
1439 RETVAL 1432 RETVAL
1440 1433
1441void 1434void
1442rxvt_term::_resource (char *name, int index, SV *newval = 0) 1435rxvt_term::_resource (char *name, int index, SV *newval = 0)
1443 PPCODE: 1436 PPCODE:
1444{ 1437{
1445 struct resval { const char *name; int value; } rslist [] = { 1438 static const struct resval { const char *name; int value; } *rs, rslist [] = {
1446# define def(name) { # name, Rs_ ## name }, 1439# define def(name) { # name, Rs_ ## name },
1447# define reserve(name,count) 1440# define reserve(name,count)
1448# include "rsinc.h" 1441# include "rsinc.h"
1449# undef def 1442# undef def
1450# undef reserve 1443# undef reserve
1451 }; 1444 };
1452 1445
1453 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1446 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1454 1447
1455 do { 1448 do {
1456 if (rs-- == rslist) 1449 if (rs-- == rslist)
1457 croak ("no such resource '%s', requested", name); 1450 croak ("no such resource '%s', requested", name);
1458 } while (strcmp (name, rs->name)); 1451 } while (strcmp (name, rs->name));
1551 if (items == 3) 1544 if (items == 3)
1552 { 1545 {
1553 rc.row = SvIV (ST (1)); 1546 rc.row = SvIV (ST (1));
1554 rc.col = SvIV (ST (2)); 1547 rc.col = SvIV (ST (2));
1555 1548
1556 if (ix == 2 && rc.col == 0) 1549 if (ix == 2)
1557 { 1550 {
1551 if (rc.col == 0)
1552 {
1553 // col == 0 means end of previous line
1558 rc.row--; 1554 rc.row--;
1559 rc.col = THIS->ncol; 1555 rc.col = THIS->ncol;
1556 }
1557 else if (IN_RANGE_EXC (rc.row, THIS->top_row, THIS->nrow)
1558 && rc.col > ROW(rc.row).l)
1559 {
1560 // col >= length means while line and add newline
1561 rc.col = THIS->ncol;
1562 }
1560 } 1563 }
1561 1564
1562 clamp_it (rc.col, 0, THIS->ncol); 1565 clamp_it (rc.col, 0, THIS->ncol);
1563 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1566 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1564 1567
1572 CODE: 1575 CODE:
1573 RETVAL = THIS->charsets [THIS->screen.charset]; 1576 RETVAL = THIS->charsets [THIS->screen.charset];
1574 OUTPUT: 1577 OUTPUT:
1575 RETVAL 1578 RETVAL
1576 1579
1577#void 1580void
1578#rxvt_term::selection_clear () 1581rxvt_term::selection_clear ()
1579 1582
1580void 1583void
1581rxvt_term::selection_make (U32 eventtime, bool rect = false) 1584rxvt_term::selection_make (Time eventtime, bool rect = false)
1582 CODE: 1585 CODE:
1583 THIS->selection.op = SELECTION_CONT; 1586 THIS->selection.op = SELECTION_CONT;
1584 THIS->selection.rect = rect; 1587 THIS->selection.rect = rect;
1585 THIS->selection_make (eventtime); 1588 THIS->selection_make (eventtime);
1586 1589
1587int 1590int
1588rxvt_term::selection_grab (U32 eventtime) 1591rxvt_term::selection_grab (Time eventtime)
1589 1592
1590void 1593void
1591rxvt_term::selection (SV *newtext = 0) 1594rxvt_term::selection (SV *newtext = 0)
1592 PPCODE: 1595 PPCODE:
1593{ 1596{
1611void 1614void
1612rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) 1615rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid)
1613 1616
1614void 1617void
1615rxvt_term::scr_bell () 1618rxvt_term::scr_bell ()
1619
1620void
1621rxvt_term::scr_change_screen (int screen)
1616 1622
1617void 1623void
1618rxvt_term::scr_add_lines (SV *string) 1624rxvt_term::scr_add_lines (SV *string)
1619 CODE: 1625 CODE:
1620{ 1626{
1661 o->self = (HV *)SvRV (RETVAL); 1667 o->self = (HV *)SvRV (RETVAL);
1662} 1668}
1663 OUTPUT: 1669 OUTPUT:
1664 RETVAL 1670 RETVAL
1665 1671
1672#############################################################################
1673# Various X Utility Functions
1674#############################################################################
1675
1676void
1677rxvt_term::XListProperties (Window window)
1678 PPCODE:
1679{
1680 int count;
1681 Atom *props = XListProperties (THIS->dpy, window, &count);
1682
1683 EXTEND (SP, count);
1684 while (count--)
1685 PUSHs (newSVuv ((U32)props [count]));
1686
1687 XFree (props);
1688}
1689
1690void
1691rxvt_term::XGetWindowProperty (Window window, Atom property)
1692 PPCODE:
1693{
1694 Atom type;
1695 int format;
1696 unsigned long nitems;
1697 unsigned long bytes_after;
1698 unsigned char *prop;
1699
1700 XGetWindowProperty (THIS->dpy, window, property,
1701 0, 1<<24, 0, AnyPropertyType,
1702 &type, &format, &nitems, &bytes_after, &prop);
1703
1704 if (type != None)
1705 {
1706 int elemsize = format == 16 ? sizeof (short)
1707 : format == 32 ? sizeof (long)
1708 : 1;
1709
1710 EXTEND (SP, 3);
1711 PUSHs (newSVuv ((U32)type));
1712 PUSHs (newSViv (format));
1713 PUSHs (newSVpvn ((char *)prop, nitems * elemsize));
1714 XFree (prop);
1715 }
1716}
1717
1718void
1719rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data)
1720 CODE:
1721{
1722 STRLEN len;
1723 char *data_ = SvPVbyte (data, len);
1724
1725 int elemsize = format == 16 ? sizeof (short)
1726 : format == 32 ? sizeof (long)
1727 : 1;
1728
1729 XChangeProperty (THIS->dpy, window, property,
1730 type, format, PropModeReplace,
1731 (unsigned char *)data_, len / elemsize);
1732}
1733
1734Atom
1735XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1736 C_ARGS: term->dpy, atom_name, only_if_exists
1737
1738char *
1739XGetAtomName (rxvt_term *term, Atom atom)
1740 C_ARGS: term->dpy, atom
1741 CLEANUP:
1742 XFree (RETVAL);
1743
1744void
1745XDeleteProperty (rxvt_term *term, Window window, Atom property)
1746 C_ARGS: term->dpy, window, property
1747
1748Window
1749rxvt_term::DefaultRootWindow ()
1750 CODE:
1751 RETVAL = THIS->display->root;
1752 OUTPUT:
1753 RETVAL
1754
1755#if 0
1756
1757Window
1758XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1759 C_ARGS: term->dpy, (Window)parent,
1760 x, y, width, height, 0,
1761 term->pix_colors_focused[Color_border],
1762 term->pix_colors_focused[Color_border]
1763
1764#endif
1765
1766void
1767XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1768 C_ARGS: term->dpy, window, parent, x, y
1769
1770void
1771XMapWindow (rxvt_term *term, Window window)
1772 C_ARGS: term->dpy, window
1773
1774void
1775XUnmapWindow (rxvt_term *term, Window window)
1776 C_ARGS: term->dpy, window
1777
1778void
1779XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1780 C_ARGS: term->dpy, window, x, y, width, height
1781
1782void
1783rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0)
1784 CODE:
1785{
1786 XWindowAttributes attr;
1787 XGetWindowAttributes (THIS->dpy, window, &attr);
1788 XSelectInput (THIS->dpy, window, attr.your_event_mask | add_events & ~del_events);
1789}
1790
1791void
1792rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y)
1793 PPCODE:
1794{
1795 int dx, dy;
1796 Window child;
1797
1798 if (XTranslateCoordinates (THIS->dpy, src, dst, x, y, &dx, &dy, &child))
1799 {
1800 EXTEND (SP, 3);
1801 PUSHs (newSViv (dx));
1802 PUSHs (newSViv (dy));
1803 PUSHs (newSVuv (child));
1804 }
1805}
1806
1807#############################################################################
1808# urxvt::overlay
1809#############################################################################
1810
1666MODULE = urxvt PACKAGE = urxvt::overlay 1811MODULE = urxvt PACKAGE = urxvt::overlay
1667 1812
1668void 1813void
1669overlay::set (int x, int y, SV *text, SV *rend = 0) 1814overlay::set (int x, int y, SV *text, SV *rend = 0)
1670 1815
1675overlay::hide () 1820overlay::hide ()
1676 1821
1677void 1822void
1678overlay::DESTROY () 1823overlay::DESTROY ()
1679 1824
1680MODULE = urxvt PACKAGE = urxvt::timer 1825INCLUDE: $PERL <iom_perl.xs -pe s/IOM_MODULE/urxvt/g,s/IOM_CLASS/urxvt/g |
1681 1826
1682SV *
1683timer::new ()
1684 CODE:
1685 timer *w = new timer;
1686 w->start (NOW);
1687 RETVAL = newSVptr ((void *)w, "urxvt::timer");
1688 w->self = (HV *)SvRV (RETVAL);
1689 OUTPUT:
1690 RETVAL
1691
1692timer *
1693timer::cb (SV *cb)
1694 CODE:
1695 THIS->cb (cb);
1696 RETVAL = THIS;
1697 OUTPUT:
1698 RETVAL
1699
1700NV
1701timer::at ()
1702 CODE:
1703 RETVAL = THIS->at;
1704 OUTPUT:
1705 RETVAL
1706
1707timer *
1708timer::interval (NV interval)
1709 CODE:
1710 THIS->interval = interval;
1711 RETVAL = THIS;
1712 OUTPUT:
1713 RETVAL
1714
1715timer *
1716timer::set (NV tstamp)
1717 CODE:
1718 THIS->set (tstamp);
1719 RETVAL = THIS;
1720 OUTPUT:
1721 RETVAL
1722
1723timer *
1724timer::start (NV tstamp = THIS->at)
1725 CODE:
1726 THIS->start (tstamp);
1727 RETVAL = THIS;
1728 OUTPUT:
1729 RETVAL
1730
1731timer *
1732timer::after (NV delay)
1733 CODE:
1734 THIS->start (NOW + delay);
1735 RETVAL = THIS;
1736 OUTPUT:
1737 RETVAL
1738
1739timer *
1740timer::stop ()
1741 CODE:
1742 THIS->stop ();
1743 RETVAL = THIS;
1744 OUTPUT:
1745 RETVAL
1746
1747void
1748timer::DESTROY ()
1749
1750MODULE = urxvt PACKAGE = urxvt::iow
1751
1752SV *
1753iow::new ()
1754 CODE:
1755 iow *w = new iow;
1756 RETVAL = newSVptr ((void *)w, "urxvt::iow");
1757 w->self = (HV *)SvRV (RETVAL);
1758 OUTPUT:
1759 RETVAL
1760
1761iow *
1762iow::cb (SV *cb)
1763 CODE:
1764 THIS->cb (cb);
1765 RETVAL = THIS;
1766 OUTPUT:
1767 RETVAL
1768
1769iow *
1770iow::fd (int fd)
1771 CODE:
1772 THIS->fd = fd;
1773 RETVAL = THIS;
1774 OUTPUT:
1775 RETVAL
1776
1777iow *
1778iow::events (short events)
1779 CODE:
1780 THIS->events = events;
1781 RETVAL = THIS;
1782 OUTPUT:
1783 RETVAL
1784
1785iow *
1786iow::start ()
1787 CODE:
1788 THIS->start ();
1789 RETVAL = THIS;
1790 OUTPUT:
1791 RETVAL
1792
1793iow *
1794iow::stop ()
1795 CODE:
1796 THIS->stop ();
1797 RETVAL = THIS;
1798 OUTPUT:
1799 RETVAL
1800
1801void
1802iow::DESTROY ()
1803
1804

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines