summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-08-25 21:49:46 +0200
committerAki <please@ignore.pl>2021-08-25 21:49:46 +0200
commita0334d3350556b92b12d4f4e62bd7b91cee5d3f8 (patch)
tree9fc283913c81686b2cc7104980c275619f0a2f89
parentb4ef9730e22e3232415c89ca288b6d3f1a7f5e4b (diff)
downloadclipfs-a0334d3350556b92b12d4f4e62bd7b91cee5d3f8.zip
clipfs-a0334d3350556b92b12d4f4e62bd7b91cee5d3f8.tar.gz
clipfs-a0334d3350556b92b12d4f4e62bd7b91cee5d3f8.tar.bz2
Added selection owner check before updating
-rw-r--r--clipfs.c9
1 files 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;