From 4083822b98e8a6e1dfcf04a9203a92f196f25b35 Mon Sep 17 00:00:00 2001 From: Brian Pitts Date: Sun, 20 Nov 2011 23:37:49 -0500 Subject: [PATCH] Import program and documentation --- README.markdown | 31 +++++++++++++++++++++++++++ i3tree | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 README.markdown create mode 100755 i3tree diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..f49e21a --- /dev/null +++ b/README.markdown @@ -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. diff --git a/i3tree b/i3tree new file mode 100755 index 0000000..38eed67 --- /dev/null +++ b/i3tree @@ -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 ); +