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.97 by root, Sat Feb 4 16:12:48 2006 UTC vs.
Revision 1.127 by root, Sat May 30 08:51:23 2009 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
85static SV *
86newSVptr (void *ptr, const char *klass) 74newSVptr (void *ptr, const char *klass)
87{ 75{
88 HV *hv = newHV (); 76 HV *hv = newHV ();
89 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 77 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
90 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 78 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
117#define newSVterm(term) SvREFCNT_inc ((SV *)(term)->perl.self) 105#define newSVterm(term) SvREFCNT_inc ((SV *)(term)->perl.self)
118#define SvTERM(sv) (rxvt_term *)SvPTR ((sv), "urxvt::term") 106#define SvTERM(sv) (rxvt_term *)SvPTR ((sv), "urxvt::term")
119 107
120///////////////////////////////////////////////////////////////////////////// 108/////////////////////////////////////////////////////////////////////////////
121 109
122#define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, "urxvt::watcher")
123
124struct perl_watcher
125{
126 SV *cbsv;
127 HV *self;
128
129 perl_watcher ()
130 : cbsv (0)
131 {
132 }
133
134 ~perl_watcher ()
135 {
136 SvREFCNT_dec (cbsv);
137 }
138
139 void cb (SV *cb)
140 {
141 SvREFCNT_dec (cbsv);
142 cbsv = newSVsv (cb);
143 }
144
145 void invoke (const char *type, SV *self, int arg = -1);
146};
147
148void
149perl_watcher::invoke (const char *type, SV *self, int arg)
150{
151 dSP;
152
153 ENTER;
154 SAVETMPS;
155
156 PUSHMARK (SP);
157
158 XPUSHs (sv_2mortal (self));
159
160 if (arg >= 0)
161 XPUSHs (sv_2mortal (newSViv (arg)));
162
163 PUTBACK;
164 call_sv (cbsv, G_VOID | G_EVAL | G_DISCARD);
165 SPAGAIN;
166
167 PUTBACK;
168 FREETMPS;
169 LEAVE;
170
171 if (SvTRUE (ERRSV))
172 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
173}
174
175#define newSVtimer(timer) new_ref ((timer)->self, "urxvt::timer")
176#define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR ((sv), "urxvt::timer")
177
178struct timer : perl_watcher, time_watcher
179{
180 tstamp interval;
181
182 timer ()
183 : time_watcher (this, &timer::execute)
184 {
185 }
186
187 void execute (time_watcher &w)
188 {
189 if (interval)
190 start (at + interval);
191
192 invoke ("urxvt::timer", newSVtimer (this));
193 }
194};
195
196#define newSViow(iow) new_ref ((iow)->self, "urxvt::iow")
197#define SvIOW(sv) (iow *)(perl_watcher *)SvPTR ((sv), "urxvt::iow")
198
199struct iow : perl_watcher, io_watcher
200{
201 iow ()
202 : io_watcher (this, &iow::execute)
203 {
204 }
205
206 void execute (io_watcher &w, short revents)
207 {
208 invoke ("urxvt::iow", newSViow (this), revents);
209 }
210};
211
212#define newSViw(iw) new_ref ((iw)->self, "urxvt::iw")
213#define SvIW(sv) (iw *)(perl_watcher *)SvPTR ((sv), "urxvt::iw")
214
215struct iw : perl_watcher, idle_watcher
216{
217 iw ()
218 : idle_watcher (this, &iw::execute)
219 {
220 }
221
222 void execute (idle_watcher &w)
223 {
224 invoke ("urxvt::iw", newSViw (this));
225 }
226};
227
228#define newSVpw(pw) new_ref ((pw)->self, "urxvt::pw")
229#define SvPW(sv) (pw *)(perl_watcher *)SvPTR ((sv), "urxvt::pw")
230
231struct pw : perl_watcher, child_watcher
232{
233 pw ()
234 : child_watcher (this, &pw::execute)
235 {
236 }
237
238 void execute (child_watcher &w, int status)
239 {
240 invoke ("urxvt::pw", newSVpw (this), status);
241 }
242};
243
244/////////////////////////////////////////////////////////////////////////////
245
246#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") 110#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay")
247 111
248class overlay { 112class overlay : overlay_base
113{
249 rxvt_term *THIS; 114 rxvt_term *THIS;
250 AV *overlay_av; 115 AV *overlay_av;
251 int x, y, w, h;
252 int border; 116 int border;
253 text_t **text;
254 rend_t **rend;
255 117
256public: 118public:
257 HV *self; 119 HV *self;
258 120
259 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); 121 overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
266 128
267 void set (int x, int y, SV *str, SV *rend); 129 void set (int x, int y, SV *str, SV *rend);
268}; 130};
269 131
270overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) 132overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border)
271: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0) 133: THIS(THIS), border(border == 2), overlay_av (0)
272{ 134{
135 x = x_;
136 y = y_;
137 w = w_;
138 h = h_;
139
140 if (w < 0) w = 0;
141 if (h < 0) h = 0;
142
273 if (border == 2) 143 if (border == 2)
274 { 144 {
275 w += 2; 145 w += 2;
276 h += 2; 146 h += 2;
277 } 147 }
343 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0) 213 *hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)
344 )); 214 ));
345 av_push (overlay_av, newSViv ((long)this)); 215 av_push (overlay_av, newSViv ((long)this));
346 216
347 THIS->want_refresh = 1; 217 THIS->want_refresh = 1;
218 THIS->refresh_check ();
348} 219}
349 220
350void 221void
351overlay::hide () 222overlay::hide ()
352{ 223{
355 226
356 int i; 227 int i;
357 228
358 for (i = AvFILL (overlay_av); i >= 0; i--) 229 for (i = AvFILL (overlay_av); i >= 0; i--)
359 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this) 230 if (SvIV (*av_fetch (overlay_av, i, 1)) == (long)this)
360 {
361 av_delete (overlay_av, i, G_DISCARD);
362 break; 231 break;
363 }
364 232
365 for (; i < AvFILL (overlay_av); i++) 233 for (; i < AvFILL (overlay_av); i++)
366 av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0))); 234 av_store (overlay_av, i, SvREFCNT_inc (*av_fetch (overlay_av, i + 1, 0)));
367 235
368 av_pop (overlay_av); 236 av_pop (overlay_av);
369 237
370 SvREFCNT_dec (overlay_av); 238 SvREFCNT_dec (overlay_av);
371 overlay_av = 0; 239 overlay_av = 0;
372 240
373 THIS->want_refresh = 1; 241 THIS->want_refresh = 1;
242 THIS->refresh_check ();
374} 243}
375 244
376void overlay::swap () 245void overlay::swap ()
377{ 246{
378 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); 247 int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
379 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); 248 int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h));
380 249
381 int ov_w = min (w, THIS->ncol - ov_x); 250 int ov_w = min (w, THIS->ncol - ov_x);
382 int ov_h = min (h, THIS->nrow - ov_y); 251 int ov_h = min (h, THIS->nrow - ov_y);
252
253 // hide cursor if it is within the overlay area
254 if (IN_RANGE_EXC (THIS->screen.cur.col - ov_x, 0, ov_w)
255 && IN_RANGE_EXC (THIS->screen.cur.row - ov_y, 0, ov_h))
256 THIS->screen.flags &= ~Screen_VisibleCursor;
383 257
384 for (int y = ov_h; y--; ) 258 for (int y = ov_h; y--; )
385 { 259 {
386 text_t *t1 = text [y]; 260 text_t *t1 = text [y];
387 rend_t *r1 = rend [y]; 261 rend_t *r1 = rend [y];
423 for (int col = min (AvFILL (av) + 1, w - x - border); col--; ) 297 for (int col = min (AvFILL (av) + 1, w - x - border); col--; )
424 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); 298 this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1));
425 } 299 }
426 300
427 THIS->want_refresh = 1; 301 THIS->want_refresh = 1;
302 THIS->refresh_check ();
428} 303}
429 304
305/////////////////////////////////////////////////////////////////////////////
306
307#define IOM_CLASS "urxvt"
308#define IOM_WARN rxvt_warn
309#include "iom_perl.h"
430 310
431///////////////////////////////////////////////////////////////////////////// 311/////////////////////////////////////////////////////////////////////////////
432 312
433struct rxvt_perl_interp rxvt_perl; 313struct rxvt_perl_interp rxvt_perl;
434 314
438{ 318{
439 if (perl) 319 if (perl)
440 { 320 {
441 perl_destruct (perl); 321 perl_destruct (perl);
442 perl_free (perl); 322 perl_free (perl);
323 PERL_SYS_TERM ();
443 } 324 }
444} 325}
445 326
446void 327void
447rxvt_perl_interp::init (rxvt_term *term) 328rxvt_perl_interp::init (rxvt_term *term)
451 rxvt_push_locale (""); // perl init destroys current locale 332 rxvt_push_locale (""); // perl init destroys current locale
452 333
453 perl_environ = rxvt_environ; 334 perl_environ = rxvt_environ;
454 swap (perl_environ, environ); 335 swap (perl_environ, environ);
455 336
456 char *argv[] = { 337 char *args[] = {
457 "", 338 "",
458 "-e" 339 "-e"
459 "BEGIN {" 340 "BEGIN {"
460 " urxvt->bootstrap;" 341 " urxvt->bootstrap;"
461 " unshift @INC, '" LIBDIR "';" 342 " unshift @INC, '" LIBDIR "';"
462 "}" 343 "}"
463 "" 344 ""
464 "use urxvt;" 345 "use urxvt;"
465 }; 346 };
347 int argc = sizeof (args) / sizeof (args[0]);
348 char **argv = args;
466 349
350 PERL_SYS_INIT3 (&argc, &argv, &environ);
467 perl = perl_alloc (); 351 perl = perl_alloc ();
468 perl_construct (perl); 352 perl_construct (perl);
469 353
470 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 354 if (perl_parse (perl, xs_init, argc, argv, (char **)NULL)
471 || perl_run (perl)) 355 || perl_run (perl))
472 { 356 {
473 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); 357 rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n");
474 358
475 perl_destruct (perl); 359 perl_destruct (perl);
509 393
510 // pre-handling of some events 394 // pre-handling of some events
511 if (htype == HOOK_REFRESH_END) 395 if (htype == HOOK_REFRESH_END)
512 { 396 {
513 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 397 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
514 398
515 for (int i = 0; i <= AvFILL (av); i++) 399 for (int i = 0; i <= AvFILL (av); i++)
516 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 400 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
517 } 401 }
518 402
519 swap (perl_environ, environ); 403 swap (perl_environ, environ);
718 602
719 // post-handling of some events 603 // post-handling of some events
720 if (htype == HOOK_REFRESH_BEGIN) 604 if (htype == HOOK_REFRESH_BEGIN)
721 { 605 {
722 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); 606 AV *av = (AV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
723 607
724 for (int i = AvFILL (av); i >= 0; i--) 608 for (int i = AvFILL (av); i >= 0; i--)
725 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap (); 609 ((overlay *)SvIV (*av_fetch (av, i, 0)))->swap ();
726 } 610 }
727 else if (htype == HOOK_DESTROY) 611 else if (htype == HOOK_DESTROY)
728 { 612 {
729 clearSVptr ((SV *)term->perl.self); 613 clearSVptr ((SV *)term->perl.self);
730 SvREFCNT_dec ((SV *)term->perl.self); 614 SvREFCNT_dec ((SV *)term->perl.self);
731 615
732 // don't allow further calls 616 // don't allow further calls
733 term->perl.self = 0; 617 term->perl.self = 0;
734 } 618 }
735 619
736 swap (perl_environ, environ); 620 swap (perl_environ, environ);
767 static const struct { 651 static const struct {
768 const char *name; 652 const char *name;
769 IV iv; 653 IV iv;
770 } *civ, const_iv[] = { 654 } *civ, const_iv[] = {
771# define const_iv(name) { # name, (IV)name } 655# define const_iv(name) { # name, (IV)name }
656 const_iv (NUM_RESOURCES),
772 const_iv (DEFAULT_RSTYLE), 657 const_iv (DEFAULT_RSTYLE),
773 const_iv (OVERLAY_RSTYLE), 658 const_iv (OVERLAY_RSTYLE),
774 const_iv (RS_Bold), 659 const_iv (RS_Bold),
775 const_iv (RS_Italic), 660 const_iv (RS_Italic),
776 const_iv (RS_Blink), 661 const_iv (RS_Blink),
791 const_iv (Button3Mask), 676 const_iv (Button3Mask),
792 const_iv (Button4Mask), 677 const_iv (Button4Mask),
793 const_iv (Button5Mask), 678 const_iv (Button5Mask),
794 const_iv (AnyModifier), 679 const_iv (AnyModifier),
795 680
796 const_iv (EVENT_NONE), 681 const_iv (NoSymbol),
797 const_iv (EVENT_READ), 682 const_iv (GrabModeSync),
798 const_iv (EVENT_WRITE), 683 const_iv (GrabModeAsync),
799 684
800 const_iv (NoEventMask), 685 const_iv (NoEventMask),
801 const_iv (KeyPressMask), 686 const_iv (KeyPressMask),
802 const_iv (KeyReleaseMask), 687 const_iv (KeyReleaseMask),
803 const_iv (ButtonPressMask), 688 const_iv (ButtonPressMask),
902_exit (int status) 787_exit (int status)
903 788
904NV 789NV
905NOW () 790NOW ()
906 CODE: 791 CODE:
907 RETVAL = NOW; 792 RETVAL = ev::now ();
908 OUTPUT: 793 OUTPUT:
909 RETVAL 794 RETVAL
910 795
911int 796int
912GET_BASEFG (int rend) 797GET_BASEFG (int rend)
923 RETVAL 808 RETVAL
924 809
925int 810int
926SET_FGCOLOR (int rend, int new_color) 811SET_FGCOLOR (int rend, int new_color)
927 CODE: 812 CODE:
928 RETVAL = SET_FGCOLOR (rend, new_color); 813 RETVAL = SET_FGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
929 OUTPUT: 814 OUTPUT:
930 RETVAL 815 RETVAL
931 816
932int 817int
933SET_BGCOLOR (int rend, int new_color) 818SET_BGCOLOR (int rend, int new_color)
934 CODE: 819 CODE:
935 RETVAL = SET_BGCOLOR (rend, new_color); 820 RETVAL = SET_BGCOLOR (rend, clamp (new_color, 0, TOTAL_COLORS - 1));
936 OUTPUT: 821 OUTPUT:
937 RETVAL 822 RETVAL
938 823
939int 824int
940GET_CUSTOM (int rend) 825GET_CUSTOM (int rend)
941 CODE: 826 CODE:
942 RETVAL = (rend && RS_customMask) >> RS_customShift; 827 RETVAL = (rend & RS_customMask) >> RS_customShift;
943 OUTPUT: 828 OUTPUT:
944 RETVAL 829 RETVAL
945 830
946int 831int
947SET_CUSTOM (int rend, int new_value) 832SET_CUSTOM (int rend, int new_value)
984 for (int i = AvFILL (env) + 1; i--; ) 869 for (int i = AvFILL (env) + 1; i--; )
985 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1)))); 870 envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (env, i, 1))));
986 871
987 envv->push_back (0); 872 envv->push_back (0);
988 873
989 bool success;
990
991 try 874 try
992 { 875 {
993 success = term->init (argv, envv); 876 term->init (argv, envv);
994 } 877 }
995 catch (const class rxvt_failure_exception &e) 878 catch (const class rxvt_failure_exception &e)
996 {
997 success = false;
998 }
999
1000 if (!success)
1001 { 879 {
1002 term->destroy (); 880 term->destroy ();
1003 croak ("error while initializing new terminal instance"); 881 croak ("error while initializing new terminal instance");
1004 } 882 }
1005 883
1015void 893void
1016rxvt_term::set_should_invoke (int htype, int inc) 894rxvt_term::set_should_invoke (int htype, int inc)
1017 CODE: 895 CODE:
1018 THIS->perl.should_invoke [htype] += inc; 896 THIS->perl.should_invoke [htype] += inc;
1019 897
1020void 898int
1021rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt) 899rxvt_term::grab_button (int button, U32 modifiers, Window window = THIS->vt)
1022 CODE: 900 CODE:
1023 XGrabButton (THIS->dpy, button, modifiers, window, 1, 901 RETVAL = XGrabButton (THIS->dpy, button, modifiers, window, 1,
1024 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, 902 ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
1025 GrabModeSync, GrabModeSync, None, GRAB_CURSOR); 903 GrabModeSync, GrabModeSync, None, GRAB_CURSOR);
904 OUTPUT: RETVAL
1026 905
1027void 906int
1028rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt) 907rxvt_term::ungrab_button (int button, U32 modifiers, Window window = THIS->vt)
1029 CODE: 908 CODE:
1030 XUngrabButton (THIS->dpy, button, modifiers, window); 909 RETVAL = XUngrabButton (THIS->dpy, button, modifiers, window);
910 OUTPUT: RETVAL
1031 911
1032#if 0
1033
1034void 912void
1035XGrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt) 913rxvt_term::XGrabKey (int keycode, U32 modifiers, Window window = THIS->vt, \
1036 C_ARGS: 914 int owner_events = 1, int pointer_mode = GrabModeAsync, int keyboard_mode = GrabModeAsync)
1037 THIS->dpy, keycode, modifiers, window, 1, 915 CODE:
1038 GrabModeSync, GrabModeSync 916 XGrabKey (THIS->dpy, keycode, modifiers, window, owner_events, pointer_mode, keyboard_mode);
1039 917
1040void 918void
1041XUngrabKey (rxvt_term *THIS, int keycode, U32 modifiers, Window window = THIS->vt) 919rxvt_term::XUngrabKey (int keycode, U32 modifiers, Window window = THIS->vt)
920 CODE:
1042 C_ARGS: THIS->dpy, keycode, modifiers, window 921 XUngrabKey (THIS->dpy, keycode, modifiers, window);
1043 922
1044#endif 923void
924rxvt_term::XUngrabKeyboard (Time eventtime)
925 CODE:
926 XUngrabKeyboard (THIS->dpy, eventtime);
1045 927
1046bool 928bool
1047rxvt_term::grab (Time eventtime, int sync = 0) 929rxvt_term::grab (Time eventtime, int sync = 0)
1048 CODE: 930 CODE:
1049{ 931{
1084rxvt_term::ungrab () 966rxvt_term::ungrab ()
1085 CODE: 967 CODE:
1086 ungrab (THIS); 968 ungrab (THIS);
1087 969
1088int 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
993
994int
1089rxvt_term::strwidth (SV *str) 995rxvt_term::strwidth (SV *str)
1090 CODE: 996 CODE:
1091{ 997{
1092 wchar_t *wstr = sv2wcs (str); 998 wchar_t *wstr = sv2wcs (str);
1093 999
1094 rxvt_push_locale (THIS->locale); 1000 rxvt_push_locale (THIS->locale);
1095 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 }
1096 rxvt_pop_locale (); 1009 rxvt_pop_locale ();
1097 1010
1098 free (wstr); 1011 free (wstr);
1099} 1012}
1100 OUTPUT: 1013 OUTPUT:
1133 free (wstr); 1046 free (wstr);
1134} 1047}
1135 OUTPUT: 1048 OUTPUT:
1136 RETVAL 1049 RETVAL
1137 1050
1051char *
1052rxvt_term::locale ()
1053 CODE:
1054 RETVAL = THIS->locale;
1055 OUTPUT:
1056 RETVAL
1057
1138#define TERM_OFFSET(sym) offsetof (TermWin_t, sym) 1058#define TERM_OFFSET(sym) offsetof (TermWin_t, sym)
1139 1059
1140#define TERM_OFFSET_width TERM_OFFSET(width) 1060#define TERM_OFFSET_width TERM_OFFSET(width)
1141#define TERM_OFFSET_height TERM_OFFSET(height) 1061#define TERM_OFFSET_height TERM_OFFSET(height)
1142#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) 1062#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth)
1143#define TERM_OFFSET_fheight TERM_OFFSET(fheight) 1063#define TERM_OFFSET_fheight TERM_OFFSET(fheight)
1144#define TERM_OFFSET_fbase TERM_OFFSET(fbase) 1064#define TERM_OFFSET_fbase TERM_OFFSET(fbase)
1145#define TERM_OFFSET_nrow TERM_OFFSET(nrow) 1065#define TERM_OFFSET_nrow TERM_OFFSET(nrow)
1146#define TERM_OFFSET_ncol TERM_OFFSET(ncol) 1066#define TERM_OFFSET_ncol TERM_OFFSET(ncol)
1147#define TERM_OFFSET_focus TERM_OFFSET(focus) 1067#define TERM_OFFSET_focus TERM_OFFSET(focus)
1148#define TERM_OFFSET_mapped TERM_OFFSET(mapped) 1068#define TERM_OFFSET_mapped TERM_OFFSET(mapped)
1149#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth) 1069#define TERM_OFFSET_int_bwidth TERM_OFFSET(int_bwidth)
1150#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth) 1070#define TERM_OFFSET_ext_bwidth TERM_OFFSET(ext_bwidth)
1151#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace) 1071#define TERM_OFFSET_lineSpace TERM_OFFSET(lineSpace)
1072#define TERM_OFFSET_letterSpace TERM_OFFSET(letterSpace)
1152#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) 1073#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines)
1153#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) 1074#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows)
1154#define TERM_OFFSET_top_row TERM_OFFSET(top_row) 1075#define TERM_OFFSET_top_row TERM_OFFSET(top_row)
1155 1076
1156int 1077int
1157rxvt_term::width () 1078rxvt_term::width ()
1158 ALIAS: 1079 ALIAS:
1159 width = TERM_OFFSET_width 1080 width = TERM_OFFSET_width
1160 height = TERM_OFFSET_height 1081 height = TERM_OFFSET_height
1161 fwidth = TERM_OFFSET_fwidth 1082 fwidth = TERM_OFFSET_fwidth
1162 fheight = TERM_OFFSET_fheight 1083 fheight = TERM_OFFSET_fheight
1163 fbase = TERM_OFFSET_fbase 1084 fbase = TERM_OFFSET_fbase
1164 nrow = TERM_OFFSET_nrow 1085 nrow = TERM_OFFSET_nrow
1165 ncol = TERM_OFFSET_ncol 1086 ncol = TERM_OFFSET_ncol
1166 focus = TERM_OFFSET_focus 1087 focus = TERM_OFFSET_focus
1167 mapped = TERM_OFFSET_mapped 1088 mapped = TERM_OFFSET_mapped
1168 int_bwidth = TERM_OFFSET_int_bwidth 1089 int_bwidth = TERM_OFFSET_int_bwidth
1169 ext_bwidth = TERM_OFFSET_ext_bwidth 1090 ext_bwidth = TERM_OFFSET_ext_bwidth
1170 lineSpace = TERM_OFFSET_lineSpace 1091 lineSpace = TERM_OFFSET_lineSpace
1092 letterSpace = TERM_OFFSET_letterSpace
1171 saveLines = TERM_OFFSET_saveLines 1093 saveLines = TERM_OFFSET_saveLines
1172 total_rows = TERM_OFFSET_total_rows 1094 total_rows = TERM_OFFSET_total_rows
1173 top_row = TERM_OFFSET_top_row 1095 top_row = TERM_OFFSET_top_row
1174 CODE: 1096 CODE:
1175 RETVAL = *(int *)((char *)THIS + ix); 1097 RETVAL = *(int *)((char *)THIS + ix);
1176 OUTPUT: 1098 OUTPUT:
1177 RETVAL 1099 RETVAL
1178 1100
1189 { 1111 {
1190 case 0: RETVAL = THIS->ModLevel3Mask; break; 1112 case 0: RETVAL = THIS->ModLevel3Mask; break;
1191 case 1: RETVAL = THIS->ModMetaMask; break; 1113 case 1: RETVAL = THIS->ModMetaMask; break;
1192 case 2: RETVAL = THIS->ModNumLockMask; break; 1114 case 2: RETVAL = THIS->ModNumLockMask; break;
1193 case 3: RETVAL = THIS->current_screen; break; 1115 case 3: RETVAL = THIS->current_screen; break;
1116#ifdef CURSOR_BLINK
1194 case 4: RETVAL = THIS->hidden_cursor; break; 1117 case 4: RETVAL = THIS->hidden_cursor; break;
1118#endif
1195 } 1119 }
1196 OUTPUT: 1120 OUTPUT:
1197 RETVAL 1121 RETVAL
1198 1122
1199char * 1123char *
1209 } 1133 }
1210 OUTPUT: 1134 OUTPUT:
1211 RETVAL 1135 RETVAL
1212 1136
1213SV * 1137SV *
1214rxvt_term::_env () 1138rxvt_term::envv ()
1139 ALIAS:
1140 argv = 1
1215 CODE: 1141 PPCODE:
1216{ 1142{
1217 if (THIS->envv) 1143 stringvec *vec = ix ? THIS->argv : THIS->envv;
1218 {
1219 AV *av = newAV ();
1220 1144
1145 EXTEND (SP, vec->size ());
1146
1221 for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) 1147 for (char **i = vec->begin (); i != vec->end (); ++i)
1222 if (*i) 1148 if (*i)
1223 av_push (av, newSVpv (*i, 0)); 1149 PUSHs (sv_2mortal (newSVpv (*i, 0)));
1224
1225 RETVAL = newRV_noinc ((SV *)av);
1226 }
1227 else
1228 RETVAL = &PL_sv_undef;
1229} 1150}
1230 OUTPUT:
1231 RETVAL
1232 1151
1233int 1152int
1234rxvt_term::pty_ev_events (int events = EVENT_UNDEF) 1153rxvt_term::pty_ev_events (int events = ev::UNDEF)
1235 CODE: 1154 CODE:
1236 RETVAL = THIS->pty_ev.events; 1155 RETVAL = THIS->pty_ev.events;
1237 if (events != EVENT_UNDEF) 1156 if (events != ev::UNDEF)
1238 THIS->pty_ev.set (events); 1157 THIS->pty_ev.set (events);
1239 OUTPUT: 1158 OUTPUT:
1240 RETVAL 1159 RETVAL
1241 1160
1242int 1161int
1292 1211
1293void 1212void
1294rxvt_term::focus_out () 1213rxvt_term::focus_out ()
1295 1214
1296void 1215void
1216rxvt_term::key_press (unsigned int state, unsigned int keycode, Time time = CurrentTime)
1217 ALIAS:
1218 key_release = 1
1219 CODE:
1220{
1221 XKeyEvent xkey;
1222
1223 memset (&xkey, 0, sizeof (xkey));
1224
1225 xkey.time = time;
1226 xkey.state = state;
1227 xkey.keycode = keycode;
1228
1229 xkey.type = ix ? KeyRelease : KeyPress;
1230 xkey.display = THIS->dpy;
1231 xkey.window = THIS->vt;
1232 xkey.root = THIS->display->root;
1233 xkey.subwindow = THIS->vt;
1234
1235 if (ix)
1236 THIS->key_release (xkey);
1237 else
1238 THIS->key_press (xkey);
1239}
1240
1241void
1297rxvt_term::want_refresh () 1242rxvt_term::want_refresh ()
1298 CODE: 1243 CODE:
1299 THIS->want_refresh = 1; 1244 THIS->want_refresh = 1;
1245 THIS->refresh_check ();
1300 1246
1301void 1247void
1302rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) 1248rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS)
1303 PPCODE: 1249 PPCODE:
1304{ 1250{
1459SV * 1405SV *
1460rxvt_term::special_decode (SV *text) 1406rxvt_term::special_decode (SV *text)
1461 CODE: 1407 CODE:
1462{ 1408{
1463 wchar_t *wstr = sv2wcs (text); 1409 wchar_t *wstr = sv2wcs (text);
1464 int wlen = wcslen (wstr);
1465 int dlen = 0; 1410 int dlen = 0;
1466 1411
1467 // find length 1412 // find length
1468 for (wchar_t *s = wstr; *s; s++) 1413 for (wchar_t *s = wstr; *s; s++)
1469 if (*s == NOCHAR) 1414 if (*s == NOCHAR)
1502# undef reserve 1447# undef reserve
1503 }; 1448 };
1504 1449
1505 rs = rslist + sizeof (rslist) / sizeof (rslist [0]); 1450 rs = rslist + sizeof (rslist) / sizeof (rslist [0]);
1506 1451
1452 if (*name)
1507 do { 1453 {
1454 do {
1508 if (rs-- == rslist) 1455 if (rs-- == rslist)
1509 croak ("no such resource '%s', requested", name); 1456 croak ("no such resource '%s', requested", name);
1510 } while (strcmp (name, rs->name)); 1457 } while (strcmp (name, rs->name));
1511 1458
1512 index += rs->value; 1459 index += rs->value;
1460 }
1461 else
1462 {
1463 --rs;
1464 name = "";
1465 }
1513 1466
1514 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) 1467 if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES))
1515 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); 1468 croak ("requested out-of-bound resource %s+%d,", name, index - rs->value);
1516 1469
1517 if (GIMME_V != G_VOID) 1470 if (GIMME_V != G_VOID)
1532 1485
1533const char * 1486const char *
1534rxvt_term::x_resource (const char *name) 1487rxvt_term::x_resource (const char *name)
1535 1488
1536bool 1489bool
1537rxvt_term::option (U32 optval, int set = -1) 1490rxvt_term::option (U8 optval, int set = -1)
1538 CODE: 1491 CODE:
1539{ 1492{
1540 RETVAL = THIS->options & optval; 1493 RETVAL = THIS->option (optval);
1541 1494
1542 if (set >= 0) 1495 if (set >= 0)
1543 { 1496 {
1544 if (set)
1545 THIS->options |= optval; 1497 THIS->set_option (optval, set);
1546 else
1547 THIS->options &= ~optval;
1548 1498
1549 if (THIS->check_ev.is_active ()) // avoid doing this before START 1499 if (THIS->env_colorfgbg [0]) // avoid doing this before START
1550 switch (optval) 1500 switch (optval)
1551 { 1501 {
1552 case Opt_skipBuiltinGlyphs: 1502 case Opt_skipBuiltinGlyphs:
1553 THIS->set_fonts (); 1503 THIS->set_fonts ();
1554 THIS->scr_remap_chars (); 1504 THIS->scr_remap_chars ();
1555 THIS->scr_touch (true); 1505 THIS->scr_touch (true);
1556 THIS->want_refresh = 1; 1506 THIS->want_refresh = 1;
1507 THIS->refresh_check ();
1557 break; 1508 break;
1558 1509
1559 case Opt_cursorUnderline: 1510 case Opt_cursorUnderline:
1560 THIS->want_refresh = 1; 1511 THIS->want_refresh = 1;
1512 THIS->refresh_check ();
1561 break; 1513 break;
1562 1514
1563# case Opt_scrollBar_floating: 1515# case Opt_scrollBar_floating:
1564# case Opt_scrollBar_right: 1516# case Opt_scrollBar_right:
1565# THIS->resize_all_windows (THIS->width, THIS->height, 1); 1517# THIS->resize_all_windows (THIS->width, THIS->height, 1);
1623 1575
1624 clamp_it (rc.col, 0, THIS->ncol); 1576 clamp_it (rc.col, 0, THIS->ncol);
1625 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1); 1577 clamp_it (rc.row, THIS->top_row, THIS->nrow - 1);
1626 1578
1627 if (ix) 1579 if (ix)
1580 {
1628 THIS->want_refresh = 1; 1581 THIS->want_refresh = 1;
1582 THIS->refresh_check ();
1583 }
1629 } 1584 }
1630} 1585}
1631 1586
1632char 1587char
1633rxvt_term::cur_charset () 1588rxvt_term::cur_charset ()
1740 Atom *props = XListProperties (THIS->dpy, window, &count); 1695 Atom *props = XListProperties (THIS->dpy, window, &count);
1741 1696
1742 EXTEND (SP, count); 1697 EXTEND (SP, count);
1743 while (count--) 1698 while (count--)
1744 PUSHs (newSVuv ((U32)props [count])); 1699 PUSHs (newSVuv ((U32)props [count]));
1745 1700
1746 XFree (props); 1701 XFree (props);
1747} 1702}
1748 1703
1749void 1704void
1750rxvt_term::XGetWindowProperty (Window window, Atom property) 1705rxvt_term::XGetWindowProperty (Window window, Atom property)
1773 XFree (prop); 1728 XFree (prop);
1774 } 1729 }
1775} 1730}
1776 1731
1777void 1732void
1778rxvt_term::XChangeWindowProperty (Window window, Atom property, Atom type, int format, SV *data) 1733rxvt_term::XChangeProperty (Window window, Atom property, Atom type, int format, SV *data)
1779 CODE: 1734 CODE:
1780{ 1735{
1781 STRLEN len; 1736 STRLEN len;
1782 char *data_ = SvPVbyte (data, len); 1737 char *data_ = SvPVbyte (data, len);
1783 1738
1786 : 1; 1741 : 1;
1787 1742
1788 XChangeProperty (THIS->dpy, window, property, 1743 XChangeProperty (THIS->dpy, window, property,
1789 type, format, PropModeReplace, 1744 type, format, PropModeReplace,
1790 (unsigned char *)data_, len / elemsize); 1745 (unsigned char *)data_, len / elemsize);
1791 XSync (THIS->dpy, 0);
1792} 1746}
1793 1747
1794Atom 1748Atom
1795XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE) 1749XInternAtom (rxvt_term *term, char *atom_name, int only_if_exists = FALSE)
1796 C_ARGS: term->dpy, atom_name, only_if_exists 1750 C_ARGS: term->dpy, atom_name, only_if_exists
1880overlay::hide () 1834overlay::hide ()
1881 1835
1882void 1836void
1883overlay::DESTROY () 1837overlay::DESTROY ()
1884 1838
1885############################################################################# 1839INCLUDE: $PERL <iom_perl.xs -pe s/IOM_MODULE/urxvt/g,s/IOM_CLASS/urxvt/g |
1886# urxvt::watcher
1887#############################################################################
1888 1840
1889MODULE = urxvt PACKAGE = urxvt::watcher
1890
1891CHAINED
1892perl_watcher::cb (SV *cb)
1893 CODE:
1894 THIS->cb (cb);
1895 OUTPUT:
1896 RETVAL
1897
1898#############################################################################
1899# urxvt::timer
1900#############################################################################
1901
1902MODULE = urxvt PACKAGE = urxvt::timer
1903
1904SV *
1905timer::new ()
1906 CODE:
1907 timer *w = new timer;
1908 w->start (NOW);
1909 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::timer");
1910 w->self = (HV *)SvRV (RETVAL);
1911 OUTPUT:
1912 RETVAL
1913
1914NV
1915timer::at ()
1916 CODE:
1917 RETVAL = THIS->at;
1918 OUTPUT:
1919 RETVAL
1920
1921CHAINED
1922timer::interval (NV interval)
1923 CODE:
1924 THIS->interval = interval;
1925 OUTPUT:
1926 RETVAL
1927
1928CHAINED
1929timer::set (NV tstamp)
1930 CODE:
1931 THIS->set (tstamp);
1932 OUTPUT:
1933 RETVAL
1934
1935CHAINED
1936timer::start (NV tstamp = THIS->at)
1937 CODE:
1938 THIS->start (tstamp);
1939 OUTPUT:
1940 RETVAL
1941
1942CHAINED
1943timer::after (NV delay)
1944 CODE:
1945 THIS->start (NOW + delay);
1946 OUTPUT:
1947 RETVAL
1948
1949CHAINED
1950timer::stop ()
1951 CODE:
1952 THIS->stop ();
1953 OUTPUT:
1954 RETVAL
1955
1956void
1957timer::DESTROY ()
1958
1959#############################################################################
1960# urxvt::iow
1961#############################################################################
1962
1963MODULE = urxvt PACKAGE = urxvt::iow
1964
1965SV *
1966iow::new ()
1967 CODE:
1968 iow *w = new iow;
1969 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iow");
1970 w->self = (HV *)SvRV (RETVAL);
1971 OUTPUT:
1972 RETVAL
1973
1974CHAINED
1975iow::fd (int fd)
1976 CODE:
1977 THIS->fd = fd;
1978 OUTPUT:
1979 RETVAL
1980
1981CHAINED
1982iow::events (short events)
1983 CODE:
1984 THIS->events = events;
1985 OUTPUT:
1986 RETVAL
1987
1988CHAINED
1989iow::start ()
1990 CODE:
1991 THIS->start ();
1992 OUTPUT:
1993 RETVAL
1994
1995CHAINED
1996iow::stop ()
1997 CODE:
1998 THIS->stop ();
1999 OUTPUT:
2000 RETVAL
2001
2002void
2003iow::DESTROY ()
2004
2005#############################################################################
2006# urxvt::iw
2007#############################################################################
2008
2009MODULE = urxvt PACKAGE = urxvt::iw
2010
2011SV *
2012iw::new ()
2013 CODE:
2014 iw *w = new iw;
2015 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::iw");
2016 w->self = (HV *)SvRV (RETVAL);
2017 OUTPUT:
2018 RETVAL
2019
2020CHAINED
2021iw::start ()
2022 CODE:
2023 THIS->start ();
2024 OUTPUT:
2025 RETVAL
2026
2027CHAINED
2028iw::stop ()
2029 CODE:
2030 THIS->stop ();
2031 OUTPUT:
2032 RETVAL
2033
2034void
2035iw::DESTROY ()
2036
2037#############################################################################
2038# urxvt::pw
2039#############################################################################
2040
2041MODULE = urxvt PACKAGE = urxvt::pw
2042
2043SV *
2044pw::new ()
2045 CODE:
2046 pw *w = new pw;
2047 RETVAL = newSVptr ((void *)(perl_watcher *)w, "urxvt::pw");
2048 w->self = (HV *)SvRV (RETVAL);
2049 OUTPUT:
2050 RETVAL
2051
2052CHAINED
2053pw::start (int pid)
2054 CODE:
2055 THIS->start (pid);
2056 OUTPUT:
2057 RETVAL
2058
2059CHAINED
2060pw::stop ()
2061 CODE:
2062 THIS->stop ();
2063 OUTPUT:
2064 RETVAL
2065
2066void
2067pw::DESTROY ()
2068
2069

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines