From 632bdb7d2a3ab9b779cc7e3e33b88dff419265ee Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 13 Mar 2010 17:11:09 +0100 Subject: [PATCH 01/56] Initial commit --- Changes | 5 + MANIFEST | 9 ++ Makefile.PL | 12 +++ README | 55 ++++++++++ ignore.txt | 12 +++ lib/AnyEvent/I3.pm | 257 +++++++++++++++++++++++++++++++++++++++++++++ t/00-load.t | 10 ++ t/01-workspaces.t | 12 +++ t/boilerplate.t | 55 ++++++++++ t/manifest.t | 13 +++ t/pod-coverage.t | 18 ++++ t/pod.t | 12 +++ 12 files changed, 470 insertions(+) create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README create mode 100644 ignore.txt create mode 100644 lib/AnyEvent/I3.pm create mode 100644 t/00-load.t create mode 100644 t/01-workspaces.t create mode 100644 t/boilerplate.t create mode 100644 t/manifest.t create mode 100644 t/pod-coverage.t create mode 100644 t/pod.t diff --git a/Changes b/Changes new file mode 100644 index 00000000..7071c737 --- /dev/null +++ b/Changes @@ -0,0 +1,5 @@ +Revision history for AnyEvent-I3 + +0.01 Date/time + First version, released on an unsuspecting world. + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 00000000..7087a287 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,9 @@ +Changes +MANIFEST +Makefile.PL +README +lib/AnyEvent/I3.pm +t/00-load.t +t/manifest.t +t/pod-coverage.t +t/pod.t diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 00000000..2082ce24 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,12 @@ +use inc::Module::Install; + +name 'AnyEvent-I3'; +all_from 'lib/AnyEvent/I3.pm'; +author 'Michael Stapelberg'; + +requires 'AnyEvent'; +requires 'AnyEvent::Handle'; +requires 'AnyEvent::Socket'; +requires 'JSON::XS'; + +WriteAll; diff --git a/README b/README new file mode 100644 index 00000000..3aff4b15 --- /dev/null +++ b/README @@ -0,0 +1,55 @@ +AnyEvent-I3 + +The README is used to introduce the module and provide instructions on +how to install the module, any machine dependencies it may have (for +example C compilers and installed libraries) and any other information +that should be provided before the module is installed. + +A README file is required for CPAN modules since CPAN extracts the README +file from a module distribution so that people browsing the archive +can use it to get an idea of the module's uses. It is usually a good idea +to provide version information here so that people can decide whether +fixes for the module are worth downloading. + + +INSTALLATION + +To install this module, run the following commands: + + perl Makefile.PL + make + make test + make install + +SUPPORT AND DOCUMENTATION + +After installing, you can find documentation for this module with the +perldoc command. + + perldoc AnyEvent::I3 + +You can also look for information at: + + RT, CPAN's request tracker + http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-I3 + + AnnoCPAN, Annotated CPAN documentation + http://annocpan.org/dist/AnyEvent-I3 + + CPAN Ratings + http://cpanratings.perl.org/d/AnyEvent-I3 + + Search CPAN + http://search.cpan.org/dist/AnyEvent-I3/ + + +LICENSE AND COPYRIGHT + +Copyright (C) 2010 Michael Stapelberg + +This program is free software; you can redistribute it and/or modify it +under the terms of either: the GNU General Public License as published +by the Free Software Foundation; or the Artistic License. + +See http://dev.perl.org/licenses/ for more information. + diff --git a/ignore.txt b/ignore.txt new file mode 100644 index 00000000..01d97f8a --- /dev/null +++ b/ignore.txt @@ -0,0 +1,12 @@ +blib* +Makefile +Makefile.old +Build +Build.bat +_build* +pm_to_blib* +*.tar.gz +.lwpcookies +cover_db +pod2htm*.tmp +AnyEvent-I3-* diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm new file mode 100644 index 00000000..f365d394 --- /dev/null +++ b/lib/AnyEvent/I3.pm @@ -0,0 +1,257 @@ +package AnyEvent::I3; +# vim:ts=4:sw=4:expandtab + +use strict; +use warnings; +use JSON::XS; +use AnyEvent::Handle; +use AnyEvent::Socket; +use AnyEvent; + +=head1 NAME + +AnyEvent::I3 - communicate with the i3 window manager + +=cut + +our $VERSION = '0.01'; + +=head1 VERSION + +Version 0.01 + +=head1 SYNOPSIS + +This module connects to the i3 window manager using the UNIX socket based +IPC interface it provides (if enabled in the configuration file). You can +then subscribe to events or send messages and receive their replies. + +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; + + my $i3 = i3("/tmp/i3-ipc.sock"); + + $i3->connect->recv; + say "Connected to i3"; + + my $workspaces = $i3->message(1)->recv; + say "Currently, you use " . @{$workspaces} . " workspaces"; + +=head1 EXPORT + +=head2 $i3 = i3([ $path ]); + +Creates a new C object and returns it. C is the path of +the UNIX socket to connect to. + +=head1 SUBROUTINES/METHODS + +=cut + + +use Exporter; +use base 'Exporter'; + +our @EXPORT = qw(i3); + + +my $magic = "i3-ipc"; + +# TODO: auto-generate this from the header file? (i3/ipc.h) +my $event_mask = (1 << 31); +my %events = ( + workspace => ($event_mask | 0), +); + +sub bytelength { + my ($scalar) = @_; + use bytes; + length($scalar) +} + +sub i3 { + AnyEvent::I3->new(@_) +} + +=head2 $i3 = AnyEvent::I3->new([ $path ]) + +Creates a new C object and returns it. C is the path of +the UNIX socket to connect to. + +=cut +sub new { + my ($class, $path) = @_; + + $path ||= '/tmp/i3-ipc.sock'; + + bless { path => $path } => $class; +} + +=head2 $i3->connect + +Establishes the connection to i3. Returns an C which will +be triggered as soon as the connection has been established. + +=cut +sub connect { + my ($self) = @_; + my $hdl; + my $cv = AnyEvent->condvar; + + tcp_connect "unix/", $self->{path}, sub { + my ($fh) = @_; + + $self->{ipchdl} = AnyEvent::Handle->new( + fh => $fh, + on_read => sub { my ($hdl) = @_; $self->data_available($hdl) } + ); + + $cv->send + }; + + $cv +} + +sub data_available { + my ($self, $hdl) = @_; + + $hdl->unshift_read( + chunk => length($magic) + 4 + 4, + sub { + my $header = $_[1]; + # Unpack message length and read the payload + my ($len, $type) = unpack("LL", substr($header, length($magic))); + $hdl->unshift_read( + chunk => $len, + sub { $self->handle_i3_message($type, $_[1]) } + ); + } + ); +} + +sub handle_i3_message { + my ($self, $type, $payload) = @_; + + return unless defined($self->{callbacks}->{$type}); + + my $cb = $self->{callbacks}->{$type}; + $cb->(decode_json $payload); +} + +=head2 $i3->subscribe(\%callbacks) + +Subscribes to the given event types. This function awaits a hashref with the +key being the name of the event and the value being a callback. + + $i3->subscribe({ + workspace => sub { say "Workspaces changed" } + }); + +=cut +sub subscribe { + my ($self, $callbacks) = @_; + + my $payload = encode_json [ keys %{$callbacks} ]; + my $message = $magic . pack("LL", bytelength($payload), 2) . $payload; + $self->{ipchdl}->push_write($message); + + # Register callbacks for each message type + for my $key (keys %{$callbacks}) { + my $type = $events{$key}; + $self->{callbacks}->{$type} = $callbacks->{$key}; + } +} + +=head2 $i3->message($type, $content) + +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; + if ($reply->{success}) { + say "Configuration successfully reloaded"; + } + +=cut +sub message { + my ($self, $type, $content) = @_; + + die "No message type specified" unless $type; + + my $payload = ""; + if ($content) { + if (ref($content) eq "SCALAR") { + $payload = $content; + } else { + $payload = encode_json $content; + } + } + my $message = $magic . pack("LL", bytelength($payload), $type) . $payload; + $self->{ipchdl}->push_write($message); + + my $cv = AnyEvent->condvar; + + # We don’t preserve the old callback as it makes no sense to + # have a callback on message reply types (only on events) + $self->{callbacks}->{$type} = + sub { + my ($reply) = @_; + $cv->send($reply); + undef $self->{callbacks}->{$type}; + }; + + $cv +} + +=head1 AUTHOR + +Michael Stapelberg, C<< >> + +=head1 BUGS + +Please report any bugs or feature requests to C, or through +the web interface at L. I will be notified, and then you'll +automatically be notified of progress on your bug as I make changes. + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc AnyEvent::I3 + +You can also look for information at: + +=over 2 + +=item * RT: CPAN's request tracker + +L + +=item * The i3 window manager website + +L + +=back + + +=head1 ACKNOWLEDGEMENTS + + +=head1 LICENSE AND COPYRIGHT + +Copyright 2010 Michael Stapelberg. + +This program is free software; you can redistribute it and/or modify it +under the terms of either: the GNU General Public License as published +by the Free Software Foundation; or the Artistic License. + +See http://dev.perl.org/licenses/ for more information. + + +=cut + +1; # End of AnyEvent::I3 diff --git a/t/00-load.t b/t/00-load.t new file mode 100644 index 00000000..4bf6151e --- /dev/null +++ b/t/00-load.t @@ -0,0 +1,10 @@ +#!perl -T + +use Test::More tests => 1; + +BEGIN { + use_ok( 'AnyEvent::I3' ) || print "Bail out! +"; +} + +diag( "Testing AnyEvent::I3 $AnyEvent::I3::VERSION, Perl $], $^X" ); diff --git a/t/01-workspaces.t b/t/01-workspaces.t new file mode 100644 index 00000000..5e708d13 --- /dev/null +++ b/t/01-workspaces.t @@ -0,0 +1,12 @@ +#!perl -T + +use Test::More tests => 1; +use AnyEvent::I3; + +my $i3 = i3(); +my $cv = $i3->connect; +$cv->recv; + +ok(1, "connected"); + +diag( "Testing AnyEvent::I3 $AnyEvent::I3::VERSION, Perl $], $^X" ); diff --git a/t/boilerplate.t b/t/boilerplate.t new file mode 100644 index 00000000..effb65b6 --- /dev/null +++ b/t/boilerplate.t @@ -0,0 +1,55 @@ +#!perl -T + +use strict; +use warnings; +use Test::More tests => 3; + +sub not_in_file_ok { + my ($filename, %regex) = @_; + open( my $fh, '<', $filename ) + or die "couldn't open $filename for reading: $!"; + + my %violated; + + while (my $line = <$fh>) { + while (my ($desc, $regex) = each %regex) { + if ($line =~ $regex) { + push @{$violated{$desc}||=[]}, $.; + } + } + } + + if (%violated) { + fail("$filename contains boilerplate text"); + diag "$_ appears on lines @{$violated{$_}}" for keys %violated; + } else { + pass("$filename contains no boilerplate text"); + } +} + +sub module_boilerplate_ok { + my ($module) = @_; + not_in_file_ok($module => + 'the great new $MODULENAME' => qr/ - The great new /, + 'boilerplate description' => qr/Quick summary of what the module/, + 'stub function definition' => qr/function[12]/, + ); +} + +TODO: { + local $TODO = "Need to replace the boilerplate text"; + + not_in_file_ok(README => + "The README is used..." => qr/The README is used/, + "'version information here'" => qr/to provide version information/, + ); + + not_in_file_ok(Changes => + "placeholder date/time" => qr(Date/time) + ); + + module_boilerplate_ok('lib/AnyEvent/I3.pm'); + + +} + diff --git a/t/manifest.t b/t/manifest.t new file mode 100644 index 00000000..45eb83fd --- /dev/null +++ b/t/manifest.t @@ -0,0 +1,13 @@ +#!perl -T + +use strict; +use warnings; +use Test::More; + +unless ( $ENV{RELEASE_TESTING} ) { + plan( skip_all => "Author tests not required for installation" ); +} + +eval "use Test::CheckManifest 0.9"; +plan skip_all => "Test::CheckManifest 0.9 required" if $@; +ok_manifest(); diff --git a/t/pod-coverage.t b/t/pod-coverage.t new file mode 100644 index 00000000..fc40a57c --- /dev/null +++ b/t/pod-coverage.t @@ -0,0 +1,18 @@ +use strict; +use warnings; +use Test::More; + +# Ensure a recent version of Test::Pod::Coverage +my $min_tpc = 1.08; +eval "use Test::Pod::Coverage $min_tpc"; +plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage" + if $@; + +# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version, +# but older versions don't recognize some common documentation styles +my $min_pc = 0.18; +eval "use Pod::Coverage $min_pc"; +plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage" + if $@; + +all_pod_coverage_ok(); diff --git a/t/pod.t b/t/pod.t new file mode 100644 index 00000000..ee8b18ad --- /dev/null +++ b/t/pod.t @@ -0,0 +1,12 @@ +#!perl -T + +use strict; +use warnings; +use Test::More; + +# Ensure a recent version of Test::Pod +my $min_tp = 1.22; +eval "use Test::Pod $min_tp"; +plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; + +all_pod_files_ok(); From 5c9e2833b6d8f3128d3c94ebb7113a7a7e6f50d3 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 13 Mar 2010 17:19:38 +0100 Subject: [PATCH 02/56] prefix internal subs with _ --- lib/AnyEvent/I3.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index f365d394..c11acf01 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -66,7 +66,7 @@ my %events = ( workspace => ($event_mask | 0), ); -sub bytelength { +sub _bytelength { my ($scalar) = @_; use bytes; length($scalar) @@ -106,7 +106,7 @@ sub connect { $self->{ipchdl} = AnyEvent::Handle->new( fh => $fh, - on_read => sub { my ($hdl) = @_; $self->data_available($hdl) } + on_read => sub { my ($hdl) = @_; $self->_data_available($hdl) } ); $cv->send @@ -115,7 +115,7 @@ sub connect { $cv } -sub data_available { +sub _data_available { my ($self, $hdl) = @_; $hdl->unshift_read( @@ -126,13 +126,13 @@ sub data_available { my ($len, $type) = unpack("LL", substr($header, length($magic))); $hdl->unshift_read( chunk => $len, - sub { $self->handle_i3_message($type, $_[1]) } + sub { $self->_handle_i3_message($type, $_[1]) } ); } ); } -sub handle_i3_message { +sub _handle_i3_message { my ($self, $type, $payload) = @_; return unless defined($self->{callbacks}->{$type}); @@ -155,7 +155,7 @@ sub subscribe { my ($self, $callbacks) = @_; my $payload = encode_json [ keys %{$callbacks} ]; - my $message = $magic . pack("LL", bytelength($payload), 2) . $payload; + my $message = $magic . pack("LL", _bytelength($payload), 2) . $payload; $self->{ipchdl}->push_write($message); # Register callbacks for each message type @@ -190,7 +190,7 @@ sub message { $payload = encode_json $content; } } - my $message = $magic . pack("LL", bytelength($payload), $type) . $payload; + my $message = $magic . pack("LL", _bytelength($payload), $type) . $payload; $self->{ipchdl}->push_write($message); my $cv = AnyEvent->condvar; From 7d92e2c3e2589560632fc49446466f5a6aa0a27d Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 13 Mar 2010 17:21:52 +0100 Subject: [PATCH 03/56] kill boilerplate --- Changes | 2 +- README | 25 +++++-------------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/Changes b/Changes index 7071c737..0dc96033 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,5 @@ Revision history for AnyEvent-I3 -0.01 Date/time +0.01 2010-03-13 First version, released on an unsuspecting world. diff --git a/README b/README index 3aff4b15..4658ba16 100644 --- a/README +++ b/README @@ -1,16 +1,8 @@ AnyEvent-I3 -The README is used to introduce the module and provide instructions on -how to install the module, any machine dependencies it may have (for -example C compilers and installed libraries) and any other information -that should be provided before the module is installed. - -A README file is required for CPAN modules since CPAN extracts the README -file from a module distribution so that people browsing the archive -can use it to get an idea of the module's uses. It is usually a good idea -to provide version information here so that people can decide whether -fixes for the module are worth downloading. - +This module connects to the i3 window manager using the UNIX socket based +IPC interface it provides (if enabled in the configuration file). You can +then subscribe to events or send messages and receive their replies. INSTALLATION @@ -33,14 +25,8 @@ You can also look for information at: RT, CPAN's request tracker http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-I3 - AnnoCPAN, Annotated CPAN documentation - http://annocpan.org/dist/AnyEvent-I3 - - CPAN Ratings - http://cpanratings.perl.org/d/AnyEvent-I3 - - Search CPAN - http://search.cpan.org/dist/AnyEvent-I3/ + The i3 window manager website + http://i3.zekjur.net/ LICENSE AND COPYRIGHT @@ -52,4 +38,3 @@ under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. - From 279528a863906638b677a319bacf3a362d168419 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 13 Mar 2010 17:38:32 +0100 Subject: [PATCH 04/56] Return connection status in condvar in $i3->connect --- lib/AnyEvent/I3.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index c11acf01..bf25bda4 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -60,6 +60,7 @@ our @EXPORT = qw(i3); 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 = ( @@ -93,7 +94,12 @@ sub new { =head2 $i3->connect Establishes the connection to i3. Returns an C which will -be triggered as soon as the connection has been established. +be triggered with a boolean (true if the connection was established) as soon as +the connection has been established. + + if ($i3->connect->recv) { + say "Connected to i3"; + } =cut sub connect { @@ -104,12 +110,14 @@ sub connect { tcp_connect "unix/", $self->{path}, sub { my ($fh) = @_; + return $cv->send(0) unless $fh; + $self->{ipchdl} = AnyEvent::Handle->new( fh => $fh, on_read => sub { my ($hdl) = @_; $self->_data_available($hdl) } ); - $cv->send + $cv->send(1) }; $cv From 1044c9814b0fa3b49bf81b33a39dac7ec2fc1273 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 13 Mar 2010 17:38:59 +0100 Subject: [PATCH 05/56] Expand testcase for the get_workspaces message (needs i3 to be running) --- t/01-workspaces.t | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/t/01-workspaces.t b/t/01-workspaces.t index 5e708d13..f3206d89 100644 --- a/t/01-workspaces.t +++ b/t/01-workspaces.t @@ -1,12 +1,29 @@ #!perl -T +# vim:ts=4:sw=4:expandtab -use Test::More tests => 1; +use Test::More tests => 3; use AnyEvent::I3; +use AnyEvent; my $i3 = i3(); -my $cv = $i3->connect; -$cv->recv; +my $cv = AnyEvent->condvar; -ok(1, "connected"); +# Try to connect to i3 +$i3->connect->cb(sub { my ($v) = @_; $cv->send($v->recv) }); + +# But cancel if we are not connected after 0.5 seconds +my $t = AnyEvent->timer(after => 0.5, cb => sub { $cv->send(0) }); +my $connected = $cv->recv; + +SKIP: { + skip 'No connection to i3', 3 unless $connected; + + my $workspaces = $i3->message(1)->recv; + isa_ok($workspaces, 'ARRAY'); + + ok(@{$workspaces} > 0, 'More than zero workspaces found'); + + ok(defined(@{$workspaces}[0]->{num}), 'JSON deserialized'); +} diag( "Testing AnyEvent::I3 $AnyEvent::I3::VERSION, Perl $], $^X" ); From e35d6039d75cde4d0002db9f4b4d97f1ec4522f5 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 13 Mar 2010 18:17:12 +0100 Subject: [PATCH 06/56] 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"; } From 4c6b8f91e02de962edbfea7278419329ad48aa08 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 13 Mar 2010 18:27:32 +0100 Subject: [PATCH 07/56] Update MANIFEST --- MANIFEST | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/MANIFEST b/MANIFEST index 7087a287..61ca8577 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,9 +1,22 @@ Changes -MANIFEST -Makefile.PL -README +ignore.txt +inc/Module/Install.pm +inc/Module/Install/Base.pm +inc/Module/Install/Can.pm +inc/Module/Install/Fetch.pm +inc/Module/Install/Makefile.pm +inc/Module/Install/Metadata.pm +inc/Module/Install/Win32.pm +inc/Module/Install/WriteAll.pm lib/AnyEvent/I3.pm +Makefile.PL +MANIFEST +META.yml +README t/00-load.t +t/01-workspaces.t +t/02-constants.t +t/boilerplate.t t/manifest.t t/pod-coverage.t t/pod.t From f6a26056104ea31f273c492ae13b4f534ec58c3a Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 13 Mar 2010 18:30:46 +0100 Subject: [PATCH 08/56] update MANIFEST correctly (use MANIFEST.SKIP instead of ignore.txt) --- MANIFEST | 5 +---- MANIFEST.SKIP | 11 +++++++++++ ignore.txt | 12 ------------ 3 files changed, 12 insertions(+), 16 deletions(-) create mode 100644 MANIFEST.SKIP delete mode 100644 ignore.txt diff --git a/MANIFEST b/MANIFEST index 61ca8577..c9c9c27c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,21 +1,18 @@ Changes -ignore.txt inc/Module/Install.pm inc/Module/Install/Base.pm inc/Module/Install/Can.pm inc/Module/Install/Fetch.pm -inc/Module/Install/Makefile.pm inc/Module/Install/Metadata.pm inc/Module/Install/Win32.pm inc/Module/Install/WriteAll.pm lib/AnyEvent/I3.pm -Makefile.PL MANIFEST +MANIFEST.SKIP META.yml README t/00-load.t t/01-workspaces.t -t/02-constants.t t/boilerplate.t t/manifest.t t/pod-coverage.t diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 00000000..f58f7ef8 --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,11 @@ +^\.git/ +\.bak$ +blib/ +Makefile +Makefile.old +Build +Build.bat +^pm_to_blib +\.tar\.gz$ +^pod2htm(.*).tmp$ +^AnyEvent-I3- diff --git a/ignore.txt b/ignore.txt deleted file mode 100644 index 01d97f8a..00000000 --- a/ignore.txt +++ /dev/null @@ -1,12 +0,0 @@ -blib* -Makefile -Makefile.old -Build -Build.bat -_build* -pm_to_blib* -*.tar.gz -.lwpcookies -cover_db -pod2htm*.tmp -AnyEvent-I3-* From e3f0e5b01ca13080a6b89d6f3c7da16e70782230 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 19 Mar 2010 22:35:19 +0100 Subject: [PATCH 09/56] Add new constants --- lib/AnyEvent/I3.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index d2fae1c7..9c8cbbdc 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -59,9 +59,10 @@ our @EXPORT = qw(i3); use constant TYPE_COMMAND => 0; use constant TYPE_GET_WORKSPACES => 1; use constant TYPE_SUBSCRIBE => 2; +use constant TYPE_GET_OUTPUTS => 3; our %EXPORT_TAGS = ( 'all' => [ - qw(TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE) + qw(i3 TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE TYPE_GET_OUTPUTS) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } ); @@ -72,6 +73,7 @@ my $magic = "i3-ipc"; my $event_mask = (1 << 31); my %events = ( workspace => ($event_mask | 0), + output => ($event_mask | 1), ); sub _bytelength { From 8b2db9a238ae2c37968646af74ca97b1f2fb8d82 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 22 Mar 2010 21:37:33 +0100 Subject: [PATCH 10/56] Bugfix: Handle message_type == 0 --- lib/AnyEvent/I3.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 9c8cbbdc..7296a9c5 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -196,7 +196,7 @@ structure C, if specified. sub message { my ($self, $type, $content) = @_; - die "No message type specified" unless $type; + die "No message type specified" unless defined($type); my $payload = ""; if ($content) { From 460f09915f61d4af44eec3c4ef9b729e6efac501 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 22 Mar 2010 21:37:44 +0100 Subject: [PATCH 11/56] Get rid of _bytelength, use encode_utf8 and length instead. Correctly check for scalar --- lib/AnyEvent/I3.pm | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 7296a9c5..2addeb34 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -7,6 +7,7 @@ use JSON::XS; use AnyEvent::Handle; use AnyEvent::Socket; use AnyEvent; +use Encode; =head1 NAME @@ -76,12 +77,6 @@ my %events = ( output => ($event_mask | 1), ); -sub _bytelength { - my ($scalar) = @_; - use bytes; - length($scalar) -} - sub i3 { AnyEvent::I3->new(@_) } @@ -172,7 +167,7 @@ sub subscribe { my ($self, $callbacks) = @_; my $payload = encode_json [ keys %{$callbacks} ]; - my $message = $magic . pack("LL", _bytelength($payload), 2) . $payload; + my $message = $magic . pack("LL", length($payload), 2) . $payload; $self->{ipchdl}->push_write($message); # Register callbacks for each message type @@ -185,7 +180,8 @@ sub subscribe { =head2 $i3->message($type, $content) Sends a message of the specified C to i3, possibly containing the data -structure C, if specified. +structure C (or C, encoded as utf8, if C is a +scalar), if specified. my $reply = $i3->message(TYPE_COMMAND, "reload")->recv; if ($reply->{success}) { @@ -200,13 +196,14 @@ sub message { my $payload = ""; if ($content) { - if (ref($content) eq "SCALAR") { - $payload = $content; + if (not ref($content)) { + # Convert from Perl’s internal encoding to UTF8 octets + $payload = encode_utf8($content); } else { $payload = encode_json $content; } } - my $message = $magic . pack("LL", _bytelength($payload), $type) . $payload; + my $message = $magic . pack("LL", length($payload), $type) . $payload; $self->{ipchdl}->push_write($message); my $cv = AnyEvent->condvar; From 4ba7259f6a60be3ba350d14b5682b9d99807aa57 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 22 Mar 2010 21:42:35 +0100 Subject: [PATCH 12/56] use constant instead of magic number --- lib/AnyEvent/I3.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 2addeb34..e69604a8 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -167,7 +167,8 @@ sub subscribe { my ($self, $callbacks) = @_; my $payload = encode_json [ keys %{$callbacks} ]; - my $message = $magic . pack("LL", length($payload), 2) . $payload; + my $len = length($payload); + my $message = $magic . pack("LL", $len, TYPE_SUBSCRIBE) . $payload; $self->{ipchdl}->push_write($message); # Register callbacks for each message type From 98e32d39a561aefc39ee2c676a8b332c36b50765 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 22 Mar 2010 21:43:05 +0100 Subject: [PATCH 13/56] reformat perldoc paragraph --- lib/AnyEvent/I3.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index e69604a8..3a82552d 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -227,9 +227,11 @@ Michael Stapelberg, C<< >> =head1 BUGS -Please report any bugs or feature requests to C, or through -the web interface at L. I will be notified, and then you'll -automatically be notified of progress on your bug as I make changes. +Please report any bugs or feature requests to C, or through the web interface at +L. I will be +notified, and then you'll automatically be notified of progress on your bug as +I make changes. =head1 SUPPORT From 7ffa4bea31a11ea79f89a27bd7d6897182590701 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 22 Mar 2010 21:50:41 +0100 Subject: [PATCH 14/56] Use only 'import' of 'Exporter' --- lib/AnyEvent/I3.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 3a82552d..bb7c3d92 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -52,7 +52,7 @@ the UNIX socket to connect to. =cut -use Exporter; +use Exporter qw(import); use base 'Exporter'; our @EXPORT = qw(i3); From b57fca1ef9b61b9cd6bbb519adf59f146cabe5fb Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 22 Mar 2010 22:22:46 +0100 Subject: [PATCH 15/56] kill left-over variable --- lib/AnyEvent/I3.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index bb7c3d92..282f24a5 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -108,7 +108,6 @@ the connection has been established. =cut sub connect { my ($self) = @_; - my $hdl; my $cv = AnyEvent->condvar; tcp_connect "unix/", $self->{path}, sub { From 1aac4d3f14864b9c08f50e3852c59d9677f12a0e Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 22 Mar 2010 22:33:26 +0100 Subject: [PATCH 16/56] Use $self->message in subscribe --- lib/AnyEvent/I3.pm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 282f24a5..310fa5ef 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -157,24 +157,25 @@ sub _handle_i3_message { Subscribes to the given event types. This function awaits a hashref with the key being the name of the event and the value being a callback. - $i3->subscribe({ + my %callbacks = ( workspace => sub { say "Workspaces changed" } - }); + ); + + if ($i3->subscribe(\%callbacks)->recv->{success}) + say "Successfully subscribed"; + } =cut sub subscribe { my ($self, $callbacks) = @_; - my $payload = encode_json [ keys %{$callbacks} ]; - my $len = length($payload); - my $message = $magic . pack("LL", $len, TYPE_SUBSCRIBE) . $payload; - $self->{ipchdl}->push_write($message); - # Register callbacks for each message type for my $key (keys %{$callbacks}) { my $type = $events{$key}; $self->{callbacks}->{$type} = $callbacks->{$key}; } + + $self->message(TYPE_SUBSCRIBE, [ keys %{$callbacks} ]) } =head2 $i3->message($type, $content) From 45eef6bdf7e2718a2e0cf3e4ba3b247b2eb5199f Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 22 Mar 2010 23:22:42 +0100 Subject: [PATCH 17/56] Remove obsolete paragraph about the need for a second connection Due to the event-based handling of incoming data from i3 we do not suffer from this problem. --- lib/AnyEvent/I3.pm | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 310fa5ef..d763357c 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -27,10 +27,6 @@ This module connects to the i3 window manager using the UNIX socket based IPC interface it provides (if enabled in the configuration file). You can then subscribe to events or send messages and receive their replies. -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 qw(:all); my $i3 = i3("/tmp/i3-ipc.sock"); From d137f834528f99fcb91adeda73bd29a27e5c506f Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 22 Mar 2010 23:23:07 +0100 Subject: [PATCH 18/56] Add sugar methods for easier usage --- lib/AnyEvent/I3.pm | 74 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index d763357c..5df58257 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -31,12 +31,20 @@ then subscribe to events or send messages and receive their replies. my $i3 = i3("/tmp/i3-ipc.sock"); - $i3->connect->recv; + $i3->connect->recv or die "Error connecting"; say "Connected to i3"; my $workspaces = $i3->message(TYPE_GET_WORKSPACES)->recv; say "Currently, you use " . @{$workspaces} . " workspaces"; +...or, using the sugar methods: + + use AnyEvent::I3; + + my $i3 = i3; + my $workspaces = $i3->workspaces->recv; + say "Currently, you use " . @{$workspaces} . " workspaces"; + =head1 EXPORT =head2 $i3 = i3([ $path ]); @@ -217,6 +225,70 @@ sub message { $cv } +=head1 SUGAR METHODS + +These methods intend to make your scripts as beautiful as possible. All of +them automatically establish a connection to i3 blockingly (if it does not +already exist). + +=cut + +sub _ensure_connection { + my ($self) = @_; + + return if defined($self->{ipchdl}); + + $self->connect->recv or die "Unable to connect to i3" +} + +=head2 get_workspaces + +Gets the current workspaces from i3. + + my $ws = i3->get_workspaces->recv; + say Dumper($ws); + +=cut +sub get_workspaces { + my ($self) = @_; + + $self->_ensure_connection; + + $self->message(TYPE_GET_WORKSPACES) +} + +=head2 get_outputs + +Gets the current outputs from i3. + + my $outs = i3->get_outputs->recv; + say Dumper($outs); + +=cut +sub get_outputs { + my ($self) = @_; + + $self->_ensure_connection; + + $self->message(TYPE_GET_OUTPUTS) +} + +=head2 command($content) + +Makes i3 execute the given command + + my $reply = i3->command("reload")->recv; + die "command failed" unless $reply->{success}; + +=cut +sub command { + my ($self, $content) = @_; + + $self->_ensure_connection; + + $self->message(TYPE_COMMAND, $content) +} + =head1 AUTHOR Michael Stapelberg, C<< >> From e34675c3c7ee62a8d77e20627c1c824272ca16ab Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 23 Mar 2010 02:04:28 +0100 Subject: [PATCH 19/56] Implement _error callback --- lib/AnyEvent/I3.pm | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 5df58257..a09c7512 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -41,8 +41,7 @@ then subscribe to events or send messages and receive their replies. use AnyEvent::I3; - my $i3 = i3; - my $workspaces = $i3->workspaces->recv; + my $workspaces = i3->workspaces->recv; say "Currently, you use " . @{$workspaces} . " workspaces"; =head1 EXPORT @@ -79,6 +78,7 @@ my $event_mask = (1 << 31); my %events = ( workspace => ($event_mask | 0), output => ($event_mask | 1), + _error => 0xFFFFFFFF, ); sub i3 { @@ -121,7 +121,25 @@ sub connect { $self->{ipchdl} = AnyEvent::Handle->new( fh => $fh, - on_read => sub { my ($hdl) = @_; $self->_data_available($hdl) } + on_read => sub { my ($hdl) = @_; $self->_data_available($hdl) }, + on_error => sub { + my ($hdl, $fatal, $msg) = @_; + delete $self->{ipchdl}; + $hdl->destroy; + + my $cb = $self->{callbacks}; + + # Trigger all one-time callbacks with undef + for my $type (keys %{$cb}) { + next if ($type & $event_mask) == $event_mask; + $cb->{$type}->(); + } + + # Trigger _error callback, if set + my $type = $events{_error}; + return unless defined($cb->{$type}); + $cb->{$type}->($msg); + } ); $cv->send(1) @@ -154,6 +172,12 @@ sub _handle_i3_message { my $cb = $self->{callbacks}->{$type}; $cb->(decode_json $payload); + + return if ($type & $event_mask) == $event_mask; + + # If this was a one-time callback, we delete it + # (when connection is lost, all one-time callbacks get triggered) + delete $self->{callbacks}->{$type}; } =head2 $i3->subscribe(\%callbacks) @@ -169,6 +193,20 @@ key being the name of the event and the value being a callback. say "Successfully subscribed"; } +The special callback with name C<_error> is called when the connection to i3 +is killed (because of a crash, exit or restart of i3 most likely). You can +use it to print an appropriate message and exit cleanly or to try to reconnect. + + my %callbacks = ( + _error => sub { + my ($msg) = @_; + say "I am sorry. I am so sorry: $msg"; + exit 1; + } + ); + + $i3->subscribe(\%callbacks)->recv; + =cut sub subscribe { my ($self, $callbacks) = @_; @@ -199,6 +237,8 @@ sub message { die "No message type specified" unless defined($type); + die "No connection to i3" unless defined($self->{ipchdl}); + my $payload = ""; if ($content) { if (not ref($content)) { From b9c83fbd2623e62a637326470827372f05c1eddc Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 23 Mar 2010 02:05:33 +0100 Subject: [PATCH 20/56] add testcase for sugar methods --- t/02-sugar.t | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 t/02-sugar.t diff --git a/t/02-sugar.t b/t/02-sugar.t new file mode 100644 index 00000000..a3e2cc79 --- /dev/null +++ b/t/02-sugar.t @@ -0,0 +1,29 @@ +#!perl -T +# vim:ts=4:sw=4:expandtab + +use Test::More tests => 3; +use AnyEvent::I3; +use AnyEvent; + +my $i3 = i3(); +my $cv = AnyEvent->condvar; + +# Try to connect to i3 +$i3->connect->cb(sub { my ($v) = @_; $cv->send($v->recv) }); + +# But cancel if we are not connected after 0.5 seconds +my $t = AnyEvent->timer(after => 0.5, cb => sub { $cv->send(0) }); +my $connected = $cv->recv; + +SKIP: { + skip 'No connection to i3', 3 unless $connected; + + my $workspaces = i3->get_workspaces->recv; + isa_ok($workspaces, 'ARRAY'); + + ok(@{$workspaces} > 0, 'More than zero workspaces found'); + + ok(defined(@{$workspaces}[0]->{num}), 'JSON deserialized'); +} + +diag( "Testing AnyEvent::I3 $AnyEvent::I3::VERSION, Perl $], $^X" ); From f12facc184650fb84f66632968a850929edd51da Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 23 Mar 2010 02:07:02 +0100 Subject: [PATCH 21/56] bump version to 0.02, update MANIFEST --- MANIFEST | 1 + lib/AnyEvent/I3.pm | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/MANIFEST b/MANIFEST index c9c9c27c..99d318ff 100644 --- a/MANIFEST +++ b/MANIFEST @@ -13,6 +13,7 @@ META.yml README t/00-load.t t/01-workspaces.t +t/02-sugar.t t/boilerplate.t t/manifest.t t/pod-coverage.t diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index a09c7512..36852623 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -15,11 +15,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; =head1 VERSION -Version 0.01 +Version 0.02 =head1 SYNOPSIS From 5d1bb0b0ce0dcce063c5e63e0533e7805ec856df Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 26 Mar 2010 19:48:59 +0100 Subject: [PATCH 22/56] Bump version for new CPAN upload, fix MANIFEST --- MANIFEST | 2 ++ MANIFEST.SKIP | 4 ++-- lib/AnyEvent/I3.pm | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/MANIFEST b/MANIFEST index 99d318ff..34c8a8fb 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3,10 +3,12 @@ inc/Module/Install.pm inc/Module/Install/Base.pm inc/Module/Install/Can.pm inc/Module/Install/Fetch.pm +inc/Module/Install/Makefile.pm inc/Module/Install/Metadata.pm inc/Module/Install/Win32.pm inc/Module/Install/WriteAll.pm lib/AnyEvent/I3.pm +Makefile.PL MANIFEST MANIFEST.SKIP META.yml diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index f58f7ef8..01bee91f 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -1,8 +1,8 @@ ^\.git/ \.bak$ blib/ -Makefile -Makefile.old +^Makefile$ +^Makefile.old$ Build Build.bat ^pm_to_blib diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 36852623..a2951767 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -15,11 +15,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.02'; +our $VERSION = '0.03'; =head1 VERSION -Version 0.02 +Version 0.03 =head1 SYNOPSIS From e6568648386348ba29f0f36654163eeb0db1d89e Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 27 Mar 2010 14:54:30 +0100 Subject: [PATCH 23/56] use new default ipc-socket path, glob() path, bump version --- lib/AnyEvent/I3.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index a2951767..d9a55b2b 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -15,11 +15,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.03'; +our $VERSION = '0.04'; =head1 VERSION -Version 0.03 +Version 0.04 =head1 SYNOPSIS @@ -29,7 +29,7 @@ then subscribe to events or send messages and receive their replies. use AnyEvent::I3 qw(:all); - my $i3 = i3("/tmp/i3-ipc.sock"); + my $i3 = i3("~/.i3/ipc.sock"); $i3->connect->recv or die "Error connecting"; say "Connected to i3"; @@ -94,9 +94,9 @@ the UNIX socket to connect to. sub new { my ($class, $path) = @_; - $path ||= '/tmp/i3-ipc.sock'; + $path ||= '~/.i3/ipc.sock'; - bless { path => $path } => $class; + bless { path => glob($path) } => $class; } =head2 $i3->connect From 192ef6a827fb1f5385c82d8ada4cee602ae848dc Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 10 Jun 2010 00:18:50 +0200 Subject: [PATCH 24/56] use getpwuid() to resolve ~ in socket paths instead of glob() This fixes a warning about using a tainted variable (broke the tests with newer perl versions). --- lib/AnyEvent/I3.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index d9a55b2b..944d5f02 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -96,7 +96,16 @@ sub new { $path ||= '~/.i3/ipc.sock'; - bless { path => glob($path) } => $class; + # Check if we need to resolve ~ + if ($path =~ /~/) { + # We use getpwuid() instead of $ENV{HOME} because the latter is tainted + # and thus produces warnings when running tests with perl -T + my $home = (getpwuid($<))[7]; + die "Could not get home directory" unless $home and -d $home; + $path =~ s/~/$home/g; + } + + bless { path => $path } => $class; } =head2 $i3->connect From da94674f8fdd98ae324b79b90a1698721a1c6bb2 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 10 Jun 2010 00:20:11 +0200 Subject: [PATCH 25/56] bump version --- lib/AnyEvent/I3.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 944d5f02..953de81e 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -15,11 +15,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.04'; +our $VERSION = '0.05'; =head1 VERSION -Version 0.04 +Version 0.05 =head1 SYNOPSIS From a3a42f30e100ecc84165381a71e140bf32284b5a Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 16 Jun 2010 19:40:55 +0200 Subject: [PATCH 26/56] Add check to Makefile to abort in a Windows environment (neither i3 nor unix sockets available) Hopefully, this will stop CPAN Testers emails about failing tests on windows. --- Makefile.PL | 4 ++++ lib/AnyEvent/I3.pm | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 2082ce24..8b81a065 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -9,4 +9,8 @@ requires 'AnyEvent::Handle'; requires 'AnyEvent::Socket'; requires 'JSON::XS'; +if ($^O eq 'MSWin32') { + die "AnyEvent::I3 cannot be used on win32 (unix sockets are missing)"; +} + WriteAll; diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 953de81e..61486488 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -15,11 +15,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.05'; +our $VERSION = '0.06'; =head1 VERSION -Version 0.05 +Version 0.06 =head1 SYNOPSIS From 7176a7074b9a1c94b9f22a2532826bd01586cf3d Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 21 Nov 2010 21:52:43 +0100 Subject: [PATCH 27/56] introduce get_tree request (tree branch only) --- lib/AnyEvent/I3.pm | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 61486488..d191241c 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -15,11 +15,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.06'; +our $VERSION = '0.07'; =head1 VERSION -Version 0.06 +Version 0.07 =head1 SYNOPSIS @@ -64,9 +64,10 @@ use constant TYPE_COMMAND => 0; use constant TYPE_GET_WORKSPACES => 1; use constant TYPE_SUBSCRIBE => 2; use constant TYPE_GET_OUTPUTS => 3; +use constant TYPE_GET_TREE => 4; our %EXPORT_TAGS = ( 'all' => [ - qw(i3 TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE TYPE_GET_OUTPUTS) + qw(i3 TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE TYPE_GET_OUTPUTS TYPE_GET_TREE) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } ); @@ -322,6 +323,23 @@ sub get_outputs { $self->message(TYPE_GET_OUTPUTS) } +=head2 get_tree + +Gets the layout tree from i3 (tree branch only). + + my $tree = i3->get_tree->recv; + say Dumper($tree); + +=cut +sub get_tree { + my ($self) = @_; + + $self->_ensure_connection; + + $self->message(TYPE_GET_TREE) +} + + =head2 command($content) Makes i3 execute the given command From 62749590294edb97cdfb5f2316b90f9e13b9e113 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 26 Sep 2011 19:25:38 +0100 Subject: [PATCH 28/56] =?UTF-8?q?Bugfix:=20The=20synopsis=20mentioned=20->?= =?UTF-8?q?workspaces,=20but=20it=E2=80=99s=20->get=5Fworkspaces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/AnyEvent/I3.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index d191241c..36642643 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -41,7 +41,7 @@ then subscribe to events or send messages and receive their replies. use AnyEvent::I3; - my $workspaces = i3->workspaces->recv; + my $workspaces = i3->get_workspaces->recv; say "Currently, you use " . @{$workspaces} . " workspaces"; =head1 EXPORT From 1a272f96a58bde317621bb3fd13db5548313b1e9 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 26 Sep 2011 19:25:59 +0100 Subject: [PATCH 29/56] Implement support for the TYPE_GET_MARKS request, add ->get_marks sugar method --- lib/AnyEvent/I3.pm | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 36642643..979e0867 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -65,9 +65,10 @@ use constant TYPE_GET_WORKSPACES => 1; use constant TYPE_SUBSCRIBE => 2; use constant TYPE_GET_OUTPUTS => 3; use constant TYPE_GET_TREE => 4; +use constant TYPE_GET_MARKS => 5; our %EXPORT_TAGS = ( 'all' => [ - qw(i3 TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE TYPE_GET_OUTPUTS TYPE_GET_TREE) + qw(i3 TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE TYPE_GET_OUTPUTS TYPE_GET_TREE TYPE_GET_MARKS) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } ); @@ -325,7 +326,7 @@ sub get_outputs { =head2 get_tree -Gets the layout tree from i3 (tree branch only). +Gets the layout tree from i3 (>= v4.0). my $tree = i3->get_tree->recv; say Dumper($tree); @@ -339,6 +340,21 @@ sub get_tree { $self->message(TYPE_GET_TREE) } +=head2 get_marks + +Gets all the window identifier marks from i3 (>= v4.1). + + my $marks = i3->get_marks->recv; + say Dumper($tree); + +=cut +sub get_marks { + my ($self) = @_; + + $self->_ensure_connection; + + $self->message(TYPE_GET_MARKS) +} =head2 command($content) From 9054711650a02fb7b4113a2186bb19208151c5da Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 26 Sep 2011 19:26:18 +0100 Subject: [PATCH 30/56] Bump version to 0.08 --- lib/AnyEvent/I3.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 979e0867..cf43ab0c 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -15,11 +15,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.07'; +our $VERSION = '0.08'; =head1 VERSION -Version 0.07 +Version 0.08 =head1 SYNOPSIS From d7bd64586319846d7da50c66304cb49fff9fbff4 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 12 Oct 2011 23:25:56 +0100 Subject: [PATCH 31/56] Fix documentation for get_marks (s/tree/marks) --- lib/AnyEvent/I3.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index cf43ab0c..3977e652 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -345,7 +345,7 @@ sub get_tree { Gets all the window identifier marks from i3 (>= v4.1). my $marks = i3->get_marks->recv; - say Dumper($tree); + say Dumper($marks); =cut sub get_marks { From 7a934b94dd62bd05d2df59518d66410ccbac1492 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 12 Oct 2011 23:26:04 +0100 Subject: [PATCH 32/56] Add TYPE_GET_MARKS and accompanying sugar method --- lib/AnyEvent/I3.pm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 3977e652..4a5e8c24 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -66,9 +66,11 @@ use constant TYPE_SUBSCRIBE => 2; use constant TYPE_GET_OUTPUTS => 3; use constant TYPE_GET_TREE => 4; use constant TYPE_GET_MARKS => 5; +use constant TYPE_GET_BAR_CONFIG => 6; our %EXPORT_TAGS = ( 'all' => [ - qw(i3 TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE TYPE_GET_OUTPUTS TYPE_GET_TREE TYPE_GET_MARKS) + qw(i3 TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE TYPE_GET_OUTPUTS + TYPE_GET_TREE TYPE_GET_MARKS TYPE_GET_BAR_CONFIG) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } ); @@ -356,6 +358,22 @@ sub get_marks { $self->message(TYPE_GET_MARKS) } +=head2 get_bar_config + +Gets the bar configuration for the specific bar id from i3 (>= v4.1). + + my $config = i3->get_bar_config($id)->recv; + say Dumper($config); + +=cut +sub get_bar_config { + my ($self, $id) = @_; + + $self->_ensure_connection; + + $self->message(TYPE_GET_BAR_CONFIG, $id) +} + =head2 command($content) Makes i3 execute the given command From 23beaa83ea00c3b6475e91e49150863eefc7a6c9 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 20 Oct 2011 20:28:04 +0100 Subject: [PATCH 33/56] Bump version to 0.09 --- lib/AnyEvent/I3.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 4a5e8c24..fea470bc 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -15,11 +15,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.08'; +our $VERSION = '0.09'; =head1 VERSION -Version 0.08 +Version 0.09 =head1 SYNOPSIS From ead15574680e34144142f203ec01c8d4689e908d Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 10 Dec 2011 11:37:43 +0000 Subject: [PATCH 34/56] implement the GET_LOG_MARKERS request Requires i3 version 966c654112561b21fca076a8e967033510da9981 or later. --- lib/AnyEvent/I3.pm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index fea470bc..6b8f905b 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -67,10 +67,11 @@ use constant TYPE_GET_OUTPUTS => 3; use constant TYPE_GET_TREE => 4; use constant TYPE_GET_MARKS => 5; use constant TYPE_GET_BAR_CONFIG => 6; +use constant TYPE_GET_LOG_MARKERS => 7; our %EXPORT_TAGS = ( 'all' => [ qw(i3 TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE TYPE_GET_OUTPUTS - TYPE_GET_TREE TYPE_GET_MARKS TYPE_GET_BAR_CONFIG) + TYPE_GET_TREE TYPE_GET_MARKS TYPE_GET_BAR_CONFIG TYPE_GET_LOG_MARKERS) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } ); @@ -374,6 +375,23 @@ sub get_bar_config { $self->message(TYPE_GET_BAR_CONFIG, $id) } +=head2 get_log_markers + +Gets the bar configuration for the specific bar id from i3 (>= v4.1). + + my $markers = i3->get_log_markers()->recv; + say Dumper($markers); + +=cut +sub get_log_markers { + my ($self) = @_; + + $self->_ensure_connection; + + $self->message(TYPE_GET_LOG_MARKERS) +} + + =head2 command($content) Makes i3 execute the given command From 3a9024de63f92066e74c11684511e7ecc7538fc7 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 21 Jan 2012 21:59:12 +0000 Subject: [PATCH 35/56] Bugfix: Also delete callbacks which are triggered due to an error --- lib/AnyEvent/I3.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 6b8f905b..6c7dbd12 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -147,6 +147,7 @@ sub connect { for my $type (keys %{$cb}) { next if ($type & $event_mask) == $event_mask; $cb->{$type}->(); + delete $cb->{$type}; } # Trigger _error callback, if set From 7021bb43154a46114509ed0dffcbe4429968be13 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 21 Jan 2012 22:00:04 +0000 Subject: [PATCH 36/56] Revert "implement the GET_LOG_MARKERS request" (no longer available) This reverts commit 7e2ed06447af5e3b49af69dd24e2a5dec373ad9c. --- lib/AnyEvent/I3.pm | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 6c7dbd12..398040cb 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -67,11 +67,10 @@ use constant TYPE_GET_OUTPUTS => 3; use constant TYPE_GET_TREE => 4; use constant TYPE_GET_MARKS => 5; use constant TYPE_GET_BAR_CONFIG => 6; -use constant TYPE_GET_LOG_MARKERS => 7; our %EXPORT_TAGS = ( 'all' => [ qw(i3 TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE TYPE_GET_OUTPUTS - TYPE_GET_TREE TYPE_GET_MARKS TYPE_GET_BAR_CONFIG TYPE_GET_LOG_MARKERS) + TYPE_GET_TREE TYPE_GET_MARKS TYPE_GET_BAR_CONFIG) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } ); @@ -376,23 +375,6 @@ sub get_bar_config { $self->message(TYPE_GET_BAR_CONFIG, $id) } -=head2 get_log_markers - -Gets the bar configuration for the specific bar id from i3 (>= v4.1). - - my $markers = i3->get_log_markers()->recv; - say Dumper($markers); - -=cut -sub get_log_markers { - my ($self) = @_; - - $self->_ensure_connection; - - $self->message(TYPE_GET_LOG_MARKERS) -} - - =head2 command($content) Makes i3 execute the given command From 476e41ddc3aac7c938b7ebefa146e77b3723d80f Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 9 Jul 2012 15:49:16 +0200 Subject: [PATCH 37/56] use i3 --get-socketpath by default for determining the socket path This was introduced in i3 v4.1 (released 2011-11-11, so should be widespread enough by now). --- lib/AnyEvent/I3.pm | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 398040cb..33347638 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -29,7 +29,7 @@ then subscribe to events or send messages and receive their replies. use AnyEvent::I3 qw(:all); - my $i3 = i3("~/.i3/ipc.sock"); + my $i3 = i3(); $i3->connect->recv or die "Error connecting"; say "Connected to i3"; @@ -48,8 +48,12 @@ then subscribe to events or send messages and receive their replies. =head2 $i3 = i3([ $path ]); -Creates a new C object and returns it. C is the path of -the UNIX socket to connect to. +Creates a new C object and returns it. + +C is an optional path of the UNIX socket to connect to. It is strongly +advised to NOT specify this unless you're absolutely sure you need it. +C will automatically figure it out by querying the running i3 +instance on the current DISPLAY which is almost always what you want. =head1 SUBROUTINES/METHODS @@ -91,13 +95,37 @@ sub i3 { =head2 $i3 = AnyEvent::I3->new([ $path ]) -Creates a new C object and returns it. C is the path of -the UNIX socket to connect to. +Creates a new C object and returns it. + +C is an optional path of the UNIX socket to connect to. It is strongly +advised to NOT specify this unless you're absolutely sure you need it. +C will automatically figure it out by querying the running i3 +instance on the current DISPLAY which is almost always what you want. =cut sub new { my ($class, $path) = @_; + if (!$path) { + # This effectively circumvents taint mode checking for $ENV{PATH}. We + # do this because users might specify PATH explicitly to call i3 in a + # custom location (think ~/.bin/). + my $paths = $ENV{PATH}; + if ($paths =~ /^(.*)$/) { + $ENV{PATH} = $1; + } + chomp($path = qx(i3 --get-socketpath)); + # Circumventing taint mode again: the socket can be anywhere on the + # system and that’s okay. + if ($path =~ /^([^\0]+)$/) { + $path = $1; + } else { + warn "Asking i3 for the socket path failed. Is DISPLAY set and is i3 in your PATH?"; + } + } + + # This is the old default path (v3.*). This fallback line can be removed in + # a year from now. -- Michael, 2012-07-09 $path ||= '~/.i3/ipc.sock'; # Check if we need to resolve ~ @@ -292,7 +320,7 @@ sub _ensure_connection { return if defined($self->{ipchdl}); - $self->connect->recv or die "Unable to connect to i3" + $self->connect->recv or die "Unable to connect to i3 (socket path " . $self->{path} . ")"; } =head2 get_workspaces From a6a0e11718a7346d40a98dd33110be2dcc784ce2 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 9 Jul 2012 15:51:37 +0200 Subject: [PATCH 38/56] update copyright and URL/email --- lib/AnyEvent/I3.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 33347638..deadd9fb 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -421,7 +421,7 @@ sub command { =head1 AUTHOR -Michael Stapelberg, C<< >> +Michael Stapelberg, C<< >> =head1 BUGS @@ -447,7 +447,7 @@ L =item * The i3 window manager website -L +L =back @@ -457,7 +457,7 @@ L =head1 LICENSE AND COPYRIGHT -Copyright 2010 Michael Stapelberg. +Copyright 2010-2012 Michael Stapelberg. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published From 2ec58b40f8095f7845012342022f4cf62b756113 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 9 Jul 2012 15:54:26 +0200 Subject: [PATCH 39/56] bump version to 0.10 --- lib/AnyEvent/I3.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index deadd9fb..831f350d 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -15,11 +15,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.09'; +our $VERSION = '0.10'; =head1 VERSION -Version 0.09 +Version 0.10 =head1 SYNOPSIS From 4c97c94a0a29e0b775974c780d574639372e76c2 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 10 Jul 2012 18:55:05 +0200 Subject: [PATCH 40/56] taint mode fix for FreeBSD --- lib/AnyEvent/I3.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 831f350d..b08fdf63 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -114,6 +114,8 @@ sub new { if ($paths =~ /^(.*)$/) { $ENV{PATH} = $1; } + # Otherwise the qx() operator wont work: + delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; chomp($path = qx(i3 --get-socketpath)); # Circumventing taint mode again: the socket can be anywhere on the # system and that’s okay. From af6f180c35c3024ce4265a69a14ccc3d474131dc Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 10 Jul 2012 18:55:30 +0200 Subject: [PATCH 41/56] bump version to 0.11 --- lib/AnyEvent/I3.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index b08fdf63..4128870f 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -15,11 +15,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.10'; +our $VERSION = '0.11'; =head1 VERSION -Version 0.10 +Version 0.11 =head1 SYNOPSIS From b4058790cc47d147d3448795da679ea4ccfe4055 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 11 Jul 2012 08:58:59 +0200 Subject: [PATCH 42/56] remove relative directories from $ENV{PATH} (for taint mode) Otherwise, the module will die when you use it with PATH=$PATH:. (as is the case on the OpenBSD cpan testers). --- lib/AnyEvent/I3.pm | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 4128870f..2170b267 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -8,6 +8,7 @@ use AnyEvent::Handle; use AnyEvent::Socket; use AnyEvent; use Encode; +use Scalar::Util qw(tainted); =head1 NAME @@ -107,12 +108,25 @@ sub new { my ($class, $path) = @_; if (!$path) { + my $path_tainted = tainted($ENV{PATH}); # This effectively circumvents taint mode checking for $ENV{PATH}. We # do this because users might specify PATH explicitly to call i3 in a # custom location (think ~/.bin/). - my $paths = $ENV{PATH}; - if ($paths =~ /^(.*)$/) { - $ENV{PATH} = $1; + (local $ENV{PATH}) = ($ENV{PATH} =~ /(.*)/); + + # In taint mode, we also need to remove all relative directories from + # PATH (like . or ../bin). We only do this in taint mode and warn the + # user, since this might break a real-world use case for some people. + if ($path_tainted) { + my @dirs = split /:/, $ENV{PATH}; + my @filtered = grep !/^\./, @dirs; + if (scalar @dirs != scalar @filtered) { + $ENV{PATH} = join ':', @filtered; + warn qq|Removed relative directories from PATH because you | . + qq|are running Perl with taint mode enabled. Remove -T | . + qq|to be able to use relative directories in PATH. | . + qq|New PATH is "$ENV{PATH}"|; + } } # Otherwise the qx() operator wont work: delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; From 3a7f5d7912ca2d812c9513c5898571ec39906618 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 11 Jul 2012 08:59:51 +0200 Subject: [PATCH 43/56] bump version to 0.12 --- lib/AnyEvent/I3.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 2170b267..c338878a 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -16,11 +16,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.11'; +our $VERSION = '0.12'; =head1 VERSION -Version 0.11 +Version 0.12 =head1 SYNOPSIS From d8ad62c36fb1d481f399a7292349dfaa1041ee96 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 5 Aug 2012 17:31:07 +0200 Subject: [PATCH 44/56] add a more involved example to the SYNOPSIS --- lib/AnyEvent/I3.pm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index c338878a..63f063f4 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -45,6 +45,28 @@ then subscribe to events or send messages and receive their replies. my $workspaces = i3->get_workspaces->recv; say "Currently, you use " . @{$workspaces} . " workspaces"; +A somewhat more involved example which dumps the i3 layout tree whenever there +is a workspace event: + + use Data::Dumper; + use AnyEvent; + use AnyEvent::I3; + + my $i3 = i3(); + + $i3->connect->recv or die "Error connecting to i3"; + + $i3->subscribe({ + workspace => sub { + $i3->get_tree->cb(sub { + my ($tree) = @_; + say "tree: " . Dumper($tree); + }); + } + })->recv->{success} or die "Error subscribing to events"; + + AE::cv->recv + =head1 EXPORT =head2 $i3 = i3([ $path ]); From 64fddbe41bf8d50eda121d822cdc71399fc0a2ec Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 5 Aug 2012 17:31:22 +0200 Subject: [PATCH 45/56] Implement the GET_VERSION request (with a fallback to i3 --version) --- lib/AnyEvent/I3.pm | 121 ++++++++++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 33 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 63f063f4..b46f2c62 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -94,10 +94,11 @@ use constant TYPE_GET_OUTPUTS => 3; use constant TYPE_GET_TREE => 4; use constant TYPE_GET_MARKS => 5; use constant TYPE_GET_BAR_CONFIG => 6; +use constant TYPE_GET_VERSION => 7; our %EXPORT_TAGS = ( 'all' => [ qw(i3 TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE TYPE_GET_OUTPUTS - TYPE_GET_TREE TYPE_GET_MARKS TYPE_GET_BAR_CONFIG) + TYPE_GET_TREE TYPE_GET_MARKS TYPE_GET_BAR_CONFIG TYPE_GET_VERSION) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } ); @@ -116,6 +117,43 @@ sub i3 { AnyEvent::I3->new(@_) } +# Calls i3, even when running in taint mode. +sub _call_i3 { + my ($args) = @_; + + my $path_tainted = tainted($ENV{PATH}); + # This effectively circumvents taint mode checking for $ENV{PATH}. We + # do this because users might specify PATH explicitly to call i3 in a + # custom location (think ~/.bin/). + (local $ENV{PATH}) = ($ENV{PATH} =~ /(.*)/); + + # In taint mode, we also need to remove all relative directories from + # PATH (like . or ../bin). We only do this in taint mode and warn the + # user, since this might break a real-world use case for some people. + if ($path_tainted) { + my @dirs = split /:/, $ENV{PATH}; + my @filtered = grep !/^\./, @dirs; + if (scalar @dirs != scalar @filtered) { + $ENV{PATH} = join ':', @filtered; + warn qq|Removed relative directories from PATH because you | . + qq|are running Perl with taint mode enabled. Remove -T | . + qq|to be able to use relative directories in PATH. | . + qq|New PATH is "$ENV{PATH}"|; + } + } + # Otherwise the qx() operator wont work: + delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; + chomp(my $result = qx(i3 $args)); + # Circumventing taint mode again: the socket can be anywhere on the + # system and that’s okay. + if ($result =~ /^([^\0]+)$/) { + return $1; + } + + warn "Calling i3 $args failed. Is DISPLAY set and is i3 in your PATH?"; + return undef; +} + =head2 $i3 = AnyEvent::I3->new([ $path ]) Creates a new C object and returns it. @@ -129,38 +167,7 @@ instance on the current DISPLAY which is almost always what you want. sub new { my ($class, $path) = @_; - if (!$path) { - my $path_tainted = tainted($ENV{PATH}); - # This effectively circumvents taint mode checking for $ENV{PATH}. We - # do this because users might specify PATH explicitly to call i3 in a - # custom location (think ~/.bin/). - (local $ENV{PATH}) = ($ENV{PATH} =~ /(.*)/); - - # In taint mode, we also need to remove all relative directories from - # PATH (like . or ../bin). We only do this in taint mode and warn the - # user, since this might break a real-world use case for some people. - if ($path_tainted) { - my @dirs = split /:/, $ENV{PATH}; - my @filtered = grep !/^\./, @dirs; - if (scalar @dirs != scalar @filtered) { - $ENV{PATH} = join ':', @filtered; - warn qq|Removed relative directories from PATH because you | . - qq|are running Perl with taint mode enabled. Remove -T | . - qq|to be able to use relative directories in PATH. | . - qq|New PATH is "$ENV{PATH}"|; - } - } - # Otherwise the qx() operator wont work: - delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; - chomp($path = qx(i3 --get-socketpath)); - # Circumventing taint mode again: the socket can be anywhere on the - # system and that’s okay. - if ($path =~ /^([^\0]+)$/) { - $path = $1; - } else { - warn "Asking i3 for the socket path failed. Is DISPLAY set and is i3 in your PATH?"; - } - } + $path = _call_i3('--get-socketpath') unless $path; # This is the old default path (v3.*). This fallback line can be removed in # a year from now. -- Michael, 2012-07-09 @@ -441,6 +448,54 @@ sub get_bar_config { $self->message(TYPE_GET_BAR_CONFIG, $id) } +=head2 get_version + +Gets the i3 version via IPC, with a fall-back that parses the output of i3 +--version (for i3 < v4.3). + + my $version = i3->get_version()->recv; + say "major: " . $version->{major} . ", minor = " . $version->{minor}; + +=cut +sub get_version { + my ($self) = @_; + + $self->_ensure_connection; + + my $cv = AnyEvent->condvar; + + my $version_cv = $self->message(TYPE_GET_VERSION); + my $timeout; + $timeout = AnyEvent->timer( + after => 1, + cb => sub { + warn "Falling back to i3 --version since the running i3 doesn’t support GET_VERSION yet."; + my $version = _call_i3('--version'); + $version =~ s/^i3 version //; + my $patch = 0; + my ($major, $minor) = ($version =~ /^([0-9]+)\.([0-9]+)/); + if ($version =~ /^[0-9]+\.[0-9]+\.([0-9]+)/) { + $patch = $1; + } + # Strip everything from the © sign on. + $version =~ s/ ©.*$//g; + $cv->send({ + major => int($major), + minor => int($minor), + patch => int($patch), + human_readable => $version, + }); + undef $timeout; + }, + ); + $version_cv->cb(sub { + undef $timeout; + $cv->send($version_cv->recv); + }); + + return $cv; +} + =head2 command($content) Makes i3 execute the given command From c3538c4cad327dc966e3ec66eea2a6fa4aeb8208 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 5 Aug 2012 17:31:57 +0200 Subject: [PATCH 46/56] bump version to 0.13 --- lib/AnyEvent/I3.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index b46f2c62..5254e22d 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -16,11 +16,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.12'; +our $VERSION = '0.13'; =head1 VERSION -Version 0.12 +Version 0.13 =head1 SYNOPSIS From 879266c40b71d137f55256a920024fc1ecb1b594 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 5 Aug 2012 17:41:16 +0200 Subject: [PATCH 47/56] update Changes file --- Changes | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 0dc96033..5915a90d 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,52 @@ Revision history for AnyEvent-I3 -0.01 2010-03-13 - First version, released on an unsuspecting world. +0.13 2012-08-05 + * support the GET_VERSION request with a fall-back to i3 --version + +0.12 2012-07-11 + + * taint mode fix: remove relative directories from $ENV{PATH} + +0.11 2012-07-10 + + * taint mode fix for FreeBSD + +0.10 2012-07-09 + + * Use i3 --get-socketpath by default for determining the socket path + * Bugfix: Also delete callbacks which are triggered due to an error + +0.09 2011-10-12 + + * Implement GET_BAR_CONFIG request + +0.08 2011-09-26 + + * Implement GET_MARKS request + * The synopsis mentioned ->workspaces, but it’s ->get_workspaces + +0.07 2010-11-21 + + * Implement GET_TREE request + +0.06 2010-06-16 + + * Add check to Makefile to abort in a Windows environment (neither i3 nor + unix sockets available) + +0.05 2010-06-09 + + * use getpwuid() to resolve ~ in socket paths instead of glob() + +0.04 2010-03-27 + + * use new default ipc-socket path, glob() path, bump version + +0.03 2010-03-26 + + * fix MANIFEST + +0.02 2010-03-23 + + * first upload to CPAN From b008d8b2e96cecb33347527fdf640a8e87a3d4fa Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 22 Sep 2012 13:11:08 +0200 Subject: [PATCH 48/56] 0.14: add support for the mode event --- Changes | 4 ++++ lib/AnyEvent/I3.pm | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 5915a90d..0a62838b 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for AnyEvent-I3 +0.14 2012-09-22 + + * support the mode event + 0.13 2012-08-05 * support the GET_VERSION request with a fall-back to i3 --version diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 5254e22d..b0bf2a09 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -16,11 +16,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.13'; +our $VERSION = '0.14'; =head1 VERSION -Version 0.13 +Version 0.14 =head1 SYNOPSIS @@ -110,6 +110,7 @@ my $event_mask = (1 << 31); my %events = ( workspace => ($event_mask | 0), output => ($event_mask | 1), + mode => ($event_mask | 2), _error => 0xFFFFFFFF, ); From 85e98d8d7d579cb02ae1a6810f39b2d5713a0bfc Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 3 Nov 2012 11:47:27 +0100 Subject: [PATCH 49/56] fix doc error: missing opening brace (Thanks bitonic) --- lib/AnyEvent/I3.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index b0bf2a09..309a11c0 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -277,7 +277,7 @@ key being the name of the event and the value being a callback. workspace => sub { say "Workspaces changed" } ); - if ($i3->subscribe(\%callbacks)->recv->{success}) + if ($i3->subscribe(\%callbacks)->recv->{success}) { say "Successfully subscribed"; } From bd1c33588d7b9b8788e58ecbd6fab154ee554d7c Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 18 Feb 2013 11:01:04 +0100 Subject: [PATCH 50/56] support the window event, tag 0.15 --- Changes | 4 ++++ lib/AnyEvent/I3.pm | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 0a62838b..ab63dd06 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for AnyEvent-I3 +0.15 2013-02-18 + + * support the window event + 0.14 2012-09-22 * support the mode event diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 309a11c0..e472ccc6 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -16,11 +16,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.14'; +our $VERSION = '0.15'; =head1 VERSION -Version 0.14 +Version 0.15 =head1 SYNOPSIS @@ -111,6 +111,7 @@ my %events = ( workspace => ($event_mask | 0), output => ($event_mask | 1), mode => ($event_mask | 2), + window => ($event_mask | 3), _error => 0xFFFFFFFF, ); From 538c50c8ef0cdcce8825aa28d4e7f44c8434964a Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 3 Oct 2014 09:39:10 +0200 Subject: [PATCH 51/56] support the barconfig_update and binding event, tag 0.16 --- Changes | 4 ++++ lib/AnyEvent/I3.pm | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index ab63dd06..dd68f4cb 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for AnyEvent-I3 +0.16 2014-10-03 + + * support the barconfig_update and binding event + 0.15 2013-02-18 * support the window event diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index e472ccc6..9f93519e 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -16,11 +16,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.15'; +our $VERSION = '0.16'; =head1 VERSION -Version 0.15 +Version 0.16 =head1 SYNOPSIS @@ -112,6 +112,8 @@ my %events = ( output => ($event_mask | 1), mode => ($event_mask | 2), window => ($event_mask | 3), + barconfig_update => ($event_mask | 4), + binding => ($event_mask | 5), _error => 0xFFFFFFFF, ); From 0940f7b9d19ec45f0b20e9cd585c889d4ba22e81 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 6 May 2016 02:44:28 -0400 Subject: [PATCH 52/56] Add the shutdown event (#2) The shutdown event is triggered when the ipc shuts down because of either a restart or when i3 exits. --- lib/AnyEvent/I3.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 9f93519e..a8872d5d 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -114,6 +114,7 @@ my %events = ( window => ($event_mask | 3), barconfig_update => ($event_mask | 4), binding => ($event_mask | 5), + shutdown => ($event_mask | 6), _error => 0xFFFFFFFF, ); From f7645336cb499e208df66037ea1ffc269cae94d6 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 9 Apr 2017 15:32:04 +0200 Subject: [PATCH 53/56] use lib '.' for Perl 5.25.11+ see also https://rt.cpan.org/Ticket/Display.html?id=120943 --- Makefile.PL | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.PL b/Makefile.PL index 8b81a065..5d2ab32e 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,3 +1,4 @@ +use lib '.'; use inc::Module::Install; name 'AnyEvent-I3'; From db35244ee766869a1b1b832cddcb311d1f8ab11c Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sun, 9 Apr 2017 15:34:36 +0200 Subject: [PATCH 54/56] tag 0.17 --- Changes | 5 +++++ lib/AnyEvent/I3.pm | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index dd68f4cb..713f7d1c 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Revision history for AnyEvent-I3 +0.17 2017-04-09 + + * support the shutdown event + * use lib '.' for Perl 5.25.11+ + 0.16 2014-10-03 * support the barconfig_update and binding event diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index a8872d5d..875f3790 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -16,11 +16,11 @@ AnyEvent::I3 - communicate with the i3 window manager =cut -our $VERSION = '0.16'; +our $VERSION = '0.17'; =head1 VERSION -Version 0.16 +Version 0.17 =head1 SYNOPSIS From 062ecdb0b5e97448c24b7aaf07e9260906d22fbe Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 19 Aug 2017 16:32:39 +0200 Subject: [PATCH 55/56] Move to AnyEvent-I3 --- Changes => AnyEvent-I3/Changes | 0 MANIFEST => AnyEvent-I3/MANIFEST | 0 MANIFEST.SKIP => AnyEvent-I3/MANIFEST.SKIP | 0 Makefile.PL => AnyEvent-I3/Makefile.PL | 0 README => AnyEvent-I3/README | 0 {lib => AnyEvent-I3/lib}/AnyEvent/I3.pm | 0 {t => AnyEvent-I3/t}/00-load.t | 0 {t => AnyEvent-I3/t}/01-workspaces.t | 0 {t => AnyEvent-I3/t}/02-sugar.t | 0 {t => AnyEvent-I3/t}/boilerplate.t | 0 {t => AnyEvent-I3/t}/manifest.t | 0 {t => AnyEvent-I3/t}/pod-coverage.t | 0 {t => AnyEvent-I3/t}/pod.t | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename Changes => AnyEvent-I3/Changes (100%) rename MANIFEST => AnyEvent-I3/MANIFEST (100%) rename MANIFEST.SKIP => AnyEvent-I3/MANIFEST.SKIP (100%) rename Makefile.PL => AnyEvent-I3/Makefile.PL (100%) rename README => AnyEvent-I3/README (100%) rename {lib => AnyEvent-I3/lib}/AnyEvent/I3.pm (100%) rename {t => AnyEvent-I3/t}/00-load.t (100%) rename {t => AnyEvent-I3/t}/01-workspaces.t (100%) rename {t => AnyEvent-I3/t}/02-sugar.t (100%) rename {t => AnyEvent-I3/t}/boilerplate.t (100%) rename {t => AnyEvent-I3/t}/manifest.t (100%) rename {t => AnyEvent-I3/t}/pod-coverage.t (100%) rename {t => AnyEvent-I3/t}/pod.t (100%) diff --git a/Changes b/AnyEvent-I3/Changes similarity index 100% rename from Changes rename to AnyEvent-I3/Changes diff --git a/MANIFEST b/AnyEvent-I3/MANIFEST similarity index 100% rename from MANIFEST rename to AnyEvent-I3/MANIFEST diff --git a/MANIFEST.SKIP b/AnyEvent-I3/MANIFEST.SKIP similarity index 100% rename from MANIFEST.SKIP rename to AnyEvent-I3/MANIFEST.SKIP diff --git a/Makefile.PL b/AnyEvent-I3/Makefile.PL similarity index 100% rename from Makefile.PL rename to AnyEvent-I3/Makefile.PL diff --git a/README b/AnyEvent-I3/README similarity index 100% rename from README rename to AnyEvent-I3/README diff --git a/lib/AnyEvent/I3.pm b/AnyEvent-I3/lib/AnyEvent/I3.pm similarity index 100% rename from lib/AnyEvent/I3.pm rename to AnyEvent-I3/lib/AnyEvent/I3.pm diff --git a/t/00-load.t b/AnyEvent-I3/t/00-load.t similarity index 100% rename from t/00-load.t rename to AnyEvent-I3/t/00-load.t diff --git a/t/01-workspaces.t b/AnyEvent-I3/t/01-workspaces.t similarity index 100% rename from t/01-workspaces.t rename to AnyEvent-I3/t/01-workspaces.t diff --git a/t/02-sugar.t b/AnyEvent-I3/t/02-sugar.t similarity index 100% rename from t/02-sugar.t rename to AnyEvent-I3/t/02-sugar.t diff --git a/t/boilerplate.t b/AnyEvent-I3/t/boilerplate.t similarity index 100% rename from t/boilerplate.t rename to AnyEvent-I3/t/boilerplate.t diff --git a/t/manifest.t b/AnyEvent-I3/t/manifest.t similarity index 100% rename from t/manifest.t rename to AnyEvent-I3/t/manifest.t diff --git a/t/pod-coverage.t b/AnyEvent-I3/t/pod-coverage.t similarity index 100% rename from t/pod-coverage.t rename to AnyEvent-I3/t/pod-coverage.t diff --git a/t/pod.t b/AnyEvent-I3/t/pod.t similarity index 100% rename from t/pod.t rename to AnyEvent-I3/t/pod.t From a91544b5b39396b7b6491fa18a61de092ea5e1f7 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 19 Aug 2017 16:51:51 +0200 Subject: [PATCH 56/56] testcases: remove external AnyEvent::I3 dependency --- Makefile.am | 14 +++++++++++++- testcases/Makefile.PL | 1 - testcases/complete-run.pl.in | 2 +- testcases/lib/i3test.pm.in | 1 + testcases/lib/i3test/XTEST.pm | 1 + testcases/t/000-load-deps.t | 1 - travis/travis-base.Dockerfile | 2 +- 7 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index 188e9e82..ec28991c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -53,6 +53,9 @@ check_PROGRAMS = \ check_SCRIPTS = \ testcases/complete-run.pl +check_DATA = \ + anyevent-i3.stamp + clean-check: rm -rf testsuite-* latest i3-cfg-for-* _Inline clean-local: clean-check @@ -573,6 +576,15 @@ i3-config-parser.stamp: parser/$(dirstamp) generate-command-parser.pl parser-spe $(AM_V_at) mv GENERATED_config_* $(top_builddir)/parser $(AM_V_at) touch $@ +################################################################################ +# AnyEvent-I3 build process +################################################################################ + +anyevent-i3.stamp: generate-command-parser.pl parser-specs/config.spec + $(AM_V_BUILD) (cd $(top_srcdir)/AnyEvent-I3 && perl Makefile.PL && make) + $(AM_V_at) touch $@ + CLEANFILES = \ i3-command-parser.stamp \ - i3-config-parser.stamp + i3-config-parser.stamp \ + anyevent-i3.stamp diff --git a/testcases/Makefile.PL b/testcases/Makefile.PL index 3c2a26f9..0b1f3055 100755 --- a/testcases/Makefile.PL +++ b/testcases/Makefile.PL @@ -8,7 +8,6 @@ WriteMakefile( MIN_PERL_VERSION => '5.010000', # 5.10.0 PREREQ_PM => { 'AnyEvent' => 0, - 'AnyEvent::I3' => '0.16', 'X11::XCB' => '0.12', 'Inline' => 0, 'Inline::C' => 0, diff --git a/testcases/complete-run.pl.in b/testcases/complete-run.pl.in index 2019253c..ba192469 100755 --- a/testcases/complete-run.pl.in +++ b/testcases/complete-run.pl.in @@ -18,7 +18,7 @@ use Time::HiRes qw(time); use IO::Handle; # these are shipped with the testsuite -use lib qw(@abs_top_builddir@/testcases/lib @abs_top_srcdir@/testcases/lib); +use lib qw(@abs_top_builddir@/testcases/lib @abs_top_srcdir@/testcases/lib @abs_top_srcdir@/AnyEvent-I3/blib/lib); use i3test::Util qw(slurp); use StartXServer; use StatusLine; diff --git a/testcases/lib/i3test.pm.in b/testcases/lib/i3test.pm.in index f7e1515d..18bebb52 100644 --- a/testcases/lib/i3test.pm.in +++ b/testcases/lib/i3test.pm.in @@ -7,6 +7,7 @@ use Test::Builder; use X11::XCB::Rect; use X11::XCB::Window; use X11::XCB qw(:all); +use lib qw(@abs_top_srcdir@/AnyEvent-I3/blib/lib); use AnyEvent::I3; use List::Util qw(first); use Time::HiRes qw(sleep); diff --git a/testcases/lib/i3test/XTEST.pm b/testcases/lib/i3test/XTEST.pm index 92adde42..3937b70a 100644 --- a/testcases/lib/i3test/XTEST.pm +++ b/testcases/lib/i3test/XTEST.pm @@ -6,6 +6,7 @@ use warnings; use v5.10; use i3test i3_autostart => 0; +use lib qw(@abs_top_srcdir@/AnyEvent-I3/blib/lib); use AnyEvent::I3; use ExtUtils::PkgConfig; diff --git a/testcases/t/000-load-deps.t b/testcases/t/000-load-deps.t index ab93233a..e0408338 100644 --- a/testcases/t/000-load-deps.t +++ b/testcases/t/000-load-deps.t @@ -8,7 +8,6 @@ BEGIN { X11::XCB::Connection X11::XCB::Window AnyEvent - AnyEvent::I3 IPC::Run ExtUtils::PkgConfig Inline diff --git a/travis/travis-base.Dockerfile b/travis/travis-base.Dockerfile index a415f549..5704d8e4 100644 --- a/travis/travis-base.Dockerfile +++ b/travis/travis-base.Dockerfile @@ -19,7 +19,7 @@ RUN apt-get update && \ dpkg-dev devscripts git equivs \ clang clang-format-3.8 \ lintian \ - libanyevent-perl libanyevent-i3-perl libextutils-pkgconfig-perl xcb-proto cpanminus xvfb xserver-xephyr xauth libinline-perl libinline-c-perl libxml-simple-perl libmouse-perl libmousex-nativetraits-perl libextutils-depends-perl perl libtest-deep-perl libtest-exception-perl libxml-parser-perl libtest-simple-perl libtest-fatal-perl libdata-dump-perl libtest-differences-perl libxml-tokeparser-perl libipc-run-perl libxcb-xtest0-dev libx11-xcb-perl libanyevent-i3-perl && \ + libmodule-install-perl libanyevent-perl libextutils-pkgconfig-perl xcb-proto cpanminus xvfb xserver-xephyr xauth libinline-perl libinline-c-perl libxml-simple-perl libmouse-perl libmousex-nativetraits-perl libextutils-depends-perl perl libtest-deep-perl libtest-exception-perl libxml-parser-perl libtest-simple-perl libtest-fatal-perl libdata-dump-perl libtest-differences-perl libxml-tokeparser-perl libipc-run-perl libxcb-xtest0-dev libx11-xcb-perl libjson-xs-perl && \ rm -rf /var/lib/apt/lists/* # Install i3 build dependencies.