void PRESENTDestroy(Display *dpy, PRESENTpriv *present_priv) { PRESENTPixmapPriv *current = NULL; pthread_mutex_lock(&present_priv->mutex_present); PRESENTForceReleases(present_priv); current = present_priv->first_present_priv; while (current) { PRESENTPixmapPriv *next = current->next; PRESENTDestroyPixmapContent(dpy, current); free(current); current = next; } PRESENTFreeXcbQueue(present_priv); xcb_disconnect(present_priv->xcb_connection); xcb_disconnect(present_priv->xcb_connection_bis); pthread_mutex_unlock(&present_priv->mutex_present); pthread_mutex_destroy(&present_priv->mutex_present); pthread_mutex_destroy(&present_priv->mutex_xcb_wait); free(present_priv); }
void SimplicityApplication::initialize_x_connection(void) { int nScreenNum = 0; m_pXConnection = xcb_connect(m_sDisplayName.c_str(), &nScreenNum); if (check_xcb_connection(m_pXConnection)) { xcb_disconnect(m_pXConnection); m_bRunning = false; return; } xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(m_pXConnection)); for (int i = 0; i != nScreenNum; i++) xcb_screen_next(&iter); m_pRootScreen = iter.data; if (m_pRootScreen == nullptr) { global_log_error << "Could not get the current screen. Exiting"; xcb_disconnect(m_pXConnection); m_bRunning = false; } global_log_debug << "Root screen dimensions: " << m_pRootScreen->width_in_pixels << "x" << m_pRootScreen->height_in_pixels; global_log_debug << "Root window: " << m_pRootScreen->root; }
static void cursor_set (xcb_connection_t *c, xcb_screen_t *screen, xcb_window_t window, int cursor_id) { uint32_t values_list[3]; xcb_void_cookie_t cookie_font; xcb_void_cookie_t cookie_gc; xcb_generic_error_t *error; xcb_font_t font; xcb_cursor_t cursor; xcb_gcontext_t gc; uint32_t mask; uint32_t value_list; font = xcb_generate_id (c); cookie_font = xcb_open_font_checked (c, font, strlen ("cursor"), "cursor"); error = xcb_request_check (c, cookie_font); if (error) { fprintf (stderr, "ERROR: can't open font : %d\n", error->error_code); xcb_disconnect (c); exit (-1); } cursor = xcb_generate_id (c); xcb_create_glyph_cursor (c, cursor, font, font, cursor_id, cursor_id + 1, 0, 0, 0, 0, 0, 0); gc = xcb_generate_id (c); mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT; values_list[0] = screen->black_pixel; values_list[1] = screen->white_pixel; values_list[2] = font; cookie_gc = xcb_create_gc_checked (c, gc, window, mask, values_list); error = xcb_request_check (c, cookie_gc); if (error) { fprintf (stderr, "ERROR: can't create gc : %d\n", error->error_code); xcb_disconnect (c); exit (-1); } mask = XCB_CW_CURSOR; value_list = cursor; xcb_change_window_attributes (c, window, mask, &value_list); xcb_free_cursor (c, cursor); cookie_font = xcb_close_font_checked (c, font); error = xcb_request_check (c, cookie_font); if (error) { fprintf (stderr, "ERROR: can't close font : %d\n", error->error_code); xcb_disconnect (c); exit (-1); } }
int main () { xcb_connection_t* connection; xcb_screen_t* screen; xcb_window_t root_window; xcb_alloc_color_reply_t *color_reply; xcb_colormap_t colormap = { 0 }; uint32_t params[1]; uint16_t r,g,b; connection = xcb_connect(NULL, NULL); if (!connection) { fprintf(stderr, "ERROR: can't connect to an X server\n"); return -1; } screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data; if (!screen) { fprintf(stderr, "ERROR: can't setup a screen\n"); xcb_disconnect(connection); return -1; } root_window = screen->root; colormap = screen->default_colormap; r = 60000, g = 20000, b = 20000; color_reply = xcb_alloc_color_reply(connection, xcb_alloc_color(connection, colormap, r, g, b), NULL); if(!color_reply) { fprintf(stderr, "ERROR: can't alloc an color\n"); xcb_disconnect(connection); return 0; } params[0] = color_reply->pixel; // sets the root_window back_pixel to pixel(params) xcb_change_window_attributes(connection, root_window, XCB_CW_BACK_PIXEL, params); // free color resources free(color_reply); // waits all things are send?? xcb_flush(connection); // xcb_destroy_window(connection, window); xcb_disconnect(connection); return 0; }
static cairo_surface_t * create_source_surface (int size) { #if CAIRO_HAS_XCB_SURFACE xcb_render_pictforminfo_t *render_format; struct closure *data; cairo_surface_t *surface; xcb_screen_t *root; xcb_void_cookie_t cookie; void *formats; data = xmalloc (sizeof (struct closure)); data->connection = xcb_connect (NULL, NULL); render_format = find_depth (data->connection, 32, &formats); if (render_format == NULL) { xcb_disconnect (data->connection); free (data); return NULL; } root = xcb_setup_roots_iterator (xcb_get_setup (data->connection)).data; data->pixmap = xcb_generate_id (data->connection); cookie = xcb_create_pixmap_checked (data->connection, 32, data->pixmap, root->root, size, size); /* slow, but sure */ if (xcb_request_check (data->connection, cookie) != NULL) { free (formats); xcb_disconnect (data->connection); free (data); return NULL; } surface = cairo_xcb_surface_create_with_xrender_format (data->connection, root, data->pixmap, render_format, size, size); free (formats); data->device = cairo_device_reference (cairo_surface_get_device (surface)); cairo_surface_set_user_data (surface, &closure_key, data, cleanup); return surface; #else return NULL; #endif }
static xcb_gc_t gc_font_get (xcb_connection_t *c, xcb_screen_t *screen, xcb_window_t window, const char *font_name) { uint32_t value_list[3]; xcb_void_cookie_t cookie_font; xcb_void_cookie_t cookie_gc; xcb_generic_error_t *error; xcb_font_t font; xcb_gcontext_t gc; uint32_t mask; font = xcb_generate_id (c); cookie_font = xcb_open_font_checked (c, font, strlen (font_name), font_name); error = xcb_request_check (c, cookie_font); if (error) { fprintf (stderr, "ERROR: can't open font : %d\n", error->error_code); xcb_disconnect (c); return -1; } gc = xcb_generate_id (c); mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT; value_list[0] = screen->black_pixel; value_list[1] = screen->white_pixel; value_list[2] = font; cookie_gc = xcb_create_gc_checked (c, gc, window, mask, value_list); error = xcb_request_check (c, cookie_gc); if (error) { fprintf (stderr, "ERROR: can't create gc : %d\n", error->error_code); xcb_disconnect (c); exit (-1); } cookie_font = xcb_close_font_checked (c, font); error = xcb_request_check (c, cookie_font); if (error) { fprintf (stderr, "ERROR: can't close font : %d\n", error->error_code); xcb_disconnect (c); exit (-1); } return gc; }
int randr_init(randr_state_t *state) { /* Initialize state. */ state->screen_num = -1; state->crtc_num = NULL; state->crtc_num_count = 0; state->crtc_count = 0; state->crtcs = NULL; state->preserve = 0; xcb_generic_error_t *error; /* Open X server connection */ state->conn = xcb_connect(NULL, &state->preferred_screen); /* Query RandR version */ xcb_randr_query_version_cookie_t ver_cookie = xcb_randr_query_version(state->conn, RANDR_VERSION_MAJOR, RANDR_VERSION_MINOR); xcb_randr_query_version_reply_t *ver_reply = xcb_randr_query_version_reply(state->conn, ver_cookie, &error); /* TODO What does it mean when both error and ver_reply is NULL? Apparently, we have to check both to avoid seg faults. */ if (error || ver_reply == NULL) { int ec = (error != 0) ? error->error_code : -1; fprintf(stderr, _("`%s' returned error %d\n"), "RANDR Query Version", ec); xcb_disconnect(state->conn); return -1; } if (ver_reply->major_version != RANDR_VERSION_MAJOR || ver_reply->minor_version < RANDR_VERSION_MINOR) { fprintf(stderr, _("Unsupported RANDR version (%u.%u)\n"), ver_reply->major_version, ver_reply->minor_version); free(ver_reply); xcb_disconnect(state->conn); return -1; } free(ver_reply); return 0; }
int XCloseDisplay ( register Display *dpy) { register _XExtension *ext; register int i; if (!(dpy->flags & XlibDisplayClosing)) { dpy->flags |= XlibDisplayClosing; for (i = 0; i < dpy->nscreens; i++) { register Screen *sp = &dpy->screens[i]; XFreeGC (dpy, sp->default_gc); } if (dpy->cursor_font != None) { XUnloadFont (dpy, dpy->cursor_font); } XSync(dpy, 1); /* throw away pending events, catch errors */ /* call out to any extensions interested */ for (ext = dpy->ext_procs; ext; ext = ext->next) { if (ext->close_display) (*ext->close_display)(dpy, &ext->codes); } /* if the closes generated more protocol, sync them up */ if (dpy->request != dpy->last_request_read) XSync(dpy, 1); } xcb_disconnect(dpy->xcb->connection); _XFreeDisplayStructure (dpy); return 0; }
/** * Stop the capture */ static void xshm_capture_stop(struct xshm_data *data) { obs_enter_graphics(); if (data->texture) { gs_texture_destroy(data->texture); data->texture = NULL; } if (data->cursor) { xcb_xcursor_destroy(data->cursor); data->cursor = NULL; } obs_leave_graphics(); if (data->xshm) { xshm_xcb_detach(data->xshm); data->xshm = NULL; } if (data->xcb) { xcb_disconnect(data->xcb); data->xcb = NULL; } if (data->server) { bfree(data->server); data->server = NULL; } }
void DisplayVkXcb::terminate() { ASSERT(mXcbConnection != nullptr); xcb_disconnect(mXcbConnection); mXcbConnection = nullptr; DisplayVk::terminate(); }
/** Perform cleanup on normal exit */ static void exit_cleanup(void) { debug("Cleaning resources up"); /* Destroy CM window, thus giving up _NET_WM_CM_Sn ownership */ if(globalconf.cm_window != XCB_NONE) xcb_destroy_window(globalconf.connection, globalconf.cm_window); /* Free resources related to the plugins */ plugin_unload_all(); /* Destroy the linked-list of windows which has to be done after unloading the plugins as the plugins may use the windows list to free memory */ window_list_cleanup(); /* Free resources related to the rendering backend which has to be done after the windows list cleanup as the latter free the rendering information associated with each window */ rendering_unload(); /* Free resources related to the keymaps */ xcb_key_symbols_free(globalconf.keysyms); /* Free resources related to EWMH */ xcb_ewmh_connection_wipe(&globalconf.ewmh); cfg_free(globalconf.cfg); free(globalconf.rendering_dir); free(globalconf.plugins_dir); xcb_disconnect(globalconf.connection); }
void v_window::_deInitOSWindow() { xcb_destroy_window(_xcb_connection,_xcb_window); xcb_disconnect(_xcb_connection); _xcb_connection = nullptr; _xcb_window = 0; }
void init(void) { int scrno; xcb_screen_iterator_t iter; conn = xcb_connect(NULL, &scrno); if (!conn) { fprintf(stderr, "can't connect to an X server\n"); exit(1); } iter = xcb_setup_roots_iterator(xcb_get_setup(conn)); for (int i = 0; i < scrno; ++i) { xcb_screen_next(&iter); } screen = iter.data; if (!screen) { fprintf(stderr, "can't get the current screen\n"); xcb_disconnect(conn); exit(1); } }
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; }
/** Call before exiting. */ void awesome_atexit(bool restart) { int screen_nbr, nscreens; if(globalconf.hooks.exit != LUA_REFNIL) luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.exit, 0, 0); lua_pushboolean(globalconf.L, restart); signal_object_emit(globalconf.L, &global_signals, "exit", 1); a_dbus_cleanup(); /* do this only for real screen */ const xcb_setup_t *setup = xcb_get_setup(globalconf.connection); nscreens = setup ? xcb_setup_roots_length(setup) : -1; for(screen_nbr = 0; screen_nbr < nscreens; screen_nbr++) systray_cleanup(0, screen_nbr); //FIXME: Clean physical screens /* Close Lua */ lua_close(globalconf.L); xcb_flush(globalconf.connection); /* Disconnect *after* closing lua */ xcb_disconnect(globalconf.connection); ev_default_destroy(); }
ShellXcb::~ShellXcb() { cleanup_vk(); dlclose(lib_handle_); xcb_disconnect(c_); }
int main() { /* Open the connection to the X server */ xcb_connection_t *connection = xcb_connect(NULL, NULL); /* Get the first screen */ const xcb_setup_t *setup = xcb_get_setup(connection); xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup); xcb_screen_t *screen = iter.data; /* Create the window */ xcb_window_t window = xcb_generate_id(connection); xcb_create_window(connection, /* Connection */ XCB_COPY_FROM_PARENT, /* depth (same as root) */ window, /* window Id */ screen->root, /* parent window */ 0, 0, /* x, y */ 150, 150, /* width, height */ 10, /* border_width */ XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ screen->root_visual, /* visual */ 0, NULL); /* masks, not used yet */ /* Map the window on the screen */ xcb_map_window(connection, window); /* Make sure commands are sent before we pause so that the window gets shown */ xcb_flush(connection); pause(); /* hold client until Ctrl-C */ xcb_disconnect(connection); return 0; }
static void cleanup(void) { /* graceful exit */ if (conn != NULL) xcb_disconnect(conn); }
/** * Wrap an existing X11 window to embed the video. */ static int EmOpen (vout_window_t *wnd, const vout_window_cfg_t *cfg) { xcb_window_t window = var_InheritInteger (wnd, "drawable-xid"); if (window == 0) return VLC_EGENERIC; if (AcquireDrawable (VLC_OBJECT(wnd), window)) return VLC_EGENERIC; vout_window_sys_t *p_sys = malloc (sizeof (*p_sys)); xcb_connection_t *conn = xcb_connect (NULL, NULL); if (p_sys == NULL || xcb_connection_has_error (conn)) goto error; p_sys->embedded = true; p_sys->keys = NULL; wnd->handle.xid = window; wnd->control = Control; wnd->sys = p_sys; p_sys->conn = conn; xcb_get_geometry_reply_t *geo = xcb_get_geometry_reply (conn, xcb_get_geometry (conn, window), NULL); if (geo == NULL) { msg_Err (wnd, "bad X11 window 0x%08"PRIx8, window); goto error; } p_sys->root = geo->root; free (geo); if (var_InheritBool (wnd, "keyboard-events")) { p_sys->keys = CreateKeyHandler (VLC_OBJECT(wnd), conn); if (p_sys->keys != NULL) { const uint32_t mask = XCB_CW_EVENT_MASK; const uint32_t values[1] = { XCB_EVENT_MASK_KEY_PRESS, }; xcb_change_window_attributes (conn, window, mask, values); } } CacheAtoms (p_sys); if ((p_sys->keys != NULL) && vlc_clone (&p_sys->thread, Thread, wnd, VLC_THREAD_PRIORITY_LOW)) DestroyKeyHandler (p_sys->keys); xcb_flush (conn); (void) cfg; return VLC_SUCCESS; error: xcb_disconnect (conn); free (p_sys); ReleaseDrawable (VLC_OBJECT(wnd), window); return VLC_EGENERIC; }
static void cleanup() { if (nil_.key_syms) { xcb_key_symbols_free(nil_.key_syms); } if (nil_.font.id) { xcb_close_font(nil_.con, nil_.font.id); } if (nil_.cursor[CURSOR_NORMAL]) { xcb_free_cursor(nil_.con, nil_.cursor[CURSOR_NORMAL]); } if (nil_.cursor[CURSOR_MOVE] && (nil_.cursor[CURSOR_MOVE] != nil_.cursor[CURSOR_NORMAL])) { xcb_free_cursor(nil_.con, nil_.cursor[CURSOR_MOVE]); } if (nil_.cursor[CURSOR_RESIZE] && (nil_.cursor[CURSOR_RESIZE] != nil_.cursor[CURSOR_NORMAL])) { xcb_free_cursor(nil_.con, nil_.cursor[CURSOR_RESIZE]); } if (bar_.win) { xcb_destroy_window(nil_.con, bar_.win); } xcb_ungrab_keyboard(nil_.con, XCB_TIME_CURRENT_TIME); xcb_destroy_subwindows(nil_.con, nil_.scr->root); xcb_flush(nil_.con); xcb_disconnect(nil_.con); if (nil_.ws) { free(nil_.ws); } }
static void Close(vout_display_t *vd) { vout_display_sys_t *sys = vd->sys; free(sys->filter); xcb_disconnect(sys->conn); }
int main(int argc, char **argv) { (void)argc; (void)argv; /* open connection with the server */ nil_.con = xcb_connect(0, 0); if (xcb_connection_has_error(nil_.con)) { NIL_ERR("xcb_connect %p", (void *)nil_.con); exit(1); } /* 1st stage */ if ((init_screen() != 0) || (init_key() != 0) || (init_mouse() != 0)) { xcb_disconnect(nil_.con); exit(1); } /* 2nd stage */ if ((init_cursor() != 0) || (init_color() != 0) != (init_font() != 0) || (init_bar() != 0) || (init_wm() != 0)) { cleanup(); exit(1); } xcb_flush(nil_.con); recv_events(); cleanup(); return 0; }
static void _cairo_boilerplate_xcb_cleanup (void *closure) { xcb_target_closure_t *xtc = closure; cairo_status_t status; cairo_surface_finish (xtc->surface); if (xtc->is_pixmap) xcb_free_pixmap (xtc->c, xtc->drawable); else xcb_destroy_window (xtc->c, xtc->drawable); cairo_surface_destroy (xtc->surface); cairo_device_finish (xtc->device); cairo_device_destroy (xtc->device); /* First synchronize with the X server to make sure there are no more errors * in-flight which we would miss otherwise */ _cairo_boilerplate_xcb_sync_server (xtc); status = _cairo_boilerplate_xcb_handle_errors (xtc); assert (status == CAIRO_STATUS_SUCCESS); xcb_disconnect (xtc->c); free (xtc); }
/* * Checks a generic cookie for errors and quits with the given message if there * was an error. * */ void check_error(xcb_connection_t *conn, xcb_void_cookie_t cookie, char *err_message) { xcb_generic_error_t *error = xcb_request_check(conn, cookie); if (error != NULL) { fprintf(stderr, "ERROR: %s (X error %d)\n", err_message, error->error_code); xcb_disconnect(conn); exit(-1); } }
void NGBUninit() { if(event) { free(event); } xcb_disconnect(con); }
int main(void) { xcb_connection_t *dpy = xcb_connect(NULL, NULL); if (dpy == NULL) { fprintf(stderr, "Can't connect to X.\n"); return EXIT_FAILURE; } xcb_atom_t WM_PROTOCOLS, WM_DELETE_WINDOW; if (!get_atom(dpy, "WM_PROTOCOLS", &WM_PROTOCOLS) || !get_atom(dpy, "WM_DELETE_WINDOW", &WM_DELETE_WINDOW)) { fprintf(stderr, "Can't get required atoms.\n"); xcb_disconnect(dpy); return EXIT_FAILURE; } xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(dpy)).data; if (screen == NULL) { fprintf(stderr, "Can't get current screen.\n"); xcb_disconnect(dpy); return EXIT_FAILURE; } xcb_window_t win = xcb_generate_id(dpy); uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; uint32_t values[] = {0xff111111, XCB_EVENT_MASK_EXPOSURE}; xcb_create_window(dpy, XCB_COPY_FROM_PARENT, win, screen->root, 0, 0, 320, 240, 2, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, mask, values); xcb_icccm_set_wm_class(dpy, win, sizeof(TEST_WINDOW_IC), TEST_WINDOW_IC); xcb_map_window(dpy, win); xcb_flush(dpy); xcb_generic_event_t *evt; bool running = true; while (running && (evt = xcb_wait_for_event(dpy)) != NULL) { uint8_t rt = XCB_EVENT_RESPONSE_TYPE(evt); if (rt == XCB_CLIENT_MESSAGE) { xcb_client_message_event_t *cme = (xcb_client_message_event_t *) evt; if (cme->type == WM_PROTOCOLS && cme->data.data32[0] == WM_DELETE_WINDOW) { running = false; } } else if (rt == XCB_EXPOSE) { render_text(dpy, win, 12, 24); } free(evt); } xcb_destroy_window(dpy, win); xcb_disconnect(dpy); return EXIT_SUCCESS; }
VulkanExampleBase::~VulkanExampleBase() { // Clean up Vulkan resources swapChain.cleanup(); if (descriptorPool != VK_NULL_HANDLE) { vkDestroyDescriptorPool(device, descriptorPool, nullptr); } if (setupCmdBuffer != VK_NULL_HANDLE) { vkFreeCommandBuffers(device, cmdPool, 1, &setupCmdBuffer); } destroyCommandBuffers(); vkDestroyRenderPass(device, renderPass, nullptr); for (uint32_t i = 0; i < frameBuffers.size(); i++) { vkDestroyFramebuffer(device, frameBuffers[i], nullptr); } for (auto& shaderModule : shaderModules) { vkDestroyShaderModule(device, shaderModule, nullptr); } vkDestroyImageView(device, depthStencil.view, nullptr); vkDestroyImage(device, depthStencil.image, nullptr); vkFreeMemory(device, depthStencil.mem, nullptr); vkDestroyPipelineCache(device, pipelineCache, nullptr); if (textureLoader) { delete textureLoader; } vkDestroyCommandPool(device, cmdPool, nullptr); vkDestroySemaphore(device, semaphores.presentComplete, nullptr); vkDestroySemaphore(device, semaphores.renderComplete, nullptr); vkDestroyDevice(device, nullptr); if (enableValidation) { vkDebug::freeDebugCallback(instance); } vkDestroyInstance(instance, nullptr); #if defined(__linux) #if defined(__ANDROID__) // todo : android cleanup (if required) #else xcb_destroy_window(connection, window); xcb_disconnect(connection); #endif #endif }
int main(int argc, char **argv) { uint32_t width = test_width - 2 * INSET_X; uint32_t height = test_height - 2 * INSET_Y; int snum; xcb_void_cookie_t check_cookie; xcb_window_t w; xcb_gcontext_t gc; xcb_pixmap_t pix; xcb_connection_t *c = xcb_connect(0, &snum); xcb_screen_t *s = xcb_aux_get_screen(c, snum); xcb_alloc_named_color_cookie_t bg_cookie = xcb_alloc_named_color(c, s->default_colormap, strlen("white"), "white"); xcb_alloc_named_color_cookie_t fg_cookie = xcb_alloc_named_color(c, s->default_colormap, strlen("black"), "black"); xcb_alloc_named_color_reply_t *bg_reply = xcb_alloc_named_color_reply(c, bg_cookie, 0); xcb_alloc_named_color_reply_t *fg_reply = xcb_alloc_named_color_reply(c, fg_cookie, 0); uint32_t fg, bg; xcb_image_t *image, *native_image, *subimage; uint32_t mask = 0; xcb_params_gc_t gcv; assert(bg_reply && fg_reply); bg = bg_reply->pixel; fg = fg_reply->pixel; free(bg_reply); free(fg_reply); w = make_window(c, s, bg, fg, width, height); gc = xcb_generate_id(c); check_cookie = xcb_create_gc_checked(c, gc, w, 0, 0); assert(!xcb_request_check(c, check_cookie)); image = xcb_image_create_from_bitmap_data((uint8_t *)test_bits, test_width, test_height); native_image = xcb_image_native(c, image, 1); assert(native_image); if (native_image != image) xcb_image_destroy(image); subimage = xcb_image_subimage(native_image, INSET_X, INSET_Y, width, height, 0, 0, 0); assert(subimage); xcb_image_destroy(native_image); subimage->format = XCB_IMAGE_FORMAT_XY_BITMAP; pix = xcb_generate_id(c); xcb_create_pixmap(c, s->root_depth, pix, w, subimage->width, subimage->height); gc = xcb_generate_id(c); XCB_AUX_ADD_PARAM(&mask, &gcv, foreground, fg); XCB_AUX_ADD_PARAM(&mask, &gcv, background, bg); xcb_aux_create_gc(c, gc, pix, mask, &gcv); xcb_image_put(c, pix, gc, subimage, 0, 0, 0); process_events(c, gc, w, pix, width, height); xcb_disconnect(c); return 1; }
void xpost_view_win_del(Xpost_View_Window *win) { if (!win) return; xcb_disconnect(win->c); free(win); }
void check_request(xcb_connection_t *dpy, xcb_void_cookie_t cookie, char *msg) { xcb_generic_error_t *err = xcb_request_check(dpy, cookie); if (err != NULL) { fprintf(stderr, "%s: error code: %u.\n", msg, err->error_code); xcb_disconnect(dpy); exit(-1); } }