]> git.sur5r.net Git - i3/i3/blob - src/debug.c
Merge pull request #2190 from jolange/userguide
[i3/i3] / src / debug.c
1 #undef I3__FILE__
2 #define I3__FILE__ "debug.c"
3 /*
4  * vim:ts=4:sw=4:expandtab
5  *
6  * i3 - an improved dynamic tiling window manager
7  * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
8  *
9  * debug.c: Debugging functions, especially FormatEvent, which prints unhandled
10  *          events.  This code is from xcb-util.
11  *
12  */
13 #include <stdio.h>
14 #include <xcb/xcb.h>
15
16 #include "log.h"
17
18 static const char *labelError[] = {
19     "Success",
20     "BadRequest",
21     "BadValue",
22     "BadWindow",
23     "BadPixmap",
24     "BadAtom",
25     "BadCursor",
26     "BadFont",
27     "BadMatch",
28     "BadDrawable",
29     "BadAccess",
30     "BadAlloc",
31     "BadColor",
32     "BadGC",
33     "BadIDChoice",
34     "BadName",
35     "BadLength",
36     "BadImplementation",
37 };
38
39 static const char *labelRequest[] = {
40     "no request",
41     "CreateWindow",
42     "ChangeWindowAttributes",
43     "GetWindowAttributes",
44     "DestroyWindow",
45     "DestroySubwindows",
46     "ChangeSaveSet",
47     "ReparentWindow",
48     "MapWindow",
49     "MapSubwindows",
50     "UnmapWindow",
51     "UnmapSubwindows",
52     "ConfigureWindow",
53     "CirculateWindow",
54     "GetGeometry",
55     "QueryTree",
56     "InternAtom",
57     "GetAtomName",
58     "ChangeProperty",
59     "DeleteProperty",
60     "GetProperty",
61     "ListProperties",
62     "SetSelectionOwner",
63     "GetSelectionOwner",
64     "ConvertSelection",
65     "SendEvent",
66     "GrabPointer",
67     "UngrabPointer",
68     "GrabButton",
69     "UngrabButton",
70     "ChangeActivePointerGrab",
71     "GrabKeyboard",
72     "UngrabKeyboard",
73     "GrabKey",
74     "UngrabKey",
75     "AllowEvents",
76     "GrabServer",
77     "UngrabServer",
78     "QueryPointer",
79     "GetMotionEvents",
80     "TranslateCoords",
81     "WarpPointer",
82     "SetInputFocus",
83     "GetInputFocus",
84     "QueryKeymap",
85     "OpenFont",
86     "CloseFont",
87     "QueryFont",
88     "QueryTextExtents",
89     "ListFonts",
90     "ListFontsWithInfo",
91     "SetFontPath",
92     "GetFontPath",
93     "CreatePixmap",
94     "FreePixmap",
95     "CreateGC",
96     "ChangeGC",
97     "CopyGC",
98     "SetDashes",
99     "SetClipRectangles",
100     "FreeGC",
101     "ClearArea",
102     "CopyArea",
103     "CopyPlane",
104     "PolyPoint",
105     "PolyLine",
106     "PolySegment",
107     "PolyRectangle",
108     "PolyArc",
109     "FillPoly",
110     "PolyFillRectangle",
111     "PolyFillArc",
112     "PutImage",
113     "GetImage",
114     "PolyText",
115     "PolyText",
116     "ImageText",
117     "ImageText",
118     "CreateColormap",
119     "FreeColormap",
120     "CopyColormapAndFree",
121     "InstallColormap",
122     "UninstallColormap",
123     "ListInstalledColormaps",
124     "AllocColor",
125     "AllocNamedColor",
126     "AllocColorCells",
127     "AllocColorPlanes",
128     "FreeColors",
129     "StoreColors",
130     "StoreNamedColor",
131     "QueryColors",
132     "LookupColor",
133     "CreateCursor",
134     "CreateGlyphCursor",
135     "FreeCursor",
136     "RecolorCursor",
137     "QueryBestSize",
138     "QueryExtension",
139     "ListExtensions",
140     "ChangeKeyboardMapping",
141     "GetKeyboardMapping",
142     "ChangeKeyboardControl",
143     "GetKeyboardControl",
144     "Bell",
145     "ChangePointerControl",
146     "GetPointerControl",
147     "SetScreenSaver",
148     "GetScreenSaver",
149     "ChangeHosts",
150     "ListHosts",
151     "SetAccessControl",
152     "SetCloseDownMode",
153     "KillClient",
154     "RotateProperties",
155     "ForceScreenSaver",
156     "SetPointerMapping",
157     "GetPointerMapping",
158     "SetModifierMapping",
159     "GetModifierMapping",
160     "major 120",
161     "major 121",
162     "major 122",
163     "major 123",
164     "major 124",
165     "major 125",
166     "major 126",
167     "NoOperation",
168 };
169
170 static const char *labelEvent[] = {
171     "error",
172     "reply",
173     "KeyPress",
174     "KeyRelease",
175     "ButtonPress",
176     "ButtonRelease",
177     "MotionNotify",
178     "EnterNotify",
179     "LeaveNotify",
180     "FocusIn",
181     "FocusOut",
182     "KeymapNotify",
183     "Expose",
184     "GraphicsExpose",
185     "NoExpose",
186     "VisibilityNotify",
187     "CreateNotify",
188     "DestroyNotify",
189     "UnmapNotify",
190     "MapNotify",
191     "MapRequest",
192     "ReparentNotify",
193     "ConfigureNotify",
194     "ConfigureRequest",
195     "GravityNotify",
196     "ResizeRequest",
197     "CirculateNotify",
198     "CirculateRequest",
199     "PropertyNotify",
200     "SelectionClear",
201     "SelectionRequest",
202     "SelectionNotify",
203     "ColormapNotify",
204     "ClientMessage",
205     "MappingNotify",
206 };
207
208 static const char *labelSendEvent[] = {
209     "",
210     " (from SendEvent)",
211 };
212
213 int format_event(xcb_generic_event_t *e) {
214     uint8_t sendEvent;
215     uint16_t seqnum;
216
217     sendEvent = (e->response_type & 0x80) ? 1 : 0;
218     e->response_type &= ~0x80;
219     seqnum = *((uint16_t *)e + 1);
220
221     switch (e->response_type) {
222         case 0:
223             DLOG("Error %s on seqnum %d (%s).\n",
224                  labelError[*((uint8_t *)e + 1)],
225                  seqnum,
226                  labelRequest[*((uint8_t *)e + 10)]);
227             break;
228         default:
229             if (e->response_type > sizeof(labelEvent) / sizeof(char *))
230                 break;
231             DLOG("Event %s following seqnum %d%s.\n",
232                  labelEvent[e->response_type],
233                  seqnum,
234                  labelSendEvent[sendEvent]);
235             break;
236         case XCB_KEYMAP_NOTIFY:
237             DLOG("Event %s%s.\n",
238                  labelEvent[e->response_type],
239                  labelSendEvent[sendEvent]);
240             break;
241     }
242
243     fflush(stdout);
244     return 1;
245 }