Merge commit '411251c6242b04119edc41ce83f09f0714e2d32b' as 'external/SDL'
This commit is contained in:
Vendored
+119
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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_libusb.h"
|
||||
|
||||
#ifdef HAVE_LIBUSB
|
||||
|
||||
#ifdef SDL_LIBUSB_DYNAMIC
|
||||
SDL_ELF_NOTE_DLOPEN(
|
||||
"libusb",
|
||||
"Support for joysticks through libusb",
|
||||
SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
|
||||
SDL_LIBUSB_DYNAMIC
|
||||
)
|
||||
#endif
|
||||
|
||||
static SDL_AtomicInt SDL_libusb_refcount;
|
||||
static bool SDL_libusb_loaded;
|
||||
static SDL_SharedObject *SDL_libusb_handle;
|
||||
static SDL_LibUSBContext SDL_libusb_context;
|
||||
|
||||
bool SDL_InitLibUSB(SDL_LibUSBContext **ctx)
|
||||
{
|
||||
if (SDL_AtomicIncRef(&SDL_libusb_refcount) == 0) {
|
||||
#ifdef SDL_LIBUSB_DYNAMIC
|
||||
SDL_libusb_handle = SDL_LoadObject(SDL_LIBUSB_DYNAMIC);
|
||||
if (SDL_libusb_handle)
|
||||
#endif
|
||||
{
|
||||
SDL_libusb_loaded = true;
|
||||
#ifdef SDL_LIBUSB_DYNAMIC
|
||||
#define LOAD_LIBUSB_SYMBOL(type, func) \
|
||||
if ((SDL_libusb_context.func = (type)SDL_LoadFunction(SDL_libusb_handle, "libusb_" #func)) == NULL) { \
|
||||
SDL_libusb_loaded = false; \
|
||||
}
|
||||
#else
|
||||
#define LOAD_LIBUSB_SYMBOL(type, func) \
|
||||
SDL_libusb_context.func = libusb_##func;
|
||||
#endif
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_context **), init)
|
||||
LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(libusb_context *), exit)
|
||||
LOAD_LIBUSB_SYMBOL(ssize_t (LIBUSB_CALL *)(libusb_context *, libusb_device ***), get_device_list)
|
||||
LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(libusb_device **, int), free_device_list)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *, struct libusb_device_descriptor *), get_device_descriptor)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *, struct libusb_config_descriptor **), get_active_config_descriptor)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *, uint8_t, struct libusb_config_descriptor **), get_config_descriptor)
|
||||
LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(struct libusb_config_descriptor *), free_config_descriptor)
|
||||
LOAD_LIBUSB_SYMBOL(uint8_t (LIBUSB_CALL *)(libusb_device *), get_bus_number)
|
||||
#ifdef SDL_PLATFORM_FREEBSD
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *dev, uint8_t *port_numbers, uint8_t port_numbers_len), get_port_numbers)
|
||||
#else
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *dev, uint8_t *port_numbers, int port_numbers_len), get_port_numbers)
|
||||
#endif
|
||||
LOAD_LIBUSB_SYMBOL(uint8_t (LIBUSB_CALL *)(libusb_device *), get_device_address)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device *, libusb_device_handle **), open)
|
||||
LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(libusb_device_handle *), close)
|
||||
LOAD_LIBUSB_SYMBOL(libusb_device * (LIBUSB_CALL *)(libusb_device_handle *dev_handle), get_device)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), claim_interface)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), release_interface)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), kernel_driver_active)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), detach_kernel_driver)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), attach_kernel_driver)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), set_auto_detach_kernel_driver)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int, int), set_interface_alt_setting)
|
||||
LOAD_LIBUSB_SYMBOL(struct libusb_transfer * (LIBUSB_CALL *)(int), alloc_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(struct libusb_transfer *), submit_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(struct libusb_transfer *), cancel_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(void (LIBUSB_CALL *)(struct libusb_transfer *), free_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, uint8_t, uint8_t, uint16_t, uint16_t, unsigned char *, uint16_t, unsigned int), control_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, unsigned char, unsigned char *, int, int *, unsigned int), interrupt_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, unsigned char, unsigned char *, int, int *, unsigned int), bulk_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_context *), handle_events)
|
||||
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_context *, int *), handle_events_completed)
|
||||
LOAD_LIBUSB_SYMBOL(const char * (LIBUSB_CALL *)(int), error_name)
|
||||
#undef LOAD_LIBUSB_SYMBOL
|
||||
}
|
||||
}
|
||||
|
||||
if (SDL_libusb_loaded) {
|
||||
*ctx = &SDL_libusb_context;
|
||||
return true;
|
||||
} else {
|
||||
SDL_QuitLibUSB();
|
||||
*ctx = NULL;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_QuitLibUSB(void)
|
||||
{
|
||||
if (SDL_AtomicDecRef(&SDL_libusb_refcount)) {
|
||||
if (SDL_libusb_handle) {
|
||||
SDL_UnloadObject(SDL_libusb_handle);
|
||||
SDL_libusb_handle = NULL;
|
||||
}
|
||||
SDL_libusb_loaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_LIBUSB
|
||||
Vendored
+102
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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"
|
||||
|
||||
#ifdef HAVE_LIBUSB
|
||||
// libusb HIDAPI Implementation
|
||||
|
||||
// Include this now, for our dynamically-loaded libusb context
|
||||
#include <libusb.h>
|
||||
|
||||
typedef struct SDL_LibUSBContext
|
||||
{
|
||||
/* *INDENT-OFF* */ // clang-format off
|
||||
int (LIBUSB_CALL *init)(libusb_context **ctx);
|
||||
void (LIBUSB_CALL *exit)(libusb_context *ctx);
|
||||
ssize_t (LIBUSB_CALL *get_device_list)(libusb_context *ctx, libusb_device ***list);
|
||||
void (LIBUSB_CALL *free_device_list)(libusb_device **list, int unref_devices);
|
||||
int (LIBUSB_CALL *get_device_descriptor)(libusb_device *dev, struct libusb_device_descriptor *desc);
|
||||
int (LIBUSB_CALL *get_active_config_descriptor)(libusb_device *dev, struct libusb_config_descriptor **config);
|
||||
int (LIBUSB_CALL *get_config_descriptor)(
|
||||
libusb_device *dev,
|
||||
uint8_t config_index,
|
||||
struct libusb_config_descriptor **config
|
||||
);
|
||||
void (LIBUSB_CALL *free_config_descriptor)(struct libusb_config_descriptor *config);
|
||||
uint8_t (LIBUSB_CALL *get_bus_number)(libusb_device *dev);
|
||||
#ifdef SDL_PLATFORM_FREEBSD
|
||||
int (LIBUSB_CALL *get_port_numbers)(libusb_device *dev, uint8_t *port_numbers, uint8_t port_numbers_len);
|
||||
#else
|
||||
int (LIBUSB_CALL *get_port_numbers)(libusb_device *dev, uint8_t *port_numbers, int port_numbers_len);
|
||||
#endif
|
||||
uint8_t (LIBUSB_CALL *get_device_address)(libusb_device *dev);
|
||||
int (LIBUSB_CALL *open)(libusb_device *dev, libusb_device_handle **dev_handle);
|
||||
void (LIBUSB_CALL *close)(libusb_device_handle *dev_handle);
|
||||
libusb_device *(LIBUSB_CALL *get_device)(libusb_device_handle *dev_handle);
|
||||
int (LIBUSB_CALL *claim_interface)(libusb_device_handle *dev_handle, int interface_number);
|
||||
int (LIBUSB_CALL *release_interface)(libusb_device_handle *dev_handle, int interface_number);
|
||||
int (LIBUSB_CALL *kernel_driver_active)(libusb_device_handle *dev_handle, int interface_number);
|
||||
int (LIBUSB_CALL *detach_kernel_driver)(libusb_device_handle *dev_handle, int interface_number);
|
||||
int (LIBUSB_CALL *attach_kernel_driver)(libusb_device_handle *dev_handle, int interface_number);
|
||||
int (LIBUSB_CALL *set_auto_detach_kernel_driver)(libusb_device_handle *dev_handle, int enable);
|
||||
int (LIBUSB_CALL *set_interface_alt_setting)(libusb_device_handle *dev, int interface_number, int alternate_setting);
|
||||
struct libusb_transfer * (LIBUSB_CALL *alloc_transfer)(int iso_packets);
|
||||
int (LIBUSB_CALL *submit_transfer)(struct libusb_transfer *transfer);
|
||||
int (LIBUSB_CALL *cancel_transfer)(struct libusb_transfer *transfer);
|
||||
void (LIBUSB_CALL *free_transfer)(struct libusb_transfer *transfer);
|
||||
int (LIBUSB_CALL *control_transfer)(
|
||||
libusb_device_handle *dev_handle,
|
||||
uint8_t request_type,
|
||||
uint8_t bRequest,
|
||||
uint16_t wValue,
|
||||
uint16_t wIndex,
|
||||
unsigned char *data,
|
||||
uint16_t wLength,
|
||||
unsigned int timeout
|
||||
);
|
||||
int (LIBUSB_CALL *interrupt_transfer)(
|
||||
libusb_device_handle *dev_handle,
|
||||
unsigned char endpoint,
|
||||
unsigned char *data,
|
||||
int length,
|
||||
int *actual_length,
|
||||
unsigned int timeout
|
||||
);
|
||||
int (LIBUSB_CALL *bulk_transfer)(
|
||||
libusb_device_handle *dev_handle,
|
||||
unsigned char endpoint,
|
||||
unsigned char *data,
|
||||
int length,
|
||||
int *transferred,
|
||||
unsigned int timeout
|
||||
);
|
||||
int (LIBUSB_CALL *handle_events)(libusb_context *ctx);
|
||||
int (LIBUSB_CALL *handle_events_completed)(libusb_context *ctx, int *completed);
|
||||
const char * (LIBUSB_CALL *error_name)(int errcode);
|
||||
/* *INDENT-ON* */ // clang-format on
|
||||
|
||||
} SDL_LibUSBContext;
|
||||
|
||||
extern bool SDL_InitLibUSB(SDL_LibUSBContext **ctx);
|
||||
extern void SDL_QuitLibUSB(void);
|
||||
|
||||
#endif // HAVE_LIBUSB
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern bool SDL_SYS_OpenURL(const char *url);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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_sysurl.h"
|
||||
|
||||
bool SDL_OpenURL(const char *url)
|
||||
{
|
||||
CHECK_PARAM(!url) {
|
||||
return SDL_InvalidParamError("url");
|
||||
}
|
||||
return SDL_SYS_OpenURL(url);
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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_sysurl.h"
|
||||
#include "../../core/android/SDL_android.h"
|
||||
|
||||
bool SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
return Android_JNI_OpenURL(url);
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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_sysurl.h"
|
||||
|
||||
bool SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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_sysurl.h"
|
||||
|
||||
#include <emscripten/emscripten.h>
|
||||
|
||||
EM_JS_DEPS(sdlsysurl, "$UTF8ToString");
|
||||
|
||||
bool SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
EM_ASM(window.open(UTF8ToString($0), "_blank"), url);
|
||||
return true;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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_sysurl.h"
|
||||
#include <Url.h>
|
||||
|
||||
bool SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
#if B_BEOS_VERSION <= B_HAIKU_VERSION_1_BETA_5
|
||||
BUrl burl(url);
|
||||
#else
|
||||
BUrl burl(url, true);
|
||||
#endif
|
||||
const status_t rc = burl.OpenWithPreferredApplication(false);
|
||||
if (rc != B_NO_ERROR) {
|
||||
return SDL_SetError("URL open failed (err=%d)", (int)rc);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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"
|
||||
|
||||
#if defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS)
|
||||
|
||||
#include "../SDL_sysurl.h"
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
bool SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSString *nsstr = [NSString stringWithUTF8String:url];
|
||||
NSURL *nsurl = [NSURL URLWithString:nsstr];
|
||||
if (![[UIApplication sharedApplication] canOpenURL:nsurl]) {
|
||||
return SDL_SetError("No handler registered for this type of URL");
|
||||
}
|
||||
[[UIApplication sharedApplication] openURL:nsurl options:@{} completionHandler:^(BOOL success) {}];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SDL_PLATFORM_IOS || SDL_PLATFORM_TVOS
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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"
|
||||
|
||||
#if defined(SDL_PLATFORM_MACOS)
|
||||
|
||||
#include "../SDL_sysurl.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
bool SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
@autoreleasepool {
|
||||
CFURLRef cfurl = CFURLCreateWithBytes(NULL, (const UInt8 *)url, SDL_strlen(url), kCFStringEncodingUTF8, NULL);
|
||||
OSStatus status = LSOpenCFURLRef(cfurl, NULL);
|
||||
CFRelease(cfurl);
|
||||
if (status != noErr) {
|
||||
return SDL_SetError("LSOpenCFURLRef() failed: %d", status);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SDL_PLATFORM_MACOS
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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_sysurl.h"
|
||||
|
||||
#include <kernel.h>
|
||||
#include <swis.h>
|
||||
|
||||
#ifndef URI_Dispatch
|
||||
#define URI_Dispatch 0x4e381
|
||||
#endif
|
||||
|
||||
bool SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
_kernel_swi_regs regs;
|
||||
_kernel_oserror *error;
|
||||
|
||||
regs.r[0] = 0;
|
||||
regs.r[1] = (int)url;
|
||||
regs.r[2] = 0;
|
||||
error = _kernel_swi(URI_Dispatch, ®s, ®s);
|
||||
if (error) {
|
||||
return SDL_SetError("Couldn't open given URL: %s", error->errmess);
|
||||
}
|
||||
|
||||
if (regs.r[0] & 1) {
|
||||
return SDL_SetError("Couldn't open given URL.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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_sysurl.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <errno.h>
|
||||
#ifdef USE_POSIX_SPAWN
|
||||
#include <spawn.h>
|
||||
extern char **environ;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DBUS_DBUS_H
|
||||
#include "../../core/linux/SDL_dbus.h"
|
||||
#endif
|
||||
|
||||
#ifdef SDL_VIDEO_DRIVER_WAYLAND
|
||||
#include "../../video/wayland/SDL_waylandutil.h"
|
||||
#endif
|
||||
|
||||
// Wayland requires an activation token for the browser to take focus.
|
||||
static void GetActivationToken(char **token, char **window_id)
|
||||
{
|
||||
#ifdef SDL_VIDEO_DRIVER_WAYLAND
|
||||
SDL_VideoDevice *vid = SDL_GetVideoDevice();
|
||||
|
||||
if (vid && SDL_strcmp(vid->name, "wayland") == 0) {
|
||||
Wayland_GetActivationTokenForExport(vid, token, window_id);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
char *activation_token = NULL;
|
||||
char *window_id = NULL;
|
||||
|
||||
GetActivationToken(&activation_token, &window_id);
|
||||
|
||||
// Prefer the D-Bus portal, if available.
|
||||
#ifdef HAVE_DBUS_DBUS_H
|
||||
if (SDL_DBus_OpenURI(url, window_id, activation_token)) {
|
||||
SDL_free(activation_token);
|
||||
SDL_free(window_id);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
const char *args[] = { "xdg-open", url, NULL };
|
||||
SDL_Environment *env = NULL;
|
||||
SDL_Process *process = NULL;
|
||||
bool result = false;
|
||||
|
||||
env = SDL_CreateEnvironment(true);
|
||||
if (!env) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
// Clear LD_PRELOAD so Chrome opens correctly when this application is launched by Steam
|
||||
SDL_UnsetEnvironmentVariable(env, "LD_PRELOAD");
|
||||
if (activation_token) {
|
||||
SDL_SetEnvironmentVariable(env, "XDG_ACTIVATION_TOKEN", activation_token, false);
|
||||
}
|
||||
|
||||
SDL_PropertiesID props = SDL_CreateProperties();
|
||||
if (!props) {
|
||||
goto done;
|
||||
}
|
||||
SDL_SetPointerProperty(props, SDL_PROP_PROCESS_CREATE_ARGS_POINTER, args);
|
||||
SDL_SetPointerProperty(props, SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER, env);
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_PROCESS_CREATE_BACKGROUND_BOOLEAN, true);
|
||||
process = SDL_CreateProcessWithProperties(props);
|
||||
SDL_DestroyProperties(props);
|
||||
if (!process) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = true;
|
||||
|
||||
done:
|
||||
SDL_free(activation_token);
|
||||
SDL_free(window_id);
|
||||
SDL_DestroyEnvironment(env);
|
||||
SDL_DestroyProcess(process);
|
||||
|
||||
return result;
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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_sysurl.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <psp2/apputil.h>
|
||||
|
||||
bool SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
SceAppUtilInitParam init_param;
|
||||
SceAppUtilBootParam boot_param;
|
||||
SceAppUtilWebBrowserParam browser_param;
|
||||
SDL_zero(init_param);
|
||||
SDL_zero(boot_param);
|
||||
sceAppUtilInit(&init_param, &boot_param);
|
||||
SDL_zero(browser_param);
|
||||
browser_param.str = url;
|
||||
browser_param.strlen = SDL_strlen(url);
|
||||
sceAppUtilLaunchWebBrowser(&browser_param);
|
||||
return true;
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2026 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_sysurl.h"
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
|
||||
#include <shellapi.h>
|
||||
|
||||
#if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
|
||||
bool SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
// Not supported
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
#else
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx
|
||||
bool SDL_SYS_OpenURL(const char *url)
|
||||
{
|
||||
WCHAR *wurl;
|
||||
HINSTANCE rc;
|
||||
|
||||
// MSDN says for safety's sake, make sure COM is initialized.
|
||||
const HRESULT hr = WIN_CoInitialize();
|
||||
if (FAILED(hr)) {
|
||||
return WIN_SetErrorFromHRESULT("CoInitialize failed", hr);
|
||||
}
|
||||
|
||||
wurl = WIN_UTF8ToStringW(url);
|
||||
if (!wurl) {
|
||||
WIN_CoUninitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Success returns value greater than 32. Less is an error.
|
||||
rc = ShellExecuteW(NULL, L"open", wurl, NULL, NULL, SW_SHOWNORMAL);
|
||||
SDL_free(wurl);
|
||||
WIN_CoUninitialize();
|
||||
if (rc <= ((HINSTANCE)32)) {
|
||||
return WIN_SetError("Couldn't open given URL.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user