gnome - 在 Gnome/Wayland session 中从 Mutter 检索事件窗口

标签 gnome wayland active-window

我正在尝试编写一个应用程序,根据事件的应用程序将不同的 dBus 信号发送到不同的应用程序。这个想法是将它与 Libinput-gestures 配对,并允许每个应用程序的手势响应。问题是,无法判断哪个应用程序在客户端处于事件状态。

我一直在做一些研究来检测应用程序是否专注于 Wayland 下的任何特定窗口管理器。共识是,Wayland 不知道应用程序是否具有焦点,并且不会提供该信息。然而,窗口管理器本身确实知道。

那么有没有办法为 gnome 创建一个完整的服务器端例程,将事件窗口客户端的标题发送到选定数量的应用程序。换句话说,我们仍然拥有不让任意应用程序了解环境的所有信息的“安全性”,但仍然允许某些具有可访问性的软件检索该信息并使用它。

最佳答案

快 2 岁了,但它来了!!我不确定 Mutter 是否也有办法做到这一点,或者是否有更好的方法来执行以下操作。我怀疑通过更好地了解 gdbus 和进一步研究,您还可以将其转换为某种官方 gdbus 监控,可以与其他应用程序通信,这样您就不必 ping 状态。

这是 Gnome 特有的,我怀疑至少适用于 3.15+。在 Ubuntu 19.10 Wayland 上测试。 (侏儒 3.34.2)

# Single Command, runs 2 calls to gdbus to get the currently active Window from Gnome 3.x
# Escaped so you can copy and paste into terminal directly
gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval global.get_window_actors\(\)[`gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval global.get_window_actors\(\).findIndex\(a\=\>a.meta_window.has_focus\(\)===true\) | cut -d"'" -f 2`].get_meta_window\(\).get_wm_class\(\) | cut -d'"' -f 2

# Unescaped version, will not run
# Broken down into 2 commands.

# Call to Gnome to get the array location of the active Application
gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval \
global.get_window_actors().findIndex(a=>a.meta_window.has_focus()===true) \
| cut -d"'" -f 2

# Replace the array number 2 with the one from the previous command and you will get the App Name of the actively focused Window
gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval \
global.get_window_actors()[2].get_meta_window().get_wm_class() \
| cut -d'"' -f 2

这是我作为给自己做的笔记的要点,与上面的代码相同。 https://gist.github.com/rbreaves/257c3edfa301786e66e964d7ac036269

我还有一个非 gdbus 方法关于如何在我的 github 上的 Wayland 下为 KDE5 Plasma 做类似的事情,供任何感兴趣的人使用。 (向已经检索类名的现有 Plasmoid 添加了一些代码。)

关于gnome - 在 Gnome/Wayland session 中从 Mutter 检索事件窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48797323/

相关文章:

韦兰的选择

centos - 错误 'bad pad value "2m": must be positive screen distance' when using tk_messageBox on a wayland display (CentOS)

python - 如何监视远程 PC 上的事件窗口

java - 如何使用Java获取全局 Activity 窗口的名称?

c - 如何获取事件窗口的名称?

eclipse - KDE下设置eclipse超链接颜色

java - 让脚本检测 gnome session

editor - UltraEdit 的最佳 Gnome 替代品?

python - 用 Python 编写的 Nautilus 扩展在调用 gtk.main() 时不会运行

linux - Qt Make 应用程序在 Weston/Wayland 平台上始终处于最前面