Module variables in Python might look like other languages' global variables, but in Python every name at the module level is scoped by the module name, so there are no global variables. The default_targets
module variable defined below contains the list of windows that WindowMover can move from one display to another:
# All windows on this list will be kept on
# the primary display or moved to the secondary
# display based on the 'keep' parameter below
default_targets = 
variable determines whether the target windows should be moved or whether they should remain in their original display while all other
windows get moved. In some testing situations it helps to switch back and forth:
# determine if the targets on the primary display
# should be kept there or moved to the secondary display.
keep = True
variable defined below controls the delay between successive iterations. Finding the right delay is very important; a delay that's too short will negatively impact system performance, because it will use up resources by constantly checking every window. A delay that's too long lets undesirable windows show up on the wrong display without moving them to the other display quickly enough:
# Determine how often to check for targets (in seconds).
# As this number approaches zero program responsiveness
# improves (windows move almost immediately to the other
# display) but it can also hog the CPU (the computer
# won't be able to do much else)
check_delay = 0.1 # in seconds
variable helps to adjust the location of a window moving between displays with different resolutions:
# This parameter is very important when resolutions
# of the two displays are different.
# If the primary display is taller than the secondary,
# then the top of the secondary display doesn't start at 0!
# The top of the secondary will actually be the difference
# in heights.
height_difference = 177
It turns out that height_difference
works in a very unintuitive way; you'll see more about that later.
You need to get the actual dimensions of the stretched desktop (across both displays), which you can do using two Windows API functions. GetDesktopWindow()
returns the window handle of the desktop itself (which is also a window), and GetWindowRect()
gets the left/top coordinate (always 0, 0
for the desktop) and the width/height:
The main() Function
monitor_width, monitor_height =
function launches the MonitorThread and determines whether it should run forever, or only for the specified number of seconds:
print 'Monitor dimensions:',
t = MonitorThread(verbose=False)
if seconds == 0.0:
# run forever
function accepts the number of seconds to run (10 seconds by default). If the parameter is 0
the program goes into an infinite loop, otherwise it sleeps for the specified number of seconds, letting the monitor thread do its thing, and eventually stops the thread.