From 0d2ee1ce46bb54fa2b12092226011b295ba3cd56 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 13 Mar 2010 18:17:12 +0100 Subject: [PATCH] Provide constants for message types --- lib/AnyEvent/I3.pm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index bf25bda4..d2fae1c7 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -30,14 +30,14 @@ Note that as soon as you subscribe to some kind of event, you should B send any more messages as race conditions might occur. Instead, open another connection for that. - use AnyEvent::I3; + use AnyEvent::I3 qw(:all); my $i3 = i3("/tmp/i3-ipc.sock"); $i3->connect->recv; say "Connected to i3"; - my $workspaces = $i3->message(1)->recv; + my $workspaces = $i3->message(TYPE_GET_WORKSPACES)->recv; say "Currently, you use " . @{$workspaces} . " workspaces"; =head1 EXPORT @@ -51,16 +51,23 @@ the UNIX socket to connect to. =cut - use Exporter; use base 'Exporter'; our @EXPORT = qw(i3); +use constant TYPE_COMMAND => 0; +use constant TYPE_GET_WORKSPACES => 1; +use constant TYPE_SUBSCRIBE => 2; + +our %EXPORT_TAGS = ( 'all' => [ + qw(TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE) +] ); + +our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } ); my $magic = "i3-ipc"; -# TODO: export constants for message types # TODO: auto-generate this from the header file? (i3/ipc.h) my $event_mask = (1 << 31); my %events = ( @@ -178,8 +185,7 @@ sub subscribe { Sends a message of the specified C to i3, possibly containing the data structure C, if specified. - my $cv = $i3->message(0, "reload"); - my $reply = $cv->recv; + my $reply = $i3->message(TYPE_COMMAND, "reload")->recv; if ($reply->{success}) { say "Configuration successfully reloaded"; } -- 2.39.2