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 | |
33 | #include "rxvt.h" |
34 | #include "rxvt.h" |
34 | #include "iom.h" |
35 | #include "iom.h" |
35 | #include "rxvtutil.h" |
36 | #include "rxvtutil.h" |
36 | #include "rxvtperl.h" |
37 | #include "rxvtperl.h" |
37 | |
38 | |
38 | #include "perlxsi.c" |
39 | #include "perlxsi.c" |
39 | |
40 | |
|
|
41 | #if defined(HAVE_SCROLLBARS) || defined(MENUBAR) |
|
|
42 | # define GRAB_CURSOR THIS->leftptr_cursor |
|
|
43 | #else |
|
|
44 | # define GRAB_CURSOR None |
|
|
45 | #endif |
|
|
46 | |
40 | #undef LINENO |
47 | #undef LINENO |
41 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
48 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
42 | #undef ROW |
49 | #undef ROW |
43 | #define ROW(n) THIS->row_buf [LINENO (n)] |
50 | #define ROW(n) THIS->row_buf [LINENO (n)] |
44 | |
51 | |
45 | ///////////////////////////////////////////////////////////////////////////// |
52 | ///////////////////////////////////////////////////////////////////////////// |
46 | |
53 | |
|
|
54 | static SV * |
|
|
55 | taint (SV *sv) |
|
|
56 | { |
|
|
57 | SvTAINT (sv); |
|
|
58 | return sv; |
|
|
59 | } |
|
|
60 | |
|
|
61 | static SV * |
|
|
62 | taint_if (SV *sv, SV *src) |
|
|
63 | { |
|
|
64 | if (SvTAINTED (src)) |
|
|
65 | SvTAINT (sv); |
|
|
66 | |
|
|
67 | return sv; |
|
|
68 | } |
|
|
69 | |
47 | static wchar_t * |
70 | static wchar_t * |
48 | sv2wcs (SV *sv) |
71 | sv2wcs (SV *sv) |
49 | { |
72 | { |
50 | STRLEN len; |
73 | STRLEN len; |
51 | char *str = SvPVutf8 (sv, len); |
74 | char *str = SvPVutf8 (sv, len); |
52 | return rxvt_utf8towcs (str, len); |
75 | return rxvt_utf8towcs (str, len); |
53 | } |
76 | } |
54 | |
77 | |
55 | static SV * |
78 | static SV * |
|
|
79 | wcs2sv (wchar_t *wstr, int len = -1) |
|
|
80 | { |
|
|
81 | char *str = rxvt_wcstoutf8 (wstr, len); |
|
|
82 | |
|
|
83 | SV *sv = newSVpv (str, 0); |
|
|
84 | SvUTF8_on (sv); |
|
|
85 | free (str); |
|
|
86 | |
|
|
87 | return sv; |
|
|
88 | } |
|
|
89 | |
|
|
90 | static SV * |
56 | new_ref (HV *hv, const char *klass) |
91 | new_ref (HV *hv, const char *klass) |
57 | { |
92 | { |
58 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
93 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
59 | } |
94 | } |
60 | |
95 | |
61 | //TODO: use magic |
96 | //TODO: use magic |
62 | static SV * |
97 | static SV * |
63 | newSVptr (void *ptr, const char *klass) |
98 | newSVptr (void *ptr, const char *klass) |
64 | { |
99 | { |
65 | HV *hv = newHV (); |
100 | HV *hv = newHV (); |
66 | hv_store (hv, "_ptr", 4, newSViv ((long)ptr), 0); |
101 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
67 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
102 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
103 | } |
|
|
104 | |
|
|
105 | static void |
|
|
106 | clearSVptr (SV *sv) |
|
|
107 | { |
|
|
108 | if (SvROK (sv)) |
|
|
109 | sv = SvRV (sv); |
|
|
110 | |
|
|
111 | hv_clear ((HV *)sv); |
|
|
112 | sv_unmagic (sv, PERL_MAGIC_ext); |
68 | } |
113 | } |
69 | |
114 | |
70 | static long |
115 | static long |
71 | SvPTR (SV *sv, const char *klass) |
116 | SvPTR (SV *sv, const char *klass) |
72 | { |
117 | { |
73 | if (!sv_derived_from (sv, klass)) |
118 | if (!sv_derived_from (sv, klass)) |
74 | croak ("object of type %s expected", klass); |
119 | croak ("object of type %s expected", klass); |
75 | |
120 | |
76 | IV iv = SvIV (*hv_fetch ((HV *)SvRV (sv), "_ptr", 4, 1)); |
121 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
77 | |
122 | |
78 | if (!iv) |
123 | if (!mg) |
79 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
124 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
80 | |
125 | |
81 | return (long)iv; |
126 | return (long)mg->mg_ptr; |
82 | } |
127 | } |
83 | |
128 | |
84 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
129 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
85 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
130 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
86 | |
131 | |
87 | ///////////////////////////////////////////////////////////////////////////// |
132 | ///////////////////////////////////////////////////////////////////////////// |
88 | |
133 | |
89 | struct perl_watcher |
134 | struct perl_watcher |
… | |
… | |
186 | rend_t **rend; |
231 | rend_t **rend; |
187 | |
232 | |
188 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
233 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
189 | ~overlay (); |
234 | ~overlay (); |
190 | |
235 | |
|
|
236 | void show (); |
|
|
237 | void hide (); |
|
|
238 | |
191 | void swap (); |
239 | void swap (); |
192 | |
240 | |
193 | void set (int x, int y, SV *str, SV *rend); |
241 | void set (int x, int y, SV *str, SV *rend); |
194 | }; |
242 | }; |
195 | |
243 | |
… | |
… | |
202 | h += 2; |
250 | h += 2; |
203 | } |
251 | } |
204 | |
252 | |
205 | text = new text_t *[h]; |
253 | text = new text_t *[h]; |
206 | rend = new rend_t *[h]; |
254 | rend = new rend_t *[h]; |
207 | |
255 | |
208 | for (int y = 0; y < h; y++) |
256 | for (int y = 0; y < h; y++) |
209 | { |
257 | { |
210 | text_t *tp = text[y] = new text_t[w]; |
258 | text_t *tp = text[y] = new text_t[w]; |
211 | rend_t *rp = rend[y] = new rend_t[w]; |
259 | rend_t *rp = rend[y] = new rend_t[w]; |
212 | |
260 | |
213 | text_t t0, t1, t2; |
261 | text_t t0, t1, t2; |
214 | rend_t r = rstyle; |
262 | rend_t r = rstyle; |
215 | |
263 | |
216 | if (border == 2) |
264 | if (border == 2) |
217 | { |
265 | { |
218 | if (y == 0) |
266 | if (y == 0) |
219 | t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
267 | t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
220 | else if (y < h - 1) |
268 | else if (y < h - 1) |
221 | t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
269 | t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
222 | else |
270 | else |
223 | t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
271 | t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
224 | |
272 | |
225 | *tp++ = t0; |
273 | *tp++ = t0; |
226 | *rp++ = r; |
274 | *rp++ = r; |
227 | |
275 | |
228 | for (int x = w - 2; x-- > 0; ) |
276 | for (int x = w - 2; x-- > 0; ) |
229 | { |
277 | { |
230 | *tp++ = t1; |
278 | *tp++ = t1; |
231 | *rp++ = r; |
279 | *rp++ = r; |
232 | } |
280 | } |
233 | |
281 | |
234 | *tp = t2; |
282 | *tp = t2; |
235 | *rp = r; |
283 | *rp = r; |
236 | } |
284 | } |
237 | else |
285 | else |
238 | for (int x = w; x-- > 0; ) |
286 | for (int x = w; x-- > 0; ) |
239 | { |
287 | { |
240 | *tp++ = 0x0020; |
288 | *tp++ = 0x0020; |
241 | *rp++ = r; |
289 | *rp++ = r; |
242 | } |
290 | } |
243 | } |
291 | } |
244 | |
292 | |
|
|
293 | show (); |
245 | THIS->want_refresh = 1; |
294 | THIS->want_refresh = 1; |
246 | } |
295 | } |
247 | |
296 | |
248 | overlay::~overlay () |
297 | overlay::~overlay () |
249 | { |
298 | { |
|
|
299 | hide (); |
|
|
300 | |
250 | for (int y = h; y--; ) |
301 | for (int y = h; y--; ) |
251 | { |
302 | { |
252 | delete [] text[y]; |
303 | delete [] text[y]; |
253 | delete [] rend[y]; |
304 | delete [] rend[y]; |
254 | } |
305 | } |
… | |
… | |
257 | delete [] rend; |
308 | delete [] rend; |
258 | |
309 | |
259 | THIS->want_refresh = 1; |
310 | THIS->want_refresh = 1; |
260 | } |
311 | } |
261 | |
312 | |
|
|
313 | void |
|
|
314 | overlay::show () |
|
|
315 | { |
|
|
316 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
317 | |
|
|
318 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
|
|
319 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
|
|
320 | } |
|
|
321 | |
|
|
322 | void |
|
|
323 | overlay::hide () |
|
|
324 | { |
|
|
325 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
|
|
326 | |
|
|
327 | if (ovs) |
|
|
328 | { |
|
|
329 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
330 | |
|
|
331 | HV *hv = (HV *)SvRV (*ovs); |
|
|
332 | hv_delete (hv, key, 32, G_DISCARD); |
|
|
333 | } |
|
|
334 | } |
|
|
335 | |
262 | void overlay::swap () |
336 | void overlay::swap () |
263 | { |
337 | { |
264 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
338 | 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)); |
339 | int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); |
266 | |
340 | |
… | |
… | |
269 | |
343 | |
270 | for (int y = ov_h; y--; ) |
344 | for (int y = ov_h; y--; ) |
271 | { |
345 | { |
272 | text_t *t1 = text [y]; |
346 | text_t *t1 = text [y]; |
273 | rend_t *r1 = rend [y]; |
347 | rend_t *r1 = rend [y]; |
274 | |
348 | |
275 | text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
349 | 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; |
350 | rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
277 | |
351 | |
278 | for (int x = ov_w; x--; ) |
352 | for (int x = ov_w; x--; ) |
279 | { |
353 | { |
280 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
354 | 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)); |
355 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
282 | } |
356 | } |
283 | } |
357 | } |
284 | |
358 | |
… | |
… | |
294 | |
368 | |
295 | wchar_t *wtext = sv2wcs (text); |
369 | wchar_t *wtext = sv2wcs (text); |
296 | |
370 | |
297 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
371 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
298 | this->text [y][x + col] = wtext [col]; |
372 | this->text [y][x + col] = wtext [col]; |
299 | |
373 | |
300 | free (wtext); |
374 | free (wtext); |
301 | |
375 | |
302 | if (rend) |
376 | if (rend) |
303 | { |
377 | { |
304 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
378 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
… | |
… | |
338 | { |
412 | { |
339 | if (!perl) |
413 | if (!perl) |
340 | { |
414 | { |
341 | char *argv[] = { |
415 | char *argv[] = { |
342 | "", |
416 | "", |
|
|
417 | "-T", |
343 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
418 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
344 | }; |
419 | }; |
345 | |
420 | |
346 | perl = perl_alloc (); |
421 | perl = perl_alloc (); |
347 | perl_construct (perl); |
422 | perl_construct (perl); |
348 | |
423 | |
349 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
424 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
350 | || perl_run (perl)) |
425 | || perl_run (perl)) |
351 | { |
426 | { |
352 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
427 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
353 | |
428 | |
354 | perl_destruct (perl); |
429 | perl_destruct (perl); |
… | |
… | |
361 | bool |
436 | bool |
362 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
437 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
363 | { |
438 | { |
364 | if (!perl) |
439 | if (!perl) |
365 | return false; |
440 | return false; |
366 | |
441 | |
367 | if (htype == HOOK_INIT) // first hook ever called |
442 | if (htype == HOOK_INIT) // first hook ever called |
368 | { |
443 | { |
369 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
444 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
370 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
445 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
371 | } |
446 | } |
|
|
447 | else if (!term->perl.self) |
|
|
448 | return false; // perl not initialized for this instance |
372 | else if (htype == HOOK_DESTROY) |
449 | else if (htype == HOOK_DESTROY) |
373 | { |
450 | { |
374 | // handled later |
451 | // handled later |
375 | } |
452 | } |
376 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
453 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
377 | { |
454 | { |
378 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
455 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
379 | |
456 | |
380 | if (HvKEYS (hv)) |
457 | if (HvKEYS (hv)) |
381 | { |
458 | { |
382 | hv_iterinit (hv); |
459 | hv_iterinit (hv); |
383 | |
460 | |
… | |
… | |
412 | |
489 | |
413 | case DT_LONG: |
490 | case DT_LONG: |
414 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
491 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
415 | break; |
492 | break; |
416 | |
493 | |
417 | case DT_STRING: |
494 | case DT_STR: |
418 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
495 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
|
|
496 | break; |
|
|
497 | |
|
|
498 | case DT_STR_LEN: |
|
|
499 | { |
|
|
500 | char *str = va_arg (ap, char *); |
|
|
501 | int len = va_arg (ap, int); |
|
|
502 | |
|
|
503 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
|
|
504 | } |
|
|
505 | break; |
|
|
506 | |
|
|
507 | case DT_WCS_LEN: |
|
|
508 | { |
|
|
509 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
510 | int wlen = va_arg (ap, int); |
|
|
511 | |
|
|
512 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
|
|
513 | } |
|
|
514 | break; |
|
|
515 | |
|
|
516 | case DT_XEVENT: |
|
|
517 | { |
|
|
518 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
519 | HV *hv = newHV (); |
|
|
520 | |
|
|
521 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
522 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
523 | # undef set |
|
|
524 | |
|
|
525 | setiv (type, xe->type); |
|
|
526 | setiv (send_event, xe->xany.send_event); |
|
|
527 | setiv (serial, xe->xany.serial); |
|
|
528 | |
|
|
529 | switch (xe->type) |
|
|
530 | { |
|
|
531 | case KeyPress: |
|
|
532 | case KeyRelease: |
|
|
533 | case ButtonPress: |
|
|
534 | case ButtonRelease: |
|
|
535 | case MotionNotify: |
|
|
536 | setiv (time, xe->xmotion.time); |
|
|
537 | setiv (x, xe->xmotion.x); |
|
|
538 | setiv (y, xe->xmotion.y); |
|
|
539 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
540 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
541 | setiv (x_root, xe->xmotion.x_root); |
|
|
542 | setiv (y_root, xe->xmotion.y_root); |
|
|
543 | setiv (state, xe->xmotion.state); |
|
|
544 | break; |
|
|
545 | } |
|
|
546 | |
|
|
547 | switch (xe->type) |
|
|
548 | { |
|
|
549 | case KeyPress: |
|
|
550 | case KeyRelease: |
|
|
551 | setiv (keycode, xe->xkey.keycode); |
|
|
552 | break; |
|
|
553 | |
|
|
554 | case ButtonPress: |
|
|
555 | case ButtonRelease: |
|
|
556 | setiv (button, xe->xbutton.button); |
|
|
557 | break; |
|
|
558 | |
|
|
559 | case MotionNotify: |
|
|
560 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
561 | break; |
|
|
562 | } |
|
|
563 | |
|
|
564 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
565 | } |
419 | break; |
566 | break; |
420 | |
567 | |
421 | case DT_END: |
568 | case DT_END: |
422 | { |
569 | { |
423 | va_end (ap); |
570 | va_end (ap); |
… | |
… | |
439 | if (SvTRUE (ERRSV)) |
586 | if (SvTRUE (ERRSV)) |
440 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
587 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
441 | |
588 | |
442 | if (htype == HOOK_DESTROY) |
589 | if (htype == HOOK_DESTROY) |
443 | { |
590 | { |
444 | // TODO: clear magic |
|
|
445 | hv_clear ((HV *)SvRV ((SV *)term->self)); |
591 | clearSVptr ((SV *)term->perl.self); |
446 | SvREFCNT_dec ((SV *)term->self); |
592 | SvREFCNT_dec ((SV *)term->perl.self); |
447 | } |
593 | } |
448 | |
594 | |
449 | return count; |
595 | return count; |
450 | } |
596 | } |
451 | |
597 | |
… | |
… | |
461 | |
607 | |
462 | PROTOTYPES: ENABLE |
608 | PROTOTYPES: ENABLE |
463 | |
609 | |
464 | BOOT: |
610 | BOOT: |
465 | { |
611 | { |
466 | # define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0)) |
612 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
467 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), #name, newSViv (name)); |
613 | |
468 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
614 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
469 | set_hookname (INIT); |
615 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
470 | set_hookname (RESET); |
616 | # include "hookinc.h" |
471 | set_hookname (START); |
617 | # undef def |
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 | set_hookname (SEL_CLICK); |
|
|
478 | 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 | set_hookname (KEYBOARD_COMMAND); |
|
|
486 | set_hookname (MOUSE_CLICK); |
|
|
487 | set_hookname (MOUSE_MOVE); |
|
|
488 | |
618 | |
|
|
619 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
620 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
621 | # define nodef(name) |
|
|
622 | # include "optinc.h" |
|
|
623 | # undef nodef |
|
|
624 | # undef def |
|
|
625 | |
|
|
626 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
627 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
489 | export_const (DEFAULT_RSTYLE); |
628 | export_const_iv (DEFAULT_RSTYLE); |
490 | export_const (OVERLAY_RSTYLE); |
629 | export_const_iv (OVERLAY_RSTYLE); |
491 | export_const (RS_Bold); |
630 | export_const_iv (RS_Bold); |
492 | export_const (RS_Italic); |
631 | export_const_iv (RS_Italic); |
493 | export_const (RS_Blink); |
632 | export_const_iv (RS_Blink); |
494 | export_const (RS_RVid); |
633 | export_const_iv (RS_RVid); |
495 | export_const (RS_Uline); |
634 | export_const_iv (RS_Uline); |
496 | |
635 | |
497 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
636 | export_const_iv (CurrentTime); |
|
|
637 | export_const_iv (ShiftMask); |
|
|
638 | export_const_iv (LockMask); |
|
|
639 | export_const_iv (ControlMask); |
|
|
640 | export_const_iv (Mod1Mask); |
|
|
641 | export_const_iv (Mod2Mask); |
|
|
642 | export_const_iv (Mod3Mask); |
|
|
643 | export_const_iv (Mod4Mask); |
|
|
644 | export_const_iv (Mod5Mask); |
|
|
645 | export_const_iv (Button1Mask); |
|
|
646 | export_const_iv (Button2Mask); |
|
|
647 | export_const_iv (Button3Mask); |
|
|
648 | export_const_iv (Button4Mask); |
|
|
649 | export_const_iv (Button5Mask); |
|
|
650 | export_const_iv (AnyModifier); |
498 | } |
651 | } |
|
|
652 | |
|
|
653 | SV * |
|
|
654 | new (...) |
|
|
655 | CODE: |
|
|
656 | { |
|
|
657 | stringvec *argv = new stringvec; |
|
|
658 | bool success; |
|
|
659 | |
|
|
660 | for (int i = 0; i < items ;i++) |
|
|
661 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
662 | |
|
|
663 | rxvt_term *term = new rxvt_term; |
|
|
664 | |
|
|
665 | term->argv = argv; |
|
|
666 | |
|
|
667 | try |
|
|
668 | { |
|
|
669 | if (!term->init (argv->size (), argv->begin ())) |
|
|
670 | term = 0; |
|
|
671 | } |
|
|
672 | catch (const class rxvt_failure_exception &e) |
|
|
673 | { |
|
|
674 | term->destroy (); |
|
|
675 | croak ("exception caught while initializing new terminal instance"); |
|
|
676 | } |
|
|
677 | |
|
|
678 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
|
|
679 | } |
|
|
680 | OUTPUT: |
|
|
681 | RETVAL |
499 | |
682 | |
500 | void |
683 | void |
501 | set_should_invoke (int htype, int value) |
684 | set_should_invoke (int htype, int value) |
502 | CODE: |
685 | CODE: |
503 | rxvt_perl.should_invoke [htype] = value; |
686 | rxvt_perl.should_invoke [htype] = value; |
… | |
… | |
566 | } |
749 | } |
567 | OUTPUT: |
750 | OUTPUT: |
568 | RETVAL |
751 | RETVAL |
569 | |
752 | |
570 | MODULE = urxvt PACKAGE = urxvt::term |
753 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
754 | |
|
|
755 | void |
|
|
756 | rxvt_term::destroy () |
|
|
757 | |
|
|
758 | void |
|
|
759 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
760 | CODE: |
|
|
761 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
762 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
763 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
|
|
764 | |
|
|
765 | bool |
|
|
766 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
767 | CODE: |
|
|
768 | { |
|
|
769 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
770 | |
|
|
771 | THIS->perl.grabtime = 0; |
|
|
772 | |
|
|
773 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
774 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
775 | mode, mode, None, GRAB_CURSOR, eventtime)) |
|
|
776 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
777 | THIS->perl.grabtime = eventtime; |
|
|
778 | else |
|
|
779 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
780 | |
|
|
781 | RETVAL = !!THIS->perl.grabtime; |
|
|
782 | } |
|
|
783 | OUTPUT: |
|
|
784 | RETVAL |
|
|
785 | |
|
|
786 | void |
|
|
787 | rxvt_term::allow_events_async () |
|
|
788 | CODE: |
|
|
789 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
|
|
790 | |
|
|
791 | void |
|
|
792 | rxvt_term::allow_events_sync () |
|
|
793 | CODE: |
|
|
794 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
|
|
795 | |
|
|
796 | void |
|
|
797 | rxvt_term::allow_events_replay () |
|
|
798 | CODE: |
|
|
799 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
|
|
800 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
|
|
801 | |
|
|
802 | void |
|
|
803 | rxvt_term::ungrab () |
|
|
804 | CODE: |
|
|
805 | { |
|
|
806 | if (THIS->perl.grabtime) |
|
|
807 | { |
|
|
808 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
809 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
810 | THIS->perl.grabtime = 0; |
|
|
811 | } |
|
|
812 | } |
571 | |
813 | |
572 | int |
814 | int |
573 | rxvt_term::strwidth (SV *str) |
815 | rxvt_term::strwidth (SV *str) |
574 | CODE: |
816 | CODE: |
575 | { |
817 | { |
… | |
… | |
594 | char *mbstr = rxvt_wcstombs (wstr); |
836 | char *mbstr = rxvt_wcstombs (wstr); |
595 | rxvt_pop_locale (); |
837 | rxvt_pop_locale (); |
596 | |
838 | |
597 | free (wstr); |
839 | free (wstr); |
598 | |
840 | |
599 | RETVAL = newSVpv (mbstr, 0); |
841 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
600 | free (mbstr); |
842 | free (mbstr); |
601 | } |
843 | } |
602 | OUTPUT: |
844 | OUTPUT: |
603 | RETVAL |
845 | RETVAL |
604 | |
846 | |
… | |
… | |
611 | |
853 | |
612 | rxvt_push_locale (THIS->locale); |
854 | rxvt_push_locale (THIS->locale); |
613 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
855 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
614 | rxvt_pop_locale (); |
856 | rxvt_pop_locale (); |
615 | |
857 | |
616 | char *str = rxvt_wcstoutf8 (wstr); |
858 | RETVAL = taint_if (wcs2sv (wstr), octets); |
617 | free (wstr); |
859 | free (wstr); |
618 | |
|
|
619 | RETVAL = newSVpv (str, 0); |
|
|
620 | SvUTF8_on (RETVAL); |
|
|
621 | free (str); |
|
|
622 | } |
860 | } |
623 | OUTPUT: |
861 | OUTPUT: |
624 | RETVAL |
862 | RETVAL |
625 | |
863 | |
|
|
864 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
|
|
865 | |
|
|
866 | #define TERM_OFFSET_width TERM_OFFSET(width) |
|
|
867 | #define TERM_OFFSET_height TERM_OFFSET(height) |
|
|
868 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
|
|
869 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
|
|
870 | #define TERM_OFFSET_fbase TERM_OFFSET(fbase) |
|
|
871 | #define TERM_OFFSET_nrow TERM_OFFSET(nrow) |
|
|
872 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
|
|
873 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
|
|
874 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
|
|
875 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
|
|
876 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
|
|
877 | #define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) |
|
|
878 | |
626 | int |
879 | int |
|
|
880 | rxvt_term::width () |
|
|
881 | ALIAS: |
|
|
882 | width = TERM_OFFSET_width |
|
|
883 | height = TERM_OFFSET_height |
|
|
884 | fwidth = TERM_OFFSET_fwidth |
|
|
885 | fheight = TERM_OFFSET_fheight |
|
|
886 | fbase = TERM_OFFSET_fbase |
|
|
887 | nrow = TERM_OFFSET_nrow |
|
|
888 | ncol = TERM_OFFSET_ncol |
|
|
889 | focus = TERM_OFFSET_focus |
|
|
890 | mapped = TERM_OFFSET_mapped |
|
|
891 | saveLines = TERM_OFFSET_saveLines |
|
|
892 | total_rows = TERM_OFFSET_total_rows |
|
|
893 | nsaved = TERM_OFFSET_nsaved |
|
|
894 | CODE: |
|
|
895 | RETVAL = *(int *)((char *)THIS + ix); |
|
|
896 | OUTPUT: |
|
|
897 | RETVAL |
|
|
898 | |
|
|
899 | unsigned int |
|
|
900 | rxvt_term::ModLevel3Mask () |
|
|
901 | ALIAS: |
|
|
902 | ModLevel3Mask = 0 |
|
|
903 | ModMetaMask = 1 |
|
|
904 | ModNumLockMask = 2 |
|
|
905 | CODE: |
|
|
906 | switch (ix) |
|
|
907 | { |
|
|
908 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
909 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
910 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
911 | } |
|
|
912 | OUTPUT: |
|
|
913 | RETVAL |
|
|
914 | |
|
|
915 | U32 |
|
|
916 | rxvt_term::parent () |
|
|
917 | CODE: |
|
|
918 | RETVAL = (U32)THIS->parent [0]; |
|
|
919 | OUTPUT: |
|
|
920 | RETVAL |
|
|
921 | |
|
|
922 | U32 |
627 | rxvt_term::nsaved () |
923 | rxvt_term::vt () |
628 | CODE: |
924 | CODE: |
|
|
925 | RETVAL = (U32)THIS->vt; |
|
|
926 | OUTPUT: |
|
|
927 | RETVAL |
|
|
928 | |
|
|
929 | U32 |
|
|
930 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
|
|
931 | CODE: |
|
|
932 | { |
629 | RETVAL = THIS->nsaved; |
933 | RETVAL = THIS->rstyle; |
|
|
934 | THIS->rstyle = new_rstyle; |
|
|
935 | } |
630 | OUTPUT: |
936 | OUTPUT: |
631 | RETVAL |
937 | RETVAL |
632 | |
938 | |
633 | int |
939 | int |
634 | rxvt_term::view_start (int newval = -1) |
940 | rxvt_term::view_start (int newval = -1) |
635 | CODE: |
941 | CODE: |
636 | { |
942 | { |
… | |
… | |
643 | } |
949 | } |
644 | } |
950 | } |
645 | OUTPUT: |
951 | OUTPUT: |
646 | RETVAL |
952 | RETVAL |
647 | |
953 | |
648 | 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 |
954 | void |
663 | rxvt_term::want_refresh () |
955 | rxvt_term::want_refresh () |
664 | CODE: |
956 | CODE: |
665 | THIS->want_refresh = 1; |
957 | THIS->want_refresh = 1; |
666 | |
958 | |
667 | void |
959 | void |
668 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
960 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
669 | PPCODE: |
961 | PPCODE: |
670 | { |
962 | { |
671 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
963 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
672 | croak ("row_number number of out range"); |
964 | XSRETURN_EMPTY; |
673 | |
965 | |
674 | line_t &l = ROW(row_number); |
966 | line_t &l = ROW(row_number); |
675 | |
967 | |
676 | if (GIMME_V != G_VOID) |
968 | if (GIMME_V != G_VOID) |
677 | { |
969 | { |
678 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
970 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
679 | |
971 | |
680 | for (int col = 0; col <THIS->ncol; col++) |
972 | for (int col = 0; col < THIS->ncol; col++) |
681 | wstr [col] = l.t [col]; |
973 | wstr [col] = l.t [col]; |
682 | |
974 | |
683 | char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); |
975 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
684 | free (wstr); |
|
|
685 | |
976 | |
686 | SV *sv = newSVpv (str, 0); |
977 | delete [] wstr; |
687 | SvUTF8_on (sv); |
|
|
688 | XPUSHs (sv_2mortal (sv)); |
|
|
689 | free (str); |
|
|
690 | } |
978 | } |
691 | |
979 | |
692 | if (new_text) |
980 | if (new_text) |
693 | { |
981 | { |
694 | wchar_t *wstr = sv2wcs (new_text); |
982 | wchar_t *wstr = sv2wcs (new_text); |
695 | |
983 | |
696 | int len = wcslen (wstr); |
984 | int len = min (wcslen (wstr) - start_ofs, max_len); |
697 | |
985 | |
698 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
986 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
699 | { |
987 | { |
700 | free (wstr); |
988 | free (wstr); |
701 | croak ("new_text extends beyond horizontal margins"); |
989 | croak ("new_text extends beyond horizontal margins"); |
702 | } |
990 | } |
703 | |
991 | |
704 | for (int col = start_col; col < start_col + len; col++) |
992 | for (int col = start_col; col < start_col + len; col++) |
705 | { |
993 | { |
706 | l.t [col] = wstr [col - start_col]; |
994 | l.t [col] = wstr [start_ofs + col - start_col]; |
707 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
995 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
708 | } |
996 | } |
709 | |
997 | |
710 | free (wstr); |
998 | free (wstr); |
711 | } |
999 | } |
712 | } |
1000 | } |
713 | |
1001 | |
714 | void |
1002 | void |
715 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
1003 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
716 | PPCODE: |
1004 | PPCODE: |
717 | { |
1005 | { |
718 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1006 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
719 | croak ("row_number number of out range"); |
1007 | XSRETURN_EMPTY; |
720 | |
1008 | |
721 | line_t &l = ROW(row_number); |
1009 | line_t &l = ROW(row_number); |
722 | |
1010 | |
723 | if (GIMME_V != G_VOID) |
1011 | if (GIMME_V != G_VOID) |
724 | { |
1012 | { |
… | |
… | |
735 | { |
1023 | { |
736 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
1024 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
737 | croak ("new_rend must be arrayref"); |
1025 | croak ("new_rend must be arrayref"); |
738 | |
1026 | |
739 | AV *av = (AV *)SvRV (new_rend); |
1027 | AV *av = (AV *)SvRV (new_rend); |
740 | int len = av_len (av) + 1; |
1028 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
741 | |
1029 | |
742 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
1030 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
743 | croak ("new_rend array extends beyond horizontal margins"); |
1031 | croak ("new_rend array extends beyond horizontal margins"); |
744 | |
1032 | |
745 | for (int col = start_col; col < start_col + len; col++) |
1033 | for (int col = start_col; col < start_col + len; col++) |
746 | { |
1034 | { |
747 | rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
1035 | rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
748 | |
1036 | |
749 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
1037 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
750 | } |
1038 | } |
751 | } |
1039 | } |
752 | } |
1040 | } |
753 | |
1041 | |
754 | int |
1042 | int |
755 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
1043 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
756 | CODE: |
1044 | CODE: |
757 | { |
1045 | { |
758 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1046 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
759 | croak ("row_number number of out range"); |
1047 | XSRETURN_EMPTY; |
760 | |
1048 | |
761 | line_t &l = ROW(row_number); |
1049 | line_t &l = ROW(row_number); |
762 | RETVAL = l.l; |
1050 | RETVAL = l.l; |
763 | |
1051 | |
764 | if (new_length >= -1) |
1052 | if (new_length >= 0) |
765 | l.l = new_length; |
1053 | l.l = new_length; |
766 | } |
1054 | } |
767 | OUTPUT: |
1055 | OUTPUT: |
768 | RETVAL |
1056 | RETVAL |
769 | |
1057 | |
|
|
1058 | bool |
|
|
1059 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
|
|
1060 | CODE: |
|
|
1061 | { |
|
|
1062 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
|
|
1063 | XSRETURN_EMPTY; |
|
|
1064 | |
|
|
1065 | line_t &l = ROW(row_number); |
|
|
1066 | RETVAL = l.is_longer (); |
|
|
1067 | |
|
|
1068 | if (new_is_longer >= 0) |
|
|
1069 | l.is_longer (new_is_longer); |
|
|
1070 | } |
|
|
1071 | OUTPUT: |
|
|
1072 | RETVAL |
|
|
1073 | |
770 | SV * |
1074 | SV * |
771 | rxvt_term::special_encode (SV *str) |
1075 | rxvt_term::special_encode (SV *string) |
772 | CODE: |
1076 | CODE: |
773 | abort ();//TODO |
1077 | { |
|
|
1078 | wchar_t *wstr = sv2wcs (string); |
|
|
1079 | int wlen = wcslen (wstr); |
|
|
1080 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1081 | |
|
|
1082 | rxvt_push_locale (THIS->locale); |
|
|
1083 | |
|
|
1084 | wchar_t *r = rstr; |
|
|
1085 | for (wchar_t *s = wstr; *s; s++) |
|
|
1086 | if (wcwidth (*s) == 0) |
|
|
1087 | { |
|
|
1088 | if (r == rstr) |
|
|
1089 | croak ("leading combining character unencodable"); |
|
|
1090 | |
|
|
1091 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1092 | if (n == NOCHAR) |
|
|
1093 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1094 | |
|
|
1095 | r[-1] = n; |
|
|
1096 | } |
|
|
1097 | #if !UNICODE_3 |
|
|
1098 | else if (*s >= 0x10000) |
|
|
1099 | *r++ = rxvt_composite.compose (*s); |
|
|
1100 | #endif |
|
|
1101 | else |
|
|
1102 | *r++ = *s; |
|
|
1103 | |
|
|
1104 | rxvt_pop_locale (); |
|
|
1105 | |
|
|
1106 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
|
|
1107 | |
|
|
1108 | delete [] rstr; |
|
|
1109 | } |
|
|
1110 | OUTPUT: |
|
|
1111 | RETVAL |
774 | |
1112 | |
775 | SV * |
1113 | SV * |
776 | rxvt_term::special_decode (SV *str) |
1114 | rxvt_term::special_decode (SV *text) |
777 | CODE: |
1115 | CODE: |
778 | abort ();//TODO |
1116 | { |
|
|
1117 | wchar_t *wstr = sv2wcs (text); |
|
|
1118 | int wlen = wcslen (wstr); |
|
|
1119 | int dlen = 0; |
|
|
1120 | |
|
|
1121 | // find length |
|
|
1122 | for (wchar_t *s = wstr; *s; s++) |
|
|
1123 | if (*s == NOCHAR) |
|
|
1124 | ; |
|
|
1125 | else if (IS_COMPOSE (*s)) |
|
|
1126 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1127 | else |
|
|
1128 | dlen++; |
|
|
1129 | |
|
|
1130 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1131 | |
|
|
1132 | // decode |
|
|
1133 | wchar_t *r = rstr; |
|
|
1134 | for (wchar_t *s = wstr; *s; s++) |
|
|
1135 | if (*s == NOCHAR) |
|
|
1136 | ; |
|
|
1137 | else if (IS_COMPOSE (*s)) |
|
|
1138 | r += rxvt_composite.expand (*s, r); |
|
|
1139 | else |
|
|
1140 | *r++ = *s; |
|
|
1141 | |
|
|
1142 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
|
|
1143 | |
|
|
1144 | delete [] rstr; |
|
|
1145 | } |
|
|
1146 | OUTPUT: |
|
|
1147 | RETVAL |
779 | |
1148 | |
780 | void |
1149 | void |
781 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1150 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
782 | PPCODE: |
1151 | PPCODE: |
783 | { |
1152 | { |
784 | struct resval { const char *name; int value; } rslist [] = { |
1153 | struct resval { const char *name; int value; } rslist [] = { |
785 | # define Rs_def(name) { # name, Rs_ ## name }, |
1154 | # define def(name) { # name, Rs_ ## name }, |
786 | # define Rs_reserve(name,count) |
1155 | # define reserve(name,count) |
787 | # include "rsinc.h" |
1156 | # include "rsinc.h" |
788 | # undef Rs_def |
1157 | # undef def |
789 | # undef Rs_reserve |
1158 | # undef reserve |
790 | }; |
1159 | }; |
791 | |
1160 | |
792 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1161 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
793 | |
1162 | |
794 | do { |
1163 | do { |
… | |
… | |
800 | |
1169 | |
801 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1170 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
802 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1171 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
803 | |
1172 | |
804 | if (GIMME_V != G_VOID) |
1173 | if (GIMME_V != G_VOID) |
805 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1174 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
806 | |
1175 | |
807 | if (newval) |
1176 | if (newval) |
808 | { |
1177 | { |
809 | if (SvOK (newval)) |
1178 | if (SvOK (newval)) |
810 | { |
1179 | { |
… | |
… | |
815 | else |
1184 | else |
816 | THIS->rs [index] = 0; |
1185 | THIS->rs [index] = 0; |
817 | } |
1186 | } |
818 | } |
1187 | } |
819 | |
1188 | |
|
|
1189 | bool |
|
|
1190 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1191 | CODE: |
|
|
1192 | { |
|
|
1193 | RETVAL = THIS->options & optval; |
|
|
1194 | |
|
|
1195 | if (set >= 0) |
|
|
1196 | { |
|
|
1197 | if (set) |
|
|
1198 | THIS->options |= optval; |
|
|
1199 | else |
|
|
1200 | THIS->options &= ~optval; |
|
|
1201 | |
|
|
1202 | switch (optval) |
|
|
1203 | { |
|
|
1204 | case Opt_skipBuiltinGlyphs: |
|
|
1205 | THIS->set_fonts (); |
|
|
1206 | THIS->scr_remap_chars (); |
|
|
1207 | THIS->scr_touch (true); |
|
|
1208 | THIS->want_refresh = 1; |
|
|
1209 | break; |
|
|
1210 | |
|
|
1211 | case Opt_cursorUnderline: |
|
|
1212 | THIS->want_refresh = 1; |
|
|
1213 | break; |
|
|
1214 | |
|
|
1215 | # case Opt_scrollBar_floating: |
|
|
1216 | # case Opt_scrollBar_right: |
|
|
1217 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1218 | # break; |
|
|
1219 | } |
|
|
1220 | } |
|
|
1221 | } |
|
|
1222 | OUTPUT: |
|
|
1223 | RETVAL |
|
|
1224 | |
820 | void |
1225 | void |
821 | rxvt_term::selection_mark (...) |
1226 | rxvt_term::cur (...) |
822 | PROTOTYPE: $;$$ |
1227 | PROTOTYPE: $;$$ |
823 | ALIAS: |
1228 | ALIAS: |
|
|
1229 | screen_cur = 0 |
824 | selection_beg = 1 |
1230 | selection_beg = 1 |
825 | selection_end = 2 |
1231 | selection_end = 2 |
|
|
1232 | selection_mark = 3 |
826 | PPCODE: |
1233 | PPCODE: |
827 | { |
1234 | { |
828 | row_col_t &sel = ix == 1 ? THIS->selection.beg |
1235 | row_col_t &rc = ix == 0 ? THIS->screen.cur |
|
|
1236 | : ix == 1 ? THIS->selection.beg |
829 | : ix == 2 ? THIS->selection.end |
1237 | : ix == 2 ? THIS->selection.end |
830 | : THIS->selection.mark; |
1238 | : THIS->selection.mark; |
831 | |
1239 | |
832 | if (GIMME_V != G_VOID) |
1240 | if (GIMME_V != G_VOID) |
833 | { |
1241 | { |
834 | EXTEND (SP, 2); |
1242 | EXTEND (SP, 2); |
835 | PUSHs (sv_2mortal (newSViv (sel.row))); |
1243 | PUSHs (sv_2mortal (newSViv (rc.row))); |
836 | PUSHs (sv_2mortal (newSViv (sel.col))); |
1244 | PUSHs (sv_2mortal (newSViv (rc.col))); |
837 | } |
1245 | } |
838 | |
1246 | |
839 | if (items == 3) |
1247 | if (items == 3) |
840 | { |
1248 | { |
841 | sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
1249 | rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
842 | sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
1250 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
843 | |
1251 | |
844 | if (ix) |
1252 | if (ix) |
845 | THIS->want_refresh = 1; |
1253 | THIS->want_refresh = 1; |
846 | } |
1254 | } |
847 | } |
1255 | } |
848 | |
1256 | |
849 | int |
1257 | int |
850 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1258 | rxvt_term::selection_grab (U32 eventtime) |
851 | |
1259 | |
852 | void |
1260 | void |
853 | rxvt_term::selection (SV *newtext = 0) |
1261 | rxvt_term::selection (SV *newtext = 0) |
854 | PPCODE: |
1262 | PPCODE: |
855 | { |
1263 | { |
856 | if (GIMME_V != G_VOID) |
1264 | if (GIMME_V != G_VOID) |
857 | { |
1265 | XPUSHs (taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len)))); |
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 | |
1266 | |
865 | if (newtext) |
1267 | if (newtext) |
866 | { |
1268 | { |
867 | free (THIS->selection.text); |
1269 | free (THIS->selection.text); |
868 | |
1270 | |
869 | THIS->selection.text = sv2wcs (newtext); |
1271 | THIS->selection.text = sv2wcs (newtext); |
870 | THIS->selection.len = wcslen (THIS->selection.text); |
1272 | THIS->selection.len = wcslen (THIS->selection.text); |
871 | } |
1273 | } |
872 | } |
1274 | } |
873 | |
1275 | |
|
|
1276 | void |
|
|
1277 | rxvt_term::scr_add_lines (SV *string) |
|
|
1278 | CODE: |
|
|
1279 | { |
|
|
1280 | wchar_t *wstr = sv2wcs (string); |
|
|
1281 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
|
|
1282 | free (wstr); |
|
|
1283 | } |
|
|
1284 | |
874 | void |
1285 | void |
875 | rxvt_term::tt_write (SV *octets) |
1286 | rxvt_term::tt_write (SV *octets) |
876 | INIT: |
1287 | INIT: |
877 | STRLEN len; |
1288 | STRLEN len; |
878 | char *str = SvPVbyte (octets, len); |
1289 | char *str = SvPVbyte (octets, len); |
879 | C_ARGS: |
1290 | C_ARGS: |
880 | (unsigned char *)str, len |
1291 | str, len |
|
|
1292 | |
|
|
1293 | void |
|
|
1294 | rxvt_term::cmd_parse (SV *octets) |
|
|
1295 | CODE: |
|
|
1296 | { |
|
|
1297 | STRLEN len; |
|
|
1298 | char *str = SvPVbyte (octets, len); |
|
|
1299 | |
|
|
1300 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1301 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1302 | |
|
|
1303 | THIS->cmdbuf_ptr = str; |
|
|
1304 | THIS->cmdbuf_endp = str + len; |
|
|
1305 | |
|
|
1306 | rxvt_push_locale (THIS->locale); |
|
|
1307 | THIS->cmd_parse (); |
|
|
1308 | rxvt_pop_locale (); |
|
|
1309 | |
|
|
1310 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1311 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1312 | } |
881 | |
1313 | |
882 | SV * |
1314 | SV * |
883 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1315 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
884 | CODE: |
1316 | CODE: |
885 | { |
1317 | { |
886 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1318 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
887 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
1319 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
888 | o->self = (HV *)SvRV (RETVAL); |
1320 | o->self = (HV *)SvRV (RETVAL); |
889 | |
|
|
890 | 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 | } |
1321 | } |
894 | OUTPUT: |
1322 | OUTPUT: |
895 | RETVAL |
1323 | RETVAL |
896 | |
1324 | |
897 | MODULE = urxvt PACKAGE = urxvt::overlay |
1325 | MODULE = urxvt PACKAGE = urxvt::overlay |
898 | |
1326 | |
899 | void |
1327 | void |
900 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
1328 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
901 | |
1329 | |
902 | void |
1330 | void |
|
|
1331 | overlay::show () |
|
|
1332 | |
|
|
1333 | void |
|
|
1334 | overlay::hide () |
|
|
1335 | |
|
|
1336 | void |
903 | overlay::DESTROY () |
1337 | overlay::DESTROY () |
904 | CODE: |
|
|
905 | { |
|
|
906 | 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 | } |
|
|
916 | |
1338 | |
917 | MODULE = urxvt PACKAGE = urxvt::timer |
1339 | MODULE = urxvt PACKAGE = urxvt::timer |
918 | |
1340 | |
919 | SV * |
1341 | SV * |
920 | timer::new () |
1342 | timer::new () |