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 "unistd.h" |
|
|
35 | |
|
|
36 | #include "iom.h" |
33 | #include "rxvt.h" |
37 | #include "rxvt.h" |
34 | #include "iom.h" |
38 | #include "keyboard.h" |
35 | #include "rxvtutil.h" |
39 | #include "rxvtutil.h" |
36 | #include "rxvtperl.h" |
40 | #include "rxvtperl.h" |
37 | |
41 | |
38 | #include "perlxsi.c" |
42 | #include "perlxsi.c" |
|
|
43 | |
|
|
44 | #ifdef HAVE_SCROLLBARS |
|
|
45 | # define GRAB_CURSOR THIS->leftptr_cursor |
|
|
46 | #else |
|
|
47 | # define GRAB_CURSOR None |
|
|
48 | #endif |
39 | |
49 | |
40 | #undef LINENO |
50 | #undef LINENO |
41 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
51 | #define LINENO(n) MOD (THIS->term_start + int(n), THIS->total_rows) |
42 | #undef ROW |
52 | #undef ROW |
43 | #define ROW(n) THIS->row_buf [LINENO (n)] |
53 | #define ROW(n) THIS->row_buf [LINENO (n)] |
44 | |
54 | |
|
|
55 | #define ENABLE_PERL_FRILLS 1 |
|
|
56 | |
45 | ///////////////////////////////////////////////////////////////////////////// |
57 | ///////////////////////////////////////////////////////////////////////////// |
|
|
58 | |
|
|
59 | static SV * |
|
|
60 | taint (SV *sv) |
|
|
61 | { |
|
|
62 | SvTAINT (sv); |
|
|
63 | return sv; |
|
|
64 | } |
|
|
65 | |
|
|
66 | static SV * |
|
|
67 | taint_if (SV *sv, SV *src) |
|
|
68 | { |
|
|
69 | if (SvTAINTED (src)) |
|
|
70 | SvTAINT (sv); |
|
|
71 | |
|
|
72 | return sv; |
|
|
73 | } |
46 | |
74 | |
47 | static wchar_t * |
75 | static wchar_t * |
48 | sv2wcs (SV *sv) |
76 | sv2wcs (SV *sv) |
49 | { |
77 | { |
50 | STRLEN len; |
78 | STRLEN len; |
51 | char *str = SvPVutf8 (sv, len); |
79 | char *str = SvPVutf8 (sv, len); |
52 | return rxvt_utf8towcs (str, len); |
80 | return rxvt_utf8towcs (str, len); |
53 | } |
81 | } |
54 | |
82 | |
55 | static SV * |
83 | static SV * |
|
|
84 | wcs2sv (wchar_t *wstr, int len = -1) |
|
|
85 | { |
|
|
86 | char *str = rxvt_wcstoutf8 (wstr, len); |
|
|
87 | |
|
|
88 | SV *sv = newSVpv (str, 0); |
|
|
89 | SvUTF8_on (sv); |
|
|
90 | free (str); |
|
|
91 | |
|
|
92 | return sv; |
|
|
93 | } |
|
|
94 | |
|
|
95 | static SV * |
56 | new_ref (HV *hv, const char *klass) |
96 | new_ref (HV *hv, const char *klass) |
57 | { |
97 | { |
58 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
98 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
59 | } |
99 | } |
60 | |
100 | |
61 | //TODO: use magic |
101 | //TODO: use magic |
62 | static SV * |
102 | static SV * |
63 | newSVptr (void *ptr, const char *klass) |
103 | newSVptr (void *ptr, const char *klass) |
64 | { |
104 | { |
65 | HV *hv = newHV (); |
105 | HV *hv = newHV (); |
66 | hv_store (hv, "_ptr", 4, newSViv ((long)ptr), 0); |
106 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
67 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
107 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
108 | } |
|
|
109 | |
|
|
110 | static void |
|
|
111 | clearSVptr (SV *sv) |
|
|
112 | { |
|
|
113 | if (SvROK (sv)) |
|
|
114 | sv = SvRV (sv); |
|
|
115 | |
|
|
116 | hv_clear ((HV *)sv); |
|
|
117 | sv_unmagic (sv, PERL_MAGIC_ext); |
68 | } |
118 | } |
69 | |
119 | |
70 | static long |
120 | static long |
71 | SvPTR (SV *sv, const char *klass) |
121 | SvPTR (SV *sv, const char *klass) |
72 | { |
122 | { |
73 | if (!sv_derived_from (sv, klass)) |
123 | if (!sv_derived_from (sv, klass)) |
74 | croak ("object of type %s expected", klass); |
124 | croak ("object of type %s expected", klass); |
75 | |
125 | |
76 | IV iv = SvIV (*hv_fetch ((HV *)SvRV (sv), "_ptr", 4, 1)); |
126 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
77 | |
127 | |
78 | if (!iv) |
128 | if (!mg) |
79 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
129 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
80 | |
130 | |
81 | return (long)iv; |
131 | return (long)mg->mg_ptr; |
82 | } |
132 | } |
83 | |
133 | |
84 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
134 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
85 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
135 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
86 | |
136 | |
87 | ///////////////////////////////////////////////////////////////////////////// |
137 | ///////////////////////////////////////////////////////////////////////////// |
88 | |
138 | |
89 | struct perl_watcher |
139 | struct perl_watcher |
… | |
… | |
186 | rend_t **rend; |
236 | rend_t **rend; |
187 | |
237 | |
188 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
238 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
189 | ~overlay (); |
239 | ~overlay (); |
190 | |
240 | |
|
|
241 | void show (); |
|
|
242 | void hide (); |
|
|
243 | |
191 | void swap (); |
244 | void swap (); |
192 | |
245 | |
193 | void set (int x, int y, SV *str, SV *rend); |
246 | void set (int x, int y, SV *str, SV *rend); |
194 | }; |
247 | }; |
195 | |
248 | |
… | |
… | |
202 | h += 2; |
255 | h += 2; |
203 | } |
256 | } |
204 | |
257 | |
205 | text = new text_t *[h]; |
258 | text = new text_t *[h]; |
206 | rend = new rend_t *[h]; |
259 | rend = new rend_t *[h]; |
207 | |
260 | |
208 | for (int y = 0; y < h; y++) |
261 | for (int y = 0; y < h; y++) |
209 | { |
262 | { |
210 | text_t *tp = text[y] = new text_t[w]; |
263 | text_t *tp = text[y] = new text_t[w]; |
211 | rend_t *rp = rend[y] = new rend_t[w]; |
264 | rend_t *rp = rend[y] = new rend_t[w]; |
212 | |
265 | |
213 | text_t t0, t1, t2; |
266 | text_t t0, t1, t2; |
214 | rend_t r = rstyle; |
267 | rend_t r = rstyle; |
215 | |
268 | |
216 | if (border == 2) |
269 | if (border == 2) |
217 | { |
270 | { |
218 | if (y == 0) |
271 | if (y == 0) |
219 | t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
272 | t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
220 | else if (y < h - 1) |
273 | else if (y < h - 1) |
221 | t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
274 | t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
222 | else |
275 | else |
223 | t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
276 | t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
224 | |
277 | |
225 | *tp++ = t0; |
278 | *tp++ = t0; |
226 | *rp++ = r; |
279 | *rp++ = r; |
227 | |
280 | |
228 | for (int x = w - 2; x-- > 0; ) |
281 | for (int x = w - 2; x-- > 0; ) |
229 | { |
282 | { |
230 | *tp++ = t1; |
283 | *tp++ = t1; |
231 | *rp++ = r; |
284 | *rp++ = r; |
232 | } |
285 | } |
233 | |
286 | |
234 | *tp = t2; |
287 | *tp = t2; |
235 | *rp = r; |
288 | *rp = r; |
236 | } |
289 | } |
237 | else |
290 | else |
238 | for (int x = w; x-- > 0; ) |
291 | for (int x = w; x-- > 0; ) |
239 | { |
292 | { |
240 | *tp++ = 0x0020; |
293 | *tp++ = 0x0020; |
241 | *rp++ = r; |
294 | *rp++ = r; |
242 | } |
295 | } |
243 | } |
296 | } |
244 | |
297 | |
|
|
298 | show (); |
245 | THIS->want_refresh = 1; |
299 | THIS->want_refresh = 1; |
246 | } |
300 | } |
247 | |
301 | |
248 | overlay::~overlay () |
302 | overlay::~overlay () |
249 | { |
303 | { |
|
|
304 | hide (); |
|
|
305 | |
250 | for (int y = h; y--; ) |
306 | for (int y = h; y--; ) |
251 | { |
307 | { |
252 | delete [] text[y]; |
308 | delete [] text[y]; |
253 | delete [] rend[y]; |
309 | delete [] rend[y]; |
254 | } |
310 | } |
… | |
… | |
257 | delete [] rend; |
313 | delete [] rend; |
258 | |
314 | |
259 | THIS->want_refresh = 1; |
315 | THIS->want_refresh = 1; |
260 | } |
316 | } |
261 | |
317 | |
|
|
318 | void |
|
|
319 | overlay::show () |
|
|
320 | { |
|
|
321 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
322 | |
|
|
323 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
|
|
324 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
|
|
325 | } |
|
|
326 | |
|
|
327 | void |
|
|
328 | overlay::hide () |
|
|
329 | { |
|
|
330 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
|
|
331 | |
|
|
332 | if (ovs) |
|
|
333 | { |
|
|
334 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
335 | |
|
|
336 | HV *hv = (HV *)SvRV (*ovs); |
|
|
337 | hv_delete (hv, key, 32, G_DISCARD); |
|
|
338 | } |
|
|
339 | } |
|
|
340 | |
262 | void overlay::swap () |
341 | void overlay::swap () |
263 | { |
342 | { |
264 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
343 | 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)); |
344 | int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); |
266 | |
345 | |
… | |
… | |
269 | |
348 | |
270 | for (int y = ov_h; y--; ) |
349 | for (int y = ov_h; y--; ) |
271 | { |
350 | { |
272 | text_t *t1 = text [y]; |
351 | text_t *t1 = text [y]; |
273 | rend_t *r1 = rend [y]; |
352 | rend_t *r1 = rend [y]; |
274 | |
353 | |
275 | text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
354 | 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; |
355 | rend_t *r2 = ROW(y + ov_y + THIS->view_start).r + ov_x; |
277 | |
356 | |
278 | for (int x = ov_w; x--; ) |
357 | for (int x = ov_w; x--; ) |
279 | { |
358 | { |
280 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
359 | 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)); |
360 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
282 | } |
361 | } |
283 | } |
362 | } |
284 | |
363 | |
… | |
… | |
294 | |
373 | |
295 | wchar_t *wtext = sv2wcs (text); |
374 | wchar_t *wtext = sv2wcs (text); |
296 | |
375 | |
297 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
376 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
298 | this->text [y][x + col] = wtext [col]; |
377 | this->text [y][x + col] = wtext [col]; |
299 | |
378 | |
300 | free (wtext); |
379 | free (wtext); |
301 | |
380 | |
302 | if (rend) |
381 | if (rend) |
303 | { |
382 | { |
304 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
383 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
… | |
… | |
317 | ///////////////////////////////////////////////////////////////////////////// |
396 | ///////////////////////////////////////////////////////////////////////////// |
318 | |
397 | |
319 | struct rxvt_perl_interp rxvt_perl; |
398 | struct rxvt_perl_interp rxvt_perl; |
320 | |
399 | |
321 | static PerlInterpreter *perl; |
400 | static PerlInterpreter *perl; |
322 | |
|
|
323 | rxvt_perl_interp::rxvt_perl_interp () |
|
|
324 | { |
|
|
325 | } |
|
|
326 | |
401 | |
327 | rxvt_perl_interp::~rxvt_perl_interp () |
402 | rxvt_perl_interp::~rxvt_perl_interp () |
328 | { |
403 | { |
329 | if (perl) |
404 | if (perl) |
330 | { |
405 | { |
… | |
… | |
332 | perl_free (perl); |
407 | perl_free (perl); |
333 | } |
408 | } |
334 | } |
409 | } |
335 | |
410 | |
336 | void |
411 | void |
337 | rxvt_perl_interp::init () |
412 | rxvt_perl_interp::init (rxvt_term *term) |
338 | { |
413 | { |
339 | if (!perl) |
414 | if (!perl) |
340 | { |
415 | { |
|
|
416 | rxvt_push_locale (""); // perl init destroys current locale |
|
|
417 | |
|
|
418 | perl_environ = rxvt_environ; |
|
|
419 | swap (perl_environ, environ); |
|
|
420 | |
341 | char *argv[] = { |
421 | char *argv[] = { |
342 | "", |
422 | "", |
|
|
423 | "-T", |
343 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
424 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
344 | }; |
425 | }; |
345 | |
426 | |
346 | perl = perl_alloc (); |
427 | perl = perl_alloc (); |
347 | perl_construct (perl); |
428 | perl_construct (perl); |
348 | |
429 | |
349 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
430 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
350 | || perl_run (perl)) |
431 | || perl_run (perl)) |
351 | { |
432 | { |
352 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
433 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
353 | |
434 | |
354 | perl_destruct (perl); |
435 | perl_destruct (perl); |
355 | perl_free (perl); |
436 | perl_free (perl); |
356 | perl = 0; |
437 | perl = 0; |
357 | } |
438 | } |
|
|
439 | |
|
|
440 | swap (perl_environ, environ); |
|
|
441 | |
|
|
442 | rxvt_pop_locale (); |
|
|
443 | } |
|
|
444 | |
|
|
445 | if (perl) |
|
|
446 | { |
|
|
447 | // runs outside of perls ENV |
|
|
448 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
|
|
449 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
|
|
450 | } |
|
|
451 | } |
|
|
452 | |
|
|
453 | static void |
|
|
454 | ungrab (rxvt_term *THIS) |
|
|
455 | { |
|
|
456 | if (THIS->perl.grabtime) |
|
|
457 | { |
|
|
458 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
459 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
460 | THIS->perl.grabtime = 0; |
|
|
461 | } |
|
|
462 | } |
|
|
463 | |
|
|
464 | static void |
|
|
465 | swap_overlays (rxvt_term *term) |
|
|
466 | { |
|
|
467 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
468 | |
|
|
469 | if (HvKEYS (hv)) |
|
|
470 | { |
|
|
471 | hv_iterinit (hv); |
|
|
472 | |
|
|
473 | while (HE *he = hv_iternext (hv)) |
|
|
474 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
358 | } |
475 | } |
359 | } |
476 | } |
360 | |
477 | |
361 | bool |
478 | bool |
362 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
479 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
363 | { |
480 | { |
364 | if (!perl) |
481 | if (!perl || !term->perl.self) |
365 | return false; |
482 | return false; |
366 | |
483 | |
367 | if (htype == HOOK_INIT) // first hook ever called |
484 | // pre-handling of some events |
|
|
485 | if (htype == HOOK_REFRESH_END) |
|
|
486 | swap_overlays (term); |
|
|
487 | |
|
|
488 | swap (perl_environ, environ); |
|
|
489 | |
|
|
490 | bool event_consumed; |
|
|
491 | |
|
|
492 | if (htype == HOOK_INIT || htype == HOOK_DESTROY // must be called always |
|
|
493 | || term->perl.should_invoke [htype]) |
|
|
494 | try |
368 | { |
495 | { |
369 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
496 | dSP; |
370 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
497 | va_list ap; |
|
|
498 | |
|
|
499 | va_start (ap, htype); |
|
|
500 | |
|
|
501 | ENTER; |
|
|
502 | SAVETMPS; |
|
|
503 | |
|
|
504 | PUSHMARK (SP); |
|
|
505 | |
|
|
506 | XPUSHs (sv_2mortal (newSVterm (term))); |
|
|
507 | XPUSHs (sv_2mortal (newSViv (htype))); |
|
|
508 | |
|
|
509 | for (;;) { |
|
|
510 | data_type dt = (data_type)va_arg (ap, int); |
|
|
511 | |
|
|
512 | switch (dt) |
|
|
513 | { |
|
|
514 | case DT_INT: |
|
|
515 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
|
|
516 | break; |
|
|
517 | |
|
|
518 | case DT_LONG: |
|
|
519 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
|
|
520 | break; |
|
|
521 | |
|
|
522 | case DT_STR: |
|
|
523 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
|
|
524 | break; |
|
|
525 | |
|
|
526 | case DT_STR_LEN: |
|
|
527 | { |
|
|
528 | char *str = va_arg (ap, char *); |
|
|
529 | int len = va_arg (ap, int); |
|
|
530 | |
|
|
531 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
|
|
532 | } |
|
|
533 | break; |
|
|
534 | |
|
|
535 | case DT_WCS_LEN: |
|
|
536 | { |
|
|
537 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
538 | int wlen = va_arg (ap, int); |
|
|
539 | |
|
|
540 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
|
|
541 | } |
|
|
542 | break; |
|
|
543 | |
|
|
544 | case DT_XEVENT: |
|
|
545 | { |
|
|
546 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
547 | HV *hv = newHV (); |
|
|
548 | |
|
|
549 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
550 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
551 | # undef set |
|
|
552 | |
|
|
553 | setiv (type, xe->type); |
|
|
554 | setiv (send_event, xe->xany.send_event); |
|
|
555 | setiv (serial, xe->xany.serial); |
|
|
556 | |
|
|
557 | switch (xe->type) |
|
|
558 | { |
|
|
559 | case KeyPress: |
|
|
560 | case KeyRelease: |
|
|
561 | case ButtonPress: |
|
|
562 | case ButtonRelease: |
|
|
563 | case MotionNotify: |
|
|
564 | setiv (time, xe->xmotion.time); |
|
|
565 | setiv (x, xe->xmotion.x); |
|
|
566 | setiv (y, xe->xmotion.y); |
|
|
567 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
568 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
569 | setiv (x_root, xe->xmotion.x_root); |
|
|
570 | setiv (y_root, xe->xmotion.y_root); |
|
|
571 | setiv (state, xe->xmotion.state); |
|
|
572 | break; |
|
|
573 | } |
|
|
574 | |
|
|
575 | switch (xe->type) |
|
|
576 | { |
|
|
577 | case KeyPress: |
|
|
578 | case KeyRelease: |
|
|
579 | setiv (keycode, xe->xkey.keycode); |
|
|
580 | break; |
|
|
581 | |
|
|
582 | case ButtonPress: |
|
|
583 | case ButtonRelease: |
|
|
584 | setiv (button, xe->xbutton.button); |
|
|
585 | break; |
|
|
586 | |
|
|
587 | case MotionNotify: |
|
|
588 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
589 | break; |
|
|
590 | } |
|
|
591 | |
|
|
592 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
593 | } |
|
|
594 | break; |
|
|
595 | |
|
|
596 | case DT_END: |
|
|
597 | goto call; |
|
|
598 | |
|
|
599 | default: |
|
|
600 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
601 | } |
|
|
602 | } |
|
|
603 | |
|
|
604 | call: |
|
|
605 | va_end (ap); |
|
|
606 | |
|
|
607 | PUTBACK; |
|
|
608 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
609 | SPAGAIN; |
|
|
610 | |
|
|
611 | if (count) |
|
|
612 | { |
|
|
613 | SV *status = POPs; |
|
|
614 | count = SvTRUE (status); |
|
|
615 | } |
|
|
616 | |
|
|
617 | PUTBACK; |
|
|
618 | FREETMPS; |
|
|
619 | LEAVE; |
|
|
620 | |
|
|
621 | if (SvTRUE (ERRSV)) |
|
|
622 | { |
|
|
623 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
624 | ungrab (term); // better lose the grab than the session |
|
|
625 | } |
|
|
626 | |
|
|
627 | event_consumed = !!count; |
371 | } |
628 | } |
372 | else if (!term->self) |
629 | catch (...) |
373 | return false; // perl not initialized for this instance |
630 | { |
|
|
631 | swap (perl_environ, environ); |
|
|
632 | throw; |
|
|
633 | } |
|
|
634 | else |
|
|
635 | event_consumed = false; |
|
|
636 | |
|
|
637 | // post-handling of some events |
|
|
638 | if (htype == HOOK_REFRESH_BEGIN) |
|
|
639 | swap_overlays (term); |
374 | else if (htype == HOOK_DESTROY) |
640 | else if (htype == HOOK_DESTROY) |
375 | { |
641 | { |
376 | // handled later |
642 | clearSVptr ((SV *)term->perl.self); |
|
|
643 | SvREFCNT_dec ((SV *)term->perl.self); |
377 | } |
644 | } |
378 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
|
|
379 | { |
|
|
380 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
|
|
381 | |
645 | |
382 | if (HvKEYS (hv)) |
646 | swap (perl_environ, environ); |
383 | { |
|
|
384 | hv_iterinit (hv); |
|
|
385 | |
647 | |
386 | while (HE *he = hv_iternext (hv)) |
648 | return event_consumed; |
387 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
388 | } |
|
|
389 | } |
|
|
390 | else if (!should_invoke [htype]) |
|
|
391 | return false; |
|
|
392 | |
|
|
393 | dSP; |
|
|
394 | va_list ap; |
|
|
395 | |
|
|
396 | va_start (ap, htype); |
|
|
397 | |
|
|
398 | ENTER; |
|
|
399 | SAVETMPS; |
|
|
400 | |
|
|
401 | PUSHMARK (SP); |
|
|
402 | |
|
|
403 | XPUSHs (sv_2mortal (newSVterm (term))); |
|
|
404 | XPUSHs (sv_2mortal (newSViv (htype))); |
|
|
405 | |
|
|
406 | for (;;) { |
|
|
407 | data_type dt = (data_type)va_arg (ap, int); |
|
|
408 | |
|
|
409 | switch (dt) |
|
|
410 | { |
|
|
411 | case DT_INT: |
|
|
412 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, int)))); |
|
|
413 | break; |
|
|
414 | |
|
|
415 | case DT_LONG: |
|
|
416 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
|
|
417 | break; |
|
|
418 | |
|
|
419 | case DT_STRING: |
|
|
420 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
|
|
421 | break; |
|
|
422 | |
|
|
423 | case DT_END: |
|
|
424 | { |
|
|
425 | va_end (ap); |
|
|
426 | |
|
|
427 | PUTBACK; |
|
|
428 | int count = call_pv ("urxvt::invoke", G_ARRAY | G_EVAL); |
|
|
429 | SPAGAIN; |
|
|
430 | |
|
|
431 | if (count) |
|
|
432 | { |
|
|
433 | SV *status = POPs; |
|
|
434 | count = SvTRUE (status); |
|
|
435 | } |
|
|
436 | |
|
|
437 | PUTBACK; |
|
|
438 | FREETMPS; |
|
|
439 | LEAVE; |
|
|
440 | |
|
|
441 | if (SvTRUE (ERRSV)) |
|
|
442 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
443 | |
|
|
444 | if (htype == HOOK_DESTROY) |
|
|
445 | { |
|
|
446 | // TODO: clear magic |
|
|
447 | hv_clear ((HV *)SvRV ((SV *)term->self)); |
|
|
448 | SvREFCNT_dec ((SV *)term->self); |
|
|
449 | } |
|
|
450 | |
|
|
451 | return count; |
|
|
452 | } |
|
|
453 | |
|
|
454 | default: |
|
|
455 | rxvt_fatal ("FATAL: unable to pass data type %d\n", dt); |
|
|
456 | } |
|
|
457 | } |
|
|
458 | } |
649 | } |
459 | |
650 | |
460 | ///////////////////////////////////////////////////////////////////////////// |
651 | ///////////////////////////////////////////////////////////////////////////// |
461 | |
652 | |
462 | MODULE = urxvt PACKAGE = urxvt |
653 | MODULE = urxvt PACKAGE = urxvt |
463 | |
654 | |
464 | PROTOTYPES: ENABLE |
655 | PROTOTYPES: ENABLE |
465 | |
656 | |
466 | BOOT: |
657 | BOOT: |
467 | { |
658 | { |
468 | # define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0)) |
659 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
469 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), #name, newSViv (name)); |
660 | sv_setsv (get_sv ("urxvt::RESNAME", 1), newSVpvn (RESNAME, sizeof (RESNAME) - 1)); |
|
|
661 | sv_setsv (get_sv ("urxvt::RESCLASS", 1), newSVpvn (RESCLASS, sizeof (RESCLASS) - 1)); |
|
|
662 | sv_setsv (get_sv ("urxvt::RXVTNAME", 1), newSVpvn (RXVTNAME, sizeof (RXVTNAME) - 1)); |
|
|
663 | |
470 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
664 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
471 | set_hookname (INIT); |
665 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
472 | set_hookname (RESET); |
666 | # include "hookinc.h" |
473 | set_hookname (START); |
667 | # undef def |
474 | set_hookname (DESTROY); |
|
|
475 | set_hookname (SEL_BEGIN); |
|
|
476 | set_hookname (SEL_EXTEND); |
|
|
477 | set_hookname (SEL_MAKE); |
|
|
478 | set_hookname (SEL_GRAB); |
|
|
479 | set_hookname (FOCUS_IN); |
|
|
480 | set_hookname (FOCUS_OUT); |
|
|
481 | set_hookname (VIEW_CHANGE); |
|
|
482 | set_hookname (SCROLL_BACK); |
|
|
483 | set_hookname (TTY_ACTIVITY); |
|
|
484 | set_hookname (REFRESH_BEGIN); |
|
|
485 | set_hookname (REFRESH_END); |
|
|
486 | set_hookname (KEYBOARD_COMMAND); |
|
|
487 | |
668 | |
|
|
669 | HV *option = get_hv ("urxvt::OPTION", 1); |
|
|
670 | # define def(name,val) hv_store (option, # name, sizeof (# name) - 1, newSVuv (Opt_ ## name), 0); |
|
|
671 | # define nodef(name) |
|
|
672 | # include "optinc.h" |
|
|
673 | # undef nodef |
|
|
674 | # undef def |
|
|
675 | |
|
|
676 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
677 | struct { |
|
|
678 | const char *name; |
|
|
679 | IV iv; |
|
|
680 | } *civ, const_iv[] = { |
|
|
681 | # define const_iv(name) { # name, (IV)name } |
488 | export_const (DEFAULT_RSTYLE); |
682 | const_iv (DEFAULT_RSTYLE), |
489 | export_const (OVERLAY_RSTYLE); |
683 | const_iv (OVERLAY_RSTYLE), |
490 | export_const (RS_Bold); |
684 | const_iv (RS_Bold), |
491 | export_const (RS_Italic); |
685 | const_iv (RS_Italic), |
492 | export_const (RS_Blink); |
686 | const_iv (RS_Blink), |
493 | export_const (RS_RVid); |
687 | const_iv (RS_RVid), |
494 | export_const (RS_Uline); |
688 | const_iv (RS_Uline), |
495 | |
689 | |
496 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
690 | const_iv (CurrentTime), |
497 | } |
691 | const_iv (ShiftMask), |
|
|
692 | const_iv (LockMask), |
|
|
693 | const_iv (ControlMask), |
|
|
694 | const_iv (Mod1Mask), |
|
|
695 | const_iv (Mod2Mask), |
|
|
696 | const_iv (Mod3Mask), |
|
|
697 | const_iv (Mod4Mask), |
|
|
698 | const_iv (Mod5Mask), |
|
|
699 | const_iv (Button1Mask), |
|
|
700 | const_iv (Button2Mask), |
|
|
701 | const_iv (Button3Mask), |
|
|
702 | const_iv (Button4Mask), |
|
|
703 | const_iv (Button5Mask), |
|
|
704 | const_iv (AnyModifier), |
498 | |
705 | |
499 | void |
706 | const_iv (EVENT_NONE), |
500 | set_should_invoke (int htype, int value) |
707 | const_iv (EVENT_READ), |
501 | CODE: |
708 | const_iv (EVENT_WRITE), |
502 | rxvt_perl.should_invoke [htype] = value; |
709 | |
|
|
710 | const_iv (NoEventMask), |
|
|
711 | const_iv (KeyPressMask), |
|
|
712 | const_iv (KeyReleaseMask), |
|
|
713 | const_iv (ButtonPressMask), |
|
|
714 | const_iv (ButtonReleaseMask), |
|
|
715 | const_iv (EnterWindowMask), |
|
|
716 | const_iv (LeaveWindowMask), |
|
|
717 | const_iv (PointerMotionMask), |
|
|
718 | const_iv (PointerMotionHintMask), |
|
|
719 | const_iv (Button1MotionMask), |
|
|
720 | const_iv (Button2MotionMask), |
|
|
721 | const_iv (Button3MotionMask), |
|
|
722 | const_iv (Button4MotionMask), |
|
|
723 | const_iv (Button5MotionMask), |
|
|
724 | const_iv (ButtonMotionMask), |
|
|
725 | const_iv (KeymapStateMask), |
|
|
726 | const_iv (ExposureMask), |
|
|
727 | const_iv (VisibilityChangeMask), |
|
|
728 | const_iv (StructureNotifyMask), |
|
|
729 | const_iv (ResizeRedirectMask), |
|
|
730 | const_iv (SubstructureNotifyMask), |
|
|
731 | const_iv (SubstructureRedirectMask), |
|
|
732 | const_iv (FocusChangeMask), |
|
|
733 | const_iv (PropertyChangeMask), |
|
|
734 | const_iv (ColormapChangeMask), |
|
|
735 | const_iv (OwnerGrabButtonMask), |
|
|
736 | |
|
|
737 | const_iv (KeyPress), |
|
|
738 | const_iv (KeyRelease), |
|
|
739 | const_iv (ButtonPress), |
|
|
740 | const_iv (ButtonRelease), |
|
|
741 | const_iv (MotionNotify), |
|
|
742 | const_iv (EnterNotify), |
|
|
743 | const_iv (LeaveNotify), |
|
|
744 | const_iv (FocusIn), |
|
|
745 | const_iv (FocusOut), |
|
|
746 | const_iv (KeymapNotify), |
|
|
747 | const_iv (Expose), |
|
|
748 | const_iv (GraphicsExpose), |
|
|
749 | const_iv (NoExpose), |
|
|
750 | const_iv (VisibilityNotify), |
|
|
751 | const_iv (CreateNotify), |
|
|
752 | const_iv (DestroyNotify), |
|
|
753 | const_iv (UnmapNotify), |
|
|
754 | const_iv (MapNotify), |
|
|
755 | const_iv (MapRequest), |
|
|
756 | const_iv (ReparentNotify), |
|
|
757 | const_iv (ConfigureNotify), |
|
|
758 | const_iv (ConfigureRequest), |
|
|
759 | const_iv (GravityNotify), |
|
|
760 | const_iv (ResizeRequest), |
|
|
761 | const_iv (CirculateNotify), |
|
|
762 | const_iv (CirculateRequest), |
|
|
763 | const_iv (PropertyNotify), |
|
|
764 | const_iv (SelectionClear), |
|
|
765 | const_iv (SelectionRequest), |
|
|
766 | const_iv (SelectionNotify), |
|
|
767 | const_iv (ColormapNotify), |
|
|
768 | const_iv (ClientMessage), |
|
|
769 | const_iv (MappingNotify), |
|
|
770 | }; |
|
|
771 | |
|
|
772 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); |
|
|
773 | civ-- > const_iv; ) |
|
|
774 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
775 | } |
503 | |
776 | |
504 | void |
777 | void |
505 | warn (const char *msg) |
778 | warn (const char *msg) |
506 | CODE: |
779 | CODE: |
507 | rxvt_warn ("%s", msg); |
780 | rxvt_warn ("%s", msg); |
508 | |
781 | |
509 | void |
782 | void |
510 | fatal (const char *msg) |
783 | fatal (const char *msg) |
511 | CODE: |
784 | CODE: |
512 | rxvt_fatal ("%s", msg); |
785 | rxvt_fatal ("%s", msg); |
|
|
786 | |
|
|
787 | SV * |
|
|
788 | untaint (SV *sv) |
|
|
789 | CODE: |
|
|
790 | RETVAL = newSVsv (sv); |
|
|
791 | SvTAINTED_off (RETVAL); |
|
|
792 | OUTPUT: |
|
|
793 | RETVAL |
|
|
794 | |
|
|
795 | void |
|
|
796 | _exit (int status) |
|
|
797 | |
|
|
798 | bool |
|
|
799 | safe () |
|
|
800 | CODE: |
|
|
801 | RETVAL = !rxvt_tainted (); |
|
|
802 | OUTPUT: |
|
|
803 | RETVAL |
513 | |
804 | |
514 | NV |
805 | NV |
515 | NOW () |
806 | NOW () |
516 | CODE: |
807 | CODE: |
517 | RETVAL = NOW; |
808 | RETVAL = NOW; |
… | |
… | |
565 | } |
856 | } |
566 | OUTPUT: |
857 | OUTPUT: |
567 | RETVAL |
858 | RETVAL |
568 | |
859 | |
569 | MODULE = urxvt PACKAGE = urxvt::term |
860 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
861 | |
|
|
862 | SV * |
|
|
863 | _new (...) |
|
|
864 | CODE: |
|
|
865 | { |
|
|
866 | if (items < 1 || !SvROK (ST (0)) || SvTYPE (SvRV (ST (0))) != SVt_PVAV) |
|
|
867 | croak ("first argument to urxvt::term->_new must be arrayref"); |
|
|
868 | |
|
|
869 | rxvt_term *term = new rxvt_term; |
|
|
870 | |
|
|
871 | term->argv = new stringvec; |
|
|
872 | term->envv = new stringvec; |
|
|
873 | |
|
|
874 | for (int i = 1; i < items; i++) |
|
|
875 | term->argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
876 | |
|
|
877 | AV *envv = (AV *)SvRV (ST (0)); |
|
|
878 | for (int i = av_len (envv) + 1; i--; ) |
|
|
879 | term->envv->push_back (strdup (SvPVbyte_nolen (*av_fetch (envv, i, 1)))); |
|
|
880 | |
|
|
881 | term->envv->push_back (0); |
|
|
882 | |
|
|
883 | bool success; |
|
|
884 | |
|
|
885 | try |
|
|
886 | { |
|
|
887 | success = term->init (term->argv->size (), term->argv->begin ()); |
|
|
888 | } |
|
|
889 | catch (const class rxvt_failure_exception &e) |
|
|
890 | { |
|
|
891 | success = false; |
|
|
892 | } |
|
|
893 | |
|
|
894 | if (!success) |
|
|
895 | { |
|
|
896 | term->destroy (); |
|
|
897 | croak ("error while initializing new terminal instance"); |
|
|
898 | } |
|
|
899 | |
|
|
900 | RETVAL = term && term->perl.self |
|
|
901 | ? newSVterm (term) : &PL_sv_undef; |
|
|
902 | } |
|
|
903 | OUTPUT: |
|
|
904 | RETVAL |
|
|
905 | |
|
|
906 | void |
|
|
907 | rxvt_term::destroy () |
|
|
908 | |
|
|
909 | #if ENABLE_PERL_FRILLS |
|
|
910 | |
|
|
911 | void |
|
|
912 | rxvt_term::XListProperties (U32 window) |
|
|
913 | PPCODE: |
|
|
914 | { |
|
|
915 | int count; |
|
|
916 | Atom *props = XListProperties (THIS->display->display, (Window)window, &count); |
|
|
917 | |
|
|
918 | EXTEND (SP, count); |
|
|
919 | while (count--) |
|
|
920 | PUSHs (newSVuv ((U32)props [count])); |
|
|
921 | |
|
|
922 | XFree (props); |
|
|
923 | } |
|
|
924 | |
|
|
925 | void |
|
|
926 | rxvt_term::XGetWindowProperty (U32 window, U32 property) |
|
|
927 | PPCODE: |
|
|
928 | { |
|
|
929 | Atom type; |
|
|
930 | int format; |
|
|
931 | unsigned long nitems; |
|
|
932 | unsigned long bytes_after; |
|
|
933 | unsigned char *prop; |
|
|
934 | XGetWindowProperty (THIS->display->display, (Window)window, (Atom)property, |
|
|
935 | 0, 1<<30, 0, AnyPropertyType, |
|
|
936 | &type, &format, &nitems, &bytes_after, &prop); |
|
|
937 | if (type != None) |
|
|
938 | { |
|
|
939 | EXTEND (SP, 3); |
|
|
940 | PUSHs (newSVuv ((U32)type)); |
|
|
941 | PUSHs (newSViv (format)); |
|
|
942 | PUSHs (newSVpvn ((char *)prop, nitems * format / 8)); |
|
|
943 | XFree (prop); |
|
|
944 | } |
|
|
945 | } |
|
|
946 | |
|
|
947 | void |
|
|
948 | rxvt_term::XChangeWindowProperty (U32 window, U32 property, U32 type, int format, SV *data) |
|
|
949 | CODE: |
|
|
950 | { |
|
|
951 | STRLEN len; |
|
|
952 | char *data_ = SvPVbyte (data, len); |
|
|
953 | |
|
|
954 | XChangeProperty (THIS->display->display, (Window)window, (Atom)property, |
|
|
955 | type, format, PropModeReplace, |
|
|
956 | (unsigned char *)data, len * 8 / format); |
|
|
957 | } |
|
|
958 | |
|
|
959 | void |
|
|
960 | rxvt_term::XDeleteProperty (U32 window, U32 property) |
|
|
961 | CODE: |
|
|
962 | XDeleteProperty (THIS->display->display, (Window)window, (Atom)property); |
|
|
963 | |
|
|
964 | U32 |
|
|
965 | rxvt_term::DefaultRootWindow () |
|
|
966 | CODE: |
|
|
967 | RETVAL = (U32)THIS->display->root; |
|
|
968 | OUTPUT: |
|
|
969 | RETVAL |
|
|
970 | |
|
|
971 | U32 |
|
|
972 | rxvt_term::XCreateSimpleWindow (U32 parent, int x, int y, unsigned int width, unsigned int height) |
|
|
973 | CODE: |
|
|
974 | RETVAL = XCreateSimpleWindow (THIS->display->display, (Window)parent, |
|
|
975 | x, y, width, height, 0, |
|
|
976 | THIS->pix_colors_focused[Color_border], |
|
|
977 | THIS->pix_colors_focused[Color_border]); |
|
|
978 | OUTPUT: |
|
|
979 | RETVAL |
|
|
980 | |
|
|
981 | void |
|
|
982 | rxvt_term::XReparentWindow (U32 window, U32 parent, int x = 0, int y = 0) |
|
|
983 | CODE: |
|
|
984 | XReparentWindow (THIS->display->display, (Window)window, (Window)parent, x, y); |
|
|
985 | |
|
|
986 | void |
|
|
987 | rxvt_term::XMapWindow (U32 window) |
|
|
988 | CODE: |
|
|
989 | XMapWindow (THIS->display->display, (Window)window); |
|
|
990 | |
|
|
991 | void |
|
|
992 | rxvt_term::XUnmapWindow (U32 window) |
|
|
993 | CODE: |
|
|
994 | XUnmapWindow (THIS->display->display, (Window)window); |
|
|
995 | |
|
|
996 | #endif |
|
|
997 | |
|
|
998 | void |
|
|
999 | rxvt_term::set_should_invoke (int htype, int inc) |
|
|
1000 | CODE: |
|
|
1001 | THIS->perl.should_invoke [htype] += inc; |
|
|
1002 | |
|
|
1003 | void |
|
|
1004 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
1005 | CODE: |
|
|
1006 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
1007 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
1008 | GrabModeSync, GrabModeSync, None, GRAB_CURSOR); |
|
|
1009 | |
|
|
1010 | bool |
|
|
1011 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
1012 | CODE: |
|
|
1013 | { |
|
|
1014 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
1015 | |
|
|
1016 | THIS->perl.grabtime = 0; |
|
|
1017 | |
|
|
1018 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
1019 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
1020 | mode, mode, None, GRAB_CURSOR, eventtime)) |
|
|
1021 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
1022 | THIS->perl.grabtime = eventtime; |
|
|
1023 | else |
|
|
1024 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
1025 | |
|
|
1026 | RETVAL = !!THIS->perl.grabtime; |
|
|
1027 | } |
|
|
1028 | OUTPUT: |
|
|
1029 | RETVAL |
|
|
1030 | |
|
|
1031 | void |
|
|
1032 | rxvt_term::allow_events_async () |
|
|
1033 | CODE: |
|
|
1034 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
|
|
1035 | |
|
|
1036 | void |
|
|
1037 | rxvt_term::allow_events_sync () |
|
|
1038 | CODE: |
|
|
1039 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
|
|
1040 | |
|
|
1041 | void |
|
|
1042 | rxvt_term::allow_events_replay () |
|
|
1043 | CODE: |
|
|
1044 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
|
|
1045 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
|
|
1046 | |
|
|
1047 | void |
|
|
1048 | rxvt_term::ungrab () |
|
|
1049 | CODE: |
|
|
1050 | ungrab (THIS); |
570 | |
1051 | |
571 | int |
1052 | int |
572 | rxvt_term::strwidth (SV *str) |
1053 | rxvt_term::strwidth (SV *str) |
573 | CODE: |
1054 | CODE: |
574 | { |
1055 | { |
… | |
… | |
593 | char *mbstr = rxvt_wcstombs (wstr); |
1074 | char *mbstr = rxvt_wcstombs (wstr); |
594 | rxvt_pop_locale (); |
1075 | rxvt_pop_locale (); |
595 | |
1076 | |
596 | free (wstr); |
1077 | free (wstr); |
597 | |
1078 | |
598 | RETVAL = newSVpv (mbstr, 0); |
1079 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
599 | free (mbstr); |
1080 | free (mbstr); |
600 | } |
1081 | } |
601 | OUTPUT: |
1082 | OUTPUT: |
602 | RETVAL |
1083 | RETVAL |
603 | |
1084 | |
… | |
… | |
610 | |
1091 | |
611 | rxvt_push_locale (THIS->locale); |
1092 | rxvt_push_locale (THIS->locale); |
612 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
1093 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
613 | rxvt_pop_locale (); |
1094 | rxvt_pop_locale (); |
614 | |
1095 | |
615 | char *str = rxvt_wcstoutf8 (wstr); |
1096 | RETVAL = taint_if (wcs2sv (wstr), octets); |
616 | free (wstr); |
1097 | free (wstr); |
617 | |
|
|
618 | RETVAL = newSVpv (str, 0); |
|
|
619 | SvUTF8_on (RETVAL); |
|
|
620 | free (str); |
|
|
621 | } |
1098 | } |
622 | OUTPUT: |
1099 | OUTPUT: |
623 | RETVAL |
1100 | RETVAL |
624 | |
1101 | |
|
|
1102 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
|
|
1103 | |
|
|
1104 | #define TERM_OFFSET_width TERM_OFFSET(width) |
|
|
1105 | #define TERM_OFFSET_height TERM_OFFSET(height) |
|
|
1106 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
|
|
1107 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
|
|
1108 | #define TERM_OFFSET_fbase TERM_OFFSET(fbase) |
|
|
1109 | #define TERM_OFFSET_nrow TERM_OFFSET(nrow) |
|
|
1110 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
|
|
1111 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
|
|
1112 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
|
|
1113 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
|
|
1114 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
|
|
1115 | #define TERM_OFFSET_top_row TERM_OFFSET(top_row) |
|
|
1116 | |
625 | int |
1117 | int |
|
|
1118 | rxvt_term::width () |
|
|
1119 | ALIAS: |
|
|
1120 | width = TERM_OFFSET_width |
|
|
1121 | height = TERM_OFFSET_height |
|
|
1122 | fwidth = TERM_OFFSET_fwidth |
|
|
1123 | fheight = TERM_OFFSET_fheight |
|
|
1124 | fbase = TERM_OFFSET_fbase |
|
|
1125 | nrow = TERM_OFFSET_nrow |
|
|
1126 | ncol = TERM_OFFSET_ncol |
|
|
1127 | focus = TERM_OFFSET_focus |
|
|
1128 | mapped = TERM_OFFSET_mapped |
|
|
1129 | saveLines = TERM_OFFSET_saveLines |
|
|
1130 | total_rows = TERM_OFFSET_total_rows |
|
|
1131 | top_row = TERM_OFFSET_top_row |
|
|
1132 | CODE: |
|
|
1133 | RETVAL = *(int *)((char *)THIS + ix); |
|
|
1134 | OUTPUT: |
|
|
1135 | RETVAL |
|
|
1136 | |
|
|
1137 | unsigned int |
|
|
1138 | rxvt_term::ModLevel3Mask () |
|
|
1139 | ALIAS: |
|
|
1140 | ModLevel3Mask = 0 |
|
|
1141 | ModMetaMask = 1 |
|
|
1142 | ModNumLockMask = 2 |
|
|
1143 | CODE: |
|
|
1144 | switch (ix) |
|
|
1145 | { |
|
|
1146 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
1147 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
1148 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
1149 | } |
|
|
1150 | OUTPUT: |
|
|
1151 | RETVAL |
|
|
1152 | |
|
|
1153 | char * |
|
|
1154 | rxvt_term::display_id () |
|
|
1155 | ALIAS: |
|
|
1156 | display_id = 0 |
|
|
1157 | locale = 1 |
|
|
1158 | CODE: |
|
|
1159 | switch (ix) |
|
|
1160 | { |
|
|
1161 | case 0: RETVAL = THIS->display->id; break; |
|
|
1162 | case 1: RETVAL = THIS->locale; break; |
|
|
1163 | } |
|
|
1164 | OUTPUT: |
|
|
1165 | RETVAL |
|
|
1166 | |
|
|
1167 | SV * |
626 | rxvt_term::nsaved () |
1168 | rxvt_term::_env () |
627 | CODE: |
1169 | CODE: |
628 | RETVAL = THIS->nsaved; |
1170 | { |
|
|
1171 | if (THIS->envv) |
|
|
1172 | { |
|
|
1173 | AV *av = newAV (); |
|
|
1174 | |
|
|
1175 | for (char **i = THIS->envv->begin (); i != THIS->envv->end (); ++i) |
|
|
1176 | if (*i) |
|
|
1177 | av_push (av, newSVpv (*i, 0)); |
|
|
1178 | |
|
|
1179 | RETVAL = newRV_noinc ((SV *)av); |
|
|
1180 | } |
|
|
1181 | else |
|
|
1182 | RETVAL = &PL_sv_undef; |
|
|
1183 | } |
629 | OUTPUT: |
1184 | OUTPUT: |
630 | RETVAL |
1185 | RETVAL |
631 | |
1186 | |
632 | int |
1187 | int |
|
|
1188 | rxvt_term::pty_ev_events (int events = EVENT_UNDEF) |
|
|
1189 | CODE: |
|
|
1190 | RETVAL = THIS->pty_ev.events; |
|
|
1191 | if (events != EVENT_UNDEF) |
|
|
1192 | THIS->pty_ev.set (events); |
|
|
1193 | OUTPUT: |
|
|
1194 | RETVAL |
|
|
1195 | |
|
|
1196 | U32 |
|
|
1197 | rxvt_term::parent () |
|
|
1198 | CODE: |
|
|
1199 | RETVAL = (U32)THIS->parent [0]; |
|
|
1200 | OUTPUT: |
|
|
1201 | RETVAL |
|
|
1202 | |
|
|
1203 | U32 |
|
|
1204 | rxvt_term::vt () |
|
|
1205 | CODE: |
|
|
1206 | RETVAL = (U32)THIS->vt; |
|
|
1207 | OUTPUT: |
|
|
1208 | RETVAL |
|
|
1209 | |
|
|
1210 | void |
|
|
1211 | rxvt_term::vt_emask_add (U32 emask) |
|
|
1212 | CODE: |
|
|
1213 | THIS->vt_emask_perl |= emask; |
|
|
1214 | THIS->vt_select_input (); |
|
|
1215 | |
|
|
1216 | U32 |
|
|
1217 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
|
|
1218 | CODE: |
|
|
1219 | RETVAL = THIS->rstyle; |
|
|
1220 | THIS->rstyle = new_rstyle; |
|
|
1221 | OUTPUT: |
|
|
1222 | RETVAL |
|
|
1223 | |
|
|
1224 | int |
633 | rxvt_term::view_start (int newval = -1) |
1225 | rxvt_term::view_start (int newval = 1) |
|
|
1226 | PROTOTYPE: $;$ |
634 | CODE: |
1227 | CODE: |
635 | { |
1228 | { |
636 | RETVAL = THIS->view_start; |
1229 | RETVAL = THIS->view_start; |
637 | |
1230 | |
638 | if (newval >= 0) |
1231 | if (newval <= 0) |
639 | { |
1232 | THIS->scr_changeview (max (newval, THIS->top_row)); |
640 | THIS->view_start = min (newval, THIS->nsaved); |
|
|
641 | THIS->scr_changeview (RETVAL); |
|
|
642 | } |
|
|
643 | } |
1233 | } |
644 | OUTPUT: |
1234 | OUTPUT: |
645 | RETVAL |
1235 | RETVAL |
646 | |
1236 | |
647 | int |
|
|
648 | rxvt_term::nrow () |
|
|
649 | CODE: |
|
|
650 | RETVAL = THIS->nrow; |
|
|
651 | OUTPUT: |
|
|
652 | RETVAL |
|
|
653 | |
|
|
654 | int |
|
|
655 | rxvt_term::ncol () |
|
|
656 | CODE: |
|
|
657 | RETVAL = THIS->ncol; |
|
|
658 | OUTPUT: |
|
|
659 | RETVAL |
|
|
660 | |
|
|
661 | void |
1237 | void |
662 | rxvt_term::want_refresh () |
1238 | rxvt_term::want_refresh () |
663 | CODE: |
1239 | CODE: |
664 | THIS->want_refresh = 1; |
1240 | THIS->want_refresh = 1; |
665 | |
1241 | |
666 | void |
1242 | void |
667 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
1243 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
668 | PPCODE: |
1244 | PPCODE: |
669 | { |
1245 | { |
670 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1246 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
671 | croak ("row_number number of out range"); |
1247 | XSRETURN_EMPTY; |
672 | |
1248 | |
673 | line_t &l = ROW(row_number); |
1249 | line_t &l = ROW(row_number); |
674 | |
1250 | |
675 | if (GIMME_V != G_VOID) |
1251 | if (GIMME_V != G_VOID) |
676 | { |
1252 | { |
677 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1253 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
678 | |
1254 | |
679 | for (int col = 0; col <THIS->ncol; col++) |
1255 | for (int col = 0; col < THIS->ncol; col++) |
680 | wstr [col] = l.t [col]; |
1256 | wstr [col] = l.t [col]; |
681 | |
1257 | |
682 | char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); |
1258 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
683 | free (wstr); |
|
|
684 | |
1259 | |
685 | SV *sv = newSVpv (str, 0); |
1260 | delete [] wstr; |
686 | SvUTF8_on (sv); |
|
|
687 | XPUSHs (sv_2mortal (sv)); |
|
|
688 | free (str); |
|
|
689 | } |
1261 | } |
690 | |
1262 | |
691 | if (new_text) |
1263 | if (new_text) |
692 | { |
1264 | { |
693 | wchar_t *wstr = sv2wcs (new_text); |
1265 | wchar_t *wstr = sv2wcs (new_text); |
694 | |
1266 | |
695 | int len = wcslen (wstr); |
1267 | int len = min (wcslen (wstr) - start_ofs, max_len); |
696 | |
1268 | |
697 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
1269 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
698 | { |
1270 | { |
699 | free (wstr); |
1271 | free (wstr); |
700 | croak ("new_text extends beyond horizontal margins"); |
1272 | croak ("new_text extends beyond horizontal margins"); |
701 | } |
1273 | } |
702 | |
1274 | |
703 | for (int col = start_col; col < start_col + len; col++) |
1275 | for (int col = start_col; col < start_col + len; col++) |
704 | { |
1276 | { |
705 | l.t [col] = wstr [col - start_col]; |
1277 | l.t [col] = wstr [start_ofs + col - start_col]; |
706 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
1278 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
707 | } |
1279 | } |
708 | |
1280 | |
709 | free (wstr); |
1281 | free (wstr); |
710 | } |
1282 | } |
711 | } |
1283 | } |
712 | |
1284 | |
713 | void |
1285 | void |
714 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
1286 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
715 | PPCODE: |
1287 | PPCODE: |
716 | { |
1288 | { |
717 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1289 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
718 | croak ("row_number number of out range"); |
1290 | XSRETURN_EMPTY; |
719 | |
1291 | |
720 | line_t &l = ROW(row_number); |
1292 | line_t &l = ROW(row_number); |
721 | |
1293 | |
722 | if (GIMME_V != G_VOID) |
1294 | if (GIMME_V != G_VOID) |
723 | { |
1295 | { |
… | |
… | |
734 | { |
1306 | { |
735 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
1307 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
736 | croak ("new_rend must be arrayref"); |
1308 | croak ("new_rend must be arrayref"); |
737 | |
1309 | |
738 | AV *av = (AV *)SvRV (new_rend); |
1310 | AV *av = (AV *)SvRV (new_rend); |
739 | int len = av_len (av) + 1; |
1311 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
740 | |
1312 | |
741 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
1313 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
742 | croak ("new_rend array extends beyond horizontal margins"); |
1314 | croak ("new_rend array extends beyond horizontal margins"); |
743 | |
1315 | |
744 | for (int col = start_col; col < start_col + len; col++) |
1316 | for (int col = start_col; col < start_col + len; col++) |
745 | { |
1317 | { |
746 | rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
1318 | rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
747 | |
1319 | |
748 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
1320 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
749 | } |
1321 | } |
750 | } |
1322 | } |
751 | } |
1323 | } |
752 | |
1324 | |
753 | int |
1325 | int |
754 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
1326 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
755 | CODE: |
1327 | CODE: |
756 | { |
1328 | { |
757 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1329 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
758 | croak ("row_number number of out range"); |
1330 | XSRETURN_EMPTY; |
759 | |
1331 | |
760 | line_t &l = ROW(row_number); |
1332 | line_t &l = ROW(row_number); |
761 | RETVAL = l.l; |
1333 | RETVAL = l.l; |
762 | |
1334 | |
763 | if (new_length >= -1) |
1335 | if (new_length >= 0) |
764 | l.l = new_length; |
1336 | l.l = new_length; |
765 | } |
1337 | } |
766 | OUTPUT: |
1338 | OUTPUT: |
767 | RETVAL |
1339 | RETVAL |
768 | |
1340 | |
|
|
1341 | bool |
|
|
1342 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
|
|
1343 | CODE: |
|
|
1344 | { |
|
|
1345 | if (!IN_RANGE_EXC (row_number, THIS->top_row, THIS->nrow)) |
|
|
1346 | XSRETURN_EMPTY; |
|
|
1347 | |
|
|
1348 | line_t &l = ROW(row_number); |
|
|
1349 | RETVAL = l.is_longer (); |
|
|
1350 | |
|
|
1351 | if (new_is_longer >= 0) |
|
|
1352 | l.is_longer (new_is_longer); |
|
|
1353 | } |
|
|
1354 | OUTPUT: |
|
|
1355 | RETVAL |
|
|
1356 | |
769 | SV * |
1357 | SV * |
770 | rxvt_term::special_encode (SV *str) |
1358 | rxvt_term::special_encode (SV *string) |
771 | CODE: |
1359 | CODE: |
772 | abort ();//TODO |
1360 | { |
|
|
1361 | wchar_t *wstr = sv2wcs (string); |
|
|
1362 | int wlen = wcslen (wstr); |
|
|
1363 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1364 | |
|
|
1365 | rxvt_push_locale (THIS->locale); |
|
|
1366 | |
|
|
1367 | wchar_t *r = rstr; |
|
|
1368 | for (wchar_t *s = wstr; *s; s++) |
|
|
1369 | if (wcwidth (*s) == 0) |
|
|
1370 | { |
|
|
1371 | if (r == rstr) |
|
|
1372 | croak ("leading combining character unencodable"); |
|
|
1373 | |
|
|
1374 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1375 | if (n == NOCHAR) |
|
|
1376 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1377 | |
|
|
1378 | r[-1] = n; |
|
|
1379 | } |
|
|
1380 | #if !UNICODE_3 |
|
|
1381 | else if (*s >= 0x10000) |
|
|
1382 | *r++ = rxvt_composite.compose (*s); |
|
|
1383 | #endif |
|
|
1384 | else |
|
|
1385 | *r++ = *s; |
|
|
1386 | |
|
|
1387 | rxvt_pop_locale (); |
|
|
1388 | |
|
|
1389 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
|
|
1390 | |
|
|
1391 | delete [] rstr; |
|
|
1392 | } |
|
|
1393 | OUTPUT: |
|
|
1394 | RETVAL |
773 | |
1395 | |
774 | SV * |
1396 | SV * |
775 | rxvt_term::special_decode (SV *str) |
1397 | rxvt_term::special_decode (SV *text) |
776 | CODE: |
1398 | CODE: |
777 | abort ();//TODO |
1399 | { |
|
|
1400 | wchar_t *wstr = sv2wcs (text); |
|
|
1401 | int wlen = wcslen (wstr); |
|
|
1402 | int dlen = 0; |
|
|
1403 | |
|
|
1404 | // find length |
|
|
1405 | for (wchar_t *s = wstr; *s; s++) |
|
|
1406 | if (*s == NOCHAR) |
|
|
1407 | ; |
|
|
1408 | else if (IS_COMPOSE (*s)) |
|
|
1409 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1410 | else |
|
|
1411 | dlen++; |
|
|
1412 | |
|
|
1413 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1414 | |
|
|
1415 | // decode |
|
|
1416 | wchar_t *r = rstr; |
|
|
1417 | for (wchar_t *s = wstr; *s; s++) |
|
|
1418 | if (*s == NOCHAR) |
|
|
1419 | ; |
|
|
1420 | else if (IS_COMPOSE (*s)) |
|
|
1421 | r += rxvt_composite.expand (*s, r); |
|
|
1422 | else |
|
|
1423 | *r++ = *s; |
|
|
1424 | |
|
|
1425 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
|
|
1426 | |
|
|
1427 | delete [] rstr; |
|
|
1428 | } |
|
|
1429 | OUTPUT: |
|
|
1430 | RETVAL |
778 | |
1431 | |
779 | void |
1432 | void |
780 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1433 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
781 | PPCODE: |
1434 | PPCODE: |
782 | { |
1435 | { |
783 | struct resval { const char *name; int value; } rslist [] = { |
1436 | struct resval { const char *name; int value; } rslist [] = { |
784 | # define Rs_def(name) { # name, Rs_ ## name }, |
1437 | # define def(name) { # name, Rs_ ## name }, |
785 | # define Rs_reserve(name,count) |
1438 | # define reserve(name,count) |
786 | # include "rsinc.h" |
1439 | # include "rsinc.h" |
787 | # undef Rs_def |
1440 | # undef def |
788 | # undef Rs_reserve |
1441 | # undef reserve |
789 | }; |
1442 | }; |
790 | |
1443 | |
791 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1444 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
792 | |
1445 | |
793 | do { |
1446 | do { |
… | |
… | |
799 | |
1452 | |
800 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1453 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
801 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1454 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
802 | |
1455 | |
803 | if (GIMME_V != G_VOID) |
1456 | if (GIMME_V != G_VOID) |
804 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1457 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
805 | |
1458 | |
806 | if (newval) |
1459 | if (newval) |
807 | { |
1460 | { |
808 | if (SvOK (newval)) |
1461 | if (SvOK (newval)) |
809 | { |
1462 | { |
… | |
… | |
814 | else |
1467 | else |
815 | THIS->rs [index] = 0; |
1468 | THIS->rs [index] = 0; |
816 | } |
1469 | } |
817 | } |
1470 | } |
818 | |
1471 | |
|
|
1472 | const char * |
|
|
1473 | rxvt_term::x_resource (const char *name) |
|
|
1474 | CLEANUP: |
|
|
1475 | SvTAINTED_on (ST (0)); |
|
|
1476 | |
|
|
1477 | bool |
|
|
1478 | rxvt_term::option (U32 optval, int set = -1) |
|
|
1479 | CODE: |
|
|
1480 | { |
|
|
1481 | RETVAL = THIS->options & optval; |
|
|
1482 | |
|
|
1483 | if (set >= 0) |
|
|
1484 | { |
|
|
1485 | if (set) |
|
|
1486 | THIS->options |= optval; |
|
|
1487 | else |
|
|
1488 | THIS->options &= ~optval; |
|
|
1489 | |
|
|
1490 | switch (optval) |
|
|
1491 | { |
|
|
1492 | case Opt_skipBuiltinGlyphs: |
|
|
1493 | THIS->set_fonts (); |
|
|
1494 | THIS->scr_remap_chars (); |
|
|
1495 | THIS->scr_touch (true); |
|
|
1496 | THIS->want_refresh = 1; |
|
|
1497 | break; |
|
|
1498 | |
|
|
1499 | case Opt_cursorUnderline: |
|
|
1500 | THIS->want_refresh = 1; |
|
|
1501 | break; |
|
|
1502 | |
|
|
1503 | # case Opt_scrollBar_floating: |
|
|
1504 | # case Opt_scrollBar_right: |
|
|
1505 | # THIS->resize_all_windows (THIS->width, THIS->height, 1); |
|
|
1506 | # break; |
|
|
1507 | } |
|
|
1508 | } |
|
|
1509 | } |
|
|
1510 | OUTPUT: |
|
|
1511 | RETVAL |
|
|
1512 | |
|
|
1513 | bool |
|
|
1514 | rxvt_term::parse_keysym (char *keysym, char *str) |
|
|
1515 | CODE: |
|
|
1516 | RETVAL = 0 < THIS->parse_keysym (keysym, str); |
|
|
1517 | THIS->keyboard->register_done (); |
|
|
1518 | OUTPUT: |
|
|
1519 | RETVAL |
|
|
1520 | |
819 | void |
1521 | void |
820 | rxvt_term::selection_mark (...) |
1522 | rxvt_term::screen_cur (...) |
821 | PROTOTYPE: $;$$ |
1523 | PROTOTYPE: $;$$ |
822 | ALIAS: |
1524 | ALIAS: |
|
|
1525 | screen_cur = 0 |
823 | selection_beg = 1 |
1526 | selection_beg = 1 |
824 | selection_end = 2 |
1527 | selection_end = 2 |
|
|
1528 | selection_mark = 3 |
825 | PPCODE: |
1529 | PPCODE: |
826 | { |
1530 | { |
827 | row_col_t &sel = ix == 1 ? THIS->selection.beg |
1531 | row_col_t &rc = ix == 0 ? THIS->screen.cur |
|
|
1532 | : ix == 1 ? THIS->selection.beg |
828 | : ix == 2 ? THIS->selection.end |
1533 | : ix == 2 ? THIS->selection.end |
829 | : THIS->selection.mark; |
1534 | : THIS->selection.mark; |
830 | |
1535 | |
831 | if (GIMME_V != G_VOID) |
1536 | if (GIMME_V != G_VOID) |
832 | { |
1537 | { |
833 | EXTEND (SP, 2); |
1538 | EXTEND (SP, 2); |
834 | PUSHs (sv_2mortal (newSViv (sel.row))); |
1539 | PUSHs (sv_2mortal (newSViv (rc.row))); |
835 | PUSHs (sv_2mortal (newSViv (sel.col))); |
1540 | PUSHs (sv_2mortal (newSViv (rc.col))); |
836 | } |
1541 | } |
837 | |
1542 | |
838 | if (items == 3) |
1543 | if (items == 3) |
839 | { |
1544 | { |
840 | sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
1545 | rc.row = clamp (SvIV (ST (1)), THIS->top_row, THIS->nrow - 1); |
841 | sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
1546 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
842 | |
1547 | |
843 | if (ix) |
1548 | if (ix) |
844 | THIS->want_refresh = 1; |
1549 | THIS->want_refresh = 1; |
845 | } |
1550 | } |
846 | } |
1551 | } |
847 | |
1552 | |
|
|
1553 | char |
|
|
1554 | rxvt_term::cur_charset () |
|
|
1555 | CODE: |
|
|
1556 | RETVAL = THIS->charsets [THIS->screen.charset]; |
|
|
1557 | OUTPUT: |
|
|
1558 | RETVAL |
|
|
1559 | |
|
|
1560 | #void |
|
|
1561 | #rxvt_term::selection_clear () |
|
|
1562 | |
|
|
1563 | void |
|
|
1564 | rxvt_term::selection_make (U32 eventtime, bool rect = false) |
|
|
1565 | CODE: |
|
|
1566 | THIS->selection.op = SELECTION_CONT; |
|
|
1567 | THIS->selection.rect = rect; |
|
|
1568 | THIS->selection_make (eventtime); |
|
|
1569 | |
848 | int |
1570 | int |
849 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1571 | rxvt_term::selection_grab (U32 eventtime) |
850 | |
1572 | |
851 | void |
1573 | void |
852 | rxvt_term::selection (SV *newtext = 0) |
1574 | rxvt_term::selection (SV *newtext = 0) |
853 | PPCODE: |
1575 | PPCODE: |
854 | { |
1576 | { |
855 | if (GIMME_V != G_VOID) |
1577 | if (GIMME_V != G_VOID) |
856 | { |
1578 | XPUSHs (THIS->selection.text |
857 | char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); |
1579 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
858 | SV *sv = newSVpv (sel, 0); |
1580 | : &PL_sv_undef); |
859 | SvUTF8_on (sv); |
|
|
860 | free (sel); |
|
|
861 | XPUSHs (sv_2mortal (sv)); |
|
|
862 | } |
|
|
863 | |
1581 | |
864 | if (newtext) |
1582 | if (newtext) |
865 | { |
1583 | { |
866 | free (THIS->selection.text); |
1584 | free (THIS->selection.text); |
867 | |
1585 | |
868 | THIS->selection.text = sv2wcs (newtext); |
1586 | THIS->selection.text = sv2wcs (newtext); |
869 | THIS->selection.len = wcslen (THIS->selection.text); |
1587 | THIS->selection.len = wcslen (THIS->selection.text); |
870 | } |
1588 | } |
871 | } |
1589 | } |
872 | |
1590 | |
|
|
1591 | void |
|
|
1592 | 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) |
|
|
1593 | |
|
|
1594 | void |
|
|
1595 | rxvt_term::scr_xor_span (int beg_row, int beg_col, int end_row, int end_col, U32 rstyle = RS_RVid) |
|
|
1596 | |
|
|
1597 | void |
|
|
1598 | rxvt_term::scr_bell () |
|
|
1599 | |
|
|
1600 | void |
|
|
1601 | rxvt_term::scr_add_lines (SV *string) |
|
|
1602 | CODE: |
|
|
1603 | { |
|
|
1604 | wchar_t *wstr = sv2wcs (string); |
|
|
1605 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
|
|
1606 | free (wstr); |
|
|
1607 | } |
|
|
1608 | |
873 | void |
1609 | void |
874 | rxvt_term::tt_write (SV *octets) |
1610 | rxvt_term::tt_write (SV *octets) |
875 | INIT: |
1611 | INIT: |
876 | STRLEN len; |
1612 | STRLEN len; |
877 | char *str = SvPVbyte (octets, len); |
1613 | char *str = SvPVbyte (octets, len); |
878 | C_ARGS: |
1614 | C_ARGS: |
879 | (unsigned char *)str, len |
1615 | str, len |
|
|
1616 | |
|
|
1617 | void |
|
|
1618 | rxvt_term::cmd_parse (SV *octets) |
|
|
1619 | CODE: |
|
|
1620 | { |
|
|
1621 | STRLEN len; |
|
|
1622 | char *str = SvPVbyte (octets, len); |
|
|
1623 | |
|
|
1624 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1625 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1626 | |
|
|
1627 | THIS->cmdbuf_ptr = str; |
|
|
1628 | THIS->cmdbuf_endp = str + len; |
|
|
1629 | |
|
|
1630 | rxvt_push_locale (THIS->locale); |
|
|
1631 | THIS->cmd_parse (); |
|
|
1632 | rxvt_pop_locale (); |
|
|
1633 | |
|
|
1634 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1635 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1636 | } |
880 | |
1637 | |
881 | SV * |
1638 | SV * |
882 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1639 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
883 | CODE: |
1640 | CODE: |
884 | { |
1641 | { |
885 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1642 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
886 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
1643 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
887 | o->self = (HV *)SvRV (RETVAL); |
1644 | o->self = (HV *)SvRV (RETVAL); |
888 | |
|
|
889 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
|
|
890 | char key[33]; sprintf (key, "%32lx", (long)o); |
|
|
891 | hv_store (hv, key, 32, newSViv ((long)o), 0); |
|
|
892 | } |
1645 | } |
893 | OUTPUT: |
1646 | OUTPUT: |
894 | RETVAL |
1647 | RETVAL |
895 | |
1648 | |
896 | MODULE = urxvt PACKAGE = urxvt::overlay |
1649 | MODULE = urxvt PACKAGE = urxvt::overlay |
897 | |
1650 | |
898 | void |
1651 | void |
899 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
1652 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
900 | |
1653 | |
901 | void |
1654 | void |
|
|
1655 | overlay::show () |
|
|
1656 | |
|
|
1657 | void |
|
|
1658 | overlay::hide () |
|
|
1659 | |
|
|
1660 | void |
902 | overlay::DESTROY () |
1661 | overlay::DESTROY () |
903 | CODE: |
|
|
904 | { |
|
|
905 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->THIS->self), "_overlay", 8, 0); |
|
|
906 | if (ovs) |
|
|
907 | { |
|
|
908 | HV *hv = (HV *)SvRV (*ovs); |
|
|
909 | char key[33]; sprintf (key, "%32lx", (long)THIS); |
|
|
910 | hv_delete (hv, key, 32, G_DISCARD); |
|
|
911 | } |
|
|
912 | |
|
|
913 | delete THIS; |
|
|
914 | } |
|
|
915 | |
1662 | |
916 | MODULE = urxvt PACKAGE = urxvt::timer |
1663 | MODULE = urxvt PACKAGE = urxvt::timer |
917 | |
1664 | |
918 | SV * |
1665 | SV * |
919 | timer::new () |
1666 | timer::new () |