#!/usr/bin/perl # # save/restore the workspace location of every window # # TODO? restore geometry (not needed for tiling wm though) # use strict; use warnings; use Getopt::Long; use JSON; my $filename = "$ENV{HOME}/.windowpositions.json"; sub save_windows { my $windows = {}; foreach my $line (split('\n', `wmctrl -l`)) { if ($line =~ m/^([0-9a-fx]+)\s+(\d+)\s+/) { $windows->{$1} = $2; } } open FILE, ">$filename" or die "Can't store positions."; print FILE encode_json($windows); close FILE; } sub restore_windows { my $desk_count = `wmctrl -d | wc -l`; open FILE, "<$filename" or die "No positions stored."; my $windows = decode_json(); close FILE; foreach my $win (keys %$windows) { my $desk = $windows->{$win} % $desk_count; `wmctrl -i -r $win -t $desk`; } } GetOptions( 'save' => \&save_windows, 'restore' => \&restore_windows, 'help' => sub { print "Usage: $0 <--save|--restore>\n"; }, );