From 85b0e5a78d218597a3d217905edeeea07e8ce13c Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 26 Aug 2021 18:36:56 +0200 Subject: Exported owner lookup to an utility function --- clipfs.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/clipfs.c b/clipfs.c index 488b57e..48f27e8 100644 --- a/clipfs.c +++ b/clipfs.c @@ -18,6 +18,7 @@ struct selection }; int get_selection_index(const char *); +xcb_window_t find_owner(int); void update_selection(int); xcb_atom_t get_atom(xcb_connection_t *, const char *); int clip_getattr(const char *, struct stat *, struct fuse_file_info *); @@ -69,15 +70,23 @@ int get_selection_index(const char * path) } +xcb_window_t find_owner(const int i) +{ + xcb_get_selection_owner_cookie_t cookie = xcb_get_selection_owner(c, x[i].atom); + xcb_get_selection_owner_reply_t * reply = xcb_get_selection_owner_reply(c, cookie, NULL); + xcb_window_t owner = XCB_WINDOW_NONE; + if (reply) + owner = reply->owner; + free(reply); + return owner; +} + + 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. - 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) + xcb_atom_t UTF8_STRING = get_atom(c, "UTF8_STRING"); // TODO: Look into ways to support various TARGETS. + if (XCB_WINDOW_NONE == find_owner(i)) return; xcb_convert_selection(c, w, x[i].atom, UTF8_STRING, TARGET_PROPERTY, XCB_CURRENT_TIME); xcb_flush(c); -- cgit v1.1