1AnyEvent::I3(3)       User Contributed Perl Documentation      AnyEvent::I3(3)
2
3
4

NAME

6       AnyEvent::I3 - communicate with the i3 window manager
7

VERSION

9       Version 0.17
10

SYNOPSIS

12       This module connects to the i3 window manager using the UNIX socket
13       based IPC interface it provides (if enabled in the configuration file).
14       You can then subscribe to events or send messages and receive their
15       replies.
16
17           use AnyEvent::I3 qw(:all);
18
19           my $i3 = i3();
20
21           $i3->connect->recv or die "Error connecting";
22           say "Connected to i3";
23
24           my $workspaces = $i3->message(TYPE_GET_WORKSPACES)->recv;
25           say "Currently, you use " . @{$workspaces} . " workspaces";
26
27       ...or, using the sugar methods:
28
29           use AnyEvent::I3;
30
31           my $workspaces = i3->get_workspaces->recv;
32           say "Currently, you use " . @{$workspaces} . " workspaces";
33
34       A somewhat more involved example which dumps the i3 layout tree
35       whenever there is a workspace event:
36
37           use Data::Dumper;
38           use AnyEvent;
39           use AnyEvent::I3;
40
41           my $i3 = i3();
42
43           $i3->connect->recv or die "Error connecting to i3";
44
45           $i3->subscribe({
46               workspace => sub {
47                   $i3->get_tree->cb(sub {
48                       my ($tree) = @_;
49                       say "tree: " . Dumper($tree);
50                   });
51               }
52           })->recv->{success} or die "Error subscribing to events";
53
54           AE::cv->recv
55

EXPORT

57   $i3 = i3([ $path ]);
58       Creates a new "AnyEvent::I3" object and returns it.
59
60       "path" is an optional path of the UNIX socket to connect to. It is
61       strongly advised to NOT specify this unless you're absolutely sure you
62       need it.  "AnyEvent::I3" will automatically figure it out by querying
63       the running i3 instance on the current DISPLAY which is almost always
64       what you want.
65

SUBROUTINES/METHODS

67   $i3 = AnyEvent::I3->new([ $path ])
68       Creates a new "AnyEvent::I3" object and returns it.
69
70       "path" is an optional path of the UNIX socket to connect to. It is
71       strongly advised to NOT specify this unless you're absolutely sure you
72       need it.  "AnyEvent::I3" will automatically figure it out by querying
73       the running i3 instance on the current DISPLAY which is almost always
74       what you want.
75
76   $i3->connect
77       Establishes the connection to i3. Returns an "AnyEvent::CondVar" which
78       will be triggered with a boolean (true if the connection was
79       established) as soon as the connection has been established.
80
81           if ($i3->connect->recv) {
82               say "Connected to i3";
83           }
84
85   $i3->subscribe(\%callbacks)
86       Subscribes to the given event types. This function awaits a hashref
87       with the key being the name of the event and the value being a
88       callback.
89
90           my %callbacks = (
91               workspace => sub { say "Workspaces changed" }
92           );
93
94           if ($i3->subscribe(\%callbacks)->recv->{success}) {
95               say "Successfully subscribed";
96           }
97
98       The special callback with name "_error" is called when the connection
99       to i3 is killed (because of a crash, exit or restart of i3 most
100       likely). You can use it to print an appropriate message and exit
101       cleanly or to try to reconnect.
102
103           my %callbacks = (
104               _error => sub {
105                   my ($msg) = @_;
106                   say "I am sorry. I am so sorry: $msg";
107                   exit 1;
108               }
109           );
110
111           $i3->subscribe(\%callbacks)->recv;
112
113   $i3->message($type, $content)
114       Sends a message of the specified "type" to i3, possibly containing the
115       data structure "content" (or "content", encoded as utf8, if "content"
116       is a scalar), if specified.
117
118           my $reply = $i3->message(TYPE_COMMAND, "reload")->recv;
119           if ($reply->{success}) {
120               say "Configuration successfully reloaded";
121           }
122

SUGAR METHODS

124       These methods intend to make your scripts as beautiful as possible. All
125       of them automatically establish a connection to i3 blockingly (if it
126       does not already exist).
127
128   get_workspaces
129       Gets the current workspaces from i3.
130
131           my $ws = i3->get_workspaces->recv;
132           say Dumper($ws);
133
134   get_outputs
135       Gets the current outputs from i3.
136
137           my $outs = i3->get_outputs->recv;
138           say Dumper($outs);
139
140   get_tree
141       Gets the layout tree from i3 (>= v4.0).
142
143           my $tree = i3->get_tree->recv;
144           say Dumper($tree);
145
146   get_marks
147       Gets all the window identifier marks from i3 (>= v4.1).
148
149           my $marks = i3->get_marks->recv;
150           say Dumper($marks);
151
152   get_bar_config
153       Gets the bar configuration for the specific bar id from i3 (>= v4.1).
154
155           my $config = i3->get_bar_config($id)->recv;
156           say Dumper($config);
157
158   get_version
159       Gets the i3 version via IPC, with a fall-back that parses the output of
160       i3 --version (for i3 < v4.3).
161
162           my $version = i3->get_version()->recv;
163           say "major: " . $version->{major} . ", minor = " . $version->{minor};
164
165   command($content)
166       Makes i3 execute the given command
167
168           my $reply = i3->command("reload")->recv;
169           die "command failed" unless $reply->{success};
170

AUTHOR

172       Michael Stapelberg, "<michael at i3wm.org>"
173

BUGS

175       Please report any bugs or feature requests to "bug-anyevent-i3 at
176       rt.cpan.org", or through the web interface at
177       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-I3>.  I will
178       be notified, and then you'll automatically be notified of progress on
179       your bug as I make changes.
180

SUPPORT

182       You can find documentation for this module with the perldoc command.
183
184           perldoc AnyEvent::I3
185
186       You can also look for information at:
187
188       • RT: CPAN's request tracker
189
190         <http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-I3>
191
192       • The i3 window manager website
193
194         <http://i3wm.org>
195

ACKNOWLEDGEMENTS

198       Copyright 2010-2012 Michael Stapelberg.
199
200       This program is free software; you can redistribute it and/or modify it
201       under the terms of either: the GNU General Public License as published
202       by the Free Software Foundation; or the Artistic License.
203
204       See http://dev.perl.org/licenses/ for more information.
205
206
207
208perl v5.32.1                      2021-01-26                   AnyEvent::I3(3)
Impressum