AnyEvent-I3X-Workspace-OnDemand

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


Workspace switcher for i3.

This module listens to tick events which are named `group:$name` where the
name corresponds to the workspace groups you have defined. When you send a tick
event the current workspaces get renamed to `$former_group:$workspace_name` and leaves new workspaces for the ones you have defined.

In your `.config/i3/config` you can set something like this to switch
groups:

    bindsym $mod+w mode "Activities"
    mode "Activities" {
      bindsym 0 exec i3-msg -t send_tick group:foo; mode default
      bindsym 9 exec i3-msg -t send_tick group:bar; mode default
      bindsym 8 exec i3-msg -t send_tick group:baz; mode default
      bindsym Return mode "default"
      bindsym Escape mode "default"
    }

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(

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

field $log_all_events :param = undef;

field $socket :param = undef;
field $i3status :param = '/usr/bin/i3status';

field %workspace;
field %output;
field %mode;
field %window;
field %barconfig_update;
field %binding;
field %tick;
field %shutdown;

field @swallows;
field $c;

field $current_group;
field $current_workspace;

field $x11;

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

  %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';
  %mode     = %{ delete $args->{mode} }     if ref $args->{mode} eq 'HASH';
  %window   = %{ delete $args->{window} }   if ref $args->{window} eq 'HASH';
  %binding  = %{ delete $args->{binding} }  if ref $args->{binding} eq 'HASH';

  @groups   = @{ delete $args->{groups} } if ref $args->{groups} eq 'ARRAY';
  @swallows = @{ delete $args->{swallows} }
    if ref $args->{swallows} eq 'ARRAY';
}

method parse_path($path) {
  $path =~ s/\$(\w+)/$ENV{$1} \/\/ "\$$1"/ge;
  return $path;
}

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

      my $event   = shift;
      $self->log_event('window', $event);

      my $payload = $event->{change};
      if (my $sub = $window{$payload}) {
        $sub->($self, $i3, $event);
      }
    }
  );
  $self->subscribe(
    binding => sub {
      my $event   = shift;
      $self->log_event('binding', $event);
      my $payload = $event->{change};
      if (my $sub = $binding{$payload}) {
        $sub->($self, $i3, $event);
      }
    }
  );

}

method _is_in_group ($name, $group) {
  my $ws = $workspace{$name};
  return 0 unless $ws;

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

Workspace switcher for i3.

This module listens to tick events which are named C<< group:$name >> where the
name corresponds to the workspace groups you have defined. When you send a tick
event the current workspaces get renamed to C<< $former_group:$workspace_name
>> and leaves new workspaces for the ones you have defined.

In your C<< .config/i3/config >> you can set something like this to switch
groups:

  bindsym $mod+w mode "Activities"
  mode "Activities" {
    bindsym 0 exec i3-msg -t send_tick group:foo; mode default
    bindsym 9 exec i3-msg -t send_tick group:bar; mode default
    bindsym 8 exec i3-msg -t send_tick group:baz; mode default
    bindsym Return mode "default"
    bindsym Escape mode "default"
  }

For the user guide please refer to
L<AnyEvent::I3X::Workspace::OnDemand::UserGuide>.

=head1 METHODS

=head2 $self->subscribe

See L<AnyEvent::I3/subscribe>

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

        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"
  }

=head2 Layout Management

Now you need to create layouts for your workspaces, for this please refer to
the L<i3 website|https://i3wm.org/docs/layout-saving.html>. They have excellent
documenation and allows you to play a bit with your layout(s) before
configuring them: C<i3-msg "workspace foo; append_layout /path/to/layout.json">

You can store your layouts in C<$HOME/.config/i3>, or put them elsewhere and

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

layout without having to start them when you open i3. Closing an empty
workspace and reopening it will result in an C<init> action by i3 and gives you
a fresh layout start.

=head2 i3 Integration

Use to ensure i3-wod is always running correctly, even after reloading i3:

  exec_always --no-startup-id "i3-wod &"

As shown earlier you can use regular C<bindsym>s to trigger group or context
changes. Modes are the preferred way:

  # 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"
  }

But you can also use L<rofi|https://davatorium.github.io/rofi/> for a more
visual style. Script for this are not included in the distribution as it
would add a dependency and maybe unneeded for users who use different tools.

Once a group (or context) is switched current workspaces get renamed to
$former_group:$workspace_name and leaves new workspaces for the ones you have
defined. If you switch back to the previous group the workspaces get renamed,
and the old ones get reinserted/applied.



( run in 0.678 second using v1.01-cache-2.11-cpan-13bb782fe5a )