1 |
/*----------------------------------------------------------------------* |
2 |
* File: rxvtperl.xs |
3 |
*----------------------------------------------------------------------* |
4 |
* |
5 |
* All portions of code are copyright by their respective author/s. |
6 |
* Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
7 |
* |
8 |
* This program is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
10 |
* the Free Software Foundation; either version 2 of the License, or |
11 |
* (at your option) any later version. |
12 |
* |
13 |
* This program is distributed in the hope that it will be useful, |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
* GNU General Public License for more details. |
17 |
* |
18 |
* You should have received a copy of the GNU General Public License |
19 |
* along with this program; if not, write to the Free Software |
20 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 |
*----------------------------------------------------------------------*/ |
22 |
|
23 |
#define line_t perl_line_t |
24 |
#include <EXTERN.h> |
25 |
#include <perl.h> |
26 |
#include <XSUB.h> |
27 |
#undef line_t |
28 |
|
29 |
#include "../config.h" |
30 |
|
31 |
#include <cstdarg> |
32 |
|
33 |
#include "rxvt.h" |
34 |
#include "iom.h" |
35 |
#include "rxvtutil.h" |
36 |
#include "rxvtperl.h" |
37 |
|
38 |
#include "perlxsi.c" |
39 |
|
40 |
#undef LINENO |
41 |
#define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
42 |
#undef ROW |
43 |
#define ROW(n) THIS->row_buf [LINENO (n)] |
44 |
|
45 |
///////////////////////////////////////////////////////////////////////////// |
46 |
|
47 |
static wchar_t * |
48 |
sv2wcs (SV *sv) |
49 |
{ |
50 |
STRLEN len; |
51 |
char *str = SvPVutf8 (sv, len); |
52 |
return rxvt_utf8towcs (str, len); |
53 |
} |
54 |
|
55 |
static SV * |
56 |
wcs2sv (wchar_t *wstr, int len = -1) |
57 |
{ |
58 |
char *str = rxvt_wcstoutf8 (wstr, len); |
59 |
|
60 |
SV *sv = newSVpv (str, 0); |
61 |
SvUTF8_on (sv); |
62 |
free (str); |
63 |
|
64 |
return sv; |
65 |
} |
66 |
|
67 |
static SV * |
68 |
new_ref (HV *hv, const char *klass) |
69 |
{ |
70 |
return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
71 |
} |
72 |
|
73 |
//TODO: use magic |
74 |
static SV * |
75 |
newSVptr (void *ptr, const char *klass) |
76 |
{ |
77 |
HV *hv = newHV (); |
78 |
sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
79 |
return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
80 |
} |
81 |
|
82 |
static void |
83 |
clearSVptr (SV *sv) |
84 |
{ |
85 |
if (SvROK (sv)) |
86 |
sv = SvRV (sv); |
87 |
|
88 |
hv_clear ((HV *)sv); |
89 |
sv_unmagic (sv, PERL_MAGIC_ext); |
90 |
} |
91 |
|
92 |
static long |
93 |
SvPTR (SV *sv, const char *klass) |
94 |
{ |
95 |
if (!sv_derived_from (sv, klass)) |
96 |
croak ("object of type %s expected", klass); |
97 |
|
98 |
MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
99 |
|
100 |
if (!mg) |
101 |
croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
102 |
|
103 |
return (long)mg->mg_ptr; |
104 |
} |
105 |
|
106 |
#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
107 |
#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
108 |
|
109 |
///////////////////////////////////////////////////////////////////////////// |
110 |
|
111 |
struct perl_watcher |
112 |
{ |
113 |
SV *cbsv; |
114 |
HV *self; |
115 |
|
116 |
perl_watcher () |
117 |
: cbsv (newSV (0)) |
118 |
{ |
119 |
} |
120 |
|
121 |
~perl_watcher () |
122 |
{ |
123 |
SvREFCNT_dec (cbsv); |
124 |
} |
125 |
|
126 |
void cb (SV *cb) |
127 |
{ |
128 |
sv_setsv (cbsv, cb); |
129 |
} |
130 |
|
131 |
void invoke (const char *type, SV *self, int arg = -1); |
132 |
}; |
133 |
|
134 |
void |
135 |
perl_watcher::invoke (const char *type, SV *self, int arg) |
136 |
{ |
137 |
dSP; |
138 |
|
139 |
ENTER; |
140 |
SAVETMPS; |
141 |
|
142 |
PUSHMARK (SP); |
143 |
|
144 |
XPUSHs (sv_2mortal (self)); |
145 |
|
146 |
if (arg >= 0) |
147 |
XPUSHs (sv_2mortal (newSViv (arg))); |
148 |
|
149 |
PUTBACK; |
150 |
call_sv (cbsv, G_VOID | G_EVAL | G_DISCARD); |
151 |
SPAGAIN; |
152 |
|
153 |
PUTBACK; |
154 |
FREETMPS; |
155 |
LEAVE; |
156 |
|
157 |
if (SvTRUE (ERRSV)) |
158 |
rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV)); |
159 |
} |
160 |
|
161 |
#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") |
162 |
#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") |
163 |
|
164 |
struct timer : time_watcher, perl_watcher |
165 |
{ |
166 |
tstamp interval; |
167 |
|
168 |
timer () |
169 |
: time_watcher (this, &timer::execute) |
170 |
{ |
171 |
} |
172 |
|
173 |
void execute (time_watcher &w) |
174 |
{ |
175 |
if (interval) |
176 |
start (at + interval); |
177 |
|
178 |
invoke ("urxvt::timer", newSVtimer (this)); |
179 |
} |
180 |
}; |
181 |
|
182 |
#define newSViow(iow) new_ref (iow->self, "urxvt::iow") |
183 |
#define SvIOW(sv) (iow *)SvPTR (sv, "urxvt::iow") |
184 |
|
185 |
struct iow : io_watcher, perl_watcher |
186 |
{ |
187 |
iow () |
188 |
: io_watcher (this, &iow::execute) |
189 |
{ |
190 |
} |
191 |
|
192 |
void execute (io_watcher &w, short revents) |
193 |
{ |
194 |
invoke ("urxvt::iow", newSViow (this), revents); |
195 |
} |
196 |
}; |
197 |
|
198 |
///////////////////////////////////////////////////////////////////////////// |
199 |
|
200 |
#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") |
201 |
|
202 |
struct overlay { |
203 |
HV *self; |
204 |
rxvt_term *THIS; |
205 |
int x, y, w, h; |
206 |
int border; |
207 |
text_t **text; |
208 |
rend_t **rend; |
209 |
|
210 |
overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
211 |
~overlay (); |
212 |
|
213 |
void show (); |
214 |
void hide (); |
215 |
|
216 |
void swap (); |
217 |
|
218 |
void set (int x, int y, SV *str, SV *rend); |
219 |
}; |
220 |
|
221 |
overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) |
222 |
: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2) |
223 |
{ |
224 |
if (border == 2) |
225 |
{ |
226 |
w += 2; |
227 |
h += 2; |
228 |
} |
229 |
|
230 |
text = new text_t *[h]; |
231 |
rend = new rend_t *[h]; |
232 |
|
233 |
for (int y = 0; y < h; y++) |
234 |
{ |
235 |
text_t *tp = text[y] = new text_t[w]; |
236 |
rend_t *rp = rend[y] = new rend_t[w]; |
237 |
|
238 |
text_t t0, t1, t2; |
239 |
rend_t r = rstyle; |
240 |
|
241 |
if (border == 2) |
242 |
{ |
243 |
if (y == 0) |
244 |
t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
245 |
else if (y < h - 1) |
246 |
t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
247 |
else |
248 |
t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
249 |
|
250 |
*tp++ = t0; |
251 |
*rp++ = r; |
252 |
|
253 |
for (int x = w - 2; x-- > 0; ) |
254 |
{ |
255 |
*tp++ = t1; |
256 |
*rp++ = r; |
257 |
} |
258 |
|
259 |
*tp = t2; |
260 |
*rp = r; |
261 |
} |
262 |
else |
263 |
for (int x = w; x-- > 0; ) |
264 |
{ |
265 |
*tp++ = 0x0020; |
266 |
*rp++ = r; |
267 |
} |
268 |
} |
269 |
|
270 |
show (); |
271 |
THIS->want_refresh = 1; |
272 |
} |
273 |
|
274 |
overlay::~overlay () |
275 |
{ |
276 |
hide (); |
277 |
|
278 |
for (int y = h; y--; ) |
279 |
{ |
280 |
delete [] text[y]; |
281 |
delete [] rend[y]; |
282 |
} |
283 |
|
284 |
delete [] text; |
285 |
delete [] rend; |
286 |
|
287 |
THIS->want_refresh = 1; |
288 |
} |
289 |
|
290 |
void |
291 |
overlay::show () |
292 |
{ |
293 |
char key[33]; sprintf (key, "%32lx", (long)this); |
294 |
|
295 |
HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
296 |
hv_store (hv, key, 32, newSViv ((long)this), 0); |
297 |
} |
298 |
|
299 |
void |
300 |
overlay::hide () |
301 |
{ |
302 |
SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); |
303 |
|
304 |
if (ovs) |
305 |
{ |
306 |
char key[33]; sprintf (key, "%32lx", (long)this); |
307 |
|
308 |
HV *hv = (HV *)SvRV (*ovs); |
309 |
hv_delete (hv, key, 32, G_DISCARD); |
310 |
} |
311 |
} |
312 |
|
313 |
void overlay::swap () |
314 |
{ |
315 |
int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
316 |
int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); |
317 |
|
318 |
int ov_w = min (w, THIS->ncol - ov_x); |
319 |
int ov_h = min (h, THIS->nrow - ov_y); |
320 |
|
321 |
for (int y = ov_h; y--; ) |
322 |
{ |
323 |
text_t *t1 = text [y]; |
324 |
rend_t *r1 = rend [y]; |
325 |
|
326 |
text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
327 |
rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
328 |
|
329 |
for (int x = ov_w; x--; ) |
330 |
{ |
331 |
text_t t = *t1; *t1++ = *t2; *t2++ = t; |
332 |
rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
333 |
} |
334 |
} |
335 |
|
336 |
} |
337 |
|
338 |
void overlay::set (int x, int y, SV *text, SV *rend) |
339 |
{ |
340 |
x += border; |
341 |
y += border; |
342 |
|
343 |
if (!IN_RANGE_EXC (y, 0, h - border)) |
344 |
return; |
345 |
|
346 |
wchar_t *wtext = sv2wcs (text); |
347 |
|
348 |
for (int col = min (wcslen (wtext), w - x - border); col--; ) |
349 |
this->text [y][x + col] = wtext [col]; |
350 |
|
351 |
free (wtext); |
352 |
|
353 |
if (rend) |
354 |
{ |
355 |
if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
356 |
croak ("rend must be arrayref"); |
357 |
|
358 |
AV *av = (AV *)SvRV (rend); |
359 |
|
360 |
for (int col = min (av_len (av) + 1, w - x - border); col--; ) |
361 |
this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
362 |
} |
363 |
|
364 |
THIS->want_refresh = 1; |
365 |
} |
366 |
|
367 |
|
368 |
///////////////////////////////////////////////////////////////////////////// |
369 |
|
370 |
struct rxvt_perl_interp rxvt_perl; |
371 |
|
372 |
static PerlInterpreter *perl; |
373 |
|
374 |
rxvt_perl_interp::rxvt_perl_interp () |
375 |
{ |
376 |
} |
377 |
|
378 |
rxvt_perl_interp::~rxvt_perl_interp () |
379 |
{ |
380 |
if (perl) |
381 |
{ |
382 |
perl_destruct (perl); |
383 |
perl_free (perl); |
384 |
} |
385 |
} |
386 |
|
387 |
void |
388 |
rxvt_perl_interp::init () |
389 |
{ |
390 |
if (!perl) |
391 |
{ |
392 |
char *argv[] = { |
393 |
"", |
394 |
"-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
395 |
}; |
396 |
|
397 |
perl = perl_alloc (); |
398 |
perl_construct (perl); |
399 |
|
400 |
if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
401 |
|| perl_run (perl)) |
402 |
{ |
403 |
rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
404 |
|
405 |
perl_destruct (perl); |
406 |
perl_free (perl); |
407 |
perl = 0; |
408 |
} |
409 |
} |
410 |
} |
411 |
|
412 |
bool |
413 |
rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
414 |
{ |
415 |
if (!perl) |
416 |
return false; |
417 |
|
418 |
if (htype == HOOK_INIT) // first hook ever called |
419 |
{ |
420 |
term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
421 |
hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
422 |
} |
423 |
else if (!term->self) |
424 |
return false; // perl not initialized for this instance |
425 |
else if (htype == HOOK_DESTROY) |
426 |
{ |
427 |
// handled later |
428 |
} |
429 |
else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
430 |
{ |
431 |
HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
432 |
|
433 |
if (HvKEYS (hv)) |
434 |
{ |
435 |
hv_iterinit (hv); |
436 |
|
437 |
while (HE *he = hv_iternext (hv)) |
438 |
((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
439 |
} |
440 |
} |
441 |
else if (!should_invoke [htype]) |
442 |
return false; |
443 |
|
444 |
dSP; |
445 |
va_list ap; |
446 |
|
447 |
va_start (ap, htype); |
448 |
|
449 |
ENTER; |
450 |
SAVETMPS; |
451 |
|
452 |
PUSHMARK (SP); |
453 |
|
454 |
XPUSHs (sv_2mortal (newSVterm (term))); |
455 |
XPUSHs (sv_2mortal (newSViv (htype))); |
456 |
|
457 |
for (;;) { |
458 |
data_type dt = (data_type)va_arg (ap, int); |
459 |
|
460 |
switch (dt) |
461 |
{ |
462 |
case DT_INT: |
463 |
XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
464 |
break; |
465 |
|
466 |
case DT_LONG: |
467 |
XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
468 |
break; |
469 |
|
470 |
case DT_STRING: |
471 |
XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
472 |
break; |
473 |
|
474 |
case DT_STRING_LEN: |
475 |
{ |
476 |
char *str = va_arg (ap, char *); |
477 |
int len = va_arg (ap, int); |
478 |
|
479 |
XPUSHs (sv_2mortal (newSVpvn (str, len))); |
480 |
} |
481 |
break; |
482 |
|
483 |
case DT_XEVENT: |
484 |
{ |
485 |
XEvent *xe = va_arg (ap, XEvent *); |
486 |
HV *hv = newHV (); |
487 |
|
488 |
# define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
489 |
# define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
490 |
# undef set |
491 |
|
492 |
setiv (type, xe->type); |
493 |
setiv (send_event, xe->xany.send_event); |
494 |
setiv (serial, xe->xany.serial); |
495 |
|
496 |
switch (xe->type) |
497 |
{ |
498 |
case KeyPress: |
499 |
case KeyRelease: |
500 |
case ButtonPress: |
501 |
case ButtonRelease: |
502 |
case MotionNotify: |
503 |
setiv (time, xe->xmotion.time); |
504 |
setiv (x, xe->xmotion.x); |
505 |
setiv (y, xe->xmotion.y); |
506 |
setiv (row, xe->xmotion.y / term->fheight); |
507 |
setiv (col, xe->xmotion.x / term->fwidth); |
508 |
setiv (x_root, xe->xmotion.x_root); |
509 |
setiv (y_root, xe->xmotion.y_root); |
510 |
setiv (state, xe->xmotion.state); |
511 |
break; |
512 |
} |
513 |
|
514 |
switch (xe->type) |
515 |
{ |
516 |
case KeyPress: |
517 |
case KeyRelease: |
518 |
setiv (keycode, xe->xkey.keycode); |
519 |
break; |
520 |
|
521 |
case ButtonPress: |
522 |
case ButtonRelease: |
523 |
setiv (button, xe->xbutton.button); |
524 |
break; |
525 |
|
526 |
case MotionNotify: |
527 |
setiv (is_hint, xe->xmotion.is_hint); |
528 |
break; |
529 |
} |
530 |
|
531 |
XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
532 |
} |
533 |
break; |
534 |
|
535 |
case DT_USTRING_LEN: |
536 |
{ |
537 |
unicode_t *ustr = va_arg (ap, unicode_t *); |
538 |
int ulen = va_arg (ap, int); |
539 |
wchar_t *wstr = new wchar_t [ulen]; |
540 |
|
541 |
for (int i = ulen; i--; ) |
542 |
wstr [i] = ustr [i]; |
543 |
|
544 |
XPUSHs (sv_2mortal (wcs2sv (wstr, ulen))); |
545 |
|
546 |
delete [] wstr; |
547 |
} |
548 |
|
549 |
case DT_END: |
550 |
{ |
551 |
va_end (ap); |
552 |
|
553 |
PUTBACK; |
554 |
int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
555 |
SPAGAIN; |
556 |
|
557 |
if (count) |
558 |
{ |
559 |
SV *status = POPs; |
560 |
count = SvTRUE (status); |
561 |
} |
562 |
|
563 |
PUTBACK; |
564 |
FREETMPS; |
565 |
LEAVE; |
566 |
|
567 |
if (SvTRUE (ERRSV)) |
568 |
rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
569 |
|
570 |
if (htype == HOOK_DESTROY) |
571 |
{ |
572 |
clearSVptr ((SV *)term->self); |
573 |
SvREFCNT_dec ((SV *)term->self); |
574 |
} |
575 |
|
576 |
return count; |
577 |
} |
578 |
|
579 |
default: |
580 |
rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
581 |
} |
582 |
} |
583 |
} |
584 |
|
585 |
///////////////////////////////////////////////////////////////////////////// |
586 |
|
587 |
MODULE = urxvt PACKAGE = urxvt |
588 |
|
589 |
PROTOTYPES: ENABLE |
590 |
|
591 |
BOOT: |
592 |
{ |
593 |
# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), # name, newSViv (name)); |
594 |
AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
595 |
# define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
596 |
# include "hookinc.h" |
597 |
# undef def |
598 |
|
599 |
export_const (DEFAULT_RSTYLE); |
600 |
export_const (OVERLAY_RSTYLE); |
601 |
export_const (RS_Bold); |
602 |
export_const (RS_Italic); |
603 |
export_const (RS_Blink); |
604 |
export_const (RS_RVid); |
605 |
export_const (RS_Uline); |
606 |
|
607 |
sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
608 |
} |
609 |
|
610 |
SV * |
611 |
new (...) |
612 |
CODE: |
613 |
{ |
614 |
stringvec *argv = new stringvec; |
615 |
bool success; |
616 |
|
617 |
for (int i = 0; i < items ;i++) |
618 |
argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
619 |
|
620 |
rxvt_term *term = new rxvt_term; |
621 |
|
622 |
term->argv = argv; |
623 |
|
624 |
try |
625 |
{ |
626 |
if (!term->init (argv->size (), argv->begin ())) |
627 |
term = 0; |
628 |
} |
629 |
catch (const class rxvt_failure_exception &e) |
630 |
{ |
631 |
term->destroy (); |
632 |
croak ("exception caught while initializing new terminal instance"); |
633 |
} |
634 |
|
635 |
RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef; |
636 |
} |
637 |
OUTPUT: |
638 |
RETVAL |
639 |
|
640 |
void |
641 |
set_should_invoke (int htype, int value) |
642 |
CODE: |
643 |
rxvt_perl.should_invoke [htype] = value; |
644 |
|
645 |
void |
646 |
warn (const char *msg) |
647 |
CODE: |
648 |
rxvt_warn ("%s", msg); |
649 |
|
650 |
void |
651 |
fatal (const char *msg) |
652 |
CODE: |
653 |
rxvt_fatal ("%s", msg); |
654 |
|
655 |
NV |
656 |
NOW () |
657 |
CODE: |
658 |
RETVAL = NOW; |
659 |
OUTPUT: |
660 |
RETVAL |
661 |
|
662 |
int |
663 |
GET_BASEFG (int rend) |
664 |
CODE: |
665 |
RETVAL = GET_BASEFG (rend); |
666 |
OUTPUT: |
667 |
RETVAL |
668 |
|
669 |
int |
670 |
GET_BASEBG (int rend) |
671 |
CODE: |
672 |
RETVAL = GET_BASEBG (rend); |
673 |
OUTPUT: |
674 |
RETVAL |
675 |
|
676 |
int |
677 |
SET_FGCOLOR (int rend, int new_color) |
678 |
CODE: |
679 |
RETVAL = SET_FGCOLOR (rend, new_color); |
680 |
OUTPUT: |
681 |
RETVAL |
682 |
|
683 |
int |
684 |
SET_BGCOLOR (int rend, int new_color) |
685 |
CODE: |
686 |
RETVAL = SET_BGCOLOR (rend, new_color); |
687 |
OUTPUT: |
688 |
RETVAL |
689 |
|
690 |
int |
691 |
GET_CUSTOM (int rend) |
692 |
CODE: |
693 |
RETVAL = (rend && RS_customMask) >> RS_customShift; |
694 |
OUTPUT: |
695 |
RETVAL |
696 |
|
697 |
int |
698 |
SET_CUSTOM (int rend, int new_value) |
699 |
CODE: |
700 |
{ |
701 |
if (!IN_RANGE_EXC (new_value, 0, RS_customCount)) |
702 |
croak ("custom value out of range, must be 0..%d", RS_customCount - 1); |
703 |
|
704 |
RETVAL = (rend & ~RS_customMask) |
705 |
| ((new_value << RS_customShift) & RS_customMask); |
706 |
} |
707 |
OUTPUT: |
708 |
RETVAL |
709 |
|
710 |
MODULE = urxvt PACKAGE = urxvt::term |
711 |
|
712 |
void |
713 |
rxvt_term::destroy () |
714 |
|
715 |
int |
716 |
rxvt_term::strwidth (SV *str) |
717 |
CODE: |
718 |
{ |
719 |
wchar_t *wstr = sv2wcs (str); |
720 |
|
721 |
rxvt_push_locale (THIS->locale); |
722 |
RETVAL = wcswidth (wstr, wcslen (wstr)); |
723 |
rxvt_pop_locale (); |
724 |
|
725 |
free (wstr); |
726 |
} |
727 |
OUTPUT: |
728 |
RETVAL |
729 |
|
730 |
SV * |
731 |
rxvt_term::locale_encode (SV *str) |
732 |
CODE: |
733 |
{ |
734 |
wchar_t *wstr = sv2wcs (str); |
735 |
|
736 |
rxvt_push_locale (THIS->locale); |
737 |
char *mbstr = rxvt_wcstombs (wstr); |
738 |
rxvt_pop_locale (); |
739 |
|
740 |
free (wstr); |
741 |
|
742 |
RETVAL = newSVpv (mbstr, 0); |
743 |
free (mbstr); |
744 |
} |
745 |
OUTPUT: |
746 |
RETVAL |
747 |
|
748 |
SV * |
749 |
rxvt_term::locale_decode (SV *octets) |
750 |
CODE: |
751 |
{ |
752 |
STRLEN len; |
753 |
char *data = SvPVbyte (octets, len); |
754 |
|
755 |
rxvt_push_locale (THIS->locale); |
756 |
wchar_t *wstr = rxvt_mbstowcs (data, len); |
757 |
rxvt_pop_locale (); |
758 |
|
759 |
RETVAL = wcs2sv (wstr); |
760 |
free (wstr); |
761 |
} |
762 |
OUTPUT: |
763 |
RETVAL |
764 |
|
765 |
# very portable, especially on objects as opposed to pods |
766 |
#define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
767 |
|
768 |
#define TERM_OFFSET_width TERM_OFFSET(width) |
769 |
#define TERM_OFFSET_height TERM_OFFSET(height) |
770 |
#define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
771 |
#define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
772 |
#define TERM_OFFSET_fbase TERM_OFFSET(fbase) |
773 |
#define TERM_OFFSET_nrow TERM_OFFSET(nrow) |
774 |
#define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
775 |
#define TERM_OFFSET_focus TERM_OFFSET(focus) |
776 |
#define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
777 |
#define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
778 |
#define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
779 |
#define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) |
780 |
|
781 |
int |
782 |
rxvt_term::width () |
783 |
ALIAS: |
784 |
width = TERM_OFFSET_width |
785 |
height = TERM_OFFSET_height |
786 |
fwidth = TERM_OFFSET_fwidth |
787 |
fheight = TERM_OFFSET_fheight |
788 |
fbase = TERM_OFFSET_fbase |
789 |
nrow = TERM_OFFSET_nrow |
790 |
ncol = TERM_OFFSET_ncol |
791 |
focus = TERM_OFFSET_focus |
792 |
mapped = TERM_OFFSET_mapped |
793 |
saveLines = TERM_OFFSET_saveLines |
794 |
total_rows = TERM_OFFSET_total_rows |
795 |
nsaved = TERM_OFFSET_nsaved |
796 |
CODE: |
797 |
RETVAL = *(int *)((char *)THIS + ix); |
798 |
OUTPUT: |
799 |
RETVAL |
800 |
|
801 |
U32 |
802 |
rxvt_term::parent () |
803 |
CODE: |
804 |
RETVAL = (U32)THIS->parent [0]; |
805 |
OUTPUT: |
806 |
RETVAL |
807 |
|
808 |
U32 |
809 |
rxvt_term::vt () |
810 |
CODE: |
811 |
RETVAL = (U32)THIS->vt; |
812 |
OUTPUT: |
813 |
RETVAL |
814 |
|
815 |
U32 |
816 |
rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
817 |
CODE: |
818 |
{ |
819 |
RETVAL = THIS->rstyle; |
820 |
THIS->rstyle = new_rstyle; |
821 |
} |
822 |
OUTPUT: |
823 |
RETVAL |
824 |
|
825 |
int |
826 |
rxvt_term::view_start (int newval = -1) |
827 |
CODE: |
828 |
{ |
829 |
RETVAL = THIS->view_start; |
830 |
|
831 |
if (newval >= 0) |
832 |
{ |
833 |
THIS->view_start = min (newval, THIS->nsaved); |
834 |
THIS->scr_changeview (RETVAL); |
835 |
} |
836 |
} |
837 |
OUTPUT: |
838 |
RETVAL |
839 |
|
840 |
void |
841 |
rxvt_term::want_refresh () |
842 |
CODE: |
843 |
THIS->want_refresh = 1; |
844 |
|
845 |
void |
846 |
rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
847 |
PPCODE: |
848 |
{ |
849 |
if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
850 |
XSRETURN_EMPTY; |
851 |
|
852 |
line_t &l = ROW(row_number); |
853 |
|
854 |
if (GIMME_V != G_VOID) |
855 |
{ |
856 |
wchar_t *wstr = new wchar_t [THIS->ncol]; |
857 |
|
858 |
for (int col = 0; col <THIS->ncol; col++) |
859 |
wstr [col] = l.t [col]; |
860 |
|
861 |
XPUSHs (sv_2mortal (wcs2sv (wstr))); |
862 |
|
863 |
delete [] wstr; |
864 |
} |
865 |
|
866 |
if (new_text) |
867 |
{ |
868 |
wchar_t *wstr = sv2wcs (new_text); |
869 |
|
870 |
int len = min (wcslen (wstr) - start_ofs, max_len); |
871 |
|
872 |
if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
873 |
{ |
874 |
free (wstr); |
875 |
croak ("new_text extends beyond horizontal margins"); |
876 |
} |
877 |
|
878 |
for (int col = start_col; col < start_col + len; col++) |
879 |
{ |
880 |
l.t [col] = wstr [start_ofs + col - start_col]; |
881 |
l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
882 |
} |
883 |
|
884 |
free (wstr); |
885 |
} |
886 |
} |
887 |
|
888 |
void |
889 |
rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
890 |
PPCODE: |
891 |
{ |
892 |
if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
893 |
XSRETURN_EMPTY; |
894 |
|
895 |
line_t &l = ROW(row_number); |
896 |
|
897 |
if (GIMME_V != G_VOID) |
898 |
{ |
899 |
AV *av = newAV (); |
900 |
|
901 |
av_extend (av, THIS->ncol - 1); |
902 |
for (int col = 0; col < THIS->ncol; col++) |
903 |
av_store (av, col, newSViv (l.r [col])); |
904 |
|
905 |
XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
906 |
} |
907 |
|
908 |
if (new_rend) |
909 |
{ |
910 |
if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
911 |
croak ("new_rend must be arrayref"); |
912 |
|
913 |
AV *av = (AV *)SvRV (new_rend); |
914 |
int len = min (av_len (av) + 1 - start_ofs, max_len); |
915 |
|
916 |
if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
917 |
croak ("new_rend array extends beyond horizontal margins"); |
918 |
|
919 |
for (int col = start_col; col < start_col + len; col++) |
920 |
{ |
921 |
rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
922 |
|
923 |
l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
924 |
} |
925 |
} |
926 |
} |
927 |
|
928 |
int |
929 |
rxvt_term::ROW_l (int row_number, int new_length = -1) |
930 |
CODE: |
931 |
{ |
932 |
if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
933 |
XSRETURN_EMPTY; |
934 |
|
935 |
line_t &l = ROW(row_number); |
936 |
RETVAL = l.l; |
937 |
|
938 |
if (new_length >= 0) |
939 |
l.l = new_length; |
940 |
} |
941 |
OUTPUT: |
942 |
RETVAL |
943 |
|
944 |
bool |
945 |
rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
946 |
CODE: |
947 |
{ |
948 |
if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
949 |
XSRETURN_EMPTY; |
950 |
|
951 |
line_t &l = ROW(row_number); |
952 |
RETVAL = l.is_longer (); |
953 |
|
954 |
if (new_is_longer >= 0) |
955 |
l.is_longer (new_is_longer); |
956 |
} |
957 |
OUTPUT: |
958 |
RETVAL |
959 |
|
960 |
SV * |
961 |
rxvt_term::special_encode (SV *str) |
962 |
CODE: |
963 |
abort ();//TODO |
964 |
|
965 |
SV * |
966 |
rxvt_term::special_decode (SV *str) |
967 |
CODE: |
968 |
abort ();//TODO |
969 |
|
970 |
void |
971 |
rxvt_term::_resource (char *name, int index, SV *newval = 0) |
972 |
PPCODE: |
973 |
{ |
974 |
struct resval { const char *name; int value; } rslist [] = { |
975 |
# define def(name) { # name, Rs_ ## name }, |
976 |
# define reserve(name,count) |
977 |
# include "rsinc.h" |
978 |
# undef def |
979 |
# undef reserve |
980 |
}; |
981 |
|
982 |
struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
983 |
|
984 |
do { |
985 |
if (rs-- == rslist) |
986 |
croak ("no such resource '%s', requested", name); |
987 |
} while (strcmp (name, rs->name)); |
988 |
|
989 |
index += rs->value; |
990 |
|
991 |
if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
992 |
croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
993 |
|
994 |
if (GIMME_V != G_VOID) |
995 |
XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
996 |
|
997 |
if (newval) |
998 |
{ |
999 |
if (SvOK (newval)) |
1000 |
{ |
1001 |
char *str = strdup (SvPVbyte_nolen (newval)); |
1002 |
THIS->rs [index] = str; |
1003 |
THIS->allocated.push_back (str); |
1004 |
} |
1005 |
else |
1006 |
THIS->rs [index] = 0; |
1007 |
} |
1008 |
} |
1009 |
|
1010 |
void |
1011 |
rxvt_term::cur (...) |
1012 |
PROTOTYPE: $;$$ |
1013 |
ALIAS: |
1014 |
screen_cur = 0 |
1015 |
selection_beg = 1 |
1016 |
selection_end = 2 |
1017 |
selection_mark = 3 |
1018 |
PPCODE: |
1019 |
{ |
1020 |
row_col_t &rc = ix == 0 ? THIS->screen.cur |
1021 |
: ix == 1 ? THIS->selection.beg |
1022 |
: ix == 2 ? THIS->selection.end |
1023 |
: THIS->selection.mark; |
1024 |
|
1025 |
if (GIMME_V != G_VOID) |
1026 |
{ |
1027 |
EXTEND (SP, 2); |
1028 |
PUSHs (sv_2mortal (newSViv (rc.row))); |
1029 |
PUSHs (sv_2mortal (newSViv (rc.col))); |
1030 |
} |
1031 |
|
1032 |
if (items == 3) |
1033 |
{ |
1034 |
rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
1035 |
rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
1036 |
|
1037 |
if (ix) |
1038 |
THIS->want_refresh = 1; |
1039 |
} |
1040 |
} |
1041 |
|
1042 |
int |
1043 |
rxvt_term::selection_grab (int eventtime = CurrentTime) |
1044 |
|
1045 |
void |
1046 |
rxvt_term::selection (SV *newtext = 0) |
1047 |
PPCODE: |
1048 |
{ |
1049 |
if (GIMME_V != G_VOID) |
1050 |
XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1051 |
|
1052 |
if (newtext) |
1053 |
{ |
1054 |
free (THIS->selection.text); |
1055 |
|
1056 |
THIS->selection.text = sv2wcs (newtext); |
1057 |
THIS->selection.len = wcslen (THIS->selection.text); |
1058 |
} |
1059 |
} |
1060 |
|
1061 |
void |
1062 |
rxvt_term::scr_add_lines (SV *string) |
1063 |
CODE: |
1064 |
{ |
1065 |
wchar_t *wstr = sv2wcs (string); |
1066 |
int wlen = wcslen (wstr); |
1067 |
unicode_t *ustr = new unicode_t [wlen]; |
1068 |
int nlines = 0; |
1069 |
|
1070 |
for (int i = wlen; i--; ) |
1071 |
{ |
1072 |
ustr [i] = wstr [i]; |
1073 |
nlines += ustr [i] == '\012'; |
1074 |
} |
1075 |
|
1076 |
THIS->scr_add_lines (ustr, nlines, wlen); |
1077 |
|
1078 |
free (wstr); |
1079 |
delete [] ustr; |
1080 |
} |
1081 |
|
1082 |
void |
1083 |
rxvt_term::tt_write (SV *octets) |
1084 |
INIT: |
1085 |
STRLEN len; |
1086 |
char *str = SvPVbyte (octets, len); |
1087 |
C_ARGS: |
1088 |
str, len |
1089 |
|
1090 |
void |
1091 |
rxvt_term::cmd_parse (SV *octets) |
1092 |
CODE: |
1093 |
{ |
1094 |
STRLEN len; |
1095 |
char *str = SvPVbyte (octets, len); |
1096 |
|
1097 |
char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
1098 |
char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
1099 |
|
1100 |
THIS->cmdbuf_ptr = str; |
1101 |
THIS->cmdbuf_endp = str + len; |
1102 |
|
1103 |
THIS->cmd_parse (); |
1104 |
|
1105 |
THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
1106 |
THIS->cmdbuf_endp = old_cmdbuf_endp; |
1107 |
} |
1108 |
|
1109 |
SV * |
1110 |
rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1111 |
CODE: |
1112 |
{ |
1113 |
overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1114 |
RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
1115 |
o->self = (HV *)SvRV (RETVAL); |
1116 |
} |
1117 |
OUTPUT: |
1118 |
RETVAL |
1119 |
|
1120 |
MODULE = urxvt PACKAGE = urxvt::overlay |
1121 |
|
1122 |
void |
1123 |
overlay::set (int x, int y, SV *text, SV *rend = 0) |
1124 |
|
1125 |
void |
1126 |
overlay::show () |
1127 |
|
1128 |
void |
1129 |
overlay::hide () |
1130 |
|
1131 |
void |
1132 |
overlay::DESTROY () |
1133 |
|
1134 |
MODULE = urxvt PACKAGE = urxvt::timer |
1135 |
|
1136 |
SV * |
1137 |
timer::new () |
1138 |
CODE: |
1139 |
timer *w = new timer; |
1140 |
w->start (NOW); |
1141 |
RETVAL = newSVptr ((void *)w, "urxvt::timer"); |
1142 |
w->self = (HV *)SvRV (RETVAL); |
1143 |
OUTPUT: |
1144 |
RETVAL |
1145 |
|
1146 |
timer * |
1147 |
timer::cb (SV *cb) |
1148 |
CODE: |
1149 |
THIS->cb (cb); |
1150 |
RETVAL = THIS; |
1151 |
OUTPUT: |
1152 |
RETVAL |
1153 |
|
1154 |
NV |
1155 |
timer::at () |
1156 |
CODE: |
1157 |
RETVAL = THIS->at; |
1158 |
OUTPUT: |
1159 |
RETVAL |
1160 |
|
1161 |
timer * |
1162 |
timer::interval (NV interval) |
1163 |
CODE: |
1164 |
THIS->interval = interval; |
1165 |
RETVAL = THIS; |
1166 |
OUTPUT: |
1167 |
RETVAL |
1168 |
|
1169 |
timer * |
1170 |
timer::set (NV tstamp) |
1171 |
CODE: |
1172 |
THIS->set (tstamp); |
1173 |
RETVAL = THIS; |
1174 |
OUTPUT: |
1175 |
RETVAL |
1176 |
|
1177 |
timer * |
1178 |
timer::start (NV tstamp = THIS->at) |
1179 |
CODE: |
1180 |
THIS->start (tstamp); |
1181 |
RETVAL = THIS; |
1182 |
OUTPUT: |
1183 |
RETVAL |
1184 |
|
1185 |
timer * |
1186 |
timer::stop () |
1187 |
CODE: |
1188 |
THIS->stop (); |
1189 |
RETVAL = THIS; |
1190 |
OUTPUT: |
1191 |
RETVAL |
1192 |
|
1193 |
void |
1194 |
timer::DESTROY () |
1195 |
|
1196 |
MODULE = urxvt PACKAGE = urxvt::iow |
1197 |
|
1198 |
SV * |
1199 |
iow::new () |
1200 |
CODE: |
1201 |
iow *w = new iow; |
1202 |
RETVAL = newSVptr ((void *)w, "urxvt::iow"); |
1203 |
w->self = (HV *)SvRV (RETVAL); |
1204 |
OUTPUT: |
1205 |
RETVAL |
1206 |
|
1207 |
iow * |
1208 |
iow::cb (SV *cb) |
1209 |
CODE: |
1210 |
THIS->cb (cb); |
1211 |
RETVAL = THIS; |
1212 |
OUTPUT: |
1213 |
RETVAL |
1214 |
|
1215 |
iow * |
1216 |
iow::fd (int fd) |
1217 |
CODE: |
1218 |
THIS->fd = fd; |
1219 |
RETVAL = THIS; |
1220 |
OUTPUT: |
1221 |
RETVAL |
1222 |
|
1223 |
iow * |
1224 |
iow::events (short events) |
1225 |
CODE: |
1226 |
THIS->events = events; |
1227 |
RETVAL = THIS; |
1228 |
OUTPUT: |
1229 |
RETVAL |
1230 |
|
1231 |
iow * |
1232 |
iow::start () |
1233 |
CODE: |
1234 |
THIS->start (); |
1235 |
RETVAL = THIS; |
1236 |
OUTPUT: |
1237 |
RETVAL |
1238 |
|
1239 |
iow * |
1240 |
iow::stop () |
1241 |
CODE: |
1242 |
THIS->stop (); |
1243 |
RETVAL = THIS; |
1244 |
OUTPUT: |
1245 |
RETVAL |
1246 |
|
1247 |
void |
1248 |
iow::DESTROY () |
1249 |
|
1250 |
|