static XtAppContext app;
static Display *display;
+static Widget toplevel_window;
+
+static int event_pipe[2];
static String fallback[] = {
"*renderTable: rt",
return setlocale(LC_ALL, NULL);
}
+typedef struct EventLoopCB {
+ XtWorkProc proc;
+ XtPointer data;
+} EventLoopCB;
+
+static void input_proc(XtPointer data, int *source, XtInputId *iid) {
+ EventLoopCB cb[16];
+ ssize_t r = read(event_pipe[0], cb, sizeof(EventLoopCB)*16);
+ size_t n = r / sizeof(EventLoopCB);
+ for(int i=0;i<n;i++) {
+ cb[i].proc(cb[i].data);
+ }
+}
+
int main(int argc, char** argv) {
// disable stdout buffering, because the netbeans's internal terminal
// has a bug on freebsd and doesn't flush the output after a newline
setvbuf(stdout, NULL, _IONBF, 0);
+
+ // init event pipe for xt event loop
+ if(pipe(event_pipe)) {
+ perror("pipe");
+ return 2;
+ }
// initialize toolkit
XtToolkitInitialize();
XtSetLanguageProc(NULL, langProc, NULL);
app = XtCreateApplicationContext();
XtAppSetFallbackResources(app, fallback);
-
+
display = XtOpenDisplay(app, NULL, APP_NAME, APP_CLASS, NULL, 0, &argc, argv);
+ XtAppAddInput(
+ app,
+ event_pipe[0],
+ (XtPointer)XtInputReadMask,
+ input_proc,
+ NULL);
+
// load settings
if(load_settings()) {
return 1;
}
MainWindow *window = WindowCreate(display);
+ toplevel_window = window->window;
// random numbers only used for creating tmp dirs
srand(time(NULL));
XtAppSetExitFlag(app);
}
-void AppAddTimeOut(unsigned long interval, XtTimerCallbackProc proc, XtPointer data) {
- XtAppAddTimeOut(app, interval, proc, data);
+void AppExecProc(XtWorkProc proc, XtPointer data) {
+ EventLoopCB cb;
+ cb.proc = proc;
+ cb.data = data;
+ write(event_pipe[1], &cb, sizeof(cb));
}