… | |
… | |
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 *text, 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 *wtext = sv2wcs (text); |
|
|
296 | |
|
|
297 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
|
|
298 | this->text [y][x + col] = wtext [col]; |
|
|
299 | |
|
|
300 | free (wtext); |
|
|
301 | |
|
|
302 | if (rend) |
|
|
303 | { |
|
|
304 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
|
|
305 | croak ("rend must be arrayref"); |
|
|
306 | |
|
|
307 | AV *av = (AV *)SvRV (rend); |
|
|
308 | |
|
|
309 | for (int col = min (av_len (av) + 1, w - x - border); col--; ) |
|
|
310 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
|
|
311 | } |
|
|
312 | |
|
|
313 | THIS->want_refresh = 1; |
|
|
314 | } |
|
|
315 | |
170 | |
316 | |
171 | ///////////////////////////////////////////////////////////////////////////// |
317 | ///////////////////////////////////////////////////////////////////////////// |
172 | |
318 | |
173 | struct rxvt_perl_interp rxvt_perl; |
319 | struct rxvt_perl_interp rxvt_perl; |
174 | |
320 | |
… | |
… | |
213 | } |
359 | } |
214 | |
360 | |
215 | bool |
361 | bool |
216 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
362 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
217 | { |
363 | { |
218 | if (!perl |
364 | if (!perl) |
219 | || (!should_invoke [htype] && htype != HOOK_INIT && htype != HOOK_DESTROY)) |
|
|
220 | return false; |
365 | return false; |
221 | |
366 | |
222 | if (htype == HOOK_INIT) // first hook ever called |
367 | if (htype == HOOK_INIT) // first hook ever called |
|
|
368 | { |
223 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
369 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
|
|
370 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
|
|
371 | } |
|
|
372 | else if (htype == HOOK_DESTROY) |
|
|
373 | { |
|
|
374 | // handled later |
|
|
375 | } |
|
|
376 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
|
|
377 | { |
|
|
378 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); |
|
|
379 | |
|
|
380 | if (HvKEYS (hv)) |
|
|
381 | { |
|
|
382 | hv_iterinit (hv); |
|
|
383 | |
|
|
384 | while (HE *he = hv_iternext (hv)) |
|
|
385 | ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); |
|
|
386 | } |
|
|
387 | } |
|
|
388 | else if (!should_invoke [htype]) |
|
|
389 | return false; |
224 | |
390 | |
225 | dSP; |
391 | dSP; |
226 | va_list ap; |
392 | va_list ap; |
227 | |
393 | |
228 | va_start (ap, htype); |
394 | va_start (ap, htype); |
… | |
… | |
306 | set_hookname (DESTROY); |
472 | set_hookname (DESTROY); |
307 | set_hookname (SEL_BEGIN); |
473 | set_hookname (SEL_BEGIN); |
308 | set_hookname (SEL_EXTEND); |
474 | set_hookname (SEL_EXTEND); |
309 | set_hookname (SEL_MAKE); |
475 | set_hookname (SEL_MAKE); |
310 | set_hookname (SEL_GRAB); |
476 | set_hookname (SEL_GRAB); |
|
|
477 | set_hookname (SEL_CLICK); |
311 | set_hookname (FOCUS_IN); |
478 | set_hookname (FOCUS_IN); |
312 | set_hookname (FOCUS_OUT); |
479 | set_hookname (FOCUS_OUT); |
313 | set_hookname (VIEW_CHANGE); |
480 | set_hookname (VIEW_CHANGE); |
314 | set_hookname (SCROLL_BACK); |
481 | set_hookname (SCROLL_BACK); |
315 | set_hookname (TTY_ACTIVITY); |
482 | set_hookname (TTY_ACTIVITY); |
316 | set_hookname (REFRESH_BEGIN); |
483 | set_hookname (REFRESH_BEGIN); |
317 | set_hookname (REFRESH_END); |
484 | set_hookname (REFRESH_END); |
318 | set_hookname (KEYBOARD_COMMAND); |
485 | set_hookname (KEYBOARD_COMMAND); |
|
|
486 | set_hookname (MOUSE_CLICK); |
|
|
487 | set_hookname (MOUSE_MOVE); |
319 | |
488 | |
320 | export_const (DEFAULT_RSTYLE); |
489 | export_const (DEFAULT_RSTYLE); |
321 | export_const (OVERLAY_RSTYLE); |
490 | export_const (OVERLAY_RSTYLE); |
322 | export_const (RS_Bold); |
491 | export_const (RS_Bold); |
323 | export_const (RS_Italic); |
492 | export_const (RS_Italic); |
… | |
… | |
520 | free (str); |
689 | free (str); |
521 | } |
690 | } |
522 | |
691 | |
523 | if (new_text) |
692 | if (new_text) |
524 | { |
693 | { |
525 | STRLEN slen; |
|
|
526 | char *str = SvPVutf8 (new_text, slen); |
694 | wchar_t *wstr = sv2wcs (new_text); |
527 | wchar_t *wstr = rxvt_utf8towcs (str, slen); |
|
|
528 | |
695 | |
529 | int len = wcslen (wstr); |
696 | int len = wcslen (wstr); |
530 | |
697 | |
531 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
698 | if (!IN_RANGE_INC (start_col, 0, THIS->ncol - len)) |
532 | { |
699 | { |
… | |
… | |
678 | THIS->want_refresh = 1; |
845 | THIS->want_refresh = 1; |
679 | } |
846 | } |
680 | } |
847 | } |
681 | |
848 | |
682 | int |
849 | int |
683 | rxvt_term::selection_grab (int eventtime) |
850 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
684 | |
851 | |
685 | void |
852 | void |
686 | rxvt_term::selection (SV *newtext = 0) |
853 | rxvt_term::selection (SV *newtext = 0) |
687 | PPCODE: |
854 | PPCODE: |
688 | { |
855 | { |
… | |
… | |
702 | THIS->selection.text = sv2wcs (newtext); |
869 | THIS->selection.text = sv2wcs (newtext); |
703 | THIS->selection.len = wcslen (THIS->selection.text); |
870 | THIS->selection.len = wcslen (THIS->selection.text); |
704 | } |
871 | } |
705 | } |
872 | } |
706 | |
873 | |
707 | void |
|
|
708 | rxvt_term::scr_overlay_new (int x, int y, int w, int h) |
|
|
709 | |
|
|
710 | void |
|
|
711 | rxvt_term::scr_overlay_off () |
|
|
712 | |
|
|
713 | void |
|
|
714 | rxvt_term::scr_overlay_set_char (int x, int y, U32 text, U32 rend = OVERLAY_RSTYLE) |
|
|
715 | CODE: |
|
|
716 | THIS->scr_overlay_set (x, y, text, rend); |
|
|
717 | |
|
|
718 | void |
|
|
719 | rxvt_term::scr_overlay_set (int x, int y, SV *text) |
|
|
720 | CODE: |
|
|
721 | { |
|
|
722 | wchar_t *wtext = sv2wcs (text); |
|
|
723 | THIS->scr_overlay_set (x, y, wtext); |
|
|
724 | free (wtext); |
|
|
725 | } |
|
|
726 | |
|
|
727 | void |
874 | void |
728 | rxvt_term::tt_write (SV *octets) |
875 | rxvt_term::tt_write (SV *octets) |
729 | INIT: |
876 | INIT: |
730 | STRLEN len; |
877 | STRLEN len; |
731 | char *str = SvPVbyte (octets, len); |
878 | char *str = SvPVbyte (octets, len); |
732 | C_ARGS: |
879 | C_ARGS: |
733 | (unsigned char *)str, len |
880 | (unsigned char *)str, len |
734 | |
881 | |
|
|
882 | SV * |
|
|
883 | rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) |
|
|
884 | CODE: |
|
|
885 | { |
|
|
886 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
|
|
887 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
|
|
888 | 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 | } |
|
|
894 | OUTPUT: |
|
|
895 | RETVAL |
|
|
896 | |
|
|
897 | MODULE = urxvt PACKAGE = urxvt::overlay |
|
|
898 | |
|
|
899 | void |
|
|
900 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
|
|
901 | |
|
|
902 | void |
|
|
903 | 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 | |
735 | MODULE = urxvt PACKAGE = urxvt::timer |
917 | MODULE = urxvt PACKAGE = urxvt::timer |
736 | |
918 | |
737 | SV * |
919 | SV * |
738 | timer::new () |
920 | timer::new () |
739 | CODE: |
921 | CODE: |
740 | timer *w = new timer; |
922 | timer *w = new timer; |
|
|
923 | w->start (NOW); |
741 | RETVAL = newSVptr ((void *)w, "urxvt::timer"); |
924 | RETVAL = newSVptr ((void *)w, "urxvt::timer"); |
742 | w->self = (HV *)SvRV (RETVAL); |
925 | w->self = (HV *)SvRV (RETVAL); |
743 | OUTPUT: |
926 | OUTPUT: |
744 | RETVAL |
927 | RETVAL |
745 | |
928 | |
… | |
… | |
753 | |
936 | |
754 | NV |
937 | NV |
755 | timer::at () |
938 | timer::at () |
756 | CODE: |
939 | CODE: |
757 | RETVAL = THIS->at; |
940 | RETVAL = THIS->at; |
|
|
941 | OUTPUT: |
|
|
942 | RETVAL |
|
|
943 | |
|
|
944 | timer * |
|
|
945 | timer::interval (NV interval) |
|
|
946 | CODE: |
|
|
947 | THIS->interval = interval; |
|
|
948 | RETVAL = THIS; |
758 | OUTPUT: |
949 | OUTPUT: |
759 | RETVAL |
950 | RETVAL |
760 | |
951 | |
761 | timer * |
952 | timer * |
762 | timer::set (NV tstamp) |
953 | timer::set (NV tstamp) |