#!/usr/bin/perl -w # This does not work if multiple windows have the same name. NAWM # provides no way to address this situation (e.g., specify window by # id). NAWM provides no way to iterate over top-level windows. It # provides an array of ALL X11 windows, which of course is unusable. # Hence I use ratpoison to get the window list. $tmpwm = shift || 'fluxbox'; @windows = qx{ ratpoison -c 'windows %l %t'|sort -n|sed -e 's/^[^ ]* //' } or die "ratpoison -c windows error: $!"; chomp for @windows; my %dup; $dup{$_}++ && die "two windows, one name! plz patch NAWM.\n" for @windows; ($width, $height) = qx{ nawm -e 'put itoa(screenwidth); put itoa(screenheight);' } or die "nawm error: $!"; my @nawm_cmds; sub nawm { my $cmd = shift; my $win = shift || 0; my $args; if ($win) { $win = qq{"$win"}; $args = join ", ", ($win, @_); } push @nawm_cmds, qq{$cmd $args;\n}; } sub resize { nawm 'sizeto', @_ } sub move { nawm 'moveto', @_ } sub raise { nawm 'raise', @_ } sub lower { nawm 'lower', @_ } sub focus { nawm 'raise', @_; nawm 'warptowindow', @_ } # iff focus follows mouse my ($x, $y) = (0,0); for $w (@windows) { resize $w, $width * .75, $height * .75; move $w, $x, $y; $_ += 30 for $x, $y; } lower $_ for reverse @windows; focus $windows[$#windows]; s/'/'\\''/g for @nawm_cmds; exec 'ratpoison', '-c', qq{tmpwm nawm -e '@nawm_cmds'; exec $tmpwm};