]> uap-core.de Git - uwplayer.git/commitdiff
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 8a43d19099c0d86dd7ffa29ff049c39364b14d92..55a9d4f930996d24fc76ee303ffd749fd02cbbc7 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 dbaca589707194468c89ee4f1fb9e68c689b22cb..5c481fa8c400a0ce1c7820b5aa478ce52b1b2d69 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 88a0db8391e33bb2972dc9d30886315a1a256d0d..9ec43234397b53539c1a0cb4b80909773d61d0a1 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 66db8aea8cd695be0eba3b8c5e610492cbcccac3..9ffa93c720fbf488ed19ba43cae15aae45881997 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);