我最近安装了 Ubuntu 17.10,它使用 Wayland 而不是(或某种组合?)X11。在我可以使用xprop -root|grep ^_NET_CLIENT_LIST
或 wmctrl ( wmctrl -lpGxu
) 获取所有活动窗口的列表之前。这不再适用于所有 gnome 应用程序(如终端)和其他一些应用程序(如 Nautlius)。有没有办法列出这些?
是啊,在韦兰,可悲的Xorg公用事业喜欢wmctrl
和xdotool
不工作。相反,我们可以与窗口管理器交谈。
对于 Gnome,我们可以运行gdbus
以发送 DBUS 消息来执行一些 GJS(GNOME C API 的 JavaScript 绑定)。
要获取窗口列表,以及它们的类和标题(使用sed
和jq
美化):
$ gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /org/gnome/Shell \
--method org.gnome.Shell.Eval "
global
.get_window_actors()
.map(a=>a.meta_window)
.map(w=>({class: w.get_wm_class(), title: w.get_title()}))" \
| sed -E -e "s/^\(\S+, '//" -e "s/'\)$//" \
| jq .
Run Code Online (Sandbox Code Playgroud)
示例输出:
[
{
"class": "firefox",
"title": "Mozilla Firefox"
},
{
"class": "org.gnome.Nautilus",
"title": "Downloads"
},
{
"class": "Google-chrome",
"title": "ubuntu - Bash command to focus a specific window - Super User - Google Chrome"
},
{
"class": "sublime_text",
"title": "untitled (dotfiles) - Sublime Text"
},
{
"class": "gnome-terminal-server",
"title": "Projects"
},
{
"class": "Gnome-shell",
"title": "gnome-shell"
}
]
Run Code Online (Sandbox Code Playgroud)
获取当前聚焦窗口的类:
$ gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /org/gnome/Shell \
--method org.gnome.Shell.Eval "
global
.get_window_actors()
.map(a=>a.meta_window)
.find(w=>w.has_focus())
.get_wm_class()" \
| cut -d'"' -f 2
gnome-terminal-server
Run Code Online (Sandbox Code Playgroud)
您可以使用 Gnome 的“Looking Glass”调试器:Alt+F2 尝试 GJS 中的可能功能,然后运行 lg
归档时间: |
|
查看次数: |
2201 次 |
最近记录: |