def _getWindowRect(hWnd):
    """Returns `Rect` for specified MacOS window based on CGWindowID"""
    # hWnd equivalent in MacOS is CGWindowID
    # https://developer.apple.com/documentation/coregraphics/cgwindowid?language=objc
    # windows = Quartz.CGWindowListCopyWindowInfo(Quartz.kCGWindowListExcludeDesktopElements | Quartz.kCGWindowListOptionOnScreenOnly, Quartz.kCGNullWindowID)
    windows = Quartz.CGWindowListCopyWindowInfo(
        Quartz.kCGWindowListExcludeDesktopElements, Quartz.kCGNullWindowID)
    for win in windows:
        if hWnd == win['kCGWindowNumber']:
            w = win['kCGWindowBounds']
            return pygetwindow.Rect(left=w['X'],
                                    top=w['Y'],
                                    right=w['X'] + w['Width'],
                                    bottom=w['Y'] + w['Height'])
Ejemplo n.º 2
0
def _getWindowRect(hWnd):
    """A nice wrapper for GetWindowRect(). TODO

    Syntax:
    BOOL GetWindowRect(
      HWND   hWnd,
      LPRECT lpRect
    );

    Microsoft Documentation:
    https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowrect
    """
    rect = RECT()
    result = ctypes.windll.user32.GetWindowRect(hWnd, ctypes.byref(rect))
    if result != 0:
        return pygetwindow.Rect(rect.left, rect.top, rect.right, rect.bottom)
    else:
        _raiseWithLastError()