X-Git-Url: https://develop.uap-core.de/gitweb/uwplayer.git/blobdiff_plain/5dddf6a0fd936f4f3349d0174c1261d8fb99523c..c4d69d05f758eb2f8f98be04ff42456c9ae711fe:/application/main.c diff --git a/application/main.c b/application/main.c index 8a43d19..e12d1aa 100644 --- a/application/main.c +++ b/application/main.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "window.h" #include "main.h" @@ -36,6 +37,11 @@ static XtAppContext app; static Display *display; +static Widget toplevel_window; + +static char *open_file_arg; + +static int event_pipe[2]; static String fallback[] = { "*renderTable: rt", @@ -45,7 +51,7 @@ static String fallback[] = { "*pbbutton.shadowThickness: 1", "*pbbutton.highlightThickness: 1", - + "*XmText.baseTranslations: #override\\n" \ "Ctrl~Alt~Metav: paste-clipboard()\\n" \ "Ctrl~Alt~Metac: copy-clipboard()\\n" \ @@ -65,31 +71,69 @@ static String langProc(Display *dp, String xnl, XtPointer closure) { 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 1) { + struct stat s; + if(stat(argv[1], &s)) { + fprintf(stderr, "Cannot open file: %s\n", argv[1]); + perror(""); + return 1; + } + open_file_arg = argv[1]; + } + + XtAppAddInput( + app, + event_pipe[0], + (XtPointer)XtInputReadMask, + input_proc, + NULL); + // load settings - if(load_settings()) { + if(load_config()) { return 1; } - + MainWindow *window = WindowCreate(display); + toplevel_window = window->window; - // random numbers only used for creating tmp dirs + // random numbers used for creating tmp dirs and for random playback srand(time(NULL)); WindowShow(window); - XtAppMainLoop(app); + AppMainLoop(app); return 0; } @@ -102,6 +146,39 @@ void ApplicationExit(void) { 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)); +} + +char* GetOpenFileArg(void) { + return open_file_arg; +} + +void CleanOpenFileArg(void) { + open_file_arg = NULL; +} + +static Window app_player_window = 0; + +void SetPlayerWindow(Window w) { + app_player_window = w; +} + +/* + * Extended Xt main loop, that also handles external window events + */ +void AppMainLoop(XtAppContext app) { + while(!XtAppGetExitFlag(app)) { + XEvent event; + XtAppNextEvent(app, &event); + + if(app_player_window != 0 && event.xany.window == app_player_window) { + WindowHandlePlayerEvent(GetMainWindow(), &event); + } else { + XtDispatchEvent(&event); + } + } }