… | |
… | |
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)); |
… | |
… | |
441 | if (SvTRUE (ERRSV)) |
480 | if (SvTRUE (ERRSV)) |
442 | 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)); |
443 | |
482 | |
444 | if (htype == HOOK_DESTROY) |
483 | if (htype == HOOK_DESTROY) |
445 | { |
484 | { |
446 | // TODO: clear magic |
|
|
447 | hv_clear ((HV *)SvRV ((SV *)term->self)); |
485 | clearSVptr ((SV *)term->self); |
448 | SvREFCNT_dec ((SV *)term->self); |
486 | SvREFCNT_dec ((SV *)term->self); |
449 | } |
487 | } |
450 | |
488 | |
451 | return count; |
489 | return count; |
452 | } |
490 | } |
… | |
… | |
883 | CODE: |
921 | CODE: |
884 | { |
922 | { |
885 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
923 | overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); |
886 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
924 | RETVAL = newSVptr ((void *)o, "urxvt::overlay"); |
887 | o->self = (HV *)SvRV (RETVAL); |
925 | o->self = (HV *)SvRV (RETVAL); |
888 | |
|
|
889 | HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); |
|
|
890 | char key[33]; sprintf (key, "%32lx", (long)o); |
|
|
891 | hv_store (hv, key, 32, newSViv ((long)o), 0); |
|
|
892 | } |
926 | } |
893 | OUTPUT: |
927 | OUTPUT: |
894 | RETVAL |
928 | RETVAL |
895 | |
929 | |
896 | MODULE = urxvt PACKAGE = urxvt::overlay |
930 | MODULE = urxvt PACKAGE = urxvt::overlay |
897 | |
931 | |
898 | void |
932 | void |
899 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
933 | overlay::set (int x, int y, SV *text, SV *rend = 0) |
900 | |
934 | |
901 | void |
935 | void |
|
|
936 | overlay::show () |
|
|
937 | |
|
|
938 | void |
|
|
939 | overlay::hide () |
|
|
940 | |
|
|
941 | void |
902 | overlay::DESTROY () |
942 | overlay::DESTROY () |
903 | CODE: |
|
|
904 | { |
|
|
905 | SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->THIS->self), "_overlay", 8, 0); |
|
|
906 | if (ovs) |
|
|
907 | { |
|
|
908 | HV *hv = (HV *)SvRV (*ovs); |
|
|
909 | char key[33]; sprintf (key, "%32lx", (long)THIS); |
|
|
910 | hv_delete (hv, key, 32, G_DISCARD); |
|
|
911 | } |
|
|
912 | |
|
|
913 | delete THIS; |
|
|
914 | } |
|
|
915 | |
943 | |
916 | MODULE = urxvt PACKAGE = urxvt::timer |
944 | MODULE = urxvt PACKAGE = urxvt::timer |
917 | |
945 | |
918 | SV * |
946 | SV * |
919 | timer::new () |
947 | timer::new () |