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