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-2005 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2006 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. |
… | |
… | |
26 | #include <XSUB.h> |
26 | #include <XSUB.h> |
27 | #undef line_t |
27 | #undef line_t |
28 | |
28 | |
29 | #include "../config.h" |
29 | #include "../config.h" |
30 | |
30 | |
|
|
31 | #include <cstddef> |
31 | #include <cstdarg> |
32 | #include <cstdarg> |
32 | |
33 | |
|
|
34 | #include "iom.h" |
33 | #include "rxvt.h" |
35 | #include "rxvt.h" |
34 | #include "iom.h" |
36 | #include "keyboard.h" |
35 | #include "rxvtutil.h" |
37 | #include "rxvtutil.h" |
36 | #include "rxvtperl.h" |
38 | #include "rxvtperl.h" |
37 | |
39 | |
38 | #include "perlxsi.c" |
40 | #include "perlxsi.c" |
|
|
41 | |
|
|
42 | #if defined(HAVE_SCROLLBARS) || defined(MENUBAR) |
|
|
43 | # define GRAB_CURSOR THIS->leftptr_cursor |
|
|
44 | #else |
|
|
45 | # define GRAB_CURSOR None |
|
|
46 | #endif |
39 | |
47 | |
40 | #undef LINENO |
48 | #undef LINENO |
41 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
49 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
42 | #undef ROW |
50 | #undef ROW |
43 | #define ROW(n) THIS->row_buf [LINENO (n)] |
51 | #define ROW(n) THIS->row_buf [LINENO (n)] |
44 | |
52 | |
45 | ///////////////////////////////////////////////////////////////////////////// |
53 | ///////////////////////////////////////////////////////////////////////////// |
46 | |
54 | |
|
|
55 | static SV * |
|
|
56 | taint (SV *sv) |
|
|
57 | { |
|
|
58 | SvTAINT (sv); |
|
|
59 | return sv; |
|
|
60 | } |
|
|
61 | |
|
|
62 | static SV * |
|
|
63 | taint_if (SV *sv, SV *src) |
|
|
64 | { |
|
|
65 | if (SvTAINTED (src)) |
|
|
66 | SvTAINT (sv); |
|
|
67 | |
|
|
68 | return sv; |
|
|
69 | } |
|
|
70 | |
47 | static wchar_t * |
71 | static wchar_t * |
48 | sv2wcs (SV *sv) |
72 | sv2wcs (SV *sv) |
49 | { |
73 | { |
50 | STRLEN len; |
74 | STRLEN len; |
51 | char *str = SvPVutf8 (sv, len); |
75 | char *str = SvPVutf8 (sv, len); |
52 | return rxvt_utf8towcs (str, len); |
76 | return rxvt_utf8towcs (str, len); |
53 | } |
77 | } |
54 | |
78 | |
55 | static SV * |
79 | static SV * |
|
|
80 | wcs2sv (wchar_t *wstr, int len = -1) |
|
|
81 | { |
|
|
82 | char *str = rxvt_wcstoutf8 (wstr, len); |
|
|
83 | |
|
|
84 | SV *sv = newSVpv (str, 0); |
|
|
85 | SvUTF8_on (sv); |
|
|
86 | free (str); |
|
|
87 | |
|
|
88 | return sv; |
|
|
89 | } |
|
|
90 | |
|
|
91 | static SV * |
56 | new_ref (HV *hv, const char *klass) |
92 | new_ref (HV *hv, const char *klass) |
57 | { |
93 | { |
58 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
94 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
59 | } |
95 | } |
60 | |
96 | |
61 | //TODO: use magic |
97 | //TODO: use magic |
62 | static SV * |
98 | static SV * |
63 | newSVptr (void *ptr, const char *klass) |
99 | newSVptr (void *ptr, const char *klass) |
64 | { |
100 | { |
65 | HV *hv = newHV (); |
101 | HV *hv = newHV (); |
66 | hv_store (hv, "_ptr", 4, newSViv ((long)ptr), 0); |
102 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
67 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
103 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
104 | } |
|
|
105 | |
|
|
106 | static void |
|
|
107 | clearSVptr (SV *sv) |
|
|
108 | { |
|
|
109 | if (SvROK (sv)) |
|
|
110 | sv = SvRV (sv); |
|
|
111 | |
|
|
112 | hv_clear ((HV *)sv); |
|
|
113 | sv_unmagic (sv, PERL_MAGIC_ext); |
68 | } |
114 | } |
69 | |
115 | |
70 | static long |
116 | static long |
71 | SvPTR (SV *sv, const char *klass) |
117 | SvPTR (SV *sv, const char *klass) |
72 | { |
118 | { |
73 | if (!sv_derived_from (sv, klass)) |
119 | if (!sv_derived_from (sv, klass)) |
74 | croak ("object of type %s expected", klass); |
120 | croak ("object of type %s expected", klass); |
75 | |
121 | |
76 | IV iv = SvIV (*hv_fetch ((HV *)SvRV (sv), "_ptr", 4, 1)); |
122 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
77 | |
123 | |
78 | if (!iv) |
124 | if (!mg) |
79 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
125 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
80 | |
126 | |
81 | return (long)iv; |
127 | return (long)mg->mg_ptr; |
82 | } |
128 | } |
83 | |
129 | |
84 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
130 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
85 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
131 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
86 | |
132 | |
87 | ///////////////////////////////////////////////////////////////////////////// |
133 | ///////////////////////////////////////////////////////////////////////////// |
88 | |
134 | |
89 | struct perl_watcher |
135 | struct perl_watcher |
… | |
… | |
139 | #define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") |
185 | #define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") |
140 | #define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") |
186 | #define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") |
141 | |
187 | |
142 | struct timer : time_watcher, perl_watcher |
188 | struct timer : time_watcher, perl_watcher |
143 | { |
189 | { |
|
|
190 | tstamp interval; |
|
|
191 | |
144 | timer () |
192 | timer () |
145 | : time_watcher (this, &timer::execute) |
193 | : time_watcher (this, &timer::execute) |
146 | { |
194 | { |
147 | } |
195 | } |
148 | |
196 | |
149 | void execute (time_watcher &w) |
197 | void execute (time_watcher &w) |
150 | { |
198 | { |
|
|
199 | if (interval) |
|
|
200 | start (at + interval); |
|
|
201 | |
151 | invoke ("urxvt::timer", newSVtimer (this)); |
202 | invoke ("urxvt::timer", newSVtimer (this)); |
152 | } |
203 | } |
153 | }; |
204 | }; |
154 | |
205 | |
155 | #define newSViow(iow) new_ref (iow->self, "urxvt::iow") |
206 | #define newSViow(iow) new_ref (iow->self, "urxvt::iow") |
… | |
… | |
168 | } |
219 | } |
169 | }; |
220 | }; |
170 | |
221 | |
171 | ///////////////////////////////////////////////////////////////////////////// |
222 | ///////////////////////////////////////////////////////////////////////////// |
172 | |
223 | |
|
|
224 | #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") |
|
|
225 | |
|
|
226 | struct overlay { |
|
|
227 | HV *self; |
|
|
228 | rxvt_term *THIS; |
|
|
229 | int x, y, w, h; |
|
|
230 | int border; |
|
|
231 | text_t **text; |
|
|
232 | rend_t **rend; |
|
|
233 | |
|
|
234 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
|
|
235 | ~overlay (); |
|
|
236 | |
|
|
237 | void show (); |
|
|
238 | void hide (); |
|
|
239 | |
|
|
240 | void swap (); |
|
|
241 | |
|
|
242 | void set (int x, int y, SV *str, SV *rend); |
|
|
243 | }; |
|
|
244 | |
|
|
245 | overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) |
|
|
246 | : THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2) |
|
|
247 | { |
|
|
248 | if (border == 2) |
|
|
249 | { |
|
|
250 | w += 2; |
|
|
251 | h += 2; |
|
|
252 | } |
|
|
253 | |
|
|
254 | text = new text_t *[h]; |
|
|
255 | rend = new rend_t *[h]; |
|
|
256 | |
|
|
257 | for (int y = 0; y < h; y++) |
|
|
258 | { |
|
|
259 | text_t *tp = text[y] = new text_t[w]; |
|
|
260 | rend_t *rp = rend[y] = new rend_t[w]; |
|
|
261 | |
|
|
262 | text_t t0, t1, t2; |
|
|
263 | rend_t r = rstyle; |
|
|
264 | |
|
|
265 | if (border == 2) |
|
|
266 | { |
|
|
267 | if (y == 0) |
|
|
268 | t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
|
|
269 | else if (y < h - 1) |
|
|
270 | t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
|
|
271 | else |
|
|
272 | t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
|
|
273 | |
|
|
274 | *tp++ = t0; |
|
|
275 | *rp++ = r; |
|
|
276 | |
|
|
277 | for (int x = w - 2; x-- > 0; ) |
|
|
278 | { |
|
|
279 | *tp++ = t1; |
|
|
280 | *rp++ = r; |
|
|
281 | } |
|
|
282 | |
|
|
283 | *tp = t2; |
|
|
284 | *rp = r; |
|
|
285 | } |
|
|
286 | else |
|
|
287 | for (int x = w; x-- > 0; ) |
|
|
288 | { |
|
|
289 | *tp++ = 0x0020; |
|
|
290 | *rp++ = r; |
|
|
291 | } |
|
|
292 | } |
|
|
293 | |
|
|
294 | show (); |
|
|
295 | THIS->want_refresh = 1; |
|
|
296 | } |
|
|
297 | |
|
|
298 | overlay::~overlay () |
|
|
299 | { |
|
|
300 | hide (); |
|
|
301 | |
|
|
302 | for (int y = h; y--; ) |
|
|
303 | { |
|
|
304 | delete [] text[y]; |
|
|
305 | delete [] rend[y]; |
|
|
306 | } |
|
|
307 | |
|
|
308 | delete [] text; |
|
|
309 | delete [] rend; |
|
|
310 | |
|
|
311 | THIS->want_refresh = 1; |
|
|
312 | } |
|
|
313 | |
|
|
314 | void |
|
|
315 | overlay::show () |
|
|
316 | { |
|
|
317 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
318 | |
|
|
319 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
|
|
320 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
|
|
321 | } |
|
|
322 | |
|
|
323 | void |
|
|
324 | overlay::hide () |
|
|
325 | { |
|
|
326 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
|
|
327 | |
|
|
328 | if (ovs) |
|
|
329 | { |
|
|
330 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
331 | |
|
|
332 | HV *hv = (HV *)SvRV (*ovs); |
|
|
333 | hv_delete (hv, key, 32, G_DISCARD); |
|
|
334 | } |
|
|
335 | } |
|
|
336 | |
|
|
337 | void overlay::swap () |
|
|
338 | { |
|
|
339 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
|
|
340 | int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); |
|
|
341 | |
|
|
342 | int ov_w = min (w, THIS->ncol - ov_x); |
|
|
343 | int ov_h = min (h, THIS->nrow - ov_y); |
|
|
344 | |
|
|
345 | for (int y = ov_h; y--; ) |
|
|
346 | { |
|
|
347 | text_t *t1 = text [y]; |
|
|
348 | rend_t *r1 = rend [y]; |
|
|
349 | |
|
|
350 | text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
|
|
351 | rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
|
|
352 | |
|
|
353 | for (int x = ov_w; x--; ) |
|
|
354 | { |
|
|
355 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
|
|
356 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
|
|
357 | } |
|
|
358 | } |
|
|
359 | |
|
|
360 | } |
|
|
361 | |
|
|
362 | void overlay::set (int x, int y, SV *text, SV *rend) |
|
|
363 | { |
|
|
364 | x += border; |
|
|
365 | y += border; |
|
|
366 | |
|
|
367 | if (!IN_RANGE_EXC (y, 0, h - border)) |
|
|
368 | return; |
|
|
369 | |
|
|
370 | wchar_t *wtext = sv2wcs (text); |
|
|
371 | |
|
|
372 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
|
|
373 | this->text [y][x + col] = wtext [col]; |
|
|
374 | |
|
|
375 | free (wtext); |
|
|
376 | |
|
|
377 | if (rend) |
|
|
378 | { |
|
|
379 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
|
|
380 | croak ("rend must be arrayref"); |
|
|
381 | |
|
|
382 | AV *av = (AV *)SvRV (rend); |
|
|
383 | |
|
|
384 | for (int col = min (av_len (av) + 1, w - x - border); col--; ) |
|
|
385 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
|
|
386 | } |
|
|
387 | |
|
|
388 | THIS->want_refresh = 1; |
|
|
389 | } |
|
|
390 | |
|
|
391 | |
|
|
392 | ///////////////////////////////////////////////////////////////////////////// |
|
|
393 | |
173 | struct rxvt_perl_interp rxvt_perl; |
394 | struct rxvt_perl_interp rxvt_perl; |
174 | |
395 | |
175 | static PerlInterpreter *perl; |
396 | static PerlInterpreter *perl; |
176 | |
397 | |
177 | rxvt_perl_interp::rxvt_perl_interp () |
398 | rxvt_perl_interp::rxvt_perl_interp () |
… | |
… | |
190 | void |
411 | void |
191 | rxvt_perl_interp::init () |
412 | rxvt_perl_interp::init () |
192 | { |
413 | { |
193 | if (!perl) |
414 | if (!perl) |
194 | { |
415 | { |
|
|
416 | temp_environ temp_environ(rxvt_environ); |
|
|
417 | |
195 | char *argv[] = { |
418 | char *argv[] = { |
196 | "", |
419 | "", |
|
|
420 | "-T", |
197 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
421 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
198 | }; |
422 | }; |
199 | |
423 | |
200 | perl = perl_alloc (); |
424 | perl = perl_alloc (); |
201 | perl_construct (perl); |
425 | perl_construct (perl); |
202 | |
426 | |
203 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
427 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
204 | || perl_run (perl)) |
428 | || perl_run (perl)) |
205 | { |
429 | { |
206 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
430 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
207 | |
431 | |
208 | perl_destruct (perl); |
432 | perl_destruct (perl); |
… | |
… | |
210 | perl = 0; |
434 | perl = 0; |
211 | } |
435 | } |
212 | } |
436 | } |
213 | } |
437 | } |
214 | |
438 | |
|
|
439 | static void |
|
|
440 | ungrab (rxvt_term *THIS) |
|
|
441 | { |
|
|
442 | if (THIS->perl.grabtime) |
|
|
443 | { |
|
|
444 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
445 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
446 | THIS->perl.grabtime = 0; |
|
|
447 | } |
|
|
448 | } |
|
|
449 | |
215 | bool |
450 | bool |
216 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
451 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
217 | { |
452 | { |
218 | if (!perl |
453 | if (!perl) |
219 | || (!should_invoke [htype] && htype != HOOK_INIT && htype != HOOK_DESTROY)) |
|
|
220 | return false; |
454 | return false; |
221 | |
455 | |
222 | if (htype == HOOK_INIT) // first hook ever called |
456 | if (htype == HOOK_INIT) // first hook ever called |
|
|
457 | { |
223 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
458 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
|
|
459 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
|
|
460 | } |
|
|
461 | else if (!term->perl.self) |
|
|
462 | return false; // perl not initialized for this instance |
|
|
463 | else if (htype == HOOK_DESTROY) |
|
|
464 | { |
|
|
465 | // handled later |
|
|
466 | } |
|
|
467 | else |
|
|
468 | { |
|
|
469 | if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
|
|
470 | { |
|
|
471 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
472 | |
|
|
473 | if (HvKEYS (hv)) |
|
|
474 | { |
|
|
475 | hv_iterinit (hv); |
|
|
476 | |
|
|
477 | while (HE *he = hv_iternext (hv)) |
|
|
478 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
479 | } |
|
|
480 | |
|
|
481 | } |
|
|
482 | |
|
|
483 | if (!should_invoke [htype]) |
|
|
484 | return false; |
|
|
485 | } |
|
|
486 | |
|
|
487 | temp_environ temp_environ(rxvt_environ); |
224 | |
488 | |
225 | dSP; |
489 | dSP; |
226 | va_list ap; |
490 | va_list ap; |
227 | |
491 | |
228 | va_start (ap, htype); |
492 | va_start (ap, htype); |
… | |
… | |
246 | |
510 | |
247 | case DT_LONG: |
511 | case DT_LONG: |
248 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
512 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
249 | break; |
513 | break; |
250 | |
514 | |
251 | case DT_STRING: |
515 | case DT_STR: |
252 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
516 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
|
|
517 | break; |
|
|
518 | |
|
|
519 | case DT_STR_LEN: |
|
|
520 | { |
|
|
521 | char *str = va_arg (ap, char *); |
|
|
522 | int len = va_arg (ap, int); |
|
|
523 | |
|
|
524 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
|
|
525 | } |
|
|
526 | break; |
|
|
527 | |
|
|
528 | case DT_WCS_LEN: |
|
|
529 | { |
|
|
530 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
531 | int wlen = va_arg (ap, int); |
|
|
532 | |
|
|
533 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
|
|
534 | } |
|
|
535 | break; |
|
|
536 | |
|
|
537 | case DT_XEVENT: |
|
|
538 | { |
|
|
539 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
540 | HV *hv = newHV (); |
|
|
541 | |
|
|
542 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
543 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
544 | # undef set |
|
|
545 | |
|
|
546 | setiv (type, xe->type); |
|
|
547 | setiv (send_event, xe->xany.send_event); |
|
|
548 | setiv (serial, xe->xany.serial); |
|
|
549 | |
|
|
550 | switch (xe->type) |
|
|
551 | { |
|
|
552 | case KeyPress: |
|
|
553 | case KeyRelease: |
|
|
554 | case ButtonPress: |
|
|
555 | case ButtonRelease: |
|
|
556 | case MotionNotify: |
|
|
557 | setiv (time, xe->xmotion.time); |
|
|
558 | setiv (x, xe->xmotion.x); |
|
|
559 | setiv (y, xe->xmotion.y); |
|
|
560 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
561 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
562 | setiv (x_root, xe->xmotion.x_root); |
|
|
563 | setiv (y_root, xe->xmotion.y_root); |
|
|
564 | setiv (state, xe->xmotion.state); |
|
|
565 | break; |
|
|
566 | } |
|
|
567 | |
|
|
568 | switch (xe->type) |
|
|
569 | { |
|
|
570 | case KeyPress: |
|
|
571 | case KeyRelease: |
|
|
572 | setiv (keycode, xe->xkey.keycode); |
|
|
573 | break; |
|
|
574 | |
|
|
575 | case ButtonPress: |
|
|
576 | case ButtonRelease: |
|
|
577 | setiv (button, xe->xbutton.button); |
|
|
578 | break; |
|
|
579 | |
|
|
580 | case MotionNotify: |
|
|
581 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
582 | break; |
|
|
583 | } |
|
|
584 | |
|
|
585 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
586 | } |
253 | break; |
587 | break; |
254 | |
588 | |
255 | case DT_END: |
589 | case DT_END: |
256 | { |
590 | { |
257 | va_end (ap); |
591 | va_end (ap); |
… | |
… | |
269 | PUTBACK; |
603 | PUTBACK; |
270 | FREETMPS; |
604 | FREETMPS; |
271 | LEAVE; |
605 | LEAVE; |
272 | |
606 | |
273 | if (SvTRUE (ERRSV)) |
607 | if (SvTRUE (ERRSV)) |
|
|
608 | { |
274 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
609 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
610 | ungrab (term); // better lose the grab than the session |
|
|
611 | } |
275 | |
612 | |
276 | if (htype == HOOK_DESTROY) |
613 | if (htype == HOOK_DESTROY) |
277 | { |
614 | { |
278 | // TODO: clear magic |
|
|
279 | hv_clear ((HV *)SvRV ((SV *)term->self)); |
615 | clearSVptr ((SV *)term->perl.self); |
280 | SvREFCNT_dec ((SV *)term->self); |
616 | SvREFCNT_dec ((SV *)term->perl.self); |
281 | } |
617 | } |
282 | |
618 | |
283 | return count; |
619 | return count; |
284 | } |
620 | } |
285 | |
621 | |
… | |
… | |
295 | |
631 | |
296 | PROTOTYPES: ENABLE |
632 | PROTOTYPES: ENABLE |
297 | |
633 | |
298 | BOOT: |
634 | BOOT: |
299 | { |
635 | { |
300 | # define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0)) |
636 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
301 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), #name, newSViv (name)); |
637 | sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1)); |
|
|
638 | sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1)); |
|
|
639 | sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1)); |
|
|
640 | |
302 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
641 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
303 | set_hookname (INIT); |
642 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
304 | set_hookname (RESET); |
643 | # include "hookinc.h" |
305 | set_hookname (START); |
644 | # undef def |
306 | set_hookname (DESTROY); |
|
|
307 | set_hookname (SEL_BEGIN); |
|
|
308 | set_hookname (SEL_EXTEND); |
|
|
309 | set_hookname (SEL_MAKE); |
|
|
310 | set_hookname (SEL_GRAB); |
|
|
311 | set_hookname (FOCUS_IN); |
|
|
312 | set_hookname (FOCUS_OUT); |
|
|
313 | set_hookname (VIEW_CHANGE); |
|
|
314 | set_hookname (SCROLL_BACK); |
|
|
315 | set_hookname (TTY_ACTIVITY); |
|
|
316 | set_hookname (REFRESH_BEGIN); |
|
|
317 | set_hookname (REFRESH_END); |
|
|
318 | set_hookname (KEYBOARD_COMMAND); |
|
|
319 | |
645 | |
|
|
646 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
647 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
648 | # define nodef(name) |
|
|
649 | # include "optinc.h" |
|
|
650 | # undef nodef |
|
|
651 | # undef def |
|
|
652 | |
|
|
653 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
654 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
320 | export_const (DEFAULT_RSTYLE); |
655 | export_const_iv (DEFAULT_RSTYLE); |
321 | export_const (OVERLAY_RSTYLE); |
656 | export_const_iv (OVERLAY_RSTYLE); |
322 | export_const (RS_Bold); |
657 | export_const_iv (RS_Bold); |
323 | export_const (RS_Italic); |
658 | export_const_iv (RS_Italic); |
324 | export_const (RS_Blink); |
659 | export_const_iv (RS_Blink); |
325 | export_const (RS_RVid); |
660 | export_const_iv (RS_RVid); |
326 | export_const (RS_Uline); |
661 | export_const_iv (RS_Uline); |
327 | |
662 | |
328 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
663 | export_const_iv (CurrentTime); |
|
|
664 | export_const_iv (ShiftMask); |
|
|
665 | export_const_iv (LockMask); |
|
|
666 | export_const_iv (ControlMask); |
|
|
667 | export_const_iv (Mod1Mask); |
|
|
668 | export_const_iv (Mod2Mask); |
|
|
669 | export_const_iv (Mod3Mask); |
|
|
670 | export_const_iv (Mod4Mask); |
|
|
671 | export_const_iv (Mod5Mask); |
|
|
672 | export_const_iv (Button1Mask); |
|
|
673 | export_const_iv (Button2Mask); |
|
|
674 | export_const_iv (Button3Mask); |
|
|
675 | export_const_iv (Button4Mask); |
|
|
676 | export_const_iv (Button5Mask); |
|
|
677 | export_const_iv (AnyModifier); |
|
|
678 | |
|
|
679 | export_const_iv (EVENT_NONE); |
|
|
680 | export_const_iv (EVENT_READ); |
|
|
681 | export_const_iv (EVENT_WRITE); |
329 | } |
682 | } |
330 | |
683 | |
331 | void |
684 | void |
332 | set_should_invoke (int htype, int value) |
685 | set_should_invoke (int htype, int value) |
333 | CODE: |
686 | CODE: |
… | |
… | |
340 | |
693 | |
341 | void |
694 | void |
342 | fatal (const char *msg) |
695 | fatal (const char *msg) |
343 | CODE: |
696 | CODE: |
344 | rxvt_fatal ("%s", msg); |
697 | rxvt_fatal ("%s", msg); |
|
|
698 | |
|
|
699 | SV * |
|
|
700 | untaint (SV *sv) |
|
|
701 | CODE: |
|
|
702 | RETVAL = newSVsv (sv); |
|
|
703 | SvTAINTED_off (RETVAL); |
|
|
704 | OUTPUT: |
|
|
705 | RETVAL |
|
|
706 | |
|
|
707 | bool |
|
|
708 | safe () |
|
|
709 | CODE: |
|
|
710 | RETVAL = !rxvt_tainted (); |
|
|
711 | OUTPUT: |
|
|
712 | RETVAL |
345 | |
713 | |
346 | NV |
714 | NV |
347 | NOW () |
715 | NOW () |
348 | CODE: |
716 | CODE: |
349 | RETVAL = NOW; |
717 | RETVAL = NOW; |
… | |
… | |
397 | } |
765 | } |
398 | OUTPUT: |
766 | OUTPUT: |
399 | RETVAL |
767 | RETVAL |
400 | |
768 | |
401 | MODULE = urxvt PACKAGE = urxvt::term |
769 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
770 | |
|
|
771 | SV * |
|
|
772 | _new (...) |
|
|
773 | CODE: |
|
|
774 | { |
|
|
775 | if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) |
|
|
776 | croak ("first argument to urxvt::term->_new must be arrayref"); |
|
|
777 | |
|
|
778 | rxvt_term *term = new rxvt_term; |
|
|
779 | |
|
|
780 | term->argv = new stringvec; |
|
|
781 | term->envv = new stringvec; |
|
|
782 | |
|
|
783 | for (int i = 1; i < items; i++) |
|
|
784 | term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
785 | |
|
|
786 | AV *envv = (AV *)SvRV (ST (0)); |
|
|
787 | for (int i = av_len (envv) + 1; i--; ) |
|
|
788 | term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); |
|
|
789 | |
|
|
790 | term->envv->push_back (0); |
|
|
791 | |
|
|
792 | bool success; |
|
|
793 | |
|
|
794 | try |
|
|
795 | { |
|
|
796 | success = term->init (term->argv->size (), term->argv->begin ()); |
|
|
797 | } |
|
|
798 | catch (const class rxvt_failure_exception &e) |
|
|
799 | { |
|
|
800 | success = false; |
|
|
801 | } |
|
|
802 | |
|
|
803 | if (!success) |
|
|
804 | { |
|
|
805 | term->destroy (); |
|
|
806 | croak ("error while initializing new terminal instance"); |
|
|
807 | } |
|
|
808 | |
|
|
809 | RETVAL = term && term->perl.self |
|
|
810 | ? newSVterm (term) : &PL_sv_undef; |
|
|
811 | } |
|
|
812 | OUTPUT: |
|
|
813 | RETVAL |
|
|
814 | |
|
|
815 | void |
|
|
816 | rxvt_term::destroy () |
|
|
817 | |
|
|
818 | void |
|
|
819 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
820 | CODE: |
|
|
821 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
822 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
823 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
|
|
824 | |
|
|
825 | bool |
|
|
826 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
827 | CODE: |
|
|
828 | { |
|
|
829 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
830 | |
|
|
831 | THIS->perl.grabtime = 0; |
|
|
832 | |
|
|
833 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
834 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
835 | mode, mode, None, GRAB_CURSOR, eventtime)) |
|
|
836 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
837 | THIS->perl.grabtime = eventtime; |
|
|
838 | else |
|
|
839 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
840 | |
|
|
841 | RETVAL = !!THIS->perl.grabtime; |
|
|
842 | } |
|
|
843 | OUTPUT: |
|
|
844 | RETVAL |
|
|
845 | |
|
|
846 | void |
|
|
847 | rxvt_term::allow_events_async () |
|
|
848 | CODE: |
|
|
849 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
|
|
850 | |
|
|
851 | void |
|
|
852 | rxvt_term::allow_events_sync () |
|
|
853 | CODE: |
|
|
854 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
|
|
855 | |
|
|
856 | void |
|
|
857 | rxvt_term::allow_events_replay () |
|
|
858 | CODE: |
|
|
859 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
|
|
860 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
|
|
861 | |
|
|
862 | void |
|
|
863 | rxvt_term::ungrab () |
|
|
864 | CODE: |
|
|
865 | ungrab (THIS); |
402 | |
866 | |
403 | int |
867 | int |
404 | rxvt_term::strwidth (SV *str) |
868 | rxvt_term::strwidth (SV *str) |
405 | CODE: |
869 | CODE: |
406 | { |
870 | { |
… | |
… | |
425 | char *mbstr = rxvt_wcstombs (wstr); |
889 | char *mbstr = rxvt_wcstombs (wstr); |
426 | rxvt_pop_locale (); |
890 | rxvt_pop_locale (); |
427 | |
891 | |
428 | free (wstr); |
892 | free (wstr); |
429 | |
893 | |
430 | RETVAL = newSVpv (mbstr, 0); |
894 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
431 | free (mbstr); |
895 | free (mbstr); |
432 | } |
896 | } |
433 | OUTPUT: |
897 | OUTPUT: |
434 | RETVAL |
898 | RETVAL |
435 | |
899 | |
… | |
… | |
442 | |
906 | |
443 | rxvt_push_locale (THIS->locale); |
907 | rxvt_push_locale (THIS->locale); |
444 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
908 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
445 | rxvt_pop_locale (); |
909 | rxvt_pop_locale (); |
446 | |
910 | |
447 | char *str = rxvt_wcstoutf8 (wstr); |
911 | RETVAL = taint_if (wcs2sv (wstr), octets); |
448 | free (wstr); |
912 | free (wstr); |
449 | |
|
|
450 | RETVAL = newSVpv (str, 0); |
|
|
451 | SvUTF8_on (RETVAL); |
|
|
452 | free (str); |
|
|
453 | } |
913 | } |
454 | OUTPUT: |
914 | OUTPUT: |
455 | RETVAL |
915 | RETVAL |
|
|
916 | |
|
|
917 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
|
|
918 | |
|
|
919 | #define TERM_OFFSET_width TERM_OFFSET(width) |
|
|
920 | #define TERM_OFFSET_height TERM_OFFSET(height) |
|
|
921 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
|
|
922 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
|
|
923 | #define TERM_OFFSET_fbase TERM_OFFSET(fbase) |
|
|
924 | #define TERM_OFFSET_nrow TERM_OFFSET(nrow) |
|
|
925 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
|
|
926 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
|
|
927 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
|
|
928 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
|
|
929 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
|
|
930 | #define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) |
456 | |
931 | |
457 | int |
932 | int |
|
|
933 | rxvt_term::width () |
|
|
934 | ALIAS: |
|
|
935 | width = TERM_OFFSET_width |
|
|
936 | height = TERM_OFFSET_height |
|
|
937 | fwidth = TERM_OFFSET_fwidth |
|
|
938 | fheight = TERM_OFFSET_fheight |
|
|
939 | fbase = TERM_OFFSET_fbase |
|
|
940 | nrow = TERM_OFFSET_nrow |
|
|
941 | ncol = TERM_OFFSET_ncol |
|
|
942 | focus = TERM_OFFSET_focus |
|
|
943 | mapped = TERM_OFFSET_mapped |
|
|
944 | saveLines = TERM_OFFSET_saveLines |
|
|
945 | total_rows = TERM_OFFSET_total_rows |
|
|
946 | nsaved = TERM_OFFSET_nsaved |
|
|
947 | CODE: |
|
|
948 | RETVAL = *(int *)((char *)THIS + ix); |
|
|
949 | OUTPUT: |
|
|
950 | RETVAL |
|
|
951 | |
|
|
952 | unsigned int |
|
|
953 | rxvt_term::ModLevel3Mask () |
|
|
954 | ALIAS: |
|
|
955 | ModLevel3Mask = 0 |
|
|
956 | ModMetaMask = 1 |
|
|
957 | ModNumLockMask = 2 |
|
|
958 | CODE: |
|
|
959 | switch (ix) |
|
|
960 | { |
|
|
961 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
962 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
963 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
964 | } |
|
|
965 | OUTPUT: |
|
|
966 | RETVAL |
|
|
967 | |
|
|
968 | char * |
|
|
969 | rxvt_term::display_id () |
|
|
970 | ALIAS: |
|
|
971 | display_id = 0 |
|
|
972 | locale = 1 |
|
|
973 | CODE: |
|
|
974 | switch (ix) |
|
|
975 | { |
|
|
976 | case 0: RETVAL = THIS->display->id; break; |
|
|
977 | case 1: RETVAL = THIS->locale; break; |
|
|
978 | } |
|
|
979 | OUTPUT: |
|
|
980 | RETVAL |
|
|
981 | |
|
|
982 | SV * |
458 | rxvt_term::nsaved () |
983 | rxvt_term::_env () |
459 | CODE: |
984 | CODE: |
|
|
985 | { |
|
|
986 | if (THIS->envv) |
|
|
987 | { |
|
|
988 | AV *av = newAV (); |
|
|
989 | |
|
|
990 | for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) |
|
|
991 | if (*i) |
|
|
992 | av_push (av, newSVpv (*i, 0)); |
|
|
993 | |
|
|
994 | RETVAL = newRV_noinc ((SV *)av); |
|
|
995 | } |
|
|
996 | else |
|
|
997 | RETVAL = &PL_sv_undef; |
|
|
998 | } |
|
|
999 | OUTPUT: |
|
|
1000 | RETVAL |
|
|
1001 | |
|
|
1002 | int |
|
|
1003 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
|
|
1004 | CODE: |
|
|
1005 | RETVAL = THIS->pty_ev.events; |
|
|
1006 | if (events != EVENT_UNDEF) |
|
|
1007 | THIS->pty_ev.set (events); |
|
|
1008 | OUTPUT: |
|
|
1009 | RETVAL |
|
|
1010 | |
|
|
1011 | U32 |
|
|
1012 | rxvt_term::parent () |
|
|
1013 | CODE: |
|
|
1014 | RETVAL = (U32)THIS->parent [0]; |
|
|
1015 | OUTPUT: |
|
|
1016 | RETVAL |
|
|
1017 | |
|
|
1018 | U32 |
|
|
1019 | rxvt_term::vt () |
|
|
1020 | CODE: |
|
|
1021 | RETVAL = (U32)THIS->vt; |
|
|
1022 | OUTPUT: |
|
|
1023 | RETVAL |
|
|
1024 | |
|
|
1025 | U32 |
|
|
1026 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
|
|
1027 | CODE: |
|
|
1028 | { |
460 | RETVAL = THIS->nsaved; |
1029 | RETVAL = THIS->rstyle; |
|
|
1030 | THIS->rstyle = new_rstyle; |
|
|
1031 | } |
461 | OUTPUT: |
1032 | OUTPUT: |
462 | RETVAL |
1033 | RETVAL |
463 | |
1034 | |
464 | int |
1035 | int |
465 | rxvt_term::view_start (int newval = -1) |
1036 | rxvt_term::view_start (int newval = -1) |
466 | CODE: |
1037 | CODE: |
467 | { |
1038 | { |
… | |
… | |
474 | } |
1045 | } |
475 | } |
1046 | } |
476 | OUTPUT: |
1047 | OUTPUT: |
477 | RETVAL |
1048 | RETVAL |
478 | |
1049 | |
479 | int |
|
|
480 | rxvt_term::nrow () |
|
|
481 | CODE: |
|
|
482 | RETVAL = THIS->nrow; |
|
|
483 | OUTPUT: |
|
|
484 | RETVAL |
|
|
485 | |
|
|
486 | int |
|
|
487 | rxvt_term::ncol () |
|
|
488 | CODE: |
|
|
489 | RETVAL = THIS->ncol; |
|
|
490 | OUTPUT: |
|
|
491 | RETVAL |
|
|
492 | |
|
|
493 | void |
1050 | void |
494 | rxvt_term::want_refresh () |
1051 | rxvt_term::want_refresh () |
495 | CODE: |
1052 | CODE: |
496 | THIS->want_refresh = 1; |
1053 | THIS->want_refresh = 1; |
497 | |
1054 | |
498 | void |
1055 | void |
499 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
1056 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
500 | PPCODE: |
1057 | PPCODE: |
501 | { |
1058 | { |
502 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1059 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
503 | croak ("row_number number of out range"); |
1060 | XSRETURN_EMPTY; |
504 | |
1061 | |
505 | line_t &l = ROW(row_number); |
1062 | line_t &l = ROW(row_number); |
506 | |
1063 | |
507 | if (GIMME_V != G_VOID) |
1064 | if (GIMME_V != G_VOID) |
508 | { |
1065 | { |
509 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1066 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
510 | |
1067 | |
511 | for (int col = 0; col <THIS->ncol; col++) |
1068 | for (int col = 0; col < THIS->ncol; col++) |
512 | wstr [col] = l.t [col]; |
1069 | wstr [col] = l.t [col]; |
513 | |
1070 | |
514 | char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); |
1071 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
515 | free (wstr); |
|
|
516 | |
1072 | |
517 | SV *sv = newSVpv (str, 0); |
1073 | delete [] wstr; |
518 | SvUTF8_on (sv); |
|
|
519 | XPUSHs (sv_2mortal (sv)); |
|
|
520 | free (str); |
|
|
521 | } |
1074 | } |
522 | |
1075 | |
523 | if (new_text) |
1076 | if (new_text) |
524 | { |
1077 | { |
525 | STRLEN slen; |
|
|
526 | char *str = SvPVutf8 (new_text, slen); |
1078 | wchar_t *wstr = sv2wcs (new_text); |
527 | wchar_t *wstr = rxvt_utf8towcs (str, slen); |
|
|
528 | |
1079 | |
529 | int len = wcslen (wstr); |
1080 | int len = min (wcslen (wstr) - start_ofs, max_len); |
530 | |
1081 | |
531 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
1082 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
532 | { |
1083 | { |
533 | free (wstr); |
1084 | free (wstr); |
534 | croak ("new_text extends beyond horizontal margins"); |
1085 | croak ("new_text extends beyond horizontal margins"); |
535 | } |
1086 | } |
536 | |
1087 | |
537 | for (int col = start_col; col < start_col + len; col++) |
1088 | for (int col = start_col; col < start_col + len; col++) |
538 | { |
1089 | { |
539 | l.t [col] = wstr [col - start_col]; |
1090 | l.t [col] = wstr [start_ofs + col - start_col]; |
540 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
1091 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
541 | } |
1092 | } |
542 | |
1093 | |
543 | free (wstr); |
1094 | free (wstr); |
544 | } |
1095 | } |
545 | } |
1096 | } |
546 | |
1097 | |
547 | void |
1098 | void |
548 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
1099 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
549 | PPCODE: |
1100 | PPCODE: |
550 | { |
1101 | { |
551 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1102 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
552 | croak ("row_number number of out range"); |
1103 | XSRETURN_EMPTY; |
553 | |
1104 | |
554 | line_t &l = ROW(row_number); |
1105 | line_t &l = ROW(row_number); |
555 | |
1106 | |
556 | if (GIMME_V != G_VOID) |
1107 | if (GIMME_V != G_VOID) |
557 | { |
1108 | { |
… | |
… | |
568 | { |
1119 | { |
569 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
1120 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
570 | croak ("new_rend must be arrayref"); |
1121 | croak ("new_rend must be arrayref"); |
571 | |
1122 | |
572 | AV *av = (AV *)SvRV (new_rend); |
1123 | AV *av = (AV *)SvRV (new_rend); |
573 | int len = av_len (av) + 1; |
1124 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
574 | |
1125 | |
575 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
1126 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
576 | croak ("new_rend array extends beyond horizontal margins"); |
1127 | croak ("new_rend array extends beyond horizontal margins"); |
577 | |
1128 | |
578 | for (int col = start_col; col < start_col + len; col++) |
1129 | for (int col = start_col; col < start_col + len; col++) |
579 | { |
1130 | { |
580 | rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
1131 | rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
581 | |
1132 | |
582 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
1133 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
583 | } |
1134 | } |
584 | } |
1135 | } |
585 | } |
1136 | } |
586 | |
1137 | |
587 | int |
1138 | int |
588 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
1139 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
589 | CODE: |
1140 | CODE: |
590 | { |
1141 | { |
591 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1142 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
592 | croak ("row_number number of out range"); |
1143 | XSRETURN_EMPTY; |
593 | |
1144 | |
594 | line_t &l = ROW(row_number); |
1145 | line_t &l = ROW(row_number); |
595 | RETVAL = l.l; |
1146 | RETVAL = l.l; |
596 | |
1147 | |
597 | if (new_length >= -1) |
1148 | if (new_length >= 0) |
598 | l.l = new_length; |
1149 | l.l = new_length; |
599 | } |
1150 | } |
600 | OUTPUT: |
1151 | OUTPUT: |
601 | RETVAL |
1152 | RETVAL |
602 | |
1153 | |
|
|
1154 | bool |
|
|
1155 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
|
|
1156 | CODE: |
|
|
1157 | { |
|
|
1158 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
|
|
1159 | XSRETURN_EMPTY; |
|
|
1160 | |
|
|
1161 | line_t &l = ROW(row_number); |
|
|
1162 | RETVAL = l.is_longer (); |
|
|
1163 | |
|
|
1164 | if (new_is_longer >= 0) |
|
|
1165 | l.is_longer (new_is_longer); |
|
|
1166 | } |
|
|
1167 | OUTPUT: |
|
|
1168 | RETVAL |
|
|
1169 | |
603 | SV * |
1170 | SV * |
604 | rxvt_term::special_encode (SV *str) |
1171 | rxvt_term::special_encode (SV *string) |
605 | CODE: |
1172 | CODE: |
606 | abort ();//TODO |
1173 | { |
|
|
1174 | wchar_t *wstr = sv2wcs (string); |
|
|
1175 | int wlen = wcslen (wstr); |
|
|
1176 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1177 | |
|
|
1178 | rxvt_push_locale (THIS->locale); |
|
|
1179 | |
|
|
1180 | wchar_t *r = rstr; |
|
|
1181 | for (wchar_t *s = wstr; *s; s++) |
|
|
1182 | if (wcwidth (*s) == 0) |
|
|
1183 | { |
|
|
1184 | if (r == rstr) |
|
|
1185 | croak ("leading combining character unencodable"); |
|
|
1186 | |
|
|
1187 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1188 | if (n == NOCHAR) |
|
|
1189 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1190 | |
|
|
1191 | r[-1] = n; |
|
|
1192 | } |
|
|
1193 | #if !UNICODE_3 |
|
|
1194 | else if (*s >= 0x10000) |
|
|
1195 | *r++ = rxvt_composite.compose (*s); |
|
|
1196 | #endif |
|
|
1197 | else |
|
|
1198 | *r++ = *s; |
|
|
1199 | |
|
|
1200 | rxvt_pop_locale (); |
|
|
1201 | |
|
|
1202 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
|
|
1203 | |
|
|
1204 | delete [] rstr; |
|
|
1205 | } |
|
|
1206 | OUTPUT: |
|
|
1207 | RETVAL |
607 | |
1208 | |
608 | SV * |
1209 | SV * |
609 | rxvt_term::special_decode (SV *str) |
1210 | rxvt_term::special_decode (SV *text) |
610 | CODE: |
1211 | CODE: |
611 | abort ();//TODO |
1212 | { |
|
|
1213 | wchar_t *wstr = sv2wcs (text); |
|
|
1214 | int wlen = wcslen (wstr); |
|
|
1215 | int dlen = 0; |
|
|
1216 | |
|
|
1217 | // find length |
|
|
1218 | for (wchar_t *s = wstr; *s; s++) |
|
|
1219 | if (*s == NOCHAR) |
|
|
1220 | ; |
|
|
1221 | else if (IS_COMPOSE (*s)) |
|
|
1222 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1223 | else |
|
|
1224 | dlen++; |
|
|
1225 | |
|
|
1226 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1227 | |
|
|
1228 | // decode |
|
|
1229 | wchar_t *r = rstr; |
|
|
1230 | for (wchar_t *s = wstr; *s; s++) |
|
|
1231 | if (*s == NOCHAR) |
|
|
1232 | ; |
|
|
1233 | else if (IS_COMPOSE (*s)) |
|
|
1234 | r += rxvt_composite.expand (*s, r); |
|
|
1235 | else |
|
|
1236 | *r++ = *s; |
|
|
1237 | |
|
|
1238 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
|
|
1239 | |
|
|
1240 | delete [] rstr; |
|
|
1241 | } |
|
|
1242 | OUTPUT: |
|
|
1243 | RETVAL |
612 | |
1244 | |
613 | void |
1245 | void |
614 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1246 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
615 | PPCODE: |
1247 | PPCODE: |
616 | { |
1248 | { |
617 | struct resval { const char *name; int value; } rslist [] = { |
1249 | struct resval { const char *name; int value; } rslist [] = { |
618 | # define Rs_def(name) { # name, Rs_ ## name }, |
1250 | # define def(name) { # name, Rs_ ## name }, |
619 | # define Rs_reserve(name,count) |
1251 | # define reserve(name,count) |
620 | # include "rsinc.h" |
1252 | # include "rsinc.h" |
621 | # undef Rs_def |
1253 | # undef def |
622 | # undef Rs_reserve |
1254 | # undef reserve |
623 | }; |
1255 | }; |
624 | |
1256 | |
625 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1257 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
626 | |
1258 | |
627 | do { |
1259 | do { |
… | |
… | |
633 | |
1265 | |
634 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1266 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
635 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1267 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
636 | |
1268 | |
637 | if (GIMME_V != G_VOID) |
1269 | if (GIMME_V != G_VOID) |
638 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1270 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
639 | |
1271 | |
640 | if (newval) |
1272 | if (newval) |
641 | { |
1273 | { |
642 | if (SvOK (newval)) |
1274 | if (SvOK (newval)) |
643 | { |
1275 | { |
… | |
… | |
648 | else |
1280 | else |
649 | THIS->rs [index] = 0; |
1281 | THIS->rs [index] = 0; |
650 | } |
1282 | } |
651 | } |
1283 | } |
652 | |
1284 | |
|
|
1285 | const char * |
|
|
1286 | rxvt_term::x_resource (const char *name) |
|
|
1287 | CLEANUP: |
|
|
1288 | SvTAINTED_on (ST (0)); |
|
|
1289 | |
|
|
1290 | bool |
|
|
1291 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1292 | CODE: |
|
|
1293 | { |
|
|
1294 | RETVAL = THIS->options & optval; |
|
|
1295 | |
|
|
1296 | if (set >= 0) |
|
|
1297 | { |
|
|
1298 | if (set) |
|
|
1299 | THIS->options |= optval; |
|
|
1300 | else |
|
|
1301 | THIS->options &= ~optval; |
|
|
1302 | |
|
|
1303 | switch (optval) |
|
|
1304 | { |
|
|
1305 | case Opt_skipBuiltinGlyphs: |
|
|
1306 | THIS->set_fonts (); |
|
|
1307 | THIS->scr_remap_chars (); |
|
|
1308 | THIS->scr_touch (true); |
|
|
1309 | THIS->want_refresh = 1; |
|
|
1310 | break; |
|
|
1311 | |
|
|
1312 | case Opt_cursorUnderline: |
|
|
1313 | THIS->want_refresh = 1; |
|
|
1314 | break; |
|
|
1315 | |
|
|
1316 | # case Opt_scrollBar_floating: |
|
|
1317 | # case Opt_scrollBar_right: |
|
|
1318 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1319 | # break; |
|
|
1320 | } |
|
|
1321 | } |
|
|
1322 | } |
|
|
1323 | OUTPUT: |
|
|
1324 | RETVAL |
|
|
1325 | |
|
|
1326 | bool |
|
|
1327 | rxvt_term::parse_keysym (char *keysym, char *str) |
|
|
1328 | CODE: |
|
|
1329 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
|
|
1330 | THIS->keyboard->register_done (); |
|
|
1331 | OUTPUT: |
|
|
1332 | RETVAL |
|
|
1333 | |
653 | void |
1334 | void |
654 | rxvt_term::selection_mark (...) |
1335 | rxvt_term::screen_cur (...) |
655 | PROTOTYPE: $;$$ |
1336 | PROTOTYPE: $;$$ |
656 | ALIAS: |
1337 | ALIAS: |
|
|
1338 | screen_cur = 0 |
657 | selection_beg = 1 |
1339 | selection_beg = 1 |
658 | selection_end = 2 |
1340 | selection_end = 2 |
|
|
1341 | selection_mark = 3 |
659 | PPCODE: |
1342 | PPCODE: |
660 | { |
1343 | { |
661 | row_col_t &sel = ix == 1 ? THIS->selection.beg |
1344 | row_col_t &rc = ix == 0 ? THIS->screen.cur |
|
|
1345 | : ix == 1 ? THIS->selection.beg |
662 | : ix == 2 ? THIS->selection.end |
1346 | : ix == 2 ? THIS->selection.end |
663 | : THIS->selection.mark; |
1347 | : THIS->selection.mark; |
664 | |
1348 | |
665 | if (GIMME_V != G_VOID) |
1349 | if (GIMME_V != G_VOID) |
666 | { |
1350 | { |
667 | EXTEND (SP, 2); |
1351 | EXTEND (SP, 2); |
668 | PUSHs (sv_2mortal (newSViv (sel.row))); |
1352 | PUSHs (sv_2mortal (newSViv (rc.row))); |
669 | PUSHs (sv_2mortal (newSViv (sel.col))); |
1353 | PUSHs (sv_2mortal (newSViv (rc.col))); |
670 | } |
1354 | } |
671 | |
1355 | |
672 | if (items == 3) |
1356 | if (items == 3) |
673 | { |
1357 | { |
674 | sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
1358 | rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
675 | sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
1359 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
676 | |
1360 | |
677 | if (ix) |
1361 | if (ix) |
678 | THIS->want_refresh = 1; |
1362 | THIS->want_refresh = 1; |
679 | } |
1363 | } |
680 | } |
1364 | } |
681 | |
1365 | |
|
|
1366 | char |
|
|
1367 | rxvt_term::cur_charset () |
|
|
1368 | CODE: |
|
|
1369 | RETVAL = THIS->charsets [THIS->screen.charset]; |
|
|
1370 | OUTPUT: |
|
|
1371 | RETVAL |
|
|
1372 | |
682 | int |
1373 | int |
683 | rxvt_term::selection_grab (int eventtime) |
1374 | rxvt_term::selection_grab (U32 eventtime) |
684 | |
1375 | |
685 | void |
1376 | void |
686 | rxvt_term::selection (SV *newtext = 0) |
1377 | rxvt_term::selection (SV *newtext = 0) |
687 | PPCODE: |
1378 | PPCODE: |
688 | { |
1379 | { |
689 | if (GIMME_V != G_VOID) |
1380 | if (GIMME_V != G_VOID) |
690 | { |
1381 | XPUSHs (THIS->selection.text |
691 | char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); |
1382 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
692 | SV *sv = newSVpv (sel, 0); |
1383 | : &PL_sv_undef); |
693 | SvUTF8_on (sv); |
|
|
694 | free (sel); |
|
|
695 | XPUSHs (sv_2mortal (sv)); |
|
|
696 | } |
|
|
697 | |
1384 | |
698 | if (newtext) |
1385 | if (newtext) |
699 | { |
1386 | { |
700 | free (THIS->selection.text); |
1387 | free (THIS->selection.text); |
701 | |
1388 | |
702 | THIS->selection.text = sv2wcs (newtext); |
1389 | THIS->selection.text = sv2wcs (newtext); |
703 | THIS->selection.len = wcslen (THIS->selection.text); |
1390 | THIS->selection.len = wcslen (THIS->selection.text); |
704 | } |
1391 | } |
705 | } |
1392 | } |
706 | |
|
|
707 | void |
|
|
708 | rxvt_term::scr_overlay_new (int x, int y, int w, int h) |
|
|
709 | |
1393 | |
710 | void |
1394 | void |
|
|
1395 | rxvt_term::scr_xor_rect (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle1 = RS_RVid, U32 rstyle2 = RS_RVid | RS_Uline) |
|
|
1396 | |
|
|
1397 | void |
|
|
1398 | rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) |
|
|
1399 | |
|
|
1400 | void |
711 | rxvt_term::scr_overlay_off () |
1401 | rxvt_term::scr_bell () |
712 | |
1402 | |
713 | void |
1403 | void |
714 | rxvt_term::scr_overlay_set_char (int x, int y, U32 text, U32 rend = OVERLAY_RSTYLE) |
1404 | rxvt_term::scr_add_lines (SV *string) |
715 | CODE: |
1405 | CODE: |
716 | THIS->scr_overlay_set (x, y, text, rend); |
|
|
717 | |
|
|
718 | void |
|
|
719 | rxvt_term::scr_overlay_set (int x, int y, SV *text) |
|
|
720 | CODE: |
|
|
721 | { |
1406 | { |
722 | wchar_t *wtext = sv2wcs (text); |
1407 | wchar_t *wstr = sv2wcs (string); |
723 | THIS->scr_overlay_set (x, y, wtext); |
1408 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
724 | free (wtext); |
1409 | free (wstr); |
725 | } |
1410 | } |
726 | |
1411 | |
727 | void |
1412 | void |
728 | rxvt_term::tt_write (SV *octets) |
1413 | rxvt_term::tt_write (SV *octets) |
729 | INIT: |
1414 | INIT: |
730 | STRLEN len; |
1415 | STRLEN len; |
731 | char *str = SvPVbyte (octets, len); |
1416 | char *str = SvPVbyte (octets, len); |
732 | C_ARGS: |
1417 | C_ARGS: |
733 | (unsigned char *)str, len |
1418 | str, len |
|
|
1419 | |
|
|
1420 | void |
|
|
1421 | rxvt_term::cmd_parse (SV *octets) |
|
|
1422 | CODE: |
|
|
1423 | { |
|
|
1424 | STRLEN len; |
|
|
1425 | char *str = SvPVbyte (octets, len); |
|
|
1426 | |
|
|
1427 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1428 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1429 | |
|
|
1430 | THIS->cmdbuf_ptr = str; |
|
|
1431 | THIS->cmdbuf_endp = str + len; |
|
|
1432 | |
|
|
1433 | rxvt_push_locale (THIS->locale); |
|
|
1434 | THIS->cmd_parse (); |
|
|
1435 | rxvt_pop_locale (); |
|
|
1436 | |
|
|
1437 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1438 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1439 | } |
|
|
1440 | |
|
|
1441 | SV * |
|
|
1442 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
|
|
1443 | CODE: |
|
|
1444 | { |
|
|
1445 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
|
|
1446 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
|
|
1447 | o->self = (HV *)SvRV (RETVAL); |
|
|
1448 | } |
|
|
1449 | OUTPUT: |
|
|
1450 | RETVAL |
|
|
1451 | |
|
|
1452 | MODULE = urxvt PACKAGE = urxvt::overlay |
|
|
1453 | |
|
|
1454 | void |
|
|
1455 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
|
|
1456 | |
|
|
1457 | void |
|
|
1458 | overlay::show () |
|
|
1459 | |
|
|
1460 | void |
|
|
1461 | overlay::hide () |
|
|
1462 | |
|
|
1463 | void |
|
|
1464 | overlay::DESTROY () |
734 | |
1465 | |
735 | MODULE = urxvt PACKAGE = urxvt::timer |
1466 | MODULE = urxvt PACKAGE = urxvt::timer |
736 | |
1467 | |
737 | SV * |
1468 | SV * |
738 | timer::new () |
1469 | timer::new () |
739 | CODE: |
1470 | CODE: |
740 | timer *w = new timer; |
1471 | timer *w = new timer; |
|
|
1472 | w->start (NOW); |
741 | RETVAL = newSVptr ((void *)w, "urxvt::timer"); |
1473 | RETVAL = newSVptr ((void *)w, "urxvt::timer"); |
742 | w->self = (HV *)SvRV (RETVAL); |
1474 | w->self = (HV *)SvRV (RETVAL); |
743 | OUTPUT: |
1475 | OUTPUT: |
744 | RETVAL |
1476 | RETVAL |
745 | |
1477 | |
… | |
… | |
753 | |
1485 | |
754 | NV |
1486 | NV |
755 | timer::at () |
1487 | timer::at () |
756 | CODE: |
1488 | CODE: |
757 | RETVAL = THIS->at; |
1489 | RETVAL = THIS->at; |
|
|
1490 | OUTPUT: |
|
|
1491 | RETVAL |
|
|
1492 | |
|
|
1493 | timer * |
|
|
1494 | timer::interval (NV interval) |
|
|
1495 | CODE: |
|
|
1496 | THIS->interval = interval; |
|
|
1497 | RETVAL = THIS; |
758 | OUTPUT: |
1498 | OUTPUT: |
759 | RETVAL |
1499 | RETVAL |
760 | |
1500 | |
761 | timer * |
1501 | timer * |
762 | timer::set (NV tstamp) |
1502 | timer::set (NV tstamp) |