This allows options from https://gitlab.winehq.org/wine/wine/-/merge_requests/8686 to be set directly in an environment variable, making it easier for users to configure the hidraw preference system-wide, to match their devices across all prefixes.
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winebus.sys/main.c | 29 +++++++++++++++++++++++++++++ programs/services/services.c | 22 +++++++++++++++------- tools/wine/wine.man.in | 13 +++++++++++++ 3 files changed, 57 insertions(+), 7 deletions(-)
diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index a9f634a8e42..8813ec61fef 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -1083,6 +1083,8 @@ static void load_device_options(void)
static void bus_options_init(void) { + char *env; + options.disable_sdl = !check_bus_option(L"Enable SDL", 1); if (options.disable_sdl) TRACE("SDL devices disabled in registry\n"); options.disable_hidraw = check_bus_option(L"DisableHidraw", 0); @@ -1102,6 +1104,33 @@ static void bus_options_init(void) }
load_device_options(); + + if ((env = getenv("WINEBUSCONFIG")) && (env = strdup(env))) + { + struct device_options *device; + UINT vid, pid; + int ret; + + TRACE("Parsing WINEBUSCONFIG %s\n", debugstr_a(env)); + + for (const char *next, *opt = strtok(env, ","); opt; opt = strtok(NULL, ",")) + { + if ((ret = sscanf(opt, "%04x/%04x=", &vid, &pid)) < 1) continue; + if (!(device = add_device_options(vid, ret == 1 ? -1 : pid))) break; + + for (opt = strchr(opt + 1, '='); opt; opt = next) + { + if (!strncmp(opt + 1, "hidraw", 6)) device->hidraw = 1; + else if (!strncmp(opt + 1, "nohidraw", 8)) device->hidraw = 0; + + if (!(next = strchr(opt + 1, '/'))) break; + } + + if (device->hidraw != -1) TRACE("- %04x/%04x: %sabling hidraw\n", device->vid, device->pid, device->hidraw ? "en" : "dis"); + } + + free(env); + } }
static void bus_options_cleanup(void) diff --git a/programs/services/services.c b/programs/services/services.c index dff3cd60040..4131106d43d 100644 --- a/programs/services/services.c +++ b/programs/services/services.c @@ -1030,15 +1030,23 @@ found:
if (!environment && OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_DUPLICATE, &token)) { - WCHAR val[16]; - CreateEnvironmentBlock(&environment, token, FALSE); - if (GetEnvironmentVariableW( L"WINEBOOTSTRAPMODE", val, ARRAY_SIZE(val) )) + static const WCHAR *preserve[] = { - UNICODE_STRING name = RTL_CONSTANT_STRING(L"WINEBOOTSTRAPMODE"); - UNICODE_STRING value; + L"WINEBOOTSTRAPMODE", + L"WINEBUSCONFIG", + }; + WCHAR buffer[1024];
- RtlInitUnicodeString( &value, val ); - RtlSetEnvironmentVariable( (WCHAR **)&environment, &name, &value ); + CreateEnvironmentBlock(&environment, token, FALSE); + for (size_t i = 0; i < ARRAY_SIZE(preserve); i++) + { + if (GetEnvironmentVariableW( preserve[i], buffer, ARRAY_SIZE(buffer) )) + { + UNICODE_STRING value, name; + RtlInitUnicodeString( &name, preserve[i] ); + RtlInitUnicodeString( &value, buffer ); + RtlSetEnvironmentVariable( (WCHAR **)&environment, &name, &value ); + } } CloseHandle(token); } diff --git a/tools/wine/wine.man.in b/tools/wine/wine.man.in index ddc84e8345b..02bc1292a5c 100644 --- a/tools/wine/wine.man.in +++ b/tools/wine/wine.man.in @@ -234,6 +234,19 @@ WINE_D3D_CONFIG="renderer=vulkan;VideoPciVendorID=0xc0de" If an individual setting is specified in both the environment variable and the registry, the former takes precedence. .RE +.B WINEBUSCONFIG +Specifies WineBus configuration options. It can be used instead of +modifying the +.B HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\WineBus\\Devices +registry key. The value is a comma-separated list of key-value pairs. +.RS +For example: +.TP +WINEBUSCONFIG="3344=nohidraw,231d/0128=hidraw,044f/b10a=nohidraw" +.PP +If an individual setting is specified in both +the environment variable and the registry, the former takes precedence. +.RE .TP .B DISPLAY Specifies the X11 display to use.