add menu item for toggling window size adjustment
[uwplayer.git] / application / player.c
index d9a88ce..2d63135 100644 (file)
@@ -41,6 +41,7 @@
 #include "json.h"
 #include "utils.h"
 #include "settings.h"
+#include "playlist.h"
 
 extern char **environ;
 
@@ -241,6 +242,12 @@ static int connect_to_ipc(Player *player) {
     return 0;
 }
 
+static Boolean update_player_window(XtPointer data) {
+    MainWindow *win = data;
+    WindowUpdate(win);
+    return 0;
+}
+
 static void* start_player(void *data) {
     MainWindow *win = data;
     
@@ -271,6 +278,9 @@ static void* start_player(void *data) {
     }
     win->player = player;
     
+    // update main window
+    AppExecProc(update_player_window, win);
+    
     // IO
     player_io(player);
     
@@ -288,7 +298,7 @@ static void player_io(Player *p) {
     JSONParser *js = json_parser_new();
      
     char buf[PLAYER_IN_BUFSIZE];
-    while(p->isactive && poll(fds, 2, PLAYER_POLL_TIMEOUT)) {
+    while(p->isactive && (poll(fds, 2, PLAYER_POLL_TIMEOUT) >= 0)) {
         if(fds[0].revents == POLLIN) {
             ssize_t r;
             if((r = read(fds[0].fd, buf, PLAYER_IN_BUFSIZE)) <= 0) {
@@ -347,6 +357,10 @@ static void handle_json_rpc_msg(Player *player, JSONValue *v) {
 static Boolean player_widget_set_size(XtPointer data) {
     Player *player = data;
     MainWindow *win = GetMainWindow();
+    
+    if(!win->adjustWindowSize) {
+        return 0;
+    }
         
     Dimension win_width, win_height;
     XtVaGetValues(win->window, XmNwidth, &win_width, XmNheight, &win_height, NULL);
@@ -572,27 +586,19 @@ static void json_print(JSONValue *value, char *name, int indent) {
     }
 }
 
-static Boolean open_next_file(XtPointer data) {
-    char *file = data;
+static Boolean play_next(XtPointer data) {
     MainWindow *win = GetMainWindow();
-    if(win->file) {
-        free(file);
-    }
-    win->file = file;
-    PlayerOpenFile(win);
+    PlayListPlayNext(win, false);    
     return 0;
 }
 
 void PlayerEOF(Player *p) {
     MainWindow *win = GetMainWindow();
-    if(win->repeatTrack) {
+    if(win->playlist.repeatTrack) {
         char *cmd = "{ \"command\": [\"set_property\", \"playback-time\", 0] }\n";
         write(p->ipc, cmd, strlen(cmd));
-    } else if(win->autoplayFolder) {
-        char *next_file = util_find_next_file(win->file);
-        if(next_file) {
-            AppExecProc(open_next_file, next_file);
-        }
+    } else {
+        AppExecProc(play_next, NULL);
     }
 }