force window aspect ratio
[uwplayer.git] / application / player.c
index 5c481fa..7620a63 100644 (file)
@@ -309,7 +309,7 @@ static void player_io(Player *p) {
 
 static void handle_json_rpc_msg(Player *player, JSONValue *v) {
     if(v->type != JSON_OBJECT) return;
-    
+      
     JSONValue *request_id_v = json_obj_get(&v->value.object, "request_id");
     JSONValue *event = NULL;
     if(request_id_v && request_id_v->type == JSON_STRING) {
@@ -323,11 +323,11 @@ static void handle_json_rpc_msg(Player *player, JSONValue *v) {
         handle_json_rpc_event(player, v, event);
     }
     
-    json_print(v, NULL, 0);
+    //json_print(v, NULL, 0);
     fflush(stdout);
 }
 
-static void player_widget_set_size(XtPointer data, XtIntervalId *id) {
+static Boolean player_widget_set_size(XtPointer data) {
     Player *player = data;
     MainWindow *win = GetMainWindow();
         
@@ -339,8 +339,19 @@ static void player_widget_set_size(XtPointer data, XtIntervalId *id) {
     Dimension new_width = player->width + win_width - player_width;
     Dimension new_height = player->height + win_height - player_height;
     
+    // set window size
     XtVaSetValues(win->window, XmNwidth, new_width, XmNheight, new_height, NULL);
     
+    // set window aspect ratio
+    XSizeHints hints;
+    hints.flags = PAspect;
+    hints.min_aspect.x = new_width;
+    hints.min_aspect.y = new_height;
+    hints.max_aspect.x = new_width;
+    hints.max_aspect.y = new_height;
+    XSetWMNormalHints(XtDisplay(win->window), XtWindow(win->window), &hints);
+    
+    return 0;
 }
 
 
@@ -353,7 +364,7 @@ static void player_set_size(Player *player, int width, int height) {
         player->height = height;
     }
     if(player->width > 0 && player->height > 0) {
-        AppAddTimeOut(0, player_widget_set_size, player);
+        AppExecProc(player_widget_set_size, player);
     }
 }
 
@@ -392,13 +403,14 @@ static void handle_json_rpc_event(Player *p, JSONValue *v, JSONValue *event) {
                 PlayerEOF(p);
             }
         }
-    } else if(!json_strcmp(event, "playback-restart")) {
+    } else if(!p->isstarted && !json_strcmp(event, "playback-restart")) {
         char *cmd = "{ \"command\": [\"observe_property\", 1, \"playback-time\"] }\n"
                     "{ \"command\": [\"observe_property\", 1, \"eof-reached\"] }\n"
                     "{ \"command\": [\"get_property\", \"width\"], request_id=\"" REQ_ID_WIDTH "\" }\n"
                     "{ \"command\": [\"get_property\", \"height\"], request_id=\"" REQ_ID_HEIGHT "\" }\n"
                     "{ \"command\": [\"set_property\", \"keep-open\", true] }\n";
         write(p->ipc, cmd, strlen(cmd));
+        p->isstarted = TRUE;
     }
 }