Need help with creating a GUI window on Linux using libxcb.so XCB API
- Posted by system_X Jul 02, 2013
- 1624 views
I'm trying to use the XCB API to create a Window on Peppermint Linux(based on Ubuntu 13.04) and not really sure how to do it. Many of us could learn quite a bit from seeing this program wrote in Euphoria if someone wants to show us how it's done?
libxcb.so is a C library for accessing the XCB API. To open up libxcb.so we must use
include std/dll.e atom libxcb libxcb = open_dll("libxcb.so") -- Must have a 32bit .so installed if on a 64bit machine. if libxcb = 0 then -- libxcb will be 0 if the library cannot be opened. puts(1, "Could not open libxcb.so!\n) end if
Here is a small C program to create a window of size 150x150 pixels, positioned at the top-left corner of the screen. Source code located at XCB Tutorial :
#include <unistd.h> /* pause() */ #include <xcb/xcb.h> 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; }