Bind journal to ending on macOS and Linux

This commit is contained in:
Vinyl Darkscratch 2018-03-08 03:48:38 -08:00
parent 00dcba7785
commit b9d5b954b5

View file

@ -13,6 +13,8 @@
#else
#define OS_LINUX
#endif
#include <unistd.h>
#endif
#include <SDL.h>
@ -32,7 +34,7 @@ RB_METHOD(nikoStart)
SDL_VERSION(&syswindow.version);
SDL_GetWindowWMInfo(shState->rtData().window, &syswindow);
#if defined _WIN32
#ifdef _WIN32
// Calculate where to stick the window
POINT pos;
pos.x = NIKO_X;
@ -50,36 +52,53 @@ RB_METHOD(nikoStart)
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
CreateProcessW(path, args, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
#elif defined LINUX
#else
// Calculate where to stick the window
int x, y; // Top-left area of client (hopefully)
SDL_GetWindowPosition(shState->rtData().window, &x, &y);
x += NIKO_X;
y += NIKO_Y;
char path[PATH_MAX];
ssize_t len = readlink("/proc/self/exe", path, PATH_MAX);
if (len > 0) {
// Replace filename
for (size_t i = len; i > 0; --i) {
if (path[i-1] == '/') {
strcpy(path + i, "_______");
break;
}
}
// X and Y string arguments
char x_str[16];
char y_str[16];
sprintf(x_str, "%d", x);
sprintf(y_str, "%d", y);
// Assume that was a success and run the binary
char path[PATH_MAX];
std::string journal;
// Get current path
getcwd(path, sizeof(path));
#ifdef OS_OSX
journal = std::string(path) + std::string("/_______.app/Contents/MacOS/_______");
#else
journal = std::string(path) + std::string("_______");
#endif
// Run the binary
pid_t pid = fork();
if (pid == 0) {
execl(path, "_______", x_str, y_str, NULL);
execl(journal.c_str(), x_str, y_str, (char*)0);
exit(1);
}
}
#else
#error "not yet implemented"
// ssize_t len = readlink("/proc/self/exe", path, PATH_MAX);
// if (len > 0) {
// // Replace filename
// for (size_t i = len; i > 0; --i) {
// if (path[i-1] == '/') {
// strcpy(path + i, "_______");
// break;
// }
// }
// // Run the binary
// pid_t pid = fork();
// if (pid == 0) {
// execl(path, "_______", x_str, y_str, (char*)0);
// exit(1);
// }
// }
#endif
return Qnil;
}