Commit fca6b5a4 authored by kpetersn's avatar kpetersn
Browse files

Initial import of xWindowFix, a python script that works around bugs in XQuartz

OS X systems with multiple monitors and "Displays have separate Spaces" enabled,
X-windows are frequently displayed off-screen with no way of accessing them when
the computer is unlocked. This script eliminates the need to kill and restart

git-svn-id: f095f811-4e88-6c84-d33e-e382bdb4531c
#!/usr/bin/env python
# Move X11 windows that wander away when the screen is locked back to the main display
from subprocess import Popen, PIPE, call, check_output
# output=`xprop -root | grep "_NET_CLIENT_LIST(WINDOW)"`
p1 = Popen(["xprop", "-root"], stdout=PIPE)
p2 = Popen(["grep", "_NET_CLIENT_LIST(WINDOW)"], stdin=p1.stdout, stdout=PIPE)
output = p2.communicate()[0]
#!print output
junk, idListStr = output.split("#")
#!print junk
idList = idListStr.strip().split(", ")
#!print idList
titleDict = {}
# xdotool windowmove 0x100017d 10 10
index = 1
for idStr in idList:
#print idStr
# xdotool getwindowname 0x60017d
# get the window name
cmd = "{0} {1}".format("xdotool getwindowname", idStr)
title=check_output(cmd, shell=True)
titleDict[idStr] = title.strip()
# xdotool windowraise 0xe0017d
# raise the window to see if it is visible (not helpful because it often obscures the terminal)
#cmd = "{0} {1}".format("xdotool windowraise", idStr)
#call(cmd, shell=True)
#response = raw_input("Do you see the window? ")
#if response.strip().lower() in ("y", "yes"):
# print "Good. Continuing on to the next window."
# print "Ok. I'll try to fix the problem."
# indescrimately move the windows to the left (not a good approach)
#cmd = "{0} {1} {2} {2}".format("xdotool windowmove", idStr, index*10)
#print cmd
#call(cmd, shell=True)
index += 1
print "Type 'yes' to correct the window's position"
for idStr in idList:
promptStr = "{0}\n? ".format(titleDict[idStr])
response = raw_input(promptStr)
print response
if response.strip().lower() in ("y", "yes"):
print "Fixing the problem..."
# Get the X position of the window
# xdotool getwindowgeometry 0x60017d
cmd = "{0} {1}".format("xdotool getwindowgeometry --shell", idStr)
geomStr = check_output(cmd, shell=True)
geomList = geomStr.strip().split("\n")
# X pos is the 2nd in the list
xPos = int(geomList[1].split("=")[1])
# Correct the X position
if xPos >= 1920:
# move the window to the left
print "Moved the window left"
cmd = "xdotool windowmove --relative {0} {1}, y".format(idStr, -1920)
call(cmd, shell=True)
# move the window to the right
print "Moved the window right"
cmd = "xdotool windowmove --relative {0} {1}, y".format(idStr, 1920)
call(cmd, shell=True)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment