… | |
… | |
139 | #define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") |
139 | #define newSVtimer(timer) new_ref (timer->self, "urxvt::timer") |
140 | #define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") |
140 | #define SvTIMER(sv) (timer *)SvPTR (sv, "urxvt::timer") |
141 | |
141 | |
142 | struct timer : time_watcher, perl_watcher |
142 | struct timer : time_watcher, perl_watcher |
143 | { |
143 | { |
|
|
144 | tstamp interval; |
|
|
145 | |
144 | timer () |
146 | timer () |
145 | : time_watcher (this, &timer::execute) |
147 | : time_watcher (this, &timer::execute) |
146 | { |
148 | { |
147 | } |
149 | } |
148 | |
150 | |
149 | void execute (time_watcher &w) |
151 | void execute (time_watcher &w) |
150 | { |
152 | { |
|
|
153 | if (interval) |
|
|
154 | start (at + interval); |
|
|
155 | |
151 | invoke ("urxvt::timer", newSVtimer (this)); |
156 | invoke ("urxvt::timer", newSVtimer (this)); |
152 | } |
157 | } |
153 | }; |
158 | }; |
154 | |
159 | |
155 | #define newSViow(iow) new_ref (iow->self, "urxvt::iow") |
160 | #define newSViow(iow) new_ref (iow->self, "urxvt::iow") |
… | |
… | |
165 | void execute (io_watcher &w, short revents) |
170 | void execute (io_watcher &w, short revents) |
166 | { |
171 | { |
167 | invoke ("urxvt::iow", newSViow (this), revents); |
172 | invoke ("urxvt::iow", newSViow (this), revents); |
168 | } |
173 | } |
169 | }; |
174 | }; |
|
|
175 | |
|
|
176 | ///////////////////////////////////////////////////////////////////////////// |
|
|
177 | |
|
|
178 | #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") |
|
|
179 | |
|
|
180 | struct overlay { |
|
|
181 | HV *self; |
|
|
182 | rxvt_term *THIS; |
|
|
183 | int x, y, w, h; |
|
|
184 | int border; |
|
|
185 | text_t **text; |
|
|
186 | rend_t **rend; |
|
|
187 | |
|
|
188 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
|
|
189 | ~overlay (); |
|
|
190 | |
|
|
191 | void swap (); |
|
|
192 | |
|
|
193 | void set (int x, int y, SV *str, SV *rend); |
|
|
194 | }; |
|
|
195 | |
|
|
196 | overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) |
|
|
197 | : THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2) |
|
|
198 | { |
|
|
199 | if (border == 2) |
|
|
200 | { |
|
|
201 | w += 2; |
|
|
202 | h += 2; |
|
|
203 | } |
|
|
204 | |
|
|
205 | text = new text_t *[h]; |
|
|
206 | rend = new rend_t *[h]; |
|
|
207 | |
|
|
208 | for (int y = 0; y < h; y++) |
|
|
209 | { |
|
|
210 | text_t *tp = text[y] = new text_t[w]; |
|
|
211 | rend_t *rp = rend[y] = new rend_t[w]; |
|
|
212 | |
|
|
213 | text_t t0, t1, t2; |
|
|
214 | rend_t r = rstyle; |
|
|
215 | |
|
|
216 | if (border == 2) |
|
|
217 | { |
|
|
218 | if (y == 0) |
|
|
219 | t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; |
|
|
220 | else if (y < h - 1) |
|
|
221 | t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; |
|
|
222 | else |
|
|
223 | t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; |
|
|
224 | |
|
|
225 | *tp++ = t0; |
|
|
226 | *rp++ = r; |
|
|
227 | |
|
|
228 | for (int x = w - 2; x-- > 0; ) |
|
|
229 | { |
|
|
230 | *tp++ = t1; |
|
|
231 | *rp++ = r; |
|
|
232 | } |
|
|
233 | |
|
|
234 | *tp = t2; |
|
|
235 | *rp = r; |
|
|
236 | } |
|
|
237 | else |
|
|
238 | for (int x = w; x-- > 0; ) |
|
|
239 | { |
|
|
240 | *tp++ = 0x0020; |
|
|
241 | *rp++ = r; |
|
|
242 | } |
|
|
243 | } |
|
|
244 | |
|
|
245 | THIS->want_refresh = 1; |
|
|
246 | } |
|
|
247 | |
|
|
248 | overlay::~overlay () |
|
|
249 | { |
|
|
250 | for (int y = h; y--; ) |
|
|
251 | { |
|
|
252 | delete [] text[y]; |
|
|
253 | delete [] rend[y]; |
|
|
254 | } |
|
|
255 | |
|
|
256 | delete [] text; |
|
|
257 | delete [] rend; |
|
|
258 | |
|
|
259 | THIS->want_refresh = 1; |
|
|
260 | } |
|
|
261 | |
|
|
262 | void overlay::swap () |
|
|
263 | { |
|
|
264 | 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)); |
|
|
266 | |
|
|
267 | int ov_w = min (w, THIS->ncol - ov_x); |
|
|
268 | int ov_h = min (h, THIS->nrow - ov_y); |
|
|
269 | |
|
|
270 | for (int y = ov_h; y--; ) |
|
|
271 | { |
|
|
272 | text_t *t1 = text [y]; |
|
|
273 | rend_t *r1 = rend [y]; |
|
|
274 | |
|
|
275 | 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; |
|
|
277 | |
|
|
278 | for (int x = ov_w; x--; ) |
|
|
279 | { |
|
|
280 | 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)); |
|
|
282 | } |
|
|
283 | } |
|
|
284 | |
|
|
285 | } |
|
|
286 | |
|
|
287 | void overlay::set (int x, int y, SV *str, SV *rend) |
|
|
288 | { |
|
|
289 | x += border; |
|
|
290 | y += border; |
|
|
291 | |
|
|
292 | if (!IN_RANGE_EXC (y, 0, h - border)) |
|
|
293 | return; |
|
|
294 | |
|
|
295 | wchar_t *wstr = sv2wcs (str); |
|
|
296 | |
|
|
297 | for (int col = min (wcslen (wstr), w - x - border); col--; ) |
|
|
298 | text [y][x + col] = wstr [col]; |
|
|
299 | |
|
|
300 | free (wstr); |
|
|
301 | |
|
|
302 | THIS->want_refresh = 1; |
|
|
303 | } |
|
|
304 | |
170 | |
305 | |
171 | ///////////////////////////////////////////////////////////////////////////// |
306 | ///////////////////////////////////////////////////////////////////////////// |
172 | |
307 | |
173 | struct rxvt_perl_interp rxvt_perl; |
308 | struct rxvt_perl_interp rxvt_perl; |
174 | |
309 | |
… | |
… | |
213 | } |
348 | } |
214 | |
349 | |
215 | bool |
350 | bool |
216 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
351 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
217 | { |
352 | { |
218 | if (!perl |
353 | if (!perl) |
219 | || (!should_invoke [htype] && htype != HOOK_INIT && htype != HOOK_DESTROY)) |
|
|
220 | return false; |
354 | return false; |
221 | |
355 | |
222 | if (htype == HOOK_INIT) // first hook ever called |
356 | if (htype == HOOK_INIT) // first hook ever called |
|
|
357 | { |
223 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
358 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
|
|
359 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
|
|
360 | } |
|
|
361 | else if (htype == HOOK_DESTROY) |
|
|
362 | { |
|
|
363 | // handled later |
|
|
364 | } |
|
|
365 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
|
|
366 | { |
|
|
367 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
|
|
368 | |
|
|
369 | if (HvKEYS (hv)) |
|
|
370 | { |
|
|
371 | hv_iterinit (hv); |
|
|
372 | |
|
|
373 | while (HE *he = hv_iternext (hv)) |
|
|
374 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
375 | } |
|
|
376 | } |
|
|
377 | else if (!should_invoke [htype]) |
|
|
378 | return false; |
224 | |
379 | |
225 | dSP; |
380 | dSP; |
226 | va_list ap; |
381 | va_list ap; |
227 | |
382 | |
228 | va_start (ap, htype); |
383 | va_start (ap, htype); |
… | |
… | |
296 | PROTOTYPES: ENABLE |
451 | PROTOTYPES: ENABLE |
297 | |
452 | |
298 | BOOT: |
453 | BOOT: |
299 | { |
454 | { |
300 | # define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0)) |
455 | # define set_hookname(sym) av_store (hookname, PP_CONCAT(HOOK_, sym), newSVpv (PP_STRINGIFY(sym), 0)) |
|
|
456 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), #name, newSViv (name)); |
301 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
457 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
302 | set_hookname (INIT); |
458 | set_hookname (INIT); |
303 | set_hookname (RESET); |
459 | set_hookname (RESET); |
304 | set_hookname (START); |
460 | set_hookname (START); |
305 | set_hookname (DESTROY); |
461 | set_hookname (DESTROY); |
… | |
… | |
314 | set_hookname (TTY_ACTIVITY); |
470 | set_hookname (TTY_ACTIVITY); |
315 | set_hookname (REFRESH_BEGIN); |
471 | set_hookname (REFRESH_BEGIN); |
316 | set_hookname (REFRESH_END); |
472 | set_hookname (REFRESH_END); |
317 | set_hookname (KEYBOARD_COMMAND); |
473 | set_hookname (KEYBOARD_COMMAND); |
318 | |
474 | |
319 | newCONSTSUB (gv_stashpv ("urxvt", 1), "DEFAULT_RSTYLE", newSViv (DEFAULT_RSTYLE)); |
475 | export_const (DEFAULT_RSTYLE); |
|
|
476 | export_const (OVERLAY_RSTYLE); |
|
|
477 | export_const (RS_Bold); |
|
|
478 | export_const (RS_Italic); |
|
|
479 | export_const (RS_Blink); |
|
|
480 | export_const (RS_RVid); |
|
|
481 | export_const (RS_Uline); |
320 | |
482 | |
321 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
483 | sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR); |
322 | } |
484 | } |
323 | |
485 | |
324 | void |
486 | void |
… | |
… | |
339 | NV |
501 | NV |
340 | NOW () |
502 | NOW () |
341 | CODE: |
503 | CODE: |
342 | RETVAL = NOW; |
504 | RETVAL = NOW; |
343 | OUTPUT: |
505 | OUTPUT: |
|
|
506 | RETVAL |
|
|
507 | |
|
|
508 | int |
|
|
509 | GET_BASEFG (int rend) |
|
|
510 | CODE: |
|
|
511 | RETVAL = GET_BASEFG (rend); |
|
|
512 | OUTPUT: |
|
|
513 | RETVAL |
|
|
514 | |
|
|
515 | int |
|
|
516 | GET_BASEBG (int rend) |
|
|
517 | CODE: |
|
|
518 | RETVAL = GET_BASEBG (rend); |
|
|
519 | OUTPUT: |
|
|
520 | RETVAL |
|
|
521 | |
|
|
522 | int |
|
|
523 | SET_FGCOLOR (int rend, int new_color) |
|
|
524 | CODE: |
|
|
525 | RETVAL = SET_FGCOLOR (rend, new_color); |
|
|
526 | OUTPUT: |
|
|
527 | RETVAL |
|
|
528 | |
|
|
529 | int |
|
|
530 | SET_BGCOLOR (int rend, int new_color) |
|
|
531 | CODE: |
|
|
532 | RETVAL = SET_BGCOLOR (rend, new_color); |
|
|
533 | OUTPUT: |
|
|
534 | RETVAL |
|
|
535 | |
|
|
536 | int |
|
|
537 | GET_CUSTOM (int rend) |
|
|
538 | CODE: |
|
|
539 | RETVAL = (rend && RS_customMask) >> RS_customShift; |
|
|
540 | OUTPUT: |
|
|
541 | RETVAL |
|
|
542 | |
|
|
543 | int |
|
|
544 | SET_CUSTOM (int rend, int new_value) |
|
|
545 | CODE: |
|
|
546 | { |
|
|
547 | if (!IN_RANGE_EXC (new_value, 0, RS_customCount)) |
|
|
548 | croak ("custom value out of range, must be 0..%d", RS_customCount - 1); |
|
|
549 | |
|
|
550 | RETVAL = (rend & ~RS_customMask) |
|
|
551 | | ((new_value << RS_customShift) & RS_customMask); |
|
|
552 | } |
|
|
553 | OUTPUT: |
344 | RETVAL |
554 | RETVAL |
345 | |
555 | |
346 | MODULE = urxvt PACKAGE = urxvt::term |
556 | MODULE = urxvt PACKAGE = urxvt::term |
347 | |
557 | |
348 | int |
558 | int |
… | |
… | |
465 | free (str); |
675 | free (str); |
466 | } |
676 | } |
467 | |
677 | |
468 | if (new_text) |
678 | if (new_text) |
469 | { |
679 | { |
470 | STRLEN slen; |
|
|
471 | char *str = SvPVutf8 (new_text, slen); |
680 | wchar_t *wstr = sv2wcs (new_text); |
472 | wchar_t *wstr = rxvt_utf8towcs (str, slen); |
|
|
473 | |
681 | |
474 | int len = wcslen (wstr); |
682 | int len = wcslen (wstr); |
475 | |
683 | |
476 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
684 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
477 | { |
685 | { |
… | |
… | |
648 | THIS->selection.len = wcslen (THIS->selection.text); |
856 | THIS->selection.len = wcslen (THIS->selection.text); |
649 | } |
857 | } |
650 | } |
858 | } |
651 | |
859 | |
652 | void |
860 | void |
653 | rxvt_term::scr_overlay_new (int x, int y, int w, int h) |
|
|
654 | |
|
|
655 | void |
|
|
656 | rxvt_term::scr_overlay_off () |
|
|
657 | |
|
|
658 | void |
|
|
659 | rxvt_term::scr_overlay_set_char (int x, int y, U32 text, U32 rend = OVERLAY_RSTYLE) |
|
|
660 | 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 | { |
|
|
667 | wchar_t *wtext = sv2wcs (text); |
|
|
668 | THIS->scr_overlay_set (x, y, wtext); |
|
|
669 | free (wtext); |
|
|
670 | } |
|
|
671 | |
|
|
672 | void |
|
|
673 | rxvt_term::tt_write (SV *octets) |
861 | rxvt_term::tt_write (SV *octets) |
674 | INIT: |
862 | INIT: |
675 | STRLEN len; |
863 | STRLEN len; |
676 | char *str = SvPVbyte (octets, len); |
864 | char *str = SvPVbyte (octets, len); |
677 | C_ARGS: |
865 | C_ARGS: |
678 | (unsigned char *)str, len |
866 | (unsigned char *)str, len |
679 | |
867 | |
|
|
868 | SV * |
|
|
869 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
|
|
870 | CODE: |
|
|
871 | { |
|
|
872 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
|
|
873 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
|
|
874 | o->self = (HV *)SvRV (RETVAL); |
|
|
875 | |
|
|
876 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
|
|
877 | char key[33]; sprintf (key, "%32lx", (long)o); |
|
|
878 | hv_store (hv, key, 32, newSViv ((long)o), 0); |
|
|
879 | } |
|
|
880 | OUTPUT: |
|
|
881 | RETVAL |
|
|
882 | |
|
|
883 | MODULE = urxvt PACKAGE = urxvt::overlay |
|
|
884 | |
|
|
885 | void |
|
|
886 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
|
|
887 | |
|
|
888 | void |
|
|
889 | overlay::DESTROY () |
|
|
890 | CODE: |
|
|
891 | { |
|
|
892 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->THIS->self), "_overlay", 8, 0); |
|
|
893 | if (ovs) |
|
|
894 | { |
|
|
895 | HV *hv = (HV *)SvRV (*ovs); |
|
|
896 | char key[33]; sprintf (key, "%32lx", (long)THIS); |
|
|
897 | hv_delete (hv, key, 32, G_DISCARD); |
|
|
898 | } |
|
|
899 | |
|
|
900 | delete THIS; |
|
|
901 | } |
|
|
902 | |
680 | MODULE = urxvt PACKAGE = urxvt::timer |
903 | MODULE = urxvt PACKAGE = urxvt::timer |
681 | |
904 | |
682 | SV * |
905 | SV * |
683 | timer::new () |
906 | timer::new () |
684 | CODE: |
907 | CODE: |
685 | timer *w = new timer; |
908 | timer *w = new timer; |
|
|
909 | w->start (NOW); |
686 | RETVAL = newSVptr ((void *)w, "urxvt::timer"); |
910 | RETVAL = newSVptr ((void *)w, "urxvt::timer"); |
687 | w->self = (HV *)SvRV (RETVAL); |
911 | w->self = (HV *)SvRV (RETVAL); |
688 | OUTPUT: |
912 | OUTPUT: |
689 | RETVAL |
913 | RETVAL |
690 | |
914 | |
… | |
… | |
698 | |
922 | |
699 | NV |
923 | NV |
700 | timer::at () |
924 | timer::at () |
701 | CODE: |
925 | CODE: |
702 | RETVAL = THIS->at; |
926 | RETVAL = THIS->at; |
|
|
927 | OUTPUT: |
|
|
928 | RETVAL |
|
|
929 | |
|
|
930 | timer * |
|
|
931 | timer::interval (NV interval) |
|
|
932 | CODE: |
|
|
933 | THIS->interval = interval; |
|
|
934 | RETVAL = THIS; |
703 | OUTPUT: |
935 | OUTPUT: |
704 | RETVAL |
936 | RETVAL |
705 | |
937 | |
706 | timer * |
938 | timer * |
707 | timer::set (NV tstamp) |
939 | timer::set (NV tstamp) |