@@ -14353,11 +14353,16 @@ static void SetClipboardTextFn_DefaultImpl(void* user_data_ctx, const char* text
14353
14353
14354
14354
//-----------------------------------------------------------------------------
14355
14355
14356
- #if defined(__APPLE__) && defined( TARGET_OS_IPHONE) && !defined(IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS)
14356
+ #if defined(__APPLE__) && TARGET_OS_IPHONE && !defined(IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS)
14357
14357
#define IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS
14358
14358
#endif
14359
14359
14360
- #if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS)
14360
+ #if defined(_WIN32) && defined(IMGUI_DISABLE_WIN32_FUNCTIONS)
14361
+ #define IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS
14362
+ #endif
14363
+
14364
+ #ifndef IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS
14365
+ #ifdef _WIN32
14361
14366
#include <shellapi.h> // ShellExecuteA()
14362
14367
#ifdef _MSC_VER
14363
14368
#pragma comment(lib, "shell32")
@@ -14366,18 +14371,32 @@ static bool PlatformOpenInShellFn_DefaultImpl(ImGuiContext*, const char* path)
14366
14371
{
14367
14372
return (INT_PTR)::ShellExecuteA(NULL, "open", path, NULL, NULL, SW_SHOWDEFAULT) > 32;
14368
14373
}
14369
- #elif !defined(IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS)
14374
+ #else
14375
+ #include <sys/wait.h>
14376
+ #include <unistd.h>
14370
14377
static bool PlatformOpenInShellFn_DefaultImpl(ImGuiContext*, const char* path)
14371
14378
{
14372
14379
#if __APPLE__
14373
- const char* open_executable = "open";
14380
+ const char* args[] { "open", "--", path, NULL } ;
14374
14381
#else
14375
- const char* open_executable = "xdg-open";
14382
+ const char* args[] { "xdg-open", path, NULL } ;
14376
14383
#endif
14377
- ImGuiTextBuffer buf;
14378
- buf.appendf("%s \"%s\"", open_executable, path);
14379
- return system(buf.c_str()) != -1;
14384
+ pid_t pid = fork();
14385
+ if (pid < 0)
14386
+ return false;
14387
+ else if (!pid)
14388
+ {
14389
+ execvp(args[0], const_cast<char **>(args));
14390
+ exit(-1);
14391
+ }
14392
+ else
14393
+ {
14394
+ int status;
14395
+ waitpid(pid, &status, 0);
14396
+ return WEXITSTATUS(status) == 0;
14397
+ }
14380
14398
}
14399
+ #endif
14381
14400
#else
14382
14401
static bool PlatformOpenInShellFn_DefaultImpl(ImGuiContext*, const char*) { return false; }
14383
14402
#endif // Default shell handlers
0 commit comments