AnyEvent-I3X-Workspace-OnDemand

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

    }

For the user guide please refer to
[AnyEvent::I3X::Workspace::OnDemand::UserGuide](https://metacpan.org/pod/AnyEvent%3A%3AI3X%3A%3AWorkspace%3A%3AOnDemand%3A%3AUserGuide).

# SYNOPSIS

    use AnyEvent::I3X::Workspace::OnDemand;

    my $i3 = AnyEvent::I3X::Workspace::OnDemand->new(
        debug => 0,
        layout_path => "$ENV{HOME}/.config/i3",
        workspaces => {
            foo => {
                layout => 'foo.json',
            },
            bar => {
                layout => 'bar.json',
                groups => {
                    foo => undef,
                    # Override the layout for group bar

README.md  view on Meta::CPAN

## $self->get\_i3

Get the [AnyEvent::I3](https://metacpan.org/pod/AnyEvent%3A%3AI3) instance

## $self->command(@args)

Execute a command, the command can be in scalar or list context.

See also ["command" in AnyEvent::I3](https://metacpan.org/pod/AnyEvent%3A%3AI3#command).

## $self->debug(1)

Enable or disable debug

## $self->log($msg)

Print warns when debug is enabled

## $self->on\_tick($payload, $sub)

Subscribe to a tick event with `$payload` and perform the action. Your sub
needs to support the following prototype:

    sub foo($self, $i3, $event) {
        print "Yay processed foo tick";
    }

bin/i3-ipc  view on Meta::CPAN

use EV;
use Getopt::Long;
use File::Spec::Functions qw(catfile);
use Pod::Usage qw(pod2usage);


my %options = (
  logfile => catfile($ENV{HOME}, qw(.config i3 i3-ipc-events.log)),
);

GetOptions(\%options, qw(debug help man logfile=s socket=s));

if ($options{help}) {
    pod2usage(-verbose => 1);
}
if ($options{man}) {
    pod2usage(-verbose => 2);
}

my $i3 = AnyEvent::I3X::Workspace::OnDemand->new(
  debug          => $options{debug} // 0,
  socket         => $options{socket},
  log_all_events => $options{logfile},
);

EV::loop;
AE::cv->recv;

exit 0;

__END__

bin/i3-wod  view on Meta::CPAN

use YAML::XS qw(LoadFile);
use Pod::Usage qw(pod2usage);
use Proc::Find qw(find_proc);


my %options = (
  config => catfile($ENV{HOME}, qw(.config i3 wod.conf)),
  workdir => catfile($ENV{HOME}, qw(.config i3)),
);

GetOptions(\%options, qw(debug help man config=s workdir=s));

if ($options{help}) {
    pod2usage(-verbose => 1);
}
if ($options{man}) {
    pod2usage(-verbose => 2);
}

if (!-f $options{config} || ! -r $options{config}) {
    die "Unable to open configuration file $options{config}";
}

my $config = LoadFile($options{config});
my $workdir = $options{workdir} // delete $config->{workdir};
my $debug = $options{debug} // delete $config->{debug};

my $pidfile = catfile($workdir, 'pid');

if (-f $pidfile) {
    open my $fh, '<', $pidfile;
    my $pid = find_proc(pid => <$fh>, detail => 1);
    close($fh);
    if (@$pid && $pid->[0]{fname} eq 'i3-wod') {
        die "Already started, not running twice", $/;
    }
    unlink($pidfile);
}

open my $fh, '>', $pidfile;
print $fh $$;
close($fh);


my $i3 = AnyEvent::I3X::Workspace::OnDemand->new(
  %{$config},
  defined $debug ? (debug => $debug) : (),
);

# We kill ourselves after a shutdown
$i3->on_shutdown(exit => sub { exit 0 });
$i3->on_shutdown(restart => sub { exit 0 });

EV::loop;
AE::cv->recv;

exit 0;

bin/i3-wod  view on Meta::CPAN

=head1 OPTIONS

=head2 --config

Your configuration for this workspace loader

=head2 --workdir

The workdir for this loader

=head2 --debug

Enable debugging

=head2 --help

This help

=head1 AUTHOR

Wesley Schwengle <waterkip@cpan.org>

=head1 COPYRIGHT AND LICENSE

lib/AnyEvent/I3X/Workspace/OnDemand.pm  view on Meta::CPAN

use File::Spec::Functions qw(catfile);
use Data::Compare;
use Data::Dumper;

field $i3;
field $layout_path : param = catfile($ENV{HOME}, qw(.config i3));

field @groups;
field $starting_group :param = undef;
field $starting_workspace :param = undef;
field $debug :param          = 0;

field $log_all_events :param = undef;

field $socket :param = undef;

field %workspace;
field %output;
field %mode;
field %window;
field %barconfig_update;

lib/AnyEvent/I3X/Workspace/OnDemand.pm  view on Meta::CPAN


field @swallows;
field $c;

field $current_group;
field $current_workspace;

ADJUSTPARAMS {
  my $args = shift;

  $debug = 1 if $log_all_events;

  # i3
  %workspace = %{ delete $args->{workspace} }
    if ref $args->{workspace} eq 'HASH';
  %barconfig_update = %{ delete $args->{barconfig_update} }
    if ref $args->{barconfig_update} eq 'HASH';

  %tick     = %{ delete $args->{tick} }     if ref $args->{tick} eq 'HASH';
  %shutdown = %{ delete $args->{shutdown} } if ref $args->{shutdown} eq 'HASH';
  %output   = %{ delete $args->{output} }   if ref $args->{output} eq 'HASH';

lib/AnyEvent/I3X/Workspace/OnDemand.pm  view on Meta::CPAN


      $current_group = $group;
      $self->workspace($cur);
    }
  );


}

method log ($msg) {
  return unless $debug;
  warn $msg, $/;
  return;
}

method debug ($d = undef) {
  return $debug unless defined $d;
  $debug = $d;
}

my @any = qw(any *);

method on_workspace ($name, $type, $sub) {

  if (ref $sub ne 'CODE') {
    croak("Please supply a code ref!");
  }

lib/AnyEvent/I3X/Workspace/OnDemand.pm  view on Meta::CPAN


=head1 VERSION

version 0.005

=head1 SYNOPSIS

    use AnyEvent::I3X::Workspace::OnDemand;

    my $i3 = AnyEvent::I3X::Workspace::OnDemand->new(
        debug => 0,
        layout_path => "$ENV{HOME}/.config/i3",
        workspaces => {
            foo => {
                layout => 'foo.json',
            },
            bar => {
                layout => 'bar.json',
                groups => {
                    foo => undef,
                    # Override the layout for group bar

lib/AnyEvent/I3X/Workspace/OnDemand.pm  view on Meta::CPAN

=head2 $self->get_i3

Get the L<AnyEvent::I3> instance

=head2 $self->command(@args)

Execute a command, the command can be in scalar or list context.

See also L<AnyEvent::I3/command>.

=head2 $self->debug(1)

Enable or disable debug

=head2 $self->log($msg)

Print warns when debug is enabled

=head2 $self->on_tick($payload, $sub)

Subscribe to a tick event with C<< $payload >> and perform the action. Your sub
needs to support the following prototype:

    sub foo($self, $i3, $event) {
        print "Yay processed foo tick";
    }

lib/AnyEvent/I3X/Workspace/OnDemand/UserGuide.pod  view on Meta::CPAN

      group:
        work:
        personal:
    dbg:
      group:
        work:
        personal:

  # i3 config
  set $dev "dev"
  set $debug "dbg"
  bindsym $mod+1 workspace $dev
  bindsym $mod+2 workspace $debug
  bindsym $mod+Shift+1 move container to workspace $dev
  bindsym $mod+Shift+2 move container to workspace $debug

  # Dynamic workspaces
  bindsym $mod+w mode "Dynamic workspaces"
  mode "Dynamic workspaces" {
    bindsym 0 exec i3-msg -t send_tick group:personal; mode default
    bindsym 9 exec i3-msg -t send_tick group:work; mode default
    bindsym Return mode "default"
    bindsym Escape mode "default"
  }



( run in 0.280 second using v1.01-cache-2.11-cpan-5f4f29bf90f )