newSVptr (void *ptr, const char *klass)
{
HV *hv = newHV ();
- hv_store (hv, "_ptr", 4, newSViv ((long)ptr), 0);
+ sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
}
+static void
+clearSVptr (SV *sv)
+{
+ if (SvROK (sv))
+ sv = SvRV (sv);
+
+ hv_clear ((HV *)sv);
+ sv_unmagic (sv, PERL_MAGIC_ext);
+}
+
static long
SvPTR (SV *sv, const char *klass)
{
if (!sv_derived_from (sv, klass))
croak ("object of type %s expected", klass);
- IV iv = SvIV (*hv_fetch ((HV *)SvRV (sv), "_ptr", 4, 1));
+ MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
- if (!iv)
+ if (!mg)
croak ("perl code used %s object, but C++ object is already destroyed, caught", klass);
- return (long)iv;
+ return (long)mg->mg_ptr;
}
#define newSVterm(term) SvREFCNT_inc ((SV *)term->self)
overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border);
~overlay ();
+ void show ();
+ void hide ();
+
void swap ();
void set (int x, int y, SV *str, SV *rend);
}
}
+ show ();
THIS->want_refresh = 1;
}
overlay::~overlay ()
{
+ hide ();
+
for (int y = h; y--; )
{
delete [] text[y];
THIS->want_refresh = 1;
}
+void
+overlay::show ()
+{
+ char key[33]; sprintf (key, "%32lx", (long)this);
+
+ HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0));
+ hv_store (hv, key, 32, newSViv ((long)this), 0);
+}
+
+void
+overlay::hide ()
+{
+ SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0);
+
+ if (ovs)
+ {
+ char key[33]; sprintf (key, "%32lx", (long)this);
+
+ HV *hv = (HV *)SvRV (*ovs);
+ hv_delete (hv, key, 32, G_DISCARD);
+ }
+}
+
void overlay::swap ()
{
int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w));
if (htype == HOOK_DESTROY)
{
- // TODO: clear magic
- hv_clear ((HV *)SvRV ((SV *)term->self));
+ clearSVptr ((SV *)term->self);
SvREFCNT_dec ((SV *)term->self);
}
overlay *o = new overlay (THIS, x, y, w, h, rstyle, border);
RETVAL = newSVptr ((void *)o, "urxvt::overlay");
o->self = (HV *)SvRV (RETVAL);
-
- HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0));
- char key[33]; sprintf (key, "%32lx", (long)o);
- hv_store (hv, key, 32, newSViv ((long)o), 0);
}
OUTPUT:
RETVAL
overlay::set (int x, int y, SV *text, SV *rend = 0)
void
-overlay::DESTROY ()
- CODE:
-{
- SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->THIS->self), "_overlay", 8, 0);
- if (ovs)
- {
- HV *hv = (HV *)SvRV (*ovs);
- char key[33]; sprintf (key, "%32lx", (long)THIS);
- hv_delete (hv, key, 32, G_DISCARD);
- }
+overlay::show ()
- delete THIS;
-}
+void
+overlay::hide ()
+
+void
+overlay::DESTROY ()
MODULE = urxvt PACKAGE = urxvt::timer
=item selection
-Miscellaneous selection modifications.
+Intelligent selection. This etxension tries to be more intelligent when the user
+extends selections (double-click).
+
+It also offers the following bindable event:
=over 4
Returning a true value aborts selection grabbing. It will still be hilighted.
+=item on_sel_extend $term
+
+Called whenever the user tries to extend the selection (e.g. with a double
+click) and is either supposed to return false (normal operation), or
+should extend the selection itelf and return true to suppress the built-in
+processing.
+
+See the F<selection> example extension.
+
=item on_focus_in $term
Called whenever the window gets the keyboard focus, before urxvt does
This method returns an urxvt::overlay object. The overlay will be visible
as long as the perl object is referenced.
-Currently, the only method on the C<urxvt::overlay> object is C<set>:
+The methods currently supported on C<urxvt::overlay> objects are:
+
+=over 4
=item $overlay->set ($x, $y, $text, $rend)
text in rxvt-unicode's special encoding and an array of rendition values
at a specific position inside the overlay.
+=item $overlay->hide
+
+If visible, hide the overlay, but do not destroy it.
+
+=item $overlay->show
+
+If hidden, display the overlay again.
+
+=back
+
=item $cellwidth = $term->strwidth $string
Returns the number of screen-cells this string would need. Correctly