From d165fb07a7fd8e80662281e46b998d5458e9d02c Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Thu, 13 Jan 2022 20:53:42 +0100 Subject: [PATCH] set window size after a video is opened --- application/main.c | 16 +++++++++++++++- application/player.c | 23 +++++++++++++++++++++-- application/window.c | 4 ++++ application/window.h | 2 ++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/application/main.c b/application/main.c index 8a43d19..55a9d4f 100644 --- a/application/main.c +++ b/application/main.c @@ -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); } diff --git a/application/player.c b/application/player.c index dbaca58..5c481fa 100644 --- a/application/player.c +++ b/application/player.c @@ -21,6 +21,7 @@ */ #include "player.h" +#include "main.h" #include #include @@ -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); } } diff --git a/application/window.c b/application/window.c index 88a0db8..9ec4323 100644 --- a/application/window.c +++ b/application/window.c @@ -114,6 +114,10 @@ MainWindow* WindowCreate(Display *display) { return window; } +MainWindow* GetMainWindow(void) { + return main_window; +} + void WindowShow(MainWindow *win) { XtRealizeWidget(win->window); } diff --git a/application/window.h b/application/window.h index 66db8ae..9ffa93c 100644 --- a/application/window.h +++ b/application/window.h @@ -57,6 +57,8 @@ typedef struct MainWindow { MainWindow* WindowCreate(Display *dp); +MainWindow* GetMainWindow(void); + void WindowShow(MainWindow *win); void WindowFullscreen(MainWindow *win, bool enableFullscreen); -- 1.8.3.1