Old env vars as fallback for SDL_VIDEO_DRIVER + SDL_AUDIO_DRIVER #11115
especially SDL_VIDEODRIVER is commonly used to use the native Wayland backend, so I think it's a good idea to keep supporting the old name instead of forcing users to find out that they now have to add an underscore.. Not sure how popular SDL_AUDIODRIVER is, but with all the audio backends that exist on Linux alone I'm sure some people use it to work around sound issues. Note: Doing this in the SDL_hints implementation instead of the call-sites of SDL_GetHint(SDL_HINT_VIDEO_DRIVER) etc ensures that 1. Hint priorities work (env var overriding hint set by application with normal priority, but not when application used SDL_HINT_OVERRIDE) 2. SDL_ResetHint() (called by user code) respects the fallback environment variable
This commit is contained in:
committed by
Sam Lantinga
parent
3e57d996fe
commit
9a81892447
@@ -83,13 +83,28 @@ static void SDLCALL CleanupHintProperty(void *userdata, void *value)
|
||||
SDL_free(hint);
|
||||
}
|
||||
|
||||
static const char* GetHintEnvironmentVariable(const char *name)
|
||||
{
|
||||
const char *result = SDL_getenv(name);
|
||||
if (!result && name && *name) {
|
||||
// fall back to old (SDL2) names of environment variables that
|
||||
// are important to users (e.g. many use SDL_VIDEODRIVER=wayland)
|
||||
if (SDL_strcmp(name, SDL_HINT_VIDEO_DRIVER) == 0) {
|
||||
result = SDL_getenv("SDL_VIDEODRIVER");
|
||||
} else if (SDL_strcmp(name, SDL_HINT_AUDIO_DRIVER) == 0) {
|
||||
result = SDL_getenv("SDL_AUDIODRIVER");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriority priority)
|
||||
{
|
||||
if (!name || !*name) {
|
||||
return SDL_InvalidParamError("name");
|
||||
}
|
||||
|
||||
const char *env = SDL_getenv(name);
|
||||
const char *env = GetHintEnvironmentVariable(name);
|
||||
if (env && (priority < SDL_HINT_OVERRIDE)) {
|
||||
return SDL_SetError("An environment variable is taking priority");
|
||||
}
|
||||
@@ -143,7 +158,7 @@ bool SDL_ResetHint(const char *name)
|
||||
return SDL_InvalidParamError("name");
|
||||
}
|
||||
|
||||
const char *env = SDL_getenv(name);
|
||||
const char *env = GetHintEnvironmentVariable(name);
|
||||
|
||||
const SDL_PropertiesID hints = GetHintProperties(false);
|
||||
if (!hints) {
|
||||
@@ -182,7 +197,7 @@ static void SDLCALL ResetHintsCallback(void *userdata, SDL_PropertiesID hints, c
|
||||
return; // uh...okay.
|
||||
}
|
||||
|
||||
const char *env = SDL_getenv(name);
|
||||
const char *env = GetHintEnvironmentVariable(name);
|
||||
if ((!env && hint->value) || (env && !hint->value) || (env && SDL_strcmp(env, hint->value) != 0)) {
|
||||
SDL_HintWatch *entry = hint->callbacks;
|
||||
while (entry) {
|
||||
@@ -213,7 +228,7 @@ const char *SDL_GetHint(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *result = SDL_getenv(name);
|
||||
const char *result = GetHintEnvironmentVariable(name);
|
||||
|
||||
const SDL_PropertiesID hints = GetHintProperties(false);
|
||||
if (hints) {
|
||||
|
||||
Reference in New Issue
Block a user