Skip to content

Commit

Permalink
Removed SDL_AndroidOpenURL, added SDL_OpenURL.
Browse files Browse the repository at this point in the history
Still needs to be wired into Xcode and Visual Studio projects.
  • Loading branch information
icculus committed Oct 5, 2020
1 parent a70bb58 commit 77c9d73
Show file tree
Hide file tree
Showing 22 changed files with 517 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Android.mk
Expand Up @@ -37,6 +37,8 @@ LOCAL_SRC_FILES := \
$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c) \
$(wildcard $(LOCAL_PATH)/src/locale/*.c) \
$(wildcard $(LOCAL_PATH)/src/locale/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/misc/*.c) \
$(wildcard $(LOCAL_PATH)/src/misc/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/power/*.c) \
$(wildcard $(LOCAL_PATH)/src/power/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/filesystem/android/*.c) \
Expand Down
26 changes: 26 additions & 0 deletions CMakeLists.txt
Expand Up @@ -407,6 +407,7 @@ file(GLOB SOURCE_FILES
${SDL2_SOURCE_DIR}/src/haptic/*.c
${SDL2_SOURCE_DIR}/src/libm/*.c
${SDL2_SOURCE_DIR}/src/locale/*.c
${SDL2_SOURCE_DIR}/src/misc/*.c
${SDL2_SOURCE_DIR}/src/power/*.c
${SDL2_SOURCE_DIR}/src/render/*.c
${SDL2_SOURCE_DIR}/src/render/*/*.c
Expand Down Expand Up @@ -941,6 +942,10 @@ if(ANDROID)
file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES} ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)

file(GLOB ANDROID_MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/android/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_MISC_SOURCES})
set(HAVE_SDL_MISC TRUE)

# SDL_spinlock.c Needs to be compiled in ARM mode.
# There seems to be no better way currently to set the ARM mode.
# see: https://issuetracker.google.com/issues/62264618
Expand Down Expand Up @@ -1301,6 +1306,10 @@ elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
endif()

file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/unix/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${MISC_SOURCES})
set(HAVE_SDL_MISC TRUE)

if(SDL_POWER)
if(LINUX)
set(SDL_POWER_LINUX 1)
Expand Down Expand Up @@ -1366,6 +1375,10 @@ elseif(WINDOWS)
endif()
endif()

file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/windows/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${MISC_SOURCES})
set(HAVE_SDL_MISC TRUE)

# Check for DirectX
if(DIRECTX)
if(DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700)
Expand Down Expand Up @@ -1606,6 +1619,10 @@ elseif(APPLE)
message_error("SDL_FILE must be enabled to build on MacOS X")
endif()

