问题描述
我希望我的 UI 根据屏幕是否合成(从而支持某些效果)来更改设计.可以吗
I want my UI to change design depending on whether the screen is composited (thus supporting certain effects) or not. Is it possible to
- 可靠地查询 X 服务器是否正在运行合成窗口管理器
- 在打开/关闭合成时收到通知?
解决方案:
为了向不太熟悉 X11 API 的人详细说明 Andrey Sidorov 的正确答案,这是用于检测符合 EWMH 的合成器的代码:
To elaborate on Andrey Sidorov's correct answer for people not so familiar with the X11 API, this is the code for detecting a EWMH-compliant compositor:
int has_compositor(Display *dpy, int screen) {
char prop_name[20];
snprintf(prop_name, 20, "_NET_WM_CM_S%d", screen);
Atom prop_atom = XInternAtom(dpy, prop_name, False);
return XGetSelectionOwner(dpy, prop_atom) != None;
}
推荐答案
符合 EWMH 的合成器 必须获得名为 _NET_WM_CM_Sn 的选择的所有权,其中 n 是屏幕编号
EWMH-compliant compositors must acquire ownership of a selection named _NET_WM_CM_Sn, where n is the screen number
要跟踪合成器,您需要使用 XGetSelectionOwner
检查选择是否属于 _NET_WM_CM_S0
的所有人(假设您在屏幕 0 上).如果未拥有,请自行获取所有权并监控 SelectionClear 检测合成器何时启动的事件.
To track compositor you'll need to check if selection is _NET_WM_CM_S0
is owned by anyone (assuming you are on screen 0) using XGetSelectionOwner
. If not owned, acquire ownership yourself and monitor SelectionClear events to detect when compositor is started.
这篇关于检测合成器是否正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!