set window size after a video is opened
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 13 Jan 2022 19:53:42 +0000 (20:53 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 13 Jan 2022 19:53:42 +0000 (20:53 +0100)
application/main.c
application/player.c
application/window.c
application/window.h

index 8a43d19..55a9d4f 100644 (file)
@@ -36,6 +36,7 @@
 
 static XtAppContext app;
 static Display *display;
+static Widget toplevel_window;
 
 static String fallback[] = {
         "*renderTable: rt",
@@ -75,7 +76,7 @@ int main(int argc, char** argv) {
     XtSetLanguageProc(NULL, langProc, NULL);
     app = XtCreateApplicationContext();
     XtAppSetFallbackResources(app, fallback);
-    
+       
     display =  XtOpenDisplay(app, NULL, APP_NAME, APP_CLASS, NULL, 0, &argc, argv);
     
     // load settings
@@ -84,6 +85,7 @@ int main(int argc, char** argv) {
     }
     
     MainWindow *window = WindowCreate(display);
+    toplevel_window = window->window;
     
     // random numbers only used for creating tmp dirs
     srand(time(NULL));
@@ -104,4 +106,16 @@ void ApplicationExit(void) {
 
 void AppAddTimeOut(unsigned long interval, XtTimerCallbackProc proc, XtPointer data) {
     XtAppAddTimeOut(app, interval, proc, data);
+    
+    if(!toplevel_window) return;
+    
+    // send a dummy X11 event, because the event loop may be waiting
+    // and the timeout proc is only called when an event is processed
+    XClientMessageEvent event;
+    memset(&event, 0, sizeof(XClientMessageEvent));
+    event.type = ClientMessage;
+    event.window = XtWindow(toplevel_window);
+    event.format = 32;
+    XSendEvent(display, XtWindow(toplevel_window), 0, 0, (XEvent*)&event);
+    XFlush(display);
 }
index dbaca58..5c481fa 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include "player.h"
+#include "main.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -106,7 +107,7 @@ static void* wait_for_process(void *data) {
     int status = 0;
     waitpid(player->process, &status, 0);
 
-    //player->isactive = FALSE;
+    player->isactive = FALSE;
     player->status = status;
     
     return NULL;
@@ -326,6 +327,24 @@ static void handle_json_rpc_msg(Player *player, JSONValue *v) {
     fflush(stdout);
 }
 
+static void player_widget_set_size(XtPointer data, XtIntervalId *id) {
+    Player *player = data;
+    MainWindow *win = GetMainWindow();
+        
+    Dimension win_width, win_height;
+    XtVaGetValues(win->window, XmNwidth, &win_width, XmNheight, &win_height, NULL);
+    Dimension player_width, player_height;
+    XtVaGetValues(win->player_widget, XmNwidth, &player_width, XmNheight, &player_height, NULL);
+
+    Dimension new_width = player->width + win_width - player_width;
+    Dimension new_height = player->height + win_height - player_height;
+    
+    XtVaSetValues(win->window, XmNwidth, new_width, XmNheight, new_height, NULL);
+    
+}
+
+
+
 static void player_set_size(Player *player, int width, int height) {
     if(width >= 0) {
         player->width = width;
@@ -334,7 +353,7 @@ static void player_set_size(Player *player, int width, int height) {
         player->height = height;
     }
     if(player->width > 0 && player->height > 0) {
-        printf("TODO: set player size\n");
+        AppAddTimeOut(0, player_widget_set_size, player);
     }
 }
 
index 88a0db8..9ec4323 100644 (file)
@@ -114,6 +114,10 @@ MainWindow* WindowCreate(Display *display) {
     return window;
 }
 
+MainWindow* GetMainWindow(void) {
+    return main_window;
+}
+
 void WindowShow(MainWindow *win) {
     XtRealizeWidget(win->window);
 }
index 66db8ae..9ffa93c 100644 (file)
@@ -57,6 +57,8 @@ typedef struct MainWindow {
 
 MainWindow* WindowCreate(Display *dp);
 
+MainWindow* GetMainWindow(void);
+
 void WindowShow(MainWindow *win);
 
 void WindowFullscreen(MainWindow *win, bool enableFullscreen);