tags:

views:

198

answers:

1

I'm running X across a slow network connection. How can I tell when a window has become visible? I need to wait so that I can perform another operation on the visible window.

xterm -T foo &
# how to flush the display, or wait until the window is visible?
# polling the visibility would be acceptable as well
xmovewindow foo  10 20

update: Thanks to Jim Lewis, here's a quick shell function that does the trick.

function xwait() {
    while ! xwininfo -name $1|grep 'Map State: IsViewable';do sleep 1;done
}
xterm -T foo &
xwait foo
xmovewindow foo  10 20
+5  A: 

You probably want to know when the remote X server has mapped your application's main window. The xwininfo command will let you query the X server by window name -- I think it's part of the standard X11 install. But you'd have to do the polling yourself, rerunning the command until the "Map State" property comes back "IsViewable"

Jonathan Leffler also mentioned Sun's toolwait utility (documentation here). toolwait launches a process (in this case, your xterm command), and returns when the application has mapped a top-level window...it does the polling for you. There's a package that purports to be a Linux clone of toolwait in the X11/xutils directory at www.ibiblio.org (here).

toolwait dates all the way back to OpenWindows -- now that's some old school X window programming, man! I have in front of me a Solaris man page dated 1994, which states "The OpenWindows environment may no longer be supported in a future release. You may want to migrate to CDE, the Common Desktop Environment..."

Jim Lewis
just what I needed, thanks! and OpenWindows, that does take me back... :-)
Mark Harrison