Linux wmctrl 的替代品是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4272232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are the alternatives to wmctrl?
提问by joeytwiddle
Do you know of any alternatives to wmctrl? A program that lets you manipulate windows and window management from the command line.
你知道 wmctrl 的任何替代品吗?一个让你从命令行操作窗口和窗口管理的程序。
One drawback with wmctrl is that whilst you can manipulate the current window, you cannot get wmctrl to list information about the current window (it ignores -r).
wmctrl 的一个缺点是,虽然您可以操作当前窗口,但您无法让 wmctrl 列出有关当前窗口的信息(它忽略 -r)。
回答by Deven T. Corzine
You can trick wmctrl into outputting the ID number of the active window by turning on verbose mode and telling it to move the active window with an invalid parameter:
您可以通过打开详细模式并告诉 wmctrl 使用无效参数移动活动窗口来欺骗 wmctrl 输出活动窗口的 ID 号:
wmctrl -v -r :ACTIVE: -e dummy
While this doesexit with an error status, it also outputs the ID number of the active window:
虽然这确实以错误状态退出,但它还会输出活动窗口的 ID 号:
envir_utf8: 1
Using window: 0x08400004
The -e option expects a list of comma separated integers: "gravity,X,Y,width,height"
Once you have the ID number of the active window, you can list all the windows and search for that ID number:
获得活动窗口的 ID 号后,您可以列出所有窗口并搜索该 ID 号:
wmctrl -l
It's awkward to get information about the active window with wmctrl, but it's possible.
使用 wmctrl 获取有关活动窗口的信息很尴尬,但这是可能的。
回答by Amir
To find the id of the currently active window, use:
要查找当前活动窗口的 id,请使用:
xprop -root -f _NET_ACTIVE_WINDOW 0x " $0\n" _NET_ACTIVE_WINDOW | awk "{print $2}"
Using this id, you can then get a lot of information about the currently active window:
使用此 id,您可以获取有关当前活动窗口的大量信息:
xprop -id $(xprop -root -f _NET_ACTIVE_WINDOW 0x " $0\n" _NET_ACTIVE_WINDOW | awk "{print $2}")
From there, you can grep
what you need, or make it show just the desired field the same way I extracted _NET_ACTIVE_WINDOW
above. So, to find the PID of the currently active window, you would append -f _NET_WM_PID 0c " \$0\\n" _NET_WM_PID
to the command above, making it:
从那里,您可以选择grep
您需要的内容,或者按照我_NET_ACTIVE_WINDOW
在上面提取的方式使其仅显示所需的字段。因此,要查找当前活动窗口的 PID,您可以附加-f _NET_WM_PID 0c " \$0\\n" _NET_WM_PID
到上面的命令,使其:
xprop -id $(xprop -root -f _NET_ACTIVE_WINDOW 0x " $0\n" _NET_ACTIVE_WINDOW | awk "{print $2}") -f _NET_WM_PID 0c " $0\n" _NET_WM_PID | awk "{print $2}"
Note that wmctrl
also accepts the same kind of id in combination with the -i
flag.
请注意,wmctrl
它还接受与-i
标志组合的相同类型的 id 。
回答by Adam Spiers
xdotoolis a reasonable alternative (github project here), although unfortunately the author doesn't seem to care about it much any more.
xdotool是一个合理的选择(这里是github 项目),尽管不幸的是作者似乎不再关心它了。
回答by dinman2022
My experience with wmctrl version 1.07 under RH Linux 5.5 and 5.6 64-bits is that wmctrl gets completely lost at times. For instance, when looking for a firefox window the following returns nothing:
我在 RH Linux 5.5 和 5.6 64 位下使用 wmctrl 1.07 版的经验是 wmctrl 有时会完全丢失。例如,在查找 Firefox 窗口时,以下内容不返回任何内容:
% wmctrl -lpGx | grep -i 'Firefox'
My suspicion is that wmcntl cannot find firefox windows due to the nature of the window manager, in this case, metacity. This manager seems to reparent windows and perhaps this causes wmctrl not to list firefox windows. 'xwininfo' does list the firefox windows.
我怀疑 wmcntl 由于窗口管理器的性质(在本例中为元城市)而无法找到 Firefox 窗口。这个管理器似乎重新设置了窗口的父级,也许这会导致 wmctrl 不列出 Firefox 窗口。'xwininfo' 确实列出了 Firefox 窗口。
If you have access to xdotool (my version is 2.20110530.1) then you can try:
如果您可以访问 xdotool(我的版本是 2.20110530.1),那么您可以尝试:
% mywin=`xwininfo -root -tree | awk '/- Mozilla Firefox/ { printf ; exit}'`
% xdotool windowactivate --sync $mywin mousemove --window $mywin 0 0
This makes firefox active, makes it the top window in the stack on your desktop, and puts the mouse over it (as is sometimes needed when a user's environment sets focus to a window under the mouse without requiring a click.) If you don't want the mouse to move simply remove 'mousemove --window $mywin 0 0' from the above.
这使 Firefox 处于活动状态,使其成为桌面堆栈中的顶部窗口,并将鼠标放在它上面(当用户环境将焦点设置到鼠标下的窗口而不需要单击时,有时需要这样做。)如果您不这样做不希望鼠标移动,只需从上面删除 'mousemove --window $mywin 0 0'。
Note: I had the same problem with finding Konqueror windows on the same Linux systems.
注意:我在相同的 Linux 系统上找到 Konqueror 窗口时遇到了同样的问题。
回答by 吴毅凡
window id
窗口编号
wmctrl -a :ACTIVE: -v 2>&1 | grep "Using window: " | awk "{print $3}"