Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@sleekweasel 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

This comment has been minimized.

Copy link

@ageis 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

This comment has been minimized.

Copy link

@ageis 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