// === WindowIcon() === QIcon LXCB::WindowIcon(WId win){ //Fetch the _NET_WM_ICON for the window and return it as a QIcon if(DEBUG){ qDebug() << "XCB: WindowIcon()"; } QIcon icon; if(win==0){ return icon; } xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_icon_unchecked(&EWMH, win); xcb_ewmh_get_wm_icon_reply_t reply; if(1 == xcb_ewmh_get_wm_icon_reply(&EWMH, cookie, &reply, NULL)){ xcb_ewmh_wm_icon_iterator_t iter = xcb_ewmh_get_wm_icon_iterator(&reply); //Just use the first bool done =false; while(!done){ //Now convert the current data into a Qt image // - first 2 elements are width and height (removed via XCB functions) // - data in rows from left to right and top to bottom QImage image(iter.width, iter.height, QImage::Format_ARGB32); //initial setup uint* dat = iter.data; //dat+=2; //remember the first 2 element offset for(int i=0; i<image.byteCount()/4; ++i, ++dat){ ((uint*)image.bits())[i] = *dat; } icon.addPixmap(QPixmap::fromImage(image)); //layer this pixmap onto the icon //Now see if there are any more icons available done = (iter.rem<1); //number of icons remaining if(!done){ xcb_ewmh_get_wm_icon_next(&iter); } //get the next icon data } xcb_ewmh_get_wm_icon_reply_wipe(&reply); } return icon; }
void x_client_icon::update_net_wm_icon(void) { xcb_free_pixmap(m_c(), m_net_wm_icon); m_net_wm_icon = XCB_NONE; xcb_generic_error_t * error; xcb_get_property_cookie_t c = xcb_ewmh_get_wm_icon(m_c.ewmh(), m_x_client.window()); xcb_ewmh_get_wm_icon_reply_t wm_icon; std::memset(&wm_icon, 0, sizeof(xcb_ewmh_get_wm_icon_reply_t)); xcb_ewmh_get_wm_icon_reply(m_c.ewmh(), c, &wm_icon, &error); if (error) { std::free(error); } else if (0 < xcb_ewmh_get_wm_icon_length(&wm_icon)) { uint32_t width = 0; uint32_t height = 0; uint32_t * data = NULL; xcb_ewmh_wm_icon_iterator_t iter = xcb_ewmh_get_wm_icon_iterator(&wm_icon); for (; iter.rem; xcb_ewmh_get_wm_icon_next(&iter)) { if (iter.width > width) { width = iter.width; height = iter.height; data = iter.data; } } m_icon_geometry.first = width; m_icon_geometry.second = height; m_net_wm_icon = xcb_generate_id(m_c()); xcb_create_pixmap( m_c(), 32, m_net_wm_icon, m_c.root_window(), width, height); xcb_image_t * image = xcb_image_create_native( m_c(), width, height, XCB_IMAGE_FORMAT_Z_PIXMAP, 32, NULL, 0, NULL); image->data = (uint8_t *)data; alpha_transform(image->data, width, height); xcb_gcontext_t gc = xcb_generate_id(m_c()); xcb_create_gc(m_c(), gc, m_net_wm_icon, 0, NULL); xcb_image_put(m_c(), m_net_wm_icon, gc, image, 0, 0, 0); xcb_image_destroy(image); xcb_free_gc(m_c(), gc); xcb_ewmh_get_wm_icon_reply_wipe(&wm_icon); } }