5

我可以使用wmctrl在 Ubuntu 上的 wine 中运行的窗口关闭一个窗口吗?

对于上下文:

$ wmctrl -m
Name: compiz
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: OFF

还:

$ wmctrl -l
0x0240a3be -1 mjol N/A
0x02000003  0 mjol Top Expanded Edge Panel
0x0200004c  0 mjol Bottom Expanded Edge Panel
0x01e00024  0 mjol x-nautilus-desktop
0x04800253  0 mjol using wmctrl to close windows - Stack Overflow - Google Chrome
0x03c0c8c3  0 mjol Terminal
0x03c53f25  0 mjol Terminal
0x04400001  0 mjol Untitled - SketchUp
0x04400003  0 mjol Instructor
0x04400009  0 mjol SketchUp

我要关闭的窗口是最后一个:

0x04400009  0 mjol SketchUp

我尝试了以下方法:

$ wmctrl -c "SketchUp"

$ wmctrl -c 0x04400009

$ wmctrl -i 0x04400009

$ wmctrl -c -i 0x04400009

但没有任何效果。

4

3 回答 3

6

也许有点晚,但现在第一次看到。阅读 wmctrl 的信息,它说正确的语法是 'options' before actions,并且-i是一个选项,-c一个动作。尝试 wmctrl -i -c 0x04400009

于 2012-10-30T14:54:33.657 回答
2

I was having the same question and just found how to do it!

Here's the one-liner that will gracefully close all Google Chrome windows:

wmctrl -lix |grep 'Google-chrome'|cut -d ' ' -f 1 |xargs -i% wmctrl -i -c %

Explanation:

wmctrl -lix list all windows including their Id and Class

grep 'Google-chrome' grep only windows with Google-chrome class (this is important because when you use a site with the app/shortcut option it gets it own class like 'calendar.google.com.Google-chrome'

cut -d ' ' -f 1 cuts the output to get only the IDs column

xargs -i% wmctrl -i -c % passes each ID to the wmctrl using the ID option -i and close command -c

Note: the xargs only worked when I used the -i option to specify replace-string. Otherwise it would only act on the first item.

于 2020-04-26T12:19:41.423 回答
1

根据手册页,您应该首先使用选择选项选择-r窗口,例如and -a,例如:

$ wmctrl -l      
0x01800006  0 hostname Terminal - byobu

$ wmctrl -a Terminal

-a这里确实选择了终端窗口(并且由于 提升了焦点)。

然后您可以使用调整大小/移动选项,例如-e gravity,X,Y,width,height

至于你的问题,我刚刚测试了这个:

$ wmctrl -l                              
0x01800006  0 machine_hostname - byobu
0x06800002  0 moe Microsoft Excel - Classeur1

当我进入时,Excel(显然在 Wine 中运行)优雅地关闭了

$ wmctrl -c Microsoft

这里有很多额外的信息。

于 2013-04-30T08:50:03.420 回答