1 |
root |
1.1 |
/*----------------------------------------------------------------------* |
2 |
|
|
* File: rxvtperl.xs |
3 |
|
|
*----------------------------------------------------------------------* |
4 |
|
|
* |
5 |
|
|
* All portions of code are copyright by their respective author/s. |
6 |
|
|
* Copyright (c) 2005-2005 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 |
root |
1.8 |
#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 |
root |
1.1 |
///////////////////////////////////////////////////////////////////////////// |
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 |
|
|
new_ref (HV *hv, const char *klass) |
57 |
|
|
{ |
58 |
|
|
return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
//TODO: use magic |
62 |
|
|
static SV * |
63 |
|
|
newSVptr (void *ptr, const char *klass) |
64 |
|
|
{ |
65 |
|
|
HV *hv = newHV (); |
66 |
|
|
hv_store (hv, "_ptr", 4, newSViv ((long)ptr), 0); |
67 |
|
|
return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
static long |
71 |
|
|
SvPTR (SV *sv, const char *klass) |
72 |
|
|
{ |
73 |
|
|
if (!sv_derived_from (sv, klass)) |
74 |
|
|
croak ("object of type %s expected", klass); |
75 |
|
|
|
76 |
|
|
IV iv = SvIV (*hv_fetch ((HV *)SvRV (sv), "_ptr", 4, 1)); |
77 |
|
|
|
78 |
|
|
if (!iv) |
79 |
|
|
croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
80 |
|
|
|
81 |
|
|
return (long)iv; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
#define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
85 |
|
|
#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
86 |
|
|
|
87 |
|
|
///////////////////////////////////////////////////////////////////////////// |
88 |
|
|
|
89 |
|
|
struct perl_watcher |
90 |
|
|
{ |
91 |
|
|
SV *cbsv; |
92 |
|
|
HV *self; |
93 |
|
|
|
94 |
|
|
perl_watcher () |
95 |
|
|
: cbsv (newSV (0)) |
96 |
|
|
{ |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
~perl_watcher () |
100 |
|
|
{ |
101 |
|
|
SvREFCNT_dec (cbsv); |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
void cb (SV *cb) |
105 |
|
|
{ |
106 |
|
|
sv_setsv (cbsv, cb); |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
void invoke (const char *type, SV *self, int arg = -1); |
110 |
|
|
}; |
111 |
|
|
|
112 |
|
|
void |
113 |
|
|
perl_watcher::invoke (const char *type, SV *self, int arg) |
114 |
|
|
{ |
115 |
|
|
dSP; |
116 |
|
|
|
117 |
|
|
ENTER; |
118 |
|
|
SAVETMPS; |
119 |
|
|
|
120 |
|
|
PUSHMARK (SP); |
121 |
|
|
|
122 |
|
|
XPUSHs (sv_2mortal (self)); |
123 |
|
|
|
124 |
|
|
if (arg >= 0) |
125 |
|
|
XPUSHs (sv_2mortal (newSViv (arg))); |
126 |
|
|
|
127 |
|
|
PUTBACK; |
128 |
|
|
call_sv (cbsv, G_VOID | G_EVAL | G_DISCARD); |
129 |
|
|
SPAGAIN; |
130 |
|
|
|
131 |
|
|
PUTBACK; |
132 |
|
|
FREETMPS; |
133 |
|
|
LEAVE; |
134 |
|
|
|
135 |
|
|
if (SvTRUE (ERRSV)) |
136 |
|
|
rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV)); |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
#define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") |
140 |
|
|
#define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") |
141 |
|
|
|
142 |
|
|
struct timer : time_watcher, perl_watcher |
143 |
|
|
{ |
144 |
root |
1.13 |
tstamp interval; |
145 |
|
|
|
146 |
root |
1.1 |
timer () |
147 |
|
|
: time_watcher (this, &timer::execute) |
148 |
|
|
{ |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
void execute (time_watcher &w) |
152 |
|
|
{ |
153 |
root |
1.13 |
if (interval) |
154 |
|
|
start (at + interval); |
155 |
|
|
|
156 |
root |
1.1 |
invoke ("urxvt::timer", newSVtimer (this)); |
157 |
|
|
} |
158 |
|
|
}; |
159 |
|
|
|
160 |
|
|
#define newSViow(iow) new_ref (iow->self, "urxvt::iow") |
161 |
|
|
#define SvIOW(sv) (iow *)SvPTR (sv, "urxvt::iow") |
162 |
|
|
|
163 |
|
|
struct iow : io_watcher, perl_watcher |
164 |
|
|
{ |
165 |
|
|
iow () |
166 |
|
|
: io_watcher (this, &iow::execute) |
167 |
|
|
{ |
168 |
|
|
} |
169 |
|
|
|
170 |
|
|
void execute (io_watcher &w, short revents) |
171 |
|
|
{ |
172 |
|
|
invoke ("urxvt::iow", newSViow (this), revents); |
173 |
|
|
} |
174 |
|
|
}; |
175 |
|
|
|
176 |
|
|
///////////////////////////////////////////////////////////////////////////// |
177 |
|
|
|
178 |
root |
1.13 |
#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") |
179 |
|
|
|
180 |
|
|
struct overlay { |
181 |
|
|
HV *self; |
182 |
|
|
rxvt_term *THIS; |
183 |
|
|
int x, y, w, h; |
184 |
|
|
int border; |
185 |
|
|
text_t **text; |
186 |
|
|
rend_t **rend; |
187 |
|
|
|
188 |
|
|
overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
189 |
|
|
~overlay (); |
190 |
|
|
|
191 |
|
|
void swap (); |
192 |
|
|
|
193 |
|
|
void set (int x, int y, SV *str, SV *rend); |
194 |
|
|
}; |
195 |
|
|
|
196 |
|
|
overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) |
197 |
|
|
: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2) |
198 |
|
|
{ |
199 |
|
|
if (border == 2) |
200 |
|
|
{ |
201 |
|
|
w += 2; |
202 |
|
|
h += 2; |
203 |
|
|
} |
204 |
|
|
|
205 |
|
|
text = new text_t *[h]; |
206 |
|
|
rend = new rend_t *[h]; |
207 |
|
|
|
208 |
|
|
for (int y = 0; y < h; y++) |
209 |
|
|
{ |
210 |
|
|
text_t *tp = text[y] = new text_t[w]; |
211 |
|
|
rend_t *rp = rend[y] = new rend_t[w]; |
212 |
|
|
|
213 |
|
|
text_t t0, t1, t2; |
214 |
|
|
rend_t r = rstyle; |
215 |
|
|
|
216 |
|
|
if (border == 2) |
217 |
|
|
{ |
218 |
|
|
if (y == 0) |
219 |
|
|
t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
220 |
|
|
else if (y < h - 1) |
221 |
|
|
t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
222 |
|
|
else |
223 |
|
|
t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
224 |
|
|
|
225 |
|
|
*tp++ = t0; |
226 |
|
|
*rp++ = r; |
227 |
|
|
|
228 |
|
|
for (int x = w - 2; x-- > 0; ) |
229 |
|
|
{ |
230 |
|
|
*tp++ = t1; |
231 |
|
|
*rp++ = r; |
232 |
|
|
} |
233 |
|
|
|
234 |
|
|
*tp = t2; |
235 |
|
|
*rp = r; |
236 |
|
|
} |
237 |
|
|
else |
238 |
|
|
for (int x = w; x-- > 0; ) |
239 |
|
|
{ |
240 |
|
|
*tp++ = 0x0020; |
241 |
|
|
*rp++ = r; |
242 |
|
|
} |
243 |
|
|
} |
244 |
|
|
|
245 |
|
|
THIS->want_refresh = 1; |
246 |
|
|
} |
247 |
|
|
|
248 |
|
|
overlay::~overlay () |
249 |
|
|
{ |
250 |
|
|
for (int y = h; y--; ) |
251 |
|
|
{ |
252 |
|
|
delete [] text[y]; |
253 |
|
|
delete [] rend[y]; |
254 |
|
|
} |
255 |
|
|
|
256 |
|
|
delete [] text; |
257 |
|
|
delete [] rend; |
258 |
|
|
|
259 |
|
|
THIS->want_refresh = 1; |
260 |
|
|
} |
261 |
|
|
|
262 |
|
|
void overlay::swap () |
263 |
|
|
{ |
264 |
|
|
int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
265 |
|
|
int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); |
266 |
|
|
|
267 |
|
|
int ov_w = min (w, THIS->ncol - ov_x); |
268 |
|
|
int ov_h = min (h, THIS->nrow - ov_y); |
269 |
|
|
|
270 |
|
|
for (int y = ov_h; y--; ) |
271 |
|
|
{ |
272 |
|
|
text_t *t1 = text [y]; |
273 |
|
|
rend_t *r1 = rend [y]; |
274 |
|
|
|
275 |
|
|
text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
276 |
|
|
rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
277 |
|
|
|
278 |
|
|
for (int x = ov_w; x--; ) |
279 |
|
|
{ |
280 |
|
|
text_t t = *t1; *t1++ = *t2; *t2++ = t; |
281 |
|
|
rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
282 |
|
|
} |
283 |
|
|
} |
284 |
|
|
|
285 |
|
|
} |
286 |
|
|
|
287 |
root |
1.14 |
void overlay::set (int x, int y, SV *text, SV *rend) |
288 |
root |
1.13 |
{ |
289 |
|
|
x += border; |
290 |
|
|
y += border; |
291 |
|
|
|
292 |
|
|
if (!IN_RANGE_EXC (y, 0, h - border)) |
293 |
|
|
return; |
294 |
|
|
|
295 |
root |
1.14 |
wchar_t *wtext = sv2wcs (text); |
296 |
root |
1.13 |
|
297 |
root |
1.14 |
for (int col = min (wcslen (wtext), w - x - border); col--; ) |
298 |
|
|
this->text [y][x + col] = wtext [col]; |
299 |
root |
1.13 |
|
300 |
root |
1.14 |
free (wtext); |
301 |
|
|
|
302 |
|
|
if (rend) |
303 |
|
|
{ |
304 |
|
|
if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
305 |
|
|
croak ("rend must be arrayref"); |
306 |
|
|
|
307 |
|
|
AV *av = (AV *)SvRV (rend); |
308 |
|
|
|
309 |
|
|
for (int col = min (av_len (av) + 1, w - x - border); col--; ) |
310 |
|
|
this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
311 |
|
|
} |
312 |
root |
1.13 |
|
313 |
|
|
THIS->want_refresh = 1; |
314 |
|
|
} |
315 |
|
|
|
316 |
|
|
|
317 |
|
|
///////////////////////////////////////////////////////////////////////////// |
318 |
|
|
|
319 |
root |
1.1 |
struct rxvt_perl_interp rxvt_perl; |
320 |
|
|
|
321 |
|
|
static PerlInterpreter *perl; |
322 |
|
|
|
323 |
|
|
rxvt_perl_interp::rxvt_perl_interp () |
324 |
|
|
{ |
325 |
|
|
} |
326 |
|
|
|
327 |
|
|
rxvt_perl_interp::~rxvt_perl_interp () |
328 |
|
|
{ |
329 |
|
|
if (perl) |
330 |
|
|
{ |
331 |
|
|
perl_destruct (perl); |
332 |
|
|
perl_free (perl); |
333 |
|
|
} |
334 |
|
|
} |
335 |
|
|
|
336 |
|
|
void |
337 |
|
|
rxvt_perl_interp::init () |
338 |
|
|
{ |
339 |
|
|
if (!perl) |
340 |
|
|
{ |
341 |
|
|
char *argv[] = { |
342 |
|
|
"", |
343 |
|
|
"-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
344 |
|
|
}; |
345 |
|
|
|
346 |
|
|
perl = perl_alloc (); |
347 |
|
|
perl_construct (perl); |
348 |
|
|
|
349 |
|
|
if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
350 |
|
|
|| perl_run (perl)) |
351 |
|
|
{ |
352 |
|
|
rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
353 |
|
|
|
354 |
|
|
perl_destruct (perl); |
355 |
|
|
perl_free (perl); |
356 |
|
|
perl = 0; |
357 |
|
|
} |
358 |
|
|
} |
359 |
|
|
} |
360 |
|
|
|
361 |
|
|
bool |
362 |
|
|
rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
363 |
|
|
{ |
364 |
root |
1.13 |
if (!perl) |
365 |
root |
1.1 |
return false; |
366 |
root |
1.4 |
|
367 |
root |
1.1 |
if (htype == HOOK_INIT) // first hook ever called |
368 |
root |
1.13 |
{ |
369 |
|
|
term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
370 |
|
|
hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
371 |
|
|
} |
372 |
|
|
else if (htype == HOOK_DESTROY) |
373 |
|
|
{ |
374 |
|
|
// handled later |
375 |
|
|
} |
376 |
|
|
else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
377 |
|
|
{ |
378 |
|
|
HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
379 |
|
|
|
380 |
|
|
if (HvKEYS (hv)) |
381 |
|
|
{ |
382 |
|
|
hv_iterinit (hv); |
383 |
|
|
|
384 |
|
|
while (HE *he = hv_iternext (hv)) |
385 |
|
|
((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
386 |
|
|
} |
387 |
|
|
} |
388 |
|
|
else if (!should_invoke [htype]) |
389 |
|
|
return false; |
390 |
root |
1.1 |
|
391 |
|
|
dSP; |
392 |
|
|
va_list ap; |
393 |
|
|
|
394 |
|
|
va_start (ap, htype); |
395 |
|
|
|
396 |
|
|
ENTER; |
397 |
|
|
SAVETMPS; |
398 |
|
|
|
399 |
|
|
PUSHMARK (SP); |
400 |
|
|
|
401 |
|
|
XPUSHs (sv_2mortal (newSVterm (term))); |
402 |
|
|
XPUSHs (sv_2mortal (newSViv (htype))); |
403 |
|
|
|
404 |
|
|
for (;;) { |
405 |
|
|
data_type dt = (data_type)va_arg (ap, int); |
406 |
|
|
|
407 |
|
|
switch (dt) |
408 |
|
|
{ |
409 |
|
|
case DT_INT: |
410 |
|
|
XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
411 |
|
|
break; |
412 |
|
|
|
413 |
|
|
case DT_LONG: |
414 |
|
|
XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
415 |
|
|
break; |
416 |
|
|
|
417 |
root |
1.6 |
case DT_STRING: |
418 |
|
|
XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
419 |
|
|
break; |
420 |
|
|
|
421 |
root |
1.1 |
case DT_END: |
422 |
|
|
{ |
423 |
|
|
va_end (ap); |
424 |
|
|
|
425 |
|
|
PUTBACK; |
426 |
|
|
int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
427 |
|
|
SPAGAIN; |
428 |
|
|
|
429 |
|
|
if (count) |
430 |
|
|
{ |
431 |
|
|
SV *status = POPs; |
432 |
|
|
count = SvTRUE (status); |
433 |
|
|
} |
434 |
|
|
|
435 |
|
|
PUTBACK; |
436 |
|
|
FREETMPS; |
437 |
|
|
LEAVE; |
438 |
|
|
|
439 |
|
|
if (SvTRUE (ERRSV)) |
440 |
|
|
rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
441 |
|
|
|
442 |
root |
1.4 |
if (htype == HOOK_DESTROY) |
443 |
|
|
{ |
444 |
|
|
// TODO: clear magic |
445 |
|
|
hv_clear ((HV *)SvRV ((SV *)term->self)); |
446 |
|
|
SvREFCNT_dec ((SV *)term->self); |
447 |
|
|
} |
448 |
|
|
|
449 |
root |
1.1 |
return count; |
450 |
|
|
} |
451 |
|
|
|
452 |
|
|
default: |
453 |
|
|
rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
454 |
|
|
} |
455 |
|
|
} |
456 |
|
|
} |
457 |
|
|
|
458 |
|
|
///////////////////////////////////////////////////////////////////////////// |
459 |
|
|
|
460 |
|
|
MODULE = urxvt PACKAGE = urxvt |
461 |
|
|
|
462 |
|
|
PROTOTYPES: ENABLE |
463 |
|
|
|
464 |
|
|
BOOT: |
465 |
|
|
{ |
466 |
|
|
# define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0)) |
467 |
root |
1.11 |
# define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), #name, newSViv (name)); |
468 |
root |
1.1 |
AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
469 |
|
|
set_hookname (INIT); |
470 |
|
|
set_hookname (RESET); |
471 |
|
|
set_hookname (START); |
472 |
|
|
set_hookname (DESTROY); |
473 |
|
|
set_hookname (SEL_BEGIN); |
474 |
|
|
set_hookname (SEL_EXTEND); |
475 |
|
|
set_hookname (SEL_MAKE); |
476 |
|
|
set_hookname (SEL_GRAB); |
477 |
root |
1.16 |
set_hookname (SEL_CLICK); |
478 |
root |
1.1 |
set_hookname (FOCUS_IN); |
479 |
|
|
set_hookname (FOCUS_OUT); |
480 |
|
|
set_hookname (VIEW_CHANGE); |
481 |
|
|
set_hookname (SCROLL_BACK); |
482 |
|
|
set_hookname (TTY_ACTIVITY); |
483 |
|
|
set_hookname (REFRESH_BEGIN); |
484 |
|
|
set_hookname (REFRESH_END); |
485 |
root |
1.6 |
set_hookname (KEYBOARD_COMMAND); |
486 |
root |
1.16 |
set_hookname (MOUSE_CLICK); |
487 |
|
|
set_hookname (MOUSE_MOVE); |
488 |
root |
1.1 |
|
489 |
root |
1.11 |
export_const (DEFAULT_RSTYLE); |
490 |
|
|
export_const (OVERLAY_RSTYLE); |
491 |
|
|
export_const (RS_Bold); |
492 |
|
|
export_const (RS_Italic); |
493 |
|
|
export_const (RS_Blink); |
494 |
|
|
export_const (RS_RVid); |
495 |
|
|
export_const (RS_Uline); |
496 |
root |
1.9 |
|
497 |
root |
1.1 |
sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
498 |
|
|
} |
499 |
|
|
|
500 |
|
|
void |
501 |
|
|
set_should_invoke (int htype, int value) |
502 |
|
|
CODE: |
503 |
|
|
rxvt_perl.should_invoke [htype] = value; |
504 |
|
|
|
505 |
|
|
void |
506 |
|
|
warn (const char *msg) |
507 |
|
|
CODE: |
508 |
|
|
rxvt_warn ("%s", msg); |
509 |
|
|
|
510 |
|
|
void |
511 |
|
|
fatal (const char *msg) |
512 |
|
|
CODE: |
513 |
|
|
rxvt_fatal ("%s", msg); |
514 |
|
|
|
515 |
root |
1.3 |
NV |
516 |
|
|
NOW () |
517 |
|
|
CODE: |
518 |
|
|
RETVAL = NOW; |
519 |
|
|
OUTPUT: |
520 |
|
|
RETVAL |
521 |
|
|
|
522 |
root |
1.11 |
int |
523 |
|
|
GET_BASEFG (int rend) |
524 |
|
|
CODE: |
525 |
|
|
RETVAL = GET_BASEFG (rend); |
526 |
|
|
OUTPUT: |
527 |
|
|
RETVAL |
528 |
|
|
|
529 |
|
|
int |
530 |
|
|
GET_BASEBG (int rend) |
531 |
|
|
CODE: |
532 |
|
|
RETVAL = GET_BASEBG (rend); |
533 |
|
|
OUTPUT: |
534 |
|
|
RETVAL |
535 |
|
|
|
536 |
|
|
int |
537 |
root |
1.12 |
SET_FGCOLOR (int rend, int new_color) |
538 |
root |
1.11 |
CODE: |
539 |
root |
1.12 |
RETVAL = SET_FGCOLOR (rend, new_color); |
540 |
root |
1.11 |
OUTPUT: |
541 |
|
|
RETVAL |
542 |
|
|
|
543 |
|
|
int |
544 |
root |
1.12 |
SET_BGCOLOR (int rend, int new_color) |
545 |
root |
1.11 |
CODE: |
546 |
root |
1.12 |
RETVAL = SET_BGCOLOR (rend, new_color); |
547 |
|
|
OUTPUT: |
548 |
|
|
RETVAL |
549 |
|
|
|
550 |
|
|
int |
551 |
|
|
GET_CUSTOM (int rend) |
552 |
|
|
CODE: |
553 |
|
|
RETVAL = (rend && RS_customMask) >> RS_customShift; |
554 |
|
|
OUTPUT: |
555 |
|
|
RETVAL |
556 |
|
|
|
557 |
|
|
int |
558 |
|
|
SET_CUSTOM (int rend, int new_value) |
559 |
|
|
CODE: |
560 |
|
|
{ |
561 |
|
|
if (!IN_RANGE_EXC (new_value, 0, RS_customCount)) |
562 |
|
|
croak ("custom value out of range, must be 0..%d", RS_customCount - 1); |
563 |
|
|
|
564 |
|
|
RETVAL = (rend & ~RS_customMask) |
565 |
|
|
| ((new_value << RS_customShift) & RS_customMask); |
566 |
|
|
} |
567 |
root |
1.11 |
OUTPUT: |
568 |
|
|
RETVAL |
569 |
|
|
|
570 |
root |
1.3 |
MODULE = urxvt PACKAGE = urxvt::term |
571 |
|
|
|
572 |
root |
1.1 |
int |
573 |
root |
1.3 |
rxvt_term::strwidth (SV *str) |
574 |
root |
1.1 |
CODE: |
575 |
|
|
{ |
576 |
|
|
wchar_t *wstr = sv2wcs (str); |
577 |
root |
1.3 |
|
578 |
|
|
rxvt_push_locale (THIS->locale); |
579 |
root |
1.1 |
RETVAL = wcswidth (wstr, wcslen (wstr)); |
580 |
root |
1.3 |
rxvt_pop_locale (); |
581 |
|
|
|
582 |
root |
1.1 |
free (wstr); |
583 |
|
|
} |
584 |
|
|
OUTPUT: |
585 |
|
|
RETVAL |
586 |
|
|
|
587 |
root |
1.3 |
SV * |
588 |
|
|
rxvt_term::locale_encode (SV *str) |
589 |
root |
1.1 |
CODE: |
590 |
root |
1.3 |
{ |
591 |
|
|
wchar_t *wstr = sv2wcs (str); |
592 |
|
|
|
593 |
|
|
rxvt_push_locale (THIS->locale); |
594 |
|
|
char *mbstr = rxvt_wcstombs (wstr); |
595 |
|
|
rxvt_pop_locale (); |
596 |
|
|
|
597 |
|
|
free (wstr); |
598 |
|
|
|
599 |
|
|
RETVAL = newSVpv (mbstr, 0); |
600 |
|
|
free (mbstr); |
601 |
|
|
} |
602 |
|
|
OUTPUT: |
603 |
root |
1.1 |
RETVAL |
604 |
|
|
|
605 |
root |
1.3 |
SV * |
606 |
|
|
rxvt_term::locale_decode (SV *octets) |
607 |
|
|
CODE: |
608 |
|
|
{ |
609 |
|
|
STRLEN len; |
610 |
|
|
char *data = SvPVbyte (octets, len); |
611 |
|
|
|
612 |
|
|
rxvt_push_locale (THIS->locale); |
613 |
|
|
wchar_t *wstr = rxvt_mbstowcs (data, len); |
614 |
|
|
rxvt_pop_locale (); |
615 |
|
|
|
616 |
|
|
char *str = rxvt_wcstoutf8 (wstr); |
617 |
|
|
free (wstr); |
618 |
|
|
|
619 |
|
|
RETVAL = newSVpv (str, 0); |
620 |
|
|
SvUTF8_on (RETVAL); |
621 |
|
|
free (str); |
622 |
|
|
} |
623 |
|
|
OUTPUT: |
624 |
|
|
RETVAL |
625 |
root |
1.1 |
|
626 |
root |
1.7 |
int |
627 |
|
|
rxvt_term::nsaved () |
628 |
|
|
CODE: |
629 |
|
|
RETVAL = THIS->nsaved; |
630 |
|
|
OUTPUT: |
631 |
|
|
RETVAL |
632 |
|
|
|
633 |
|
|
int |
634 |
|
|
rxvt_term::view_start (int newval = -1) |
635 |
|
|
CODE: |
636 |
|
|
{ |
637 |
|
|
RETVAL = THIS->view_start; |
638 |
|
|
|
639 |
|
|
if (newval >= 0) |
640 |
|
|
{ |
641 |
|
|
THIS->view_start = min (newval, THIS->nsaved); |
642 |
|
|
THIS->scr_changeview (RETVAL); |
643 |
|
|
} |
644 |
|
|
} |
645 |
|
|
OUTPUT: |
646 |
|
|
RETVAL |
647 |
|
|
|
648 |
root |
1.8 |
int |
649 |
|
|
rxvt_term::nrow () |
650 |
|
|
CODE: |
651 |
|
|
RETVAL = THIS->nrow; |
652 |
|
|
OUTPUT: |
653 |
|
|
RETVAL |
654 |
|
|
|
655 |
|
|
int |
656 |
|
|
rxvt_term::ncol () |
657 |
|
|
CODE: |
658 |
|
|
RETVAL = THIS->ncol; |
659 |
|
|
OUTPUT: |
660 |
|
|
RETVAL |
661 |
|
|
|
662 |
|
|
void |
663 |
root |
1.9 |
rxvt_term::want_refresh () |
664 |
|
|
CODE: |
665 |
|
|
THIS->want_refresh = 1; |
666 |
|
|
|
667 |
|
|
void |
668 |
root |
1.8 |
rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
669 |
|
|
PPCODE: |
670 |
|
|
{ |
671 |
|
|
if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
672 |
|
|
croak ("row_number number of out range"); |
673 |
|
|
|
674 |
|
|
line_t &l = ROW(row_number); |
675 |
|
|
|
676 |
|
|
if (GIMME_V != G_VOID) |
677 |
|
|
{ |
678 |
|
|
wchar_t *wstr = new wchar_t [THIS->ncol]; |
679 |
|
|
|
680 |
|
|
for (int col = 0; col <THIS->ncol; col++) |
681 |
|
|
wstr [col] = l.t [col]; |
682 |
|
|
|
683 |
|
|
char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); |
684 |
|
|
free (wstr); |
685 |
|
|
|
686 |
|
|
SV *sv = newSVpv (str, 0); |
687 |
|
|
SvUTF8_on (sv); |
688 |
|
|
XPUSHs (sv_2mortal (sv)); |
689 |
|
|
free (str); |
690 |
|
|
} |
691 |
|
|
|
692 |
|
|
if (new_text) |
693 |
|
|
{ |
694 |
root |
1.13 |
wchar_t *wstr = sv2wcs (new_text); |
695 |
root |
1.8 |
|
696 |
|
|
int len = wcslen (wstr); |
697 |
|
|
|
698 |
root |
1.10 |
if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
699 |
root |
1.8 |
{ |
700 |
|
|
free (wstr); |
701 |
root |
1.10 |
croak ("new_text extends beyond horizontal margins"); |
702 |
root |
1.8 |
} |
703 |
|
|
|
704 |
|
|
for (int col = start_col; col < start_col + len; col++) |
705 |
|
|
{ |
706 |
root |
1.9 |
l.t [col] = wstr [col - start_col]; |
707 |
root |
1.8 |
l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
708 |
|
|
} |
709 |
root |
1.9 |
|
710 |
|
|
free (wstr); |
711 |
root |
1.8 |
} |
712 |
|
|
} |
713 |
|
|
|
714 |
|
|
void |
715 |
|
|
rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
716 |
|
|
PPCODE: |
717 |
|
|
{ |
718 |
|
|
if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
719 |
|
|
croak ("row_number number of out range"); |
720 |
|
|
|
721 |
|
|
line_t &l = ROW(row_number); |
722 |
|
|
|
723 |
|
|
if (GIMME_V != G_VOID) |
724 |
|
|
{ |
725 |
|
|
AV *av = newAV (); |
726 |
|
|
|
727 |
|
|
av_extend (av, THIS->ncol - 1); |
728 |
|
|
for (int col = 0; col < THIS->ncol; col++) |
729 |
|
|
av_store (av, col, newSViv (l.r [col])); |
730 |
|
|
|
731 |
|
|
XPUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
732 |
|
|
} |
733 |
|
|
|
734 |
|
|
if (new_rend) |
735 |
|
|
{ |
736 |
|
|
if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
737 |
|
|
croak ("new_rend must be arrayref"); |
738 |
|
|
|
739 |
|
|
AV *av = (AV *)SvRV (new_rend); |
740 |
|
|
int len = av_len (av) + 1; |
741 |
|
|
|
742 |
root |
1.10 |
if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
743 |
|
|
croak ("new_rend array extends beyond horizontal margins"); |
744 |
root |
1.8 |
|
745 |
|
|
for (int col = start_col; col < start_col + len; col++) |
746 |
|
|
{ |
747 |
root |
1.9 |
rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
748 |
root |
1.8 |
|
749 |
|
|
l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
750 |
|
|
} |
751 |
|
|
} |
752 |
|
|
} |
753 |
|
|
|
754 |
|
|
int |
755 |
|
|
rxvt_term::ROW_l (int row_number, int new_length = -2) |
756 |
|
|
CODE: |
757 |
|
|
{ |
758 |
|
|
if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
759 |
|
|
croak ("row_number number of out range"); |
760 |
|
|
|
761 |
|
|
line_t &l = ROW(row_number); |
762 |
|
|
RETVAL = l.l; |
763 |
|
|
|
764 |
|
|
if (new_length >= -1) |
765 |
|
|
l.l = new_length; |
766 |
|
|
} |
767 |
|
|
OUTPUT: |
768 |
|
|
RETVAL |
769 |
|
|
|
770 |
|
|
SV * |
771 |
|
|
rxvt_term::special_encode (SV *str) |
772 |
|
|
CODE: |
773 |
|
|
abort ();//TODO |
774 |
|
|
|
775 |
|
|
SV * |
776 |
|
|
rxvt_term::special_decode (SV *str) |
777 |
|
|
CODE: |
778 |
|
|
abort ();//TODO |
779 |
|
|
|
780 |
root |
1.1 |
void |
781 |
root |
1.2 |
rxvt_term::_resource (char *name, int index, SV *newval = 0) |
782 |
|
|
PPCODE: |
783 |
|
|
{ |
784 |
|
|
struct resval { const char *name; int value; } rslist [] = { |
785 |
|
|
# define Rs_def(name) { # name, Rs_ ## name }, |
786 |
|
|
# define Rs_reserve(name,count) |
787 |
|
|
# include "rsinc.h" |
788 |
|
|
# undef Rs_def |
789 |
|
|
# undef Rs_reserve |
790 |
|
|
}; |
791 |
|
|
|
792 |
|
|
struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
793 |
|
|
|
794 |
|
|
do { |
795 |
|
|
if (rs-- == rslist) |
796 |
|
|
croak ("no such resource '%s', requested", name); |
797 |
|
|
} while (strcmp (name, rs->name)); |
798 |
|
|
|
799 |
|
|
index += rs->value; |
800 |
|
|
|
801 |
|
|
if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
802 |
|
|
croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
803 |
|
|
|
804 |
|
|
if (GIMME_V != G_VOID) |
805 |
|
|
XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
806 |
|
|
|
807 |
|
|
if (newval) |
808 |
|
|
{ |
809 |
|
|
if (SvOK (newval)) |
810 |
|
|
{ |
811 |
|
|
char *str = strdup (SvPVbyte_nolen (newval)); |
812 |
|
|
THIS->rs [index] = str; |
813 |
|
|
THIS->allocated.push_back (str); |
814 |
|
|
} |
815 |
|
|
else |
816 |
|
|
THIS->rs [index] = 0; |
817 |
|
|
} |
818 |
|
|
} |
819 |
|
|
|
820 |
|
|
void |
821 |
root |
1.1 |
rxvt_term::selection_mark (...) |
822 |
|
|
PROTOTYPE: $;$$ |
823 |
|
|
ALIAS: |
824 |
|
|
selection_beg = 1 |
825 |
|
|
selection_end = 2 |
826 |
|
|
PPCODE: |
827 |
|
|
{ |
828 |
|
|
row_col_t &sel = ix == 1 ? THIS->selection.beg |
829 |
|
|
: ix == 2 ? THIS->selection.end |
830 |
|
|
: THIS->selection.mark; |
831 |
|
|
|
832 |
|
|
if (GIMME_V != G_VOID) |
833 |
|
|
{ |
834 |
|
|
EXTEND (SP, 2); |
835 |
|
|
PUSHs (sv_2mortal (newSViv (sel.row))); |
836 |
|
|
PUSHs (sv_2mortal (newSViv (sel.col))); |
837 |
|
|
} |
838 |
|
|
|
839 |
|
|
if (items == 3) |
840 |
|
|
{ |
841 |
|
|
sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
842 |
|
|
sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
843 |
|
|
|
844 |
|
|
if (ix) |
845 |
|
|
THIS->want_refresh = 1; |
846 |
|
|
} |
847 |
|
|
} |
848 |
|
|
|
849 |
|
|
int |
850 |
root |
1.15 |
rxvt_term::selection_grab (int eventtime = CurrentTime) |
851 |
root |
1.1 |
|
852 |
|
|
void |
853 |
|
|
rxvt_term::selection (SV *newtext = 0) |
854 |
|
|
PPCODE: |
855 |
|
|
{ |
856 |
|
|
if (GIMME_V != G_VOID) |
857 |
|
|
{ |
858 |
|
|
char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); |
859 |
|
|
SV *sv = newSVpv (sel, 0); |
860 |
|
|
SvUTF8_on (sv); |
861 |
|
|
free (sel); |
862 |
|
|
XPUSHs (sv_2mortal (sv)); |
863 |
|
|
} |
864 |
|
|
|
865 |
|
|
if (newtext) |
866 |
|
|
{ |
867 |
|
|
free (THIS->selection.text); |
868 |
|
|
|
869 |
|
|
THIS->selection.text = sv2wcs (newtext); |
870 |
|
|
THIS->selection.len = wcslen (THIS->selection.text); |
871 |
|
|
} |
872 |
|
|
} |
873 |
|
|
|
874 |
|
|
void |
875 |
root |
1.13 |
rxvt_term::tt_write (SV *octets) |
876 |
|
|
INIT: |
877 |
|
|
STRLEN len; |
878 |
|
|
char *str = SvPVbyte (octets, len); |
879 |
|
|
C_ARGS: |
880 |
|
|
(unsigned char *)str, len |
881 |
|
|
|
882 |
|
|
SV * |
883 |
|
|
rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
884 |
|
|
CODE: |
885 |
|
|
{ |
886 |
|
|
overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
887 |
|
|
RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
888 |
|
|
o->self = (HV *)SvRV (RETVAL); |
889 |
root |
1.1 |
|
890 |
root |
1.13 |
HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
891 |
|
|
char key[33]; sprintf (key, "%32lx", (long)o); |
892 |
|
|
hv_store (hv, key, 32, newSViv ((long)o), 0); |
893 |
|
|
} |
894 |
|
|
OUTPUT: |
895 |
|
|
RETVAL |
896 |
|
|
|
897 |
|
|
MODULE = urxvt PACKAGE = urxvt::overlay |
898 |
root |
1.1 |
|
899 |
|
|
void |
900 |
root |
1.13 |
overlay::set (int x, int y, SV *text, SV *rend = 0) |
901 |
root |
1.1 |
|
902 |
|
|
void |
903 |
root |
1.13 |
overlay::DESTROY () |
904 |
root |
1.1 |
CODE: |
905 |
|
|
{ |
906 |
root |
1.13 |
SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->THIS->self), "_overlay", 8, 0); |
907 |
|
|
if (ovs) |
908 |
|
|
{ |
909 |
|
|
HV *hv = (HV *)SvRV (*ovs); |
910 |
|
|
char key[33]; sprintf (key, "%32lx", (long)THIS); |
911 |
|
|
hv_delete (hv, key, 32, G_DISCARD); |
912 |
|
|
} |
913 |
|
|
|
914 |
|
|
delete THIS; |
915 |
root |
1.1 |
} |
916 |
|
|
|
917 |
|
|
MODULE = urxvt PACKAGE = urxvt::timer |
918 |
|
|
|
919 |
|
|
SV * |
920 |
|
|
timer::new () |
921 |
|
|
CODE: |
922 |
|
|
timer *w = new timer; |
923 |
root |
1.13 |
w->start (NOW); |
924 |
root |
1.1 |
RETVAL = newSVptr ((void *)w, "urxvt::timer"); |
925 |
|
|
w->self = (HV *)SvRV (RETVAL); |
926 |
|
|
OUTPUT: |
927 |
|
|
RETVAL |
928 |
|
|
|
929 |
|
|
timer * |
930 |
|
|
timer::cb (SV *cb) |
931 |
|
|
CODE: |
932 |
|
|
THIS->cb (cb); |
933 |
|
|
RETVAL = THIS; |
934 |
|
|
OUTPUT: |
935 |
|
|
RETVAL |
936 |
|
|
|
937 |
|
|
NV |
938 |
|
|
timer::at () |
939 |
|
|
CODE: |
940 |
|
|
RETVAL = THIS->at; |
941 |
|
|
OUTPUT: |
942 |
|
|
RETVAL |
943 |
|
|
|
944 |
|
|
timer * |
945 |
root |
1.13 |
timer::interval (NV interval) |
946 |
|
|
CODE: |
947 |
|
|
THIS->interval = interval; |
948 |
|
|
RETVAL = THIS; |
949 |
|
|
OUTPUT: |
950 |
|
|
RETVAL |
951 |
|
|
|
952 |
|
|
timer * |
953 |
root |
1.1 |
timer::set (NV tstamp) |
954 |
|
|
CODE: |
955 |
|
|
THIS->set (tstamp); |
956 |
|
|
RETVAL = THIS; |
957 |
|
|
OUTPUT: |
958 |
|
|
RETVAL |
959 |
|
|
|
960 |
|
|
timer * |
961 |
|
|
timer::start (NV tstamp = THIS->at) |
962 |
|
|
CODE: |
963 |
|
|
THIS->start (tstamp); |
964 |
|
|
RETVAL = THIS; |
965 |
|
|
OUTPUT: |
966 |
|
|
RETVAL |
967 |
|
|
|
968 |
|
|
timer * |
969 |
|
|
timer::stop () |
970 |
|
|
CODE: |
971 |
|
|
THIS->stop (); |
972 |
|
|
RETVAL = THIS; |
973 |
|
|
OUTPUT: |
974 |
|
|
RETVAL |
975 |
|
|
|
976 |
|
|
void |
977 |
|
|
timer::DESTROY () |
978 |
|
|
|
979 |
|
|
MODULE = urxvt PACKAGE = urxvt::iow |
980 |
|
|
|
981 |
|
|
SV * |
982 |
|
|
iow::new () |
983 |
|
|
CODE: |
984 |
|
|
iow *w = new iow; |
985 |
|
|
RETVAL = newSVptr ((void *)w, "urxvt::iow"); |
986 |
|
|
w->self = (HV *)SvRV (RETVAL); |
987 |
|
|
OUTPUT: |
988 |
|
|
RETVAL |
989 |
|
|
|
990 |
|
|
iow * |
991 |
|
|
iow::cb (SV *cb) |
992 |
|
|
CODE: |
993 |
|
|
THIS->cb (cb); |
994 |
|
|
RETVAL = THIS; |
995 |
|
|
OUTPUT: |
996 |
|
|
RETVAL |
997 |
|
|
|
998 |
|
|
iow * |
999 |
|
|
iow::fd (int fd) |
1000 |
|
|
CODE: |
1001 |
|
|
THIS->fd = fd; |
1002 |
|
|
RETVAL = THIS; |
1003 |
|
|
OUTPUT: |
1004 |
|
|
RETVAL |
1005 |
|
|
|
1006 |
|
|
iow * |
1007 |
|
|
iow::events (short events) |
1008 |
|
|
CODE: |
1009 |
|
|
THIS->events = events; |
1010 |
|
|
RETVAL = THIS; |
1011 |
|
|
OUTPUT: |
1012 |
|
|
RETVAL |
1013 |
|
|
|
1014 |
|
|
iow * |
1015 |
|
|
iow::start () |
1016 |
|
|
CODE: |
1017 |
|
|
THIS->start (); |
1018 |
|
|
RETVAL = THIS; |
1019 |
|
|
OUTPUT: |
1020 |
|
|
RETVAL |
1021 |
|
|
|
1022 |
|
|
iow * |
1023 |
|
|
iow::stop () |
1024 |
|
|
CODE: |
1025 |
|
|
THIS->stop (); |
1026 |
|
|
RETVAL = THIS; |
1027 |
|
|
OUTPUT: |
1028 |
|
|
RETVAL |
1029 |
|
|
|
1030 |
|
|
void |
1031 |
|
|
iow::DESTROY () |
1032 |
|
|
|
1033 |
|
|
|