X11,如何检测我是显示屏上的最后一个窗口/应用程序

发布于 2024-08-29 22:55:34 字数 297 浏览 8 评论 0原文

我有一个 x11 显示器,带有窗口管理器(遗憾的是不是特定的,可能是 twm、dtwm、mwm、metacity …)、myApp 和其他带有窗口的应用程序。如果其他应用程序关闭并且 myApp 是显示屏上唯一一个带有窗口的应用程序,我想关闭显示屏。我确实知道 myApp 的窗口,但是我如何区分 windowmanger 的窗口和其他应用程序的窗口。

我目前正在使用 xwininfo -tree -root -children 进行轮询,并将其与我的预期进行比较,但这仅适用于“明确定义”的环境。

看来上面提到的许多窗口管理器都不支持EWMH。

I have an x11 display with a windowmanager (sadly not a specific one, could be twm, dtwm, mwm, metacity …) , myApp and other applications with windows. I want to close the display if the other applications are closed and myApp is the only one with windows on the display. I do know the windows of myApp, but how do I distinguish between the windows of the windowmanger and of the other applications.

I’m currently polling with xwininfo -tree -root -children and comparing this to what I’m expecting, but this only works in a ‘well defined’ environment.

It seems that many of the above mentioned windowmanager don’t support EWMH.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合约呢 2024-09-05 22:55:34

不会有一种完全不 hacky 的方法。

ICCCM 建议通过查找 WM_STATE 属性来识别顶级窗口(尤其是 WM 帧)。所以你可以用它来区分应用程序窗口。但是,当 WM 将窗口重新设置为框架时,在框架窗口内找到应用程序窗口将变得很棘手。您必须实现一个小程序来执行类似 xwininfo -tree 的操作,但仅检查设置了 WM_STATE 的窗口。

一个相对不错的解决方案是使用 libwnck 或基于它的工具之一(wmctrl,devil's pie)。然而,这需要一个 EWMH 窗口管理器(其中包括任何远程现代或理智的东西,但听起来你正在处理一些非常古老的、脾气暴躁的东西)。
这些工具的优点是它们使用 EWMH 来识别应用程序窗口,甚至这些应用程序窗口的语义类型(对话框等)。

另外,libwnck 消除了轮询的需要,它可以只监视顶层窗口列表中的更改。

There isn't going to be a completely non-hacky way.

The ICCCM recommends identifying toplevel windows (as opposed in particular to WM frames) by looking for the WM_STATE property. So you could distinguish application windows with that. However, when the WM reparents the window into a frame it'll get tricky to find the app window inside the frame window. You'd have to implement a little program to do something like xwininfo -tree but only check for windows with WM_STATE set.

A relatively nice solution would be to use libwnck, or one of the tools based on it (wmctrl, devil's pie). However, this requires an EWMH window manager (which includes anything remotely modern or sane, but it sounds like you are dealing with some really old curmudgeonly stuff).
The advantage of these tools is that they use EWMH to identify application windows and even the semantic type of those application windows (dialog, etc.).

Also, libwnck removes the need to poll, it can just watch for changes in the toplevel window list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文