Thursday, November 10, 2011

Create Button Using Pure XCB Code on Mac OS X

First create two images sing GIMP or any other image editor of your favorite, but it must be saved as C code.
The images are only 1 x 36 pixels each (yes, that's correct, only 1 pixel width). It will be repeated automatically.

Here's my example on the button, modify it according to your needs:


I write the above code my self, but pasted into PasteBin just to get the syntax highlighting style, it's easier to read the code this way.

The following is the output of the program:

XCB Button Test


NOTE:
Mac OS X Snow Leopard is using version of libxcb which is located at different location (as compared to Linux), so you must add -I/usr/X11/include -L/usr/X11/lib -lxcb -lxcb-atom to compile the code.

The complete compilation command should be:

gcc -I/usr/X11/include -L/usr/X11/lib -lxcb -lxcb-atom -o MacButton-Test MacButton.c

Further more, libxcb itself is a work on progress, if using the newer version (X11R7.6) you don't even need to include xcb_atom.h, and there's no WM_NAME, it's defined as XCB_ATOM_WM_NAME and XCB_ATOM_STRING. These items are actually just a typedef of uint32_t (integer 32 bit).

You can try it now!