X-Git-Url: https://develop.uap-core.de/gitweb/uwplayer.git/blobdiff_plain/86c051bbad8e57edb6219601813e9d6042a1f0f9..92835e632a2570c851ecd45af5c3b97af2037322:/application/main.c?ds=sidebyside diff --git a/application/main.c b/application/main.c index 6aaac89..42078dc 100644 --- a/application/main.c +++ b/application/main.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "window.h" #include "main.h" @@ -38,6 +39,8 @@ static XtAppContext app; static Display *display; static Widget toplevel_window; +static char *open_file_arg; + static int event_pipe[2]; static String fallback[] = { @@ -101,6 +104,16 @@ int main(int argc, char** argv) { display = XtOpenDisplay(app, NULL, APP_NAME, APP_CLASS, NULL, 0, &argc, argv); + if(argc > 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], @@ -109,7 +122,7 @@ int main(int argc, char** argv) { NULL); // load settings - if(load_settings()) { + if(load_config()) { return 1; } @@ -120,7 +133,7 @@ int main(int argc, char** argv) { srand(time(NULL)); WindowShow(window); - XtAppMainLoop(app); + AppMainLoop(app); return 0; } @@ -139,3 +152,33 @@ void AppExecProc(XtWorkProc proc, XtPointer data) { 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); + } + } +}