2011-02-05 10:02:39 -08:00
|
|
|
/*
|
2011-04-08 13:03:26 -07:00
|
|
|
Simple DirectMedia Layer
|
2013-02-15 08:47:44 -08:00
|
|
|
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
2011-02-05 10:02:39 -08:00
|
|
|
|
2011-04-08 13:03:26 -07:00
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
2011-02-05 10:02:39 -08:00
|
|
|
|
2011-04-08 13:03:26 -07:00
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
2011-02-05 10:02:39 -08:00
|
|
|
|
2011-04-08 13:03:26 -07:00
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
2011-02-05 10:02:39 -08:00
|
|
|
*/
|
|
|
|
#include "SDL_config.h"
|
|
|
|
|
|
|
|
#include "SDL_hints.h"
|
2011-06-10 14:23:36 +01:00
|
|
|
#include "SDL_hints_c.h"
|
2011-02-05 10:02:39 -08:00
|
|
|
|
|
|
|
|
|
|
|
/* Assuming there aren't many hints set and they aren't being queried in
|
|
|
|
critical performance paths, we'll just use a linked list here.
|
|
|
|
*/
|
|
|
|
typedef struct SDL_Hint {
|
|
|
|
char *name;
|
|
|
|
char *value;
|
|
|
|
SDL_HintPriority priority;
|
2011-06-10 14:23:36 +01:00
|
|
|
SDL_HintChangedCb callback;
|
2011-02-05 10:02:39 -08:00
|
|
|
struct SDL_Hint *next;
|
|
|
|
} SDL_Hint;
|
|
|
|
|
|
|
|
static SDL_Hint *SDL_hints;
|
|
|
|
|
2011-06-10 14:23:36 +01:00
|
|
|
SDL_bool
|
|
|
|
SDL_RegisterHintChangedCb(const char *name, SDL_HintChangedCb hintCb)
|
|
|
|
{
|
|
|
|
SDL_Hint *hint;
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2011-06-10 14:23:36 +01:00
|
|
|
for (hint = SDL_hints; hint; hint = hint->next) {
|
|
|
|
if (SDL_strcmp(name, hint->name) == 0) {
|
|
|
|
hint->callback = hintCb;
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2011-06-10 14:23:36 +01:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
2011-02-05 10:02:39 -08:00
|
|
|
|
|
|
|
SDL_bool
|
2011-02-05 20:02:37 -08:00
|
|
|
SDL_SetHintWithPriority(const char *name, const char *value,
|
|
|
|
SDL_HintPriority priority)
|
2011-02-05 10:02:39 -08:00
|
|
|
{
|
|
|
|
const char *env;
|
2012-08-09 14:14:41 -04:00
|
|
|
SDL_Hint *hint;
|
2011-02-05 10:02:39 -08:00
|
|
|
|
|
|
|
if (!name || !value) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
env = SDL_getenv(name);
|
|
|
|
if (env && priority < SDL_HINT_OVERRIDE) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-09 14:14:41 -04:00
|
|
|
for (hint = SDL_hints; hint; hint = hint->next) {
|
2011-02-05 10:02:39 -08:00
|
|
|
if (SDL_strcmp(name, hint->name) == 0) {
|
|
|
|
if (priority < hint->priority) {
|
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
if (SDL_strcmp(hint->value, value) != 0) {
|
2011-06-10 14:23:36 +01:00
|
|
|
if (hint->callback != NULL) {
|
|
|
|
(*hint->callback)(name, hint->value, value);
|
|
|
|
}
|
2011-02-05 10:02:39 -08:00
|
|
|
SDL_free(hint->value);
|
|
|
|
hint->value = SDL_strdup(value);
|
|
|
|
}
|
|
|
|
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 = SDL_strdup(value);
|
|
|
|
hint->priority = priority;
|
2011-06-10 14:23:36 +01:00
|
|
|
hint->callback = NULL;
|
2011-02-05 10:02:39 -08:00
|
|
|
hint->next = SDL_hints;
|
|
|
|
SDL_hints = hint;
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2011-02-05 20:02:37 -08:00
|
|
|
SDL_bool
|
|
|
|
SDL_SetHint(const char *name, const char *value)
|
|
|
|
{
|
|
|
|
return SDL_SetHintWithPriority(name, value, SDL_HINT_NORMAL);
|
|
|
|
}
|
|
|
|
|
2011-02-05 10:02:39 -08:00
|
|
|
const char *
|
|
|
|
SDL_GetHint(const char *name)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-02-12 12:04:23 -08:00
|
|
|
void SDL_ClearHints(void)
|
2011-02-05 10:02:39 -08:00
|
|
|
{
|
|
|
|
SDL_Hint *hint;
|
|
|
|
|
|
|
|
while (SDL_hints) {
|
|
|
|
hint = SDL_hints;
|
|
|
|
SDL_hints = hint->next;
|
|
|
|
|
|
|
|
SDL_free(hint->name);
|
|
|
|
SDL_free(hint->value);
|
|
|
|
SDL_free(hint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|