diff --git a/docs/README-migration.md b/docs/README-migration.md index 887b1bb59a..0d45145322 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -798,7 +798,7 @@ The following functions have been removed: Calling SDL_GetHint() with the name of the hint being changed from within a hint callback will now return the new value rather than the old value. The old value is still passed as a parameter to the hint callback. -The environment variables SDL_VIDEODRIVER and SDL_AUDIODRIVER have been renamed to SDL_VIDEO_DRIVER and SDL_AUDIO_DRIVER. +The environment variables SDL_VIDEODRIVER and SDL_AUDIODRIVER have been renamed to SDL_VIDEO_DRIVER and SDL_AUDIO_DRIVER, but the old names are still supported as a fallback. The environment variables SDL_VIDEO_X11_WMCLASS and SDL_VIDEO_WAYLAND_WMCLASS have been removed and replaced by either using the appindentifier param to SDL_SetAppMetadata() or setting SDL_PROP_APP_METADATA_IDENTIFIER_STRING with SDL_SetAppMetadataProperty() diff --git a/src/SDL_hints.c b/src/SDL_hints.c index c92ad46fc0..91c2bfec96 100644 --- a/src/SDL_hints.c +++ b/src/SDL_hints.c @@ -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) {