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 |
… | |
… | |
186 | rend_t **rend; |
208 | rend_t **rend; |
187 | |
209 | |
188 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
210 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
189 | ~overlay (); |
211 | ~overlay (); |
190 | |
212 | |
|
|
213 | void show (); |
|
|
214 | void hide (); |
|
|
215 | |
191 | void swap (); |
216 | void swap (); |
192 | |
217 | |
193 | void set (int x, int y, SV *str, SV *rend); |
218 | void set (int x, int y, SV *str, SV *rend); |
194 | }; |
219 | }; |
195 | |
220 | |
… | |
… | |
202 | h += 2; |
227 | h += 2; |
203 | } |
228 | } |
204 | |
229 | |
205 | text = new text_t *[h]; |
230 | text = new text_t *[h]; |
206 | rend = new rend_t *[h]; |
231 | rend = new rend_t *[h]; |
207 | |
232 | |
208 | for (int y = 0; y < h; y++) |
233 | for (int y = 0; y < h; y++) |
209 | { |
234 | { |
210 | text_t *tp = text[y] = new text_t[w]; |
235 | text_t *tp = text[y] = new text_t[w]; |
211 | rend_t *rp = rend[y] = new rend_t[w]; |
236 | rend_t *rp = rend[y] = new rend_t[w]; |
212 | |
237 | |
213 | text_t t0, t1, t2; |
238 | text_t t0, t1, t2; |
214 | rend_t r = rstyle; |
239 | rend_t r = rstyle; |
215 | |
240 | |
216 | if (border == 2) |
241 | if (border == 2) |
217 | { |
242 | { |
218 | if (y == 0) |
243 | if (y == 0) |
219 | t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
244 | t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
220 | else if (y < h - 1) |
245 | else if (y < h - 1) |
221 | t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
246 | t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
222 | else |
247 | else |
223 | t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
248 | t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
224 | |
249 | |
225 | *tp++ = t0; |
250 | *tp++ = t0; |
226 | *rp++ = r; |
251 | *rp++ = r; |
227 | |
252 | |
228 | for (int x = w - 2; x-- > 0; ) |
253 | for (int x = w - 2; x-- > 0; ) |
229 | { |
254 | { |
230 | *tp++ = t1; |
255 | *tp++ = t1; |
231 | *rp++ = r; |
256 | *rp++ = r; |
232 | } |
257 | } |
233 | |
258 | |
234 | *tp = t2; |
259 | *tp = t2; |
235 | *rp = r; |
260 | *rp = r; |
236 | } |
261 | } |
237 | else |
262 | else |
238 | for (int x = w; x-- > 0; ) |
263 | for (int x = w; x-- > 0; ) |
239 | { |
264 | { |
240 | *tp++ = 0x0020; |
265 | *tp++ = 0x0020; |
241 | *rp++ = r; |
266 | *rp++ = r; |
242 | } |
267 | } |
243 | } |
268 | } |
244 | |
269 | |
|
|
270 | show (); |
245 | THIS->want_refresh = 1; |
271 | THIS->want_refresh = 1; |
246 | } |
272 | } |
247 | |
273 | |
248 | overlay::~overlay () |
274 | overlay::~overlay () |
249 | { |
275 | { |
|
|
276 | hide (); |
|
|
277 | |
250 | for (int y = h; y--; ) |
278 | for (int y = h; y--; ) |
251 | { |
279 | { |
252 | delete [] text[y]; |
280 | delete [] text[y]; |
253 | delete [] rend[y]; |
281 | delete [] rend[y]; |
254 | } |
282 | } |
… | |
… | |
257 | delete [] rend; |
285 | delete [] rend; |
258 | |
286 | |
259 | THIS->want_refresh = 1; |
287 | THIS->want_refresh = 1; |
260 | } |
288 | } |
261 | |
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 | |
262 | void overlay::swap () |
313 | void overlay::swap () |
263 | { |
314 | { |
264 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
315 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
265 | int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); |
316 | int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); |
266 | |
317 | |
… | |
… | |
269 | |
320 | |
270 | for (int y = ov_h; y--; ) |
321 | for (int y = ov_h; y--; ) |
271 | { |
322 | { |
272 | text_t *t1 = text [y]; |
323 | text_t *t1 = text [y]; |
273 | rend_t *r1 = rend [y]; |
324 | rend_t *r1 = rend [y]; |
274 | |
325 | |
275 | text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
326 | text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; |
276 | rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
327 | rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; |
277 | |
328 | |
278 | for (int x = ov_w; x--; ) |
329 | for (int x = ov_w; x--; ) |
279 | { |
330 | { |
280 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
331 | text_t t = *t1; *t1++ = *t2; *t2++ = t; |
281 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
332 | rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); |
282 | } |
333 | } |
283 | } |
334 | } |
284 | |
335 | |
… | |
… | |
294 | |
345 | |
295 | wchar_t *wtext = sv2wcs (text); |
346 | wchar_t *wtext = sv2wcs (text); |
296 | |
347 | |
297 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
348 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
298 | this->text [y][x + col] = wtext [col]; |
349 | this->text [y][x + col] = wtext [col]; |
299 | |
350 | |
300 | free (wtext); |
351 | free (wtext); |
301 | |
352 | |
302 | if (rend) |
353 | if (rend) |
303 | { |
354 | { |
304 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
355 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
… | |
… | |
361 | bool |
412 | bool |
362 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
413 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
363 | { |
414 | { |
364 | if (!perl) |
415 | if (!perl) |
365 | return false; |
416 | return false; |
366 | |
417 | |
367 | if (htype == HOOK_INIT) // first hook ever called |
418 | if (htype == HOOK_INIT) // first hook ever called |
368 | { |
419 | { |
369 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
420 | term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term"); |
370 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
421 | hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
371 | } |
422 | } |
|
|
423 | else if (!term->perl.self) |
|
|
424 | return false; // perl not initialized for this instance |
372 | else if (htype == HOOK_DESTROY) |
425 | else if (htype == HOOK_DESTROY) |
373 | { |
426 | { |
374 | // handled later |
427 | // handled later |
375 | } |
428 | } |
376 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
429 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
377 | { |
430 | { |
378 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
431 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0)); |
379 | |
432 | |
380 | if (HvKEYS (hv)) |
433 | if (HvKEYS (hv)) |
381 | { |
434 | { |
382 | hv_iterinit (hv); |
435 | hv_iterinit (hv); |
383 | |
436 | |
… | |
… | |
412 | |
465 | |
413 | case DT_LONG: |
466 | case DT_LONG: |
414 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
467 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
415 | break; |
468 | break; |
416 | |
469 | |
417 | case DT_STRING: |
470 | case DT_STR: |
418 | 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 | } |
419 | break; |
542 | break; |
420 | |
543 | |
421 | case DT_END: |
544 | case DT_END: |
422 | { |
545 | { |
423 | va_end (ap); |
546 | va_end (ap); |
… | |
… | |
439 | if (SvTRUE (ERRSV)) |
562 | if (SvTRUE (ERRSV)) |
440 | 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)); |
441 | |
564 | |
442 | if (htype == HOOK_DESTROY) |
565 | if (htype == HOOK_DESTROY) |
443 | { |
566 | { |
444 | // TODO: clear magic |
|
|
445 | hv_clear ((HV *)SvRV ((SV *)term->self)); |
567 | clearSVptr ((SV *)term->perl.self); |
446 | SvREFCNT_dec ((SV *)term->self); |
568 | SvREFCNT_dec ((SV *)term->perl.self); |
447 | } |
569 | } |
448 | |
570 | |
449 | return count; |
571 | return count; |
450 | } |
572 | } |
451 | |
573 | |
… | |
… | |
461 | |
583 | |
462 | PROTOTYPES: ENABLE |
584 | PROTOTYPES: ENABLE |
463 | |
585 | |
464 | BOOT: |
586 | BOOT: |
465 | { |
587 | { |
466 | # define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0)) |
588 | HV *stash = gv_stashpv ("urxvt", 1); |
467 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), #name, newSViv (name)); |
589 | # define export_const_iv(name) newCONSTSUB (stash, # name, newSViv (name)); |
|
|
590 | |
468 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
591 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
469 | set_hookname (INIT); |
592 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
470 | set_hookname (RESET); |
593 | # include "hookinc.h" |
471 | set_hookname (START); |
594 | # undef def |
472 | set_hookname (DESTROY); |
|
|
473 | set_hookname (SEL_BEGIN); |
|
|
474 | set_hookname (SEL_EXTEND); |
|
|
475 | set_hookname (SEL_MAKE); |
|
|
476 | set_hookname (SEL_GRAB); |
|
|
477 | set_hookname (SEL_CLICK); |
|
|
478 | set_hookname (FOCUS_IN); |
|
|
479 | set_hookname (FOCUS_OUT); |
|
|
480 | set_hookname (VIEW_CHANGE); |
|
|
481 | set_hookname (SCROLL_BACK); |
|
|
482 | set_hookname (TTY_ACTIVITY); |
|
|
483 | set_hookname (REFRESH_BEGIN); |
|
|
484 | set_hookname (REFRESH_END); |
|
|
485 | set_hookname (KEYBOARD_COMMAND); |
|
|
486 | set_hookname (MOUSE_CLICK); |
|
|
487 | set_hookname (MOUSE_MOVE); |
|
|
488 | |
595 | |
|
|
596 | |
489 | export_const (DEFAULT_RSTYLE); |
597 | export_const_iv (DEFAULT_RSTYLE); |
490 | export_const (OVERLAY_RSTYLE); |
598 | export_const_iv (OVERLAY_RSTYLE); |
491 | export_const (RS_Bold); |
599 | export_const_iv (RS_Bold); |
492 | export_const (RS_Italic); |
600 | export_const_iv (RS_Italic); |
493 | export_const (RS_Blink); |
601 | export_const_iv (RS_Blink); |
494 | export_const (RS_RVid); |
602 | export_const_iv (RS_RVid); |
495 | export_const (RS_Uline); |
603 | export_const_iv (RS_Uline); |
|
|
604 | export_const_iv (CurrentTime); |
496 | |
605 | |
497 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
606 | sv_setsv (get_sv ("urxvt::LIBDIR", 1), newSVpvn (LIBDIR, sizeof (LIBDIR) - 1)); |
498 | } |
607 | } |
|
|
608 | |
|
|
609 | SV * |
|
|
610 | new (...) |
|
|
611 | CODE: |
|
|
612 | { |
|
|
613 | stringvec *argv = new stringvec; |
|
|
614 | bool success; |
|
|
615 | |
|
|
616 | for (int i = 0; i < items ;i++) |
|
|
617 | argv->push_back (strdup (SvPVbyte_nolen (ST (i)))); |
|
|
618 | |
|
|
619 | rxvt_term *term = new rxvt_term; |
|
|
620 | |
|
|
621 | term->argv = argv; |
|
|
622 | |
|
|
623 | try |
|
|
624 | { |
|
|
625 | if (!term->init (argv->size (), argv->begin ())) |
|
|
626 | term = 0; |
|
|
627 | } |
|
|
628 | catch (const class rxvt_failure_exception &e) |
|
|
629 | { |
|
|
630 | term->destroy (); |
|
|
631 | croak ("exception caught while initializing new terminal instance"); |
|
|
632 | } |
|
|
633 | |
|
|
634 | RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef; |
|
|
635 | } |
|
|
636 | OUTPUT: |
|
|
637 | RETVAL |
499 | |
638 | |
500 | void |
639 | void |
501 | set_should_invoke (int htype, int value) |
640 | set_should_invoke (int htype, int value) |
502 | CODE: |
641 | CODE: |
503 | rxvt_perl.should_invoke [htype] = value; |
642 | rxvt_perl.should_invoke [htype] = value; |
… | |
… | |
566 | } |
705 | } |
567 | OUTPUT: |
706 | OUTPUT: |
568 | RETVAL |
707 | RETVAL |
569 | |
708 | |
570 | MODULE = urxvt PACKAGE = urxvt::term |
709 | MODULE = urxvt PACKAGE = urxvt::term |
|
|
710 | |
|
|
711 | void |
|
|
712 | rxvt_term::destroy () |
|
|
713 | |
|
|
714 | void |
|
|
715 | rxvt_term::grab_button (int button, U32 modifiers) |
|
|
716 | CODE: |
|
|
717 | XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1, |
|
|
718 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
719 | GrabModeSync, GrabModeSync, None, None); |
|
|
720 | |
|
|
721 | bool |
|
|
722 | rxvt_term::grab (U32 eventtime, int sync = 0) |
|
|
723 | CODE: |
|
|
724 | { |
|
|
725 | int mode = sync ? GrabModeSync : GrabModeAsync; |
|
|
726 | |
|
|
727 | THIS->perl.grabtime = 0; |
|
|
728 | |
|
|
729 | if (!XGrabPointer (THIS->display->display, THIS->vt, 0, |
|
|
730 | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, |
|
|
731 | mode, mode, None, None, eventtime)) |
|
|
732 | if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime)) |
|
|
733 | THIS->perl.grabtime = eventtime; |
|
|
734 | else |
|
|
735 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
736 | |
|
|
737 | RETVAL = !!THIS->perl.grabtime; |
|
|
738 | } |
|
|
739 | OUTPUT: |
|
|
740 | RETVAL |
|
|
741 | |
|
|
742 | void |
|
|
743 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
|
|
744 | CODE: |
|
|
745 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
|
|
746 | |
|
|
747 | void |
|
|
748 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
|
|
749 | CODE: |
|
|
750 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
|
|
751 | |
|
|
752 | void |
|
|
753 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
|
|
754 | CODE: |
|
|
755 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
|
|
756 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
|
|
757 | |
|
|
758 | void |
|
|
759 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
|
|
760 | CODE: |
|
|
761 | THIS->perl.grabtime = 0; |
|
|
762 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
763 | XUngrabPointer (THIS->display->display, eventtime); |
571 | |
764 | |
572 | int |
765 | int |
573 | rxvt_term::strwidth (SV *str) |
766 | rxvt_term::strwidth (SV *str) |
574 | CODE: |
767 | CODE: |
575 | { |
768 | { |
… | |
… | |
611 | |
804 | |
612 | rxvt_push_locale (THIS->locale); |
805 | rxvt_push_locale (THIS->locale); |
613 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
806 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
614 | rxvt_pop_locale (); |
807 | rxvt_pop_locale (); |
615 | |
808 | |
616 | char *str = rxvt_wcstoutf8 (wstr); |
809 | RETVAL = wcs2sv (wstr); |
617 | free (wstr); |
810 | free (wstr); |
618 | |
|
|
619 | RETVAL = newSVpv (str, 0); |
|
|
620 | SvUTF8_on (RETVAL); |
|
|
621 | free (str); |
|
|
622 | } |
811 | } |
623 | OUTPUT: |
812 | OUTPUT: |
624 | RETVAL |
813 | RETVAL |
625 | |
814 | |
|
|
815 | # very portable, especially on objects as opposed to pods |
|
|
816 | #define TERM_OFFSET(sym) (((char *)&((TermWin_t *)0)->sym) - (char *)(TermWin_t *)0) |
|
|
817 | |
|
|
818 | #define TERM_OFFSET_width TERM_OFFSET(width) |
|
|
819 | #define TERM_OFFSET_height TERM_OFFSET(height) |
|
|
820 | #define TERM_OFFSET_fwidth TERM_OFFSET(fwidth) |
|
|
821 | #define TERM_OFFSET_fheight TERM_OFFSET(fheight) |
|
|
822 | #define TERM_OFFSET_fbase TERM_OFFSET(fbase) |
|
|
823 | #define TERM_OFFSET_nrow TERM_OFFSET(nrow) |
|
|
824 | #define TERM_OFFSET_ncol TERM_OFFSET(ncol) |
|
|
825 | #define TERM_OFFSET_focus TERM_OFFSET(focus) |
|
|
826 | #define TERM_OFFSET_mapped TERM_OFFSET(mapped) |
|
|
827 | #define TERM_OFFSET_saveLines TERM_OFFSET(saveLines) |
|
|
828 | #define TERM_OFFSET_total_rows TERM_OFFSET(total_rows) |
|
|
829 | #define TERM_OFFSET_nsaved TERM_OFFSET(nsaved) |
|
|
830 | |
626 | int |
831 | int |
|
|
832 | rxvt_term::width () |
|
|
833 | ALIAS: |
|
|
834 | width = TERM_OFFSET_width |
|
|
835 | height = TERM_OFFSET_height |
|
|
836 | fwidth = TERM_OFFSET_fwidth |
|
|
837 | fheight = TERM_OFFSET_fheight |
|
|
838 | fbase = TERM_OFFSET_fbase |
|
|
839 | nrow = TERM_OFFSET_nrow |
|
|
840 | ncol = TERM_OFFSET_ncol |
|
|
841 | focus = TERM_OFFSET_focus |
|
|
842 | mapped = TERM_OFFSET_mapped |
|
|
843 | saveLines = TERM_OFFSET_saveLines |
|
|
844 | total_rows = TERM_OFFSET_total_rows |
|
|
845 | nsaved = TERM_OFFSET_nsaved |
|
|
846 | CODE: |
|
|
847 | RETVAL = *(int *)((char *)THIS + ix); |
|
|
848 | OUTPUT: |
|
|
849 | RETVAL |
|
|
850 | |
|
|
851 | U32 |
|
|
852 | rxvt_term::parent () |
|
|
853 | CODE: |
|
|
854 | RETVAL = (U32)THIS->parent [0]; |
|
|
855 | OUTPUT: |
|
|
856 | RETVAL |
|
|
857 | |
|
|
858 | U32 |
627 | rxvt_term::nsaved () |
859 | rxvt_term::vt () |
628 | CODE: |
860 | CODE: |
|
|
861 | RETVAL = (U32)THIS->vt; |
|
|
862 | OUTPUT: |
|
|
863 | RETVAL |
|
|
864 | |
|
|
865 | U32 |
|
|
866 | rxvt_term::rstyle (U32 new_rstyle = THIS->rstyle) |
|
|
867 | CODE: |
|
|
868 | { |
629 | RETVAL = THIS->nsaved; |
869 | RETVAL = THIS->rstyle; |
|
|
870 | THIS->rstyle = new_rstyle; |
|
|
871 | } |
630 | OUTPUT: |
872 | OUTPUT: |
631 | RETVAL |
873 | RETVAL |
632 | |
874 | |
633 | int |
875 | int |
634 | rxvt_term::view_start (int newval = -1) |
876 | rxvt_term::view_start (int newval = -1) |
635 | CODE: |
877 | CODE: |
636 | { |
878 | { |
… | |
… | |
643 | } |
885 | } |
644 | } |
886 | } |
645 | OUTPUT: |
887 | OUTPUT: |
646 | RETVAL |
888 | RETVAL |
647 | |
889 | |
648 | int |
|
|
649 | rxvt_term::nrow () |
|
|
650 | CODE: |
|
|
651 | RETVAL = THIS->nrow; |
|
|
652 | OUTPUT: |
|
|
653 | RETVAL |
|
|
654 | |
|
|
655 | int |
|
|
656 | rxvt_term::ncol () |
|
|
657 | CODE: |
|
|
658 | RETVAL = THIS->ncol; |
|
|
659 | OUTPUT: |
|
|
660 | RETVAL |
|
|
661 | |
|
|
662 | void |
890 | void |
663 | rxvt_term::want_refresh () |
891 | rxvt_term::want_refresh () |
664 | CODE: |
892 | CODE: |
665 | THIS->want_refresh = 1; |
893 | THIS->want_refresh = 1; |
666 | |
894 | |
667 | void |
895 | void |
668 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
896 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
669 | PPCODE: |
897 | PPCODE: |
670 | { |
898 | { |
671 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
899 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
672 | croak ("row_number number of out range"); |
900 | XSRETURN_EMPTY; |
673 | |
901 | |
674 | line_t &l = ROW(row_number); |
902 | line_t &l = ROW(row_number); |
675 | |
903 | |
676 | if (GIMME_V != G_VOID) |
904 | if (GIMME_V != G_VOID) |
677 | { |
905 | { |
678 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
906 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
679 | |
907 | |
680 | for (int col = 0; col <THIS->ncol; col++) |
908 | for (int col = 0; col < THIS->ncol; col++) |
681 | wstr [col] = l.t [col]; |
909 | wstr [col] = l.t [col]; |
682 | |
910 | |
683 | char *str = rxvt_wcstoutf8 (wstr, THIS->ncol); |
|
|
684 | free (wstr); |
|
|
685 | |
|
|
686 | SV *sv = newSVpv (str, 0); |
|
|
687 | SvUTF8_on (sv); |
|
|
688 | XPUSHs (sv_2mortal (sv)); |
911 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
689 | free (str); |
912 | |
|
|
913 | delete [] wstr; |
690 | } |
914 | } |
691 | |
915 | |
692 | if (new_text) |
916 | if (new_text) |
693 | { |
917 | { |
694 | wchar_t *wstr = sv2wcs (new_text); |
918 | wchar_t *wstr = sv2wcs (new_text); |
695 | |
919 | |
696 | int len = wcslen (wstr); |
920 | int len = min (wcslen (wstr) - start_ofs, max_len); |
697 | |
921 | |
698 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
922 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
699 | { |
923 | { |
700 | free (wstr); |
924 | free (wstr); |
701 | croak ("new_text extends beyond horizontal margins"); |
925 | croak ("new_text extends beyond horizontal margins"); |
702 | } |
926 | } |
703 | |
927 | |
704 | for (int col = start_col; col < start_col + len; col++) |
928 | for (int col = start_col; col < start_col + len; col++) |
705 | { |
929 | { |
706 | l.t [col] = wstr [col - start_col]; |
930 | l.t [col] = wstr [start_ofs + col - start_col]; |
707 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
931 | l.r [col] = SET_FONT (l.r [col], THIS->fontset [GET_STYLE (l.r [col])]->find_font (l.t [col])); |
708 | } |
932 | } |
709 | |
933 | |
710 | free (wstr); |
934 | free (wstr); |
711 | } |
935 | } |
712 | } |
936 | } |
713 | |
937 | |
714 | void |
938 | void |
715 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
939 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0, int start_ofs = 0, int max_len = MAX_COLS) |
716 | PPCODE: |
940 | PPCODE: |
717 | { |
941 | { |
718 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
942 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
719 | croak ("row_number number of out range"); |
943 | XSRETURN_EMPTY; |
720 | |
944 | |
721 | line_t &l = ROW(row_number); |
945 | line_t &l = ROW(row_number); |
722 | |
946 | |
723 | if (GIMME_V != G_VOID) |
947 | if (GIMME_V != G_VOID) |
724 | { |
948 | { |
… | |
… | |
735 | { |
959 | { |
736 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
960 | if (!SvROK (new_rend) || SvTYPE (SvRV (new_rend)) != SVt_PVAV) |
737 | croak ("new_rend must be arrayref"); |
961 | croak ("new_rend must be arrayref"); |
738 | |
962 | |
739 | AV *av = (AV *)SvRV (new_rend); |
963 | AV *av = (AV *)SvRV (new_rend); |
740 | int len = av_len (av) + 1; |
964 | int len = min (av_len (av) + 1 - start_ofs, max_len); |
741 | |
965 | |
742 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
966 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
743 | croak ("new_rend array extends beyond horizontal margins"); |
967 | croak ("new_rend array extends beyond horizontal margins"); |
744 | |
968 | |
745 | for (int col = start_col; col < start_col + len; col++) |
969 | for (int col = start_col; col < start_col + len; col++) |
746 | { |
970 | { |
747 | rend_t r = SvIV (*av_fetch (av, col - start_col, 1)) & ~RS_fontMask; |
971 | rend_t r = SvIV (*av_fetch (av, start_ofs + col - start_col, 1)) & ~RS_fontMask; |
748 | |
972 | |
749 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
973 | l.r [col] = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (l.t [col])); |
750 | } |
974 | } |
751 | } |
975 | } |
752 | } |
976 | } |
753 | |
977 | |
754 | int |
978 | int |
755 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
979 | rxvt_term::ROW_l (int row_number, int new_length = -1) |
756 | CODE: |
980 | CODE: |
757 | { |
981 | { |
758 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
982 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
759 | croak ("row_number number of out range"); |
983 | XSRETURN_EMPTY; |
760 | |
984 | |
761 | line_t &l = ROW(row_number); |
985 | line_t &l = ROW(row_number); |
762 | RETVAL = l.l; |
986 | RETVAL = l.l; |
763 | |
987 | |
764 | if (new_length >= -1) |
988 | if (new_length >= 0) |
765 | l.l = new_length; |
989 | l.l = new_length; |
766 | } |
990 | } |
767 | OUTPUT: |
991 | OUTPUT: |
768 | RETVAL |
992 | RETVAL |
769 | |
993 | |
|
|
994 | bool |
|
|
995 | rxvt_term::ROW_is_longer (int row_number, int new_is_longer = -1) |
|
|
996 | CODE: |
|
|
997 | { |
|
|
998 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
|
|
999 | XSRETURN_EMPTY; |
|
|
1000 | |
|
|
1001 | line_t &l = ROW(row_number); |
|
|
1002 | RETVAL = l.is_longer (); |
|
|
1003 | |
|
|
1004 | if (new_is_longer >= 0) |
|
|
1005 | l.is_longer (new_is_longer); |
|
|
1006 | } |
|
|
1007 | OUTPUT: |
|
|
1008 | RETVAL |
|
|
1009 | |
770 | SV * |
1010 | SV * |
771 | rxvt_term::special_encode (SV *str) |
1011 | rxvt_term::special_encode (SV *string) |
772 | CODE: |
1012 | CODE: |
773 | abort ();//TODO |
1013 | { |
|
|
1014 | wchar_t *wstr = sv2wcs (string); |
|
|
1015 | int wlen = wcslen (wstr); |
|
|
1016 | wchar_t *rstr = new wchar_t [wlen]; // cannot become longer |
|
|
1017 | |
|
|
1018 | rxvt_push_locale (THIS->locale); |
|
|
1019 | |
|
|
1020 | wchar_t *r = rstr; |
|
|
1021 | for (wchar_t *s = wstr; *s; s++) |
|
|
1022 | if (wcwidth (*s) == 0) |
|
|
1023 | { |
|
|
1024 | if (r == rstr) |
|
|
1025 | croak ("leading combining character unencodable"); |
|
|
1026 | |
|
|
1027 | unicode_t n = rxvt_compose (r[-1], *s); |
|
|
1028 | if (n == NOCHAR) |
|
|
1029 | n = rxvt_composite.compose (r[-1], *s); |
|
|
1030 | |
|
|
1031 | r[-1] = n; |
|
|
1032 | } |
|
|
1033 | #if !UNICODE_3 |
|
|
1034 | else if (*s >= 0x10000) |
|
|
1035 | *r++ = rxvt_composite.compose (*s); |
|
|
1036 | #endif |
|
|
1037 | else |
|
|
1038 | *r++ = *s; |
|
|
1039 | |
|
|
1040 | rxvt_pop_locale (); |
|
|
1041 | |
|
|
1042 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1043 | |
|
|
1044 | delete [] rstr; |
|
|
1045 | } |
|
|
1046 | OUTPUT: |
|
|
1047 | RETVAL |
774 | |
1048 | |
775 | SV * |
1049 | SV * |
776 | rxvt_term::special_decode (SV *str) |
1050 | rxvt_term::special_decode (SV *text) |
777 | CODE: |
1051 | CODE: |
778 | abort ();//TODO |
1052 | { |
|
|
1053 | wchar_t *wstr = sv2wcs (text); |
|
|
1054 | int wlen = wcslen (wstr); |
|
|
1055 | int dlen = 0; |
|
|
1056 | |
|
|
1057 | // find length |
|
|
1058 | for (wchar_t *s = wstr; *s; s++) |
|
|
1059 | if (*s == NOCHAR) |
|
|
1060 | ; |
|
|
1061 | else if (IS_COMPOSE (*s)) |
|
|
1062 | dlen += rxvt_composite.expand (*s, 0); |
|
|
1063 | else |
|
|
1064 | dlen++; |
|
|
1065 | |
|
|
1066 | wchar_t *rstr = new wchar_t [dlen]; |
|
|
1067 | |
|
|
1068 | // decode |
|
|
1069 | wchar_t *r = rstr; |
|
|
1070 | for (wchar_t *s = wstr; *s; s++) |
|
|
1071 | if (*s == NOCHAR) |
|
|
1072 | ; |
|
|
1073 | else if (IS_COMPOSE (*s)) |
|
|
1074 | r += rxvt_composite.expand (*s, r); |
|
|
1075 | else |
|
|
1076 | *r++ = *s; |
|
|
1077 | |
|
|
1078 | RETVAL = wcs2sv (rstr, r - rstr); |
|
|
1079 | |
|
|
1080 | delete [] rstr; |
|
|
1081 | } |
|
|
1082 | OUTPUT: |
|
|
1083 | RETVAL |
779 | |
1084 | |
780 | void |
1085 | void |
781 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
1086 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
782 | PPCODE: |
1087 | PPCODE: |
783 | { |
1088 | { |
784 | struct resval { const char *name; int value; } rslist [] = { |
1089 | struct resval { const char *name; int value; } rslist [] = { |
785 | # define Rs_def(name) { # name, Rs_ ## name }, |
1090 | # define def(name) { # name, Rs_ ## name }, |
786 | # define Rs_reserve(name,count) |
1091 | # define reserve(name,count) |
787 | # include "rsinc.h" |
1092 | # include "rsinc.h" |
788 | # undef Rs_def |
1093 | # undef def |
789 | # undef Rs_reserve |
1094 | # undef reserve |
790 | }; |
1095 | }; |
791 | |
1096 | |
792 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
1097 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
793 | |
1098 | |
794 | do { |
1099 | do { |
… | |
… | |
816 | THIS->rs [index] = 0; |
1121 | THIS->rs [index] = 0; |
817 | } |
1122 | } |
818 | } |
1123 | } |
819 | |
1124 | |
820 | void |
1125 | void |
821 | rxvt_term::selection_mark (...) |
1126 | rxvt_term::cur (...) |
822 | PROTOTYPE: $;$$ |
1127 | PROTOTYPE: $;$$ |
823 | ALIAS: |
1128 | ALIAS: |
|
|
1129 | screen_cur = 0 |
824 | selection_beg = 1 |
1130 | selection_beg = 1 |
825 | selection_end = 2 |
1131 | selection_end = 2 |
|
|
1132 | selection_mark = 3 |
826 | PPCODE: |
1133 | PPCODE: |
827 | { |
1134 | { |
828 | row_col_t &sel = ix == 1 ? THIS->selection.beg |
1135 | row_col_t &rc = ix == 0 ? THIS->screen.cur |
|
|
1136 | : ix == 1 ? THIS->selection.beg |
829 | : ix == 2 ? THIS->selection.end |
1137 | : ix == 2 ? THIS->selection.end |
830 | : THIS->selection.mark; |
1138 | : THIS->selection.mark; |
831 | |
1139 | |
832 | if (GIMME_V != G_VOID) |
1140 | if (GIMME_V != G_VOID) |
833 | { |
1141 | { |
834 | EXTEND (SP, 2); |
1142 | EXTEND (SP, 2); |
835 | PUSHs (sv_2mortal (newSViv (sel.row))); |
1143 | PUSHs (sv_2mortal (newSViv (rc.row))); |
836 | PUSHs (sv_2mortal (newSViv (sel.col))); |
1144 | PUSHs (sv_2mortal (newSViv (rc.col))); |
837 | } |
1145 | } |
838 | |
1146 | |
839 | if (items == 3) |
1147 | if (items == 3) |
840 | { |
1148 | { |
841 | sel.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
1149 | rc.row = clamp (SvIV (ST (1)), -THIS->nsaved, THIS->nrow - 1); |
842 | sel.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
1150 | rc.col = clamp (SvIV (ST (2)), 0, THIS->ncol - 1); |
843 | |
1151 | |
844 | if (ix) |
1152 | if (ix) |
845 | THIS->want_refresh = 1; |
1153 | THIS->want_refresh = 1; |
846 | } |
1154 | } |
847 | } |
1155 | } |
848 | |
1156 | |
849 | int |
1157 | int |
850 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
1158 | rxvt_term::selection_grab (U32 eventtime) |
851 | |
1159 | |
852 | void |
1160 | void |
853 | rxvt_term::selection (SV *newtext = 0) |
1161 | rxvt_term::selection (SV *newtext = 0) |
854 | PPCODE: |
1162 | PPCODE: |
855 | { |
1163 | { |
856 | if (GIMME_V != G_VOID) |
1164 | if (GIMME_V != G_VOID) |
857 | { |
1165 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
858 | char *sel = rxvt_wcstoutf8 (THIS->selection.text, THIS->selection.len); |
|
|
859 | SV *sv = newSVpv (sel, 0); |
|
|
860 | SvUTF8_on (sv); |
|
|
861 | free (sel); |
|
|
862 | XPUSHs (sv_2mortal (sv)); |
|
|
863 | } |
|
|
864 | |
1166 | |
865 | if (newtext) |
1167 | if (newtext) |
866 | { |
1168 | { |
867 | free (THIS->selection.text); |
1169 | free (THIS->selection.text); |
868 | |
1170 | |
869 | THIS->selection.text = sv2wcs (newtext); |
1171 | THIS->selection.text = sv2wcs (newtext); |
870 | THIS->selection.len = wcslen (THIS->selection.text); |
1172 | THIS->selection.len = wcslen (THIS->selection.text); |
871 | } |
1173 | } |
872 | } |
1174 | } |
873 | |
1175 | |
|
|
1176 | void |
|
|
1177 | rxvt_term::scr_add_lines (SV *string) |
|
|
1178 | CODE: |
|
|
1179 | { |
|
|
1180 | wchar_t *wstr = sv2wcs (string); |
|
|
1181 | THIS->scr_add_lines (wstr, wcslen (wstr)); |
|
|
1182 | free (wstr); |
|
|
1183 | } |
|
|
1184 | |
874 | void |
1185 | void |
875 | rxvt_term::tt_write (SV *octets) |
1186 | rxvt_term::tt_write (SV *octets) |
876 | INIT: |
1187 | INIT: |
877 | STRLEN len; |
1188 | STRLEN len; |
878 | char *str = SvPVbyte (octets, len); |
1189 | char *str = SvPVbyte (octets, len); |
879 | C_ARGS: |
1190 | C_ARGS: |
880 | (unsigned char *)str, len |
1191 | str, len |
|
|
1192 | |
|
|
1193 | void |
|
|
1194 | rxvt_term::cmd_parse (SV *octets) |
|
|
1195 | CODE: |
|
|
1196 | { |
|
|
1197 | STRLEN len; |
|
|
1198 | char *str = SvPVbyte (octets, len); |
|
|
1199 | |
|
|
1200 | char *old_cmdbuf_ptr = THIS->cmdbuf_ptr; |
|
|
1201 | char *old_cmdbuf_endp = THIS->cmdbuf_endp; |
|
|
1202 | |
|
|
1203 | THIS->cmdbuf_ptr = str; |
|
|
1204 | THIS->cmdbuf_endp = str + len; |
|
|
1205 | |
|
|
1206 | rxvt_push_locale (THIS->locale); |
|
|
1207 | THIS->cmd_parse (); |
|
|
1208 | rxvt_pop_locale (); |
|
|
1209 | |
|
|
1210 | THIS->cmdbuf_ptr = old_cmdbuf_ptr; |
|
|
1211 | THIS->cmdbuf_endp = old_cmdbuf_endp; |
|
|
1212 | } |
881 | |
1213 | |
882 | SV * |
1214 | SV * |
883 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
1215 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
884 | CODE: |
1216 | CODE: |
885 | { |
1217 | { |
886 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
1218 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
887 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
1219 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
888 | o->self = (HV *)SvRV (RETVAL); |
1220 | o->self = (HV *)SvRV (RETVAL); |
889 | |
|
|
890 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
|
|
891 | char key[33]; sprintf (key, "%32lx", (long)o); |
|
|
892 | hv_store (hv, key, 32, newSViv ((long)o), 0); |
|
|
893 | } |
1221 | } |
894 | OUTPUT: |
1222 | OUTPUT: |
895 | RETVAL |
1223 | RETVAL |
896 | |
1224 | |
897 | MODULE = urxvt PACKAGE = urxvt::overlay |
1225 | MODULE = urxvt PACKAGE = urxvt::overlay |
898 | |
1226 | |
899 | void |
1227 | void |
900 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
1228 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
901 | |
1229 | |
902 | void |
1230 | void |
|
|
1231 | overlay::show () |
|
|
1232 | |
|
|
1233 | void |
|
|
1234 | overlay::hide () |
|
|
1235 | |
|
|
1236 | void |
903 | overlay::DESTROY () |
1237 | overlay::DESTROY () |
904 | CODE: |
|
|
905 | { |
|
|
906 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->THIS->self), "_overlay", 8, 0); |
|
|
907 | if (ovs) |
|
|
908 | { |
|
|
909 | HV *hv = (HV *)SvRV (*ovs); |
|
|
910 | char key[33]; sprintf (key, "%32lx", (long)THIS); |
|
|
911 | hv_delete (hv, key, 32, G_DISCARD); |
|
|
912 | } |
|
|
913 | |
|
|
914 | delete THIS; |
|
|
915 | } |
|
|
916 | |
1238 | |
917 | MODULE = urxvt PACKAGE = urxvt::timer |
1239 | MODULE = urxvt PACKAGE = urxvt::timer |
918 | |
1240 | |
919 | SV * |
1241 | SV * |
920 | timer::new () |
1242 | timer::new () |