2

如果我在bash脚本中有这样的东西:

audacity &
pid=$!

wmctrl -r "Audacity" -e 0,0,0,800,600

...它通常会失败,因为进程启动 ( audacity &) 将比 Audacity 窗口完全显示(并且可以由 控制wmctrl)的点完成/返回要早得多,否则可能需要几秒钟。

在继续执行脚本之前,是否有一种简单的方法可以“同步”或“等待”GUI 应用程序完全启动(即,它的窗口被完全呈现)?(我找到了一种方法,我将其作为答案发布 - 但如果有更简单、更紧凑的方法,我会在徘徊

4

1 回答 1

2

编辑:这确实检测到窗口何时显示;但不检测其中的所有菜单/小部件何时完成放置/布局

好的,所以首先我运行这个脚本:

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
于 2013-10-18T04:03:23.263 回答