diff --git a/binding-mri/niko-binding.cpp b/binding-mri/niko-binding.cpp index 20c9d6c..a91b63e 100644 --- a/binding-mri/niko-binding.cpp +++ b/binding-mri/niko-binding.cpp @@ -13,6 +13,8 @@ #else #define OS_LINUX #endif + + #include #endif #include @@ -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 x_str[16]; + char y_str[16]; + sprintf(x_str, "%d", x); + sprintf(y_str, "%d", 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 - pid_t pid = fork(); - if (pid == 0) { - execl(path, "_______", x_str, y_str, NULL); - exit(1); - } + 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(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; }