diff --git a/include/modules/xwindow.hpp b/include/modules/xwindow.hpp index 7c3777f5..f59aa6fc 100644 --- a/include/modules/xwindow.hpp +++ b/include/modules/xwindow.hpp @@ -52,6 +52,8 @@ namespace modules { if (!(title = ewmh_util::get_visible_name(ewmh, m_window)).empty()) { return title; + } else if (!(title = ewmh_util::get_wm_name(ewmh, m_window)).empty()) { + return title; } else if (!(title = icccm_util::get_wm_name(m_connection, m_window)).empty()) { return title; } else { diff --git a/include/x11/ewmh.hpp b/include/x11/ewmh.hpp index 749334ac..64a9898b 100644 --- a/include/x11/ewmh.hpp +++ b/include/x11/ewmh.hpp @@ -19,6 +19,7 @@ namespace ewmh_util { bool supports(xcb_ewmh_connection_t* ewmh, xcb_atom_t atom, int screen = 0); + string get_wm_name(xcb_ewmh_connection_t* conn, xcb_window_t win); string get_visible_name(xcb_ewmh_connection_t* conn, xcb_window_t win); string get_icon_name(xcb_ewmh_connection_t* conn, xcb_window_t win); string get_reply_string(xcb_ewmh_get_utf8_strings_reply_t* reply); diff --git a/src/x11/ewmh.cpp b/src/x11/ewmh.cpp index 0243bf6b..aaa5e126 100644 --- a/src/x11/ewmh.cpp +++ b/src/x11/ewmh.cpp @@ -48,30 +48,37 @@ namespace ewmh_util { return supports; } + string get_wm_name(xcb_ewmh_connection_t* conn, xcb_window_t win) { + xcb_ewmh_get_utf8_strings_reply_t utf8_reply; + if (xcb_ewmh_get_wm_name_reply(conn, xcb_ewmh_get_wm_name(conn, win), &utf8_reply, nullptr)) { + return get_reply_string(&utf8_reply); + } + return ""; + } + string get_visible_name(xcb_ewmh_connection_t* conn, xcb_window_t win) { xcb_ewmh_get_utf8_strings_reply_t utf8_reply; - if (!xcb_ewmh_get_wm_visible_name_reply(conn, xcb_ewmh_get_wm_visible_name(conn, win), &utf8_reply, nullptr)) { - return ""; + if (xcb_ewmh_get_wm_visible_name_reply(conn, xcb_ewmh_get_wm_visible_name(conn, win), &utf8_reply, nullptr)) { + return get_reply_string(&utf8_reply); } - return get_reply_string(&utf8_reply); + return ""; } string get_icon_name(xcb_ewmh_connection_t* conn, xcb_window_t win) { xcb_ewmh_get_utf8_strings_reply_t utf8_reply; - if (!xcb_ewmh_get_wm_icon_name_reply(conn, xcb_ewmh_get_wm_icon_name(conn, win), &utf8_reply, nullptr)) { - return ""; + if (xcb_ewmh_get_wm_icon_name_reply(conn, xcb_ewmh_get_wm_icon_name(conn, win), &utf8_reply, nullptr)) { + return get_reply_string(&utf8_reply); } - return get_reply_string(&utf8_reply); + return ""; } string get_reply_string(xcb_ewmh_get_utf8_strings_reply_t* reply) { - if (reply == nullptr || !reply->strings_len) { + if (reply == nullptr) { return ""; } - char buffer[BUFSIZ]{'\0'}; - strncpy(buffer, reply->strings, reply->strings_len); + string str(reply->strings, reply->strings_len); xcb_ewmh_get_utf8_strings_reply_wipe(reply); - return buffer; + return str; } uint32_t get_current_desktop(xcb_ewmh_connection_t* conn, int screen) { diff --git a/src/x11/icccm.cpp b/src/x11/icccm.cpp index 0818a335..4b156831 100644 --- a/src/x11/icccm.cpp +++ b/src/x11/icccm.cpp @@ -5,20 +5,19 @@ POLYBAR_NS namespace icccm_util { string get_wm_name(xcb_connection_t* conn, xcb_window_t win) { xcb_icccm_get_text_property_reply_t reply; - if (!xcb_icccm_get_wm_name_reply(conn, xcb_icccm_get_wm_name(conn, win), &reply, nullptr)) { - return ""; + if (xcb_icccm_get_wm_name_reply(conn, xcb_icccm_get_wm_name(conn, win), &reply, nullptr)) { + return get_reply_string(&reply); } - return get_reply_string(&reply); + return ""; } string get_reply_string(xcb_icccm_get_text_property_reply_t* reply) { - if (reply->name == nullptr || !reply->name_len) { + if (reply->name == nullptr) { return ""; } - char buffer[BUFSIZ]{'\0'}; - strncpy(buffer, reply->name, reply->name_len); + string str(reply->name, reply->name_len); xcb_icccm_get_text_property_reply_wipe(reply); - return buffer; + return str; } }