如何获得Gnome Wayland上的活动窗口?
背景:
我正在开发一款名为ActivityWatch的软件,该软件可以记录您在计算机上所做的事情。基本上是尝试解决以下问题:RescueTime,selfspy,arbtt等。
我们要做的核心工作之一是记录有关活动窗口的信息(类和标题)。过去,这是在Linux上使用xprop和python-xlib毫无问题地完成的。
但是现在我们有一个问题:
Wayland正在上升,据我所知,Wayland没有活动窗口的概念。因此,我担心我们将不得不为Wayland可用的每个桌面环境实现支持(假设它们将提供获取有关活动窗口的信息的功能)。
希望他们最终会融合在一起,并拥有一些通用的界面来完成此操作,但我不会屏住呼吸…
我一直在期待这个问题。但是今天,我们收到了第一个用户请求,一个实际的Wayland用户对Wayland支持。随着更大的发行版将Wayland用作默认显示服务器协议(Fedora
25已经在使用它,Ubuntu将在即将推出的17.10中进行切换),随着时间的流逝,情况将变得越来越关键。
ActivityWatch的相关问题:
- https://github.com/ActivityWatch/aw-watcher-window/issues/18
- https://github.com/ActivityWatch/activitywatch/issues/92
像ActivityWatch这样的其他应用程序也需要相同的功能(RescueTime,arbtt,selfspy等),它们似乎暂时不支持Wayland,我无法找到计划这样做的任何细节。
我现在有兴趣实施对Gnome的支持,以便 随着路径的发展变得更加清晰 , 并与其他人 一起 跟进。
关于韦斯顿的类似问题已在这里提出:获取韦兰·韦斯顿的活动窗口列表
编辑: 我在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: 在Gnome
bugtracker中提出了一个增强问题。
tl; dr: 使用Wayland时如何在Gnome上获得活动窗口?
-
前面的两个答案已经过时,这是在(Gnome)Wayland中查询应用名称和窗口标题的当前状态。
- 可以通过DBus访问的特定于Gnome的JavaScript API
- wlr-foreign-top-management Wayland协议(不幸的是,Gnome并未实现)
特定于Gnome的API可能会在Gnome版本之间中断,但它可以工作。它在很大程度上依赖于Gnome内部API的工作,因此没有机会成为标准API。在aw-
watcher窗口上有一个PR可以添加它,但是如果可能的话,它需要一些清理和afk支持。该WLR-国外顶级管理协议(在写这篇的时间)由挥洒热血,Phosh和Wayfire排字实施。与Wayland合成器广泛使用的idle.xml协议一起,在aw-
watcher-window-wayland中有一个完整的实现,其中带有ActivityWatch的afk-detection 。我一直在与sway /
rootston开发人员讨论过Wayland应用程序名称和X11
wm_class是否可互换,并且Sway和Phosh现在都可以互换使用,因此API中Wayland和XWayland窗口之间不再存在任何可区别的区别。我还没有研究过KWin是否具有类似于Gnome Shell的API来获取应用程序名称和标题,但它至少没有实现wlr-foreign-toplevel-
management。