From dfe79052d2adaafc4ac3297f36953a2bb1d288cf Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Wed, 24 Feb 2021 22:26:56 +0000 Subject: [PATCH] SDL: Add implementation of OSystem::openUrl for SDL 2.0.14 --- backends/platform/sdl/posix/posix.cpp | 10 ++-------- backends/platform/sdl/posix/posix.h | 8 ++++++-- backends/platform/sdl/sdl.cpp | 14 ++++++++++++++ backends/platform/sdl/sdl.h | 4 ++++ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp index 1af55bcd6bd..8577e926ebb 100644 --- a/backends/platform/sdl/posix/posix.cpp +++ b/backends/platform/sdl/posix/posix.cpp @@ -357,8 +357,8 @@ bool OSystem_POSIX::displayLogFile() { return WIFEXITED(status) && WEXITSTATUS(status) == 0; } -bool OSystem_POSIX::openUrl(const Common::String &url) { #ifdef HAS_POSIX_SPAWN +bool OSystem_POSIX::openUrl(const Common::String &url) { // inspired by Qt's "qdesktopservices_x11.cpp" // try "standards" @@ -393,13 +393,9 @@ bool OSystem_POSIX::openUrl(const Common::String &url) { warning("openUrl() (POSIX) failed to open URL"); return false; -#else - return false; -#endif } bool OSystem_POSIX::launchBrowser(const Common::String &client, const Common::String &url) { -#ifdef HAS_POSIX_SPAWN pid_t pid; const char *argv[] = { client.c_str(), @@ -415,10 +411,8 @@ bool OSystem_POSIX::launchBrowser(const Common::String &client, const Common::St return false; } return (waitpid(pid, NULL, WNOHANG) != -1); -#else - return false; -#endif } +#endif AudioCDManager *OSystem_POSIX::createAudioCDManager() { #ifdef USE_LINUXCD diff --git a/backends/platform/sdl/posix/posix.h b/backends/platform/sdl/posix/posix.h index af4763e4d74..f2a00b29224 100644 --- a/backends/platform/sdl/posix/posix.h +++ b/backends/platform/sdl/posix/posix.h @@ -31,8 +31,6 @@ public: virtual bool displayLogFile() override; - virtual bool openUrl(const Common::String &url) override; - virtual void init() override; virtual void initBackend() override; @@ -48,7 +46,13 @@ protected: virtual AudioCDManager *createAudioCDManager() override; +#ifdef HAS_POSIX_SPAWN +public: + virtual bool openUrl(const Common::String &url) override; + +protected: bool launchBrowser(const Common::String& client, const Common::String &url); +#endif }; #endif diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index df64d8cf02b..ff3795941cc 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -182,6 +182,9 @@ void OSystem_SDL::init() { bool OSystem_SDL::hasFeature(Feature f) { #if SDL_VERSION_ATLEAST(2, 0, 0) if (f == kFeatureClipboardSupport) return true; +#endif +#if SDL_VERSION_ATLEAST(2, 0, 14) + if (f == kFeatureOpenUrl) return true; #endif if (f == kFeatureJoystickDeadzone || f == kFeatureKbdMouseSpeed) { return _eventSource->isJoystickConnected(); @@ -614,6 +617,17 @@ bool OSystem_SDL::setTextInClipboard(const Common::U32String &text) { } #endif +#if SDL_VERSION_ATLEAST(2, 0, 14) +bool OSystem_SDL::openUrl(const Common::String &url) { + if (SDL_OpenURL(url.c_str()) != 0) { + warning("Failed to open URL: %s", SDL_GetError()); + return false; + } + + return true; +} +#endif + uint32 OSystem_SDL::getMillis(bool skipRecord) { uint32 millis = SDL_GetTicks(); diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 125d26f89dd..7eb7d8ba73b 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -75,6 +75,10 @@ public: virtual bool setTextInClipboard(const Common::U32String &text) override; #endif +#if SDL_VERSION_ATLEAST(2, 0, 14) + virtual bool openUrl(const Common::String &url) override; +#endif + virtual void setWindowCaption(const Common::U32String &caption) override; virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override; virtual uint32 getMillis(bool skipRecord = false) override;