void x_client_icon::update_default_icon(void) { xcb_free_pixmap(m_c(), m_default_icon); m_default_icon = XCB_NONE; const uint32_t width = default_application_icon.width; const uint32_t height = default_application_icon.width; m_icon_geometry.first = width; m_icon_geometry.second = height; m_default_icon = xcb_generate_id(m_c()); xcb_create_pixmap( m_c(), 32, m_default_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 *)default_application_icon.pixel_data;; xcb_gcontext_t gc = xcb_generate_id(m_c()); xcb_create_gc(m_c(), gc, m_default_icon, 0, NULL); xcb_image_put(m_c(), m_default_icon, gc, image, 0, 0, 0); xcb_image_destroy(image); xcb_free_gc(m_c(), gc); }
QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QImage::Format format) : QXcbObject(screen->connection()) , m_gc(0) , m_gc_window(0) { Q_XCB_NOOP(connection()); m_xcb_image = xcb_image_create_native(xcb_connection(), size.width(), size.height(), XCB_IMAGE_FORMAT_Z_PIXMAP, depth, 0, ~0, 0); m_shm_info.shmid = shmget (IPC_PRIVATE, m_xcb_image->stride * m_xcb_image->height, IPC_CREAT|0777); m_shm_info.shmaddr = m_xcb_image->data = (quint8 *)shmat (m_shm_info.shmid, 0, 0); m_shm_info.shmseg = xcb_generate_id(xcb_connection()); xcb_generic_error_t *error = xcb_request_check(xcb_connection(), xcb_shm_attach_checked(xcb_connection(), m_shm_info.shmseg, m_shm_info.shmid, false)); if (error) { qWarning() << "QXcbWindowSurface: Unable to attach to shared memory segment"; free(error); } if (shmctl(m_shm_info.shmid, IPC_RMID, 0) == -1) qWarning() << "QXcbWindowSurface: Error while marking the shared memory segment to be destroyed"; m_qimage = QImage( (uchar*) m_xcb_image->data, m_xcb_image->width, m_xcb_image->height, m_xcb_image->stride, format); }
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); } }
void xpost_view_page_display(Xpost_View_Window *win, const void *buffer) { xcb_image_t *image; image = xcb_image_create_native(win->c, win->width, win->height, XCB_IMAGE_FORMAT_Z_PIXMAP, win->depth, (void *)buffer, 4 * win->width * win->height, NULL); xcb_image_put(win->c, win->window, win->gc, image, 0, 0, 0); win->image = image; }
QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QImage::Format format) : QXcbObject(screen->connection()) , m_gc(0) , m_gc_window(0) { Q_XCB_NOOP(connection()); m_xcb_image = xcb_image_create_native(xcb_connection(), size.width(), size.height(), XCB_IMAGE_FORMAT_Z_PIXMAP, depth, 0, ~0, 0); const int segmentSize = m_xcb_image->stride * m_xcb_image->height; if (!segmentSize) return; int id = shmget(IPC_PRIVATE, segmentSize, IPC_CREAT | 0600); if (id == -1) qWarning("QXcbShmImage: shmget() failed (%d) for size %d (%dx%d)", errno, segmentSize, size.width(), size.height()); else m_shm_info.shmid = id; m_shm_info.shmaddr = m_xcb_image->data = (quint8 *)shmat (m_shm_info.shmid, 0, 0); m_shm_info.shmseg = xcb_generate_id(xcb_connection()); const xcb_query_extension_reply_t *shm_reply = xcb_get_extension_data(xcb_connection(), &xcb_shm_id); bool shm_present = shm_reply != NULL && shm_reply->present; xcb_generic_error_t *error = NULL; if (shm_present) error = xcb_request_check(xcb_connection(), xcb_shm_attach_checked(xcb_connection(), m_shm_info.shmseg, m_shm_info.shmid, false)); if (!shm_present || error) { free(error); shmdt(m_shm_info.shmaddr); shmctl(m_shm_info.shmid, IPC_RMID, 0); m_shm_info.shmaddr = 0; m_xcb_image->data = (uint8_t *)malloc(segmentSize); } else { if (shmctl(m_shm_info.shmid, IPC_RMID, 0) == -1) qWarning() << "QXcbBackingStore: Error while marking the shared memory segment to be destroyed"; } m_qimage = QImage( (uchar*) m_xcb_image->data, m_xcb_image->width, m_xcb_image->height, m_xcb_image->stride, format); }
void ZLEwlViewWidget::resize(int w, int h) { if(w == this->w && h == this->h) return; this->w = w; this->h = h; xcb_shm_detach(connection, shminfo.shmseg); shmdt(im->data); xcb_image_destroy(im); xcb_shm_query_version_reply_t *rep_shm; rep_shm = xcb_shm_query_version_reply (connection, xcb_shm_query_version (connection), NULL); if(rep_shm) { xcb_image_format_t format; int shmctl_status; if (rep_shm->shared_pixmaps && (rep_shm->major_version > 1 || rep_shm->minor_version > 0)) format = (xcb_image_format_t)rep_shm->pixmap_format; else format = (xcb_image_format_t)0; uint8_t depth = xcb_aux_get_depth (connection, screen); im = xcb_image_create_native (connection, w, h, format, depth, NULL, ~0, NULL); assert(im); shminfo.shmid = shmget (IPC_PRIVATE, im->stride*im->height, IPC_CREAT | 0777); assert(shminfo.shmid != -1); shminfo.shmaddr = (uint8_t*)shmat (shminfo.shmid, 0, 0); assert(shminfo.shmaddr); im->data = shminfo.shmaddr; shminfo.shmseg = xcb_generate_id (connection); xcb_shm_attach (connection, shminfo.shmseg, shminfo.shmid, 0); shmctl_status = shmctl(shminfo.shmid, IPC_RMID, 0); assert(shmctl_status != -1); free (rep_shm); } }
xcb_image_t * xcb_image_get (xcb_connection_t * conn, xcb_drawable_t draw, int16_t x, int16_t y, uint16_t width, uint16_t height, uint32_t plane_mask, xcb_image_format_t format) { xcb_get_image_cookie_t image_cookie; xcb_get_image_reply_t * imrep; xcb_image_t * image = 0; uint32_t bytes; uint8_t * data; image_cookie = xcb_get_image(conn, format, draw, x, y, width, height, plane_mask); imrep = xcb_get_image_reply(conn, image_cookie, 0); if (!imrep) return 0; bytes = xcb_get_image_data_length(imrep); data = xcb_get_image_data(imrep); switch (format) { case XCB_IMAGE_FORMAT_XY_PIXMAP: plane_mask &= xcb_mask(imrep->depth); if (plane_mask != xcb_mask(imrep->depth)) { xcb_image_t * tmp_image = xcb_image_create_native(conn, width, height, format, imrep->depth, 0, 0, 0); if (!tmp_image) { free(imrep); return 0; } int i; uint32_t rpm = plane_mask; uint8_t * src_plane = image->data; uint8_t * dst_plane = tmp_image->data; uint32_t size = image->height * image->stride; if (tmp_image->bit_order == XCB_IMAGE_ORDER_MSB_FIRST) rpm = xcb_bit_reverse(plane_mask, imrep->depth); for (i = 0; i < imrep->depth; i++) { if (rpm & 1) { memcpy(dst_plane, src_plane, size); src_plane += size; } else { memset(dst_plane, 0, size); } dst_plane += size; } tmp_image->plane_mask = plane_mask; image = tmp_image; free(imrep); break; } /* fall through */ case XCB_IMAGE_FORMAT_Z_PIXMAP: image = xcb_image_create_native(conn, width, height, format, imrep->depth, imrep, bytes, data); if (!image) { free(imrep); return 0; } break; default: assert(0); } assert(bytes == image->size); return image; }
ZLEwlViewWidget::ZLEwlViewWidget(ZLApplication *application, ZLView::Angle initialAngle) : ZLViewWidget(initialAngle) { myApplication = application; w = 600; h = 800; xcb_screen_iterator_t screen_iter; const xcb_setup_t *setup; xcb_generic_event_t *e; xcb_generic_error_t *error; xcb_void_cookie_t cookie_window; xcb_void_cookie_t cookie_map; uint32_t mask; uint32_t values[2]; int screen_number; uint8_t is_hand = 0; xcb_rectangle_t rect_coord = { 0, 0, 600, 800}; /* getting the connection */ connection = xcb_connect (NULL, &screen_number); if (xcb_connection_has_error(connection)) { fprintf (stderr, "ERROR: can't connect to an X server\n"); exit(-1); } screen = xcb_aux_get_screen (connection, screen_number); gc = xcb_generate_id (connection); mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; values[0] = screen->black_pixel; values[1] = 0; /* no graphics exposures */ xcb_create_gc (connection, gc, screen->root, mask, values); bgcolor = xcb_generate_id (connection); mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; values[0] = screen->white_pixel; values[1] = 0; /* no graphics exposures */ xcb_create_gc (connection, bgcolor, screen->root, mask, values); /* creating the window */ window = xcb_generate_id(connection); mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = screen->white_pixel; values[1] = XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_VISIBILITY_CHANGE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_PROPERTY_CHANGE; uint8_t depth = xcb_aux_get_depth (connection, screen); xcb_create_window(connection, depth, window, screen->root, 0, 0, 600, 800, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, mask, values); rect = xcb_generate_id (connection); xcb_create_pixmap (connection, depth, rect, window, 600, 800); xcb_map_window(connection, window); xcb_colormap_t colormap; colormap = screen->default_colormap; xcb_alloc_color_reply_t *rep; rep = xcb_alloc_color_reply (connection, xcb_alloc_color (connection, colormap, 0, 0, 0), NULL); pal_[0] = rep->pixel; free(rep); rep = xcb_alloc_color_reply (connection, xcb_alloc_color (connection, colormap, 0x55<<8, 0x55<<8, 0x55<<8), NULL); pal_[1] = rep->pixel; free(rep); rep = xcb_alloc_color_reply (connection, xcb_alloc_color (connection, colormap, 0xaa<<8, 0xaa<<8, 0xaa<<8), NULL); pal_[2] = rep->pixel; free(rep); rep = xcb_alloc_color_reply (connection, xcb_alloc_color (connection, colormap, 0xff<<8, 0xff<<8, 0xff<<8), NULL); pal_[3] = rep->pixel; free(rep); pal = pal_; xcb_shm_query_version_reply_t *rep_shm; rep_shm = xcb_shm_query_version_reply (connection, xcb_shm_query_version (connection), NULL); if(rep_shm) { xcb_image_format_t format; int shmctl_status; if (rep_shm->shared_pixmaps && (rep_shm->major_version > 1 || rep_shm->minor_version > 0)) format = (xcb_image_format_t)rep_shm->pixmap_format; else format = (xcb_image_format_t)0; im = xcb_image_create_native (connection, 600, 800, format, depth, NULL, ~0, NULL); assert(im); shminfo.shmid = shmget (IPC_PRIVATE, im->stride*im->height, IPC_CREAT | 0777); assert(shminfo.shmid != -1); shminfo.shmaddr = (uint8_t*)shmat (shminfo.shmid, 0, 0); assert(shminfo.shmaddr); im->data = shminfo.shmaddr; shminfo.shmseg = xcb_generate_id (connection); xcb_shm_attach (connection, shminfo.shmseg, shminfo.shmid, 0); shmctl_status = shmctl(shminfo.shmid, IPC_RMID, 0); assert(shmctl_status != -1); free (rep_shm); } xcb_flush(connection); }
void krad_x11_enable_capture (krad_x11_t *x11, uint32_t window_id) { xcb_get_geometry_reply_t *geo; xcb_query_tree_reply_t *tree; xcb_translate_coordinates_cookie_t translateCookie; xcb_translate_coordinates_reply_t *trans; geo = xcb_get_geometry_reply (x11->connection, xcb_get_geometry (x11->connection, window_id), NULL); if (geo == NULL) { window_id = 0; } else { tree = xcb_query_tree_reply (x11->connection, xcb_query_tree (x11->connection, window_id), NULL); if (tree == NULL) { window_id = 0; free (geo); } else { translateCookie = xcb_translate_coordinates (x11->connection, window_id, x11->screen->root, geo->x, geo->y); trans = xcb_translate_coordinates_reply (x11->connection, translateCookie, NULL); if (trans == NULL) { window_id = 0; free (tree); free (geo); } else { x11->width = geo->width; x11->height = geo->height; x11->x = trans->dst_x - geo->x; x11->y = trans->dst_y - geo->y; free (trans); free (tree); free (geo); } } } if (window_id == 0) { x11->width = x11->screen_width; x11->height = x11->screen_height; x11->window = x11->screen->root; } //printf ("capture width %d height %d x %d y %d\n", // x11->width, x11->height, x11->x, x11->y); x11->img = xcb_image_create_native (x11->connection, x11->width, x11->height, XCB_IMAGE_FORMAT_Z_PIXMAP, x11->screen_bit_depth, 0, ~0, 0); if (!x11->img) { exit (15); } x11->stride = x11->img->stride; x11->shminfo.shmid = shmget (IPC_PRIVATE, x11->img->stride * x11->img->height, (IPC_CREAT | 0666)); if (x11->shminfo.shmid == (uint32_t)-1) { xcb_image_destroy (x11->img); failfast ("shminfo fail"); } x11->shminfo.shmaddr = shmat (x11->shminfo.shmid, 0, 0); x11->img->data = x11->shminfo.shmaddr; if (x11->img->data == (uint8_t *)-1) { xcb_image_destroy (x11->img); failfast ("xcb image fail"); } x11->shminfo.shmseg = xcb_generate_id (x11->connection); xcb_shm_attach (x11->connection, x11->shminfo.shmseg, x11->shminfo.shmid, 0); x11->capture_enabled = 1; }
void x_client_icon::update_wm_hints_icon(void) { xcb_free_pixmap(m_c(), m_wm_hints_icon); m_wm_hints_icon = XCB_NONE; xcb_generic_error_t * error; xcb_get_property_cookie_t c = xcb_icccm_get_wm_hints(m_c(), m_x_client.window()); xcb_get_property_reply_t * r = xcb_get_property_reply(m_c(), c, &error); if (error) { std::free(error); } else { xcb_icccm_wm_hints_t wm_hints; xcb_icccm_get_wm_hints_from_reply(&wm_hints, r); if (wm_hints.flags & XCB_ICCCM_WM_HINT_ICON_PIXMAP) { unsigned int width, height; { Window root; int x, y; unsigned int border_width, depth; XGetGeometry(m_c.dpy(), wm_hints.icon_pixmap, &root, &x, &y, &width, &height, &border_width, &depth); m_icon_geometry.first = width; m_icon_geometry.second = height; } xcb_image_t * icon_rgb = xcb_image_get(m_c(), wm_hints.icon_pixmap, 0, 0, width, height, 0xffffffff, XCB_IMAGE_FORMAT_XY_PIXMAP); xcb_image_t * icon_mask; if (wm_hints.flags & XCB_ICCCM_WM_HINT_ICON_MASK) { icon_mask = xcb_image_get(m_c(), wm_hints.icon_mask, 0, 0, width, height, 0xffffffff, XCB_IMAGE_FORMAT_XY_PIXMAP); } else { icon_mask = xcb_image_create_native( m_c(), width, height, XCB_IMAGE_FORMAT_Z_PIXMAP, 32, NULL, 0, NULL); std::memset(icon_mask->data, 0xff, width * height * (icon_mask->bpp / icon_mask->stride)); } xcb_image_t * icon_rgba = xcb_image_create_native( m_c(), width, height, XCB_IMAGE_FORMAT_Z_PIXMAP, 32, NULL, 0, NULL); for (std::size_t x = 0; x < width; ++x) { for (std::size_t y = 0; y < height; ++y) { uint32_t rgba = 0; if (xcb_image_get_pixel(icon_mask, x, y)) { uint32_t rgb = xcb_image_get_pixel(icon_rgb, x, y); uint8_t * s = (uint8_t *)&rgb; uint8_t * d = (uint8_t *)&rgba; d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = 0xff; } xcb_image_put_pixel(icon_rgba, x, y, rgba); } } m_wm_hints_icon = xcb_generate_id(m_c()); xcb_create_pixmap( m_c(), 32, m_wm_hints_icon, m_c.root_window(), width, height); xcb_gcontext_t gc = xcb_generate_id(m_c()); xcb_create_gc(m_c(), gc, m_wm_hints_icon, 0, NULL); xcb_image_put(m_c(), m_wm_hints_icon, gc, icon_rgba, 0, 0, 0); xcb_image_destroy(icon_rgb); xcb_image_destroy(icon_mask); xcb_image_destroy(icon_rgba); xcb_free_gc(m_c(), gc); } } if (r) std::free(r); }
value_mask = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS, values[] = { s->black_pixel, value_mask }; if (argc<2) return -1; data = stbi_load(argv[1], &w, &h, &n, 4); if (data) { unsigned *dp = (unsigned *)data; size_t i, len = w*h; for(i=0;i<len;i++) //rgba to bgra dp[i]=dp[i]&0xff00ff00|((dp[i]>>16)&0xFF)|((dp[i]<<16)&0xFF0000); }else return -1; xcb_create_window(c,depth,win,s->root,0,0,w,h,1,win_class,s->root_visual,mask,values); xcb_create_pixmap(c,depth,pixmap,win,w,h); xcb_create_gc(c,gc,pixmap,0,NULL); image = xcb_image_create_native(c,w,h,format,depth,data,w*h*4,data); xcb_image_put(c, pixmap, gc, image, 0, 0, 0); xcb_image_destroy(image); xcb_map_window(c, win); xcb_flush(c); while ((ev = xcb_wait_for_event(c))) { switch (ev->response_type & ~0x80){ case XCB_EXPOSE: { xcb_expose_event_t *x = (xcb_expose_event_t *)ev; xcb_copy_area(c,pixmap,win,gc,x->x,x->y,x->x,x->y,x->width,x->height); xcb_flush(c); }break; case XCB_BUTTON_PRESS: goto end; default: break; } }