Prima::EventHook(3)
π Prima::EventHook π
okay bestie so picture this: this is the page for Prima::EventHook, straight out of the User Contributed Perl Documentation corner of the Prima-verse β¨ it's the whole event-filtering situation, and honestly? it ate. let me walk you through it π«Ά
πΈ NAME πΈ
Prima::EventHook β event filtering, and like... good event filtering π
β¨ SYNOPSIS β¨
okay so here's the whole vibe in code, no notes needed:
use Prima::EventHook;
sub hook
{
my ( $my_param, $object, $event, @params) = @_;
...
print "Object $object received event $event\n";
...
return 1;
}
Prima::EventHook::install( \&hook,
param => $my_param,
object => $my_window,
event => [qw(Size Move Destroy)],
children => 1
);
Prima::EventHook::deinstall(\&hook);
like, install it, let it cook, deinstall it when you're done. iconic behavior π
π¦ DESCRIPTION π¦
so here's the tea β β the toolkit dispatches notifications by calling subroutines registered on one or more objects. that's the normal way. but ALSO, the core part of the toolkit lets you install a single event hook callback that would receive all events occurring on all objects. literally all of them. main character callback energy π
Prima::EventHook provides multiplexed access to that core event hook, and it introduces a whole set of dispatching rules so your user hooks only receive a subset of events. it's giving bouncer-at-the-club, but make it perl. π
β API β
π install SUB, %RULES
installs SUB using a hash of RULES.
SUB gets called with a variable list of parameters, formed in this exact order, bestie, do not shuffle:
- first come the parameters from the
paramkey (see below π) - then the event source object
- then the event name
- and finally the parameters to the event
and SUB must return an integer β either 0 or 1 β to block or pass the event, respectively. if 1 is returned, other hook subs are called; if 0 is returned, the event is efficiently blocked and no hooks are called further. slam the door, periodt. πͺπ
rules can contain the following keys:
eventβ an event is either a string, an array of strings, or anundefvalue. in the latter case it's equal to a'*'string which selects all events to be passed to the SUB. a string is either the name of an event or one of the pre-defined event groups, declared in the%groupspackage hash. the group names are:
ability
focus
geometry
keyboard
menu
mouse
objects
visibility
these contain the respective events. see the source for a detailed description. π
in case the 'event' key is an array of strings, each of the strings is also the name of either an event or a group. in this case, if the '*' string or event duplicate names are present in the list, SUB is called several times. yes, several. no, that's not a bug, that's just how it is π
objectβ a Prima object, or an array of Prima objects, orundef; in the latter case it matches all objects. if an object is defined, the SUB is called if the event source is the same as the object. simple as that πββοΈchildrenβ if1, SUB is called using the same rules as described in'object', but also if the event source is a child of the object. so like, selectingundefas a filter object and setting'children'to0is almost the same as selecting$::applicationβ which is the root of the Prima object hierarchy β as a filter object with'children'set to1. cute symmetry, right? π§
ok but heads up: settingobjecttoundefandchildrento1is inefficient. like, it works, but it's giving "walking to the airport instead of taking a flight" π just so you know.
paramβ a scalar or array of scalars passed as first parameters to SUB π
π deinstall SUB
removes the hook sub. bye bestie, it was fun π«Ά
π₯ NOTES π₯
Prima::EventHook by default automatically starts and stops the Prima event hook mechanism when appropriate. like, it handles its own business, you don't gotta micromanage it.
but if that's not desired β for example, for your own event hook management β set $auto_hook to 0. your call, your vibes πβ
π AUTHOR π
Dmitry Karasik, <dmitry@karasik.eu.org>. the legend who made this happen π
π¦ SEE ALSO π¦
PrimaPrima::Object
go read them, iykβyk π
and that's the whole page, bestie β written by perl v5.42.0 and dated 2024-08-20, which is literally the page's little timestamp birthday π so yeah, that's everything. slay, go filter some events β¨π
π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms