return (long)mg->mg_ptr;
}
-#define newSVterm(term) SvREFCNT_inc ((SV *)term->self)
+#define newSVterm(term) SvREFCNT_inc ((SV *)term->perl.self)
#define SvTERM(sv) (rxvt_term *)SvPTR (sv, "urxvt::term")
/////////////////////////////////////////////////////////////////////////////
{
char key[33]; sprintf (key, "%32lx", (long)this);
- HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0));
+ HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->perl.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);
+ SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->perl.self), "_overlay", 8, 0);
if (ovs)
{
if (htype == HOOK_INIT) // first hook ever called
{
- term->self = (void *)newSVptr ((void *)term, "urxvt::term");
- hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
+ term->perl.self = (void *)newSVptr ((void *)term, "urxvt::term");
+ hv_store ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0);
}
- else if (!term->self)
+ else if (!term->perl.self)
return false; // perl not initialized for this instance
else if (htype == HOOK_DESTROY)
{
}
else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END)
{
- HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0));
+ HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->perl.self), "_overlay", 8, 0));
if (HvKEYS (hv))
{
if (htype == HOOK_DESTROY)
{
- clearSVptr ((SV *)term->self);
- SvREFCNT_dec ((SV *)term->self);
+ clearSVptr ((SV *)term->perl.self);
+ SvREFCNT_dec ((SV *)term->perl.self);
}
return count;
export_const (RS_Blink);
export_const (RS_RVid);
export_const (RS_Uline);
+ export_const (CurrentTime);
sv_setpv (get_sv ("urxvt::LIBDIR", 1), LIBDIR);
}
croak ("exception caught while initializing new terminal instance");
}
- RETVAL = term && term->self ? newSVterm (term) : &PL_sv_undef;
+ RETVAL = term && term->perl.self ? newSVterm (term) : &PL_sv_undef;
}
OUTPUT:
RETVAL
rxvt_term::destroy ()
void
-rxvt_term::grab (int eventtime)
+rxvt_term::grab_button (int button, U32 modifiers)
+ CODE:
+ XGrabButton (THIS->display->display, button, modifiers, THIS->vt, 1,
+ ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
+ GrabModeSync, GrabModeSync, None, None);
+
+bool
+rxvt_term::grab (U32 eventtime, int sync = 0)
CODE:
{
-return;
- XGrabPointer (THIS->display->display, THIS->vt, 0,
- ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
- GrabModeAsync, GrabModeAsync, None, None, eventtime);
- XGrabKeyboard (THIS->display->display, THIS->vt, 0, GrabModeAsync, GrabModeAsync, eventtime);
+ int mode = sync ? GrabModeSync : GrabModeAsync;
+
+ THIS->perl.grabtime = 0;
+
+ if (!XGrabPointer (THIS->display->display, THIS->vt, 0,
+ ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
+ mode, mode, None, None, eventtime))
+ if (!XGrabKeyboard (THIS->display->display, THIS->vt, 0, mode, mode, eventtime))
+ THIS->perl.grabtime = eventtime;
+ else
+ XUngrabPointer (THIS->display->display, eventtime);
+
+ RETVAL = !!THIS->perl.grabtime;
}
+ OUTPUT:
+ RETVAL
+
+void
+rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime)
+ CODE:
+ XAllowEvents (THIS->display->display, AsyncBoth, eventtime);
+
+void
+rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime)
+ CODE:
+ XAllowEvents (THIS->display->display, SyncBoth, eventtime);
+
+void
+rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime)
+ CODE:
+ XAllowEvents (THIS->display->display, ReplayPointer, eventtime);
+ XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime);
+
+void
+rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime)
+ CODE:
+ THIS->perl.grabtime = 0;
+ XUngrabKeyboard (THIS->display->display, eventtime);
+ XUngrabPointer (THIS->display->display, eventtime);
int
rxvt_term::strwidth (SV *str)
}
int
-rxvt_term::selection_grab (int eventtime = CurrentTime)
+rxvt_term::selection_grab (U32 eventtime)
void
rxvt_term::selection (SV *newtext = 0)
=head1 DESCRIPTION
-Everytime a terminal object gets created, scripts specified via the
-C<perl> resource are loaded and associated with it.
+Everytime a terminal object gets created, extension scripts specified via
+the C<perl> resource are loaded and associated with it.
Scripts are compiled in a 'use strict' and 'use utf8' environment, and
thus must be encoded as UTF-8.
called whenever the relevant event happens.
The first argument passed to them is an object private to each terminal
-and extension package. You can call all C<urxvt::term> methods on it, but
+and extension package. You can call all C<urxvt::term> methods on it, but
its not a real C<urxvt::term> object. Instead, the real C<urxvt::term>
object that is shared between all packages is stored in the C<term>
-member.
+member. It is, however, blessed intot he package of the extension script,
+so for all practical purposes you can treat an extension script as a class.
All of them must return a boolean value. If it is true, then the event
counts as being I<consumed>, and the invocation of other hooks is skipped,
}
}
-my $script_pkg = "script0000";
-my %script_pkg;
+my $extension_pkg = "extension0000";
+my %extension_pkg;
# load a single script into its own package, once only
-sub script_package($) {
+sub extension_package($) {
my ($path) = @_;
- $script_pkg{$path} ||= do {
- my $pkg = "urxvt::" . ($script_pkg++);
+ $extension_pkg{$path} ||= do {
+ my $pkg = "urxvt::" . ($extension_pkg++);
- verbose 3, "loading script '$path' into package '$pkg'";
+ verbose 3, "loading extension '$path' into package '$pkg'";
open my $fh, "<:raw", $path
or die "$path: $!";
my $source = "package $pkg; use strict; use utf8;\n"
+ . "use base urxvt::term::proxy::;\n"
. "#line 1 \"$path\"\n{\n"
. (do { local $/; <$fh> })
. "\n};\n1";
my @files = grep -f $_, map "$_/$ext", @dirs;
if (@files) {
- register_package script_package $files[0];
+ register_package extension_package $files[0];
} else {
warn "perl extension '$ext' not found in perl library search path\n";
}
keys %$cb;
while (my ($pkg, $cb) = each %$cb) {
- $retval = $cb->(
- $TERM->{_pkg}{$pkg} ||= do {
- my $proxy = bless { }, urxvt::term::proxy::;
- Scalar::Util::weaken ($proxy->{term} = $TERM);
- $proxy
- },
- @_,
- ) and last;
+ eval {
+ $retval = $cb->(
+ $TERM->{_pkg}{$pkg} ||= do {
+ my $proxy = bless { }, $pkg;
+ Scalar::Util::weaken ($proxy->{term} = $TERM);
+ $proxy
+ },
+ @_,
+ ) and last;
+ };
+ warn $@ if $@;#d#
}
}