modernc.org/99c@v1.0.1-0.20181109153923-a9e8197063d9/examples/xcb/helloworld.c (about)

     1  // 99c helloworld.c -lxcb && ./a.out
     2  
     3  // +build ignore
     4  
     5  // src: https://www.x.org/releases/current/doc/libxcb/tutorial/index.html#helloworld
     6  
     7  #include <stdio.h>
     8  #include <unistd.h>		/* pause() */
     9  
    10  #include <xcb/xcb.h>
    11  
    12  int main()
    13  {
    14  	xcb_connection_t *c;
    15  	xcb_screen_t *screen;
    16  	xcb_window_t win;
    17  
    18  	/* Open the connection to the X server */
    19  	c = xcb_connect(NULL, NULL);
    20  
    21  	/* Get the first screen */
    22  	screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
    23  
    24  	/* Ask for our window's Id */
    25  	win = xcb_generate_id(c);
    26  
    27  	/* Create the window */
    28  	xcb_create_window(c,	/* Connection          */
    29  			  XCB_COPY_FROM_PARENT,	/* depth (same as root) */
    30  			  win,	/* window Id           */
    31  			  screen->root,	/* parent window       */
    32  			  0, 0,	/* x, y                */
    33  			  150, 150,	/* width, height       */
    34  			  10,	/* border_width        */
    35  			  XCB_WINDOW_CLASS_INPUT_OUTPUT,	/* class               */
    36  			  screen->root_visual,	/* visual              */
    37  			  0, NULL);	/* masks, not used yet */
    38  
    39  	/* Map the window on the screen */
    40  	xcb_map_window(c, win);
    41  
    42  	/* Make sure commands are sent before we pause, so window is shown */
    43  	xcb_flush(c);
    44  
    45  	printf("Close the demo window and/or press ctrl-c while the terminal is focused to exit.\n");
    46  	int i = pause();	/* hold client until Ctrl-C */
    47  	printf("pause() returned %i\n", i);
    48  
    49  	return 0;
    50  }