如何在Gnome Wayland上获得活动窗口?

问题描述 投票:29回答:2

背景:我正在研究一种名为ActivityWatch的软件,它可以记录您在计算机上执行的操作。基本上是尝试解决一些问题:RescueTime,selfspy,arbtt等。

我们做的核心事情之一是关于活动窗口(类和标题)的日志信息。在过去,这已经在Linux上使用xprop和现在的python-xlib而没有问题。

但现在我们遇到了一个问题:Wayland正在崛起,据我所知,Wayland没有一个活跃窗口的概念。因此,我担心我们必须为Wayland可用的每个桌面环境实施支持(假设它们将提供获取有关活动窗口的信息的能力)。

希望他们最终能够融合并拥有一些共同的界面来完成这项工作,但我并没有屏住呼吸......

我一直是anticipating this issue。但今天我们得到了一个真正的Wayland用户的first user request for Wayland support。由于较大的发行版采用Wayland作为默认的显示服务器协议(Fedora 25已经在使用它,Ubuntu将在17.10中切换即将推出)随着时间的推移情况将变得更加重要。

ActivityWatch的相关问题:

还有其他应用程序,如ActivityWatch,需要相同的功能(RescueTime,arbtt,selfspy等),他们似乎现在似乎不支持Wayland,我找不到任何有关他们计划这样做的细节。

我现在有兴趣实现对Gnome的支持,从而开始并跟进其他人,因为路径变得更加清晰。

关于韦斯顿的类似问题在这里被问到:get the list of active windows in wayland weston

编辑:我在Freenode的#wayland问道,得到了以下回复:

15:20:44  ErikBjare    Hello everybody. I'm working on a piece of self-tracking software called ActivityWatch (https://github.com/ActivityWatch/activitywatch). I know this isn't exactly the right place to ask, but I was wondering if anyone knew anything about getting the active window in any Wayland-using DE.
15:20:57  ErikBjare    Created a question on SO: https://stackoverflow.com/questions/45465016/how-do-i-get-the-active-window-on-gnome-wayland
15:21:25  ErikBjare    Here's the issue in my repo for it: https://github.com/ActivityWatch/activitywatch/issues/92
15:22:54  ErikBjare    There are a bunch of other applications that depend on it (RescueTime, selfspy, arbtt, ulogme, etc.) so they'd need it as well
15:24:23  blocage      ErikBjare, in the core protocol you cannot know which windnow has the keyboard or cursor focus
15:24:39  blocage      ErikBjare, in the wayland core protocol *
15:25:10  blocage      ErikBjare, you can just know if your window has the focus or not, it a design choise
15:25:23  blocage      avoid client spying each other
15:25:25  ErikBjare    blocage: I'm aware, that's my reason for concern. I'm not saying it should be included or anything, but as it looks now every DE would need to implement it themselves if these kind of applications are to be supported
15:25:46  ErikBjare    So wondering if anyone knew the teams working with Wayland on Gnome for example
15:26:11  ErikBjare    But thanks for confirming
15:26:29  blocage      ErikBjare, DE should create a custom extension, or use D-bus or other IPC
15:27:31  blocage      ErikBjare, I guess some compositor are around here, but I do not know myself if there is such extension already
15:27:44  blocage      compositor developers *
15:28:36  ErikBjare    I don't think there is (I've done quite a bit of searching), so I guess I need to catch the attention of some DE developers
15:29:16  ErikBjare    Thanks a lot though
15:29:42  ErikBjare    blocage: Would you mind if I shared logs of our conversation in the issue?                                     
15:30:05  blocage      just use it :) it's public                                                                                               
15:30:19  ErikBjare    ty :)

编辑2:提起enhancement issue in the Gnome bugtracker

tl; dr:使用Wayland时如何获得Gnome上的活动窗口?

python gnome gnome-3 wayland
2个回答
1
投票

在我看来,你所拥有的最好的选择不是Wayland或任何可用的图书馆(没有一个)。实际上谁知道在gnome-wayland中关于活动窗口的是Mutter,所以你需要找到一种方法来向Mutter询问活动窗口。 Gnome可以开发API以在内部要求改变活动窗口并恢复功能。但实际上,你没有地方可以要求它。 Mutter不会开发一个API来访问他的内部表示,因为这只是Mutter的特定而不是所有Wayland的Windows管理器。因此需要将其添加到外部库中,此库可能与当前窗口管理器通信,该管理器正在使用它以一般方式解析您的请求。

另一个可能性是添加Wayland插件,其中所有窗口管理器将有一种方式来共享当前活动窗口,并以某种方式与库直接对话以恢复功能。

所以,你的应用程序是一个大问题。你可以做的最多就是在mutter上请求它(在哪里知道活动的窗口),但在我看来它无法在Mutter中解决。

我希望这对你有所帮助,你可以找到一种方法。好loock。


-2
投票

我有一个名为preguiça.py的脚本,它正是你正在做的事情,虽然它可能更简单,我还没有发布它。

对于我的脚本,我使用PyGObject的Window Navigator Construction Kit(Wnck)获取了窗口标题。

这是它的简化版本,包括以下部分:

from gi.repository import Wnck
from gi.repository import GObject

def changed (screen, window, data):
    print ("Changed!")
#    window = screen.get_active_window()
    if window:
        print ("Title: %s" % window.get_name())

screen = Wnck.Screen.get_default ()
screen.connect ("active-window-changed", changed, None)

mainLoop = GObject.MainLoop ()

try:
    mainLoop.run ()
except KeyboardInterrupt:
    print ("Hey")

mainLoop.unref ()

您要问的实际代码实际上是在上面的示例中注释掉的(我不需要捕获窗口,因为回调已经接收到它),但您可能需要它,具体取决于您的实现。

我为X写了它,当我切换到Wayland时它并没有抱怨,所以它应该适合你。

请注意,它没有像Wayland那样从Wayland获取信息,但它实际上可能更好,因为它将与X / Wayland无关。它得到了我打开的xterm的标题,所以它应该是与工具箱无关的。

但是,请不要问我有关实施细节的问题。代码至少有四年了:)

© www.soinside.com 2019 - 2024. All rights reserved.