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