NANA_POSIX for bits common to Linux, MacOS and BSD. OSS sound as fall-back for POSIX. Cheat for detecting default browser on POSIX.
This commit is contained in:
@@ -17,12 +17,15 @@
|
||||
#if defined(NANA_WINDOWS)
|
||||
#include <windows.h>
|
||||
#include "../detail/mswin/platform_spec.hpp"
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#elif defined(NANA_POSIX)
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/stat.h>
|
||||
#include <spawn.h>
|
||||
#endif
|
||||
|
||||
namespace nana
|
||||
@@ -36,7 +39,7 @@ namespace system
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
::Sleep(milliseconds);
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#elif defined(NANA_POSIX)
|
||||
struct timespec timeOut, remains;
|
||||
timeOut.tv_sec = milliseconds / 1000;
|
||||
timeOut.tv_nsec = (milliseconds % 1000) * 1000000;
|
||||
@@ -52,14 +55,16 @@ namespace system
|
||||
|
||||
//this_thread_id
|
||||
//@brief: get the identifier of calling thread.
|
||||
unsigned long this_thread_id()
|
||||
thread_t this_thread_id()
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
return ::GetCurrentThreadId();
|
||||
return (thread_t)::GetCurrentThreadId();
|
||||
#elif defined(NANA_LINUX)
|
||||
return ::syscall(__NR_gettid);
|
||||
return (thread_t)::syscall(__NR_gettid);
|
||||
#elif defined(NANA_MACOS)
|
||||
return ::syscall(SYS_thread_selfid);
|
||||
return (thread_t)::syscall(SYS_thread_selfid);
|
||||
#elif defined(NANA_POSIX)
|
||||
return (thread_t)pthread_self();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -67,7 +72,7 @@ namespace system
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
return ::GetTickCount();
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#elif defined(NANA_POSIX)
|
||||
struct timeval tv;
|
||||
::gettimeofday(&tv, 0);
|
||||
return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
|
||||
@@ -92,7 +97,7 @@ namespace system
|
||||
}
|
||||
|
||||
return (::GetAsyncKeyState(button) != 0);
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#elif defined(NANA_POSIX)
|
||||
static_cast<void>(button); //eliminate unused parameter compiler warning.
|
||||
return false;
|
||||
#endif
|
||||
@@ -105,7 +110,6 @@ namespace system
|
||||
return;
|
||||
|
||||
#if defined(NANA_WINDOWS)
|
||||
std::wstring url = to_wstring(url_utf8);
|
||||
if(::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL) < reinterpret_cast<HINSTANCE>(32))
|
||||
{
|
||||
//Because ShellExecute can delegate execution to Shell extensions (data sources, context menu handlers,
|
||||
@@ -115,8 +119,25 @@ namespace system
|
||||
nana::detail::platform_spec::co_initializer co_init;
|
||||
::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL);
|
||||
}
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#elif defined(NANA_POSIX)
|
||||
const char *home = getenv("HOME");
|
||||
std::string cheat(home);
|
||||
cheat += "/.mozilla";
|
||||
struct stat exists{};
|
||||
// Look for $HOME/.mozilla directory as
|
||||
// strong evidence they use firefox.
|
||||
if ( stat(cheat.c_str(), &exists) == 0 && S_ISDIR(exists.st_mode))
|
||||
{
|
||||
extern char **environ;
|
||||
pid_t pid = 0;
|
||||
static const char firefox[] = "firefox";
|
||||
char name[sizeof firefox]{};
|
||||
// argv does not like const-literals so make a copy.
|
||||
strcpy(name, firefox);
|
||||
char *argv[3] = {name, const_cast<char *>(url_utf8.c_str()), nullptr};
|
||||
posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}//end namespace system
|
||||
}//end namespace nana
|
||||
|
||||
Reference in New Issue
Block a user