From 1004781e00cf4e231e59d8ef6342de044bf0b5ce Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sat, 5 Feb 2022 08:19:03 -0800 Subject: setbrwindow: wait for window instead of exiting When --windowid specifies a window that hasn't yet been mapped this thing would just exit. But in scripted invocations where a window of interest is created and mapped by the client immediately prior to launching recordMyDesktop, there's a good chance the window manager hasn't yet handled the MapRequest before recordMyDesktop launched and attempted to get the window's attributes. This change subscribes to the window's visibility and structure events when the attributes show it's not yet mapped and visible, entering into an event loop waiting for the window. No timeout has been added at this time. Some interesting directions to go from here: - Pause recording on unmap, resume recording on map - Follow the window if it moves - It'd be nice if recording could handle window resizes, but especially for on-the-fly encoding this seems awkward at best. For cached recordings the encode could start with the largest dimensions and simply pad out any smaller frames. I'll have to look at Theora to see if there is any support for variable sized video streams. Fixes https://github.com/recordmydesktop/recordmydesktop/issues/7 --- src/rmd_setbrwindow.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/rmd_setbrwindow.c') diff --git a/src/rmd_setbrwindow.c b/src/rmd_setbrwindow.c index 846abe6..08d0997 100644 --- a/src/rmd_setbrwindow.c +++ b/src/rmd_setbrwindow.c @@ -63,11 +63,15 @@ boolean rmdSetBRWindow( Display *dpy, Window wchid; XWindowAttributes attribs; + XSelectInput(dpy, args->windowid, VisibilityChangeMask | StructureNotifyMask); XGetWindowAttributes(dpy, args->windowid, &attribs); - if (attribs.map_state == IsUnviewable || attribs.map_state == IsUnmapped) { - fprintf(stderr, "Window must be mapped and visible!\n"); - return FALSE; + while (attribs.map_state == IsUnviewable || attribs.map_state == IsUnmapped) { + XEvent ev; + + fprintf(stderr, "Waiting for window to be mapped and visible!\n"); + XWindowEvent(dpy, args->windowid, VisibilityChangeMask|StructureNotifyMask, &ev); + XGetWindowAttributes(dpy, args->windowid, &attribs); } XTranslateCoordinates( dpy, -- cgit v1.2.3