i3
src/debug.c
Go to the documentation of this file.
00001 /*
00002  * vim:ts=4:sw=4:expandtab
00003  *
00004  * i3 - an improved dynamic tiling window manager
00005  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
00006  *
00007  * debug.c: Debugging functions, especially FormatEvent, which prints unhandled
00008  *          events.  This code is from xcb-util.
00009  *
00010  */
00011 #include <stdio.h>
00012 #include <xcb/xcb.h>
00013 
00014 #include "log.h"
00015 
00016 static const char *labelError[] = {
00017     "Success",
00018     "BadRequest",
00019     "BadValue",
00020     "BadWindow",
00021     "BadPixmap",
00022     "BadAtom",
00023     "BadCursor",
00024     "BadFont",
00025     "BadMatch",
00026     "BadDrawable",
00027     "BadAccess",
00028     "BadAlloc",
00029     "BadColor",
00030     "BadGC",
00031     "BadIDChoice",
00032     "BadName",
00033     "BadLength",
00034     "BadImplementation",
00035 };
00036 
00037 static const char *labelRequest[] = {
00038     "no request",
00039     "CreateWindow",
00040     "ChangeWindowAttributes",
00041     "GetWindowAttributes",
00042     "DestroyWindow",
00043     "DestroySubwindows",
00044     "ChangeSaveSet",
00045     "ReparentWindow",
00046     "MapWindow",
00047     "MapSubwindows",
00048     "UnmapWindow",
00049     "UnmapSubwindows",
00050     "ConfigureWindow",
00051     "CirculateWindow",
00052     "GetGeometry",
00053     "QueryTree",
00054     "InternAtom",
00055     "GetAtomName",
00056     "ChangeProperty",
00057     "DeleteProperty",
00058     "GetProperty",
00059     "ListProperties",
00060     "SetSelectionOwner",
00061     "GetSelectionOwner",
00062     "ConvertSelection",
00063     "SendEvent",
00064     "GrabPointer",
00065     "UngrabPointer",
00066     "GrabButton",
00067     "UngrabButton",
00068     "ChangeActivePointerGrab",
00069     "GrabKeyboard",
00070     "UngrabKeyboard",
00071     "GrabKey",
00072     "UngrabKey",
00073     "AllowEvents",
00074     "GrabServer",
00075     "UngrabServer",
00076     "QueryPointer",
00077     "GetMotionEvents",
00078     "TranslateCoords",
00079     "WarpPointer",
00080     "SetInputFocus",
00081     "GetInputFocus",
00082     "QueryKeymap",
00083     "OpenFont",
00084     "CloseFont",
00085     "QueryFont",
00086     "QueryTextExtents",
00087     "ListFonts",
00088     "ListFontsWithInfo",
00089     "SetFontPath",
00090     "GetFontPath",
00091     "CreatePixmap",
00092     "FreePixmap",
00093     "CreateGC",
00094     "ChangeGC",
00095     "CopyGC",
00096     "SetDashes",
00097     "SetClipRectangles",
00098     "FreeGC",
00099     "ClearArea",
00100     "CopyArea",
00101     "CopyPlane",
00102     "PolyPoint",
00103     "PolyLine",
00104     "PolySegment",
00105     "PolyRectangle",
00106     "PolyArc",
00107     "FillPoly",
00108     "PolyFillRectangle",
00109     "PolyFillArc",
00110     "PutImage",
00111     "GetImage",
00112     "PolyText",
00113     "PolyText",
00114     "ImageText",
00115     "ImageText",
00116     "CreateColormap",
00117     "FreeColormap",
00118     "CopyColormapAndFree",
00119     "InstallColormap",
00120     "UninstallColormap",
00121     "ListInstalledColormaps",
00122     "AllocColor",
00123     "AllocNamedColor",
00124     "AllocColorCells",
00125     "AllocColorPlanes",
00126     "FreeColors",
00127     "StoreColors",
00128     "StoreNamedColor",
00129     "QueryColors",
00130     "LookupColor",
00131     "CreateCursor",
00132     "CreateGlyphCursor",
00133     "FreeCursor",
00134     "RecolorCursor",
00135     "QueryBestSize",
00136     "QueryExtension",
00137     "ListExtensions",
00138     "ChangeKeyboardMapping",
00139     "GetKeyboardMapping",
00140     "ChangeKeyboardControl",
00141     "GetKeyboardControl",
00142     "Bell",
00143     "ChangePointerControl",
00144     "GetPointerControl",
00145     "SetScreenSaver",
00146     "GetScreenSaver",
00147     "ChangeHosts",
00148     "ListHosts",
00149     "SetAccessControl",
00150     "SetCloseDownMode",
00151     "KillClient",
00152     "RotateProperties",
00153     "ForceScreenSaver",
00154     "SetPointerMapping",
00155     "GetPointerMapping",
00156     "SetModifierMapping",
00157     "GetModifierMapping",
00158     "major 120",
00159     "major 121",
00160     "major 122",
00161     "major 123",
00162     "major 124",
00163     "major 125",
00164     "major 126",
00165     "NoOperation",
00166 };
00167 
00168 static const char *labelEvent[] = {
00169     "error",
00170     "reply",
00171     "KeyPress",
00172     "KeyRelease",
00173     "ButtonPress",
00174     "ButtonRelease",
00175     "MotionNotify",
00176     "EnterNotify",
00177     "LeaveNotify",
00178     "FocusIn",
00179     "FocusOut",
00180     "KeymapNotify",
00181     "Expose",
00182     "GraphicsExpose",
00183     "NoExpose",
00184     "VisibilityNotify",
00185     "CreateNotify",
00186     "DestroyNotify",
00187     "UnmapNotify",
00188     "MapNotify",
00189     "MapRequest",
00190     "ReparentNotify",
00191     "ConfigureNotify",
00192     "ConfigureRequest",
00193     "GravityNotify",
00194     "ResizeRequest",
00195     "CirculateNotify",
00196     "CirculateRequest",
00197     "PropertyNotify",
00198     "SelectionClear",
00199     "SelectionRequest",
00200     "SelectionNotify",
00201     "ColormapNotify",
00202     "ClientMessage",
00203     "MappingNotify",
00204 };
00205 
00206 static const char *labelSendEvent[] = {
00207     "",
00208     " (from SendEvent)",
00209 };
00210 
00211 int format_event(xcb_generic_event_t *e) {
00212     uint8_t sendEvent;
00213     uint16_t seqnum;
00214 
00215     sendEvent = (e->response_type & 0x80) ? 1 : 0;
00216     e->response_type &= ~0x80;
00217     seqnum = *((uint16_t *) e + 1);
00218 
00219     switch(e->response_type) {
00220     case 0:
00221         DLOG("Error %s on seqnum %d (%s).\n",
00222             labelError[*((uint8_t *) e + 1)],
00223             seqnum,
00224             labelRequest[*((uint8_t *) e + 10)]);
00225         break;
00226     default:
00227         if (e->response_type > sizeof(labelEvent) / sizeof(char*))
00228                 break;
00229         DLOG("Event %s following seqnum %d%s.\n",
00230             labelEvent[e->response_type],
00231             seqnum,
00232             labelSendEvent[sendEvent]);
00233         break;
00234     case XCB_KEYMAP_NOTIFY:
00235         DLOG("Event %s%s.\n",
00236             labelEvent[e->response_type],
00237             labelSendEvent[sendEvent]);
00238         break;
00239     }
00240 
00241     fflush(stdout);
00242     return 1;
00243 }