[PATCH v5 5/6] winex11.drv: Query virtual screen and primary screen rectangles from user32.

Zhiyi Zhang zzhang at codeweavers.com
Tue Jun 1 21:57:29 CDT 2021


Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
---
 dlls/user32/sysparams.c    |   4 +-
 dlls/winex11.drv/display.c | 114 +++++++++----------------------------
 2 files changed, 29 insertions(+), 89 deletions(-)

diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c
index 846d5b9cc36..40c26cba1c0 100644
--- a/dlls/user32/sysparams.c
+++ b/dlls/user32/sysparams.c
@@ -3982,7 +3982,7 @@ BOOL CDECL nulldrv_GetMonitorInfo( HMONITOR handle, MONITORINFO *info )
     SERVER_START_REQ( get_monitor_info )
     {
         req->handle = wine_server_user_handle( handle );
-        if (info->cbSize >= sizeof(MONITORINFOEXW))
+        if (info->cbSize == sizeof(MONITORINFOEXW))
             wine_server_set_reply( req, ((MONITORINFOEXW *)info)->szDevice,
                                    sizeof(((MONITORINFOEXW *)info)->szDevice) - sizeof(WCHAR) );
         if (!(status = wine_server_call( req )))
@@ -3995,7 +3995,7 @@ BOOL CDECL nulldrv_GetMonitorInfo( HMONITOR handle, MONITORINFO *info )
                 info->dwFlags = MONITORINFOF_PRIMARY;
             else
                 info->dwFlags = 0;
-            if (info->cbSize >= sizeof(MONITORINFOEXW))
+            if (info->cbSize == sizeof(MONITORINFOEXW))
                 ((MONITORINFOEXW *)info)->szDevice[wine_server_reply_size( req ) / sizeof(WCHAR)] = 0;
         }
     }
diff --git a/dlls/winex11.drv/display.c b/dlls/winex11.drv/display.c
index a70b5c811dc..8d5d6755cbb 100644
--- a/dlls/winex11.drv/display.c
+++ b/dlls/winex11.drv/display.c
@@ -48,7 +48,6 @@ DEFINE_DEVPROPKEY(DEVPROPKEY_MONITOR_OUTPUT_ID, 0xca085853, 0x16ce, 0x48aa, 0xb1
 /* Wine specific properties */
 DEFINE_DEVPROPKEY(WINE_DEVPROPKEY_GPU_VULKAN_UUID, 0x233a9ef3, 0xafc4, 0x4abd, 0xb5, 0x64, 0xc3, 0x2f, 0x21, 0xf1, 0x53, 0x5c, 2);
 DEFINE_DEVPROPKEY(WINE_DEVPROPKEY_MONITOR_STATEFLAGS, 0x233a9ef3, 0xafc4, 0x4abd, 0xb5, 0x64, 0xc3, 0x2f, 0x21, 0xf1, 0x53, 0x5b, 2);
-DEFINE_DEVPROPKEY(WINE_DEVPROPKEY_MONITOR_RCMONITOR, 0x233a9ef3, 0xafc4, 0x4abd, 0xb5, 0x64, 0xc3, 0x2f, 0x21, 0xf1, 0x53, 0x5b, 3);
 DEFINE_DEVPROPKEY(WINE_DEVPROPKEY_MONITOR_ADAPTERNAME, 0x233a9ef3, 0xafc4, 0x4abd, 0xb5, 0x64, 0xc3, 0x2f, 0x21, 0xf1, 0x53, 0x5b, 5);
 
 static const WCHAR driver_date_dataW[] = {'D','r','i','v','e','r','D','a','t','e','D','a','t','a',0};
@@ -114,20 +113,6 @@ static const WCHAR driver_date_fmtW[] = {'%','u','-','%','u','-','%','u',0};
 static struct x11drv_display_device_handler host_handler;
 struct x11drv_display_device_handler desktop_handler;
 
-/* Cached screen information, protected by screen_section */
-static HKEY video_key;
-static RECT virtual_screen_rect;
-static RECT primary_monitor_rect;
-static FILETIME last_query_screen_time;
-static CRITICAL_SECTION screen_section;
-static CRITICAL_SECTION_DEBUG screen_critsect_debug =
-{
-    0, 0, &screen_section,
-    {&screen_critsect_debug.ProcessLocksList, &screen_critsect_debug.ProcessLocksList},
-     0, 0, {(DWORD_PTR)(__FILE__ ": screen_section")}
-};
-static CRITICAL_SECTION screen_section = {&screen_critsect_debug, -1, 0, 0, 0, 0};
-
 HANDLE get_display_device_init_mutex(void)
 {
     static const WCHAR init_mutexW[] = {'d','i','s','p','l','a','y','_','d','e','v','i','c','e','_','i','n','i','t',0};
@@ -143,62 +128,6 @@ void release_display_device_init_mutex(HANDLE mutex)
     CloseHandle(mutex);
 }
 
-/* Update screen rectangle cache from SetupAPI if it's outdated, return FALSE on failure and TRUE on success */
-static BOOL update_screen_cache(void)
-{
-    RECT virtual_rect = {0}, primary_rect = {0}, monitor_rect;
-    SP_DEVINFO_DATA device_data = {sizeof(device_data)};
-    HDEVINFO devinfo = INVALID_HANDLE_VALUE;
-    FILETIME filetime = {0};
-    HANDLE mutex = NULL;
-    DWORD i = 0;
-    INT result;
-    DWORD type;
-    BOOL ret = FALSE;
-
-    EnterCriticalSection(&screen_section);
-    if ((!video_key && RegOpenKeyW(HKEY_LOCAL_MACHINE, video_keyW, &video_key))
-        || RegQueryInfoKeyW(video_key, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &filetime))
-    {
-        LeaveCriticalSection(&screen_section);
-        return FALSE;
-    }
-    result = CompareFileTime(&filetime, &last_query_screen_time);
-    LeaveCriticalSection(&screen_section);
-    if (result < 1)
-        return TRUE;
-
-    mutex = get_display_device_init_mutex();
-
-    devinfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_MONITOR, displayW, NULL, DIGCF_PRESENT);
-    if (devinfo == INVALID_HANDLE_VALUE)
-        goto fail;
-
-    while (SetupDiEnumDeviceInfo(devinfo, i++, &device_data))
-    {
-        if (!SetupDiGetDevicePropertyW(devinfo, &device_data, &WINE_DEVPROPKEY_MONITOR_RCMONITOR, &type,
-                                       (BYTE *)&monitor_rect, sizeof(monitor_rect), NULL, 0))
-            goto fail;
-
-        UnionRect(&virtual_rect, &virtual_rect, &monitor_rect);
-        if (i == 1)
-            primary_rect = monitor_rect;
-    }
-
-    EnterCriticalSection(&screen_section);
-    virtual_screen_rect = virtual_rect;
-    primary_monitor_rect = primary_rect;
-    last_query_screen_time = filetime;
-    LeaveCriticalSection(&screen_section);
-    ret = TRUE;
-fail:
-    SetupDiDestroyDeviceInfoList(devinfo);
-    release_display_device_init_mutex(mutex);
-    if (!ret)
-        WARN("Update screen cache failed!\n");
-    return ret;
-}
-
 POINT virtual_screen_to_root(INT x, INT y)
 {
     RECT virtual = get_virtual_screen_rect();
@@ -219,26 +148,41 @@ POINT root_to_virtual_screen(INT x, INT y)
     return pt;
 }
 
