Skip to content

Instantly share code, notes, and snippets.

@sleekweasel
Last active February 21, 2018 15:42
Show Gist options
  • Save sleekweasel/bc7fc34ad33c9dc7126ca10ed2c9ffc4 to your computer and use it in GitHub Desktop.
Save sleekweasel/bc7fc34ad33c9dc7126ca10ed2c9ffc4 to your computer and use it in GitHub Desktop.
Tile X11 windows from the command-line with xdotool
tile_emulators() {
DGEO=$(xdotool getdisplaygeometry)
index=0
for p in $( xdotool search 'enymotion' getwindowpid %@|sort |uniq ) ; do
GEOM=$(perl -le "
%A=(tot=>$EMULATORS, ix=>$index, dx=>${DGEO% *}, dy=>${DGEO#* });"'
$sq = int(sqrt($A{tot})); $sq++ if sqrt($A{tot}) > $sq;
$sx=$A{dx}/$sq; $sy=$A{dy}/$sq;
print "windowsize $sx $sy windowmove ",($A{ix} % $sq) * $sx," ",int($A{ix} / $sq) * $sy'
);
eval "xdotool search --all --pid $p --onlyvisible --class 'enymotion' $GEOM";
index=$[ index + 1 ];
done
}
@sleekweasel
Copy link
Author

sleekweasel commented Aug 15, 2016

Note: assumes one visible window per pid, and that an nn grid is good enough.
It would be easy enough to do n
m fitting.

@ageis
Copy link

ageis commented Feb 21, 2018

@sleekweasel Thanks for your script. I wanted to narrow the search to ---name, cause I had no idea what you meant by 'enymotion', but now I know that search defaults to window name, class, and classname.

I wish there was a way to do an inverse match of the name. Also want to apply only to one workspace. I might fork this and extend it to add some arguments.
FYI shellcheck:

    index=$[ index + 1 ];
          ^-- SC2007: Use $((..)) instead of deprecated $[..]

@ageis
Copy link

ageis commented Feb 21, 2018

Illegal division by zero =/ Too many windows?

        %A=(tot=>, ix=>0, dx=>1920, dy=>1080);
        $sq = int(sqrt($A{tot})); $sq++ if sqrt($A{tot}) > $sq;
        $sx=$A{dx}/$sq; $sy=$A{dy}/$sq;
        print "windowsize $sx $sy windowmove ",($A{ix} % $sq) * $sx," ",int($A{ix} / $sq) * $sy'
Illegal division by zero at -e line 4.
+ GEOM=

Update: I think my $EMULATORS env var is empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment