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