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