Tips and Tricks from the Xfce Forum

Topics relating to MX Docs and MX Videos
Message
Author
User avatar
Jerry3904
Administrator
Posts: 21881
Joined: Wed Jul 19, 2006 6:13 am

Re: Tips and Tricks from the Xfce Forum

#21 Post by Jerry3904 »

Thanks. Just to be clear: I didn't create the script, just linked to it. Most of those on the Wiki site go back to Xfce 4.12 and GTK2, so much has changed in the meantime.
Production: 5.10, MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: Lenovo X1 Carbon with MX-23 Fluxbox and Windows 10
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

User avatar
fehlix
Developer
Posts: 10303
Joined: Wed Apr 11, 2018 5:09 pm

Re: Center a window using the keyboard

#22 Post by fehlix »

JRG wrote: Thu May 07, 2020 2:22 pm While the script may have worked in the past, it now does not. There may have been issues (e.g., "smart quotes") when the script was copied into the post. In the process of debugging it for my own use, I found a number of things in the script and rewrote it (based on the script posted by Jerry3904). I assigned it to the Right Win key.

Here it is:

Code: Select all

#!/bin/bash

# Based on the script by Jerry3904

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

winId=`xdotool getactivewindow`

width=$(xdotool getwindowgeometry -shell $winId | head -4 | tail -1 | sed 's/[^0-9]*//')
height=$(xdotool getwindowgeometry -shell $winId | head -5 | tail -1 | sed 's/[^0-9]*//')

newPosX=$((screenWidth/2-width/2))
newPosY=$((screenHeight/2-height/2))

xdotool windowmove $winId $newPosX $newPosY
This script does not work for my two monitors b/c " xdpyinfo | grep dimensions" gives me a combined dimension of both screens.
So the script moves the window in the center of/between both monitors.

Here is and adjusted and slightly shorter version which moves the window into the center of the primary monitor:

Code: Select all

#!/bin/bash
# this script moves the active window into center of the primary monitor
# inspired by mx-linux forum memember JRG within this thread:
# https://forum.mxlinux.org/viewtopic.php?p=573895#p573895
#  
eval $(xdotool getactivewindow getwindowgeometry --shell --prefix=WIN_) 
eval $(xdotool getdisplaygeometry --shell)
xdotool getactivewindow windowmove $(( ($WIDTH - $WIN_WIDTH)/2 )) $(( ($HEIGHT - $WIN_HEIGHT)/2 ))
:puppy:
Gigabyte Z77M-D3H, Intel Xeon E3-1240 V2 (Quad core), 32GB RAM,
GeForce GTX 770, Samsung SSD 850 EVO 500GB, Seagate Barracuda 4TB

JRG
Posts: 3
Joined: Tue Jun 13, 2017 4:53 pm

Re: Tips and Tricks from the Xfce Forum

#23 Post by JRG »

@Fehlix

Nicely done. :happy:

Post Reply

Return to “Documentation and videos”