From: Zhiyi Zhang zzhang@codeweavers.com
Don't use the current mode in the registry if it's a detached mode when adding virtual modes. Otherwise, the requested/previous current mode in the registry could be a detached mode and it will cause functions like MonitorFromRect() to return NULL, even after monitor gets turned on.
Fix Witcher 3 (292030) black screen after monitor is turned off and then on. --- dlls/win32u/sysparams.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index d36a6ddfb7e..783ea6c3c11 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -466,6 +466,15 @@ static UINT devmode_get( const DEVMODEW *mode, UINT field ) return 0; }
+static BOOL is_detached_mode( const DEVMODEW *mode ) +{ + return mode->dmFields & DM_POSITION && + mode->dmFields & DM_PELSWIDTH && + mode->dmFields & DM_PELSHEIGHT && + mode->dmPelsWidth == 0 && + mode->dmPelsHeight == 0; +} + static BOOL write_source_mode( HKEY hkey, UINT index, const DEVMODEW *mode ) { WCHAR bufferW[MAX_PATH] = {0}; @@ -1761,7 +1770,7 @@ static void add_modes( const DEVMODEW *current, UINT host_modes_count, const DEV } else { - if (!read_source_mode( source->key, ENUM_CURRENT_SETTINGS, &virtual )) + if (!read_source_mode( source->key, ENUM_CURRENT_SETTINGS, &virtual ) || is_detached_mode( &virtual )) virtual = physical;
if ((virtual_modes = get_virtual_modes( current, &physical, host_modes, host_modes_count, &virtual_count ))) @@ -1815,15 +1824,6 @@ static void release_display_manager_ctx( struct device_manager_ctx *ctx ) } }
-static BOOL is_detached_mode( const DEVMODEW *mode ) -{ - return mode->dmFields & DM_POSITION && - mode->dmFields & DM_PELSWIDTH && - mode->dmFields & DM_PELSHEIGHT && - mode->dmPelsWidth == 0 && - mode->dmPelsHeight == 0; -} - static BOOL is_monitor_active( struct monitor *monitor ) { DEVMODEW current_mode = {.dmSize = sizeof(DEVMODEW)};