NAME

AnyEvent::I3X::Workspace::OnDemand - An I3 workspace loader

VERSION

version 0.001

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
                bar => { layout => 'foo.json' },
            }
        },
        baz => {
            layout => 'baz.json',
            groups => {
                all => undef,
            }
        }
    },
    groups => [
        qw(foo bar baz)
    ],
    swallows => [
        {
            cmd => 'exec --no-startup-id kitty',
            match => {
                class => '^kitty$',
            }
        },
        {
            # Start firefox on group bar
            cmd => 'exec --no-startup-id firefox',
            on => {
                group => 'bar',
            }
            match => {
                window_role => '^browser$',
            }
        },
        {
            cmd => 'exec --no-startup-id google-chrome',
            on => {
                group => 'foo',
            }
            match => {
                window_role => '^browser$',
            }
        }
    ],
);

DESCRIPTION

Workspace switcher for i3.

METHODS

subscribe

See "subscribe" in AnyEvent::I3

get_i3

Get the AnyEvent::I3 instance

command(@args)

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

debug(1)

Enable or disable debug

log($msg)

Print warns when debug is enabled

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)

on_tick(
  'foo',
  sub {
    my $self  = shift;
    my $i3    = shift;
    my $event = shift;
    print "Yay processed foo tick";
  }
);

on_workspace($name, $type, $sub)

Subscribe to a workspace event for workspace $name of $type with $sub.

$type can be any of the following events from i3 plus any or *

on_workspace(
  'www', 'init',
  sub {
    my $self  = shift;
    my $i3    = shift;
    my $event = shift;
    $self->append_layout($event->{current}{name}, '/path/to/layout.json');
  }
);

add_swallow($match, $cmd, $on)

Add a command that can be used to start after a layout has been appended

add_swallow({ class => '^kitty$' }, 'exec --no-startup-id kitty');

# or only on this group
add_swallow(
  { class => '^kitty$' },
  'exec --no-startup-id kitty',
  { group => 'foo' }
);

# or workspace
add_swallow(
  { class => '^kitty$' },
  'exec --no-startup-id kitty',
  { workspace => 'foo' }
);

workspace($name, @cmds)

Runs commands on workspace by name

command

AUTHOR

Wesley Schwengle <waterkip@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2024 by Wesley Schwengle.

This is free software, licensed under:

The (three-clause) BSD License