file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/macosx/*.m)
set(SOURCE_FILES ${SOURCE_FILES} ${MISC_SOURCES})
set(HAVE_SDL_MISC TRUE)

if(SDL_AUDIO)
set(SDL_AUDIO_DRIVER_COREAUDIO 1)
file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.m)
Expand Down Expand Up @@ -1860,6 +1877,10 @@ elseif(APPLE)
CheckPTHREAD()

elseif(HAIKU)
file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/haiku/*.cc)
set(SOURCE_FILES ${SOURCE_FILES} ${MISC_SOURCES})
set(HAVE_SDL_MISC TRUE)

if(SDL_VIDEO)
set(SDL_VIDEO_DRIVER_HAIKU 1)
file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
Expand Down Expand Up @@ -1961,6 +1982,11 @@ if(NOT HAVE_SDL_LOCALE)
file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/dummy/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
endif()
if(NOT HAVE_SDL_MISC)
set(SDL_MISC_DISABLED 1)
file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/misc/dummy/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
endif()

# We always need to have threads and timers around
if(NOT HAVE_SDL_THREADS)
Expand Down
1 change: 1 addition & 0 deletions Makefile.in
Expand Up @@ -87,6 +87,7 @@ HDRS = \
SDL_main.h \
SDL_messagebox.h \
SDL_metal.h \
SDL_misc.h \
SDL_mouse.h \
SDL_mutex.h \
SDL_name.h \
Expand Down
19 changes: 19 additions & 0 deletions configure
Expand Up @@ -17313,6 +17313,7 @@ SOURCES="$SOURCES $srcdir/src/file/*.c"
SOURCES="$SOURCES $srcdir/src/haptic/*.c"
SOURCES="$SOURCES $srcdir/src/joystick/*.c"
SOURCES="$SOURCES $srcdir/src/libm/*.c"
SOURCES="$SOURCES $srcdir/src/misc/*.c"
SOURCES="$SOURCES $srcdir/src/power/*.c"
#SOURCES="$SOURCES $srcdir/src/filesystem/*.c"
SOURCES="$SOURCES $srcdir/src/render/*.c"
Expand Down Expand Up @@ -24685,6 +24686,9 @@ case "$host" in
CheckRPATH
CheckVivanteVideo

SOURCES="$SOURCES $srcdir/src/misc/unix/*.c"
have_misc=yes

SOURCES="$SOURCES $srcdir/src/locale/unix/*.c"
have_locale=yes

Expand Down Expand Up @@ -24865,6 +24869,9 @@ $as_echo "#define SDL_TIMER_UNIX 1" >>confdefs.h
# Set up the core platform files
SOURCES="$SOURCES $srcdir/src/core/windows/*.c"

SOURCES="$SOURCES $srcdir/src/misc/windows/*.c"
have_misc=yes

# Use the Windows locale APIs.
SOURCES="$SOURCES $srcdir/src/locale/windows/*.c"
have_locale=yes
Expand Down Expand Up @@ -25121,6 +25128,9 @@ $as_echo "#define SDL_FILESYSTEM_HAIKU 1" >>confdefs.h
have_filesystem=yes
fi

SOURCES="$SOURCES $srcdir/src/misc/haiku/*.cc"
have_misc=yes

# Set up files for the locale library
SOURCES="$SOURCES $srcdir/src/locale/haiku/*.cc"
have_locale=yes
Expand Down Expand Up @@ -25167,6 +25177,9 @@ fi
CheckVulkan
CheckPTHREAD

SOURCES="$SOURCES $srcdir/src/misc/ios/*.m"
have_misc=yes

# Set up files for the locale library
SOURCES="$SOURCES $srcdir/src/locale/macosx/*.m"
have_locale=yes
Expand Down Expand Up @@ -25295,6 +25308,9 @@ $as_echo "#define SDL_VIDEO_RENDER_OGL_ES2 1" >>confdefs.h
CheckPTHREAD
CheckHIDAPI

SOURCES="$SOURCES $srcdir/src/misc/macosx/*.m"
have_misc=yes

# Set up files for the locale library
SOURCES="$SOURCES $srcdir/src/locale/macosx/*.m"
have_locale=yes
Expand Down Expand Up @@ -25514,6 +25530,9 @@ INSTALL_SDL2_CONFIG=$enable_sdl2_config

# Verify that we have all the platform specific files we need

if test x$have_misc != xyes; then
SOURCES="$SOURCES $srcdir/src/misc/dummy/*.c"
fi
if test x$have_locale != xyes; then
SOURCES="$SOURCES $srcdir/src/locale/dummy/*.c"
fi
Expand Down
19 changes: 19 additions & 0 deletions configure.ac
Expand Up @@ -413,6 +413,7 @@ SOURCES="$SOURCES $srcdir/src/file/*.c"
SOURCES="$SOURCES $srcdir/src/haptic/*.c"
SOURCES="$SOURCES $srcdir/src/joystick/*.c"
SOURCES="$SOURCES $srcdir/src/libm/*.c"
SOURCES="$SOURCES $srcdir/src/misc/*.c"
SOURCES="$SOURCES $srcdir/src/power/*.c"
#SOURCES="$SOURCES $srcdir/src/filesystem/*.c"
SOURCES="$SOURCES $srcdir/src/render/*.c"
Expand Down Expand Up @@ -3533,6 +3534,9 @@ case "$host" in
CheckRPATH
CheckVivanteVideo

SOURCES="$SOURCES $srcdir/src/misc/unix/*.c"
have_misc=yes

SOURCES="$SOURCES $srcdir/src/locale/unix/*.c"
have_locale=yes

Expand Down Expand Up @@ -3685,6 +3689,9 @@ case "$host" in
# Set up the core platform files
SOURCES="$SOURCES $srcdir/src/core/windows/*.c"

SOURCES="$SOURCES $srcdir/src/misc/windows/*.c"
have_misc=yes

# Use the Windows locale APIs.
SOURCES="$SOURCES $srcdir/src/locale/windows/*.c"
have_locale=yes
Expand Down Expand Up @@ -3861,6 +3868,9 @@ AS_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
have_filesystem=yes
fi

SOURCES="$SOURCES $srcdir/src/misc/haiku/*.cc"
have_misc=yes

# Set up files for the locale library
SOURCES="$SOURCES $srcdir/src/locale/haiku/*.cc"
have_locale=yes
Expand All @@ -3885,6 +3895,9 @@ AS_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
CheckVulkan
CheckPTHREAD

SOURCES="$SOURCES $srcdir/src/misc/ios/*.m"
have_misc=yes

# Set up files for the locale library
SOURCES="$SOURCES $srcdir/src/locale/macosx/*.m"
have_locale=yes
Expand Down Expand Up @@ -3991,6 +4004,9 @@ AS_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
CheckPTHREAD
CheckHIDAPI

SOURCES="$SOURCES $srcdir/src/misc/macosx/*.m"
have_misc=yes

# Set up files for the locale library
SOURCES="$SOURCES $srcdir/src/locale/macosx/*.m"
have_locale=yes
Expand Down Expand Up @@ -4173,6 +4189,9 @@ AC_SUBST([INSTALL_SDL2_CONFIG], [$enable_sdl2_config])

# Verify that we have all the platform specific files we need

if test x$have_misc != xyes; then
SOURCES="$SOURCES $srcdir/src/misc/dummy/*.c"
fi
if test x$have_locale != xyes; then
SOURCES="$SOURCES $srcdir/src/locale/dummy/*.c"
fi
Expand Down
1 change: 1 addition & 0 deletions include/SDL.h
Expand Up @@ -60,6 +60,7 @@
#include "SDL_version.h"
#include "SDL_video.h"
#include "SDL_locale.h"
#include "SDL_misc.h"

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
Expand Down
75 changes: 75 additions & 0 deletions include/SDL_misc.h
@@ -0,0 +1,75 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
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.
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:
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.
*/

