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,508

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

#3 2024-11-28 01:20:56

RaySurf
Member
Registered: 2024-10-28
Posts: 8
LinuxChrome 131.0

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

ToZ wrote:

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

#4 2024-11-28 03:13:32

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,508
LinuxFirefox 132.0

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

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

#5 2024-11-28 12:00:39

RaySurf
Member
Registered: 2024-10-28
Posts: 8
LinuxChrome 131.0

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

ToZ wrote:

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

#6 2024-11-28 15:53:05

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,508
LinuxFirefox 133.0

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

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

#7 2024-11-29 03:30:10

RaySurf
Member
Registered: 2024-10-28
Posts: 8
LinuxChrome 131.0

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

ToZ wrote:

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

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

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.011 seconds, 7 queries executed - Memory usage: 547.94 KiB (Peak: 548.78 KiB) ]