Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement proper handling of the _NET_CM_Sn selection #320

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/compton.c
Original file line number Diff line number Diff line change
Expand Up @@ -3320,7 +3320,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);
}

Expand Down Expand Up @@ -4348,6 +4349,16 @@ ev_screen_change_notify(session_t *ps,
}
}

inline static void
ev_selection_clear(session_t *ps,
XSelectionClearEvent __attribute__((unused)) *ev) {
// The only selection we own is the _NET_WM_CM_Sn selection.
// If we lose that one, we should exit.
fprintf(stderr, "Another composite manager started and "
"took the _NET_WM_CM_Sn selection.\n");
exit(1);
}

#if defined(DEBUG_EVENTS) || defined(DEBUG_RESTACK)
/**
* Get a window's name from window ID.
Expand Down Expand Up @@ -4440,6 +4451,9 @@ ev_handle(session_t *ps, XEvent *ev) {
case PropertyNotify:
ev_property_notify(ps, (XPropertyEvent *)ev);
break;
case SelectionClear:
ev_selection_clear(ps, (XSelectionClearEvent *)ev);
break;
default:
if (ps->shape_exists && ev->type == ps->shape_event) {
ev_shape_notify(ps, (XShapeEvent *) ev);
Expand Down Expand Up @@ -4892,6 +4906,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;
Expand All @@ -4901,7 +4916,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);
}

Expand Down