… | |
… | |
61 | //TODO: use magic |
61 | //TODO: use magic |
62 | static SV * |
62 | static SV * |
63 | newSVptr (void *ptr, const char *klass) |
63 | newSVptr (void *ptr, const char *klass) |
64 | { |
64 | { |
65 | HV *hv = newHV (); |
65 | HV *hv = newHV (); |
66 | hv_store (hv, "_ptr", 4, newSViv ((long)ptr), 0); |
66 | sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); |
67 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
67 | return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
|
|
68 | } |
|
|
69 | |
|
|
70 | static void |
|
|
71 | clearSVptr (SV *sv) |
|
|
72 | { |
|
|
73 | if (SvROK (sv)) |
|
|
74 | sv = SvRV (sv); |
|
|
75 | |
|
|
76 | hv_clear ((HV *)sv); |
|
|
77 | sv_unmagic (sv, PERL_MAGIC_ext); |
68 | } |
78 | } |
69 | |
79 | |
70 | static long |
80 | static long |
71 | SvPTR (SV *sv, const char *klass) |
81 | SvPTR (SV *sv, const char *klass) |
72 | { |
82 | { |
73 | if (!sv_derived_from (sv, klass)) |
83 | if (!sv_derived_from (sv, klass)) |
74 | croak ("object of type %s expected", klass); |
84 | croak ("object of type %s expected", klass); |
75 | |
85 | |
76 | IV iv = SvIV (*hv_fetch ((HV *)SvRV (sv), "_ptr", 4, 1)); |
86 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
77 | |
87 | |
78 | if (!iv) |
88 | if (!mg) |
79 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
89 | croak ("perl code used %s object, but C++ object is already destroyed, caught", klass); |
80 | |
90 | |
81 | return (long)iv; |
91 | return (long)mg->mg_ptr; |
82 | } |
92 | } |
83 | |
93 | |
84 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
94 | #define newSVterm(term) SvREFCNT_inc ((SV *)term->self) |
85 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
95 | #define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term") |
86 | |
96 | |
… | |
… | |
185 | text_t **text; |
195 | text_t **text; |
186 | rend_t **rend; |
196 | rend_t **rend; |
187 | |
197 | |
188 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
198 | overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); |
189 | ~overlay (); |
199 | ~overlay (); |
|
|
200 | |
|
|
201 | void show (); |
|
|
202 | void hide (); |
190 | |
203 | |
191 | void swap (); |
204 | void swap (); |
192 | |
205 | |
193 | void set (int x, int y, SV *str, SV *rend); |
206 | void set (int x, int y, SV *str, SV *rend); |
194 | }; |
207 | }; |
… | |
… | |
240 | *tp++ = 0x0020; |
253 | *tp++ = 0x0020; |
241 | *rp++ = r; |
254 | *rp++ = r; |
242 | } |
255 | } |
243 | } |
256 | } |
244 | |
257 | |
|
|
258 | show (); |
245 | THIS->want_refresh = 1; |
259 | THIS->want_refresh = 1; |
246 | } |
260 | } |
247 | |
261 | |
248 | overlay::~overlay () |
262 | overlay::~overlay () |
249 | { |
263 | { |
|
|
264 | hide (); |
|
|
265 | |
250 | for (int y = h; y--; ) |
266 | for (int y = h; y--; ) |
251 | { |
267 | { |
252 | delete [] text[y]; |
268 | delete [] text[y]; |
253 | delete [] rend[y]; |
269 | delete [] rend[y]; |
254 | } |
270 | } |
255 | |
271 | |
256 | delete [] text; |
272 | delete [] text; |
257 | delete [] rend; |
273 | delete [] rend; |
258 | |
274 | |
259 | THIS->want_refresh = 1; |
275 | THIS->want_refresh = 1; |
|
|
276 | } |
|
|
277 | |
|
|
278 | void |
|
|
279 | overlay::show () |
|
|
280 | { |
|
|
281 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
282 | |
|
|
283 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
|
|
284 | hv_store (hv, key, 32, newSViv ((long)this), 0); |
|
|
285 | } |
|
|
286 | |
|
|
287 | void |
|
|
288 | overlay::hide () |
|
|
289 | { |
|
|
290 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0); |
|
|
291 | |
|
|
292 | if (ovs) |
|
|
293 | { |
|
|
294 | char key[33]; sprintf (key, "%32lx", (long)this); |
|
|
295 | |
|
|
296 | HV *hv = (HV *)SvRV (*ovs); |
|
|
297 | hv_delete (hv, key, 32, G_DISCARD); |
|
|
298 | } |
260 | } |
299 | } |
261 | |
300 | |
262 | void overlay::swap () |
301 | void overlay::swap () |
263 | { |
302 | { |
264 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
303 | int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); |
… | |
… | |
282 | } |
321 | } |
283 | } |
322 | } |
284 | |
323 | |
285 | } |
324 | } |
286 | |
325 | |
287 | void overlay::set (int x, int y, SV *str, SV *rend) |
326 | void overlay::set (int x, int y, SV *text, SV *rend) |
288 | { |
327 | { |
289 | x += border; |
328 | x += border; |
290 | y += border; |
329 | y += border; |
291 | |
330 | |
292 | if (!IN_RANGE_EXC (y, 0, h - border)) |
331 | if (!IN_RANGE_EXC (y, 0, h - border)) |
293 | return; |
332 | return; |
294 | |
333 | |
295 | wchar_t *wstr = sv2wcs (str); |
334 | wchar_t *wtext = sv2wcs (text); |
296 | |
335 | |
297 | for (int col = min (wcslen (wstr), w - x - border); col--; ) |
336 | for (int col = min (wcslen (wtext), w - x - border); col--; ) |
298 | text [y][x + col] = wstr [col]; |
337 | this->text [y][x + col] = wtext [col]; |
299 | |
338 | |
300 | free (wstr); |
339 | free (wtext); |
|
|
340 | |
|
|
341 | if (rend) |
|
|
342 | { |
|
|
343 | if (!SvROK (rend) || SvTYPE (SvRV (rend)) != SVt_PVAV) |
|
|
344 | croak ("rend must be arrayref"); |
|
|
345 | |
|
|
346 | AV *av = (AV *)SvRV (rend); |
|
|
347 | |
|
|
348 | for (int col = min (av_len (av) + 1, w - x - border); col--; ) |
|
|
349 | this->rend [y][x + col] = SvIV (*av_fetch (av, col, 1)); |
|
|
350 | } |
301 | |
351 | |
302 | THIS->want_refresh = 1; |
352 | THIS->want_refresh = 1; |
303 | } |
353 | } |
304 | |
354 | |
305 | |
355 | |
… | |
… | |
356 | if (htype == HOOK_INIT) // first hook ever called |
406 | if (htype == HOOK_INIT) // first hook ever called |
357 | { |
407 | { |
358 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
408 | term->self = (void *)newSVptr ((void *)term, "urxvt::term"); |
359 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
409 | hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); |
360 | } |
410 | } |
|
|
411 | else if (!term->self) |
|
|
412 | return false; // perl not initialized for this instance |
361 | else if (htype == HOOK_DESTROY) |
413 | else if (htype == HOOK_DESTROY) |
362 | { |
414 | { |
363 | // handled later |
415 | // handled later |
364 | } |
416 | } |
365 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
417 | else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) |
… | |
… | |
428 | if (SvTRUE (ERRSV)) |
480 | if (SvTRUE (ERRSV)) |
429 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
481 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
430 | |
482 | |
431 | if (htype == HOOK_DESTROY) |
483 | if (htype == HOOK_DESTROY) |
432 | { |
484 | { |
433 | // TODO: clear magic |
|
|
434 | hv_clear ((HV *)SvRV ((SV *)term->self)); |
485 | clearSVptr ((SV *)term->self); |
435 | SvREFCNT_dec ((SV *)term->self); |
486 | SvREFCNT_dec ((SV *)term->self); |
436 | } |
487 | } |
437 | |
488 | |
438 | return count; |
489 | return count; |
439 | } |
490 | } |
… | |
… | |
450 | |
501 | |
451 | PROTOTYPES: ENABLE |
502 | PROTOTYPES: ENABLE |
452 | |
503 | |
453 | BOOT: |
504 | BOOT: |
454 | { |
505 | { |
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)); |
506 | # define export_const(name) newCONSTSUB (gv_stashpv ("urxvt", 1), #name, newSViv (name)); |
457 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
507 | AV *hookname = get_av ("urxvt::HOOKNAME", 1); |
458 | set_hookname (INIT); |
508 | # define def(sym) av_store (hookname, HOOK_ ## sym, newSVpv (# sym, 0)); |
459 | set_hookname (RESET); |
509 | # include "hookinc.h" |
460 | set_hookname (START); |
510 | # undef def |
461 | set_hookname (DESTROY); |
|
|
462 | set_hookname (SEL_BEGIN); |
|
|
463 | set_hookname (SEL_EXTEND); |
|
|
464 | set_hookname (SEL_MAKE); |
|
|
465 | set_hookname (SEL_GRAB); |
|
|
466 | set_hookname (FOCUS_IN); |
|
|
467 | set_hookname (FOCUS_OUT); |
|
|
468 | set_hookname (VIEW_CHANGE); |
|
|
469 | set_hookname (SCROLL_BACK); |
|
|
470 | set_hookname (TTY_ACTIVITY); |
|
|
471 | set_hookname (REFRESH_BEGIN); |
|
|
472 | set_hookname (REFRESH_END); |
|
|
473 | set_hookname (KEYBOARD_COMMAND); |
|
|
474 | |
511 | |
475 | export_const (DEFAULT_RSTYLE); |
512 | export_const (DEFAULT_RSTYLE); |
476 | export_const (OVERLAY_RSTYLE); |
513 | export_const (OVERLAY_RSTYLE); |
477 | export_const (RS_Bold); |
514 | export_const (RS_Bold); |
478 | export_const (RS_Italic); |
515 | export_const (RS_Italic); |
… | |
… | |
653 | void |
690 | void |
654 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
691 | rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) |
655 | PPCODE: |
692 | PPCODE: |
656 | { |
693 | { |
657 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
694 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
658 | croak ("row_number number of out range"); |
695 | XSRETURN_EMPTY; |
659 | |
696 | |
660 | line_t &l = ROW(row_number); |
697 | line_t &l = ROW(row_number); |
661 | |
698 | |
662 | if (GIMME_V != G_VOID) |
699 | if (GIMME_V != G_VOID) |
663 | { |
700 | { |
… | |
… | |
700 | void |
737 | void |
701 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
738 | rxvt_term::ROW_r (int row_number, SV *new_rend = 0, int start_col = 0) |
702 | PPCODE: |
739 | PPCODE: |
703 | { |
740 | { |
704 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
741 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
705 | croak ("row_number number of out range"); |
742 | XSRETURN_EMPTY; |
706 | |
743 | |
707 | line_t &l = ROW(row_number); |
744 | line_t &l = ROW(row_number); |
708 | |
745 | |
709 | if (GIMME_V != G_VOID) |
746 | if (GIMME_V != G_VOID) |
710 | { |
747 | { |
… | |
… | |
740 | int |
777 | int |
741 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
778 | rxvt_term::ROW_l (int row_number, int new_length = -2) |
742 | CODE: |
779 | CODE: |
743 | { |
780 | { |
744 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
781 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
745 | croak ("row_number number of out range"); |
782 | XSRETURN_EMPTY; |
746 | |
783 | |
747 | line_t &l = ROW(row_number); |
784 | line_t &l = ROW(row_number); |
748 | RETVAL = l.l; |
785 | RETVAL = l.l < 0 ? THIS->ncol : l.l; |
749 | |
786 | |
750 | if (new_length >= -1) |
787 | if (new_length >= -1) |
751 | l.l = new_length; |
788 | l.l = new_length; |
752 | } |
789 | } |
753 | OUTPUT: |
790 | OUTPUT: |
754 | RETVAL |
791 | RETVAL |
755 | |
792 | |
|
|
793 | bool |
|
|
794 | rxvt_term::ROW_is_longer (int row_number) |
|
|
795 | CODE: |
|
|
796 | { |
|
|
797 | if (!IN_RANGE_EXC (row_number, -THIS->nsaved, THIS->nrow)) |
|
|
798 | XSRETURN_EMPTY; |
|
|
799 | |
|
|
800 | line_t &l = ROW(row_number); |
|
|
801 | RETVAL = l.l < 0; |
|
|
802 | } |
|
|
803 | OUTPUT: |
|
|
804 | RETVAL |
|
|
805 | |
756 | SV * |
806 | SV * |
757 | rxvt_term::special_encode (SV *str) |
807 | rxvt_term::special_encode (SV *str) |
758 | CODE: |
808 | CODE: |
759 | abort ();//TODO |
809 | abort ();//TODO |
760 | |
810 | |
… | |
… | |
766 | void |
816 | void |
767 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
817 | rxvt_term::_resource (char *name, int index, SV *newval = 0) |
768 | PPCODE: |
818 | PPCODE: |
769 | { |
819 | { |
770 | struct resval { const char *name; int value; } rslist [] = { |
820 | struct resval { const char *name; int value; } rslist [] = { |
771 | # define Rs_def(name) { # name, Rs_ ## name }, |
821 | # define def(name) { # name, Rs_ ## name }, |
772 | # define Rs_reserve(name,count) |
822 | # define reserve(name,count) |
773 | # include "rsinc.h" |
823 | # include "rsinc.h" |
774 | # undef Rs_def |
824 | # undef def |
775 | # undef Rs_reserve |
825 | # undef reserve |
776 | }; |
826 | }; |
777 | |
827 | |
778 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
828 | struct resval *rs = rslist + sizeof (rslist) / sizeof (rslist [0]); |
779 | |
829 | |
780 | do { |
830 | do { |
… | |
… | |
831 | THIS->want_refresh = 1; |
881 | THIS->want_refresh = 1; |
832 | } |
882 | } |
833 | } |
883 | } |
834 | |
884 | |
835 | int |
885 | int |
836 | rxvt_term::selection_grab (int eventtime) |
886 | rxvt_term::selection_grab (int eventtime = CurrentTime) |
837 | |
887 | |
838 | void |
888 | void |
839 | rxvt_term::selection (SV *newtext = 0) |
889 | rxvt_term::selection (SV *newtext = 0) |
840 | PPCODE: |
890 | PPCODE: |
841 | { |
891 | { |
… | |
… | |
870 | CODE: |
920 | CODE: |
871 | { |
921 | { |
872 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
922 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
873 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
923 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
874 | o->self = (HV *)SvRV (RETVAL); |
924 | 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 | } |
925 | } |
880 | OUTPUT: |
926 | OUTPUT: |
881 | RETVAL |
927 | RETVAL |
882 | |
928 | |
883 | MODULE = urxvt PACKAGE = urxvt::overlay |
929 | MODULE = urxvt PACKAGE = urxvt::overlay |
884 | |
930 | |
885 | void |
931 | void |
886 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
932 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
887 | |
933 | |
888 | void |
934 | void |
|
|
935 | overlay::show () |
|
|
936 | |
|
|
937 | void |
|
|
938 | overlay::hide () |
|
|
939 | |
|
|
940 | void |
889 | overlay::DESTROY () |
941 | 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 | |
942 | |
903 | MODULE = urxvt PACKAGE = urxvt::timer |
943 | MODULE = urxvt PACKAGE = urxvt::timer |
904 | |
944 | |
905 | SV * |
945 | SV * |
906 | timer::new () |
946 | timer::new () |