简体   繁体   English

如何在Linux的X Window System中找到一个窗口并将其置于最前面?

[英]How to find a window in X Window System on Linux and bring it to front?

I have a series of automated user tests of Swing GUI that use Java robot and User32 native library on Windows. 我对Swing GUI进行了一系列自动用户测试,这些测试在Windows上使用Java机器人和User32本机库。 With methods like User32.INSTANCE.EnumWindows I am able to find a window with a specific title, bring it to front and then use key-strokes to perform actions. 使用User32.INSTANCE.EnumWindows方法,我可以找到带有特定标题的窗口,将其放在最前面,然后使用按键执行操作。 The windows I am looking for are either other Swing Apps (running in separate JVM), PDF viewers or browsers. 我要查找的窗口是其他Swing应用程序(在单独的JVM中运行),PDF查看器或浏览器。 I have no control of those windows. 我无法控制这些窗口。

Is there a way how to do this on Linux? 有没有办法在Linux上执行此操作?

My setup (can be changed if it helps, virtual machines will be used anyway): 我的设置(如果有帮助,可以更改,无论如何都将使用虚拟机):

  • Ubuntu 14.04 Ubuntu 14.04
  • tightvnc server with xvnc Xvnc的紧密vnc服务器
  • IceWM window manager IceWM窗口管理器

Note: I am running these tests on a headless server. 注意:我正在无头服务器上运行这些测试。

Required operations: 所需的操作:

  • Find a named window (by title, to confirm something was opened) 查找一个命名窗口(按标题,以确认已打开某项)
  • Bring a named window to front and focus on it (to perform keystrokes) 将命名窗口置于最前面并专注于该窗口(以执行击键操作)

As per Etan's suggestion, I've installed wmctrl: 按照Etan的建议,我已经安装了wmctrl:

sudo apt-get install wmctrl

And then called it from Java. 然后从Java调用它。 For finding a named window: 查找命名窗口:

wmctrl -l <title>

For getting focus: 为了获得关注:

wmctrl -a <title>

Works well even when partial title is used, therefore I could easily replace the tests written for User32 native library. 即使使用部分标题,效果也很好,因此我可以轻松替换为User32本机库编写的测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM