From 1f2c3e8538b088f678a588121fc0bf7811336efc Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 1 Dec 2021 16:02:43 +0100 Subject: [PATCH] win32u: Move NtUserEnumDisplaySettings implementation from user32. Signed-off-by: Jacek Caban Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/user32/driver.c | 7 +------ dlls/user32/sysparams.c | 39 ++++++------------------------------ dlls/win32u/driver.c | 35 +++++++++++++++++--------------- dlls/win32u/gdiobj.c | 1 + dlls/win32u/sysparams.c | 33 ++++++++++++++++++++++++++++++ dlls/win32u/win32u.spec | 2 +- dlls/win32u/win32u_private.h | 10 ++++++++- dlls/win32u/wrappers.c | 15 ++++++-------- include/ntuser.h | 2 ++ 9 files changed, 78 insertions(+), 66 deletions(-) diff --git a/dlls/user32/driver.c b/dlls/user32/driver.c index 9ff676aca22..851404ae94d 100644 --- a/dlls/user32/driver.c +++ b/dlls/user32/driver.c @@ -274,11 +274,6 @@ static BOOL CDECL loaderdrv_EnumDisplayMonitors( HDC hdc, LPRECT rect, MONITOREN return load_driver()->pEnumDisplayMonitors( hdc, rect, proc, lp ); } -static BOOL CDECL loaderdrv_EnumDisplaySettingsEx( LPCWSTR name, DWORD num, LPDEVMODEW mode, DWORD flags ) -{ - return load_driver()->pEnumDisplaySettingsEx( name, num, mode, flags ); -} - static BOOL CDECL loaderdrv_GetMonitorInfo( HMONITOR handle, LPMONITORINFO info ) { return load_driver()->pGetMonitorInfo( handle, info ); @@ -345,7 +340,7 @@ static struct user_driver_funcs lazy_load_driver = /* display modes */ loaderdrv_ChangeDisplaySettingsEx, loaderdrv_EnumDisplayMonitors, - loaderdrv_EnumDisplaySettingsEx, + NULL, loaderdrv_GetMonitorInfo, NULL, /* windowing functions */ diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index 592b4e2fdd5..caee78dbab9 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -3296,43 +3296,16 @@ BOOL WINAPI EnumDisplaySettingsExA(LPCSTR lpszDeviceName, DWORD iModeNum, /*********************************************************************** - * EnumDisplaySettingsExW (USER32.@) + * EnumDisplaySettingsExW (USER32.@) */ -BOOL WINAPI EnumDisplaySettingsExW(LPCWSTR lpszDeviceName, DWORD iModeNum, - LPDEVMODEW lpDevMode, DWORD dwFlags) +BOOL WINAPI EnumDisplaySettingsExW( const WCHAR *device, DWORD mode, + DEVMODEW *dev_mode, DWORD flags ) { - WCHAR primary_adapter[CCHDEVICENAME]; - BOOL ret; - - TRACE("%s %#x %p %#x\n", wine_dbgstr_w(lpszDeviceName), iModeNum, lpDevMode, dwFlags); - - if (!lpszDeviceName) - { - if (!get_primary_adapter(primary_adapter)) - return FALSE; - - lpszDeviceName = primary_adapter; - } - - if (!is_valid_adapter_name(lpszDeviceName)) - { - ERR("Invalid device name %s.\n", wine_dbgstr_w(lpszDeviceName)); - return FALSE; - } - - ret = USER_Driver->pEnumDisplaySettingsEx(lpszDeviceName, iModeNum, lpDevMode, dwFlags); - if (ret) - TRACE("device:%s mode index:%#x position:(%d,%d) resolution:%ux%u frequency:%uHz " - "depth:%ubits orientation:%#x.\n", wine_dbgstr_w(lpszDeviceName), iModeNum, - lpDevMode->u1.s2.dmPosition.x, lpDevMode->u1.s2.dmPosition.y, lpDevMode->dmPelsWidth, - lpDevMode->dmPelsHeight, lpDevMode->dmDisplayFrequency, lpDevMode->dmBitsPerPel, - lpDevMode->u1.s2.dmDisplayOrientation); - else - WARN("Failed to query %s display settings.\n", wine_dbgstr_w(lpszDeviceName)); - return ret; + UNICODE_STRING str; + RtlInitUnicodeString( &str, device ); + return NtUserEnumDisplaySettings( &str, mode, dev_mode, flags ); } - /********************************************************************** * get_monitor_dpi */ diff --git a/dlls/win32u/driver.c b/dlls/win32u/driver.c index 93c2ff1da4c..4af0e4fced7 100644 --- a/dlls/win32u/driver.c +++ b/dlls/win32u/driver.c @@ -263,18 +263,18 @@ static INT CDECL nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap ) } case BITSPIXEL: { + UNICODE_STRING display; DEVMODEW devmode; - WCHAR *display; DC *dc; - if (NtGdiGetDeviceCaps( dev->hdc, TECHNOLOGY ) == DT_RASDISPLAY && user_callbacks) + if (NtGdiGetDeviceCaps( dev->hdc, TECHNOLOGY ) == DT_RASDISPLAY) { dc = get_nulldrv_dc( dev ); - display = dc->display[0] ? dc->display : NULL; memset( &devmode, 0, sizeof(devmode) ); devmode.dmSize = sizeof(devmode); - if (user_callbacks->pEnumDisplaySettingsW( display, ENUM_CURRENT_SETTINGS, &devmode ) - && devmode.dmFields & DM_BITSPERPEL && devmode.dmBitsPerPel) + init_unicode_string( &display, dc->display ); + if (NtUserEnumDisplaySettings( &display, ENUM_CURRENT_SETTINGS, &devmode, 0 ) && + (devmode.dmFields & DM_BITSPERPEL) && devmode.dmBitsPerPel) return devmode.dmBitsPerPel; } return 32; @@ -313,24 +313,21 @@ static INT CDECL nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap ) case SCALINGFACTORY: return 0; case VREFRESH: { + UNICODE_STRING display; DEVMODEW devmode; - WCHAR *display; DC *dc; if (NtGdiGetDeviceCaps( dev->hdc, TECHNOLOGY ) != DT_RASDISPLAY) return 0; - if (user_callbacks) - { - dc = get_nulldrv_dc( dev ); - - memset( &devmode, 0, sizeof(devmode) ); - devmode.dmSize = sizeof(devmode); - display = dc->display[0] ? dc->display : NULL; - if (user_callbacks->pEnumDisplaySettingsW( display, ENUM_CURRENT_SETTINGS, &devmode )) - return devmode.dmDisplayFrequency ? devmode.dmDisplayFrequency : 1; - } + dc = get_nulldrv_dc( dev ); + memset( &devmode, 0, sizeof(devmode) ); + devmode.dmSize = sizeof(devmode); + init_unicode_string( &display, dc->display ); + if (NtUserEnumDisplaySettings( &display, ENUM_CURRENT_SETTINGS, &devmode, 0 ) && + devmode.dmDisplayFrequency) + return devmode.dmDisplayFrequency; return 1; } case DESKTOPHORZRES: @@ -1044,6 +1041,11 @@ static SHORT CDECL loaderdrv_VkKeyScanEx( WCHAR ch, HKL layout ) return load_driver()->pVkKeyScanEx( ch, layout ); } +static BOOL CDECL loaderdrv_EnumDisplaySettingsEx( LPCWSTR name, DWORD num, LPDEVMODEW mode, DWORD flags ) +{ + return load_driver()->pEnumDisplaySettingsEx( name, num, mode, flags ); +} + static void CDECL loaderdrv_UpdateClipboard(void) { load_driver()->pUpdateClipboard(); @@ -1064,6 +1066,7 @@ static const struct user_driver_funcs lazy_load_driver = .pToUnicodeEx = loaderdrv_ToUnicodeEx, .pUnregisterHotKey = loaderdrv_UnregisterHotKey, .pVkKeyScanEx = loaderdrv_VkKeyScanEx, + .pEnumDisplaySettingsEx = loaderdrv_EnumDisplaySettingsEx, .pUpdateDisplayDevices = loaderdrv_UpdateDisplayDevices, .pUpdateClipboard = loaderdrv_UpdateClipboard, .pScrollDC = nulldrv_ScrollDC, diff --git a/dlls/win32u/gdiobj.c b/dlls/win32u/gdiobj.c index e74c025e838..fbd8975af8e 100644 --- a/dlls/win32u/gdiobj.c +++ b/dlls/win32u/gdiobj.c @@ -1170,6 +1170,7 @@ static struct unix_funcs unix_funcs = NtUserActivateKeyboardLayout, NtUserCountClipboardFormats, NtUserEnumDisplayDevices, + NtUserEnumDisplaySettings, NtUserGetDisplayConfigBufferSizes, NtUserGetKeyNameText, NtUserGetKeyboardLayoutList, diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 1b2e67031d3..31431545245 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -1282,3 +1282,36 @@ BOOL WINAPI NtUserEnumDisplayDevices( UNICODE_STRING *device, DWORD index, unlock_display_devices(); return !!found; } + +/*********************************************************************** + * NtUserEnumDisplaySettings (win32u.@) + */ +BOOL WINAPI NtUserEnumDisplaySettings( UNICODE_STRING *device, DWORD mode, + DEVMODEW *dev_mode, DWORD flags ) +{ + WCHAR device_name[CCHDEVICENAME]; + struct adapter *adapter; + BOOL ret; + + TRACE( "%s %#x %p %#x\n", debugstr_us(device), mode, dev_mode, flags ); + + if (!lock_display_devices()) return FALSE; + if ((adapter = find_adapter( device ))) lstrcpyW( device_name, adapter->dev.device_name ); + unlock_display_devices(); + if (!adapter) + { + WARN( "Invalid device name %s.\n", debugstr_us(device) ); + return FALSE; + } + + ret = user_driver->pEnumDisplaySettingsEx( device_name, mode, dev_mode, flags ); + if (ret) + TRACE( "device:%s mode index:%#x position:(%d,%d) resolution:%ux%u frequency:%uHz " + "depth:%ubits orientation:%#x.\n", debugstr_w(device_name), mode, + dev_mode->dmPosition.x, dev_mode->dmPosition.y, dev_mode->dmPelsWidth, + dev_mode->dmPelsHeight, dev_mode->dmDisplayFrequency, dev_mode->dmBitsPerPel, + dev_mode->dmDisplayOrientation ); + else + WARN( "Failed to query %s display settings.\n", wine_dbgstr_w(device_name) ); + return ret; +} diff --git a/dlls/win32u/win32u.spec b/dlls/win32u/win32u.spec index b210dc1062e..98e9c9bac08 100644 --- a/dlls/win32u/win32u.spec +++ b/dlls/win32u/win32u.spec @@ -877,7 +877,7 @@ @ stub NtUserEndPaint @ stdcall NtUserEnumDisplayDevices(ptr long ptr long) @ stub NtUserEnumDisplayMonitors -@ stub NtUserEnumDisplaySettings +@ stdcall NtUserEnumDisplaySettings(ptr long ptr long) @ stub NtUserEvent @ stub NtUserExcludeUpdateRgn @ stub NtUserFillWindow diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index e881a8eb2ce..44a30db966f 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -38,7 +38,6 @@ struct user_callbacks INT (WINAPI *pGetSystemMetrics)(INT); BOOL (WINAPI *pGetWindowRect)( HWND hwnd, LPRECT rect ); BOOL (WINAPI *pEnumDisplayMonitors)( HDC, LPRECT, MONITORENUMPROC, LPARAM ); - BOOL (WINAPI *pEnumDisplaySettingsW)(LPCWSTR, DWORD, LPDEVMODEW ); BOOL (WINAPI *pRedrawWindow)( HWND, const RECT*, HRGN, UINT ); DPI_AWARENESS_CONTEXT (WINAPI *pSetThreadDpiAwarenessContext)( DPI_AWARENESS_CONTEXT ); HWND (WINAPI *pWindowFromDC)( HDC ); @@ -200,6 +199,8 @@ struct unix_funcs INT (WINAPI *pNtUserCountClipboardFormats)(void); BOOL (WINAPI *pNtUserEnumDisplayDevices)( UNICODE_STRING *device, DWORD index, DISPLAY_DEVICEW *info, DWORD flags ); + BOOL (WINAPI *pNtUserEnumDisplaySettings)( UNICODE_STRING *device, DWORD mode, + DEVMODEW *dev_mode, DWORD flags ); LONG (WINAPI *pNtUserGetDisplayConfigBufferSizes)( UINT32 flags, UINT32 *num_path_info, UINT32 *num_mode_info ); INT (WINAPI *pNtUserGetKeyNameText)( LONG lparam, WCHAR *buffer, INT size ); @@ -394,6 +395,13 @@ static inline BOOL is_win9x(void) return NtCurrentTeb()->Peb->OSPlatformId == VER_PLATFORM_WIN32s; } +static inline void init_unicode_string( UNICODE_STRING *str, const WCHAR *data ) +{ + str->Length = lstrlenW(data) * sizeof(WCHAR); + str->MaximumLength = str->Length + sizeof(WCHAR); + str->Buffer = (WCHAR *)data; +} + static inline const char *debugstr_us( const UNICODE_STRING *us ) { if (!us) return ""; diff --git a/dlls/win32u/wrappers.c b/dlls/win32u/wrappers.c index 9c4937643cf..33ad3e0ff9c 100644 --- a/dlls/win32u/wrappers.c +++ b/dlls/win32u/wrappers.c @@ -612,6 +612,12 @@ BOOL WINAPI NtUserEnumDisplayDevices( UNICODE_STRING *device, DWORD index, return unix_funcs->pNtUserEnumDisplayDevices( device, index, info, flags ); } +BOOL WINAPI NtUserEnumDisplaySettings( UNICODE_STRING *device, DWORD mode, + DEVMODEW *dev_mode, DWORD flags ) +{ + return unix_funcs->pNtUserEnumDisplaySettings( device, mode, dev_mode, flags ); +} + LONG WINAPI NtUserGetDisplayConfigBufferSizes( UINT32 flags, UINT32 *num_path_info, UINT32 *num_mode_info ) { @@ -821,14 +827,6 @@ static BOOL WINAPI call_EnumDisplayMonitors( HDC hdc, RECT *rect, MONITORENUMPRO return pEnumDisplayMonitors && pEnumDisplayMonitors( hdc, rect, proc, lparam ); } -static BOOL WINAPI call_EnumDisplaySettingsW( const WCHAR *device, DWORD mode, DEVMODEW *devmode ) -{ - static BOOL (WINAPI *pEnumDisplaySettingsW)(LPCWSTR, DWORD, LPDEVMODEW ); - if (!pEnumDisplaySettingsW) - pEnumDisplaySettingsW = get_user_proc( "EnumDisplaySettingsW", FALSE ); - return pEnumDisplaySettingsW && pEnumDisplaySettingsW( device, mode, devmode ); -} - static BOOL WINAPI call_RedrawWindow( HWND hwnd, const RECT *rect, HRGN rgn, UINT flags ) { static BOOL (WINAPI *pRedrawWindow)( HWND, const RECT*, HRGN, UINT ); @@ -861,7 +859,6 @@ static const struct user_callbacks user_funcs = call_GetSystemMetrics, call_GetWindowRect, call_EnumDisplayMonitors, - call_EnumDisplaySettingsW, call_RedrawWindow, call_SetThreadDpiAwarenessContext, call_WindowFromDC, diff --git a/include/ntuser.h b/include/ntuser.h index b4e5a65cfaa..17a991b3a1a 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -66,6 +66,8 @@ HWINSTA WINAPI NtUserCreateWindowStation( OBJECT_ATTRIBUTES *attr, ACCESS_MASK m ULONG arg4, ULONG arg5, ULONG arg6, ULONG arg7 ); BOOL WINAPI NtUserEnumDisplayDevices( UNICODE_STRING *device, DWORD index, DISPLAY_DEVICEW *info, DWORD flags ); +BOOL WINAPI NtUserEnumDisplaySettings( UNICODE_STRING *device, DWORD mode, + DEVMODEW *dev_mode, DWORD flags ); INT WINAPI NtUserGetClipboardFormatName( UINT format, WCHAR *buffer, INT maxlen ); HWND WINAPI NtUserGetClipboardOwner(void); DWORD WINAPI NtUserGetClipboardSequenceNumber(void);