wmctrl的替代品有哪些?

时间:2021-08-14 16:57:27

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)。

6 个解决方案

#1


11  

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:

从那里,您可以提取所需的内容,或者让它只显示所需的字段,就像我在上面提取_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。

#2


9  

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 does exit 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获取活动窗口的信息是很尴尬的,但这是可能的。

#3


2  

xdotool is a reasonable alternative (github project here), although unfortunately the author doesn't seem to care about it much any more.

xdotool是一种合理的选择(这里是github项目),但不幸的是,作者似乎不再关心它了。

#4


1  

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窗口,在这里是metacity。这个管理器似乎重新命名了windows,这可能导致wmctrl没有列出firefox windows。“xwininfo”确实列出了firefox的windows。

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 $1; 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——windows $mywin 0”。

Note: I had the same problem with finding Konqueror windows on the same Linux systems.

注意:我在同一个Linux系统上找到Konqueror窗口时遇到了同样的问题。

#5


1  

window id

窗口id

wmctrl -a :ACTIVE: -v 2>&1 | grep "Using window: " | awk "{print \$3}"

#6


1  

You can check xdo which can do a decent job with minimal ressources.

您可以检查xdo,它可以做一个体面的工作,以最小的资源。

#1


11  

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:

从那里,您可以提取所需的内容,或者让它只显示所需的字段,就像我在上面提取_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。

#2


9  

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 does exit 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获取活动窗口的信息是很尴尬的,但这是可能的。

#3


2  

xdotool is a reasonable alternative (github project here), although unfortunately the author doesn't seem to care about it much any more.

xdotool是一种合理的选择(这里是github项目),但不幸的是,作者似乎不再关心它了。

#4


1  

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窗口,在这里是metacity。这个管理器似乎重新命名了windows,这可能导致wmctrl没有列出firefox windows。“xwininfo”确实列出了firefox的windows。

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 $1; 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——windows $mywin 0”。

Note: I had the same problem with finding Konqueror windows on the same Linux systems.

注意:我在同一个Linux系统上找到Konqueror窗口时遇到了同样的问题。

#5


1  

window id

窗口id

wmctrl -a :ACTIVE: -v 2>&1 | grep "Using window: " | awk "{print \$3}"

#6


1  

You can check xdo which can do a decent job with minimal ressources.

您可以检查xdo,它可以做一个体面的工作,以最小的资源。