Detect if compositor is running

会有一股神秘感。 提交于 2021-02-07 04:19:22

问题


I want my UI to change design depending on whether the screen is composited (thus supporting certain effects) or not. Is it possible to

  • Reliably query whether the X server is running a compositing window manager
  • Get notified when compositing is switched on/off?

Solution:

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;
}

回答1:


EWMH-compliant compositors must acquire ownership of a selection named _NET_WM_CM_Sn, where n is the screen number

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.



来源:https://stackoverflow.com/questions/33195570/detect-if-compositor-is-running

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!