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
Try this script. Make it executable and attach it to a keyboard shortcut. It requires both the wmctrl and xdotool packages.
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.
thanks for the script
i get an error when I try to run it
./centerWindows.sh: 7: Syntax error: redirection unexpected
any ideas?
oh, I'm running xfce in termux proot-distro.
i have xdotool and wmctrl installed and working fine
thanks
Offline
Interesting. The script still works for me.
Try this version instead:
#!/usr/bin/env bash
WIDTH=1920
HEIGHT=1080
while read ID X Y W H
do
NX=$(($WIDTH/2-$W/2))
NY=$(($HEIGHT/2-$H/2))
wmctrl -i -r $ID -e 0,$NX,$NY,$W,$H
done < <(wmctrl -lG | grep -v " -1 " | awk '{print $1" " $3" "$4" "$5" " $6}')
exit 0
It only uses wmctrl and takes the screen dimensions manually.
Make sure you edit the WIDTH and HEIGHT variables to match your current screen dimensions.
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
Interesting. The script still works for me.
Try this version instead:
It only uses wmctrl and takes the screen dimensions manually.Make sure you edit the WIDTH and HEIGHT variables to match your current screen dimensions.
wow! you're amazing
that works... thanks so much
btw, what other cool, helpful, scripts do you have or recommend?
I've already stolen your workspace switcher notification one ; )
Offline
Glad it helped.
Most of my scripts have been posted here in the forum. Just search for "bin/bash" or "bin/sh" or "usr/bin/env" and user "Toz" to get a result set.
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
Glad it helped.
Most of my scripts have been posted here in the forum. Just search for "bin/bash" or "bin/sh" or "usr/bin/env" and user "Toz" to get a result set.
thanks... i'll take a look
Offline
[ Generated in 0.011 seconds, 7 queries executed - Memory usage: 547.94 KiB (Peak: 548.78 KiB) ]