Last active
February 21, 2018 15:42
-
-
Save sleekweasel/bc7fc34ad33c9dc7126ca10ed2c9ffc4 to your computer and use it in GitHub Desktop.
Tile X11 windows from the command-line with xdotool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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 $[..]
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
Note: assumes one visible window per pid, and that an nn grid is good enough.
It would be easy enough to do nm fitting.