SDL_hints.c File Reference
`#include "./SDL_internal.h"`
`#include "SDL_hints.h"`
`#include "SDL_error.h"`
Include dependency graph for SDL_hints.c:

Go to the source code of this file.

## Data Structures

struct | SDL_HintWatch
struct | SDL_Hint

## Functions

SDL_bool | SDL_SetHintWithPriority (const char *name, const char *value, SDL_HintPriority priority)
| Set a hint with a specific priority. More...
SDL_bool | SDL_SetHint (const char *name, const char *value)
| Set a hint with normal priority. More...
const char * | SDL_GetHint (const char *name)
| Get a hint. More...
void | SDL_AddHintCallback (const char *name, SDL_HintCallback callback, void *userdata)
void | SDL_DelHintCallback (const char *name, SDL_HintCallback callback, void *userdata)
| Remove a function watching a particular hint. More...
void | SDL_ClearHints (void)
| Clear all hints. More...

## Variables

static SDL_Hint * | SDL_hints

## Function Documentation

void SDL_AddHintCallback | ( | const char * | name,
|  | SDL_HintCallback | callback,
|  | void * | userdata
| ) |  |

Definition at line 122 of file SDL_hints.c.

References SDL_HintWatch::callback, SDL_Hint::callbacks, SDL_Hint::name, SDL_HintWatch::next, SDL_Hint::next, NULL, SDL_Hint::priority, SDL_DelHintCallback(), SDL_free(), SDL_GetHint(), SDL_HINT_DEFAULT, SDL_hints, SDL_InvalidParamError, SDL_malloc, SDL_OutOfMemory, SDL_strcmp, SDL_strdup, SDL_HintWatch::userdata, and SDL_Hint::value.

{
SDL_Hint *hint;
SDL_HintWatch *entry;
const char *value;
if (!name || !*name) {
SDL_InvalidParamError("name");
return;
}
if (!callback) {
SDL_InvalidParamError("callback");
return;
}
SDL_DelHintCallback(name, callback, userdata);
entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
if (!entry) {
SDL_OutOfMemory();
return;
}
entry->callback = callback;
entry->userdata = userdata;
for (hint = SDL_hints; hint; hint = hint->next) {
if (SDL_strcmp(name, hint->name) == 0) {
break;
}
}
if (!hint) {
/* Need to add a hint entry for this watcher */
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
if (!hint) {
SDL_OutOfMemory();
SDL_free(entry);
return;
}
hint->name = SDL_strdup(name);
hint->value = NULL;
hint->priority = SDL_HINT_DEFAULT;
hint->callbacks = NULL;
hint->next = SDL_hints;
SDL_hints = hint;
}
/* Add it to the callbacks for this hint */
entry->next = hint->callbacks;
hint->callbacks = entry;
/* Now call it with the current value */
value = SDL_GetHint(name);
callback(userdata, name, value, value);
}
SDL_HintWatch::userdata
void * userdata
Definition: SDL_hints.c:32
SDL_GetHint
const char * SDL_GetHint(const char *name)
Get a hint.
Definition: SDL_hints.c:104
SDL_DelHintCallback
void SDL_DelHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
Remove a function watching a particular hint.
Definition: SDL_hints.c:178
SDL_Hint::next
struct SDL_Hint * next
Definition: SDL_hints.c:41
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDL_InvalidParamError
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
SDL_HINT_DEFAULT
Definition: SDL_hints.h:638
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
SDL_free
void SDL_free(void *mem)
callback
static Uint32 callback(Uint32 interval, void *param)
Definition: testtimer.c:34
SDL_Hint::callbacks
SDL_HintWatch * callbacks
Definition: SDL_hints.c:40
NULL
#define NULL
Definition: begin_code.h:143
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_Hint::priority
SDL_HintPriority priority
Definition: SDL_hints.c:39
SDL_HintWatch
Definition: SDL_hints.c:30
SDL_strdup
#define SDL_strdup
Definition: SDL_dynapi_overrides.h:403
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:380
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:423
SDL_Hint::value
char * value
Definition: SDL_hints.c:38
SDL_HintWatch::callback
SDL_HintCallback callback
Definition: SDL_hints.c:31
SDL_HintWatch::next
struct SDL_HintWatch * next
Definition: SDL_hints.c:33
SDL_Hint
Definition: SDL_hints.c:36
SDL_Hint::name
char * name
Definition: SDL_hints.c:37
SDL_hints
static SDL_Hint * SDL_hints
Definition: SDL_hints.c:44

void SDL_ClearHints | ( | void |  | ) |

Clear all hints.

This function is called during SDL_Quit() to free stored hints.

Definition at line 203 of file SDL_hints.c.

