AnyEvent-Sway
view release on metacpan or search on metacpan
lib/AnyEvent/Sway.pm view on Meta::CPAN
package AnyEvent::Sway;
# vim:ts=4:sw=4:expandtab
use strict;
use warnings;
use JSON::XS;
use AnyEvent::Handle;
use AnyEvent::Socket;
use AnyEvent;
use Encode;
use Scalar::Util qw(tainted);
use Carp;
=head1 NAME
AnyEvent::Sway - communicate with the Sway window manager
=cut
our $VERSION = '0.18';
=head1 VERSION
Version 0.18
=head1 SYNOPSIS
This module connects to the Sway 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.
use AnyEvent::Sway qw(:all);
my $sway = sway();
$sway->connect->recv or die "Error connecting";
say "Connected to Sway";
my $workspaces = $sway->message(TYPE_GET_WORKSPACES)->recv;
say "Currently, you use " . @{$workspaces} . " workspaces";
...or, using the sugar methods:
use AnyEvent::Sway;
my $workspaces = Sway->get_workspaces->recv;
say "Currently, you use " . @{$workspaces} . " workspaces";
A somewhat more involved example which dumps the Sway layout tree whenever there
is a workspace event:
use Data::Dumper;
use AnyEvent;
use AnyEvent::Sway;
my $sway = sway();
$sway->connect->recv or die "Error connecting to Sway";
$sway->subscribe({
workspace => sub {
$sway->get_tree->cb(sub {
my ($tree) = @_;
say "tree: " . Dumper($tree);
});
}
( run in 0.779 second using v1.01-cache-2.11-cpan-39bf76dae61 )