Xfce Forum

Sub domains
 

You are not logged in.

#1 2023-08-26 21:01:28

ixefce
Member
Registered: 2021-11-17
Posts: 29

Is there any keyboard-shortcut or trick to center all open windows?

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

#2 2023-08-27 00:44:48

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Is there any keyboard-shortcut or trick to center all open windows?

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

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.008 seconds, 7 queries executed - Memory usage: 522.27 KiB (Peak: 528.66 KiB) ]