diff --git a/cdp_patches/input/os_base/windows.py b/cdp_patches/input/os_base/windows.py index fc19b6e..1c8a524 100644 --- a/cdp_patches/input/os_base/windows.py +++ b/cdp_patches/input/os_base/windows.py @@ -28,6 +28,7 @@ def get_window(self) -> WindowSpecification: win32_app.connect(process=self.pid) self.browser_window: WindowSpecification = win32_app.top_window() + self.hwnd = self.browser_window.handle # Perform Window Checks self.browser_window.verify_actionable() assert self.browser_window.is_normal() diff --git a/dev/debug_conversion.py b/dev/debug_conversion.py index aec0e57..e0602b7 100644 --- a/dev/debug_conversion.py +++ b/dev/debug_conversion.py @@ -9,6 +9,8 @@ from tests.conftest import flags import subprocess +import ctypes + async def get_conversion(async_driver: typing.Union[Chrome, async_playwright] = None) -> typing.Tuple[ typing.List[typing.Tuple], typing.List[typing.Tuple]]: @@ -46,12 +48,39 @@ async def get_conversion(async_driver: typing.Union[Chrome, async_playwright] = return points, list([(x, y) for x, y in points_received]) +def is_aware(pid: int) -> bool: + process_handle = None + try: + process_handle = ctypes.windll.kernel32.OpenProcess( + 0, # no permissions + False, # bInheritHandle + pid + ) + aware = ctypes.c_int() + ctypes.windll.shcore.GetProcessDpiAwareness( + process_handle, + ctypes.byref(aware) + ) + finally: + if process_handle: + ctypes.windll.kernel32.CloseHandle(process_handle) + return aware + + async def conversion_driverless() -> typing.Tuple[typing.List[typing.Tuple], typing.List[typing.Tuple]]: options = ChromeOptions() for flag in flags: options.add_argument(flag) + options.add_argument("--device-scale-factor=0.4") async with Chrome() as driver: - driver.async_input = await AsyncInput(browser=driver) + async_input = await AsyncInput(browser=driver) + + is_dpi_aware = is_aware(async_input.pid) + if is_dpi_aware: + async_input.scale_factor = async_input.scale_factor * ( + ctypes.windll.shcore.GetScaleFactorForDevice(0) / 100) + + driver.async_input = async_input return await get_conversion(driver) @@ -60,7 +89,14 @@ async def conversion_playwright() -> typing.Tuple[typing.List[typing.Tuple], typ browser = await p.chromium.launch(headless=False, args=flags) context = await browser.new_context(locale="en-US") page = await context.new_page() - page.async_input = await AsyncInput(browser=context) # type: ignore[attr-defined] + async_input = await AsyncInput(browser=context) + + is_dpi_aware = is_aware(async_input.pid) + if is_dpi_aware: + async_input.scale_factor = async_input.scale_factor * ( + ctypes.windll.shcore.GetScaleFactorForDevice(0) / 100) + + page.async_input = async_input return await get_conversion(page)