Fabian Knorr
Fabian Knorr

Reputation: 3184

Detect if compositor is running

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

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

Upvotes: 3

Views: 2870

Answers (1)

Andrey Sidorov
Andrey Sidorov

Reputation: 25456

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.

Upvotes: 5

Related Questions