SDL_OpenURL(3)

πŸ’– SDL_OpenURL πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual β€” this is the page for SDL_OpenURL(3), and honestly? she's a little chaotic, but we love her.


✨ NAME ✨

SDL_OpenURL β€” open a URL/URI in the browser or whatever other external app the system thinks is the vibe πŸ¦‹


✨ SYNOPSIS ✨

#include <SDL3/SDL_misc.h>

bool SDL_OpenURL(const char *url);

✨ DESCRIPTION ✨

So the whole point: this opens a URL in a separate, system-provided application. Not in your app, not in a little window you drew yourself β€” in something else, that the OS picks. 🫢

How it actually works? varies wildly depending on the platform. Like, genuinely wildly. It'll likely launch whatever makes sense for that URL's protocol (so a web browser for http://, etc.), but it might also be able to launch file managers for directories and other stuff too. It's giving "we'll see" energy. πŸ’…

And what happens when you open a URL varies wildly as well, so buckle up:

  • Your game window may lose focus β€” and it 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 get paused. bye bestie, brb πŸ‘‹
  • Any given platform may or may not handle a given URL. no promises, no cap.

If this is unimplemented (or simply unavailable) for a platform, it will fail with an error. And here's the tea: a successful result does not mean the URL loaded. It just means we launched _something_ to handle it (or at least we believe we did πŸ™ˆ).

All this to say: this function can be useful, but you should definitely test it on every platform you target. every. single. one. periodt. ⭐


✨ FUNCTION PARAMETERS ✨

  • url β€” a valid URL/URI to open. Use file:///full/path/to/file for local files, if supported. πŸŽ€

✨ RETURN VALUE ✨

Returns true on success or false on failure. πŸ’€ If it's giving failure, call SDL_GetError() for more info β€” she'll tell you what went wrong.


✨ THREAD SAFETY ✨

This function should only be called on the main thread. Do not be out here calling her from a worker thread, bestie, I'm begging. 🧚


✨ AVAILABILITY ✨

This function is available since SDL 3.2.0. 🌸


and that's the whole page, you ate that πŸŽ€

sign-off time: this page comes from Simple Directmedia Layer, sitting at version SDL 3.4.18, dated SDL_OpenURL(3) β€” iykyk πŸ’œ go forth and open some URLs (but test them everywhere, fr fr). πŸ’–βœ¨πŸŒˆπŸ‘‘

πŸ“¦ where this page comes from