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