检测合成器是否为 运行

Detect if compositor is running

我希望我的 UI 根据屏幕是否合成(从而支持某些效果)来更改设计。是否可以

解法:

为了向不太熟悉 X11 的人详细说明 Andrey Sidorov 的正确答案 API,这是检测符合 EWMH 的合成器的代码:

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 的合成器 must acquire ownership of a selection named _NET_WM_CM_Sn, where n is the screen number

要跟踪合成器,您需要使用 XGetSelectionOwner 检查选择 _NET_WM_CM_S0 是否归任何人所有(假设您在屏幕 0 上)。如果不拥有,请自行获取所有权并监视 SelectionClear 事件以检测合成器何时启动。