From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/sysparams.c | 105 ++++++++++++----------------------- dlls/win32u/win32u_private.h | 2 +- dlls/win32u/winstation.c | 4 +- dlls/winex11.drv/xinerama.c | 5 +- dlls/winex11.drv/xrandr.c | 3 +- 5 files changed, 42 insertions(+), 77 deletions(-)
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 988da5a7641..5fdaa74856d 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -921,6 +921,7 @@ struct device_manager_ctx struct source source; HKEY source_key; /* for the virtual desktop settings */ + BOOL source_attached; BOOL is_primary; UINT primary_bpp; UINT primary_width; @@ -1306,6 +1307,10 @@ static void add_source( const char *name, UINT state_flags, void *param ) ctx->source_key = NULL; }
+ ctx->is_primary = !!(state_flags & DISPLAY_DEVICE_PRIMARY_DEVICE); + if (state_flags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) ctx->source_attached = TRUE; + else state_flags &= ~DISPLAY_DEVICE_PRIMARY_DEVICE; + memset( &ctx->source, 0, sizeof(ctx->source) ); ctx->source.gpu = &ctx->gpu; ctx->source.id = ctx->source_count; @@ -1449,6 +1454,13 @@ static void add_mode( const DEVMODEW *mode, BOOL current, void *param ) add_source( "Default", source_flags, ctx ); }
+ if (ctx->is_primary && current) + { + ctx->primary_bpp = mode->dmBitsPerPel; + ctx->primary_width = mode->dmPelsWidth; + ctx->primary_height = mode->dmPelsHeight; + } + nopos_mode = *mode; nopos_mode.dmPosition.x = 0; nopos_mode.dmPosition.y = 0; @@ -1783,12 +1795,6 @@ static BOOL default_update_display_devices( const struct gdi_device_manager *man return TRUE; }
-static BOOL update_display_devices( const struct gdi_device_manager *manager, BOOL force, struct device_manager_ctx *ctx ) -{ - if (user_driver->pUpdateDisplayDevices( manager, force, ctx )) return TRUE; - return default_update_display_devices( manager, force, ctx ); -} - /* parse the desktop size specification */ static BOOL parse_size( const WCHAR *size, unsigned int *width, unsigned int *height ) { @@ -1821,44 +1827,9 @@ static BOOL get_default_desktop_size( unsigned int *width, unsigned int *height return TRUE; }
-static void desktop_add_gpu( const struct gdi_gpu *gpu, void *param ) -{ -} - -static void desktop_add_source( const char *name, UINT state_flags, void *param ) -{ - struct device_manager_ctx *ctx = param; - ctx->is_primary = !!(state_flags & DISPLAY_DEVICE_PRIMARY_DEVICE); -} - -static void desktop_add_monitor( const struct gdi_monitor *monitor, void *param ) -{ -} - -static void desktop_add_mode( const DEVMODEW *mode, BOOL current, void *param ) -{ - struct device_manager_ctx *ctx = param; - - if (ctx->is_primary && current) - { - ctx->primary_bpp = mode->dmBitsPerPel; - ctx->primary_width = mode->dmPelsWidth; - ctx->primary_height = mode->dmPelsHeight; - } -} - -static const struct gdi_device_manager desktop_device_manager = -{ - desktop_add_gpu, - desktop_add_source, - desktop_add_monitor, - desktop_add_mode, -}; - -static BOOL desktop_update_display_devices( BOOL force, struct device_manager_ctx *ctx ) +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; - static const struct gdi_gpu gpu; struct gdi_monitor monitor = {0}; static struct screen_size { @@ -1898,7 +1869,6 @@ static BOOL desktop_update_display_devices( BOOL force, struct device_manager_ct {2560, 1600} };
- struct device_manager_ctx desktop_ctx = {0}; UINT screen_width, screen_height, max_width, max_height; unsigned int depths[] = {8, 16, 0}; DEVMODEW current, mode = @@ -1908,13 +1878,9 @@ static BOOL desktop_update_display_devices( BOOL force, struct device_manager_ct }; UINT i, j;
- if (!force) return TRUE; - /* in virtual desktop mode, read the device list from the user driver but expose virtual devices */ - if (!update_display_devices( &desktop_device_manager, TRUE, &desktop_ctx )) return FALSE; - - max_width = desktop_ctx.primary_width; - max_height = desktop_ctx.primary_height; - depths[ARRAY_SIZE(depths) - 1] = desktop_ctx.primary_bpp; + max_width = ctx->primary_width; + max_height = ctx->primary_height; + depths[ARRAY_SIZE(depths) - 1] = ctx->primary_bpp;
if (!get_default_desktop_size( &screen_width, &screen_height )) { @@ -1922,13 +1888,12 @@ static BOOL desktop_update_display_devices( BOOL force, struct device_manager_ct screen_height = max_height; }
- add_gpu( &gpu, ctx ); - add_source( "Default", source_flags, ctx ); - if (!read_source_mode( ctx->source_key, ENUM_CURRENT_SETTINGS, ¤t )) + add_source( "Virtual", source_flags, ctx ); + if (!use_current || !read_source_mode( ctx->source_key, ENUM_CURRENT_SETTINGS, ¤t )) { current = mode; current.dmFields |= DM_POSITION; - current.dmBitsPerPel = desktop_ctx.primary_bpp; + current.dmBitsPerPel = ctx->primary_bpp; current.dmPelsWidth = screen_width; current.dmPelsHeight = screen_height; } @@ -1973,13 +1938,25 @@ static BOOL desktop_update_display_devices( BOOL force, struct device_manager_ct return TRUE; }
-BOOL update_display_cache( BOOL force ) +static BOOL update_display_devices( BOOL force, BOOL use_current, struct device_manager_ctx *ctx ) +{ + if (user_driver->pUpdateDisplayDevices( &device_manager, force, ctx )) + { + if (is_virtual_desktop() && ctx->source_count && !ctx->source_attached) + return add_virtual_source( ctx, use_current ); + return TRUE; + } + + return default_update_display_devices( &device_manager, force, ctx ); +} + +BOOL update_display_cache( BOOL force, BOOL use_current ) { static const WCHAR wine_service_station_name[] = {'_','_','w','i','n','e','s','e','r','v','i','c','e','_','w','i','n','s','t','a','t','i','o','n',0}; HWINSTA winstation = NtUserGetProcessWindowStation(); struct device_manager_ctx ctx = {0}; - BOOL was_virtual_desktop, ret; + BOOL ret; WCHAR name[MAX_PATH];
/* services do not have any adapters, only a virtual monitor */ @@ -1993,15 +1970,7 @@ BOOL update_display_cache( BOOL force ) return TRUE; }
- if ((was_virtual_desktop = is_virtual_desktop())) ret = TRUE; - else ret = update_display_devices( &device_manager, force, &ctx ); - - /* as update_display_devices calls the user driver, it starts explorer and may change the virtual desktop state */ - if (ret && is_virtual_desktop()) - { - reset_display_manager_ctx( &ctx ); - ret = desktop_update_display_devices( force || !was_virtual_desktop, &ctx ); - } + ret = update_display_devices( force, use_current, &ctx );
release_display_manager_ctx( &ctx ); if (!ret) WARN( "Failed to update display devices\n" ); @@ -2020,7 +1989,7 @@ BOOL update_display_cache( BOOL force ) return FALSE; }
- return update_display_cache( TRUE ); + return update_display_cache( TRUE, use_current ); }
return TRUE; @@ -2028,7 +1997,7 @@ BOOL update_display_cache( BOOL force )
static BOOL lock_display_devices(void) { - if (!update_display_cache( FALSE )) return FALSE; + if (!update_display_cache( FALSE, TRUE )) return FALSE; pthread_mutex_lock( &display_lock ); return TRUE; } @@ -3232,7 +3201,7 @@ static LONG apply_display_settings( struct source *target, const DEVMODEW *devmo free( displays ); if (ret) return ret;
- if (!update_display_cache( TRUE )) + if (!update_display_cache( TRUE, TRUE )) WARN( "Failed to update display cache after mode change.\n" );
if ((source = find_source( NULL ))) diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index ff861db4dd9..d0d13ed78dd 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -187,7 +187,7 @@ extern RECT rect_thread_to_win_dpi( HWND hwnd, RECT rect ); extern HMONITOR monitor_from_point( POINT pt, UINT flags, UINT dpi ); extern HMONITOR monitor_from_rect( const RECT *rect, UINT flags, UINT dpi ); extern HMONITOR monitor_from_window( HWND hwnd, UINT flags, UINT dpi ); -extern BOOL update_display_cache( BOOL force ); +extern BOOL update_display_cache( BOOL force, BOOL use_current ); extern void user_lock(void); extern void user_unlock(void); extern void user_check_not_lock(void); diff --git a/dlls/win32u/winstation.c b/dlls/win32u/winstation.c index 6ddd5411f94..a6167f015be 100644 --- a/dlls/win32u/winstation.c +++ b/dlls/win32u/winstation.c @@ -184,7 +184,7 @@ HDESK WINAPI NtUserCreateDesktopEx( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *dev }
/* force update display cache to use virtual desktop display settings */ - if (flags & DF_WINE_VIRTUAL_DESKTOP) update_display_cache( TRUE ); + if (flags & DF_WINE_VIRTUAL_DESKTOP) update_display_cache( TRUE, FALSE ); return ret; }
@@ -264,7 +264,7 @@ BOOL WINAPI NtUserSetThreadDesktop( HDESK handle ) thread_info->client_info.top_window = 0; thread_info->client_info.msg_window = 0; if (key_state_info) key_state_info->time = 0; - if (was_virtual_desktop != is_virtual_desktop()) update_display_cache( TRUE ); + if (was_virtual_desktop != is_virtual_desktop()) update_display_cache( TRUE, FALSE ); } return ret; } diff --git a/dlls/winex11.drv/xinerama.c b/dlls/winex11.drv/xinerama.c index 426ea6c11d4..4422a7f73b6 100644 --- a/dlls/winex11.drv/xinerama.c +++ b/dlls/winex11.drv/xinerama.c @@ -259,7 +259,7 @@ static BOOL xinerama_get_adapters( ULONG_PTR gpu_id, struct x11drv_adapter **new if (i == primary_index) adapters[index].state_flags |= DISPLAY_DEVICE_PRIMARY_DEVICE;
- if (!IsRectEmpty( &monitors[i].rcMonitor )) + if (!IsRectEmpty( &monitors[i].rcMonitor ) && !is_virtual_desktop()) adapters[index].state_flags |= DISPLAY_DEVICE_ATTACHED_TO_DESKTOP;
index++; @@ -344,9 +344,6 @@ void xinerama_init( unsigned int width, unsigned int height ) int i; RECT rect;
- if (is_virtual_desktop()) - return; - pthread_mutex_lock( &xinerama_mutex );
SetRect( &rect, 0, 0, width, height ); diff --git a/dlls/winex11.drv/xrandr.c b/dlls/winex11.drv/xrandr.c index 0e7b9a07818..8054b6ed4e2 100644 --- a/dlls/winex11.drv/xrandr.c +++ b/dlls/winex11.drv/xrandr.c @@ -983,7 +983,7 @@ static BOOL xrandr14_get_adapters( ULONG_PTR gpu_id, struct x11drv_adapter **new /* Use RROutput as adapter id. The reason of not using RRCrtc is that we need to detect inactive but * attached monitors */ adapters[adapter_count].id = outputs[i]; - if (!detached) + if (!detached && !is_virtual_desktop()) adapters[adapter_count].state_flags |= DISPLAY_DEVICE_ATTACHED_TO_DESKTOP; if (is_crtc_primary( primary_rect, crtc_info )) { @@ -1662,7 +1662,6 @@ void X11DRV_XRandR_Init(void)
if (major) return; /* already initialized? */ if (!usexrandr) return; /* disabled in config */ - if (is_virtual_desktop()) return; if (!(ret = load_xrandr())) return; /* can't load the Xrandr library */
/* see if Xrandr is available */
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/winstation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/win32u/winstation.c b/dlls/win32u/winstation.c index a6167f015be..51717b577c1 100644 --- a/dlls/win32u/winstation.c +++ b/dlls/win32u/winstation.c @@ -264,7 +264,7 @@ BOOL WINAPI NtUserSetThreadDesktop( HDESK handle ) thread_info->client_info.top_window = 0; thread_info->client_info.msg_window = 0; if (key_state_info) key_state_info->time = 0; - if (was_virtual_desktop != is_virtual_desktop()) update_display_cache( TRUE, FALSE ); + if (was_virtual_desktop != is_virtual_desktop()) update_display_cache( FALSE, FALSE ); } return ret; }
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winex11.drv/window.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/dlls/winex11.drv/window.c b/dlls/winex11.drv/window.c index 5a014c9080d..4e0a17ad00c 100644 --- a/dlls/winex11.drv/window.c +++ b/dlls/winex11.drv/window.c @@ -1947,10 +1947,7 @@ void X11DRV_SetDesktopWindow( HWND hwnd )
if (!width && !height) /* not initialized yet */ { - RECT rect; - - X11DRV_DisplayDevices_Init( TRUE ); - rect = NtUserGetVirtualScreenRect(); + RECT rect = NtUserGetVirtualScreenRect();
SERVER_START_REQ( set_window_pos ) { @@ -1983,11 +1980,7 @@ void X11DRV_SetDesktopWindow( HWND hwnd ) else { Window win = (Window)NtUserGetProp( hwnd, whole_window_prop ); - if (win && win != root_window) - { - X11DRV_init_desktop( win, width, height ); - X11DRV_DisplayDevices_Init( TRUE ); - } + if (win && win != root_window) X11DRV_init_desktop( win, width, height ); } }
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 ))
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; }
I feel like this patch is making things more convoluted and difficult to review. For example, the line between virtual desktop display devices and real display devices was clearer before this patch. Also, why should update_display_cache() concern itself with whether to use the current display mode? And calling is_virtual_desktop() in xrandr14_get_adapters() seems weird. I am afraid that you have to simplify it a bit more.