References SDL_Hint::callbacks, SDL_Hint::name, SDL_HintWatch::next, SDL_Hint::next, SDL_free(), SDL_hints, and SDL_Hint::value.

{
SDL_Hint *hint;
SDL_HintWatch *entry;
while (SDL_hints) {
hint = SDL_hints;
SDL_hints = hint->next;
SDL_free(hint->name);
SDL_free(hint->value);
for (entry = hint->callbacks; entry; ) {
SDL_HintWatch *freeable = entry;
entry = entry->next;
SDL_free(freeable);
}
SDL_free(hint);
}
}
SDL_Hint::next
struct SDL_Hint * next
Definition: SDL_hints.c:41
SDL_free
void SDL_free(void *mem)
SDL_Hint::callbacks
SDL_HintWatch * callbacks
Definition: SDL_hints.c:40
SDL_HintWatch
Definition: SDL_hints.c:30
SDL_Hint::value
char * value
Definition: SDL_hints.c:38
SDL_HintWatch::next
struct SDL_HintWatch * next
Definition: SDL_hints.c:33
SDL_Hint
Definition: SDL_hints.c:36
SDL_Hint::name
char * name
Definition: SDL_hints.c:37
SDL_hints
static SDL_Hint * SDL_hints
Definition: SDL_hints.c:44

void SDL_DelHintCallback | ( | const char * | name,
|  | SDL_HintCallback | callback,
|  | void * | userdata
| ) |  |

Remove a function watching a particular hint.

Parameters

  name | The hint being watched
  callback | The function being called when the hint value changes
  userdata | A pointer being passed to the callback function

Definition at line 178 of file SDL_hints.c.

References SDL_HintWatch::callback, SDL_Hint::callbacks, SDL_Hint::name, SDL_HintWatch::next, SDL_Hint::next, NULL, SDL_free(), SDL_strcmp, and SDL_HintWatch::userdata.

Referenced by SDL_AddHintCallback().

{
SDL_Hint *hint;
SDL_HintWatch *entry, *prev;
for (hint = SDL_hints; hint; hint = hint->next) {
if (SDL_strcmp(name, hint->name) == 0) {
prev = NULL;
for (entry = hint->callbacks; entry; entry = entry->next) {
if (callback == entry->callback && userdata == entry->userdata) {
if (prev) {
prev->next = entry->next;
} else {
hint->callbacks = entry->next;
}
SDL_free(entry);
break;
}
prev = entry;
}
return;
}
}
}
SDL_HintWatch::userdata
void * userdata
Definition: SDL_hints.c:32
SDL_Hint::next
struct SDL_Hint * next
Definition: SDL_hints.c:41
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDL_free
void SDL_free(void *mem)
callback
static Uint32 callback(Uint32 interval, void *param)
Definition: testtimer.c:34
SDL_Hint::callbacks
SDL_HintWatch * callbacks
Definition: SDL_hints.c:40
NULL
#define NULL
Definition: begin_code.h:143
SDL_HintWatch
Definition: SDL_hints.c:30
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:423
SDL_HintWatch::callback
SDL_HintCallback callback
Definition: SDL_hints.c:31
SDL_HintWatch::next
struct SDL_HintWatch * next
Definition: SDL_hints.c:33
SDL_Hint
Definition: SDL_hints.c:36
SDL_Hint::name
char * name
Definition: SDL_hints.c:37
SDL_hints
static SDL_Hint * SDL_hints
Definition: SDL_hints.c:44

const char* SDL_GetHint | ( | const char * | name | ) |

Get a hint.

Returns
  The string value of a hint variable.

Definition at line 104 of file SDL_hints.c.

References SDL_Hint::name, SDL_Hint::next, SDL_Hint::priority, SDL_getenv, SDL_HINT_OVERRIDE, SDL_strcmp, and SDL_Hint::value.

Referenced by SDL_AddHintCallback().

{
const char *env;
SDL_Hint *hint;
env = SDL_getenv(name);
for (hint = SDL_hints; hint; hint = hint->next) {
if (SDL_strcmp(name, hint->name) == 0) {
if (!env || hint->priority == SDL_HINT_OVERRIDE) {
return hint->value;
}
break;
}
}
return env;
}
SDL_Hint::next
struct SDL_Hint * next
Definition: SDL_hints.c:41
SDL_HINT_OVERRIDE
Definition: SDL_hints.h:640
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDL_getenv
#define SDL_getenv
Definition: SDL_dynapi_overrides.h:384
SDL_Hint::priority
SDL_HintPriority priority
Definition: SDL_hints.c:39
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:423
SDL_Hint::value
char * value
Definition: SDL_hints.c:38
SDL_Hint
Definition: SDL_hints.c:36
SDL_Hint::name
char * name
Definition: SDL_hints.c:37
SDL_hints
static SDL_Hint * SDL_hints
Definition: SDL_hints.c:44

