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" |
… | |
… | |
51 | char *str = SvPVutf8 (sv, len); |
52 | char *str = SvPVutf8 (sv, len); |
52 | return rxvt_utf8towcs (str, len); |
53 | return rxvt_utf8towcs (str, len); |
53 | } |
54 | } |
54 | |
55 | |
55 | static SV * |
56 | static SV * |
|
|
57 | wcs2sv (wchar_t *wstr, int len = -1) |
|
|
58 | { |
|
|
59 | char *str = rxvt_wcstoutf8 (wstr, len); |
|
|
60 | |
|
|
61 | SV *sv = newSVpv (str, 0); |
|
|
62 | SvUTF8_on (sv); |
|
|
63 | free (str); |
|
|
64 | |
|
|
65 | return sv; |
|
|
66 | } |
|
|
67 | |
|
|
68 | static SV * |
56 | new_ref (HV *hv, const char *klass) |
69 | new_ref (HV *hv, const char *klass) |
57 | { |
70 | { |
58 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
71 | return sv_bless (newRV ((SV *)hv), gv_stashpv (klass, 1)); |
59 | } |
72 | } |
60 | |
73 | |
61 | //TODO: use magic |
74 | //TODO: use magic |
62 | static SV * |
75 | static SV * |
63 | newSVptr (void *ptr, const char *klass) |
76 | newSVptr (void *ptr, const char *klass) |
64 | { |
77 | { |
65 | HV *hv = newHV (); |
78 | HV *hv = newHV (); |
66 | hv_store (hv, "_ptr", 4, newSViv ((long)ptr), 0); |
79 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
67 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
80 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
81 | } |
|
|
82 | |
|
|
83 | static void |
|
|
84 | clearSVptr (SV *sv) |
|
|
85 | { |
|
|
86 | if (SvROK (sv)) |
|
|
87 | sv = SvRV (sv); |
|
|
88 | |
|
|
89 | hv_clear ((HV *)sv); |
|
|
90 | sv_unmagic (sv, PERL_MAGIC_ext); |
68 | } |
91 | } |
69 | |
92 | |
70 | static long |
93 | static long |
71 | SvPTR (SV *sv, const char *klass) |
94 | SvPTR (SV *sv, const char *klass) |
72 | { |
95 | { |
73 | if (!sv_derived_from (sv, klass)) |
96 | if (!sv_derived_from (sv, klass)) |
74 | croak ("object of type %s expected", klass); |
97 | croak ("object of type %s expected", klass); |
75 | |
98 | |
76 | IV iv = SvIV (*hv_fetch ((HV *)SvRV (sv), "_ptr", 4, 1)); |
99 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
77 | |
100 | |
78 | if (!iv) |
101 | if (!mg) |
79 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
102 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
80 | |
103 | |
81 | return (long)iv; |
104 | return (long)mg->mg_ptr; |
82 | } |
105 | } |
83 | |
106 | |
84 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
107 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self) |
85 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
108 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
86 | |
109 | |
87 | ///////////////////////////////////////////////////////////////////////////// |
110 | ///////////////////////////////////////////////////////////////////////////// |
88 | |
111 | |
89 | struct perl_watcher |
112 | struct perl_watcher |
… | |
… | |
139 | #define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") |
162 | #define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") |
140 | #define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") |
163 | #define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") |
141 | |
164 | |
142 | struct timer : time_watcher, perl_watcher |
165 | struct timer : time_watcher, perl_watcher |
143 | { |
166 | { |
|
|
167 | tstamp interval; |
|
|
168 | |
144 | timer () |
169 | timer () |
145 | : time_watcher (this, &timer::execute) |
170 | : time_watcher (this, &timer::execute) |
146 | { |
171 | { |
147 | } |
172 | } |
148 | |
173 | |
149 | void execute (time_watcher &w) |
174 | void execute (time_watcher &w) |
150 | { |
175 | { |
|
|
176 | if (interval) |
|
|
177 | start (at + interval); |
|
|
178 | |
151 | invoke ("urxvt::timer", newSVtimer (this)); |
179 | invoke ("urxvt::timer", newSVtimer (this)); |
152 | } |
180 | } |
153 | }; |
181 | }; |
154 | |
182 | |
155 | #define newSViow(iow) new_ref (iow->self, "urxvt::iow") |
183 | #define newSViow(iow) new_ref (iow->self, "urxvt::iow") |
… | |
… | |
165 | void execute (io_watcher &w, short revents) |
193 | void execute (io_watcher &w, short revents) |
166 | { |
194 | { |
167 | invoke ("urxvt::iow", newSViow (this), revents); |
195 | invoke ("urxvt::iow", newSViow (this), revents); |
168 | } |
196 | } |
169 | }; |
197 | }; |
|
|
198 | |
|
|
199 | ///////////////////////////////////////////////////////////////////////////// |
|
|
200 | |
|
|
201 | #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") |
|
|
202 | |
|
|
203 | struct overlay { |
|
|
204 | HV *self; |
|
|
205 | rxvt_term *THIS; |
|
|
206 | int x, y, w, h; |
|
|
207 | int border; |
|
|
208 | text_t **text; |
|
|
209 | rend_t **rend; |
|
|
210 | |
|
|
211 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
|
|
212 | ~overlay (); |
|
|
213 | |
|
|
214 | void show (); |
|
|
215 | void hide (); |
|
|
216 | |
|
|
217 | void swap (); |
|
|
218 | |
|
|
219 | void set (int x, int y, SV *str, SV *rend); |
|
|
220 | }; |
|
|
221 | |
|
|
222 | overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) |
|
|
223 | : THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2) |
|
|
224 | { |
|
|
225 | if (border == 2) |
|
|
226 | { |
|
|
227 | w += 2; |
|
|
228 | h += 2; |
|
|
229 | } |
|
|
230 | |
|
|
231 | text = new text_t *[h]; |
|
|
232 | rend = new rend_t *[h]; |
|
|
233 | |
|
|
234 | for (int y = 0; y < h; y++) |
|
|
235 | { |
|
|
236 | text_t *tp = text[y] = new text_t[w]; |
|
|
237 | rend_t *rp = rend[y] = new rend_t[w]; |
|
|
238 | |
|
|
239 | text_t t0, t1, t2; |
|
|
240 | rend_t r = rstyle; |
|
|
241 | |
|
|
242 | if (border == 2) |
|
|
243 | { |
|
|
244 | if (y == 0) |
|
|
245 | t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
|
|
246 | else if (y < h - 1) |
|
|
247 | t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
|
|
248 | else |
|
|
249 | t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
|
|
250 | |
|
|
251 | *tp++ = t0; |
|
|
252 | *rp++ = r; |
|
|
253 | |
|
|
254 | for (int x = w - 2; x-- > 0; ) |
|
|
255 | { |
|
|
256 | *tp++ = t1; |
|
|
257 | *rp++ = r; |
|
|
258 | } |
|
|
259 | |
|
|
260 | *tp = t2; |
|
|
261 | *rp = r; |
|
|
262 | } |
|
|
263 | else |
|
|
264 | for (int x = w; x-- > 0; ) |
|
|
265 | { |
|
|
266 | *tp++ = 0x0020; |
|
|
267 | *rp++ = r; |
|
|
268 | } |
|
|
269 | } |
|
|
270 | |
|
|
271 | show (); |
|
|
272 | THIS->want_refresh = 1; |
|
|
273 | } |
|
|
274 | |
|
|
275 | overlay::~overlay () |
|
|
276 | { |
|
|
277 | hide (); |
|
|
278 | |
|
|
279 | for (int y = h; y--; ) |
|
|
280 | { |
|
|
281 | delete [] text[y]; |
|
|
282 | delete [] rend[y]; |
|
|
283 | } |
|
|
284 | |
|
|
285 | delete [] text; |
|
|
286 | delete [] rend; |
|
|
287 | |
|
|
288 | THIS->want_refresh = 1; |
|
|
289 | } |
|
|
290 | |
|
|
291 | void |
|
|
292 | overlay::show () |
|
|
293 | { |
|
|
294 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
295 | |
|
|
296 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0)); |
|
|
297 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
|
|
298 | } |
|
|
299 | |
|
|
300 | void |
|
|
301 | overlay::hide () |
|
|
302 | { |
|
|
303 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0); |
|
|
304 | |
|
|
305 | if (ovs) |
|
|
306 | { |
|
|
307 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
308 | |
|
|
309 | HV *hv = (HV *)SvRV (*ovs); |
|
|
310 | hv_delete (hv, key, 32, G_DISCARD); |
|
|
311 | } |
|
|
312 | } |
|
|
313 | |
|
|
314 | void overlay::swap () |
|
|
315 | { |
|
|
316 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
|
|
317 | int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); |
|
|
318 | |
|
|
319 | int ov_w = min (w, THIS->ncol - ov_x); |
|
|
320 | int ov_h = min (h, THIS->nrow - ov_y); |
|
|
321 | |
|
|
322 | for (int y = ov_h; y--; ) |
|
|
323 | { |
|
|
324 | text_t *t1 = text [y]; |
|
|
325 | rend_t *r1 = rend [y]; |
|
|
326 | |
|
|
327 | text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
|
|
328 | rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
|
|
329 | |
|
|
330 | for (int x = ov_w; x--; ) |
|
|
331 | { |
|
|
332 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
|
|
333 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
|
|
334 | } |
|
|
335 | } |
|
|
336 | |
|
|
337 | } |
|
|
338 | |
|
|
339 | void overlay::set (int x, int y, SV *text, SV *rend) |
|
|
340 | { |
|
|
341 | x += border; |
|
|
342 | y += border; |
|
|
343 | |
|
|
344 | if (!IN_RANGE_EXC (y, 0, h - border)) |
|
|
345 | return; |
|
|
346 | |
|
|
347 | wchar_t *wtext = sv2wcs (text); |
|
|
348 | |
|
|
349 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
|
|
350 | this->text [y][x + col] = wtext [col]; |
|
|
351 | |
|
|
352 | free (wtext); |
|
|
353 | |
|
|
354 | if (rend) |
|
|
355 | { |
|
|
356 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
|
|
357 | croak ("rend must be arrayref"); |
|
|
358 | |
|
|
359 | AV *av = (AV *)SvRV (rend); |
|
|
360 | |
|
|
361 | for (int col = min (av_len (av) + 1, w - x - border); col--; ) |
|
|
362 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
|
|
363 | } |
|
|
364 | |
|
|
365 | THIS->want_refresh = 1; |
|
|
366 | } |
|
|
367 | |
170 | |
368 | |
171 | ///////////////////////////////////////////////////////////////////////////// |
369 | ///////////////////////////////////////////////////////////////////////////// |
172 | |
370 | |
173 | struct rxvt_perl_interp rxvt_perl; |
371 | struct rxvt_perl_interp rxvt_perl; |
174 | |
372 | |
… | |
… | |
213 | } |
411 | } |
214 | |
412 | |
215 | bool |
413 | bool |
216 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
414 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
217 | { |
415 | { |
218 | if (!perl |
416 | if (!perl) |
219 | || (!should_invoke [htype] && htype != HOOK_INIT && htype != HOOK_DESTROY)) |
|
|
220 | return false; |
417 | return false; |
221 | |
418 | |
222 | if (htype == HOOK_INIT) // first hook ever called |
419 | if (htype == HOOK_INIT) // first hook ever called |
|
|
420 | { |
223 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
421 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
|
|
422 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
|
|
423 | } |
|
|
424 | else if (!term->perl.self) |
|
|
425 | return false; // perl not initialized for this instance |
|
|
426 | else if (htype == HOOK_DESTROY) |
|
|
427 | { |
|
|
428 | // handled later |
|
|
429 | } |
|
|
430 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
|
|
431 | { |
|
|
432 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
|
|
433 | |
|
|
434 | if (HvKEYS (hv)) |
|
|
435 | { |
|
|
436 | hv_iterinit (hv); |
|
|
437 | |
|
|
438 | while (HE *he = hv_iternext (hv)) |
|
|
439 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
440 | } |
|
|
441 | } |
|
|
442 | else if (!should_invoke [htype]) |
|
|
443 | return false; |
224 | |
444 | |
225 | dSP; |
445 | dSP; |
226 | va_list ap; |
446 | va_list ap; |
227 | |
447 | |
228 | va_start (ap, htype); |
448 | va_start (ap, htype); |
… | |
… | |
246 | |
466 | |
247 | case DT_LONG: |
467 | case DT_LONG: |
248 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
468 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
249 | break; |
469 | break; |
250 | |
470 | |
251 | case DT_STRING: |
471 | case DT_STR: |
252 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
472 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
|
|
473 | break; |
|
|
474 | |
|
|
475 | case DT_STR_LEN: |
|
|
476 | { |
|
|
477 | char *str = va_arg (ap, char *); |
|
|
478 | int len = va_arg (ap, int); |
|
|
479 | |
|
|
480 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
|
|
481 | } |
|
|
482 | break; |
|
|
483 | |
|
|
484 | case DT_WCS_LEN: |
|
|
485 | { |
|
|
486 | wchar_t *wstr = va_arg (ap, wchar_t *); |
|
|
487 | int wlen = va_arg (ap, int); |
|
|
488 | |
|
|
489 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
|
|
490 | } |
|
|
491 | break; |
|
|
492 | |
|
|
493 | case DT_XEVENT: |
|
|
494 | { |
|
|
495 | XEvent *xe = va_arg (ap, XEvent *); |
|
|
496 | HV *hv = newHV (); |
|
|
497 | |
|
|
498 | # define set(name, sv) hv_store (hv, # name, sizeof (# name) - 1, sv, 0) |
|
|
499 | # define setiv(name, val) hv_store (hv, # name, sizeof (# name) - 1, newSViv (val), 0) |
|
|
500 | # undef set |
|
|
501 | |
|
|
502 | setiv (type, xe->type); |
|
|
503 | setiv (send_event, xe->xany.send_event); |
|
|
504 | setiv (serial, xe->xany.serial); |
|
|
505 | |
|
|
506 | switch (xe->type) |
|
|
507 | { |
|
|
508 | case KeyPress: |
|
|
509 | case KeyRelease: |
|
|
510 | case ButtonPress: |
|
|
511 | case ButtonRelease: |
|
|
512 | case MotionNotify: |
|
|
513 | setiv (time, xe->xmotion.time); |
|
|
514 | setiv (x, xe->xmotion.x); |
|
|
515 | setiv (y, xe->xmotion.y); |
|
|
516 | setiv (row, xe->xmotion.y / term->fheight); |
|
|
517 | setiv (col, xe->xmotion.x / term->fwidth); |
|
|
518 | setiv (x_root, xe->xmotion.x_root); |
|
|
519 | setiv (y_root, xe->xmotion.y_root); |
|
|
520 | setiv (state, xe->xmotion.state); |
|
|
521 | break; |
|
|
522 | } |
|
|
523 | |
|
|
524 | switch (xe->type) |
|
|
525 | { |
|
|
526 | case KeyPress: |
|
|
527 | case KeyRelease: |
|
|
528 | setiv (keycode, xe->xkey.keycode); |
|
|
529 | break; |
|
|
530 | |
|
|
531 | case ButtonPress: |
|
|
532 | case ButtonRelease: |
|
|
533 | setiv (button, xe->xbutton.button); |
|
|
534 | break; |
|
|
535 | |
|
|
536 | case MotionNotify: |
|
|
537 | setiv (is_hint, xe->xmotion.is_hint); |
|
|
538 | break; |
|
|
539 | } |
|
|
540 | |
|
|
541 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
542 | } |
253 | break; |
543 | break; |
254 | |
544 | |
255 | case DT_END: |
545 | case DT_END: |
256 | { |
546 | { |
257 | va_end (ap); |
547 | va_end (ap); |
… | |
… | |
273 | if (SvTRUE (ERRSV)) |
563 | if (SvTRUE (ERRSV)) |
274 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
564 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
275 | |
565 | |
276 | if (htype == HOOK_DESTROY) |
566 | if (htype == HOOK_DESTROY) |
277 | { |
567 | { |
278 | // TODO: clear magic |
|
|
279 | hv_clear ((HV *)SvRV ((SV *)term->self)); |
568 | clearSVptr ((SV *)term->perl.self); |
280 | SvREFCNT_dec ((SV *)term->self); |
569 | SvREFCNT_dec ((SV *)term->perl.self); |
281 | } |
570 | } |
282 | |
571 | |
283 | return count; |
572 | return count; |
284 | } |
573 | } |
285 | |
574 | |
… | |
… | |
295 | |
584 | |
296 | PROTOTYPES: ENABLE |
585 | PROTOTYPES: ENABLE |
297 | |
586 | |
298 | BOOT: |
587 | BOOT: |
299 | { |
588 | { |
300 | # define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0)) |
589 | HV *stash = gv_stashpv ("urxvt", 1); |
|
|
590 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
|
|
591 | |
301 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
592 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
302 | set_hookname (INIT); |
593 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
303 | set_hookname (RESET); |
594 | # include "hookinc.h" |
304 | set_hookname (START); |
595 | # 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 | |
596 | |
319 | newCONSTSUB (gv_stashpv ("urxvt", 1), "DEFAULT_RSTYLE", newSViv (DEFAULT_RSTYLE)); |
597 | |
|
|
598 | export_const_iv (DEFAULT_RSTYLE); |
|
|
599 | export_const_iv (OVERLAY_RSTYLE); |
|
|
600 | export_const_iv (RS_Bold); |
|
|
601 | export_const_iv (RS_Italic); |
|
|
602 | export_const_iv (RS_Blink); |
|
|
603 | export_const_iv (RS_RVid); |
|
|
604 | export_const_iv (RS_Uline); |
320 | |
605 | |
321 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
606 | export_const_iv (CurrentTime); |
|
|
607 | export_const_iv (ShiftMask); |
|
|
608 | export_const_iv (LockMask); |
|
|
609 | export_const_iv (ControlMask); |
|
|
610 | export_const_iv (Mod1Mask); |
|
|
611 | export_const_iv (Mod2Mask); |
|
|
612 | export_const_iv (Mod3Mask); |
|
|
613 | export_const_iv (Mod4Mask); |
|
|
614 | export_const_iv (Mod5Mask); |
|
|
615 | export_const_iv (Button1Mask); |
|
|
616 | export_const_iv (Button2Mask); |
|
|
617 | export_const_iv (Button3Mask); |
|
|
618 | export_const_iv (Button4Mask); |
|
|
619 | export_const_iv (Button5Mask); |
|
|
620 | export_const_iv (AnyModifier); |
|
|
621 | |
|
|
622 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
322 | } |
623 | } |
|
|
624 | |
|
|
625 | SV * |
|
|
626 | new (...) |
|
|
627 | CODE: |
|
|
628 | { |
|
|
629 | stringvec *argv = new stringvec; |
|
|
630 | bool success; |
|
|
631 | |
|
|
632 | for (int i = 0; i < items ;i++) |
|
|
633 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
634 | |
|
|
635 | rxvt_term *term = new rxvt_term; |
|
|
636 | |
|
|
637 | term->argv = argv; |
|
|
638 | |
|
|
639 | try |
|
|
640 | { |
|
|
641 | if (!term->init (argv->size (), argv->begin ())) |
|
|
642 | term = 0; |
|
|
643 | } |
|
|
644 | catch (const class rxvt_failure_exception &e) |
|
|
645 | { |
|
|
646 | term->destroy (); |
|
|
647 | croak ("exception caught while initializing new terminal instance"); |
|
|
648 | } |
|
|
649 | |
|
|
650 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
|
|
651 | } |
|
|
652 | OUTPUT: |
|
|
653 | RETVAL |
323 | |
654 | |
324 | void |
655 | void |
325 | set_should_invoke (int htype, int value) |
656 | set_should_invoke (int htype, int value) |
326 | CODE: |
657 | CODE: |
327 | rxvt_perl.should_invoke [htype] = value; |
658 | rxvt_perl.should_invoke [htype] = value; |
… | |
… | |
341 | CODE: |
672 | CODE: |
342 | RETVAL = NOW; |
673 | RETVAL = NOW; |
343 | OUTPUT: |
674 | OUTPUT: |
344 | RETVAL |
675 | RETVAL |
345 | |
676 | |
|
|
677 | int |
|
|
678 | GET_BASEFG (int rend) |
|
|
679 | CODE: |
|
|
680 | RETVAL = GET_BASEFG (rend); |
|
|
681 | OUTPUT: |
|
|
682 | RETVAL |
|
|
683 | |
|
|
684 | int |
|
|
685 | GET_BASEBG (int rend) |
|
|
686 | CODE: |
|
|
687 | RETVAL = GET_BASEBG (rend); |
|
|
688 | OUTPUT: |
|
|
689 | RETVAL |
|
|
690 | |
|
|
691 | int |
|
|
692 | SET_FGCOLOR (int rend, int new_color) |
|
|
693 | CODE: |
|
|
694 | RETVAL = SET_FGCOLOR (rend, new_color); |
|
|
695 | OUTPUT: |
|
|
696 | RETVAL |
|
|
697 | |
|
|
698 | int |
|
|
699 | SET_BGCOLOR (int rend, int new_color) |
|
|
700 | CODE: |
|
|
701 | RETVAL = SET_BGCOLOR (rend, new_color); |
|
|
702 | OUTPUT: |
|
|
703 | RETVAL |
|
|
704 | |
|
|
705 | int |
|
|
706 | GET_CUSTOM (int rend) |
|
|
707 | CODE: |
|
|
708 | RETVAL = (rend && RS_customMask) >> RS_customShift; |
|
|
709 | OUTPUT: |
|
|
710 | RETVAL |
|
|
711 | |
|
|
712 | int |
|
|
713 | SET_CUSTOM (int rend, int new_value) |
|
|
714 | CODE: |
|
|
715 | { |
|
|
716 | if (!IN_RANGE_EXC (new_value, 0, RS_customCount)) |
|
|
717 | croak ("custom value out of range, must be 0..%d", RS_customCount - 1); |
|
|
718 | |
|
|
719 | RETVAL = (rend & ~RS_customMask) |
|
|
720 | | ((new_value << RS_customShift) & RS_customMask); |
|
|
721 | } |
|
|
722 | OUTPUT: |
|
|
723 | RETVAL |
|
|
724 | |
346 | MODULE = urxvt PACKAGE = urxvt::term |
725 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
726 | |
|
|
727 | void |
|
|
728 | rxvt_term::destroy () |
|
|
729 | |
|
|
730 | void |
|
|
731 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
732 | CODE: |
|
|
733 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
734 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
735 | GrabModeSync, GrabModeSync, None, None); |
|
|
736 | |
|
|
737 | bool |
|
|
738 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
739 | CODE: |
|
|
740 | { |
|
|
741 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
742 | |
|
|
743 | THIS->perl.grabtime = 0; |
|
|
744 | |
|
|
745 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
746 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
747 | mode, mode, None, None, eventtime)) |
|
|
748 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
749 | THIS->perl.grabtime = eventtime; |
|
|
750 | else |
|
|
751 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
752 | |
|
|
753 | RETVAL = !!THIS->perl.grabtime; |
|
|
754 | } |
|
|
755 | OUTPUT: |
|
|
756 | RETVAL |
|
|
757 | |
|
|
758 | void |
|
|
759 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
|
|
760 | CODE: |
|
|
761 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
|
|
762 | |
|
|
763 | void |
|
|
764 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
|
|
765 | CODE: |
|
|
766 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
|
|
767 | |
|
|
768 | void |
|
|
769 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
|
|
770 | CODE: |
|
|
771 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
|
|
772 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
|
|
773 | |
|
|
774 | void |
|
|
775 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
|
|
776 | CODE: |
|
|
777 | THIS->perl.grabtime = 0; |
|
|
778 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
779 | XUngrabPointer (THIS->display->display, eventtime); |
347 | |
780 | |
348 | int |
781 | int |
349 | rxvt_term::strwidth (SV *str) |
782 | rxvt_term::strwidth (SV *str) |
350 | CODE: |
783 | CODE: |
351 | { |
784 | { |
… | |
… | |
387 | |
820 | |
388 | rxvt_push_locale (THIS->locale); |
821 | rxvt_push_locale (THIS->locale); |
389 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
822 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
390 | rxvt_pop_locale (); |
823 | rxvt_pop_locale (); |
391 | |
824 | |
392 | char *str = rxvt_wcstoutf8 (wstr); |
825 | RETVAL = wcs2sv (wstr); |
393 | free (wstr); |
826 | free (wstr); |
394 | |
|
|
395 | RETVAL = newSVpv (str, 0); |
|
|
396 | SvUTF8_on (RETVAL); |
|
|
397 | free (str); |
|
|
398 | } |
827 | } |
399 | OUTPUT: |
828 | OUTPUT: |
400 | RETVAL |
829 | RETVAL |
401 | |
830 | |
|
|
831 | #define TERM_OFFSET(sym) offsetof (TermWin_t, sym) |
|
|
832 | |
|
|
833 | #define TERM_OFFSET_width TERM_OFFSET(width) |
|
|
834 | #define TERM_OFFSET_height TERM_OFFSET(height) |
|
|
835 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
|
|
836 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
|
|
837 | #define TERM_OFFSET_fbase TERM_OFFSET(fbase) |
|
|
838 | #define TERM_OFFSET_nrow TERM_OFFSET(nrow) |
|
|
839 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
|
|
840 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
|
|
841 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
|
|
842 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
|
|
843 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
|
|
844 | #define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) |
|
|
845 | |
402 | int |
846 | int |
|
|
847 | rxvt_term::width () |
|
|
848 | ALIAS: |
|
|
849 | width = TERM_OFFSET_width |
|
|
850 | height = TERM_OFFSET_height |
|
|
851 | fwidth = TERM_OFFSET_fwidth |
|
|
852 | fheight = TERM_OFFSET_fheight |
|
|
853 | fbase = TERM_OFFSET_fbase |
|
|
854 | nrow = TERM_OFFSET_nrow |
|
|
855 | ncol = TERM_OFFSET_ncol |
|
|
856 | focus = TERM_OFFSET_focus |
|
|
857 | mapped = TERM_OFFSET_mapped |
|
|
858 | saveLines = TERM_OFFSET_saveLines |
|
|
859 | total_rows = TERM_OFFSET_total_rows |
|
|
860 | nsaved = TERM_OFFSET_nsaved |
|
|
861 | CODE: |
|
|
862 | RETVAL = *(int *)((char *)THIS + ix); |
|
|
863 | OUTPUT: |
|
|
864 | RETVAL |
|
|
865 | |
|
|
866 | unsigned int |
|
|
867 | rxvt_term::ModLevel3Mask () |
|
|
868 | ALIAS: |
|
|
869 | ModLevel3Mask = 0 |
|
|
870 | ModMetaMask = 1 |
|
|
871 | ModNumLockMask = 2 |
|
|
872 | CODE: |
|
|
873 | switch (ix) |
|
|
874 | { |
|
|
875 | case 0: RETVAL = THIS->ModLevel3Mask; break; |
|
|
876 | case 1: RETVAL = THIS->ModMetaMask; break; |
|
|
877 | case 2: RETVAL = THIS->ModNumLockMask; break; |
|
|
878 | } |
|
|
879 | OUTPUT: |
|
|
880 | RETVAL |
|
|
881 | |
|
|
882 | U32 |
|
|
883 | rxvt_term::parent () |
|
|
884 | CODE: |
|
|
885 | RETVAL = (U32)THIS->parent [0]; |
|
|
886 | OUTPUT: |
|
|
887 | RETVAL |
|
|
888 | |
|
|
889 | U32 |
403 | rxvt_term::nsaved () |
890 | rxvt_term::vt () |
404 | CODE: |
891 | CODE: |
|
|
892 | RETVAL = (U32)THIS->vt; |
|
|
893 | OUTPUT: |
|
|
894 | RETVAL |
|
|
895 | |
|
|
896 | U32 |
|
|
897 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
|
|
898 | CODE: |
|
|
899 | { |
405 | RETVAL = THIS->nsaved; |
900 | RETVAL = THIS->rstyle; |
|
|
901 | THIS->rstyle = new_rstyle; |
|
|
902 | } |
406 | OUTPUT: |
903 | OUTPUT: |
407 | RETVAL |
904 | RETVAL |
408 | |
905 | |
409 | int |
906 | int |
410 | rxvt_term::view_start (int newval = -1) |
907 | rxvt_term::view_start (int newval = -1) |
411 | CODE: |
908 | CODE: |
412 | { |
909 | { |
… | |
… | |
419 | } |
916 | } |
420 | } |
917 | } |
421 | OUTPUT: |
918 | OUTPUT: |
422 | RETVAL |
919 | RETVAL |
423 | |
920 | |
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 |
921 | void |
439 | rxvt_term::want_refresh () |
922 | rxvt_term::want_refresh () |
440 | CODE: |
923 | CODE: |
441 | THIS->want_refresh = 1; |
924 | THIS->want_refresh = 1; |
442 | |
925 | |
443 | void |
926 | void |
444 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
927 | 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: |
928 | PPCODE: |
446 | { |
929 | { |
447 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
930 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
448 | croak ("row_number number of out range"); |
931 | XSRETURN_EMPTY; |
449 | |
932 | |
450 | line_t &l = ROW(row_number); |
933 | line_t &l = ROW(row_number); |
451 | |
934 | |
452 | if (GIMME_V != G_VOID) |
935 | if (GIMME_V != G_VOID) |
453 | { |
936 | { |
454 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
937 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
455 | |
938 | |
456 | for (int col = 0; col <THIS->ncol; col++) |
939 | for (int col = 0; col < THIS->ncol; col++) |
457 | wstr [col] = l.t [col]; |
940 | wstr [col] = l.t [col]; |
458 | |
941 | |
459 | char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); |
|
|
460 | free (wstr); |
|
|
461 | |
|
|
462 | SV *sv = newSVpv (str, 0); |
|
|
463 | SvUTF8_on (sv); |
|
|
464 | XPUSHs (sv_2mortal (sv)); |
942 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
465 | free (str); |
943 | |
|
|
944 | delete [] wstr; |
466 | } |
945 | } |
467 | |
946 | |
468 | if (new_text) |
947 | if (new_text) |
469 | { |
948 | { |
470 | STRLEN slen; |
|
|
471 | char *str = SvPVutf8 (new_text, slen); |
949 | wchar_t *wstr = sv2wcs (new_text); |
472 | wchar_t *wstr = rxvt_utf8towcs (str, slen); |
|
|
473 | |
950 | |
474 | int len = wcslen (wstr); |
951 | int len = min (wcslen (wstr) - start_ofs, max_len); |
475 | |
952 | |
476 | if (start_col + len > THIS->ncol) |
953 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
477 | { |
954 | { |
478 | free (wstr); |
955 | free (wstr); |
479 | croak ("new_text extends beyond right margin"); |
956 | croak ("new_text extends beyond horizontal margins"); |
480 | } |
957 | } |
481 | |
958 | |
482 | for (int col = start_col; col < start_col + len; col++) |
959 | for (int col = start_col; col < start_col + len; col++) |
483 | { |
960 | { |
484 | l.t [col] = wstr [col - start_col]; |
961 | 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])); |
962 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
486 | } |
963 | } |
487 | |
964 | |
488 | free (wstr); |
965 | free (wstr); |
489 | } |
966 | } |
490 | } |
967 | } |
491 | |
968 | |
492 | void |
969 | void |
493 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
970 | 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: |
971 | PPCODE: |
495 | { |
972 | { |
496 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
973 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
497 | croak ("row_number number of out range"); |
974 | XSRETURN_EMPTY; |
498 | |
975 | |
499 | line_t &l = ROW(row_number); |
976 | line_t &l = ROW(row_number); |
500 | |
977 | |
501 | if (GIMME_V != G_VOID) |
978 | if (GIMME_V != G_VOID) |
502 | { |
979 | { |
… | |
… | |
513 | { |
990 | { |
514 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
991 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
515 | croak ("new_rend must be arrayref"); |
992 | croak ("new_rend must be arrayref"); |
516 | |
993 | |
517 | AV *av = (AV *)SvRV (new_rend); |
994 | AV *av = (AV *)SvRV (new_rend); |
518 | int len = av_len (av) + 1; |
995 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
519 | |
996 | |
520 | if (start_col + len > THIS->ncol) |
997 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
521 | croak ("new_rend array extends beyond right margin"); |
998 | croak ("new_rend array extends beyond horizontal margins"); |
522 | |
999 | |
523 | for (int col = start_col; col < start_col + len; col++) |
1000 | for (int col = start_col; col < start_col + len; col++) |
524 | { |
1001 | { |
525 | rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
1002 | rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
526 | |
1003 | |
527 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
1004 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
528 | } |
1005 | } |
529 | } |
1006 | } |
530 | } |
1007 | } |
531 | |
1008 | |
532 | int |
1009 | int |
533 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
1010 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
534 | CODE: |
1011 | CODE: |
535 | { |
1012 | { |
536 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
1013 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
537 | croak ("row_number number of out range"); |
1014 | XSRETURN_EMPTY; |
538 | |
1015 | |
539 | line_t &l = ROW(row_number); |
1016 | line_t &l = ROW(row_number); |
540 | RETVAL = l.l; |
1017 | RETVAL = l.l; |
541 | |
1018 | |
542 | if (new_length >= -1) |
1019 | if (new_length >= 0) |
543 | l.l = new_length; |
1020 | l.l = new_length; |
544 | } |
1021 | } |
545 | OUTPUT: |
1022 | OUTPUT: |
546 | RETVAL |
1023 | RETVAL |
547 | |
1024 | |
|
|
1025 | bool |
|
|
1026 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
|
|
1027 | CODE: |
|
|
1028 | { |
|
|
1029 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
|
|
1030 | XSRETURN_EMPTY; |
|
|
1031 | |
|
|
1032 | line_t &l = ROW(row_number); |
|
|
1033 | RETVAL = l.is_longer (); |
|
|
1034 | |
|
|
1035 | if (new_is_longer >= 0) |
|
|
1036 | l.is_longer (new_is_longer); |
|
|
1037 | } |
|
|
1038 | OUTPUT: |
|
|
1039 | RETVAL |
|
|
1040 | |
548 | SV * |
1041 | SV * |
549 | rxvt_term::special_encode (SV *str) |
1042 | rxvt_term::special_encode (SV *string) |
550 | CODE: |
1043 | CODE: |
551 | abort ();//TODO |
1044 | { |
|
|
1045 | wchar_t *wstr = sv2wcs (string); |
|
|
1046 | int wlen = wcslen (wstr); |
|
|
1047 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1048 | |
|
|
1049 | rxvt_push_locale (THIS->locale); |
|
|
1050 | |
|
|
1051 | wchar_t *r = rstr; |
|
|
1052 | for (wchar_t *s = wstr; *s; s++) |
|
|
1053 | if (wcwidth (*s) == 0) |
|
|
1054 | { |
|
|
1055 | if (r == rstr) |
|
|
1056 | croak ("leading combining character unencodable"); |
|
|
1057 | |
|
|
1058 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1059 | if (n == NOCHAR) |
|
|
1060 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1061 | |
|
|
1062 | r[-1] = n; |
|
|
1063 | } |
|
|
1064 | #if !UNICODE_3 |
|
|
1065 | else if (*s >= 0x10000) |
|
|
1066 | *r++ = rxvt_composite.compose (*s); |
|
|
1067 | #endif |
|
|
1068 | else |
|
|
1069 | *r++ = *s; |
|
|
1070 | |
|
|
1071 | rxvt_pop_locale (); |
|
|
1072 | |
|
|
1073 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1074 | |
|
|
1075 | delete [] rstr; |
|
|
1076 | } |
|
|
1077 | OUTPUT: |
|
|
1078 | RETVAL |
552 | |
1079 | |
553 | SV * |
1080 | SV * |
554 | rxvt_term::special_decode (SV *str) |
1081 | rxvt_term::special_decode (SV *text) |
555 | CODE: |
1082 | CODE: |
556 | abort ();//TODO |
1083 | { |
|
|
1084 | wchar_t *wstr = sv2wcs (text); |
|
|
1085 | int wlen = wcslen (wstr); |
|
|
1086 | int dlen = 0; |
|
|
1087 | |
|
|
1088 | // find length |
|
|
1089 | for (wchar_t *s = wstr; *s; s++) |
|
|
1090 | if (*s == NOCHAR) |
|
|
1091 | ; |
|
|
1092 | else if (IS_COMPOSE (*s)) |
|
|
1093 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1094 | else |
|
|
1095 | dlen++; |
|
|
1096 | |
|
|
1097 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1098 | |
|
|
1099 | // decode |
|
|
1100 | wchar_t *r = rstr; |
|
|
1101 | for (wchar_t *s = wstr; *s; s++) |
|
|
1102 | if (*s == NOCHAR) |
|
|
1103 | ; |
|
|
1104 | else if (IS_COMPOSE (*s)) |
|
|
1105 | r += rxvt_composite.expand (*s, r); |
|
|
1106 | else |
|
|
1107 | *r++ = *s; |
|
|
1108 | |
|
|
1109 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1110 | |
|
|
1111 | delete [] rstr; |
|
|
1112 | } |
|
|
1113 | OUTPUT: |
|
|
1114 | RETVAL |
557 | |
1115 | |
558 | void |
1116 | void |
559 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1117 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
560 | PPCODE: |
1118 | PPCODE: |
561 | { |
1119 | { |
562 | struct resval { const char *name; int value; } rslist [] = { |
1120 | struct resval { const char *name; int value; } rslist [] = { |
563 | # define Rs_def(name) { # name, Rs_ ## name }, |
1121 | # define def(name) { # name, Rs_ ## name }, |
564 | # define Rs_reserve(name,count) |
1122 | # define reserve(name,count) |
565 | # include "rsinc.h" |
1123 | # include "rsinc.h" |
566 | # undef Rs_def |
1124 | # undef def |
567 | # undef Rs_reserve |
1125 | # undef reserve |
568 | }; |
1126 | }; |
569 | |
1127 | |
570 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1128 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
571 | |
1129 | |
572 | do { |
1130 | do { |
… | |
… | |
594 | THIS->rs [index] = 0; |
1152 | THIS->rs [index] = 0; |
595 | } |
1153 | } |
596 | } |
1154 | } |
597 | |
1155 | |
598 | void |
1156 | void |
599 | rxvt_term::selection_mark (...) |
1157 | rxvt_term::cur (...) |
600 | PROTOTYPE: $;$$ |
1158 | PROTOTYPE: $;$$ |
601 | ALIAS: |
1159 | ALIAS: |
|
|
1160 | screen_cur = 0 |
602 | selection_beg = 1 |
1161 | selection_beg = 1 |
603 | selection_end = 2 |
1162 | selection_end = 2 |
|
|
1163 | selection_mark = 3 |
604 | PPCODE: |
1164 | PPCODE: |
605 | { |
1165 | { |
606 | row_col_t &sel = ix == 1 ? THIS->selection.beg |
1166 | row_col_t &rc = ix == 0 ? THIS->screen.cur |
|
|
1167 | : ix == 1 ? THIS->selection.beg |
607 | : ix == 2 ? THIS->selection.end |
1168 | : ix == 2 ? THIS->selection.end |
608 | : THIS->selection.mark; |
1169 | : THIS->selection.mark; |
609 | |
1170 | |
610 | if (GIMME_V != G_VOID) |
1171 | if (GIMME_V != G_VOID) |
611 | { |
1172 | { |
612 | EXTEND (SP, 2); |
1173 | EXTEND (SP, 2); |
613 | PUSHs (sv_2mortal (newSViv (sel.row))); |
1174 | PUSHs (sv_2mortal (newSViv (rc.row))); |
614 | PUSHs (sv_2mortal (newSViv (sel.col))); |
1175 | PUSHs (sv_2mortal (newSViv (rc.col))); |
615 | } |
1176 | } |
616 | |
1177 | |
617 | if (items == 3) |
1178 | if (items == 3) |
618 | { |
1179 | { |
619 | sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
1180 | rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
620 | sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
1181 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
621 | |
1182 | |
622 | if (ix) |
1183 | if (ix) |
623 | THIS->want_refresh = 1; |
1184 | THIS->want_refresh = 1; |
624 | } |
1185 | } |
625 | } |
1186 | } |
626 | |
1187 | |
627 | int |
1188 | int |
628 | rxvt_term::selection_grab (int eventtime) |
1189 | rxvt_term::selection_grab (U32 eventtime) |
629 | |
1190 | |
630 | void |
1191 | void |
631 | rxvt_term::selection (SV *newtext = 0) |
1192 | rxvt_term::selection (SV *newtext = 0) |
632 | PPCODE: |
1193 | PPCODE: |
633 | { |
1194 | { |
634 | if (GIMME_V != G_VOID) |
1195 | if (GIMME_V != G_VOID) |
635 | { |
1196 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
636 | char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); |
|
|
637 | SV *sv = newSVpv (sel, 0); |
|
|
638 | SvUTF8_on (sv); |
|
|
639 | free (sel); |
|
|
640 | XPUSHs (sv_2mortal (sv)); |
|
|
641 | } |
|
|
642 | |
1197 | |
643 | if (newtext) |
1198 | if (newtext) |
644 | { |
1199 | { |
645 | free (THIS->selection.text); |
1200 | free (THIS->selection.text); |
646 | |
1201 | |
647 | THIS->selection.text = sv2wcs (newtext); |
1202 | THIS->selection.text = sv2wcs (newtext); |
648 | THIS->selection.len = wcslen (THIS->selection.text); |
1203 | THIS->selection.len = wcslen (THIS->selection.text); |
649 | } |
1204 | } |
650 | } |
1205 | } |
651 | |
|
|
652 | void |
|
|
653 | rxvt_term::scr_overlay_new (int x, int y, int w, int h) |
|
|
654 | |
1206 | |
655 | void |
1207 | void |
656 | rxvt_term::scr_overlay_off () |
1208 | 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: |
1209 | 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 | { |
1210 | { |
667 | wchar_t *wtext = sv2wcs (text); |
1211 | wchar_t *wstr = sv2wcs (string); |
668 | THIS->scr_overlay_set (x, y, wtext); |
1212 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
669 | free (wtext); |
1213 | free (wstr); |
670 | } |
1214 | } |
671 | |
1215 | |
672 | void |
1216 | void |
673 | rxvt_term::tt_write (SV *octets) |
1217 | rxvt_term::tt_write (SV *octets) |
674 | INIT: |
1218 | INIT: |
675 | STRLEN len; |
1219 | STRLEN len; |
676 | char *str = SvPVbyte (octets, len); |
1220 | char *str = SvPVbyte (octets, len); |
677 | C_ARGS: |
1221 | C_ARGS: |
678 | (unsigned char *)str, len |
1222 | str, len |
|
|
1223 | |
|
|
1224 | void |
|
|
1225 | rxvt_term::cmd_parse (SV *octets) |
|
|
1226 | CODE: |
|
|
1227 | { |
|
|
1228 | STRLEN len; |
|
|
1229 | char *str = SvPVbyte (octets, len); |
|
|
1230 | |
|
|
1231 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1232 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1233 | |
|
|
1234 | THIS->cmdbuf_ptr = str; |
|
|
1235 | THIS->cmdbuf_endp = str + len; |
|
|
1236 | |
|
|
1237 | rxvt_push_locale (THIS->locale); |
|
|
1238 | THIS->cmd_parse (); |
|
|
1239 | rxvt_pop_locale (); |
|
|
1240 | |
|
|
1241 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1242 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1243 | } |
|
|
1244 | |
|
|
1245 | SV * |
|
|
1246 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
|
|
1247 | CODE: |
|
|
1248 | { |
|
|
1249 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
|
|
1250 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
|
|
1251 | o->self = (HV *)SvRV (RETVAL); |
|
|
1252 | } |
|
|
1253 | OUTPUT: |
|
|
1254 | RETVAL |
|
|
1255 | |
|
|
1256 | MODULE = urxvt PACKAGE = urxvt::overlay |
|
|
1257 | |
|
|
1258 | void |
|
|
1259 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
|
|
1260 | |
|
|
1261 | void |
|
|
1262 | overlay::show () |
|
|
1263 | |
|
|
1264 | void |
|
|
1265 | overlay::hide () |
|
|
1266 | |
|
|
1267 | void |
|
|
1268 | overlay::DESTROY () |
679 | |
1269 | |
680 | MODULE = urxvt PACKAGE = urxvt::timer |
1270 | MODULE = urxvt PACKAGE = urxvt::timer |
681 | |
1271 | |
682 | SV * |
1272 | SV * |
683 | timer::new () |
1273 | timer::new () |
684 | CODE: |
1274 | CODE: |
685 | timer *w = new timer; |
1275 | timer *w = new timer; |
|
|
1276 | w->start (NOW); |
686 | RETVAL = newSVptr ((void *)w, "urxvt::timer"); |
1277 | RETVAL = newSVptr ((void *)w, "urxvt::timer"); |
687 | w->self = (HV *)SvRV (RETVAL); |
1278 | w->self = (HV *)SvRV (RETVAL); |
688 | OUTPUT: |
1279 | OUTPUT: |
689 | RETVAL |
1280 | RETVAL |
690 | |
1281 | |
… | |
… | |
698 | |
1289 | |
699 | NV |
1290 | NV |
700 | timer::at () |
1291 | timer::at () |
701 | CODE: |
1292 | CODE: |
702 | RETVAL = THIS->at; |
1293 | RETVAL = THIS->at; |
|
|
1294 | OUTPUT: |
|
|
1295 | RETVAL |
|
|
1296 | |
|
|
1297 | timer * |
|
|
1298 | timer::interval (NV interval) |
|
|
1299 | CODE: |
|
|
1300 | THIS->interval = interval; |
|
|
1301 | RETVAL = THIS; |
703 | OUTPUT: |
1302 | OUTPUT: |
704 | RETVAL |
1303 | RETVAL |
705 | |
1304 | |
706 | timer * |
1305 | timer * |
707 | timer::set (NV tstamp) |
1306 | timer::set (NV tstamp) |