From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/sysparams.c | 49 +++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 19 deletions(-)
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 5fdaa74856d..665064ad1ed 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -923,9 +923,8 @@ struct device_manager_ctx /* for the virtual desktop settings */ BOOL source_attached; BOOL is_primary; - UINT primary_bpp; - UINT primary_width; - UINT primary_height; + DEVMODEW current; + DEVMODEW primary; };
static void link_device( const char *instance, const char *class ) @@ -1174,6 +1173,8 @@ static BOOL write_gpu_to_registry( const struct gpu *gpu, const struct pci_id *p return TRUE; }
+static void write_current_mode( struct device_manager_ctx *ctx ); + static void add_gpu( const struct gdi_gpu *gpu, void *param ) { const struct pci_id pci_id = @@ -1195,6 +1196,8 @@ static void add_gpu( const struct gdi_gpu *gpu, void *param ) if (!enum_key && !(enum_key = reg_create_ascii_key( NULL, enum_keyA, 0, NULL ))) return;
+ if (ctx->source.mode_count) write_current_mode( ctx ); + if (!ctx->mutex) { pthread_mutex_lock( &display_lock ); @@ -1301,6 +1304,8 @@ static void add_source( const char *name, UINT state_flags, void *param )
TRACE( "name %s, state_flags %#x\n", name, state_flags );
+ if (ctx->source.mode_count) write_current_mode( ctx ); + if (ctx->source_key) { NtClose( ctx->source_key ); @@ -1454,11 +1459,10 @@ static void add_mode( const DEVMODEW *mode, BOOL current, void *param ) add_source( "Default", source_flags, ctx ); }
- if (ctx->is_primary && current) + if (current) { - ctx->primary_bpp = mode->dmBitsPerPel; - ctx->primary_width = mode->dmPelsWidth; - ctx->primary_height = mode->dmPelsHeight; + if (ctx->is_primary) ctx->primary = *mode; + ctx->current = *mode; }
nopos_mode = *mode; @@ -1468,14 +1472,8 @@ static void add_mode( const DEVMODEW *mode, BOOL current, void *param )
if (write_source_mode( ctx->source_key, ctx->source.mode_count, &nopos_mode )) { - ctx->source.mode_count++; - set_reg_value( ctx->source_key, mode_countW, REG_DWORD, &ctx->source.mode_count, sizeof(ctx->source.mode_count) ); - if (current) - { - if (!read_source_mode( ctx->source_key, ENUM_REGISTRY_SETTINGS, &nopos_mode )) - write_source_mode( ctx->source_key, ENUM_REGISTRY_SETTINGS, mode ); - write_source_mode( ctx->source_key, ENUM_CURRENT_SETTINGS, mode ); - } + DWORD mode_count = ++ctx->source.mode_count; + set_reg_value( ctx->source_key, mode_countW, REG_DWORD, &mode_count, sizeof(mode_count) ); } }
@@ -1504,6 +1502,8 @@ static void reset_display_manager_ctx( struct device_manager_ctx *ctx )
static void release_display_manager_ctx( struct device_manager_ctx *ctx ) { + if (ctx->source.mode_count) write_current_mode( ctx ); + if (ctx->mutex) { pthread_mutex_unlock( &display_lock ); @@ -1878,9 +1878,9 @@ static BOOL add_virtual_source( struct device_manager_ctx *ctx, BOOL use_current }; UINT i, j;
- max_width = ctx->primary_width; - max_height = ctx->primary_height; - depths[ARRAY_SIZE(depths) - 1] = ctx->primary_bpp; + max_width = ctx->primary.dmPelsWidth; + max_height = ctx->primary.dmPelsHeight; + depths[ARRAY_SIZE(depths) - 1] = ctx->primary.dmBitsPerPel;
if (!get_default_desktop_size( &screen_width, &screen_height )) { @@ -1893,7 +1893,7 @@ static BOOL add_virtual_source( struct device_manager_ctx *ctx, BOOL use_current { current = mode; current.dmFields |= DM_POSITION; - current.dmBitsPerPel = ctx->primary_bpp; + current.dmBitsPerPel = ctx->primary.dmBitsPerPel; current.dmPelsWidth = screen_width; current.dmPelsHeight = screen_height; } @@ -1938,6 +1938,17 @@ static BOOL add_virtual_source( struct device_manager_ctx *ctx, BOOL use_current return TRUE; }
+static void write_current_mode( struct device_manager_ctx *ctx ) +{ + DEVMODEW tmp_mode = {.dmSize = sizeof(DEVMODEW)}; + + if (!read_source_mode( ctx->source_key, ENUM_REGISTRY_SETTINGS, &tmp_mode )) + write_source_mode( ctx->source_key, ENUM_REGISTRY_SETTINGS, &ctx->current ); + + write_source_mode( ctx->source_key, ENUM_CURRENT_SETTINGS, &ctx->current ); + ctx->source.mode_count = 0; +} + static BOOL update_display_devices( BOOL force, BOOL use_current, struct device_manager_ctx *ctx ) { if (user_driver->pUpdateDisplayDevices( &device_manager, force, ctx ))