diff options
author | Michael Stapelberg <michael@stapelberg.de> | 2014-01-26 16:51:32 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2014-01-26 16:51:32 +0100 |
commit | da0acb20800999558b6302b2dea3e954a9c0ea26 (patch) | |
tree | fa685c48d7aec1d08f8f2f7c492ae88688445101 /contrib | |
parent | da3fc2ad6b987bfcb493efb8ab6c117d45b18752 (diff) | |
download | i3-da0acb20800999558b6302b2dea3e954a9c0ea26.tar.gz i3-da0acb20800999558b6302b2dea3e954a9c0ea26.zip |
contrib: add per-workspace-layout.pl
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/per-workspace-layout.pl | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/contrib/per-workspace-layout.pl b/contrib/per-workspace-layout.pl new file mode 100644 index 00000000..9304b6fd --- /dev/null +++ b/contrib/per-workspace-layout.pl @@ -0,0 +1,55 @@ +#!/usr/bin/env perl +# vim:ts=4:sw=4:expandtab +# © 2012 Michael Stapelberg +# Licensed under BSD license, see http://code.i3wm.org/i3/tree/LICENSE +# +# Append this line to your i3 config file: +# exec_always ~/per-workspace-layout.pl +# +# Then, change the %layouts hash like you want your workspaces to be set up. +# This script requires i3 >= v4.4 for the extended workspace event. + +use strict; +use warnings; +use AnyEvent; +use AnyEvent::I3; +use v5.10; + +my %layouts = ( + '4' => 'tabbed', + '5' => 'stacked', +); + +my $i3 = i3(); + +die "Could not connect to i3: $!" unless $i3->connect->recv(); + +die "Could not subscribe to the workspace event: $!" unless + $i3->subscribe({ + workspace => sub { + my ($msg) = @_; + return unless $msg->{change} eq 'focus'; + die "Your version of i3 is too old. You need >= v4.4" + unless exists($msg->{current}); + my $ws = $msg->{current}; + + # If the workspace already has children, don’t change the layout. + return unless scalar @{$ws->{nodes}} == 0; + + my $name = $ws->{name}; + my $con_id = $ws->{id}; + + return unless exists $layouts{$name}; + + $i3->command(qq|[con_id="$con_id"] layout | . $layouts{$name}); + }, + _error => sub { + my ($msg) = @_; + say "AnyEvent::I3 error: $msg"; + say "Exiting."; + exit 1; + }, + })->recv->{success}; + +# Run forever. +AnyEvent->condvar->recv |