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
1 changed files with 43 additions and 24 deletions

View File

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