greengeek wrote: Wed Jan 10, 2024 7:04 am(EDIT : The optimised code still occasionally struggled to modify some windows unless i ran the script twice so now I have modified the pet to do a double pass and it seems reliable now and gives a tidier alignment)
I can confirm that - very rarely - a window is left in its position. Tried many times with a desktop filled with 50 windows. Happened only twice. Could be a timing issue with the WM. Instead of duplicating the whole code it may help to position the windows first and then, in a second loop, activate them.
Would look like this:
Code: Select all
#!/bin/sh
current_desktop_id=$(wmctrl -d | grep '*' | cut -d ' ' -f 1)
#~ # Get list of windows
window_list=$(wmctrl -l -x | awk -v current_desktop="$current_desktop_id" '$2 == current_desktop {print $1}')
#Specify offsets
horizontal_offset=30
vertical_offset=30
#Iterate through windows and position them with offsets
#Nominate starting point. Avoid 0,0 and maybe push x further out to allow Home iconspace
x=58
y=20
for window_id in $window_list
do
#~ wmctrl -ir $window_id -e 0,$x,$y,540,200 # Position window with offsets
wmctrl -ir $window_id -e 0,$x,$y,-1,-1 # Position window with offsets
x=$((x + horizontal_offset)) # Increment x and y with steps and offsets
y=$((y + vertical_offset))
done
for window_id in $window_list
do
wmctrl -ia $window_id #Bring each window to top
done
I took the liberty to change the "Position" code line back to the one of your previous script, because now you not only position the windows, you also resize them to 520x200, which certainly looks very tidy but will make it very hard to recover from this operation. Eventually you will have to resize the windows manually back to a usable size, and even if you decide to close them, many applications remember their last size when you open them again. Specially mtPaint doesn't like to be reduced to such size, and small option windows may look weird when enlarged to 520x200.