[Xcb] XCB naming conventions

Bernardo Innocenti bernie at develer.com
Sat Sep 16 13:47:18 PDT 2006


Jeremy A. Kolb wrote:

> For functions:
> xcb_ followed by the extension and function name all in lowercase, words 
> separated by underscores.
> 
> Ex.
> xcb_window_new
> xcb_glx_create_context.


I know I'm late to suggest this, but wouldn't it be better if we prefixed
functions with "x_" instead of "xcb_"?

 XConnection connection = x_connect(NULL, NULL);
 XWindow window = x_window_new(connection);
 ...

The advantage is that it shifts focus from libary name (XCB) to technology
being used (X).  Someone reading the code will be less likely to say
"what's this xcb thing?".  Besides it's shorter and easier to type :-)


And as we're breaking source level compatibility, I'd like to ask for
another change: could we re-order the fields in XCB*Event structures so
that it could be dispatched in a more polymorphic fashion?  The current
scheme requires lots of pointer casting and is very unsafe.

An application event loop will usually want to delegate handling some
events such as XCBExposeEvent or XCBResizeRequestEvent to the underlying
object associated with the drawable or with the window:

   void Screen::exec()
   {
       while (XCBGenericEvent *e = XCBPollForEvent(connection, 0))
       {
           switch (e->response_type & ~0x80)
           {
                // Dispatch all window-related events to windows
                case XCBExposeEvent:
                case XCBResizeRequestEvent:
                ...
                {
                    MyFancyWindowClass *w;

                    if (w = find_Window(e->drawable))
                        w->handleEvent(e);
                    break;
                }
           }
       }
   }

By the way, has anybody written a C++ wrapper for XCB?  I felt the
need for some wrapper classes when I wrote some XCB code in C++.


More information about the Xcb mailing list