问题
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