Convert XGetSelectionOwner to XCB

This also fixes a memory leak: buf was not freed if another composite
manager was already running.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2018-10-03 14:20:33 +02:00 committed by Yuxuan Shui
parent 2dc90e7d4d
commit 1b1b3456bc
1 changed files with 8 additions and 2 deletions

View File

@ -3562,13 +3562,19 @@ register_cm(session_t *ps) {
snprintf(buf, len, REGISTER_PROP "%d", ps->scr);
buf[len - 1] = '\0';
atom = get_atom(ps, buf);
free(buf);
if (XGetSelectionOwner(ps->dpy, atom) != None) {
xcb_get_selection_owner_reply_t *reply =
xcb_get_selection_owner_reply(c,
xcb_get_selection_owner(c, atom), NULL);
if (reply && reply->owner != XCB_NONE) {
free(reply);
fprintf(stderr, "Another composite manager is already running\n");
return false;
}
free(reply);
xcb_set_selection_owner(c, ps->reg_win, atom, 0);
free(buf);
}
return true;