SDL_bool SDL_SetHint | ( | const char * | name,
|  | const char * | value
| ) |  |

Set a hint with normal priority.

Returns
  SDL_TRUE if the hint was set, SDL_FALSE otherwise

Definition at line 98 of file SDL_hints.c.

References SDL_HINT_NORMAL, and SDL_SetHintWithPriority().

{
return SDL_SetHintWithPriority(name, value, SDL_HINT_NORMAL);
}
SDL_SetHintWithPriority
SDL_bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriority priority)
Set a hint with a specific priority.
Definition: SDL_hints.c:47
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
SDL_HINT_NORMAL
Definition: SDL_hints.h:639

SDL_bool SDL_SetHintWithPriority | ( | const char * | name,
|  | const char * | value,
|  | SDL_HintPriority | priority
| ) |  |

Set a hint with a specific priority.

The priority controls the behavior when setting a hint that already has a value. Hints will replace existing hints of their priority and lower. Environment variables are considered to have override priority.

Returns
  SDL_TRUE if the hint was set, SDL_FALSE otherwise

Definition at line 47 of file SDL_hints.c.

References SDL_HintWatch::callback, SDL_Hint::callbacks, SDL_Hint::name, SDL_HintWatch::next, SDL_Hint::next, NULL, SDL_Hint::priority, SDL_FALSE, SDL_free(), SDL_getenv, SDL_HINT_OVERRIDE, SDL_hints, SDL_malloc, SDL_strcmp, SDL_strdup, SDL_TRUE, SDL_HintWatch::userdata, and SDL_Hint::value.

Referenced by SDL_SetHint().

{
const char *env;
SDL_Hint *hint;
SDL_HintWatch *entry;
if (!name || !value) {
return SDL_FALSE;
}
env = SDL_getenv(name);
if (env && priority < SDL_HINT_OVERRIDE) {
return SDL_FALSE;
}
for (hint = SDL_hints; hint; hint = hint->next) {
if (SDL_strcmp(name, hint->name) == 0) {
if (priority < hint->priority) {
return SDL_FALSE;
}
if (!hint->value || !value || SDL_strcmp(hint->value, value) != 0) {
for (entry = hint->callbacks; entry; ) {
/* Save the next entry in case this one is deleted */
SDL_HintWatch *next = entry->next;
entry->callback(entry->userdata, name, hint->value, value);
entry = next;
}
SDL_free(hint->value);
hint->value = value ? SDL_strdup(value) : NULL;
}
hint->priority = priority;
return SDL_TRUE;
}
}
/* Couldn't find the hint, add a new one */
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
if (!hint) {
return SDL_FALSE;
}
hint->name = SDL_strdup(name);
hint->value = value ? SDL_strdup(value) : NULL;
hint->priority = priority;
hint->callbacks = NULL;
hint->next = SDL_hints;
SDL_hints = hint;
return SDL_TRUE;
}
SDL_HintWatch::userdata
void * userdata
Definition: SDL_hints.c:32
SDL_Hint::next
struct SDL_Hint * next
Definition: SDL_hints.c:41
SDL_HINT_OVERRIDE
Definition: SDL_hints.h:640
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
SDL_free
void SDL_free(void *mem)
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_Hint::callbacks
SDL_HintWatch * callbacks
Definition: SDL_hints.c:40
SDL_getenv
#define SDL_getenv
Definition: SDL_dynapi_overrides.h:384
NULL
#define NULL
Definition: begin_code.h:143
SDL_Hint::priority
SDL_HintPriority priority
Definition: SDL_hints.c:39
SDL_HintWatch
Definition: SDL_hints.c:30
SDL_strdup
#define SDL_strdup
Definition: SDL_dynapi_overrides.h:403
SDL_FALSE
Definition: SDL_stdinc.h:128
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:380
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:423
SDL_Hint::value
char * value
Definition: SDL_hints.c:38
SDL_HintWatch::callback
SDL_HintCallback callback
Definition: SDL_hints.c:31
SDL_HintWatch::next
struct SDL_HintWatch * next
Definition: SDL_hints.c:33
SDL_Hint
Definition: SDL_hints.c:36
SDL_Hint::name
char * name
Definition: SDL_hints.c:37
SDL_hints
static SDL_Hint * SDL_hints
Definition: SDL_hints.c:44

## Variable Documentation

SDL_Hint* SDL_hints

static

Definition at line 44 of file SDL_hints.c.

Referenced by SDL_AddHintCallback(), SDL_ClearHints(), and SDL_SetHintWithPriority().