Skip to content

Commit

Permalink
event: add functions to convert event/errors to labels
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Danjou <[email protected]>
  • Loading branch information
jd committed Apr 2, 2009
1 parent 2af5698 commit 8e87437
Show file tree
Hide file tree
Showing 2 changed files with 251 additions and 0 deletions.
228 changes: 228 additions & 0 deletions event/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <stdlib.h>

#include "xcb_event.h"
#include "../xcb-util-common.h"

void
xcb_event_handlers_init(xcb_connection_t *c, xcb_event_handlers_t *evenths)
Expand Down Expand Up @@ -115,3 +116,230 @@ xcb_event_set_error_handler(xcb_event_handlers_t *evenths, int error, xcb_generi
{
set_handler((xcb_generic_event_handler_t) handler, data, get_error_handler(evenths, error));
}

static const char *labelError[] =
{
"Success",
"BadRequest",
"BadValue",
"BadWindow",
"BadPixmap",
"BadAtom",
"BadCursor",
"BadFont",
"BadMatch",
"BadDrawable",
"BadAccess",
"BadAlloc",
"BadColor",
"BadGC",
"BadIDChoice",
"BadName",
"BadLength",
"BadImplementation",
};

static const char *labelRequest[] =
{
"no request",
"CreateWindow",
"ChangeWindowAttributes",
"GetWindowAttributes",
"DestroyWindow",
"DestroySubwindows",
"ChangeSaveSet",
"ReparentWindow",
"MapWindow",
"MapSubwindows",
"UnmapWindow",
"UnmapSubwindows",
"ConfigureWindow",
"CirculateWindow",
"GetGeometry",
"QueryTree",
"InternAtom",
"GetAtomName",
"ChangeProperty",
"DeleteProperty",
"GetProperty",
"ListProperties",
"SetSelectionOwner",
"GetSelectionOwner",
"ConvertSelection",
"SendEvent",
"GrabPointer",
"UngrabPointer",
"GrabButton",
"UngrabButton",
"ChangeActivePointerGrab",
"GrabKeyboard",
"UngrabKeyboard",
"GrabKey",
"UngrabKey",
"AllowEvents",
"GrabServer",
"UngrabServer",
"QueryPointer",
"GetMotionEvents",
"TranslateCoords",
"WarpPointer",
"SetInputFocus",
"GetInputFocus",
"QueryKeymap",
"OpenFont",
"CloseFont",
"QueryFont",
"QueryTextExtents",
"ListFonts",
"ListFontsWithInfo",
"SetFontPath",
"GetFontPath",
"CreatePixmap",
"FreePixmap",
"CreateGC",
"ChangeGC",
"CopyGC",
"SetDashes",
"SetClipRectangles",
"FreeGC",
"ClearArea",
"CopyArea",
"CopyPlane",
"PolyPoint",
"PolyLine",
"PolySegment",
"PolyRectangle",
"PolyArc",
"FillPoly",
"PolyFillRectangle",
"PolyFillArc",
"PutImage",
"GetImage",
"PolyText",
"PolyText",
"ImageText",
"ImageText",
"CreateColormap",
"FreeColormap",
"CopyColormapAndFree",
"InstallColormap",
"UninstallColormap",
"ListInstalledColormaps",
"AllocColor",
"AllocNamedColor",
"AllocColorCells",
"AllocColorPlanes",
"FreeColors",
"StoreColors",
"StoreNamedColor",
"QueryColors",
"LookupColor",
"CreateCursor",
"CreateGlyphCursor",
"FreeCursor",
"RecolorCursor",
"QueryBestSize",
"QueryExtension",
"ListExtensions",
"ChangeKeyboardMapping",
"GetKeyboardMapping",
"ChangeKeyboardControl",
"GetKeyboardControl",
"Bell",
"ChangePointerControl",
"GetPointerControl",
"SetScreenSaver",
"GetScreenSaver",
"ChangeHosts",
"ListHosts",
"SetAccessControl",
"SetCloseDownMode",
"KillClient",
"RotateProperties",
"ForceScreenSaver",
"SetPointerMapping",
"GetPointerMapping",
"SetModifierMapping",
"GetModifierMapping",
"major 120",
"major 121",
"major 122",
"major 123",
"major 124",
"major 125",
"major 126",
"NoOperation",
};

static const char *labelEvent[] =
{
"error",
"reply",
"KeyPress",
"KeyRelease",
"ButtonPress",
"ButtonRelease",
"MotionNotify",
"EnterNotify",
"LeaveNotify",
"FocusIn",
"FocusOut",
"KeymapNotify",
"Expose",
"GraphicsExpose",
"NoExpose",
"VisibilityNotify",
"CreateNotify",
"DestroyNotify",
"UnmapNotify",
"MapNotify",
"MapRequest",
"ReparentNotify",
"ConfigureNotify",
"ConfigureRequest",
"GravityNotify",
"ResizeRequest",
"CirculateNotify",
"CirculateRequest",
"PropertyNotify",
"SelectionClear",
"SelectionRequest",
"SelectionNotify",
"ColormapNotify",
"ClientMessage",
"MappingNotify",
};

const char *
xcb_event_get_label(const xcb_generic_event_t *e)
{
uint32_t type = XCB_EVENT_RESPONSE_TYPE(e);
if(type < countof(labelEvent))
return labelEvent[type];
return NULL;
}

const char *
xcb_event_get_error_label(const xcb_generic_event_t *e)
{
/* Check that it's an error */
if(e->response_type == 0)
{
uint32_t type = XCB_EVENT_RESPONSE_TYPE(e) + 1;
if(type < countof(labelError))
return labelError[type];
}
return NULL;
}

const char *
xcb_event_get_request_label(const xcb_generic_event_t *e)
{
if(e->response_type == 0)
{
uint32_t type = XCB_EVENT_RESPONSE_TYPE(e) + 10;
if(type < countof(labelRequest))
return labelRequest[type];
}
return NULL;
}
23 changes: 23 additions & 0 deletions event/xcb_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,29 @@ XCB_EVENT_MAKE_EVENT_HANDLER(colormap_notify, COLORMAP_NOTIFY)
XCB_EVENT_MAKE_EVENT_HANDLER(client_message, CLIENT_MESSAGE)
XCB_EVENT_MAKE_EVENT_HANDLER(mapping_notify, MAPPING_NOTIFY)

/**
* @brief Convert an event reponse type to a label.
* @param e The event.
* @return A string with the event name, or NULL if unknown.
*/
const char * xcb_event_get_label(const xcb_generic_event_t *e);

/**
* @brief Convert an event error type to a label.
* @param e The event.
* @return A string with the event name, or NULL if unknown or if the event is
* not an error.
*/
const char * xcb_event_get_error_label(const xcb_generic_event_t *e);

/**
* @brief Convert an event request type to a label.
* @param e The event.
* @return A string with the event name, or NULL if unknown or if the event is
* not an error.
*/
const char * xcb_event_get_request_label(const xcb_generic_event_t *e);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 8e87437

Please sign in to comment.