Pet*_*der 5 gnome active-window wayland
我正在尝试编写一个应用程序,根据活动的应用程序将不同的 dBus 信号发送到不同的应用程序。这个想法是将其与 Libinput 手势配对,并允许每个应用程序手势响应。问题是,无法判断哪个应用程序在客户端处于活动状态。
我一直在做一些研究来检测应用程序是否关注 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
Run Code Online (Sandbox Code Playgroud)
这是我给自己做的一个要点,与上面的代码相同。https://gist.github.com/rbreaves/257c3edfa301786e66e964d7ac036269
我还有一个非 gdbus 方法,可以在我的 github 上的 Wayland 下为 KDE5 Plasma 做类似的事情,供任何感兴趣的人使用。(向已检索类名的现有 Plasmoid 添加了一些代码。)
| 归档时间: |
|
| 查看次数: |
2442 次 |
| 最近记录: |