summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Danjou <julien@danjou.info>2009-04-02 12:11:01 +0200
committerArnaud Fontaine <arnau@debian.org>2010-11-14 19:51:10 +0900
commit94a25d209e1cdfcdaf8e4bfd2cdb1bcb82042d84 (patch)
tree54c6e86d246725173a63ba461348d68a3fff2841
parent55ad587c67fe7890c71ef151ad15868d9929f2e1 (diff)
event: add functions to convert event/errors to labels
Signed-off-by: Julien Danjou <julien@danjou.info>
-rw-r--r--event/event.c228
-rw-r--r--event/xcb_event.h23
2 files changed, 251 insertions, 0 deletions
diff --git a/event/event.c b/event/event.c
index 97af53b..3d8fd7c 100644
--- a/event/event.c
+++ b/event/event.c
@@ -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)
@@ -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;
+}
diff --git a/event/xcb_event.h b/event/xcb_event.h
index c2d1cd6..4324931 100644
--- a/event/xcb_event.h
+++ b/event/xcb_event.h
@@ -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