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