编辑:这确实检测到窗口何时显示;但不检测其中的所有菜单/小部件何时完成放置/布局
好的,所以首先我运行这个脚本:
audacity &
pid=$!
while [ "1" ] ; do
  xwininfo -name 'Audacity'
  sleep 0.1
done
...应该像这样运行,以获得完整的日志:
bash testscript.sh 2>&1 | tee testscript.log
...并且可以看到一个点,从xwininfo“过渡”转储,可以这么说:
xwininfo: Window id: 0x3a000b5 (has no name)
  Absolute upper-left X:  0
  Absolute upper-left Y:  0
  Relative upper-left X:  0
  Relative upper-left Y:  0
  Width: 200
  Height: 200
  Depth: 24
  Visual: 0x21
  Visual Class: TrueColor
  Border width: 0
  Class: InputOutput
  Colormap: 0x20 (installed)
  Bit Gravity State: NorthWestGravity
  Window Gravity State: NorthWestGravity
  Backing Store State: NotUseful
  Save Under State: no
  Map State: IsUnMapped
  Override Redirect State: no
  Corners:  +0+0  -824+0  -824-400  +0-400
  -geometry 200x200+0+0
xwininfo: Window id: 0x4c00587 "Audacity"
  Absolute upper-left X:  50
  Absolute upper-left Y:  59
  Relative upper-left X:  0
  Relative upper-left Y:  18
  Width: 830
  Height: 540
  Depth: 24
  Visual: 0x21
  Visual Class: TrueColor
  Border width: 0
  Class: InputOutput
  Colormap: 0x20 (installed)
  Bit Gravity State: NorthWestGravity
  Window Gravity State: NorthWestGravity
  Backing Store State: NotUseful
  Save Under State: no
  Map State: IsViewable
  Override Redirect State: no
  Corners:  +50+59  -144+59  -144-1  +50-1
  -geometry 830x540+50-1
所以,我基本上grep可以xwininfo输出不包含“没有名字”或包含“地图状态:IsViewable”的输出......
所以,我终于尝试了这个 - 它似乎有效:
audacity &
pid=$!
WINREP=""
while [[ ! "`echo $WINREP | grep -l 'Map State: IsViewable'`" ]] ; do
  WINREP=$(xwininfo -name 'Audacity')
  #echo $WINREP
  sleep 0.1
done
echo Exited
# must use -F here for case-insensitive, to ensure proper window targetting
wmctrl -v -F -r "Audacity" -e 0,0,0,800,600