鉴于https://unix.stackexchange.com/a/254854/674和https://unix.stackexchange.com/questions/458895/how-can-i-bring-a-background-gui-job-to -the-front-of-my-desktop,xdotool 的联机帮助页中有一个示例
# Activate google-chrome when you move the mouse to the bottom-left corner:
xdotool behave_screen_edge bottom-left search --class google-chrome windowactivate
Run Code Online (Sandbox Code Playgroud)
手册页说
--class 与窗口类匹配。
--classname 与窗口类名匹配。
什么是“类”和“类名”?
它们有哪些可能的值?
如何找出窗口的类和类名?
谢谢。
Ser*_*nyy 28
在 X11 下,窗口具有 XWindowdAttributes 结构和XClassHint 结构 属性,应用程序从中获取有关窗口的信息。特别是最后一个负责WM_CLASS属性,两个逗号分隔的字符串,通过xprop命令可以很容易地看到。例如,Chrome 有
WM_CLASS(STRING) = "google-chrome", "Google-chrome"
Run Code Online (Sandbox Code Playgroud)
这两个记录为:
- 一个字符串,用于命名拥有此窗口的客户端所属的应用程序的特定实例。...
- 一个字符串,用于命名拥有此窗口的客户端所属的应用程序的一般类。由类指定的资源适用于所有具有相同类名的应用程序......
因此,例如 Chrome 的环聊扩展,具有相同的类名,但不同的实例名:
$ xprop | grep 'CLASS'
WM_CLASS(STRING) = "crx_nckgahadagoaajjgafhacjanaoiihapd", "Google-chrome"
Run Code Online (Sandbox Code Playgroud)
这允许诸如xdotool搜索特定应用程序类型或特定窗口实例的所有窗口之类的工具。例如,这对于诸如将窗口分组到应用程序的同一图标下的停靠栏之类的东西也很有用。
特别是对于xdotool,classname对应第一个字符串,class对应第二个字符串。在我使用 Chrome 和环聊应用的示例中:
$ xdotool search -classname crx_nckgahadagoaajjgafhacjanaoiihapd
96469129
$ xdotool search -class Google-chrome
96469069
109051905
109051907
96468993
96469129
109051912
109051924
Run Code Online (Sandbox Code Playgroud)
这也可以从查看源代码中明显看出。例如,让我们关注类名。在cmd_search.c 中,我们构建了一个搜索结构,它具有搜索掩码属性(第 171 到 173 行)。
这被传递给xdo_search_windows在定义函数xdo_search.c,进而调用check_window_match,这反过来去 _xdo_match_window_classname,最终结束了检索,两种结构都在这个答案与标准开头提到的Xlib功能XGetWindowAttributes和XGetClassHint。
旁注:Gtk 应用程序显然总是创建一个带有子窗口的小型父窗口,这意味着您在搜索特定窗口时可能会得到令人困惑的结果。
Aclass将是urxvt实际上包含两者urxvt并且rxvt是 unicode rxvt 终端的那个。在classname休息的成实际名称。我将在下面展示一个例子。
我打开了 4 个 rxvt 终端窗口。
terrance-Linux:~$ xdotool search -class rxvt
130023435
127926283
125829131
132120587
terrance-Linux:~$ xdotool search -class urxvt
130023435
127926283
125829131
132120587
terrance-Linux:~$ xdotool search -classname urxvt
terrance-Linux:~$ xdotool search -classname rxvt
130023435
127926283
125829131
132120587
Run Code Online (Sandbox Code Playgroud)
然后当我启动urxvt终端时,这就是我得到的。
terrance-Linux:~$ xdotool search -classname urxvt
140509193
Run Code Online (Sandbox Code Playgroud)
使用该xprop应用程序,我们可以单击窗口,它会告诉我们WM_CLASS(STRING). 第一个是classname,第二个是class。
例子:
运行命令并单击 RXVT 终端窗口:
terrance-Linux:~$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "rxvt", "URxvt"
Run Code Online (Sandbox Code Playgroud)
单击 URXVT 窗口的相同命令:
terrance-Linux:~$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "urxvt", "URxvt"
Run Code Online (Sandbox Code Playgroud)
再次单击 Google Chrome 浏览器的相同命令:
terrance-Linux:~$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "google-chrome", "Google-chrome"
Run Code Online (Sandbox Code Playgroud)
点击一个xfce4-terminal窗口:
terrance-Linux:~$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "xfce4-terminal", "Xfce4-terminal"
Run Code Online (Sandbox Code Playgroud)
点击一个gnome-terminal窗口:
terrance-Linux:~$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "gnome-terminal-server", "Gnome-terminal"
Run Code Online (Sandbox Code Playgroud)
单击 Firefox 窗口(这是不同的):
terrance-Linux:~$ xprop | grep WM_CLASS
WM_CLASS(STRING) = "Navigator", "Firefox"
Run Code Online (Sandbox Code Playgroud)
希望这有助于传播一些差异。
| 归档时间: |
|
| 查看次数: |
23453 次 |
| 最近记录: |