[PATCH v2 6/7] winemac.drv: Use registry to query primary adapter key.

Zhiyi Zhang zzhang at codeweavers.com
Wed Mar 6 02:43:57 CST 2019


Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
---
 dlls/winemac.drv/display.c | 47 ++++++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 17 deletions(-)

diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c
index 00ad7738bb..9a9c8695f4 100644
--- a/dlls/winemac.drv/display.c
+++ b/dlls/winemac.drv/display.c
@@ -75,27 +75,40 @@ static inline CGDirectDisplayID monitor_to_display_id(HMONITOR handle)
 }
 
 
-static BOOL get_display_device_reg_key(char *key, unsigned len)
+/* Get the primary adapter key in the form of System\CurrentControlSet\Control\Video\{Primary adapter GUID}\0000 */
+static BOOL get_primary_adapter_key(char *key, unsigned len)
 {
-    static const char display_device_guid_prop[] = "__wine_display_device_guid";
-    static const char video_path[] = "System\\CurrentControlSet\\Control\\Video\\{";
-    static const char display0[] = "}\\0000";
-    ATOM guid_atom;
-
-    assert(len >= sizeof(video_path) + sizeof(display0) + 40);
+    static const CHAR value_prefix[] = "\\Registry\\Machine\\";
+    CHAR buffer[MAX_PATH];
+    CHAR *substring;
+    DWORD size;
+    size_t length;
+    BOOL ret = FALSE;
 
-    guid_atom = HandleToULong(GetPropA(GetDesktopWindow(), display_device_guid_prop));
-    if (!guid_atom) return FALSE;
+    /* Vaule data of \Device\Video0 in HKLM\HARDWARE\DEVICEMAP\VIDEO\ */
+    size = sizeof(buffer);
+    if (RegGetValueA(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\VIDEO", "\\Device\\Video0",
+                     RRF_RT_REG_SZ | RRF_ZEROONFAILURE, NULL, buffer, &size))
+        goto fail;
 
-    memcpy(key, video_path, sizeof(video_path));
+    /* Need to strip "\Registry\Machine\" from the value data, which starts with "\Registry\Machine\System\..." */
+    length = strlen(value_prefix);
+    if (strncasecmp(buffer, value_prefix, length))
+        goto fail;
 
-    if (!GlobalGetAtomNameA(guid_atom, key + strlen(key), 40))
-        return FALSE;
+    substring = buffer + length;
+    length = strlen(substring);
+    if (len < length + 1)
+        goto fail;
 
-    strcat(key, display0);
+    strcpy(key, substring);
 
-    TRACE("display device key %s\n", wine_dbgstr_a(key));
-    return TRUE;
+    ret = TRUE;
+    TRACE("primary adapter key %s\n", wine_dbgstr_a(key));
+fail:
+    if (!ret)
+        ERR("Failed to get primary adapter registry key\n");
+    return ret;
 }
 
 
@@ -108,7 +121,7 @@ static BOOL read_registry_settings(DEVMODEW *dm)
 
     dm->dmFields = 0;
 
-    if (!get_display_device_reg_key(wine_mac_reg_key, sizeof(wine_mac_reg_key)))
+    if (!get_primary_adapter_key(wine_mac_reg_key, sizeof(wine_mac_reg_key)))
         return FALSE;
 
     if (RegOpenKeyExA(HKEY_CURRENT_CONFIG, wine_mac_reg_key, 0, KEY_READ, &hkey))
@@ -148,7 +161,7 @@ static BOOL write_registry_settings(const DEVMODEW *dm)
     HKEY hkey;
     BOOL ret = TRUE;
 
-    if (!get_display_device_reg_key(wine_mac_reg_key, sizeof(wine_mac_reg_key)))
+    if (!get_primary_adapter_key(wine_mac_reg_key, sizeof(wine_mac_reg_key)))
         return FALSE;
 
     if (RegCreateKeyExA(HKEY_CURRENT_CONFIG, wine_mac_reg_key, 0, NULL,
-- 
2.20.1





More information about the wine-devel mailing list