From: Zhiyi Zhang Subject: [PATCH 4/7] winex11.drv: Get virtual desktop size limit from the host primary display. Message-Id: <4ba85508-e47a-ab01-2cb2-7960f580ac45@codeweavers.com> Date: Thu, 3 Oct 2019 15:54:37 +0800 After 25167fb286822c93582457815bcf069fef040976, get_primary_monitor_rect() maybe invalid before display device initialization or returns the desktop rectangle after desktop initialization in virtual desktop mode, both of which are wrong. This fixes a regression from efbbe66669a060dd01b3ae399f5a9e7328312f03. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47815 Signed-off-by: Zhiyi Zhang --- dlls/winex11.drv/desktop.c | 8 +++----- dlls/winex11.drv/display.c | 21 +++++++++++++++++++++ dlls/winex11.drv/x11drv.h | 1 + 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/dlls/winex11.drv/desktop.c b/dlls/winex11.drv/desktop.c index 7c2d4fd4bc..9f2eb1d41f 100644 --- a/dlls/winex11.drv/desktop.c +++ b/dlls/winex11.drv/desktop.c @@ -244,12 +244,14 @@ static void X11DRV_desktop_free_monitors( struct x11drv_monitor *monitors ) */ void X11DRV_init_desktop( Window win, unsigned int width, unsigned int height ) { - RECT primary_rect; + RECT primary_rect = get_host_primary_monitor_rect(); root_window = win; managed_mode = FALSE; /* no managed windows in desktop mode */ desktop_width = width; desktop_height = height; + max_width = primary_rect.right; + max_height = primary_rect.bottom; /* Initialize virtual desktop mode display device handler */ desktop_handler.name = "Virtual Desktop"; @@ -262,10 +264,6 @@ void X11DRV_init_desktop( Window win, unsigned int width, unsigned int height ) TRACE("Display device functions are now handled by: Virtual Desktop\n"); X11DRV_DisplayDevices_Init( TRUE ); - primary_rect = get_primary_monitor_rect(); - max_width = primary_rect.right - primary_rect.left; - max_height = primary_rect.bottom - primary_rect.top; - /* initialize the available resolutions */ dd_modes = X11DRV_Settings_SetHandlers("desktop", X11DRV_desktop_GetCurrentMode, diff --git a/dlls/winex11.drv/display.c b/dlls/winex11.drv/display.c index acf19bd8c6..31c652a300 100644 --- a/dlls/winex11.drv/display.c +++ b/dlls/winex11.drv/display.c @@ -133,6 +133,27 @@ RECT get_primary_monitor_rect(void) return primary_monitor_rect; } +/* Get the primary monitor rect from the host system */ +RECT get_host_primary_monitor_rect(void) +{ + INT gpu_count, adapter_count, monitor_count; + struct x11drv_gpu *gpus = NULL; + struct x11drv_adapter *adapters = NULL; + struct x11drv_monitor *monitors = NULL; + RECT rect = {0}; + + /* The first monitor is always primary */ + if (host_handler.pGetGpus(&gpus, &gpu_count) && gpu_count && + host_handler.pGetAdapters(gpus[0].id, &adapters, &adapter_count) && adapter_count && + host_handler.pGetMonitors(adapters[0].id, &monitors, &monitor_count) && monitor_count) + rect = monitors[0].rc_monitor; + + if (gpus) host_handler.pFreeGpus(gpus); + if (adapters) host_handler.pFreeAdapters(adapters); + if (monitors) host_handler.pFreeMonitors(monitors); + return rect; +} + void X11DRV_DisplayDevices_SetHandler(const struct x11drv_display_device_handler *new_handler) { if (new_handler->priority > host_handler.priority) diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index 6ae9564858..9f024108f4 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -641,6 +641,7 @@ extern POINT virtual_screen_to_root( INT x, INT y ) DECLSPEC_HIDDEN; extern POINT root_to_virtual_screen( INT x, INT y ) DECLSPEC_HIDDEN; extern RECT get_virtual_screen_rect(void) DECLSPEC_HIDDEN; extern RECT get_primary_monitor_rect(void) DECLSPEC_HIDDEN; +extern RECT get_host_primary_monitor_rect(void) DECLSPEC_HIDDEN; extern void query_work_area( RECT *rc_work ) DECLSPEC_HIDDEN; extern void xinerama_init( unsigned int width, unsigned int height ) DECLSPEC_HIDDEN; -- 2.23.0