From a0334d3350556b92b12d4f4e62bd7b91cee5d3f8 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 25 Aug 2021 21:49:46 +0200 Subject: Added selection owner check before updating --- clipfs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clipfs.c b/clipfs.c index 303defd..488b57e 100644 --- a/clipfs.c +++ b/clipfs.c @@ -53,7 +53,7 @@ int main(int argc, char ** argv) c, XCB_COPY_FROM_PARENT, w, s->root, 0, 0, 1, 1, 0, XCB_COPY_FROM_PARENT, s->root_visual, mask, values); xcb_flush(c); x[0].atom = get_atom(c, "PRIMARY"); - x[1].atom = get_atom(c, "PRIMARY"); // TODO: This is intentional until update can recognize missing selection. + x[1].atom = get_atom(c, "SECONDARY"); x[2].atom = get_atom(c, "CLIPBOARD"); fuse_main(argc, argv, &clip_ops, NULL); xcb_disconnect(c); @@ -73,7 +73,12 @@ void update_selection(const int i) { xcb_atom_t TARGET_PROPERTY = get_atom(c, "_TARGET_SELECTION"); xcb_atom_t UTF8_STRING = get_atom(c, "UTF8_STRING"); // TODO: Actually, focus on "rawest" format at first. - // TODO-maybe: Look for the selection owner first? + xcb_get_selection_owner_cookie_t owner_cookie = xcb_get_selection_owner(c, x[i].atom); + xcb_get_selection_owner_reply_t * owner = xcb_get_selection_owner_reply(c, owner_cookie, NULL); + xcb_window_t owner_window = owner->owner; + free(owner); + if (XCB_WINDOW_NONE == owner_window) + return; xcb_convert_selection(c, w, x[i].atom, UTF8_STRING, TARGET_PROPERTY, XCB_CURRENT_TIME); xcb_flush(c); xcb_generic_event_t * e; -- cgit v1.1