Hi,

I am having problems scripting the window-manager i3 with perl using AnyEvent::I3 and as I could not get any help in an i3-forum, I try my luck here...

This works:

use strict; use AnyEvent; use AnyEvent::I3; my $i3 = i3(); $i3->connect->recv or die "Error connecting to i3"; $i3->command("workspace 1")->recv;
Running this changes to workspace 1.

And this also works:

use strict; use AnyEvent; use AnyEvent::I3; my $i3 = i3(); $i3->connect->recv or die "Error connecting to i3"; $i3->subscribe({ workspace => \&handle })->recv->{success} or die "Error subscribing to events" +; AE::cv->recv; sub handle { my($data)=@_; if($data->{change} eq "empty") { print "empty workspace!!\n"; } }
Running this prints "empty workspace!!" whenever a workspace become empty.

What I want now is to combine the logic, so whenever a workspace becomes empty we change to workspace 1.

Here is my attempt:

use strict; use AnyEvent; use AnyEvent::I3; my $i3 = i3(); $i3->connect->recv or die "Error connecting to i3"; $i3->subscribe({ workspace => \&handle })->recv->{success} or die "Error subscribing to events" +; AE::cv->recv; sub handle { my($data)=@_; if($data->{change} eq "empty") { print "empty workspace!!\n"; $i3->command("workspace 1")->recv; } }
However this does not work. It prints "empty workspace!!" ok, but it does not send the command, the error is:
EV: error in callback (ignoring): AnyEvent::CondVar: recursive blockin +g wait attempted
Any ideas?

Many thanks!


In reply to scripting i3 with Perl by morgon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.