AnyEvent-Sway

 view release on metacpan or  search on metacpan

lib/AnyEvent/Sway.pm  view on Meta::CPAN

    my ($self) = @_;

    $self->_ensure_connection;

    $self->message(TYPE_GET_TREE)
}

=head2 get_marks

Gets all the window identifier marks from Sway (>= v4.1).

    my $marks = sway->get_marks->recv;
    say Dumper($marks);

=cut
sub get_marks
{
    my ($self) = @_;

    $self->_ensure_connection;

    $self->message(TYPE_GET_MARKS)
}

=head2 get_bar_config

Gets the bar configuration for the specific bar id from Sway (>= v4.1).

    my $config = sway->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 get_version

Gets the Sway version via IPC, with a fall-back that parses the output of Sway
--version (for Sway < v4.3).

    my $version = sway->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 sway --version since the running Sway doesn’t support GET_VERSION yet.";
            my $version = _call_sway('--version');
            $version =~ s/^sway 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 get_config

Gets the raw last read config from Sway. Requires Sway >= 4.14

=cut
sub get_config
{
    my ($self) = @_;

    $self->_ensure_connection;

    $self->message(TYPE_GET_CONFIG);
}

=head2 send_tick

Sends a tick event. Requires Sway >= 4.15

=cut
sub send_tick
{
    my ($self, $payload) = @_;

    $self->_ensure_connection;

    $self->message(TYPE_SEND_TICK, $payload);
}

=head2 sync

Sends an Sway sync event. Requires Sway >= 4.16



( run in 2.030 seconds using v1.01-cache-2.11-cpan-f4a522933cf )