Skip to content

Commit

Permalink
Merge pull request #133 from ulodha/fix_waitforwindow
Browse files Browse the repository at this point in the history
Fix waitForWindow() on Mac and Windows.
  • Loading branch information
glitchassassin authored May 12, 2019
2 parents 3684a5a + 8f6ae58 commit a53e6e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lackey/App.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ def getWindow(self):
Returns an empty string if no match could be found.
"""
if self.getPID() != -1:
if not self.hasWindow():
return ""
return PlatformManager.getWindowTitle(PlatformManager.getWindowByPID(self.getPID()))
else:
return ""
Expand All @@ -213,7 +215,7 @@ def waitForWindow(self, seconds=5):
timeout = time.time() + seconds
while True:
window_region = self.window()
if window_region is not None or time.time() < timeout:
if window_region is not None or time.time() > timeout:
break
time.sleep(0.5)
return window_region
Expand All @@ -224,6 +226,8 @@ def window(self, windowNum=0):
"""
if self._pid == -1:
return None
if not self.hasWindow():
return None
x,y,w,h = PlatformManager.getWindowRect(PlatformManager.getWindowByPID(self._pid, windowNum))
return Region(x,y,w,h).clipRegionToScreen()

Expand Down
4 changes: 2 additions & 2 deletions lackey/PlatformManagerDarwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def getWindowByPID(self, pid, order=0):
return w["kCGWindowNumber"]
else:
order -= 1
raise OSError("Could not find window for PID {} at index {}".format(pid, order))
return None
def getWindowRect(self, hwnd):
""" Returns a rect (x,y,w,h) for the specified window's area """
for w in self._get_window_list():
Expand All @@ -340,7 +340,7 @@ def getWindowRect(self, hwnd):
width = w["kCGWindowBounds"]["Width"]
height = w["kCGWindowBounds"]["Height"]
return (x, y, width, height)
raise OSError("Unrecognized window number {}".format(hwnd))
return None
def focusWindow(self, hwnd):
""" Brings specified window to the front """
Debug.log(3, "Focusing window: " + str(hwnd))
Expand Down

0 comments on commit a53e6e3

Please sign in to comment.