Skip to content

Commit

Permalink
Import program and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sciurus committed Nov 21, 2011
0 parents commit 4083822
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## OVERVIEW
i3tree is a program I wrote to help myself adjust to version 4 of the i3 tiling window manager. It displays the containers your windows are children of and what layout those containers are using.

## INSTALLATION
wwwaiter requires an installation of the i3 window manager, perl, and the following two perl modules.

* AnyEvent::I3
* X11::Protocol

## USAGE
Just run it.

## EXAMPLES

$ i3tree
Workspace 1 (horizontal)
Window foo@bar: ~
Split (vertical)
Window foo@bar: ~
Window foo@bar: ~
Workspace 2 (vertical)
Window foo@bar: ~
Window foo@bar: ~

## LIMITATIONS
You have to start i3tree from a running terminal. It would be neat if i3tree could be invoked from a keyboard shortcut and draw to a floating window.

i3tree shows containers from all workspaces. It could be useful to optionally limit this to only the current workspace.

## THANKS
Thanks to everyone who has contributed to i3.
56 changes: 56 additions & 0 deletions i3tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env perl

use strict;
use warnings;

use AnyEvent::I3;
use X11::Protocol;

# get path to i3 socket by reading property of X11 root window
my $x = X11::Protocol->new();
my ( $value, $mtype, $format, $bytes_after ) =
$x->GetProperty( $x->root, $x->atom('I3_SOCKET_PATH'),
'AnyPropertyType', 0, -1, 0 );

my $i3 = i3($value);
$i3->connect->recv or die "Error connecting";

# use number rather than constant to support older versions of anyevent::i3
my $tree = $i3->message(4)->recv;

sub display_node {
my ( $description, $depth ) = @_;
my $margin = "\t" x $depth;
print $margin . $description . "\n";
return $depth + 1;
}

sub walk_tree {
my ( $node, $depth ) = @_;

my $type = $node->{'type'};
my $orientation = $node->{'orientation'};
my $name = $node->{'name'};

if ( $type == 4 ) {
$depth = display_node( "Workspace $name ($orientation)", $depth );
}

if ( $type == 2 ) {
if ( $orientation eq "none" ) {
unless ( $name eq "content" or $name =~ "^i3bar" ) {
$depth = display_node( "Window $name", $depth );
}
}
else {
$depth = display_node( "Split ($orientation)", $depth );
}
}

foreach ( @{ $node->{'nodes'} } ) {
walk_tree( $_, $depth );
}
}

walk_tree( $tree, 0 );

0 comments on commit 4083822

Please sign in to comment.