summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2016-02-02 00:23:22 +0100
committerReiner Herrmann <reiner@reiner-h.de>2016-02-02 00:24:14 +0100
commit4207994b1be5e587c04d83a3a9f5354fd9b83c34 (patch)
treec0bf1c92e1e0f766237e32b77f9e1469691daa1b
parentb05b43242e5f739931cc197b451e6bcef1fc4327 (diff)
added windowpos script
-rwxr-xr-xwindowpos.pl48
1 files changed, 48 insertions, 0 deletions
diff --git a/windowpos.pl b/windowpos.pl
new file mode 100755
index 0000000..d070f4a
--- /dev/null
+++ b/windowpos.pl
@@ -0,0 +1,48 @@
+#!/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(<FILE>);
+ 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"; },
+);
+