Implemented SDL_GetHintBoolean() to make it easier to check boolean hints

This commit is contained in:
Sam Lantinga
2016-10-07 23:40:44 -07:00
parent 92d700f199
commit 27d4f09929
26 changed files with 68 additions and 136 deletions

View File

@@ -556,10 +556,7 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
}
if (save32bit) {
const char *hint = SDL_GetHint(SDL_HINT_BMP_SAVE_LEGACY_FORMAT);
if (hint != NULL && (hint[0] == '1' && hint[1] == 0)) {
saveLegacyBMP = SDL_TRUE;
}
saveLegacyBMP = SDL_GetHintBoolean(SDL_HINT_BMP_SAVE_LEGACY_FORMAT, SDL_FALSE);
}
if (surface && (SDL_LockSurface(surface) == 0)) {

View File

@@ -181,7 +181,7 @@ ShouldUseTextureFramebuffer()
/* See if the user or application wants a specific behavior */
hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
if (hint) {
if (*hint == '0') {
if (*hint == '0' || SDL_strcasecmp(hint, "false") == 0) {
return SDL_FALSE;
} else {
return SDL_TRUE;
@@ -258,6 +258,8 @@ SDL_CreateWindowTexture(SDL_VideoDevice *unused, SDL_Window * window, Uint32 * f
/* Check to see if there's a specific driver requested */
if (hint && *hint != '0' && *hint != '1' &&
SDL_strcasecmp(hint, "true") != 0 &&
SDL_strcasecmp(hint, "false") != 0 &&
SDL_strcasecmp(hint, "software") != 0) {
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
SDL_RendererInfo info;
@@ -447,10 +449,8 @@ int
SDL_VideoInit(const char *driver_name)
{
SDL_VideoDevice *video;
const char *hint;
int index;
int i;
SDL_bool allow_screensaver;
/* Check to make sure we don't overwrite '_this' */
if (_this != NULL) {
@@ -538,13 +538,7 @@ SDL_VideoInit(const char *driver_name)
joystick, or passively watching a movie. Things that use SDL but
function more like a normal desktop app should explicitly reenable the
screensaver. */
hint = SDL_GetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER);
if (hint) {
allow_screensaver = SDL_atoi(hint) ? SDL_TRUE : SDL_FALSE;
} else {
allow_screensaver = SDL_FALSE;
}
if (!allow_screensaver) {
if (!SDL_GetHintBoolean(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, SDL_FALSE)) {
SDL_DisableScreenSaver();
}
@@ -1336,7 +1330,6 @@ SDL_Window *
SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
{
SDL_Window *window;
const char *hint;
if (!_this) {
/* Initialize the video system if needed */
@@ -1384,8 +1377,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
* SDL_WINDOW_ALLOW_HIGHDPI flag.
*/
if (flags & SDL_WINDOW_ALLOW_HIGHDPI) {
hint = SDL_GetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED);
if (hint && SDL_atoi(hint) > 0) {
if (SDL_GetHintBoolean(SDL_HINT_VIDEO_HIGHDPI_DISABLED, SDL_FALSE)) {
flags &= ~SDL_WINDOW_ALLOW_HIGHDPI;
}
}
@@ -2509,8 +2501,6 @@ SDL_OnWindowFocusGained(SDL_Window * window)
static SDL_bool
ShouldMinimizeOnFocusLoss(SDL_Window * window)
{
const char *hint;
if (!(window->flags & SDL_WINDOW_FULLSCREEN) || window->is_destroying) {
return SDL_FALSE;
}
@@ -2521,16 +2511,7 @@ ShouldMinimizeOnFocusLoss(SDL_Window * window)
}
#endif
hint = SDL_GetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS);
if (hint) {
if (*hint == '0') {
return SDL_FALSE;
} else {
return SDL_TRUE;
}
}
return SDL_TRUE;
return SDL_GetHintBoolean(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_TRUE);
}
void
@@ -3779,15 +3760,7 @@ SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, S
SDL_bool
SDL_ShouldAllowTopmost(void)
{
const char *hint = SDL_GetHint(SDL_HINT_ALLOW_TOPMOST);
if (hint) {
if (*hint == '0') {
return SDL_FALSE;
} else {
return SDL_TRUE;
}
}
return SDL_TRUE;
return SDL_GetHintBoolean(SDL_HINT_ALLOW_TOPMOST, SDL_TRUE);
}
int

View File

@@ -348,8 +348,7 @@ Cocoa_RegisterApp(void)
[SDLApplication sharedApplication];
SDL_assert(NSApp != nil);
const char *hint = SDL_GetHint(SDL_HINT_MAC_BACKGROUND_APP);
if (!hint || *hint == '0') {
if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
[NSApp activateIgnoringOtherApps:YES];
}

View File

@@ -150,8 +150,7 @@ Cocoa_VideoInit(_THIS)
Cocoa_InitKeyboard(_this);
Cocoa_InitMouse(_this);
const char *hint = SDL_GetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
data->allow_spaces = ( (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && (!hint || (*hint != '0')) );
data->allow_spaces = ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE));
/* The IOPM assertion API can disable the screensaver as of 10.7. */
data->screensaver_use_iopm = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;

View File

@@ -211,8 +211,7 @@ ScheduleContextUpdates(SDL_WindowData *data)
static int
GetHintCtrlClickEmulateRightClick()
{
const char *hint = SDL_GetHint( SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK );
return hint != NULL && *hint != '0';
return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, SDL_FALSE);
}
static NSUInteger
@@ -1118,12 +1117,11 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
{
const char *hint = SDL_GetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH);
if (!hint) {
/* Check older hint for backwards compatibility */
hint = SDL_GetHint("SDL_MAC_MOUSE_FOCUS_CLICKTHROUGH");
if (SDL_GetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH)) {
return SDL_GetHintBoolean(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, SDL_FALSE);
} else {
return SDL_GetHintBoolean("SDL_MAC_MOUSE_FOCUS_CLICKTHROUGH", SDL_FALSE);
}
return hint && *hint != '0';
}
@end

View File

@@ -158,7 +158,7 @@ UIKit_SuspendScreenSaver(_THIS)
@autoreleasepool {
/* Ignore ScreenSaver API calls if the idle timer hint has been set. */
/* FIXME: The idle timer hint should be deprecated for SDL 2.1. */
if (SDL_GetHint(SDL_HINT_IDLE_TIMER_DISABLED) == NULL) {
if (!SDL_GetHintBoolean(SDL_HINT_IDLE_TIMER_DISABLED, SDL_FALSE)) {
UIApplication *app = [UIApplication sharedApplication];
/* Prevent the display from dimming and going to sleep. */

View File

@@ -201,8 +201,7 @@ WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
static SDL_bool
WIN_ShouldIgnoreFocusClick()
{
const char *hint = SDL_GetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH);
return (!hint || (*hint == '0')) ? SDL_TRUE : SDL_FALSE;
return !SDL_GetHintBoolean(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, SDL_FALSE);
}
void
@@ -340,17 +339,7 @@ WIN_ConvertUTF32toUTF8(UINT32 codepoint, char * text)
static SDL_bool
ShouldGenerateWindowCloseOnAltF4(void)
{
const char *hint;
hint = SDL_GetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4);
if (hint) {
if (*hint == '0') {
return SDL_TRUE;
} else {
return SDL_FALSE;
}
}
return SDL_TRUE;
return !SDL_GetHintBoolean(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, SDL_FALSE);
}
LRESULT CALLBACK

View File

@@ -1035,8 +1035,7 @@ X11_DispatchEvent(_THIS)
if (data->last_focus_event_time) {
const int X11_FOCUS_CLICK_TIMEOUT = 10;
if (!SDL_TICKS_PASSED(SDL_GetTicks(), data->last_focus_event_time + X11_FOCUS_CLICK_TIMEOUT)) {
const char *hint = SDL_GetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH);
ignore_click = (!hint || *hint == '0');
ignore_click = !SDL_GetHintBoolean(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, SDL_FALSE);
}
data->last_focus_event_time = 0;
}

View File

@@ -157,14 +157,12 @@ CheckXinerama(Display * display, int *major, int *minor)
{
int event_base = 0;
int error_base = 0;
const char *env;
/* Default the extension not available */
*major = *minor = 0;
/* Allow environment override */
env = SDL_GetHint(SDL_HINT_VIDEO_X11_XINERAMA);
if (env && !SDL_atoi(env)) {
if (!SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XINERAMA, SDL_TRUE)) {
#ifdef X11MODES_DEBUG
printf("Xinerama disabled due to hint\n");
#endif
@@ -213,22 +211,19 @@ X11_XineramaFailed(Display * d, XErrorEvent * e)
static SDL_bool
CheckXRandR(Display * display, int *major, int *minor)
{
const char *env;
/* Default the extension not available */
*major = *minor = 0;
/* Allow environment override */
env = SDL_GetHint(SDL_HINT_VIDEO_X11_XRANDR);
#ifdef XRANDR_DISABLED_BY_DEFAULT
if (!env || !SDL_atoi(env)) {
if (!SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XRANDR, SDL_FALSE)) {
#ifdef X11MODES_DEBUG
printf("XRandR disabled by default due to window manager issues\n");
#endif
return SDL_FALSE;
}
#else
if (env && !SDL_atoi(env)) {
if (!SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XRANDR, SDL_TRUE)) {
#ifdef X11MODES_DEBUG
printf("XRandR disabled due to hint\n");
#endif
@@ -507,14 +502,11 @@ X11_InitModes_XRandR(_THIS)
static SDL_bool
CheckVidMode(Display * display, int *major, int *minor)
{
const char *env;
/* Default the extension not available */
*major = *minor = 0;
/* Allow environment override */
env = SDL_GetHint(SDL_HINT_VIDEO_X11_XVIDMODE);
if (env && !SDL_atoi(env)) {
if (!SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XVIDMODE, SDL_TRUE)) {
#ifdef X11MODES_DEBUG
printf("XVidMode disabled due to hint\n");
#endif
@@ -622,8 +614,7 @@ X11_InitModes(_THIS)
we sort out the ramifications of removing XVidMode support outright.
This block should be removed with the XVidMode support. */
{
const char *env = SDL_GetHint("SDL_VIDEO_X11_REQUIRE_XRANDR");
if (env && SDL_atoi(env)) {
if (SDL_GetHintBoolean("SDL_VIDEO_X11_REQUIRE_XRANDR", SDL_FALSE)) {
#if SDL_VIDEO_DRIVER_X11_XRANDR
return SDL_SetError("XRandR support is required but not available");
#else

View File

@@ -576,14 +576,12 @@ X11_CreateWindow(_THIS, SDL_Window * window)
{
Atom protocols[3];
int proto_count = 0;
const char *ping_hint;
protocols[proto_count++] = data->WM_DELETE_WINDOW; /* Allow window to be deleted by the WM */
protocols[proto_count++] = data->WM_TAKE_FOCUS; /* Since we will want to set input focus explicitly */
ping_hint = SDL_GetHint(SDL_HINT_VIDEO_X11_NET_WM_PING);
/* Default to using ping if there is no hint */
if (!ping_hint || SDL_atoi(ping_hint)) {
if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_NET_WM_PING, SDL_TRUE)) {
protocols[proto_count++] = data->_NET_WM_PING; /* Respond so WM knows we're alive */
}
@@ -1477,7 +1475,6 @@ X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
Display *display = data->videodata->display;
SDL_bool oldstyle_fullscreen;
SDL_bool grab_keyboard;
const char *hint;
/* ICCCM2.0-compliant window managers can handle fullscreen windows
If we're using XVidMode to change resolution we need to confine
@@ -1501,8 +1498,7 @@ X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
X11_XRaiseWindow(display, data->xwindow);
/* Now grab the keyboard */
hint = SDL_GetHint(SDL_HINT_GRAB_KEYBOARD);
if (hint && SDL_atoi(hint)) {
if (SDL_GetHintBoolean(SDL_HINT_GRAB_KEYBOARD, SDL_FALSE)) {
grab_keyboard = SDL_TRUE;
} else {
/* We need to do this with the old style override_redirect