[PATCH v2 5/7] winex11.drv: Use registry to query primary adapter key.
Zhiyi Zhang
zzhang at codeweavers.com
Wed Mar 6 02:43:44 CST 2019
Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
---
dlls/winex11.drv/settings.c | 58 +++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 22 deletions(-)
diff --git a/dlls/winex11.drv/settings.c b/dlls/winex11.drv/settings.c
index 800b65dbfd..e867925c26 100644
--- a/dlls/winex11.drv/settings.c
+++ b/dlls/winex11.drv/settings.c
@@ -154,29 +154,43 @@ void X11DRV_Settings_Init(void)
X11DRV_Settings_AddOneMode( primary.right - primary.left, primary.bottom - primary.top, 0, 60);
}
-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);
-
- guid_atom = HandleToULong(GetPropA(GetDesktopWindow(), display_device_guid_prop));
- if (!guid_atom) return FALSE;
-
- memcpy(key, video_path, sizeof(video_path));
-
- if (!GlobalGetAtomNameA(guid_atom, key + strlen(key), 40))
- return FALSE;
-
- strcat(key, display0);
-
- TRACE("display device key %s\n", wine_dbgstr_a(key));
- return TRUE;
+ static const CHAR value_prefix[] = "\\Registry\\Machine\\";
+ CHAR buffer[MAX_PATH];
+ CHAR *substring;
+ DWORD size;
+ size_t length;
+ BOOL ret = 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;
+
+ /* 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;
+
+ substring = buffer + length;
+ length = strlen(substring);
+ if (len < length + 1)
+ goto fail;
+
+ strcpy(key, substring);
+
+ 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;
}
+
static BOOL read_registry_settings(DEVMODEW *dm)
{
char wine_x11_reg_key[128];
@@ -186,7 +200,7 @@ static BOOL read_registry_settings(DEVMODEW *dm)
dm->dmFields = 0;
- if (!get_display_device_reg_key(wine_x11_reg_key, sizeof(wine_x11_reg_key)))
+ if (!get_primary_adapter_key(wine_x11_reg_key, sizeof(wine_x11_reg_key)))
return FALSE;
if (RegOpenKeyExA(HKEY_CURRENT_CONFIG, wine_x11_reg_key, 0, KEY_READ, &hkey))
@@ -225,7 +239,7 @@ static BOOL write_registry_settings(const DEVMODEW *dm)
HKEY hkey;
BOOL ret = TRUE;
- if (!get_display_device_reg_key(wine_x11_reg_key, sizeof(wine_x11_reg_key)))
+ if (!get_primary_adapter_key(wine_x11_reg_key, sizeof(wine_x11_reg_key)))
return FALSE;
if (RegCreateKeyExA(HKEY_CURRENT_CONFIG, wine_x11_reg_key, 0, NULL,
--
2.20.1
More information about the wine-devel
mailing list