diff --git a/src/utils/bspwm.cpp b/src/utils/bspwm.cpp index 551c8c47..9e29366f 100644 --- a/src/utils/bspwm.cpp +++ b/src/utils/bspwm.cpp @@ -13,17 +13,18 @@ namespace bspwm_util { auto children = conn.query_tree(conn.screen()->root).children(); for (auto it = children.begin(); it != children.end(); it++) { - auto cookie = xcb_icccm_get_wm_class(conn, *it); xcb_icccm_get_wm_class_reply_t reply; + reply.class_name = reply.instance_name = nullptr; - if (xcb_icccm_get_wm_class_reply(conn, cookie, &reply, nullptr) == 0) - continue; + if (xcb_icccm_get_wm_class_reply(conn, xcb_icccm_get_wm_class(conn, *it), &reply, nullptr)) { + if (string_util::compare("Bspwm", reply.class_name) && string_util::compare("root", reply.instance_name)) { + roots.emplace_back(*it); + } + } - if (!string_util::compare("Bspwm", reply.class_name) || - !string_util::compare("root", reply.instance_name)) - continue; - - roots.emplace_back(*it); + if (reply.class_name != nullptr || reply.instance_name != nullptr) { + xcb_icccm_get_wm_class_reply_wipe(&reply); + } } return roots; diff --git a/src/utils/i3.cpp b/src/utils/i3.cpp index 8e4ecac3..bb17725d 100644 --- a/src/utils/i3.cpp +++ b/src/utils/i3.cpp @@ -19,16 +19,18 @@ namespace i3_util { auto children = conn.query_tree(conn.screen()->root).children(); for (auto it = children.begin(); it != children.end(); it++) { - auto cookie = xcb_icccm_get_wm_name(conn, *it); xcb_icccm_get_text_property_reply_t reply; + reply.name = nullptr; - if (xcb_icccm_get_wm_name_reply(conn, cookie, &reply, nullptr) == 0) - continue; + if (xcb_icccm_get_wm_name_reply(conn, xcb_icccm_get_wm_name(conn, *it), &reply, nullptr)) { + if (("[i3 con] output " + output_name).compare(0, 16 + output_name.length(), reply.name) == 0) { + roots.emplace_back(*it); + } + } - if (("[i3 con] output " + output_name).compare(0, 16 + output_name.length(), reply.name) != 0) - continue; - - roots.emplace_back(*it); + if (reply.name != nullptr) { + xcb_icccm_get_text_property_reply_wipe(&reply); + } } return roots; diff --git a/src/x11/connection.cpp b/src/x11/connection.cpp index 292ea352..1dff024e 100644 --- a/src/x11/connection.cpp +++ b/src/x11/connection.cpp @@ -3,6 +3,7 @@ #include "x11/connection.hpp" LEMONBUDDY_NS + /** * Preload required xcb atoms */