From c1336b21ed93dcdeaf06503b4bdadd9bd23c44c5 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sun, 17 Apr 2022 12:43:32 -0400
Subject: [PATCH] hints: Make SDL_VIDEODRIVER and SDL_AUDIODRIVER formal hints.
They were just environment variables before.
Fixes #5528.
---
include/SDL_hints.h | 47 +++++++++++++++++++++++++++++++++
src/audio/SDL_audio.c | 2 +-
src/video/SDL_video.c | 2 +-
src/video/dummy/SDL_nullvideo.c | 3 ++-
4 files changed, 51 insertions(+), 3 deletions(-)
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index c5371324ada..ea819c85d3a 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -1993,6 +1993,53 @@ extern "C" {
#define SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE "SDL_QUIT_ON_LAST_WINDOW_CLOSE"
+/**
+ * \brief A variable that decides what video backend to use.
+ *
+ * By default, SDL will try all available video backends in a reasonable
+ * order until it finds one that can work, but this hint allows the app
+ * or user to force a specific target, such as "x11" if, say, you are
+ * on Wayland but want to try talking to the X server instead.
+ *
+ * This functionality has existed since SDL 2.0.0 (indeed, before that)
+ * but before 2.0.22 this was an environment variable only. In 2.0.22,
+ * it was upgraded to a full SDL hint, so you can set the environment
+ * variable as usual or programatically set the hint with SDL_SetHint,
+ * which won't propagate to child processes.
+ *
+ * The default value is unset, in which case SDL will try to figure out
+ * the best video backend on your behalf. This hint needs to be set
+ * before SDL_Init() is called to be useful.
+ *
+ * This hint is available since SDL 2.0.22. Before then, you could set
+ * the environment variable to get the same effect.
+ */
+#define SDL_HINT_VIDEODRIVER "SDL_VIDEODRIVER"
+
+/**
+ * \brief A variable that decides what audio backend to use.
+ *
+ * By default, SDL will try all available audio backends in a reasonable
+ * order until it finds one that can work, but this hint allows the app
+ * or user to force a specific target, such as "alsa" if, say, you are
+ * on PulseAudio but want to try talking to the lower level instead.
+ *
+ * This functionality has existed since SDL 2.0.0 (indeed, before that)
+ * but before 2.0.22 this was an environment variable only. In 2.0.22,
+ * it was upgraded to a full SDL hint, so you can set the environment
+ * variable as usual or programatically set the hint with SDL_SetHint,
+ * which won't propagate to child processes.
+ *
+ * The default value is unset, in which case SDL will try to figure out
+ * the best audio backend on your behalf. This hint needs to be set
+ * before SDL_Init() is called to be useful.
+ *
+ * This hint is available since SDL 2.0.22. Before then, you could set
+ * the environment variable to get the same effect.
+ */
+#define SDL_HINT_AUDIODRIVER "SDL_AUDIODRIVER"
+
+
/**
* \brief An enumeration of hint priorities
*/
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 3a841450c5d..fb363f77141 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -936,7 +936,7 @@ SDL_AudioInit(const char *driver_name)
/* Select the proper audio driver */
if (driver_name == NULL) {
- driver_name = SDL_getenv("SDL_AUDIODRIVER");
+ driver_name = SDL_GetHint(SDL_HINT_AUDIODRIVER);
}
if (driver_name != NULL && *driver_name != 0) {
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 2b095243021..1673666c065 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -425,7 +425,7 @@ SDL_VideoInit(const char *driver_name)
i = index = 0;
video = NULL;
if (driver_name == NULL) {
- driver_name = SDL_getenv("SDL_VIDEODRIVER");
+ driver_name = SDL_GetHint(SDL_HINT_VIDEODRIVER);
}
if (driver_name != NULL && *driver_name != 0) {
const char *driver_attempt = driver_name;
diff --git a/src/video/dummy/SDL_nullvideo.c b/src/video/dummy/SDL_nullvideo.c
index aafed848d2b..a7fb1aac296 100644
--- a/src/video/dummy/SDL_nullvideo.c
+++ b/src/video/dummy/SDL_nullvideo.c
@@ -46,6 +46,7 @@
#include "SDL_nullvideo.h"
#include "SDL_nullevents_c.h"
#include "SDL_nullframebuffer_c.h"
+#include "SDL_hints.h"
#define DUMMYVID_DRIVER_NAME "dummy"
@@ -59,7 +60,7 @@ static void DUMMY_VideoQuit(_THIS);
static int
DUMMY_Available(void)
{
- const char *envr = SDL_getenv("SDL_VIDEODRIVER");
+ const char *envr = SDL_GetHint(SDL_HINT_VIDEODRIVER);
if ((envr) && (SDL_strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) {
return (1);
}