首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Gnome/Wayland会话上从Mutter检索活动窗口

在Gnome/Wayland会话上从Mutter检索活动窗口
EN

Stack Overflow用户
提问于 2018-02-15 06:33:17
回答 1查看 895关注 0票数 3

我正在尝试编写一个应用程序,根据活动的应用程序向不同的应用程序发送不同的dBus信号。我们的想法是将其与Libinput-gestures配对,并允许每个应用程序的手势响应。问题是,不可能知道哪个应用程序在客户端处于活动状态。

我一直在做一些研究,以检测应用程序是否专注于Wayland下的某个特定窗口管理器。共识是,Wayland不知道应用程序是否有焦点,也不会给出这些信息。但是,窗口管理器本身并不知道。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-24 12:59:37

快2岁了,但它开始了!!我不确定Mutter是否也有办法做到这一点,或者有没有更好的办法来做下面的事情。我怀疑,随着对gdbus更好的了解和进一步的研究,你也可以将其转换为某种官方的gdbus监控,可以与其他应用程序通信,这样你就不需要ping状态了。

这是特定于Gnome的,我怀疑它至少可以在3.15+上工作。在Ubuntu 19.10 Wayland上测试。(Gnome 3.34.2)

代码语言:javascript
复制
# 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上为任何感兴趣的人做一些类似的KDE5等离子。(将一些代码添加到已检索类名的现有等价物中。)

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48797323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档