首页 > 解决方案 > 如何在 mac 上使用 libxcb?

问题描述

我的笔记本电脑是 Macbook Pro。我在上面安装了 libxcb 并尝试了 x.org 给出的一个简单示例:

#include <unistd.h>      /* pause() */
#include <xcb/xcb.h>

int main ()
{
    xcb_connection_t *c;
    xcb_screen_t     *screen;
    xcb_window_t      win;

    /* Open the connection to the X server */
    c = xcb_connect (NULL, NULL);

    /* Get the first screen */
    screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;

    /* Ask for our window's Id */
    win = xcb_generate_id(c);

    /* Create the window */
    xcb_create_window (c,                             /* Connection        */
                       XCB_COPY_FROM_PARENT,          /* depth (same as root)*/
                       win,                           /* 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 (c, win);

    /* Make sure commands are sent before we pause, so window is shown */
    xcb_flush (c);

    pause ();    /* hold client until Ctrl-C */

    return 0;
}

但是屏幕上没有显示窗口。有什么我忘记了吗?

标签: cx11xcb

解决方案


推荐阅读