From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/sysparams.c | 102 ++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 46 deletions(-)
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 665064ad1ed..78d59813b8e 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -1796,7 +1796,7 @@ static BOOL default_update_display_devices( const struct gdi_device_manager *man }
/* parse the desktop size specification */ -static BOOL parse_size( const WCHAR *size, unsigned int *width, unsigned int *height ) +static BOOL parse_size( const WCHAR *size, DWORD *width, DWORD *height ) { WCHAR *end;
@@ -1809,7 +1809,7 @@ static BOOL parse_size( const WCHAR *size, unsigned int *width, unsigned int *he }
/* retrieve the default desktop size from the registry */ -static BOOL get_default_desktop_size( unsigned int *width, unsigned int *height ) +static BOOL get_default_desktop_size( DWORD *width, DWORD *height ) { WCHAR buffer[4096]; KEY_VALUE_PARTIAL_INFORMATION *value = (void *)buffer; @@ -1827,10 +1827,9 @@ static BOOL get_default_desktop_size( unsigned int *width, unsigned int *height return TRUE; }
-static BOOL add_virtual_source( struct device_manager_ctx *ctx, BOOL use_current ) +static BOOL add_virtual_modes( struct device_manager_ctx *ctx, const DEVMODEW *maximum, + const DEVMODEW *initial, const DEVMODEW *current ) { - static const DWORD source_flags = DISPLAY_DEVICE_ATTACHED_TO_DESKTOP | DISPLAY_DEVICE_PRIMARY_DEVICE | DISPLAY_DEVICE_VGA_COMPATIBLE; - struct gdi_monitor monitor = {0}; static struct screen_size { unsigned int width; @@ -1868,24 +1867,63 @@ static BOOL add_virtual_source( struct device_manager_ctx *ctx, BOOL use_current {1920, 1200}, {2560, 1600} }; + unsigned int depths[] = {8, 16, initial->dmBitsPerPel}; + DEVMODEW mode = + { + .dmFields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY, + .dmDisplayFrequency = 60, + }; + UINT i, j; + + for (i = 0; i < ARRAY_SIZE(depths); ++i) + { + mode.dmBitsPerPel = depths[i];
- UINT screen_width, screen_height, max_width, max_height; - unsigned int depths[] = {8, 16, 0}; + for (j = 0; j < ARRAY_SIZE(screen_sizes); ++j) + { + mode.dmPelsWidth = screen_sizes[j].width; + mode.dmPelsHeight = screen_sizes[j].height; + + if (mode.dmPelsWidth > maximum->dmPelsWidth || mode.dmPelsHeight > maximum->dmPelsWidth) continue; + if (mode.dmPelsWidth == maximum->dmPelsWidth && mode.dmPelsHeight == maximum->dmPelsWidth) continue; + if (mode.dmPelsWidth == initial->dmPelsWidth && mode.dmPelsHeight == initial->dmPelsHeight) continue; + if (!is_same_devmode( &mode, current )) add_mode( &mode, FALSE, ctx ); + } + + mode.dmPelsWidth = initial->dmPelsWidth; + mode.dmPelsHeight = initial->dmPelsHeight; + if (!is_same_devmode( &mode, current )) add_mode( &mode, FALSE, ctx ); + + if (maximum->dmPelsWidth != initial->dmPelsWidth || maximum->dmPelsWidth != initial->dmPelsHeight) + { + mode.dmPelsWidth = maximum->dmPelsWidth; + mode.dmPelsHeight = maximum->dmPelsHeight; + if (!is_same_devmode( &mode, current )) add_mode( &mode, FALSE, ctx ); + } + } + + return TRUE; +} + +static BOOL add_virtual_source( struct device_manager_ctx *ctx, BOOL use_current ) +{ + static const DWORD source_flags = DISPLAY_DEVICE_ATTACHED_TO_DESKTOP | DISPLAY_DEVICE_PRIMARY_DEVICE | DISPLAY_DEVICE_VGA_COMPATIBLE; + struct gdi_monitor monitor = {0}; + + DEVMODEW maximum = {0}, initial = {0}; DEVMODEW current, mode = { .dmFields = DM_DISPLAYORIENTATION | DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY, .dmDisplayFrequency = 60, }; - UINT i, j;
- max_width = ctx->primary.dmPelsWidth; - max_height = ctx->primary.dmPelsHeight; - depths[ARRAY_SIZE(depths) - 1] = ctx->primary.dmBitsPerPel; + maximum.dmPelsWidth = ctx->primary.dmPelsWidth; + maximum.dmPelsHeight = ctx->primary.dmPelsHeight;
- if (!get_default_desktop_size( &screen_width, &screen_height )) + if (!get_default_desktop_size( &initial.dmPelsWidth, &initial.dmPelsHeight )) { - screen_width = max_width; - screen_height = max_height; + initial.dmPelsWidth = maximum.dmPelsWidth; + initial.dmPelsHeight = maximum.dmPelsHeight; }
add_source( "Virtual", source_flags, ctx ); @@ -1894,8 +1932,8 @@ static BOOL add_virtual_source( struct device_manager_ctx *ctx, BOOL use_current current = mode; current.dmFields |= DM_POSITION; current.dmBitsPerPel = ctx->primary.dmBitsPerPel; - current.dmPelsWidth = screen_width; - current.dmPelsHeight = screen_height; + current.dmPelsWidth = initial.dmPelsWidth; + current.dmPelsHeight = initial.dmPelsHeight; }
monitor.rc_monitor.right = current.dmPelsWidth; @@ -1904,36 +1942,8 @@ static BOOL add_virtual_source( struct device_manager_ctx *ctx, BOOL use_current monitor.rc_work.bottom = current.dmPelsHeight; add_monitor( &monitor, ctx );
- for (i = 0; i < ARRAY_SIZE(depths); ++i) - { - mode.dmBitsPerPel = depths[i]; - - for (j = 0; j < ARRAY_SIZE(screen_sizes); ++j) - { - mode.dmPelsWidth = screen_sizes[j].width; - mode.dmPelsHeight = screen_sizes[j].height; - - if (mode.dmPelsWidth > max_width || mode.dmPelsHeight > max_height) continue; - if (mode.dmPelsWidth == max_width && mode.dmPelsHeight == max_height) continue; - if (mode.dmPelsWidth == screen_width && mode.dmPelsHeight == screen_height) continue; - - if (is_same_devmode( &mode, ¤t )) add_mode( ¤t, TRUE, ctx ); - else add_mode( &mode, FALSE, ctx ); - } - - mode.dmPelsWidth = screen_width; - mode.dmPelsHeight = screen_height; - if (is_same_devmode( &mode, ¤t )) add_mode( ¤t, TRUE, ctx ); - else add_mode( &mode, FALSE, ctx ); - - if (max_width != screen_width || max_height != screen_height) - { - mode.dmPelsWidth = max_width; - mode.dmPelsHeight = max_height; - if (is_same_devmode( &mode, ¤t )) add_mode( ¤t, TRUE, ctx ); - else add_mode( &mode, FALSE, ctx ); - } - } + add_mode( ¤t, TRUE, ctx ); + add_virtual_modes( ctx, &maximum, &initial, ¤t );
return TRUE; }