def get_scaling_factor(window):
    """
    Tries to get the scaling factor of the given Window. Currently works
    on MacOS only. Useful in figuring out what's going on with Retina and
    high-res displays.

    :param Window window: Handle to window we want to get scaling factor of.

    :return: Scaling factor. E.g., 2 would indicate scaled up twice.
    :rtype: int

    """
    from pyglet import compat_platform
    if compat_platform == 'darwin':
        from pyglet.libs.darwin.cocoapy import NSMakeRect
        view = window.context._nscontext.view()
        content_rect = NSMakeRect(0, 0, window.width, window.height)
        bounds = view.convertRectFromBacking_(content_rect)
        return int(content_rect.size.width / bounds.size.width)
    else:
        return 1
