void set_window_name(xcwm_window_t *window, xcwm_property_t *property) { xcb_get_property_cookie_t cookie; xcb_icccm_get_text_property_reply_t reply; xcb_ewmh_get_utf8_strings_reply_t data; /* Check _NET_WM_NAME first */ cookie = xcb_ewmh_get_wm_name(&window->context->atoms.ewmh_conn, window->window_id); if (xcb_ewmh_get_wm_name_reply(&window->context->atoms.ewmh_conn, cookie, &data, NULL)) { window->name = strndup(data.strings, data.strings_len); xcb_ewmh_get_utf8_strings_reply_wipe(&data); return; } cookie = xcb_icccm_get_wm_name(window->context->conn, window->window_id); if (!xcb_icccm_get_wm_name_reply(window->context->conn, cookie, &reply, NULL)) { window->name = malloc(sizeof(char)); window->name[0] = '\0'; return; } window->name = strndup(reply.name, reply.name_len); xcb_icccm_get_text_property_reply_wipe(&reply); }
void get_window_title(xcb_window_t win, char *title, size_t len) { xcb_ewmh_get_utf8_strings_reply_t ewmh_txt_prop; xcb_icccm_get_text_property_reply_t icccm_txt_prop; ewmh_txt_prop.strings = icccm_txt_prop.name = NULL; title[0] = '\0'; if (win != XCB_NONE && (xcb_ewmh_get_wm_name_reply(ewmh, xcb_ewmh_get_wm_name(ewmh, win), &ewmh_txt_prop, NULL) == 1 || xcb_icccm_get_wm_name_reply(dpy, xcb_icccm_get_wm_name(dpy, win), &icccm_txt_prop, NULL) == 1)) { char *src = NULL; size_t title_len = 0; if (ewmh_txt_prop.strings != NULL) { src = ewmh_txt_prop.strings; title_len = MIN(len, ewmh_txt_prop.strings_len); } else if (icccm_txt_prop.name != NULL) { src = icccm_txt_prop.name; title_len = MIN(len, icccm_txt_prop.name_len); } if (src != NULL) { strncpy(title, src, title_len); title[title_len] = '\0'; } } }
void x_client_name::update_net_wm_name(void) { m_net_wm_name.clear(); xcb_generic_error_t * error; xcb_get_property_cookie_t c = xcb_ewmh_get_wm_name(m_c.ewmh(), m_x_client.window()); xcb_get_property_reply_t * r = xcb_get_property_reply(m_c(), c, &error); if (error) { delete error; } else { xcb_ewmh_get_utf8_strings_reply_t net_wm_name; if (xcb_ewmh_get_wm_name_from_reply(m_c.ewmh(), &net_wm_name, r)) { m_net_wm_name = std::string(net_wm_name.strings, net_wm_name.strings_len); xcb_ewmh_get_utf8_strings_reply_wipe(&net_wm_name); r = NULL; } } if (r) delete r; }