#include #include #include #include #include #include #define WIDTH 300 #define HEIGHT 150 static void testCookie (xcb_void_cookie_t cookie, xcb_connection_t *connection, char *errMessage ) { xcb_generic_error_t *error = xcb_request_check (connection, cookie); if (error) { fprintf (stderr, "ERROR: %s : %"PRIu8"\n", errMessage , error->error_code); xcb_disconnect (connection); exit (-1); } } int main () { /* get the connection */ int screenNum; xcb_connection_t *connection = xcb_connect (NULL, &screenNum); if (!connection) { fprintf (stderr, "ERROR: can't connect to an X server\n"); return -1; } /* get the current screen */ xcb_screen_iterator_t iter = xcb_setup_roots_iterator (xcb_get_setup (connection)); /* we want the screen at index screenNum of the iterator */ for (int i = 0; i < screenNum; ++i) { xcb_screen_next (&iter); } xcb_screen_t *screen = iter.data; if (!screen) { fprintf (stderr, "ERROR: can't get the current screen\n"); xcb_disconnect (connection); return -1; } /* create the window */ xcb_window_t window = xcb_generate_id (connection); uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; uint32_t values[2]; values[0] = screen->white_pixel; values[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_POINTER_MOTION; xcb_void_cookie_t windowCookie = xcb_create_window_checked (connection, screen->root_depth, window, screen->root, 20, 200, WIDTH, HEIGHT, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, mask, values ); testCookie (windowCookie, connection, "can't create window"); xcb_void_cookie_t mapCookie = xcb_map_window_checked (connection, window); testCookie (mapCookie, connection, "can't map window"); /* create the 1x1 window */ xcb_window_t window1 = xcb_generate_id (connection); xcb_void_cookie_t windowCookie1 = xcb_create_window_checked (connection, screen->root_depth, window1, screen->root, 20, 200, WIDTH, HEIGHT, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, mask, values ); testCookie (windowCookie1, connection, "can't create window"); /* No mapping */ /* create transient window */ xcb_window_t window2 = xcb_generate_id (connection); xcb_void_cookie_t windowCookie2 = xcb_create_window_checked (connection, screen->root_depth, window2, screen->root, 20, 200, WIDTH, HEIGHT, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, mask, values ); testCookie (windowCookie2, connection, "can't create window"); xcb_change_property (connection, XCB_PROP_MODE_REPLACE, window2, XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, 32, 1, &window1); xcb_void_cookie_t mapCookie2 = xcb_map_window_checked (connection, window2); testCookie (mapCookie2, connection, "can't map window"); xcb_flush(connection); while (1) { xcb_generic_event_t *event = xcb_poll_for_event (connection); if (event) { free(event); } } return 0; }