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.89 by root, Sun Jan 22 11:57:06 2006 UTC vs.
Revision 1.125 by root, Fri Aug 22 15:36:45 2008 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: rxvtperl.xs 2 * File: rxvtperl.xs
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
31#include <cstddef> 31#include <cstddef>
32#include <cstdarg> 32#include <cstdarg>
33 33
34#include "unistd.h" 34#include "unistd.h"
35 35
36#include "iom.h" 36#include "ev_cpp.h"
37#include "rxvt.h" 37#include "rxvt.h"
38#include "keyboard.h" 38#include "keyboard.h"
39#include "rxvtutil.h" 39#include "rxvtutil.h"
40#include "rxvtperl.h" 40#include "rxvtperl.h"
41 41
42#include "perlxsi.c" 42#include "perlxsi.c"
43 43
44#ifdef HAVE_SCROLLBARS
45# define GRAB_CURSOR THIS->leftptr_cursor 44#define GRAB_CURSOR THIS->scrollBar.leftptr_cursor
46#else
47# define GRAB_CURSOR None
48#endif
49 45
50#undef LINENO 46#undef LINENO
51#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) 47#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows)
52#undef ROW 48#undef ROW
53#define ROW(n) THIS->row_buf [LINENO (n)] 49#define ROW(n) THIS->row_buf [LINENO (n)]
54 50
55typedef int CHAINED UNUSED;
56
57///////////////////////////////////////////////////////////////////////////// 51/////////////////////////////////////////////////////////////////////////////
58 52
59static wchar_t * 53static wchar_t *
60sv2wcs (SV *sv) 54sv2wcs (SV *sv)
61{ 55{
75 69
76 return sv; 70 return sv;
77} 71}
78 72
79static SV * 73static SV *
80new_ref (HV *hv, const char *klass)
81{
82 return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1));
83}
84
85//TODO: use magic
86static SV *
87newSVptr (void *ptr, const char *klass) 74newSVptr (void *ptr, const char *klass)
88{ 75{
89 HV *hv = newHV (); 76 HV *hv = newHV ();
90 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 77 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
91 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 78 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
113 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); 100 croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
114 101
115 return (long)mg->mg_ptr; 102 return (long)mg->mg_ptr;
116} 103}
117 104
118#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) 105#define newSVterm(term) SvREFCNT_inc ((SV *)(term)->perl.self)
119#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") 106#define SvTERM(sv) (rxvt_term *)SvPTR ((sv), "urxvt::term")
120 107
121///////////////////////////////////////////////////////////////////////////// 108/////////////////////////////////////////////////////////////////////////////
122 109
123#define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, "urxvt::watcher")
124
125struct perl_watcher
126{
127 SV *cbsv;
128 HV *self;
129
130 perl_watcher ()
131 : cbsv (0)
132 {
133 }
134
135 ~perl_watcher ()
136 {
137 SvREFCNT_dec (cbsv);
138 }
139
140 void cb (SV *cb)
141 {
142 SvREFCNT_dec (cbsv);
143 cbsv = newSVsv (cb);
144 }
145
146 void invoke (const char *type, SV *self, int arg = -1);
147};
148
149void
150perl_watcher::invoke (const char *type, SV *self, int arg)
151{
152 dSP;
153
154 ENTER;
155 SAVETMPS;
156
157 PUSHMARK (SP);
158
159 XPUSHs (sv_2mortal (self));
160
161 if (arg >= 0)
162 XPUSHs (sv_2mortal (newSViv (arg)));
163
164 PUTBACK;
165 call_sv (cbsv, G_VOID | G_EVAL | G_DISCARD);
166 SPAGAIN;
167
168 PUTBACK;
169 FREETMPS;
170 LEAVE;
171
172 if (SvTRUE (ERRSV))
173 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
174}
175
176#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer")
177#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR (sv, "urxvt::timer")
178
179struct timer : perl_watcher, time_watcher
180{
181 tstamp interval;
182
183 timer ()
184 : time_watcher (this, &timer::execute)
185 {
186 }
187
188 void execute (time_watcher &w)
189 {
190 if (interval)
191 start (at + interval);
192
193 invoke ("urxvt::timer", newSVtimer (this));
194 }
195};
196
197#define newSViow(iow) new_ref (iow->self, "urxvt::iow")
198#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR (sv, "urxvt::iow")
199
200struct iow : perl_watcher, io_watcher
201{
202 iow ()
203 : io_watcher (this, &iow::execute)
204 {
205 }
206
207 void execute (io_watcher &w, short revents)
208 {
209 invoke ("urxvt::iow", newSViow (this), revents);
210 }
211};
212
213#define newSViw(iw) new_ref (iw->self, "urxvt::iw")
214#define SvIW(sv) (iw *)(perl_watcher *)SvPTR (sv, "urxvt::iw")
215
216struct iw : perl_watcher, idle_watcher
217{
218 iw ()
219 : idle_watcher (this, &iw::execute)
220 {
221 }
222
223 void execute (idle_watcher &w)
224 {
225 invoke ("urxvt::iw", newSViw (this));
226 }
227};
228
229#define newSVpw(pw) new_ref (pw->self, "urxvt::pw")
230#define SvPW(sv) (pw *)(perl_watcher *)SvPTR (sv, "urxvt::pw")
231
232struct pw : perl_watcher, child_watcher
233{
234 pw ()
235 : child_watcher (this, &pw::execute)
236 {
237 }
238
239 void execute (child_watcher &w, int status)
240 {
241 invoke ("urxvt::pw", newSVpw (this), status);
242 }
243};
244
245/////////////////////////////////////////////////////////////////////////////
246
247#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 110#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
248 111
249struct overlay { 112class overlay {
250 HV *self;
251 bool visible;
252 rxvt_term *THIS; 113 rxvt_term *THIS;
114 AV *overlay_av;
253 int x, y, w, h; 115 int x, y, w, h;
254 int border; 116 int border;
255 text_t **text; 117 text_t **text;
256 rend_t **rend; 118 rend_t **rend;
257 119
120public:
121 HV *self;
122
258 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); 123 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
259 ~overlay (); 124 ~overlay ();
260 125
261 void show (); 126 void show ();
262 void hide (); 127 void hide ();
265 130
266 void set (int x, int y, SV *str, SV *rend); 131 void set (int x, int y, SV *str, SV *rend);
267}; 132};
268 133
269overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 134overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
270: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), visible(false) 135: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0)
271{ 136{
137 if (w < 0) w = 0;
138 if (h < 0) h = 0;
139
272 if (border == 2) 140 if (border == 2)
273 { 141 {
274 w += 2; 142 w += 2;
275 h += 2; 143 h += 2;
276 } 144 }
314 *rp++ = r; 182 *rp++ = r;
315 } 183 }
316 } 184 }
317 185
318 show (); 186 show ();
319 THIS->want_refresh = 1;
320} 187}
321 188
322overlay::~overlay () 189overlay::~overlay ()
323{ 190{
324 hide (); 191 hide ();
329 delete [] rend[y]; 196 delete [] rend[y];
330 } 197 }
331 198
332 delete [] text; 199 delete [] text;
333 delete [] rend; 200 delete [] rend;
201}
202
203void
204overlay::show ()
205{
206 if (overlay_av)
207 return;
208
209 overlay_av = (AV *)SvREFCNT_inc (SvRV (
210 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
211 ));
212 av_push (overlay_av, newSViv ((long)this));
334 213
335 THIS->want_refresh = 1; 214 THIS->want_refresh = 1;
215 THIS->refresh_check ();
336} 216}
337 217
338void 218void
339overlay::show () 219overlay::hide ()
340{ 220{
341 if (visible) 221 if (!overlay_av)
342 return; 222 return;
343 223
344 visible = true;
345
346 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
347 av_push (av, newSViv ((long)this));
348}
349
350void
351overlay::hide ()
352{
353 if (!visible)
354 return;
355
356 visible = false;
357
358 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0));
359
360 int i; 224 int i;
361 225
362 for (i = AvFILL (av); i >= 0; i--) 226 for (i = AvFILL (overlay_av); i >= 0; i--)
363 if (SvIV (*av_fetch (av, i, 1)) == (long)this) 227 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this)
364 {
365 av_delete (av, i, G_DISCARD);
366 break; 228 break;
367 }
368 229
369 for (; i < AvFILL (av); i++) 230 for (; i < AvFILL (overlay_av); i++)
370 av_store (av, i, SvREFCNT_inc (*av_fetch (av, i + 1, 0))); 231 av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0)));
371 232
372 av_pop (av); 233 av_pop (overlay_av);
234
235 SvREFCNT_dec (overlay_av);
236 overlay_av = 0;
237
238 THIS->want_refresh = 1;
239 THIS->refresh_check ();
373} 240}
374 241
375void overlay::swap () 242void overlay::swap ()
376{ 243{
377 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 244 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
422 for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) 289 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
423 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 290 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
424 } 291 }
425 292
426 THIS->want_refresh = 1; 293 THIS->want_refresh = 1;
294 THIS->refresh_check ();
427} 295}
428 296
297/////////////////////////////////////////////////////////////////////////////
298
299#define IOM_CLASS "urxvt"
300#define IOM_WARN rxvt_warn
301#include "iom_perl.h"
429 302
430///////////////////////////////////////////////////////////////////////////// 303/////////////////////////////////////////////////////////////////////////////
431 304
432struct rxvt_perl_interp rxvt_perl; 305struct rxvt_perl_interp rxvt_perl;
433 306
437{ 310{
438 if (perl) 311 if (perl)
439 { 312 {
440 perl_destruct (perl); 313 perl_destruct (perl);
441 perl_free (perl); 314 perl_free (perl);
315 PERL_SYS_TERM ();
442 } 316 }
443} 317}
444 318
445void 319void
446rxvt_perl_interp::init (rxvt_term *term) 320rxvt_perl_interp::init (rxvt_term *term)
450 rxvt_push_locale (""); // perl init destroys current locale 324 rxvt_push_locale (""); // perl init destroys current locale
451 325
452 perl_environ = rxvt_environ; 326 perl_environ = rxvt_environ;
453 swap (perl_environ, environ); 327 swap (perl_environ, environ);
454 328
455 char *argv[] = { 329 char *args[] = {
456 "", 330 "",
457 "-e" 331 "-e"
458 "BEGIN {" 332 "BEGIN {"
459 " urxvt->bootstrap;" 333 " urxvt->bootstrap;"
460 " unshift @INC, '" LIBDIR "';" 334 " unshift @INC, '" LIBDIR "';"
461 "}" 335 "}"
462 "" 336 ""
463 "use urxvt;" 337 "use urxvt;"
464 }; 338 };
339 int argc = sizeof (args) / sizeof (args[0]);
340 char **argv = args;
465 341
342 PERL_SYS_INIT3 (&argc, &argv, &environ);
466 perl = perl_alloc (); 343 perl = perl_alloc ();
467 perl_construct (perl); 344 perl_construct (perl);
468 345
469 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 346 if (perl_parse (perl, xs_init, argc, argv, (char **)NULL)
470 || perl_run (perl)) 347 || perl_run (perl))
471 { 348 {
472 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 349 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
473 350
474 perl_destruct (perl); 351 perl_destruct (perl);
492static void 369static void
493ungrab (rxvt_term *THIS) 370ungrab (rxvt_term *THIS)
494{ 371{
495 if (THIS->perl.grabtime) 372 if (THIS->perl.grabtime)
496 { 373 {
497 XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); 374 XUngrabKeyboard (THIS->dpy, THIS->perl.grabtime);
498 XUngrabPointer (THIS->display->display, THIS->perl.grabtime); 375 XUngrabPointer (THIS->dpy, THIS->perl.grabtime);
499 THIS->perl.grabtime = 0; 376 THIS->perl.grabtime = 0;
500 } 377 }
501} 378}
502 379
503bool 380bool
508 385
509 // pre-handling of some events 386 // pre-handling of some events
510 if (htype == HOOK_REFRESH_END) 387 if (htype == HOOK_REFRESH_END)
511 { 388 {
512 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 389 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
513 390
514 for (int i = 0; i <= AvFILL (av); i++) 391 for (int i = 0; i <= AvFILL (av); i++)
515 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 392 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
516 } 393 }
517 394
518 swap (perl_environ, environ); 395 swap (perl_environ, environ);
554 break; 431 break;
555 432
556 case DT_STR_LEN: 433 case DT_STR_LEN:
557 { 434 {
558 char *str = va_arg (ap, char *); 435 char *str = va_arg (ap, char *);
559 int len = va_arg (ap, int); 436 int len = va_arg (ap, int);
560 437
561 XPUSHs (sv_2mortal (newSVpvn (str, len))); 438 XPUSHs (sv_2mortal (newSVpvn (str, len)));
562 } 439 }
563 break; 440 break;
564 441
565 case DT_WCS_LEN: 442 case DT_WCS_LEN:
566 { 443 {
567 wchar_t *wstr = va_arg (ap, wchar_t *); 444 wchar_t *wstr = va_arg (ap, wchar_t *);
568 int wlen = va_arg (ap, int); 445 int wlen = va_arg (ap, int);
569 446
570 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); 447 XPUSHs (sv_2mortal (wcs2sv (wstr, wlen)));
448 }
449 break;
450
451 case DT_LCS_LEN:
452 {
453 long *lstr = va_arg (ap, long *);
454 int llen = va_arg (ap, int);
455
456 XPUSHs (sv_2mortal (newSVpvn ((char *)lstr, llen * sizeof (long))));
571 } 457 }
572 break; 458 break;
573 459
574 case DT_XEVENT: 460 case DT_XEVENT:
575 { 461 {
576 XEvent *xe = va_arg (ap, XEvent *); 462 XEvent *xe = va_arg (ap, XEvent *);
577 HV *hv = newHV (); 463 HV *hv = newHV ();
578 464
579# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) 465# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0)
580# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) 466# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0)
581# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0) 467# define setuv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSVuv (val), 0)
582# undef set 468# undef set
583 469
584 setiv (type, xe->type); 470 setiv (type, xe->type);
585 setiv (send_event, xe->xany.send_event); 471 setiv (send_event, xe->xany.send_event);
586 setiv (serial, xe->xany.serial); 472 setiv (serial, xe->xany.serial);
587 473
708 594
709 // post-handling of some events 595 // post-handling of some events
710 if (htype == HOOK_REFRESH_BEGIN) 596 if (htype == HOOK_REFRESH_BEGIN)
711 { 597 {
712 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 598 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
713 599
714 for (int i = AvFILL (av); i >= 0; i--) 600 for (int i = AvFILL (av); i >= 0; i--)
715 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 601 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
716 } 602 }
717 else if (htype == HOOK_DESTROY) 603 else if (htype == HOOK_DESTROY)
718 { 604 {
719 clearSVptr ((SV *)term->perl.self); 605 clearSVptr ((SV *)term->perl.self);
720 SvREFCNT_dec ((SV *)term->perl.self); 606 SvREFCNT_dec ((SV *)term->perl.self);
607
608 // don't allow further calls
609 term->perl.self = 0;
721 } 610 }
722 611
723 swap (perl_environ, environ); 612 swap (perl_environ, environ);
724 613
725 return event_consumed; 614 return event_consumed;
749# include "optinc.h" 638# include "optinc.h"
750# undef nodef 639# undef nodef
751# undef def 640# undef def
752 641
753 HV *stash = gv_stashpv ("urxvt", 1); 642 HV *stash = gv_stashpv ("urxvt", 1);
754 struct { 643 static const struct {
755 const char *name; 644 const char *name;
756 IV iv; 645 IV iv;
757 } *civ, const_iv[] = { 646 } *civ, const_iv[] = {
758# define const_iv(name) { # name, (IV)name } 647# define const_iv(name) { # name, (IV)name }
648 const_iv (NUM_RESOURCES),
759 const_iv (DEFAULT_RSTYLE), 649 const_iv (DEFAULT_RSTYLE),
760 const_iv (OVERLAY_RSTYLE), 650 const_iv (OVERLAY_RSTYLE),
761 const_iv (RS_Bold), 651 const_iv (RS_Bold),
762 const_iv (RS_Italic), 652 const_iv (RS_Italic),
763 const_iv (RS_Blink), 653 const_iv (RS_Blink),
778 const_iv (Button3Mask), 668 const_iv (Button3Mask),
779 const_iv (Button4Mask), 669 const_iv (Button4Mask),
780 const_iv (Button5Mask), 670 const_iv (Button5Mask),
781 const_iv (AnyModifier), 671 const_iv (AnyModifier),
782 672
783 const_iv (EVENT_NONE), 673 const_iv (NoSymbol),
784 const_iv (EVENT_READ), 674 const_iv (GrabModeSync),
785 const_iv (EVENT_WRITE), 675 const_iv (GrabModeAsync),
786 676
787 const_iv (NoEventMask), 677 const_iv (NoEventMask),
788 const_iv (KeyPressMask), 678 const_iv (KeyPressMask),
789 const_iv (KeyReleaseMask), 679 const_iv (KeyReleaseMask),
790 const_iv (ButtonPressMask), 680 const_iv (ButtonPressMask),
842 const_iv (SelectionRequest), 732 const_iv (SelectionRequest),
843 const_iv (SelectionNotify), 733 const_iv (SelectionNotify),
844 const_iv (ColormapNotify), 734 const_iv (ColormapNotify),
845 const_iv (ClientMessage), 735 const_iv (ClientMessage),
846 const_iv (MappingNotify), 736 const_iv (MappingNotify),
737# if ENABLE_XIM_ONTHESPOT
738 const_iv (XIMReverse),
739 const_iv (XIMUnderline),
740 const_iv (XIMHighlight),
741 const_iv (XIMPrimary),
742 const_iv (XIMSecondary),
743 const_iv (XIMTertiary),
744 const_iv (XIMVisibleToForward),
745 const_iv (XIMVisibleToBackword),
746 const_iv (XIMVisibleToCenter),
747# if 0
748 const_iv (XIMForwardChar),
749 const_iv (XIMBackwardChar),
750 const_iv (XIMForwardWord),
751 const_iv (XIMBackwardWord),
752 const_iv (XIMCaretUp),
753 const_iv (XIMCaretDown),
754 const_iv (XIMNextLine),
755 const_iv (XIMPreviousLine),
756 const_iv (XIMLineStart),
757 const_iv (XIMLineEnd),
758 const_iv (XIMAbsolutePosition),
759 const_iv (XIMDontChange),
760# endif
761# endif
847 }; 762 };
848 763
849 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); 764 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
850 civ-- > const_iv; )
851 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 765 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
852} 766}
853 767
854void 768void
855warn (const char *msg) 769warn (const char *msg)
865_exit (int status) 779_exit (int status)
866 780
867NV 781NV
868NOW () 782NOW ()
869 CODE: 783 CODE:
870 RETVAL = NOW; 784 RETVAL = ev::now ();
871 OUTPUT: 785 OUTPUT:
872 RETVAL 786 RETVAL
873 787
874int 788int
875GET_BASEFG (int rend) 789GET_BASEFG (int rend)
886 RETVAL 800 RETVAL
887 801
888int 802int
889SET_FGCOLOR (int rend, int new_color) 803SET_FGCOLOR (int rend, int new_color)
890 CODE: 804 CODE:
891 RETVAL = SET_FGCOLOR (rend, new_color); 805 RETVAL = SET_FGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
892 OUTPUT: 806 OUTPUT:
893 RETVAL 807 RETVAL
894 808
895int 809int
896SET_BGCOLOR (int rend, int new_color) 810SET_BGCOLOR (int rend, int new_color)
897 CODE: 811 CODE:
898 RETVAL = SET_BGCOLOR (rend, new_color); 812 RETVAL = SET_BGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
899 OUTPUT: 813 OUTPUT:
900 RETVAL 814 RETVAL
901 815
902int 816int
903GET_CUSTOM (int rend) 817GET_CUSTOM (int rend)
904 CODE: 818 CODE:
905 RETVAL = (rend && RS_customMask) >> RS_customShift; 819 RETVAL = (rend & RS_customMask) >> RS_customShift;
906 OUTPUT: 820 OUTPUT:
907 RETVAL 821 RETVAL
908 822
909int 823int
910SET_CUSTOM (int rend, int new_value) 824SET_CUSTOM (int rend, int new_value)
917 | ((new_value << RS_customShift) & RS_customMask); 831 | ((new_value << RS_customShift) & RS_customMask);
918} 832}
919 OUTPUT: 833 OUTPUT:
920 RETVAL 834 RETVAL
921 835
836void
837termlist ()
838 PPCODE:
839{
840 EXTEND (SP, rxvt_term::termlist.size ());
841
842 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
843 if ((*t)->perl.self)
844 PUSHs (sv_2mortal (newSVterm (*t)));
845}
846
922MODULE = urxvt PACKAGE = urxvt::term 847MODULE = urxvt PACKAGE = urxvt::term
923 848
924SV * 849SV *
925_new (...) 850_new (AV *env, AV *arg)
926 CODE: 851 CODE:
927{ 852{
928 if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV)
929 croak ("first argument to urxvt::term->_new must be arrayref");
930
931 rxvt_term *term = new rxvt_term; 853 rxvt_term *term = new rxvt_term;
932 854
933 stringvec *argv = new stringvec; 855 stringvec *argv = new stringvec;
934 stringvec *envv = new stringvec; 856 stringvec *envv = new stringvec;
935 857
936 for (int i = 1; i < items; i++) 858 for (int i = 0; i <= AvFILL (arg); i++)
937 argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); 859 argv->push_back (strdup (SvPVbyte_nolen (*av_fetch (arg, i, 1))));
938 860
939 AV *env = (AV *)SvRV (ST (0));
940 for (int i = AvFILL (env) + 1; i--; ) 861 for (int i = AvFILL (env) + 1; i--; )
941 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 862 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
942 863
943 envv->push_back (0); 864 envv->push_back (0);
944 865
945 bool success;
946
947 try 866 try
948 { 867 {
949 success = term->init (argv, envv); 868 term->init (argv, envv);
950 } 869 }
951 catch (const class rxvt_failure_exception &e) 870 catch (const class rxvt_failure_exception &e)
952 {
953 success = false;
954 }
955
956 if (!success)
957 { 871 {
958 term->destroy (); 872 term->destroy ();
959 croak ("error while initializing new terminal instance"); 873 croak ("error while initializing new terminal instance");
960 } 874 }
961 875
971void 885void
972rxvt_term::set_should_invoke (int htype, int inc) 886rxvt_term::set_should_invoke (int htype, int inc)
973 CODE: 887 CODE:
974 THIS->perl.should_invoke [htype] += inc; 888 THIS->perl.should_invoke [htype] += inc;
975 889
976void 890int
977rxvt_term::grab_button (int button, U32 modifiers) 891rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt)
978 CODE: 892 CODE:
979 XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, 893 RETVAL = XGrabButton (THIS->dpy, button, modifiers, window, 1,
980 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 894 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
981 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 895 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
896 OUTPUT: RETVAL
897
898int
899rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt)
900 CODE:
901 RETVAL = XUngrabButton (THIS->dpy, button, modifiers, window);
902 OUTPUT: RETVAL
903
904void
905rxvt_term::XGrabKey (int keycode, U32 modifiers, Window window = THIS->vt, \
906 int owner_events = 1, int pointer_mode = GrabModeAsync, int keyboard_mode = GrabModeAsync)
907 CODE:
908 XGrabKey (THIS->dpy, keycode, modifiers, window, owner_events, pointer_mode, keyboard_mode);
909
910void
911rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt)
912 CODE:
913 XUngrabKey (THIS->dpy, keycode, modifiers, window);
914
915void
916rxvt_term::XUngrabKeyboard (Time eventtime)
917 CODE:
918 XUngrabKeyboard (THIS->dpy, eventtime);
982 919
983bool 920bool
984rxvt_term::grab (Time eventtime, int sync = 0) 921rxvt_term::grab (Time eventtime, int sync = 0)
985 CODE: 922 CODE:
986{ 923{
987 int mode = sync ? GrabModeSync : GrabModeAsync; 924 int mode = sync ? GrabModeSync : GrabModeAsync;
988 925
989 THIS->perl.grabtime = 0; 926 THIS->perl.grabtime = 0;
990 927
991 if (!XGrabPointer (THIS->display->display, THIS->vt, 0, 928 if (!XGrabPointer (THIS->dpy, THIS->vt, 0,
992 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 929 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
993 mode, mode, None, GRAB_CURSOR, eventtime)) 930 mode, mode, None, GRAB_CURSOR, eventtime))
994 if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) 931 if (!XGrabKeyboard (THIS->dpy, THIS->vt, 0, mode, mode, eventtime))
995 THIS->perl.grabtime = eventtime; 932 THIS->perl.grabtime = eventtime;
996 else 933 else
997 XUngrabPointer (THIS->display->display, eventtime); 934 XUngrabPointer (THIS->dpy, eventtime);
998 935
999 RETVAL = !!THIS->perl.grabtime; 936 RETVAL = !!THIS->perl.grabtime;
1000} 937}
1001 OUTPUT: 938 OUTPUT:
1002 RETVAL 939 RETVAL
1003 940
1004void 941void
1005rxvt_term::allow_events_async () 942rxvt_term::allow_events_async ()
1006 CODE: 943 CODE:
1007 XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); 944 XAllowEvents (THIS->dpy, AsyncBoth, THIS->perl.grabtime);
1008 945
1009void 946void
1010rxvt_term::allow_events_sync () 947rxvt_term::allow_events_sync ()
1011 CODE: 948 CODE:
1012 XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); 949 XAllowEvents (THIS->dpy, SyncBoth, THIS->perl.grabtime);
1013 950
1014void 951void
1015rxvt_term::allow_events_replay () 952rxvt_term::allow_events_replay ()
1016 CODE: 953 CODE:
1017 XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); 954 XAllowEvents (THIS->dpy, ReplayPointer, THIS->perl.grabtime);
1018 XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); 955 XAllowEvents (THIS->dpy, ReplayKeyboard, THIS->perl.grabtime);
1019 956
1020void 957void
1021rxvt_term::ungrab () 958rxvt_term::ungrab ()
1022 CODE: 959 CODE:
1023 ungrab (THIS); 960 ungrab (THIS);
961
962int
963rxvt_term::XStringToKeysym (char *string)
964 CODE:
965 RETVAL = XStringToKeysym (string);
966 OUTPUT: RETVAL
967
968char *
969rxvt_term::XKeysymToString (int sym)
970 CODE:
971 RETVAL = XKeysymToString (sym);
972 OUTPUT: RETVAL
973
974int
975rxvt_term::XKeysymToKeycode (int sym)
976 CODE:
977 RETVAL = XKeysymToKeycode (THIS->dpy, sym);
978 OUTPUT: RETVAL
979
980int
981rxvt_term::XKeycodeToKeysym (int code, int index)
982 CODE:
983 RETVAL = XKeycodeToKeysym (THIS->dpy, code, index);
984 OUTPUT: RETVAL
1024 985
1025int 986int
1026rxvt_term::strwidth (SV *str) 987rxvt_term::strwidth (SV *str)
1027 CODE: 988 CODE:
1028{ 989{
1029 wchar_t *wstr = sv2wcs (str); 990 wchar_t *wstr = sv2wcs (str);
1030 991
1031 rxvt_push_locale (THIS->locale); 992 rxvt_push_locale (THIS->locale);
1032 RETVAL = wcswidth (wstr, wcslen (wstr)); 993 RETVAL = 0;
994 for (wchar_t *wc = wstr; *wc; wc++)
995 {
996 int w = WCWIDTH (*wc);
997
998 if (w)
999 RETVAL += max (w, 1);
1000 }
1033 rxvt_pop_locale (); 1001 rxvt_pop_locale ();
1034 1002
1035 free (wstr); 1003 free (wstr);
1036} 1004}
1037 OUTPUT: 1005 OUTPUT:
1067 rxvt_pop_locale (); 1035 rxvt_pop_locale ();
1068 1036
1069 RETVAL = wcs2sv (wstr); 1037 RETVAL = wcs2sv (wstr);
1070 free (wstr); 1038 free (wstr);
1071} 1039}
1040 OUTPUT:
1041 RETVAL
1042
1043char *
1044rxvt_term::locale ()
1045 CODE:
1046 RETVAL = THIS->locale;
1072 OUTPUT: 1047 OUTPUT:
1073 RETVAL 1048 RETVAL
1074 1049
1075#define TERM_OFFSET(sym) offsetof (TermWin_t, sym) 1050#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
1076 1051
1126 { 1101 {
1127 case 0: RETVAL = THIS->ModLevel3Mask; break; 1102 case 0: RETVAL = THIS->ModLevel3Mask; break;
1128 case 1: RETVAL = THIS->ModMetaMask; break; 1103 case 1: RETVAL = THIS->ModMetaMask; break;
1129 case 2: RETVAL = THIS->ModNumLockMask; break; 1104 case 2: RETVAL = THIS->ModNumLockMask; break;
1130 case 3: RETVAL = THIS->current_screen; break; 1105 case 3: RETVAL = THIS->current_screen; break;
1106#ifdef CURSOR_BLINK
1131 case 4: RETVAL = THIS->hidden_cursor; break; 1107 case 4: RETVAL = THIS->hidden_cursor; break;
1108#endif
1132 } 1109 }
1133 OUTPUT: 1110 OUTPUT:
1134 RETVAL 1111 RETVAL
1135 1112
1136char * 1113char *
1146 } 1123 }
1147 OUTPUT: 1124 OUTPUT:
1148 RETVAL 1125 RETVAL
1149 1126
1150SV * 1127SV *
1151rxvt_term::_env () 1128rxvt_term::envv ()
1129 ALIAS:
1130 argv = 1
1152 CODE: 1131 PPCODE:
1153{ 1132{
1154 if (THIS->envv) 1133 stringvec *vec = ix ? THIS->argv : THIS->envv;
1155 {
1156 AV *av = newAV ();
1157 1134
1135 EXTEND (SP, vec->size ());
1136
1158 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) 1137 for (char **i = vec->begin (); i != vec->end (); ++i)
1159 if (*i) 1138 if (*i)
1160 av_push (av, newSVpv (*i, 0)); 1139 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1161
1162 RETVAL = newRV_noinc ((SV *)av);
1163 }
1164 else
1165 RETVAL = &PL_sv_undef;
1166} 1140}
1167 OUTPUT:
1168 RETVAL
1169 1141
1170int 1142int
1171rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1143rxvt_term::pty_ev_events (int events = ev::UNDEF)
1172 CODE: 1144 CODE:
1173 RETVAL = THIS->pty_ev.events; 1145 RETVAL = THIS->pty_ev.events;
1174 if (events != EVENT_UNDEF) 1146 if (events != ev::UNDEF)
1175 THIS->pty_ev.set (events); 1147 THIS->pty_ev.set (events);
1148 OUTPUT:
1149 RETVAL
1150
1151int
1152rxvt_term::pty_fd ()
1153 CODE:
1154 RETVAL = THIS->pty->pty;
1176 OUTPUT: 1155 OUTPUT:
1177 RETVAL 1156 RETVAL
1178 1157
1179Window 1158Window
1180rxvt_term::parent () 1159rxvt_term::parent ()
1222 1201
1223void 1202void
1224rxvt_term::focus_out () 1203rxvt_term::focus_out ()
1225 1204
1226void 1205void
1206rxvt_term::key_press (unsigned int state, unsigned int keycode, Time time = CurrentTime)
1207 ALIAS:
1208 key_release = 1
1209 CODE:
1210{
1211 XKeyEvent xkey;
1212
1213 memset (&xkey, 0, sizeof (xkey));
1214
1215 xkey.time = time;
1216 xkey.state = state;
1217 xkey.keycode = keycode;
1218
1219 xkey.type = ix ? KeyRelease : KeyPress;
1220 xkey.display = THIS->dpy;
1221 xkey.window = THIS->vt;
1222 xkey.root = THIS->display->root;
1223 xkey.subwindow = THIS->vt;
1224
1225 if (ix)
1226 THIS->key_release (xkey);
1227 else
1228 THIS->key_press (xkey);
1229}
1230
1231void
1227rxvt_term::want_refresh () 1232rxvt_term::want_refresh ()
1228 CODE: 1233 CODE:
1229 THIS->want_refresh = 1; 1234 THIS->want_refresh = 1;
1235 THIS->refresh_check ();
1230 1236
1231void 1237void
1232rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1238rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1233 PPCODE: 1239 PPCODE:
1234{ 1240{
1237 1243
1238 line_t &l = ROW(row_number); 1244 line_t &l = ROW(row_number);
1239 1245
1240 if (GIMME_V != G_VOID) 1246 if (GIMME_V != G_VOID)
1241 { 1247 {
1242 wchar_t *wstr = new wchar_t [THIS->ncol]; 1248 wchar_t *wstr = rxvt_temp_buf<wchar_t> (THIS->ncol);
1243 1249
1244 for (int col = 0; col < THIS->ncol; col++) 1250 for (int col = 0; col < THIS->ncol; col++)
1245 wstr [col] = l.t [col]; 1251 wstr [col] = l.t [col];
1246 1252
1247 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); 1253 XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol)));
1248
1249 delete [] wstr;
1250 } 1254 }
1251 1255
1252 if (new_text) 1256 if (new_text)
1253 { 1257 {
1254 wchar_t *wstr = sv2wcs (new_text); 1258 wchar_t *wstr = sv2wcs (new_text);
1347rxvt_term::special_encode (SV *string) 1351rxvt_term::special_encode (SV *string)
1348 CODE: 1352 CODE:
1349{ 1353{
1350 wchar_t *wstr = sv2wcs (string); 1354 wchar_t *wstr = sv2wcs (string);
1351 int wlen = wcslen (wstr); 1355 int wlen = wcslen (wstr);
1352 wchar_t *rstr = new wchar_t [wlen]; // cannot become longer 1356 wchar_t *rstr = rxvt_temp_buf<wchar_t> (wlen * 2); // cannot become longer
1353 1357
1354 rxvt_push_locale (THIS->locale); 1358 rxvt_push_locale (THIS->locale);
1355 1359
1356 wchar_t *r = rstr; 1360 wchar_t *r = rstr;
1357 for (wchar_t *s = wstr; *s; s++) 1361 for (wchar_t *s = wstr; *s; s++)
1362 {
1363 int w = WCWIDTH (*s);
1364
1358 if (wcwidth (*s) == 0) 1365 if (w == 0)
1359 { 1366 {
1360 if (r == rstr) 1367 if (r == rstr)
1361 croak ("leading combining character unencodable"); 1368 croak ("leading combining character unencodable");
1362 1369
1363 unicode_t n = rxvt_compose (r[-1], *s); 1370 unicode_t n = rxvt_compose (r[-1], *s);
1364 if (n == NOCHAR) 1371 if (n == NOCHAR)
1365 n = rxvt_composite.compose (r[-1], *s); 1372 n = rxvt_composite.compose (r[-1], *s);
1366 1373
1367 r[-1] = n; 1374 r[-1] = n;
1368 } 1375 }
1369#if !UNICODE_3 1376#if !UNICODE_3
1370 else if (*s >= 0x10000) 1377 else if (*s >= 0x10000)
1371 *r++ = rxvt_composite.compose (*s); 1378 *r++ = rxvt_composite.compose (*s);
1372#endif 1379#endif
1373 else 1380 else
1374 *r++ = *s; 1381 *r++ = *s;
1382
1383 // the *2 above only allows wcwidth <= 2
1384 if (w > 1)
1385 *r++ = NOCHAR;
1386 }
1375 1387
1376 rxvt_pop_locale (); 1388 rxvt_pop_locale ();
1377 1389
1378 RETVAL = wcs2sv (rstr, r - rstr); 1390 RETVAL = wcs2sv (rstr, r - rstr);
1379
1380 delete [] rstr;
1381} 1391}
1382 OUTPUT: 1392 OUTPUT:
1383 RETVAL 1393 RETVAL
1384 1394
1385SV * 1395SV *
1386rxvt_term::special_decode (SV *text) 1396rxvt_term::special_decode (SV *text)
1387 CODE: 1397 CODE:
1388{ 1398{
1389 wchar_t *wstr = sv2wcs (text); 1399 wchar_t *wstr = sv2wcs (text);
1390 int wlen = wcslen (wstr);
1391 int dlen = 0; 1400 int dlen = 0;
1392 1401
1393 // find length 1402 // find length
1394 for (wchar_t *s = wstr; *s; s++) 1403 for (wchar_t *s = wstr; *s; s++)
1395 if (*s == NOCHAR) 1404 if (*s == NOCHAR)
1397 else if (IS_COMPOSE (*s)) 1406 else if (IS_COMPOSE (*s))
1398 dlen += rxvt_composite.expand (*s, 0); 1407 dlen += rxvt_composite.expand (*s, 0);
1399 else 1408 else
1400 dlen++; 1409 dlen++;
1401 1410
1402 wchar_t *rstr = new wchar_t [dlen]; 1411 wchar_t *rstr = rxvt_temp_buf<wchar_t> (dlen);
1403 1412
1404 // decode 1413 // decode
1405 wchar_t *r = rstr; 1414 wchar_t *r = rstr;
1406 for (wchar_t *s = wstr; *s; s++) 1415 for (wchar_t *s = wstr; *s; s++)
1407 if (*s == NOCHAR) 1416 if (*s == NOCHAR)
1410 r += rxvt_composite.expand (*s, r); 1419 r += rxvt_composite.expand (*s, r);
1411 else 1420 else
1412 *r++ = *s; 1421 *r++ = *s;
1413 1422
1414 RETVAL = wcs2sv (rstr, r - rstr); 1423 RETVAL = wcs2sv (rstr, r - rstr);
1415
1416 delete [] rstr;
1417} 1424}
1418 OUTPUT: 1425 OUTPUT:
1419 RETVAL 1426 RETVAL
1420 1427
1421void 1428void
1422rxvt_term::_resource (char *name, int index, SV *newval = 0) 1429rxvt_term::_resource (char *name, int index, SV *newval = 0)
1423 PPCODE: 1430 PPCODE:
1424{ 1431{
1425 struct resval { const char *name; int value; } rslist [] = { 1432 static const struct resval { const char *name; int value; } *rs, rslist [] = {
1426# define def(name) { # name, Rs_ ## name }, 1433# define def(name) { # name, Rs_ ## name },
1427# define reserve(name,count) 1434# define reserve(name,count)
1428# include "rsinc.h" 1435# include "rsinc.h"
1429# undef def 1436# undef def
1430# undef reserve 1437# undef reserve
1431 }; 1438 };
1432 1439
1433 struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1440 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1434 1441
1442 if (*name)
1435 do { 1443 {
1444 do {
1436 if (rs-- == rslist) 1445 if (rs-- == rslist)
1437 croak ("no such resource '%s', requested", name); 1446 croak ("no such resource '%s', requested", name);
1438 } while (strcmp (name, rs->name)); 1447 } while (strcmp (name, rs->name));
1439 1448
1440 index += rs->value; 1449 index += rs->value;
1450 }
1451 else
1452 {
1453 --rs;
1454 name = "";
1455 }
1441 1456
1442 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1457 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1443 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1458 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1444 1459
1445 if (GIMME_V != G_VOID) 1460 if (GIMME_V != G_VOID)
1460 1475
1461const char * 1476const char *
1462rxvt_term::x_resource (const char *name) 1477rxvt_term::x_resource (const char *name)
1463 1478
1464bool 1479bool
1465rxvt_term::option (U32 optval, int set = -1) 1480rxvt_term::option (U8 optval, int set = -1)
1466 CODE: 1481 CODE:
1467{ 1482{
1468 RETVAL = THIS->options & optval; 1483 RETVAL = THIS->option (optval);
1469 1484
1470 if (set >= 0) 1485 if (set >= 0)
1471 { 1486 {
1472 if (set)
1473 THIS->options |= optval; 1487 THIS->set_option (optval, set);
1474 else
1475 THIS->options &= ~optval;
1476 1488
1477 if (THIS->check_ev.is_active ()) // avoid doing this before START 1489 if (THIS->env_colorfgbg [0]) // avoid doing this before START
1478 switch (optval) 1490 switch (optval)
1479 { 1491 {
1480 case Opt_skipBuiltinGlyphs: 1492 case Opt_skipBuiltinGlyphs:
1481 THIS->set_fonts (); 1493 THIS->set_fonts ();
1482 THIS->scr_remap_chars (); 1494 THIS->scr_remap_chars ();
1483 THIS->scr_touch (true); 1495 THIS->scr_touch (true);
1484 THIS->want_refresh = 1; 1496 THIS->want_refresh = 1;
1497 THIS->refresh_check ();
1485 break; 1498 break;
1486 1499
1487 case Opt_cursorUnderline: 1500 case Opt_cursorUnderline:
1488 THIS->want_refresh = 1; 1501 THIS->want_refresh = 1;
1502 THIS->refresh_check ();
1489 break; 1503 break;
1490 1504
1491# case Opt_scrollBar_floating: 1505# case Opt_scrollBar_floating:
1492# case Opt_scrollBar_right: 1506# case Opt_scrollBar_right:
1493# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1507# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1551 1565
1552 clamp_it (rc.col, 0, THIS->ncol); 1566 clamp_it (rc.col, 0, THIS->ncol);
1553 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1567 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1554 1568
1555 if (ix) 1569 if (ix)
1570 {
1556 THIS->want_refresh = 1; 1571 THIS->want_refresh = 1;
1572 THIS->refresh_check ();
1573 }
1557 } 1574 }
1558} 1575}
1559 1576
1560char 1577char
1561rxvt_term::cur_charset () 1578rxvt_term::cur_charset ()
1562 CODE: 1579 CODE:
1563 RETVAL = THIS->charsets [THIS->screen.charset]; 1580 RETVAL = THIS->charsets [THIS->screen.charset];
1564 OUTPUT: 1581 OUTPUT:
1565 RETVAL 1582 RETVAL
1566 1583
1567#void 1584void
1568#rxvt_term::selection_clear () 1585rxvt_term::selection_clear ()
1569 1586
1570void 1587void
1571rxvt_term::selection_make (Time eventtime, bool rect = false) 1588rxvt_term::selection_make (Time eventtime, bool rect = false)
1572 CODE: 1589 CODE:
1573 THIS->selection.op = SELECTION_CONT; 1590 THIS->selection.op = SELECTION_CONT;
1663void 1680void
1664rxvt_term::XListProperties (Window window) 1681rxvt_term::XListProperties (Window window)
1665 PPCODE: 1682 PPCODE:
1666{ 1683{
1667 int count; 1684 int count;
1668 Atom *props = XListProperties (THIS->display->display, window, &count); 1685 Atom *props = XListProperties (THIS->dpy, window, &count);
1669 1686
1670 EXTEND (SP, count); 1687 EXTEND (SP, count);
1671 while (count--) 1688 while (count--)
1672 PUSHs (newSVuv ((U32)props [count])); 1689 PUSHs (newSVuv ((U32)props [count]));
1673 1690
1674 XFree (props); 1691 XFree (props);
1675} 1692}
1676 1693
1677void 1694void
1678rxvt_term::XGetWindowProperty (Window window, Atom property) 1695rxvt_term::XGetWindowProperty (Window window, Atom property)
1682 int format; 1699 int format;
1683 unsigned long nitems; 1700 unsigned long nitems;
1684 unsigned long bytes_after; 1701 unsigned long bytes_after;
1685 unsigned char *prop; 1702 unsigned char *prop;
1686 1703
1687 XGetWindowProperty (THIS->display->display, window, property, 1704 XGetWindowProperty (THIS->dpy, window, property,
1688 0, 1<<24, 0, AnyPropertyType, 1705 0, 1<<24, 0, AnyPropertyType,
1689 &type, &format, &nitems, &bytes_after, &prop); 1706 &type, &format, &nitems, &bytes_after, &prop);
1690 1707
1691 if (type != None) 1708 if (type != None)
1692 { 1709 {
1701 XFree (prop); 1718 XFree (prop);
1702 } 1719 }
1703} 1720}
1704 1721
1705void 1722void
1706rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data) 1723rxvt_term::XChangeProperty (Window window, Atom property, Atom type, int format, SV *data)
1707 CODE: 1724 CODE:
1708{ 1725{
1709 STRLEN len; 1726 STRLEN len;
1710 char *data_ = SvPVbyte (data, len); 1727 char *data_ = SvPVbyte (data, len);
1711 1728
1712 int elemsize = format == 16 ? sizeof (short) 1729 int elemsize = format == 16 ? sizeof (short)
1713 : format == 32 ? sizeof (long) 1730 : format == 32 ? sizeof (long)
1714 : 1; 1731 : 1;
1715 1732
1716 XChangeProperty (THIS->display->display, window, property, 1733 XChangeProperty (THIS->dpy, window, property,
1717 type, format, PropModeReplace, 1734 type, format, PropModeReplace,
1718 (unsigned char *)data_, len / elemsize); 1735 (unsigned char *)data_, len / elemsize);
1719 XSync (THIS->display->display, 0);
1720} 1736}
1721 1737
1722Atom 1738Atom
1723XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE) 1739XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1724 C_ARGS: term->display->display, atom_name, only_if_exists 1740 C_ARGS: term->dpy, atom_name, only_if_exists
1725 1741
1726char * 1742char *
1727XGetAtomName (rxvt_term *term, Atom atom) 1743XGetAtomName (rxvt_term *term, Atom atom)
1728 C_ARGS: term->display->display, atom 1744 C_ARGS: term->dpy, atom
1729 CLEANUP: 1745 CLEANUP:
1730 XFree (RETVAL); 1746 XFree (RETVAL);
1731 1747
1732void 1748void
1733XDeleteProperty (rxvt_term *term, Window window, Atom property) 1749XDeleteProperty (rxvt_term *term, Window window, Atom property)
1734 C_ARGS: term->display->display, window, property 1750 C_ARGS: term->dpy, window, property
1735 1751
1736Window 1752Window
1737rxvt_term::DefaultRootWindow () 1753rxvt_term::DefaultRootWindow ()
1738 CODE: 1754 CODE:
1739 RETVAL = THIS->display->root; 1755 RETVAL = THIS->display->root;
1742 1758
1743#if 0 1759#if 0
1744 1760
1745Window 1761Window
1746XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height) 1762XCreateSimpleWindow (rxvt_term *term, Window parent, int x, int y, unsigned int width, unsigned int height)
1747 C_ARGS: term->display->display, (Window)parent, 1763 C_ARGS: term->dpy, (Window)parent,
1748 x, y, width, height, 0, 1764 x, y, width, height, 0,
1749 term->pix_colors_focused[Color_border], 1765 term->pix_colors_focused[Color_border],
1750 term->pix_colors_focused[Color_border] 1766 term->pix_colors_focused[Color_border]
1751 1767
1752#endif 1768#endif
1753 1769
1754void 1770void
1755XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0) 1771XReparentWindow (rxvt_term *term, Window window, Window parent, int x = 0, int y = 0)
1756 C_ARGS: term->display->display, window, parent, x, y 1772 C_ARGS: term->dpy, window, parent, x, y
1757 1773
1758void 1774void
1759XMapWindow (rxvt_term *term, Window window) 1775XMapWindow (rxvt_term *term, Window window)
1760 C_ARGS: term->display->display, window 1776 C_ARGS: term->dpy, window
1761 1777
1762void 1778void
1763XUnmapWindow (rxvt_term *term, Window window) 1779XUnmapWindow (rxvt_term *term, Window window)
1764 C_ARGS: term->display->display, window 1780 C_ARGS: term->dpy, window
1765 1781
1766void 1782void
1767XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height) 1783XMoveResizeWindow (rxvt_term *term, Window window, int x, int y, unsigned int width, unsigned int height)
1768 C_ARGS: term->display->display, window, x, y, width, height 1784 C_ARGS: term->dpy, window, x, y, width, height
1769 1785
1770void 1786void
1771rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0) 1787rxvt_term::XChangeInput (Window window, U32 add_events, U32 del_events = 0)
1772 CODE: 1788 CODE:
1773{ 1789{
1774 XWindowAttributes attr; 1790 XWindowAttributes attr;
1775 XGetWindowAttributes (THIS->display->display, window, &attr); 1791 XGetWindowAttributes (THIS->dpy, window, &attr);
1776 XSelectInput (THIS->display->display, window, attr.your_event_mask | add_events & ~del_events); 1792 XSelectInput (THIS->dpy, window, attr.your_event_mask | add_events & ~del_events);
1777} 1793}
1778 1794
1779void 1795void
1780rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y) 1796rxvt_term::XTranslateCoordinates (Window src, Window dst, int x, int y)
1781 PPCODE: 1797 PPCODE:
1782{ 1798{
1783 int dx, dy; 1799 int dx, dy;
1784 Window child; 1800 Window child;
1785 1801
1786 if (XTranslateCoordinates (THIS->display->display, src, dst, x, y, &dx, &dy, &child)) 1802 if (XTranslateCoordinates (THIS->dpy, src, dst, x, y, &dx, &dy, &child))
1787 { 1803 {
1788 EXTEND (SP, 3); 1804 EXTEND (SP, 3);
1789 PUSHs (newSViv (dx)); 1805 PUSHs (newSViv (dx));
1790 PUSHs (newSViv (dy)); 1806 PUSHs (newSViv (dy));
1791 PUSHs (newSVuv (child)); 1807 PUSHs (newSVuv (child));
1808overlay::hide () 1824overlay::hide ()
1809 1825
1810void 1826void
1811overlay::DESTROY () 1827overlay::DESTROY ()
1812 1828
1813############################################################################# 1829INCLUDE: $PERL <iom_perl.xs -pe s/IOM_MODULE/urxvt/g,s/IOM_CLASS/urxvt/g |
1814# urxvt::watcher
1815#############################################################################
1816 1830
1817MODULE = urxvt PACKAGE = urxvt::watcher
1818
1819CHAINED
1820perl_watcher::cb (SV *cb)
1821 CODE:
1822 THIS->cb (cb);
1823 OUTPUT:
1824 RETVAL
1825
1826#############################################################################
1827# urxvt::timer
1828#############################################################################
1829
1830MODULE = urxvt PACKAGE = urxvt::timer
1831
1832SV *
1833timer::new ()
1834 CODE:
1835 timer *w = new timer;
1836 w->start (NOW);
1837 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::timer");
1838 w->self = (HV *)SvRV (RETVAL);
1839 OUTPUT:
1840 RETVAL
1841
1842NV
1843timer::at ()
1844 CODE:
1845 RETVAL = THIS->at;
1846 OUTPUT:
1847 RETVAL
1848
1849CHAINED
1850timer::interval (NV interval)
1851 CODE:
1852 THIS->interval = interval;
1853 OUTPUT:
1854 RETVAL
1855
1856CHAINED
1857timer::set (NV tstamp)
1858 CODE:
1859 THIS->set (tstamp);
1860 OUTPUT:
1861 RETVAL
1862
1863CHAINED
1864timer::start (NV tstamp = THIS->at)
1865 CODE:
1866 THIS->start (tstamp);
1867 OUTPUT:
1868 RETVAL
1869
1870CHAINED
1871timer::after (NV delay)
1872 CODE:
1873 THIS->start (NOW + delay);
1874 OUTPUT:
1875 RETVAL
1876
1877CHAINED
1878timer::stop ()
1879 CODE:
1880 THIS->stop ();
1881 OUTPUT:
1882 RETVAL
1883
1884void
1885timer::DESTROY ()
1886
1887#############################################################################
1888# urxvt::iow
1889#############################################################################
1890
1891MODULE = urxvt PACKAGE = urxvt::iow
1892
1893SV *
1894iow::new ()
1895 CODE:
1896 iow *w = new iow;
1897 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iow");
1898 w->self = (HV *)SvRV (RETVAL);
1899 OUTPUT:
1900 RETVAL
1901
1902CHAINED
1903iow::fd (int fd)
1904 CODE:
1905 THIS->fd = fd;
1906 OUTPUT:
1907 RETVAL
1908
1909CHAINED
1910iow::events (short events)
1911 CODE:
1912 THIS->events = events;
1913 OUTPUT:
1914 RETVAL
1915
1916CHAINED
1917iow::start ()
1918 CODE:
1919 THIS->start ();
1920 OUTPUT:
1921 RETVAL
1922
1923CHAINED
1924iow::stop ()
1925 CODE:
1926 THIS->stop ();
1927 OUTPUT:
1928 RETVAL
1929
1930void
1931iow::DESTROY ()
1932
1933#############################################################################
1934# urxvt::iw
1935#############################################################################
1936
1937MODULE = urxvt PACKAGE = urxvt::iw
1938
1939SV *
1940iw::new ()
1941 CODE:
1942 iw *w = new iw;
1943 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iw");
1944 w->self = (HV *)SvRV (RETVAL);
1945 OUTPUT:
1946 RETVAL
1947
1948CHAINED
1949iw::start ()
1950 CODE:
1951 THIS->start ();
1952 OUTPUT:
1953 RETVAL
1954
1955CHAINED
1956iw::stop ()
1957 CODE:
1958 THIS->stop ();
1959 OUTPUT:
1960 RETVAL
1961
1962void
1963iw::DESTROY ()
1964
1965#############################################################################
1966# urxvt::pw
1967#############################################################################
1968
1969MODULE = urxvt PACKAGE = urxvt::pw
1970
1971SV *
1972pw::new ()
1973 CODE:
1974 pw *w = new pw;
1975 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::pw");
1976 w->self = (HV *)SvRV (RETVAL);
1977 OUTPUT:
1978 RETVAL
1979
1980CHAINED
1981pw::start (int pid)
1982 CODE:
1983 THIS->start (pid);
1984 OUTPUT:
1985 RETVAL
1986
1987CHAINED
1988pw::stop ()
1989 CODE:
1990 THIS->stop ();
1991 OUTPUT:
1992 RETVAL
1993
1994void
1995pw::DESTROY ()
1996
1997

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines