From f8ea3e8668ab09e305fa8c0f148d02eb6ea622b8 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 24 Oct 2015 12:32:55 +0200 Subject: [PATCH] Don't steal the _NET_WM_CM_Sn selection (#301) Before becoming the selection owner for _NET_WM_CM_Sn, compton will now check if that selection is already owned (which means that another composite manager is already running). If this check fails, startup will be refused. This behaviour is required by EWMH / ICCCM. Because this should catch all composite managers, the error message that was used before when another manager is already running is reworded to mention that the other manager does not follow EWMH. Signed-off-by: Uli Schlachter --- src/compton.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/compton.c b/src/compton.c index 23606fb4..31eff5f3 100644 --- a/src/compton.c +++ b/src/compton.c @@ -3323,7 +3323,8 @@ xerror(Display __attribute__((unused)) *dpy, XErrorEvent *ev) { if (ev->request_code == ps->composite_opcode && ev->minor_code == X_CompositeRedirectSubwindows) { - fprintf(stderr, "Another composite manager is already running\n"); + fprintf(stderr, "Another composite manager is already running " + "(and does not handle _NET_WM_CM_Sn correctly)\n"); exit(1); } @@ -4895,6 +4896,7 @@ register_cm(session_t *ps) { if (!ps->o.no_x_selection) { unsigned len = strlen(REGISTER_PROP) + 2; int s = ps->scr; + Atom atom; while (s >= 10) { ++len; @@ -4904,7 +4906,13 @@ register_cm(session_t *ps) { char *buf = malloc(len); snprintf(buf, len, REGISTER_PROP "%d", ps->scr); buf[len - 1] = '\0'; - XSetSelectionOwner(ps->dpy, get_atom(ps, buf), ps->reg_win, 0); + atom = get_atom(ps, buf); + + if (XGetSelectionOwner(ps->dpy, atom) != None) { + fprintf(stderr, "Another composite manager is already running\n"); + return false; + } + XSetSelectionOwner(ps->dpy, atom, ps->reg_win, 0); free(buf); }