You are not logged in.
Hello!
I am looking for a keyboard-shortcut or trick to center all open windows at once on the active screen??
The reason is if I switch off external screen with higher resolution, the windows from this screen are mostly 'offscreen' .
Offline
Try this script. Make it executable and attach it to a keyboard shortcut. It requires both the wmctrl and xdotool packages.
#!/bin/sh
# get the current desktop
CURR_DESK=$(wmctrl -d | grep "*" | awk '{print $1}')
# get the screen dimensions
IFS='x' read screenWidth screenHeight < <(xdpyinfo | grep dimensions | grep -o '[0-9x]*' | head -n1)
# for every window on this desktop
for w in $(wmctrl -l | grep " $CURR_DESK " | awk '{print $1}')
do
# raise the window
wmctrl -ia $w
# center the window
width=$(xdotool getactivewindow getwindowgeometry --shell | head -4 | tail -1 | sed 's/[^0-9]*//')
height=$(xdotool getactivewindow getwindowgeometry --shell | head -5 | tail -1 | sed 's/[^0-9]*//')
newPosX=$((screenWidth/2-width/2))
newPosY=$((screenHeight/2-height/2))
xdotool getactivewindow windowmove "$newPosX" "$newPosY"
done
Note: it will also raise and center minimized windows - not sure if this is what you want - it can be modified to check for those as well.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
[ Generated in 0.008 seconds, 7 queries executed - Memory usage: 522.27 KiB (Peak: 528.66 KiB) ]