+static BOOL CALLBACK get_virtual_screen_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lp)
+{
+    RECT *virtual_rect = (RECT *)lp;
+
+    UnionRect(virtual_rect, virtual_rect, rect);
+    return TRUE;
+}
+
+static BOOL CALLBACK get_primary_monitor_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lp)
+{
+    RECT *primary_rect = (RECT *)lp;
+
+    if (!rect->top && !rect->left && rect->right && rect->bottom)
+    {
+        *primary_rect = *rect;
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
 RECT get_virtual_screen_rect(void)
 {
-    RECT virtual;
+    RECT rect = {0};
 
-    update_screen_cache();
-    EnterCriticalSection(&screen_section);
-    virtual = virtual_screen_rect;
-    LeaveCriticalSection(&screen_section);
-    return virtual;
+    EnumDisplayMonitors(0, NULL, get_virtual_screen_proc, (LPARAM)&rect);
+    return rect;
 }
 
 RECT get_primary_monitor_rect(void)
 {
-    RECT primary;
+    RECT rect = {0};
 
-    update_screen_cache();
-    EnterCriticalSection(&screen_section);
-    primary = primary_monitor_rect;
-    LeaveCriticalSection(&screen_section);
-    return primary;
+    EnumDisplayMonitors(0, NULL, get_primary_monitor_proc, (LPARAM)&rect);
+    return rect;
 }
 
 /* Get the primary monitor rect from the host system */
@@ -622,10 +566,6 @@ static BOOL X11DRV_InitMonitor(HDEVINFO devinfo, const struct x11drv_monitor *mo
     if (!SetupDiSetDevicePropertyW(devinfo, &device_data, &WINE_DEVPROPKEY_MONITOR_STATEFLAGS, DEVPROP_TYPE_UINT32,
                                    (const BYTE *)&monitor->state_flags, sizeof(monitor->state_flags), 0))
         goto done;
-    /* RcMonitor */
-    if (!SetupDiSetDevicePropertyW(devinfo, &device_data, &WINE_DEVPROPKEY_MONITOR_RCMONITOR, DEVPROP_TYPE_BINARY,
-                                   (const BYTE *)&monitor->rc_monitor, sizeof(monitor->rc_monitor), 0))
-        goto done;
     /* Adapter name */
     length = sprintfW(bufferW, adapter_name_fmtW, video_index + 1);
     if (!SetupDiSetDevicePropertyW(devinfo, &device_data, &WINE_DEVPROPKEY_MONITOR_ADAPTERNAME, DEVPROP_TYPE_STRING,
-- 
2.30.2




More information about the wine-devel mailing list