parent
b8c3531bff
commit
3b54638cfc
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include "journal-binding.h"
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
#include "sharedstate.h"
|
#include "sharedstate.h"
|
||||||
|
|
@ -25,6 +26,36 @@ namespace syswm {
|
||||||
#define NIKO_X (320 - 16)
|
#define NIKO_X (320 - 16)
|
||||||
#define NIKO_Y ((13 * 16) * 2)
|
#define NIKO_Y ((13 * 16) * 2)
|
||||||
|
|
||||||
|
RB_METHOD(nikoPrepare)
|
||||||
|
{
|
||||||
|
// Prime native window info
|
||||||
|
syswm::SDL_SysWMinfo syswindow;
|
||||||
|
SDL_VERSION(&syswindow.version);
|
||||||
|
SDL_GetWindowWMInfo(shState->rtData().window, &syswindow);
|
||||||
|
|
||||||
|
#ifdef LINUX
|
||||||
|
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(journal.c_str(), journal.c_str(), "niko", (char*)0);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
RB_METHOD(nikoStart)
|
RB_METHOD(nikoStart)
|
||||||
{
|
{
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
|
|
@ -58,47 +89,32 @@ RB_METHOD(nikoStart)
|
||||||
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 message[32];
|
||||||
char y_str[16];
|
sprintf(message, "%d,%d", x, y);
|
||||||
sprintf(x_str, "%d", x);
|
|
||||||
sprintf(y_str, "%d", y);
|
|
||||||
|
|
||||||
char path[PATH_MAX];
|
SDL_LockMutex(mutex);
|
||||||
std::string journal;
|
message_len = strlen(message);
|
||||||
|
strcpy((char*)message_buffer, message);
|
||||||
|
SDL_UnlockMutex(mutex);
|
||||||
|
|
||||||
// Get current path
|
// Clean up connection thread
|
||||||
getcwd(path, sizeof(path));
|
if (thread != NULL && out_pipe != -1) {
|
||||||
|
SDL_WaitThread(thread, NULL);
|
||||||
#ifdef OS_OSX
|
thread = NULL;
|
||||||
journal = std::string(path) + std::string("/_______.app/Contents/MacOS/_______");
|
}
|
||||||
#else
|
// Attempt to send it over the tubes
|
||||||
journal = std::string(path) + std::string("_______");
|
if (out_pipe != -1) {
|
||||||
#endif
|
// We have a connection, so send it over
|
||||||
|
if (write(out_pipe, (char*)message_buffer, message_len) <= 0) {
|
||||||
// Run the binary
|
// In the case of an error, close
|
||||||
pid_t pid = fork();
|
close(out_pipe);
|
||||||
if (pid == 0) {
|
out_pipe = -1;
|
||||||
execl(journal.c_str(), journal.c_str(), x_str, y_str, (char*)0);
|
}
|
||||||
exit(1);
|
}
|
||||||
|
if (out_pipe == -1) {
|
||||||
|
// We don't have a pipe open, so spawn the connection thread
|
||||||
|
thread = SDL_CreateThread(server_thread, "journal", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
|
|
@ -108,5 +124,6 @@ void nikoBindingInit()
|
||||||
VALUE module = rb_define_module("Niko");
|
VALUE module = rb_define_module("Niko");
|
||||||
|
|
||||||
//Functions
|
//Functions
|
||||||
|
_rb_define_module_function(module, "get_ready", nikoPrepare);
|
||||||
_rb_define_module_function(module, "do_your_thing", nikoStart);
|
_rb_define_module_function(module, "do_your_thing", nikoStart);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue