1AnyEvent::I3(3) User Contributed Perl Documentation AnyEvent::I3(3)
2
3
4
6 AnyEvent::I3 - communicate with the i3 window manager
7
9 Version 0.06
10
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("~/.i3/ipc.sock");
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->workspaces->recv;
32 say "Currently, you use " . @{$workspaces} . " workspaces";
33
35 $i3 = i3([ $path ]);
36 Creates a new "AnyEvent::I3" object and returns it. "path" is the path
37 of the UNIX socket to connect to.
38
40 $i3 = AnyEvent::I3->new([ $path ])
41 Creates a new "AnyEvent::I3" object and returns it. "path" is the path
42 of the UNIX socket to connect to.
43
44 $i3->connect
45 Establishes the connection to i3. Returns an "AnyEvent::CondVar" which
46 will be triggered with a boolean (true if the connection was
47 established) as soon as the connection has been established.
48
49 if ($i3->connect->recv) {
50 say "Connected to i3";
51 }
52
53 $i3->subscribe(\%callbacks)
54 Subscribes to the given event types. This function awaits a hashref
55 with the key being the name of the event and the value being a
56 callback.
57
58 my %callbacks = (
59 workspace => sub { say "Workspaces changed" }
60 );
61
62 if ($i3->subscribe(\%callbacks)->recv->{success})
63 say "Successfully subscribed";
64 }
65
66 The special callback with name "_error" is called when the connection
67 to i3 is killed (because of a crash, exit or restart of i3 most
68 likely). You can use it to print an appropriate message and exit
69 cleanly or to try to reconnect.
70
71 my %callbacks = (
72 _error => sub {
73 my ($msg) = @_;
74 say "I am sorry. I am so sorry: $msg";
75 exit 1;
76 }
77 );
78
79 $i3->subscribe(\%callbacks)->recv;
80
81 $i3->message($type, $content)
82 Sends a message of the specified "type" to i3, possibly containing the
83 data structure "content" (or "content", encoded as utf8, if "content"
84 is a scalar), if specified.
85
86 my $reply = $i3->message(TYPE_COMMAND, "reload")->recv;
87 if ($reply->{success}) {
88 say "Configuration successfully reloaded";
89 }
90
92 These methods intend to make your scripts as beautiful as possible. All
93 of them automatically establish a connection to i3 blockingly (if it
94 does not already exist).
95
96 get_workspaces
97 Gets the current workspaces from i3.
98
99 my $ws = i3->get_workspaces->recv;
100 say Dumper($ws);
101
102 get_outputs
103 Gets the current outputs from i3.
104
105 my $outs = i3->get_outputs->recv;
106 say Dumper($outs);
107
108 command($content)
109 Makes i3 execute the given command
110
111 my $reply = i3->command("reload")->recv;
112 die "command failed" unless $reply->{success};
113
115 Michael Stapelberg, "<michael at stapelberg.de>"
116
118 Please report any bugs or feature requests to "bug-anyevent-i3 at
119 rt.cpan.org", or through the web interface at
120 http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-I3
121 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-I3>. I will
122 be notified, and then you'll automatically be notified of progress on
123 your bug as I make changes.
124
126 You can find documentation for this module with the perldoc command.
127
128 perldoc AnyEvent::I3
129
130 You can also look for information at:
131
132 · RT: CPAN's request tracker
133
134 http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-I3
135 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-I3>
136
137 · The i3 window manager website
138
139 <http://i3.zekjur.net/>
140
143 Copyright 2010 Michael Stapelberg.
144
145 This program is free software; you can redistribute it and/or modify it
146 under the terms of either: the GNU General Public License as published
147 by the Free Software Foundation; or the Artistic License.
148
149 See http://dev.perl.org/licenses/ for more information.
150
151
152
153perl v5.12.1 2010-06-16 AnyEvent::I3(3)