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