/**
* \file SDL_misc.h
*
* \brief Include file for SDL API functions that don't fit elsewhere.
*/

#ifndef SDL_misc_h_
#define SDL_misc_h_

#include "SDL_stdinc.h"

#include "begin_code.h"

/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif

/**
* \brief Open an URL / URI in the browser or other
*
* Open a URL in a separate, system-provided application. How this works will
* vary wildly depending on the platform. This will likely launch what
* makes sense to handle a specific URL's protocol (a web browser for http://,
* etc), but it might also be able to launch file managers for directories
* and other things.
*
* What happens when you open a URL varies wildly as well: your game window
* may lose focus (and may or may not lose focus if your game was fullscreen
* or grabbing input at the time). On mobile devices, your app will likely
* move to the background or your process might be paused. Any given platform
* may or may not handle a given URL.
*
* If this is unimplemented (or simply unavailable) for a platform, this will
* fail with an error. A successful result does not mean the URL loaded, just
* that we launched something to handle it (or at least believe we did).
*
* All this to say: this function can be useful, but you should definitely
* test it on every platform you target.
*
* \param url A valid URL to open.
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_OpenURL(const char *url);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include "close_code.h"

#endif /* SDL_filesystem_h_ */

/* vi: set ts=4 sw=4 expandtab: */
7 changes: 0 additions & 7 deletions include/SDL_system.h
Expand Up @@ -206,13 +206,6 @@ extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath(void);
*/
extern DECLSPEC SDL_bool SDLCALL SDL_AndroidRequestPermission(const char *permission);

/**
\brief Open an URL / URI in the browser or other
\return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_AndroidOpenURL(const char *url);

#endif /* __ANDROID__ */

/* Platform specific functions for WinRT */
Expand Down
13 changes: 0 additions & 13 deletions src/core/android/SDL_android.c
Expand Up @@ -2469,19 +2469,6 @@ SDL_bool SDL_AndroidRequestPermission(const char *permission)
return Android_JNI_RequestPermission(permission);
}

int SDL_AndroidOpenURL(const char *url)
{
JNIEnv *env = Android_JNI_GetEnv();
int ret = -1;

if (url) {
jstring jurl = (*env)->NewStringUTF(env, url);
ret = (*env)->CallStaticIntMethod(env, mActivityClass, midOpenURL, jurl);
(*env)->DeleteLocalRef(env, jurl);
}
return ret;
}

void Android_JNI_GetManifestEnvironmentVariables(void)
{
if (!mActivityClass || !midGetManifestEnvironmentVariables) {
Expand Down
2 changes: 1 addition & 1 deletion src/dynapi/SDL_dynapi_overrides.h
Expand Up @@ -766,4 +766,4 @@
#define SDL_truncf SDL_truncf_REAL
#define SDL_GetPreferredLocales SDL_GetPreferredLocales_REAL
#define SDL_AndroidRequestPermission SDL_AndroidRequestPermission_REAL
#define SDL_AndroidOpenURL SDL_AndroidOpenURL_REAL
#define SDL_OpenURL SDL_OpenURL_REAL
2 changes: 1 addition & 1 deletion src/dynapi/SDL_dynapi_procs.h
Expand Up @@ -826,5 +826,5 @@ SDL_DYNAPI_PROC(float,SDL_truncf,(float a),(a),return)
SDL_DYNAPI_PROC(SDL_Locale *,SDL_GetPreferredLocales,(void),(),return)
#ifdef __ANDROID__
SDL_DYNAPI_PROC(SDL_bool,SDL_AndroidRequestPermission,(const char *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_AndroidOpenURL,(const char *a),(a),return)
#endif
SDL_DYNAPI_PROC(int,SDL_OpenURL,(const char *a),(a),return)
36 changes: 36 additions & 0 deletions src/misc/SDL_url.c
@@ -0,0 +1,36 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
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.
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:
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.
*/

#include "../../SDL_internal.h"
#include "SDL_error.h"

extern int SDL_SYS_OpenURL(const char *url);

int
SDL_OpenURL(const char *url)
{
if (!url) {
return SDL_InvalidParamError("url");
}
return SDL_SYS_OpenURL(url);
}

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit 77c9d73

Please sign in to comment.