From 2b484b1ac7a5510be54cb5341143d89dc1924b37 Mon Sep 17 00:00:00 2001 From: Zhiyi Zhang Date: Mon, 17 Aug 2020 16:36:33 +0800 Subject: [PATCH] winex11.drv: Initialize new display device registry display settings. Signed-off-by: Zhiyi Zhang Signed-off-by: Alexandre Julliard --- dlls/winex11.drv/settings.c | 32 ++++++++++++++++++++++++++++++++ dlls/winex11.drv/x11drv.h | 1 + dlls/winex11.drv/xrandr.c | 2 ++ 3 files changed, 35 insertions(+) diff --git a/dlls/winex11.drv/settings.c b/dlls/winex11.drv/settings.c index 2d1fc7220de..c4929e9b584 100644 --- a/dlls/winex11.drv/settings.c +++ b/dlls/winex11.drv/settings.c @@ -177,6 +177,38 @@ void X11DRV_Settings_Init(void) X11DRV_Settings_SetHandler(&nores_handler); } +/* Initialize registry display settings when new display devices are added */ +void init_registry_display_settings(void) +{ + DEVMODEW dm = {.dmSize = sizeof(dm)}; + DISPLAY_DEVICEW dd = {sizeof(dd)}; + DWORD i = 0; + LONG ret; + + while (EnumDisplayDevicesW(NULL, i++, &dd, 0)) + { + /* Skip if the device already has registry display settings */ + if (EnumDisplaySettingsExW(dd.DeviceName, ENUM_REGISTRY_SETTINGS, &dm, 0)) + continue; + + if (!EnumDisplaySettingsExW(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm, 0)) + { + ERR("Failed to query current display settings for %s.\n", wine_dbgstr_w(dd.DeviceName)); + continue; + } + + TRACE("Device %s current display mode %ux%u %ubits %uHz at %d,%d.\n", + wine_dbgstr_w(dd.DeviceName), dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel, + dm.dmDisplayFrequency, dm.u1.s2.dmPosition.x, dm.u1.s2.dmPosition.y); + + ret = ChangeDisplaySettingsExW(dd.DeviceName, &dm, NULL, + CDS_GLOBAL | CDS_NORESET | CDS_UPDATEREGISTRY, NULL); + if (ret != DISP_CHANGE_SUCCESSFUL) + ERR("Failed to save registry display settings for %s, returned %d.\n", + wine_dbgstr_w(dd.DeviceName), ret); + } +} + static BOOL get_display_device_reg_key(const WCHAR *device_name, WCHAR *key, unsigned len) { static const WCHAR display[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y'}; diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index 4a7a0e12d49..233891f7b00 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -701,6 +701,7 @@ extern void X11DRV_Settings_SetHandler(const struct x11drv_settings_handler *han extern void X11DRV_init_desktop( Window win, unsigned int width, unsigned int height ) DECLSPEC_HIDDEN; extern void X11DRV_resize_desktop(BOOL) DECLSPEC_HIDDEN; +extern void init_registry_display_settings(void) DECLSPEC_HIDDEN; extern BOOL is_virtual_desktop(void) DECLSPEC_HIDDEN; extern BOOL is_desktop_fullscreen(void) DECLSPEC_HIDDEN; extern BOOL is_detached_mode(const DEVMODEW *) DECLSPEC_HIDDEN; diff --git a/dlls/winex11.drv/xrandr.c b/dlls/winex11.drv/xrandr.c index 155bd85d811..faeb4d98d99 100644 --- a/dlls/winex11.drv/xrandr.c +++ b/dlls/winex11.drv/xrandr.c @@ -1072,6 +1072,8 @@ static BOOL xrandr14_device_change_handler( HWND hwnd, XEvent *event ) * ChangeDisplaySettings(). Otherwise, ChangeDisplaySettings() would send multiple * WM_DISPLAYCHANGE messages instead of just one */ X11DRV_DisplayDevices_Update( FALSE ); + + init_registry_display_settings(); } return FALSE; }