From ed6b2758b44f7cc011352326eac4eef5b802f1e6 Mon Sep 17 00:00:00 2001 From: Alex Martens Date: Fri, 24 Nov 2023 17:32:36 -0800 Subject: [PATCH] Add debug logging to windows API calls --- monitorcontrol/vcp/vcp_windows.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/monitorcontrol/vcp/vcp_windows.py b/monitorcontrol/vcp/vcp_windows.py index 5fc369e..6696f89 100644 --- a/monitorcontrol/vcp/vcp_windows.py +++ b/monitorcontrol/vcp/vcp_windows.py @@ -35,10 +35,12 @@ def __init__(self, hmonitor: HMONITOR): Args: hmonitor: logical monitor handle """ + self.logger = logging.getLogger(__name__) self.hmonitor = hmonitor def __enter__(self): num_physical = DWORD() + self.logger.debug("GetNumberOfPhysicalMonitorsFromHMONITOR") try: if not ctypes.windll.dxva2.GetNumberOfPhysicalMonitorsFromHMONITOR( self.hmonitor, ctypes.byref(num_physical) @@ -61,6 +63,7 @@ def __enter__(self): raise VCPError("more than one physical monitor per hmonitor") physical_monitors = (PhysicalMonitor * num_physical.value)() + self.logger.debug("GetPhysicalMonitorsFromHMONITOR") try: if not ctypes.windll.dxva2.GetPhysicalMonitorsFromHMONITOR( self.hmonitor, num_physical.value, physical_monitors @@ -81,6 +84,7 @@ def __exit__( exception_value: Optional[BaseException], exception_traceback: Optional[TracebackType], ) -> Optional[bool]: + self.logger.debug("DestroyPhysicalMonitor") try: if not ctypes.windll.dxva2.DestroyPhysicalMonitor(self.handle): raise VCPError( @@ -101,6 +105,7 @@ def set_vcp_feature(self, code: int, value: int): Raises: VCPError: Failed to set VCP feature. """ + self.logger.debug(f"SetVCPFeature(_, {code=}, {value=})") try: if not ctypes.windll.dxva2.SetVCPFeature( HANDLE(self.handle), BYTE(code), DWORD(value) @@ -124,6 +129,9 @@ def get_vcp_feature(self, code: int) -> Tuple[int, int]: """ feature_current = DWORD() feature_max = DWORD() + self.logger.debug( + f"GetVCPFeatureAndVCPFeatureReply(_, {code=}, None, _, _)" + ) try: if not ctypes.windll.dxva2.GetVCPFeatureAndVCPFeatureReply( HANDLE(self.handle), @@ -135,6 +143,9 @@ def get_vcp_feature(self, code: int) -> Tuple[int, int]: raise VCPError("failed to get VCP feature: " + ctypes.FormatError()) except OSError as e: raise VCPError("failed to get VCP feature") from e + self.logger.debug( + f"GetVCPFeatureAndVCPFeatureReply -> ({feature_current.value}, {feature_max.value})" + ) return feature_current.value, feature_max.value def get_vcp_capabilities(self): @@ -153,7 +164,7 @@ def get_vcp_capabilities(self): """ cap_length = DWORD() - + self.logger.debug("GetCapabilitiesStringLength") try: if not ctypes.windll.dxva2.GetCapabilitiesStringLength( HANDLE(self.handle), ctypes.byref(cap_length) @@ -162,6 +173,7 @@ def get_vcp_capabilities(self): "failed to get VCP capabilities: " + ctypes.FormatError() ) cap_string = (ctypes.c_char * cap_length.value)() + self.logger.debug("CapabilitiesRequestAndCapabilitiesReply") if not ctypes.windll.dxva2.CapabilitiesRequestAndCapabilitiesReply( HANDLE(self.handle), cap_string, cap_length ): @@ -196,6 +208,8 @@ def _callback(hmonitor, hdc, lprect, lparam): BOOL, HMONITOR, HDC, ctypes.POINTER(RECT), LPARAM ) callback = MONITORENUMPROC(_callback) + + self.logger.debug("EnumDisplayMonitors") if not ctypes.windll.user32.EnumDisplayMonitors(0, 0, callback, 0): raise VCPError("Call to EnumDisplayMonitors failed") except OSError as e: