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); }
int main(void) { xcb_connection_t *conn; xcb_screen_t *screen; xcb_window_t win; xcb_gcontext_t gcontext; xcb_generic_event_t *event; uint32_t mask; uint32_t values[2]; /* open connection with the server */ conn = xcb_connect(NULL,NULL); if (xcb_connection_has_error(conn)) { printf("Cannot open display\n"); exit(1); } /* get the first screen */ screen = xcb_setup_roots_iterator( xcb_get_setup(conn) ).data; /* create black graphics gcontext */ gcontext = xcb_generate_id(conn); win = screen->root; mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; values[0] = screen->black_pixel; values[1] = 0; xcb_create_gc(conn, gcontext, win, mask, values); /* create window */ win = xcb_generate_id(conn); mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = screen->white_pixel; values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE; xcb_create_window(conn, screen->root_depth, win, screen->root, 10, 10, 100, 100, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, mask, values); /* map (show) the window */ xcb_map_window(conn, win); xcb_flush(conn); cterm_add_event_listener(XCB_KEY_PRESS, output_string); cterm_add_event_listener(XCB_KEY_PRESS, close_window); /* event loop */ while (!done) { event = xcb_poll_for_event(conn); if(event == NULL) continue; cterm_handle_event(event); free(event); } /* close connection to server */ xcb_disconnect(conn); cterm_free_event_handlers(); return 0; }
static EGLBoolean dri2_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLNativePixmapType native_target) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); xcb_gcontext_t gc; xcb_pixmap_t target = (uintptr_t )native_target; (void) drv; (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); gc = xcb_generate_id(dri2_dpy->conn); xcb_create_gc(dri2_dpy->conn, gc, target, 0, NULL); xcb_copy_area(dri2_dpy->conn, dri2_surf->drawable, target, gc, 0, 0, 0, 0, dri2_surf->base.Width, dri2_surf->base.Height); xcb_free_gc(dri2_dpy->conn, gc); return EGL_TRUE; }
DocWindowFrame::DocWindowFrame( App& app, xcb_connection_t* conn, xcb_window_t parent, xcb_screen_t* screen, ClientWindow& client) : WindowFrame(app, conn, client) , mFrameWindow( conn, screen, parent, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS, 100 + client.getX() - 20, 100 + client.getY() - 20, client.getWidth() + kWindowWidthDelta, client.getHeight() + kWindowHeightDelta) { mWindowLabel = new Label(app, screen, mFrameWindow, app.getBlackPen(), &app.getSystemFont(), Label::kHAlignLeft, app.getColor(kColorGray), 5, 2, 100, 18, L""); mFrameParentWindow = screen->root; mGc = xcb_generate_id(app); uint32_t mask = XCB_GC_FOREGROUND; uint32_t values[] = { app.getColor(kColorGray) }; xcb_create_gc(app, mGc, mFrameWindow, mask, values); app.addWindowHandler(mFrameWindow, this); // Reparent last to make the client window topmost client.reparent(&mFrameWindow, kWindowPosLeft, kWindowPosTop); setTitle(L"Test title"); }
BOOL PRESENTHelperCopyFront(Display *dpy, PRESENTPixmapPriv *present_pixmap_priv) { PRESENTpriv *present_priv = present_pixmap_priv->present_priv; xcb_void_cookie_t cookie; xcb_generic_error_t *error; uint32_t v = 0; xcb_gcontext_t gc; pthread_mutex_lock(&present_priv->mutex_present); if (!present_priv->window) { pthread_mutex_unlock(&present_priv->mutex_present); return FALSE; } xcb_create_gc(present_priv->xcb_connection, (gc = xcb_generate_id(present_priv->xcb_connection)), present_priv->window, XCB_GC_GRAPHICS_EXPOSURES, &v); cookie = xcb_copy_area_checked(present_priv->xcb_connection, present_priv->window, present_pixmap_priv->pixmap, gc, 0, 0, 0, 0, present_pixmap_priv->width, present_pixmap_priv->height); error = xcb_request_check(present_priv->xcb_connection, cookie); xcb_free_gc(present_priv->xcb_connection, gc); pthread_mutex_unlock(&present_priv->mutex_present); return (error != NULL); }
void QXcbShmImage::put(xcb_window_t window, const QPoint &target, const QRect &source) { Q_XCB_NOOP(connection()); if (m_gc_window != window) { if (m_gc) Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc)); m_gc = xcb_generate_id(xcb_connection()); Q_XCB_CALL(xcb_create_gc(xcb_connection(), m_gc, window, 0, 0)); m_gc_window = window; } Q_XCB_NOOP(connection()); xcb_image_shm_put(xcb_connection(), window, m_gc, m_xcb_image, m_shm_info, source.x(), source.y(), target.x(), target.y(), source.width(), source.height(), false); Q_XCB_NOOP(connection()); m_dirty = m_dirty | source; xcb_flush(xcb_connection()); Q_XCB_NOOP(connection()); }
void X11WindowedBackend::createCursor(const QImage &img, const QPoint &hotspot) { const xcb_pixmap_t pix = xcb_generate_id(m_connection); const xcb_gcontext_t gc = xcb_generate_id(m_connection); const xcb_cursor_t cid = xcb_generate_id(m_connection); xcb_create_pixmap(m_connection, 32, pix, m_screen->root, img.width(), img.height()); xcb_create_gc(m_connection, gc, pix, 0, nullptr); xcb_put_image(m_connection, XCB_IMAGE_FORMAT_Z_PIXMAP, pix, gc, img.width(), img.height(), 0, 0, 0, 32, img.byteCount(), img.constBits()); XRenderPicture pic(pix, 32); xcb_render_create_cursor(m_connection, cid, pic, hotspot.x(), hotspot.y()); for (auto it = m_windows.constBegin(); it != m_windows.constEnd(); ++it) { xcb_change_window_attributes(m_connection, (*it).window, XCB_CW_CURSOR, &cid); } xcb_free_pixmap(m_connection, pix); xcb_free_gc(m_connection, gc); if (m_cursor) { xcb_free_cursor(m_connection, m_cursor); } m_cursor = cid; xcb_flush(m_connection); markCursorAsRendered(); }
void NGBInit() { event = NULL; mask = 0; con = xcb_connect(":0.0", NULL); //打开连接 if(xcb_connection_has_error(con)) { printf("Cannot open display\n"); exit(1); } screen = xcb_setup_roots_iterator(xcb_get_setup(con)).data; win = screen->root; foreground = xcb_generate_id(con); mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; values[0] = screen->black_pixel; values[1] = 0; xcb_create_gc(con, foreground, win, mask, values); win = xcb_generate_id(con); mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = screen->white_pixel; values[1] = XCB_EVENT_MASK_EXPOSURE; }
void VlcWindowlessXCB::drawBackground(xcb_drawable_t drawable) { /* Obtain the background color */ xcb_colormap_t colormap = m_screen->default_colormap; unsigned r = 0, g = 0, b = 0; HTMLColor2RGB(get_options().get_bg_color().c_str(), &r, &g, &b); xcb_alloc_color_reply_t *reply = xcb_alloc_color_reply(m_conn, xcb_alloc_color(m_conn, colormap, (uint16_t) r << 8, (uint16_t) g << 8, (uint16_t) b << 8), NULL); uint32_t colorpixel = reply->pixel; free(reply); /* Prepare to fill the background */ xcb_gcontext_t background = xcb_generate_id(m_conn); uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; uint32_t values[2] = {colorpixel, 0}; xcb_create_gc(m_conn, background, drawable, mask, values); xcb_rectangle_t rect; rect.x = 0; rect.y = 0; rect.width = npwindow.width; rect.height = npwindow.height; /* Fill the background */ xcb_poly_fill_rectangle(m_conn, drawable, background, 1, &rect); xcb_free_gc(m_conn, background); }
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); } }
static void _e_alert_create(void) { uint32_t mask, mask_list[4]; int wx = 0, wy = 0; wx = ((sw - WINDOW_WIDTH) / 2); wy = ((sh - WINDOW_HEIGHT) / 2); font = xcb_generate_id(conn); xcb_open_font(conn, font, strlen("fixed"), "fixed"); /* create main window */ mask = (XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK); mask_list[0] = screen->white_pixel; mask_list[1] = screen->black_pixel; mask_list[2] = 1; mask_list[3] = (XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE); win = xcb_generate_id(conn); xcb_create_window(conn, XCB_COPY_FROM_PARENT, win, screen->root, wx, wy, WINDOW_WIDTH, WINDOW_HEIGHT, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, mask, mask_list); /* create button 1 */ mask_list[3] = (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_EXPOSURE); btn1 = xcb_generate_id(conn); xcb_create_window(conn, XCB_COPY_FROM_PARENT, btn1, win, -100, -100, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, mask, mask_list); xcb_map_window(conn, btn1); /* create button 2 */ btn2 = xcb_generate_id(conn); xcb_create_window(conn, XCB_COPY_FROM_PARENT, btn2, win, -100, -100, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, mask, mask_list); xcb_map_window(conn, btn2); /* create drawing gc */ mask = (XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT); mask_list[0] = screen->black_pixel; mask_list[1] = screen->white_pixel; mask_list[2] = font; gc = xcb_generate_id(conn); xcb_create_gc(conn, gc, win, mask, mask_list); }
bool VlcWindowlessXCB::handle_event(void *event) { XEvent *xevent = static_cast<XEvent *>(event); switch (xevent->type) { case GraphicsExpose: xcb_gcontext_t gc; xcb_void_cookie_t cookie; xcb_generic_error_t *err; XGraphicsExposeEvent *xgeevent = reinterpret_cast<XGraphicsExposeEvent *>(xevent); /* Something went wrong during initialization */ if (!m_conn || !m_screen) break; drawBackground(xgeevent->drawable); /* Validate video size */ if (m_media_width == 0 || m_media_height == 0) break; /* Compute the position of the video */ int left = (npwindow.width - m_media_width) / 2; int top = (npwindow.height - m_media_height) / 2; gc = xcb_generate_id(m_conn); xcb_create_gc(m_conn, gc, xgeevent->drawable, 0, NULL); /* Push the frame in X11 */ cookie = xcb_put_image_checked( m_conn, XCB_IMAGE_FORMAT_Z_PIXMAP, xgeevent->drawable, gc, m_media_width, m_media_height, left, top, 0, 24, m_media_width * m_media_height * 4, (const uint8_t *)&m_frame_buf[0]); if (err = xcb_request_check(m_conn, cookie)) { fprintf(stderr, "Unable to put picture into drawable. Error %d\n", err->error_code); free(err); } /* Flush the the connection */ xcb_flush(m_conn); xcb_free_gc(m_conn, gc); } return VlcWindowlessBase::handle_event(event); }
xcb_gcontext_t _cairo_xcb_connection_create_gc (cairo_xcb_connection_t *connection, xcb_drawable_t drawable, uint32_t value_mask, uint32_t *values) { xcb_gcontext_t gc = _cairo_xcb_connection_get_xid (connection); xcb_create_gc (connection->xcb_connection, gc, drawable, value_mask, values); return gc; }
static xcb_gcontext_t dri3_drawable_gc(struct loader_dri3_drawable *draw) { if (!draw->gc) { uint32_t v = 0; xcb_create_gc(draw->conn, (draw->gc = xcb_generate_id(draw->conn)), draw->drawable, XCB_GC_GRAPHICS_EXPOSURES, &v); } return draw->gc; }
xcb_gc_t get_font_gc(xcb_connection_t *dpy, xcb_window_t win, const char *font_name) { xcb_void_cookie_t ck; xcb_font_t font = xcb_generate_id(dpy); ck = xcb_open_font_checked(dpy, font, strlen(font_name), font_name); check_request(dpy, ck, "Can't open font"); xcb_gcontext_t gc = xcb_generate_id(dpy); uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT; uint32_t values[] = {0xffcccccc, 0xff111111, font}; xcb_create_gc(dpy, gc, win, mask, values); xcb_close_font(dpy, font); return gc; }
static void swrastCreateDrawable(struct dri2_egl_display * dri2_dpy, struct dri2_egl_surface * dri2_surf, int depth) { uint32_t mask; const uint32_t function = GXcopy; uint32_t valgc[2]; /* create GC's */ dri2_surf->gc = xcb_generate_id(dri2_dpy->conn); mask = XCB_GC_FUNCTION; xcb_create_gc(dri2_dpy->conn, dri2_surf->gc, dri2_surf->drawable, mask, &function); dri2_surf->swapgc = xcb_generate_id(dri2_dpy->conn); mask = XCB_GC_FUNCTION | XCB_GC_GRAPHICS_EXPOSURES; valgc[0] = function; valgc[1] = False; xcb_create_gc(dri2_dpy->conn, dri2_surf->swapgc, dri2_surf->drawable, mask, valgc); dri2_surf->depth = depth; switch (depth) { case 32: case 24: dri2_surf->bytes_per_pixel = 4; break; case 16: dri2_surf->bytes_per_pixel = 2; break; case 8: dri2_surf->bytes_per_pixel = 1; break; case 0: dri2_surf->bytes_per_pixel = 0; break; default: _eglLog(_EGL_WARNING, "unsupported depth %d", depth); } }
void X11WindowedQPainterBackend::present(int mask, const QRegion &damage) { Q_UNUSED(mask) Q_UNUSED(damage) xcb_connection_t *c = m_backend->connection(); const xcb_window_t window = m_backend->window(); if (m_gc == XCB_NONE) { m_gc = xcb_generate_id(c); xcb_create_gc(c, m_gc, window, 0, nullptr); } // TODO: only update changes? xcb_put_image(c, XCB_IMAGE_FORMAT_Z_PIXMAP, window, m_gc, m_backBuffer.width(), m_backBuffer.height(), 0, 0, 0, 24, m_backBuffer.byteCount(), m_backBuffer.constBits()); }
/** Initialize a simple window. * \param sw The simple window to initialize. * \param phys_screen Physical screen number. * \param geometry Window geometry. * \param border_width Window border width. * \param orientation The rendering orientation. * \param bg Default foreground color. * \param bg Default background color. */ void simplewindow_init(simple_window_t *sw, int phys_screen, area_t geometry, uint16_t border_width, orientation_t orientation, const xcolor_t *fg, const xcolor_t *bg) { xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen); uint32_t create_win_val[3]; const uint32_t gc_mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND; const uint32_t gc_values[2] = { s->black_pixel, s->white_pixel }; sw->geometry.x = geometry.x; sw->geometry.y = geometry.y; sw->geometry.width = geometry.width; sw->geometry.height = geometry.height; sw->border.width = border_width; sw->orientation = orientation; sw->ctx.fg = *fg; sw->ctx.bg = *bg; create_win_val[0] = XCB_BACK_PIXMAP_PARENT_RELATIVE; create_win_val[1] = 1; create_win_val[2] = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_EXPOSURE; sw->window = xcb_generate_id(globalconf.connection); xcb_create_window(globalconf.connection, s->root_depth, sw->window, s->root, geometry.x, geometry.y, geometry.width, geometry.height, border_width, XCB_COPY_FROM_PARENT, s->root_visual, XCB_CW_BACK_PIXMAP | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK, create_win_val); sw->pixmap = xcb_generate_id(globalconf.connection); xcb_create_pixmap(globalconf.connection, s->root_depth, sw->pixmap, s->root, geometry.width, geometry.height); sw->ctx.phys_screen = phys_screen; simplewindow_draw_context_update(sw, s); /* The default GC is just a newly created associated to the root window */ sw->gc = xcb_generate_id(globalconf.connection); xcb_create_gc(globalconf.connection, sw->gc, s->root, gc_mask, gc_values); }
xcb_pixmap_t create_bg_pixmap(xcb_connection_t *conn, xcb_screen_t *scr, u_int32_t *resolution, char *color) { xcb_pixmap_t bg_pixmap = xcb_generate_id(conn); xcb_create_pixmap(conn, scr->root_depth, bg_pixmap, scr->root, resolution[0], resolution[1]); /* Generate a Graphics Context and fill the pixmap with background color * (for images that are smaller than your screen) */ xcb_gcontext_t gc = xcb_generate_id(conn); uint32_t values[] = {get_colorpixel(color)}; xcb_create_gc(conn, gc, bg_pixmap, XCB_GC_FOREGROUND, values); xcb_rectangle_t rect = {0, 0, resolution[0], resolution[1]}; xcb_poly_fill_rectangle(conn, bg_pixmap, gc, 1, &rect); xcb_free_gc(conn, gc); return bg_pixmap; }
int main() { /* Open the connection to the X server and get the first screen */ xcb_connection_t *connection = xcb_connect(NULL, NULL); xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data; /* Create a black graphic context for drawing in the foreground */ xcb_drawable_t window = screen->root; xcb_gcontext_t black = xcb_generate_id(connection); uint32_t mask = XCB_GC_FOREGROUND; uint32_t value[] = { screen->black_pixel }; xcb_create_gc(connection, black, window, mask, value); return 0; }
xcb_gcontext_t create_graphics_context(xcb_window_t window) { xcb_gcontext_t graphics_context; uint32_t mask; uint32_t values[2]; mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; values[0] = screen->black_pixel; values[1] = 0; graphics_context = xcb_generate_id(connection); xcb_create_gc(connection, graphics_context, window, mask, values); return graphics_context; }
int main() { xcb_connection_t *conn = xcb_connect(NULL, NULL); xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; xcb_drawable_t win = screen->root; xcb_gcontext_t fg = xcb_generate_id(conn); uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; uint32_t values[2] = { screen->black_pixel, 0 }; xcb_create_gc(conn, fg, win, mask, values); win = xcb_generate_id(conn); mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = screen->white_pixel; values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS; xcb_create_window(conn, XCB_COPY_FROM_PARENT, win, screen->root, x, y, w, h, bw, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, mask, values); xcb_map_window(conn, win); xcb_flush(conn); xcb_generic_event_t *event; // xcb_poll_for_event does not block, so this will only catch the EXPOSE event then die out. // If we used xcb_wait_for_event, we'd block, thus continuing the loop and would actually // have a window to receive a possible XCB_BUTTON_PRESS. while ((event = xcb_wait_for_event(conn))) { switch (event->response_type & ~0x80) { case XCB_EXPOSE: printf("Expose event\n"); xcb_flush(conn); break; case XCB_BUTTON_PRESS: printf("Button press\n"); xcb_flush(conn); break; default: printf("Some otherrr event\n"); break; } free(event); } return 0; }
void draw_border(client_t *client) { /* Clear root window to erase any old borders */ xcb_aux_clear_window(wm_conf.connection, wm_conf.screen->root); xcb_gcontext_t orange = xcb_generate_id(wm_conf.connection); uint32_t mask = XCB_GC_FOREGROUND; uint32_t value[] = { 0xffffa500 }; xcb_create_gc(wm_conf.connection, orange, wm_conf.screen->root, mask, value); xcb_rectangle_t rect[] = {{ client->rect.x - 2, client->rect.y - 2, client->rect.width + 4, client->rect.height + 4 }}; /* Draw the new border */ xcb_poly_fill_rectangle(wm_conf.connection, wm_conf.screen->root, orange, 1, rect); xcb_free_gc(wm_conf.connection, orange); xcb_map_window(wm_conf.connection, wm_conf.screen->root); xcb_flush(wm_conf.connection); }
//______________________________________________ quint32 ShadowHelper::createPixmap( const QPixmap& source ) { // do nothing for invalid pixmaps if( source.isNull() ) return 0; if( !Helper::isX11() ) return 0; /* in some cases, pixmap handle is invalid. This is the case notably when Qt uses to RasterEngine. In this case, we create an X11 Pixmap explicitly and draw the source pixmap on it. */ #if MENDA_HAVE_X11 const int width( source.width() ); const int height( source.height() ); // create X11 pixmap xcb_pixmap_t pixmap = xcb_generate_id( Helper::connection() ); xcb_create_pixmap( Helper::connection(), 32, pixmap, QX11Info::appRootWindow(), width, height ); // create gc if( !_gc ) { _gc = xcb_generate_id( Helper::connection() ); xcb_create_gc( Helper::connection(), _gc, pixmap, 0, 0x0 ); } // create image from QPixmap and assign to pixmap QImage image( source.toImage() ); xcb_put_image( Helper::connection(), XCB_IMAGE_FORMAT_Z_PIXMAP, pixmap, _gc, image.width(), image.height(), 0, 0, 0, 32, image.byteCount(), image.constBits()); return pixmap; #else return 0; #endif }
internal void hhxcb_resize_backbuffer(hhxcb_context *context, hhxcb_offscreen_buffer *buffer, int width, int height) { // xcb_image owns the referenced data, so will clean it up without an explicit free() if (buffer->xcb_image) { xcb_image_destroy(buffer->xcb_image); } if (buffer->xcb_pixmap_id) { xcb_free_pixmap(context->connection, buffer->xcb_pixmap_id); } if (buffer->xcb_gcontext_id) { xcb_free_gc(context->connection, buffer->xcb_gcontext_id); } buffer->width = width; buffer->height = height; buffer->bytes_per_pixel = context->fmt->bits_per_pixel / 8; buffer->pitch = buffer->bytes_per_pixel * width; buffer->xcb_image = hhxcb_create_image(width, height, context->fmt, context->setup); buffer->memory = buffer->xcb_image->data; buffer->xcb_pixmap_id = xcb_generate_id(context->connection); xcb_create_pixmap(context->connection, context->fmt->depth, buffer->xcb_pixmap_id, context->window, width, height); buffer->xcb_gcontext_id = xcb_generate_id (context->connection); xcb_create_gc (context->connection, buffer->xcb_gcontext_id, buffer->xcb_pixmap_id, 0, 0); }
void draw_gc(xcb_window_t win) { xcb_rectangle_t r = { 0, 0, 0,0 }; xcb_connection_t *c = G.conn; xcb_get_geometry_reply_t *geo; geo = xcb_get_geometry_reply(c, xcb_get_geometry(c, win), NULL); if(0)printf("get (%hdx%hd)@(%dx%d)\n", geo->x, geo->y, geo->width, geo->height); xcb_get_image_cookie_t cookie; xcb_get_image_reply_t *reply; xcb_generic_error_t *error; xcb_void_cookie_t ck; if(geo!=NULL){ r.width = geo->width ; r.height=geo->height; r.x=0; r.y=0; //printf("window depth=%d\n", geo->depth); if(geo->depth == 24 | geo->depth == 32) psize = r.width * r.height * 4; //correct else if(geo->depth==16) psize = r.width * r.height * 2; //correct else printf(" *** unsupported window depth\n"); }else psize = r.width * r.height * 4; //correct free(geo); static cairo_surface_t *cmask; if( pbuf == NULL){ // psize = geo->width *geo->height*4; //for test pbuf = malloc(psize); printf("malloc pbuf=0x%x size=%d\n",pbuf, psize); memset(pbuf, 0x18, psize); cmask = cairo_image_surface_create_for_data ((unsigned char *) pbuf, CAIRO_FORMAT_ARGB32, geo->width, geo->height, geo->width*4); // 12, 4, 48); if(cmask == NULL){ perror("cairo surface create"); exit(1); } } if(0)printf("width (%dx%d=%d\n", geo->width, geo->height, geo->width *geo->height*4); draw_cairo(cmask); //draw image with xcb_put_image // creat gc and draw to parent window xcb_gcontext_t g; g = xcb_generate_id(c); xcb_create_gc(c, g, win, 0,NULL); ck = xcb_put_image_checked(c, XCB_IMAGE_FORMAT_Z_PIXMAP, win, g, r.width, r.height, r.x,r.y, 0, G.s->root_depth, psize, pbuf); xcb_flush(c); }
Xpost_View_Window * xpost_view_win_new(int xorig, int yorig, int width, int height) { xcb_screen_iterator_t iter; xcb_rectangle_t rect; xcb_get_geometry_reply_t *geom; Xpost_View_Window *win; int scrno; unsigned int values[3]; unsigned int mask; win = (Xpost_View_Window *)calloc(1, sizeof(Xpost_View_Window)); if (!win) return NULL; win->width = width; win->height = height; /* open a connection */ win->c = xcb_connect(NULL, &scrno); if (xcb_connection_has_error(win->c)) { fprintf(stderr, "Fail to connect to the X server\n"); goto free_win; } /* get the screen */ iter = xcb_setup_roots_iterator(xcb_get_setup(win->c)); for (; iter.rem; --scrno, xcb_screen_next(&iter)) { if (scrno == 0) { win->scr = iter.data; break; } } /* get the depth of the screen */ geom = xcb_get_geometry_reply(win->c, xcb_get_geometry(win->c, win->scr->root), 0); if (!geom) { fprintf(stderr, "Fail to the geometry of the root window\n"); goto disconnect_c; } win->depth = geom->depth; free(geom); /* create the window */ win->window = xcb_generate_id(win->c); mask = XCB_CW_BACK_PIXMAP | XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = XCB_NONE; values[1] = win->scr->white_pixel; values[2] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_KEY_RELEASE; xcb_create_window(win->c, XCB_COPY_FROM_PARENT, win->window, win->scr->root, xorig, yorig, width, height, 5, XCB_WINDOW_CLASS_INPUT_OUTPUT, win->scr->root_visual, mask, values); /* set title of the window */ xcb_change_property(win->c, XCB_PROP_MODE_REPLACE, win->window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, sizeof("Xpost viewer") - 1, "Xpost viewer"); /* set background context */ win->gc = xcb_generate_id(win->c); values[0] = win->scr->white_pixel; values[1] = 0; xcb_create_gc(win->c, win->gc, win->window, XCB_GC_BACKGROUND | XCB_GC_GRAPHICS_EXPOSURES, values); /* set background pixmap */ rect.x = 0; rect.y = 0; rect.width = width; rect.height = height; win->pixmap = xcb_generate_id(win->c); xcb_create_pixmap(win->c, win->depth, win->pixmap, win->window, width, height); xcb_poly_fill_rectangle(win->c, win->pixmap, win->gc, 1, &rect); xcb_map_window(win->c, win->window); xcb_flush(win->c); return win; disconnect_c: xcb_disconnect(win->c); free_win: free(win); return NULL; }
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); }
/** * Probe the X server. */ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg, video_format_t *fmtp, vlc_video_context *ctx) { vlc_object_t *obj = VLC_OBJECT(vd); vout_display_sys_t *sys = vlc_obj_malloc(obj, sizeof (*sys)); if (unlikely(sys == NULL)) return VLC_ENOMEM; vd->sys = sys; /* Connect to X */ xcb_connection_t *conn; const xcb_screen_t *screen; if (vlc_xcb_parent_Create(vd, cfg, &conn, &screen) == NULL) return VLC_EGENERIC; sys->conn = conn; sys->root = screen->root; sys->format.argb = 0; sys->format.alpha = 0; if (!CheckRender(vd, conn)) goto error; xcb_render_query_pict_formats_cookie_t pic_fmt_ck = xcb_render_query_pict_formats(conn); xcb_render_query_pict_formats_reply_t *pic_fmt_r = xcb_render_query_pict_formats_reply(conn, pic_fmt_ck, NULL); if (pic_fmt_r == NULL) goto error; const xcb_setup_t *setup = xcb_get_setup(conn); const xcb_render_pictforminfo_t *const pic_fmts = xcb_render_query_pict_formats_formats(pic_fmt_r); xcb_visualid_t visual = 0; for (unsigned i = 0; i < pic_fmt_r->num_formats; i++) { const xcb_render_pictforminfo_t *const pic_fmt = pic_fmts + i; const xcb_render_directformat_t *const d = &pic_fmt->direct; if (pic_fmt->depth == 8 && pic_fmt->direct.alpha_mask == 0xff) { /* Alpha mask format */ sys->format.alpha = pic_fmt->id; continue; } xcb_visualid_t vid = FindVisual(setup, screen, pic_fmt_r, pic_fmt->id); if (vid == 0) continue; /* Use only ARGB for now. 32-bits is guaranteed to work. */ if (pic_fmt->depth != 32) continue; vlc_fourcc_t chroma = ParseFormat(setup, pic_fmt); if (chroma == 0) continue; fmtp->i_chroma = chroma; fmtp->i_rmask = ((uint32_t)d->red_mask) << d->red_shift; fmtp->i_gmask = ((uint32_t)d->green_mask) << d->green_shift; fmtp->i_bmask = ((uint32_t)d->blue_mask) << d->blue_shift; sys->format.argb = pic_fmt->id; visual = vid; } free(pic_fmt_r); if (unlikely(sys->format.argb == 0 || sys->format.alpha == 0)) goto error; /* Buggy server */ msg_Dbg(obj, "using RENDER picture format %u", sys->format.argb); msg_Dbg(obj, "using X11 visual 0x%"PRIx32, visual); char *filter = var_InheritString(obj, "x11-render-filter"); if (filter != NULL) { msg_Dbg(obj, "using filter \"%s\"", filter); sys->filter = ToCharset("ISO 8859-1", filter, &(size_t){ 0 }); free(filter); } else sys->filter = NULL; sys->drawable.source = xcb_generate_id(conn); sys->drawable.crop = xcb_generate_id(conn); sys->drawable.scale = xcb_generate_id(conn); sys->drawable.subpic = xcb_generate_id(conn); sys->drawable.alpha = xcb_generate_id(conn); sys->drawable.dest = xcb_generate_id(conn); sys->picture.source = xcb_generate_id(conn); sys->picture.crop = xcb_generate_id(conn); sys->picture.scale = xcb_generate_id(conn); sys->picture.subpic = xcb_generate_id(conn); sys->picture.alpha = xcb_generate_id(conn); sys->picture.dest = xcb_generate_id(conn); sys->gc = xcb_generate_id(conn); if (XCB_shm_Check(obj, conn)) sys->segment = xcb_generate_id(conn); else sys->segment = 0; xcb_colormap_t cmap = xcb_generate_id(conn); uint32_t cw_mask = XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP; const uint32_t cw_list[] = { /* XCB_CW_BACK_PIXEL */ screen->black_pixel, /* XCB_CW_BORDER_PIXEL */ screen->black_pixel, /* XCB_CW_EVENT_MASK */ 0, /* XCB_CW_COLORMAP */ cmap, }; xcb_create_colormap(conn, XCB_COLORMAP_ALLOC_NONE, cmap, screen->root, visual); xcb_create_pixmap(conn, 32, sys->drawable.source, screen->root, vd->source.i_width, vd->source.i_height); xcb_create_gc(conn, sys->gc, sys->drawable.source, 0, NULL); xcb_create_window(conn, 32, sys->drawable.dest, cfg->window->handle.xid, 0, 0, cfg->display.width, cfg->display.height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, visual, cw_mask, cw_list); xcb_render_create_picture(conn, sys->picture.source, sys->drawable.source, sys->format.argb, 0, NULL); xcb_render_create_picture(conn, sys->picture.dest, sys->drawable.dest, sys->format.argb, 0, NULL); CreateBuffers(vd, cfg); xcb_map_window(conn, sys->drawable.dest); sys->spu_chromas[0] = fmtp->i_chroma; sys->spu_chromas[1] = 0; vd->info.subpicture_chromas = sys->spu_chromas; vd->prepare = Prepare; vd->display = Display; vd->control = Control; (void) ctx; return VLC_SUCCESS; error: xcb_disconnect(conn); return VLC_EGENERIC; }
/** * Probe the X server. */ static int Open (vlc_object_t *obj) { vout_display_t *vd = (vout_display_t *)obj; vout_display_sys_t *sys = malloc (sizeof (*sys)); if (unlikely(sys == NULL)) return VLC_ENOMEM; vd->sys = sys; sys->pool = NULL; /* Get window, connect to X server */ xcb_connection_t *conn; const xcb_screen_t *scr; uint16_t width, height; sys->embed = XCB_parent_Create (vd, &conn, &scr, &width, &height); if (sys->embed == NULL) { free (sys); return VLC_EGENERIC; } sys->conn = conn; const xcb_setup_t *setup = xcb_get_setup (conn); /* Determine our pixel format */ video_format_t fmt_pic; xcb_visualid_t vid; sys->depth = 0; for (const xcb_format_t *fmt = xcb_setup_pixmap_formats (setup), *end = fmt + xcb_setup_pixmap_formats_length (setup); fmt < end; fmt++) { if (fmt->depth <= sys->depth) continue; /* no better than earlier format */ fmt_pic = vd->fmt; /* Check that the pixmap format is supported by VLC. */ switch (fmt->depth) { case 32: if (fmt->bits_per_pixel != 32) continue; fmt_pic.i_chroma = VLC_CODEC_ARGB; break; case 24: if (fmt->bits_per_pixel == 32) fmt_pic.i_chroma = VLC_CODEC_RGB32; else if (fmt->bits_per_pixel == 24) fmt_pic.i_chroma = VLC_CODEC_RGB24; else continue; break; case 16: if (fmt->bits_per_pixel != 16) continue; fmt_pic.i_chroma = VLC_CODEC_RGB16; break; case 15: if (fmt->bits_per_pixel != 16) continue; fmt_pic.i_chroma = VLC_CODEC_RGB15; break; case 8: if (fmt->bits_per_pixel != 8) continue; fmt_pic.i_chroma = VLC_CODEC_RGB8; break; default: continue; } /* Byte sex is a non-issue for 8-bits. It can be worked around with * RGB masks for 24-bits. Too bad for 15-bits and 16-bits. */ if (fmt->bits_per_pixel == 16 && setup->image_byte_order != ORDER) continue; /* Make sure the X server is sane */ assert (fmt->bits_per_pixel > 0); if (unlikely(fmt->scanline_pad % fmt->bits_per_pixel)) continue; /* Check that the selected screen supports this depth */ const xcb_depth_t *d = FindDepth (scr, fmt->depth); if (d == NULL) continue; /* Find a visual type for the selected depth */ const xcb_visualtype_t *vt = xcb_depth_visuals (d); /* First try True Color class */ for (int i = xcb_depth_visuals_length (d); i > 0; i--) { if (vt->_class == XCB_VISUAL_CLASS_TRUE_COLOR) { fmt_pic.i_rmask = vt->red_mask; fmt_pic.i_gmask = vt->green_mask; fmt_pic.i_bmask = vt->blue_mask; found_visual: vid = vt->visual_id; msg_Dbg (vd, "using X11 visual ID 0x%"PRIx32, vid); sys->depth = fmt->depth; msg_Dbg (vd, " %"PRIu8" bits depth", sys->depth); msg_Dbg (vd, " %"PRIu8" bits per pixel", fmt->bits_per_pixel); msg_Dbg (vd, " %"PRIu8" bits line pad", fmt->scanline_pad); goto found_format; } vt++; } /* Then try Static Gray class */ if (fmt->depth != 8) continue; vt = xcb_depth_visuals (d); for (int i = xcb_depth_visuals_length (d); i > 0 && !vid; i--) { if (vt->_class == XCB_VISUAL_CLASS_STATIC_GRAY) { fmt_pic.i_chroma = VLC_CODEC_GREY; goto found_visual; } vt++; } } msg_Err (obj, "no supported pixel format & visual"); goto error; found_format:; /* Create colormap (needed to select non-default visual) */ xcb_colormap_t cmap; if (vid != scr->root_visual) { cmap = xcb_generate_id (conn); xcb_create_colormap (conn, XCB_COLORMAP_ALLOC_NONE, cmap, scr->root, vid); } else cmap = scr->default_colormap; /* Create window */ sys->window = xcb_generate_id (conn); sys->gc = xcb_generate_id (conn); xcb_pixmap_t pixmap = xcb_generate_id (conn); { const uint32_t mask = XCB_CW_BACK_PIXMAP | XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXMAP | XCB_CW_BORDER_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP; const uint32_t values[] = { /* XCB_CW_BACK_PIXMAP */ pixmap, /* XCB_CW_BACK_PIXEL */ scr->black_pixel, /* XCB_CW_BORDER_PIXMAP */ pixmap, /* XCB_CW_BORDER_PIXEL */ scr->black_pixel, /* XCB_CW_EVENT_MASK */ XCB_EVENT_MASK_VISIBILITY_CHANGE, /* XCB_CW_COLORMAP */ cmap, }; xcb_void_cookie_t c; xcb_create_pixmap (conn, sys->depth, pixmap, scr->root, 1, 1); c = xcb_create_window_checked (conn, sys->depth, sys->window, sys->embed->handle.xid, 0, 0, width, height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, vid, mask, values); xcb_map_window (conn, sys->window); /* Create graphic context (I wonder why the heck do we need this) */ xcb_create_gc (conn, sys->gc, sys->window, 0, NULL); if (XCB_error_Check (vd, conn, "cannot create X11 window", c)) goto error; } msg_Dbg (vd, "using X11 window %08"PRIx32, sys->window); msg_Dbg (vd, "using X11 graphic context %08"PRIx32, sys->gc); sys->cursor = XCB_cursor_Create (conn, scr); sys->visible = false; if (XCB_shm_Check (obj, conn)) { sys->seg_base = xcb_generate_id (conn); for (unsigned i = 1; i < MAX_PICTURES; i++) xcb_generate_id (conn); } else sys->seg_base = 0; /* Setup vout_display_t once everything is fine */ vd->info.has_pictures_invalid = true; vd->info.has_event_thread = true; vd->fmt = fmt_pic; vd->pool = Pool; vd->prepare = NULL; vd->display = Display; vd->control = Control; vd->manage = Manage; /* */ bool is_fullscreen = vd->cfg->is_fullscreen; if (is_fullscreen && vout_window_SetFullScreen (sys->embed, true)) is_fullscreen = false; vout_display_SendEventFullscreen (vd, is_fullscreen); vout_display_SendEventDisplaySize (vd, width, height, is_fullscreen); return VLC_SUCCESS; error: Close (obj); return VLC_EGENERIC; }