如何从xwininfo中找到Firefox窗口?

时间:2009-12-29 01:14:03

标签: perl firefox mozilla

我的Perl并不是很好,我无法确定为什么this令人敬畏的perl脚本不断返回:

  

错误:找不到运行窗口   找不到窗口[Mozilla]   [xwininfo -tree -root]

我设置了这些变量:

my $PROGNAME = $0;
$PROGNAME =~ s|.*/||;
my $GRAB = 'xwd -silent -nobdrs -id %id | convert -quality 85 - %out';
my $XINFO = 'xwininfo -tree -root';
my $BROWSER = 'firefox';    # Must match find_window() code - see usage()

在使用中它说:

- Requires "Mozilla" or "Opera" browser
    (update find_window() code for other browsers)

有关的代码是:

# I'm using mozilla..
sub find_window {
  $BROWSER eq "opera" ?
    opera_find_window(@_) :
    mozilla_find_window(@_);
}

我如何得到以上内容以反映firefox浏览器。在我的shell中,如果我键入mozilla没有任何反应,如果我键入firefox - 我的浏览器打开,所以我应该使用它。

以下是有问题的代码,它返回错误:

sub mozilla_find_window {
  open(XINFO,"$XINFO|") || die("Couldn't run: [$XINFO]\n");

  # Pick the first mozilla window.  It's got the title in it, but
  # we have no way of knowing if that matches the URL, so we'll
  # hope this is the right one..
  my ($spacing,$id,$title,$x,$y);
  while(<XINFO>) {
    # This could easily break and is very mozilla specific (works on firefox)
    # Looks for [...("Mozilla" "navigator:browser") ..]
    # I've had this reported:     0x80002f "TITLE - Mozilla": ("Gecko" "Mozilla-bin")  889x687+0+22  +136+44
    last if (($spacing,$id,$title,$x,$y) = (/^(\s+)(0x[0-9a-f]+) "(.*)\s*-\s*Mozilla.*": \("Mozilla" "navigator:browser"\)\s*$GEOM_RE$/));

    last if (($spacing,$id,$title,$x,$y) = (/^(\s+)(0x[0-9a-f]+) "(.*)\s*-\s*Mozilla.*": \("mozilla-bin" "Mozilla-bin"\)\s*$GEOM_RE$/));
    # Mozilla Firefox 1.0.4
    last if (($spacing,$id,$title,$x,$y) = (/^(\s+)(0x[0-9a-f]+) "(.*)\s*-\s*Mozilla Firefox.*": \("Gecko" "Firefox-bin"\)\s*$GEOM_RE$/));
        # Debian Mozilla Firefox
        last if (($spacing,$id,$title,$x,$y) = (/^(\s+)(0x[0-9a-f]+) "(.*)\s*-\s*Mozilla Firefox.*": \("firefox-bin" "Firefox-bin"\)\s*$GEOM_RE$/));
  }
  die("Couldn't find window [Mozilla] in [$XINFO]\n") unless $title && $x && $y;

有人知道如何解决这个问题,我做错了什么?这是一个与安装firefox的位置有关的问题吗?

全部谢谢

更新

 0x140529c "Firefox": ()  10x10+-100+-100  +-100+-100
 0x14051b9 "Firefox": ()  10x10+-100+-100  +-100+-100
 0x14038c9 "Firefox": ("firefox" "Firefox")  1x1+-100+-100  +-100+-100
    1 child:
    0x14038ca (has no name): ()  1x1+-1+-1  +-101+-101
 0x14002bd "Firefox": ()  1x1+0+0  +0+0
    1 child:
    0x14002be (has no name): ()  1x1+-1+-1  +-1+-1
 0x1400210 "Firefox": ()  10x10+-100+-100  +-100+-100
 0x14000ea "Firefox": ("firefox" "Firefox")  200x200+0+0  +0+0
    1 child:
    0x14000eb (has no name): ()  1x1+-1+-1  +-1+-1
 0x14000a6 "Firefox": ("firefox" "Firefox")  200x200+0+0  +0+0
    2 children:
    0x14000a9 (has no name): ()  1x1+-1+-1  +-1+-1
       1 child:
       0x14000aa (has no name): ()  1x1+2+2  +1+1
          1 child:
          0x14000ab (has no name): ()  1x1+0+0  +1+1
             4 children:
             0x140519f (has no name): ()  1x1+-1+-1  +0+0
             0x140519e (has no name): ()  1x1+-1+-1  +0+0
             0x1400286 (has no name): ()  1x1+-1+-1  +0+0
             0x14000ad (has no name): ()  1x1+-1+-1  +0+0
    0x14000a7 (has no name): ()  1x1+-1+-1  +-1+-1
 0x140008d "Firefox": ("firefox" "Firefox")  200x200+0+0  +0+0

当我手动运行xwininfo -tree -root

时,会获得上述内容

1 个答案:

答案 0 :(得分:4)

您可以从xwininfo的输出中看到您的Firefox在X窗口列表中显示为“Firefox”:(“firefox”“Firefox”)

目前没有一个正则表达式正在寻找这种组合。在#Debian Mozilla Firefox行之后直接添加此代码(或至少在同一while块中的某个位置):

# my Firefox
last if (($spacing,$id,$title,$x,$y) = (/^(\s+)(0x[0-9a-f]+) "(Firefox)": \("firefox" "Firefox"\)\s*$GEOM_RE$/));