2 # vim:ts=4:sw=4:expandtab
10 exclude => [ qw(all) ],
13 use File::Temp qw(tmpnam);
16 use X11::XCB qw(:all);
18 use List::Util qw(first);
19 # Test::Kit already uses Exporter
20 #use Exporter qw(import);
23 our @EXPORT = qw(get_workspace_names get_unused_workspace get_ws_content get_ws get_focused);
28 return $window_count++;
32 sub open_standard_window {
35 my $window = $x->root->create_child(
36 class => WINDOW_CLASS_INPUT_OUTPUT,
37 rect => [ 0, 0, 30, 30 ],
38 background_color => '#C0C0C0',
41 $window->name('Window ' . counter_window());
49 sub get_workspace_names {
50 my $i3 = i3("/tmp/nestedcons");
51 # TODO: use correct command as soon as AnyEvent::i3 is updated
52 my $tree = $i3->get_workspaces->recv;
53 my @workspaces = map { @{$_->{nodes}} } @{$tree->{nodes}};
54 [ map { $_->{name} } @workspaces ]
57 sub get_unused_workspace {
58 my @names = get_workspace_names();
60 do { $tmp = tmpnam() } while ($tmp ~~ @names);
66 my $i3 = i3("/tmp/nestedcons");
67 my $tree = $i3->get_workspaces->recv;
68 my @ws = map { @{$_->{nodes}} } @{$tree->{nodes}};
70 # as there can only be one workspace with this name, we can safely
71 # return the first entry
72 return first { $_->{name} eq $name } @ws;
76 # returns the content (== tree, starting from the node of a workspace)
77 # of a workspace. If called in array context, also includes the focus
78 # stack of the workspace
82 my $con = get_ws($name);
83 return wantarray ? ($con->{nodes}, $con->{focus}) : $con->{nodes};
88 my $i3 = i3("/tmp/nestedcons");
89 my $tree = $i3->get_workspaces->recv;
91 my @ws = map { @{$_->{nodes}} } @{$tree->{nodes}};
92 my @cons = grep { $_->{name} eq $ws } @ws;
95 my @focused = @{$con->{focus}};
97 while (@focused > 0) {
99 last unless defined($con->{focus});
100 @focused = @{$con->{focus}};
101 @cons = grep { $_->{id} == $lf } (@{$con->{nodes}}, @{$con->{'floating-nodes'}});