[Xfce] Center window to current monitor

I have a script that centers a currently active window to the total width and height of all your screens (so basically puts the window half way on first and second monitor). I don't know xdotools (the script is from the internet, and works) and hence I'm asking here for help to make it center to either the primary monitor or to currently active monitor.

Here's the script:

IFS='x' read screenWidth screenHeight < <(xdpyinfo | grep dimensions | grep -o '[0-9x]*' | head -n1)

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"

Thank you in advance.

A start would be reading this

man xdotool
2 Likes

If you use KDE, why not go for a KWin script :slight_smile:

2 Likes

I don’t really mean to study and learn xdotool, honestly, hence I asked here. If I actually wanted to learn it, I’d spend a day or two googling and learning, but I just want this to work differently.

I’m using Xfce, but the topic was moved from there.

Ahah, you're right, sorry!
I remembered the case, but didn't notice it was from you :slight_smile:

2 Likes

This is a bash script that uses 1st grade school math.
You should ask the developer for this modification.

1 Like

That would be true if I had two the same monitors, then I’d just play with the math and be done with it, but I have one 1920x1080 and one 1600x900 monitor, and I’d want it to read the current monitor I’m in, which I don’t know how to do. But alright, guess I will not get help here.

I guess you misunderstand the situation.

You have stolen programming code and ask for help to improve it, from a community.
What should we do when we witness a theft?
What should we do with the thief?

1 Like

That script was provided on a forum hence it's not a theft as it's for public use. But if you do think it is in fact theft, just delete this topic and if needed, ban me as well.

You did not provide a link, or credit to the developer.
How would we know?

It doesn’t matter what we think. It is not a crime if you don’t know how to deal with Open Source code and licensing. Do some web research on this, so you improve your knowledge. :wink:

On topic,

I don’t know how to achieve this with command-line utilities.
Have you read xdotool man page?

Or maybe someone else knows how to do it and help…

1 Like

So, no sulotion in future.

1 Like