This is an off-shoot of the discussion on "aerosnap" started by Stemsee here.
Yes you can line up windows nicely in four quadrants using wmctrl, but what if you have
too many windows for one desktop? This script tries to solve over-population of windows
on desktop 1. Not over-population of windows on desktop 2, and not over-population
of windows on desktop 3.
I mean: "Be careful, there is no checking. This is a draft." If you try this script with
only two desktops, and app Z gets lost in Lala land because the script sent it to desktop 3,
don't blame me or the script! Got it? There, you've been told! Also, please read the
notes in the code, I won't repeat myself.
It was fun doing; you do with it what you like. Any questions? This is what this thread is for!
Enjoy!
~~~~~~~~~~~~~
Code: Select all
#!/bin/sh
# /opt/local/Redimensionner/spread-out.sh
#
# Goal: Spread out too many windows on desktop 1 to desktops 2 and 3.
#
# Requires wmctrl, awk, wc.
####
# Notes --
# -- 1) May be used with script paves2.sh
#
# -- 2) Assumes that you have three desktops and that you are
# starting from desktop 0 (aka "first desktop" in human terms).
#
# -- 3) You can repeat the script to make even more room on desktop 1.
####
# © Christian L'Écuyer, Gatineau (Qc), Canada, 15 janv. 2018. GPL3
# (alias musher0 [forum Puppy])
#################### # https://opensource.org/licenses/GPL-3.0
# This program is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
##########
# Ce programme est libre : vous pouvez le redistribuer ou modifier selon les termes
# de la Licence Publique Générale GNU publiée par la Free Software Foundation (v. 3
# ou toute version ultérieure choisie par vous).
# Ce programme est distribué dans l'espoir qu'il sera utile, mais SANS AUCUNE
# GARANTIE, ni explicite ni implicite, y compris des garanties de commercialisation
# ou d'adaptation à un but spécifique. Pour plus de détails, veuillez vous reporter
# au texte officiel de cette licence à https://opensource.org/licenses/GPL-3.0, à
# http://www.linux-france.org/article/these/gpl.html pour une traduction et, pour une
# explication en français, à https://fr.wikipedia.org/wiki/Licence_publique_générale_GNU.
#################### set -xe
wmctrl -s 0 # See note 2 above.
wmctrl -l | awk '$2 ~ /0/ { print $1}' > /tmp/fen.lst
A="`wc -l < /tmp/fen.lst`";A="`echo $[$A/3]`"
head -n "$A" /tmp/fen.lst > /tmp/fen2.lst
tail -n "$A" /tmp/fen.lst > /tmp/fen3.lst
j=1;for i in 2 3;do
while read line;do
wmctrl -i -r "$line" -t $j
done < /tmp/fen$i.lst
j="`echo $[$j+1]`"
done
rm -f /tmp/fen*.lst # set +xe