Change window title & swap window between two desktops
Saturday, June 17, 2006 6:31:31 PM
Update [12.02.2011]: The script below is now put (retroactively) into the public domain. Should have done this back then.
Update [11.03.2008]: Julien Bramary wrote a little tool in C that swaps windows much faster between Xinerama monitors than my script. Please use his swapmonitor (local copy) for production environments. If you want to learn more about Bash scripting and X11, read on.
If you want/need to change the title of a window (managed by a window manager like KWin/KDE or XFCE) just use wmctrl (Debian: apt-get install wmctrl).
wmctrl -i -r 0x02200005 -T "Datasheet 18F2550"
To get the window id use
wmctrl -l
This is particularly useful if you have opened many pdf files and your taskbar only shows the beginning of their path.
Wmctrl can do other useful things as well.
The following shell script moves a window from one screen of a Xinerama display to the other. A workaround is needed because KDE ignores window movement commands for maximized windows. The script restores the window size of a maximized window, moves it to the other screen and maximizes ist again. Bind it to a shortcut like Win+X. You'll never want to miss this feature again.
#!/bin/bash
# swap_window.sh
# Moves the active window to the other screen of a dual-screen Xinerama setup.
#
# Requires: wmctrl, xprop, xwininfo
#
# Author: Raphael Wimmer
# raphman@gmx.de
# This script has been put into the public domain - use it however you like.
# If you do something cool with it, please tell me.
# get monitorWidth
monitorLine=$(xwininfo -root | grep "Width")
monitorWidth=$((${monitorLine:8}/2 ))
echo $monitorWidth
# get active window id
activeWinLine=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)")
activeWinId="${activeWinLine:40}"
# get window position
xPosLine=$(xwininfo -id $activeWinId | grep "Absolute upper-left X")
xPos=${xPosLine:25}
# get window width
xWidthLine=$(xwininfo -id $activeWinId | grep "Width")
xWidth=${xWidthLine:8}
# get window decor
xWinDecorLine=$(xprop -id $activeWinId | grep "_KDE_NET_WM_FRAME_STRUT(CARDINAL)")
xWinDecor=${xWinDecorLine:35 :2}
# calculate new window position
if (( ${xPos} + ${xWidth}/2 > ${monitorWidth} ))
then xPos=$(( ${xPos} - ${monitorWidth} - ${xWinDecor} ))
else xPos=$(( ${xPos} + ${monitorWidth} - ${xWinDecor} ))
fi
# make sure window stays on screen completely
(( ${xPos} < 0 )) && xPos=0
(( ${xPos} + ${xWidth} > 2 * ${monitorWidth} )) && xPos=$((2*${monitorWidth} - ${xWidth}))
echo ${xPos}
# if maximized store info and de-maximize
winState=$(xprop -id ${activeWinId} | grep "_NET_WM_STATE(ATOM)" )
if [[ `echo ${winState} | grep "_NET_WM_STATE_MAXIMIZED_HORZ"` != "" ]]
then
maxH=1
wmctrl -i -r ${activeWinId} -b remove,maximized_horz
fi
if [[ `echo ${winState} | grep "_NET_WM_STATE_MAXIMIZED_VERT"` != "" ]]
then
maxV=1
wmctrl -i -r ${activeWinId} -b remove,maximized_vert
fi
# move window (finally)
wmctrl -i -r ${activeWinId} -e 0,${xPos},-1,-1,-1
# restore maximization
((${maxV})) && wmctrl -i -r ${activeWinId} -b add,maximized_vert
((${maxH})) && wmctrl -i -r ${activeWinId} -b add,maximized_horz
# raise window (seems to be necessary sometimes)
wmctrl -i -a ${activeWinId}
# and bye
exit 0








CaCO3 # Friday, August 18, 2006 11:17:13 AM
Es ist genau das, was ich gesucht habe.
Nur leider ist das Ganze recht langsam
Ich denke, mit dcop könnte man das Ganze noch um einiges beschleunigen, da man mit dcop ein Fenster direkt maximieren und verschieben kann.
Raphael Wimmerraphman # Tuesday, August 22, 2006 10:08:13 AM
Maybe (if time permits) I'll write a little C application that does the same as the script, only faster.
Or (more probably) I'll file a bug in bugs.kde.org and hope that KDE 4.0 will provide in-built functionality.
Anonymous # Tuesday, November 27, 2007 2:04:15 AM
Anonymous # Tuesday, February 26, 2008 6:01:30 PM
Raphael Wimmerraphman # Tuesday, February 26, 2008 6:12:16 PM
Anonymous # Monday, March 10, 2008 4:20:04 PM
Raphael Wimmerraphman # Tuesday, March 11, 2008 4:08:01 PM
thanks for sharing this tool. I'll be using it from now on. I've also added a link to your tool to the original post.
Thanks.
Raphael
Anonymous # Monday, July 7, 2008 1:44:12 PM
Anonymous # Friday, August 1, 2008 2:55:44 PM
Anonymous # Wednesday, October 21, 2009 9:07:52 PM
danitool # Tuesday, March 23, 2010 2:47:28 PM
thanks!!
danitool # Tuesday, March 23, 2010 3:35:20 PM
Raphael Wimmerraphman # Tuesday, March 23, 2010 3:41:12 PM
Originally posted by danitool:
Yes, this only works for one continuous display area on one X server.
Anonymous # Thursday, May 27, 2010 8:56:04 PM
Anonymous # Saturday, March 19, 2011 4:08:01 PM