- if (prop_reply == NULL || xcb_get_property_value_length(prop_reply) == 0)
- return NULL;
- if (asprintf(&socket_path, "%.*s", xcb_get_property_value_length(prop_reply),
- (char*)xcb_get_property_value(prop_reply)) == -1)
- return NULL;
- xcb_disconnect(conn);
- return socket_path;
-}
+ if (prop_reply == NULL) {
+ goto out_atom;
+ }
+ if (xcb_get_property_value_length(prop_reply) > 0 && prop_reply->bytes_after > 0) {
+ /* We received an incomplete value. Ask again but with a properly
+ * adjusted size. */
+ content_max_words += ceil(prop_reply->bytes_after / 4.0);
+ /* Repeat the request, with adjusted size */
+ free(prop_reply);
+ prop_cookie = xcb_get_property_unchecked(conn, false, root, atom_reply->atom,
+ XCB_GET_PROPERTY_TYPE_ANY, 0, content_max_words);
+ prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL);
+ if (prop_reply == NULL) {
+ goto out_atom;
+ }
+ }
+ if (xcb_get_property_value_length(prop_reply) == 0) {
+ goto out;
+ }
+ if (prop_reply->type == XCB_ATOM_CARDINAL) {
+ /* We treat a CARDINAL as a >= 32-bit unsigned int. The only CARDINAL
+ * we query is I3_PID, which is 32-bit. */
+ sasprintf(&content, "%u", *((unsigned int *)xcb_get_property_value(prop_reply)));
+ } else {
+ sasprintf(&content, "%.*s", xcb_get_property_value_length(prop_reply),
+ (char *)xcb_get_property_value(prop_reply));
+ }