SDL2 - Cross-Platform Open URL Command?

Hi,

Working on an older SDL2 game project now.
Is there a cross-platform open URL command?(Windows/macOS/Linux)
Let us know, thanks!

Jesse

1 Like

Look at my implementation for win32, ios, Android
https://bitbucket.org/akk0rd87/akk0rdsdk/src/51649aa987ffae95530df8b01c5137ceb602bb39/framework/core/platforms.h#lines-171

Hi,

I don’t see the actual code that opens a URL?
Also, I need this for Windows/macOS/Linux.
Thanks!

Jesse

#include “ProcInfo/procinfo.h”

// Windows
process_execute(“start “www.google.com””);

//Mac
process_execute("open “www.google.com”);

// Linux
process_execute("xdg-open “www.google.com”);

The repository at that link includes a lot of other useful functions, for example, you can wait for the browser window to open by checking if pids_from_ppid(ppid) does not equal an empty string and recursively convert the string to a process id and check that function again until you get the browser pid, then check that against pid_from_top to get the topmost process, and then get the browser window id from wid_from_top and lastly make the browser a child window (requires converting window handle of the parent window to a window id using wid_from_window()) this allows the browser to stay on top of the game window and works even on mac (figuring this out on mac was a nightmare)

Hi,

We have Windows open URL working:

#ifdef __WIN32__
    #include <windows.h>
    #include <shellapi.h>
#endif
// ...
#ifdef __WIN32__
    ShellExecute(NULL, "open", "http://fallenangelsoftware.com", NULL, NULL, SW_SHOWNORMAL);
#endif

Just need macOS and Linux…

Jesse

Without all the extra fluff its simply

#include <stdlib.h>

system(“commands in my previous post”)

Got it working, thanks!

Jesse