Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL: Add implementation of OSystem::openUrl for SDL 2.0.14 #2801

Merged
merged 1 commit into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions backends/platform/sdl/posix/posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions backends/platform/sdl/posix/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class OSystem_POSIX : public OSystem_SDL {

virtual bool displayLogFile() override;

virtual bool openUrl(const Common::String &url) override;

virtual void init() override;
virtual void initBackend() override;

Expand All @@ -48,7 +46,13 @@ class OSystem_POSIX : public OSystem_SDL {

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
14 changes: 14 additions & 0 deletions backends/platform/sdl/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 4 additions & 0 deletions backends/platform/sdl/sdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class OSystem_SDL : public ModularMutexBackend, public ModularMixerBackend, publ
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;
Expand Down