Replace deprecated Automake INCLUDES variable with AM_CPPFLAGS
[free-sw/xcb/demo] / reply_formats.c
1 /*
2  * Copyright (C) 2001-2002 Bart Massey and Jamey Sharp.
3  * All Rights Reserved.  See the file COPYING in this directory
4  * for licensing information.
5  */
6
7 #include <stdio.h>
8 #include "reply_formats.h"
9
10 #define WINFMT "0x%08x"
11
12 int formatGetWindowAttributesReply(xcb_window_t wid, xcb_get_window_attributes_reply_t *reply)
13 {
14     if(!reply)
15     {
16         fprintf(stderr, "Failed to get attributes for window " WINFMT ".\n",
17             (unsigned int) wid);
18         return 0;
19     }
20
21     printf("Window " WINFMT " has attributes:\n"
22            "    backingStore       = %d\n"
23            "    visualID           = %#x\n"
24            "    class              = %d\n"
25            "    bitGravity         = %d\n"
26            "    winGravity         = %d\n"
27            "    backingBitPlanes   = 0x%08x\n"
28            "    backingPixel       = %d\n"
29            "    saveUnder          = %d\n"
30            "    mapInstalled       = %d\n"
31            "    mapState           = %d\n"
32            "    override           = %d\n"
33            "    colormap           = 0x%08x\n"
34            "    allEventMasks      = 0x%08x\n"
35            "    yourEventMask      = 0x%08x\n"
36            "    doNotPropagateMask = 0x%08x\n",
37         (unsigned int) wid,
38         reply->backing_store,
39         (unsigned int) reply->visual,
40         reply->_class,
41         reply->bit_gravity,
42         reply->win_gravity,
43         reply->backing_planes,
44         reply->backing_pixel,
45         reply->save_under,
46         reply->map_is_installed,
47         reply->map_state,
48         reply->override_redirect,
49         (unsigned int) reply->colormap,
50         (unsigned int) reply->all_event_masks,
51         (unsigned int) reply->your_event_mask,
52         reply->do_not_propagate_mask);
53
54     fflush(stdout);
55     return 1;
56 }
57
58 int formatGetGeometryReply(xcb_window_t wid, xcb_get_geometry_reply_t *reply)
59 {
60     if(!reply)
61     {
62         fprintf(stderr, "Failed to get geometry for window " WINFMT ".\n",
63             (unsigned int) wid);
64         return 0;
65     }
66
67     printf("Geometry for window " WINFMT ": %dx%d%+d%+d\n",
68         (unsigned int) wid,
69         reply->width,
70         reply->height,
71         reply->x,
72         reply->y);
73
74     fflush(stdout);
75     return 1;
76 }
77
78 int formatQueryTreeReply(xcb_window_t wid, xcb_query_tree_reply_t *reply)
79 {
80     int i;
81
82     if(!reply)
83     {
84         fprintf(stderr, "Failed to query tree for window " WINFMT ".\n",
85             (unsigned int) wid);
86         return 0;
87     }
88
89     printf("Window " WINFMT " has parent " WINFMT ", root " WINFMT ", and %d children%c\n",
90         (unsigned int) wid,
91         (unsigned int) reply->parent,
92         (unsigned int) reply->root,
93         (unsigned int) reply->children_len,
94         reply->children_len ? ':' : '.');
95
96     for(i = 0; i < reply->children_len; ++i)
97         printf("    window " WINFMT "\n",
98             (unsigned int) xcb_query_tree_children(reply)[i]);
99
100     fflush(stdout);
101     return 1;
102 }
103
104 static const char *labelError[] = {
105     "Success",
106     "BadRequest",
107     "BadValue",
108     "BadWindow",
109     "BadPixmap",
110     "BadAtom",
111     "BadCursor",
112     "BadFont",
113     "BadMatch",
114     "BadDrawable",
115     "BadAccess",
116     "BadAlloc",
117     "BadColor",
118     "BadGC",
119     "BadIDChoice",
120     "BadName",
121     "BadLength",
122     "BadImplementation",
123 };
124
125 static const char *labelRequest[] = {
126     "no request",
127     "CreateWindow",
128     "ChangeWindowAttributes",
129     "GetWindowAttributes",
130     "DestroyWindow",
131     "DestroySubwindows",
132     "ChangeSaveSet",
133     "ReparentWindow",
134     "MapWindow",
135     "MapSubwindows",
136     "UnmapWindow",
137     "UnmapSubwindows",
138     "ConfigureWindow",
139     "CirculateWindow",
140     "GetGeometry",
141     "QueryTree",
142     "InternAtom",
143     "GetAtomName",
144     "ChangeProperty",
145     "DeleteProperty",
146     "GetProperty",
147     "ListProperties",
148     "SetSelectionOwner",
149     "GetSelectionOwner",
150     "ConvertSelection",
151     "SendEvent",
152     "GrabPointer",
153     "UngrabPointer",
154     "GrabButton",
155     "UngrabButton",
156     "ChangeActivePointerGrab",
157     "GrabKeyboard",
158     "UngrabKeyboard",
159     "GrabKey",
160     "UngrabKey",
161     "AllowEvents",
162     "GrabServer",
163     "UngrabServer",
164     "QueryPointer",
165     "GetMotionEvents",
166     "TranslateCoords",
167     "WarpPointer",
168     "SetInputFocus",
169     "GetInputFocus",
170     "QueryKeymap",
171     "OpenFont",
172     "CloseFont",
173     "QueryFont",
174     "QueryTextExtents",
175     "ListFonts",
176     "ListFontsWithInfo",
177     "SetFontPath",
178     "GetFontPath",
179     "CreatePixmap",
180     "FreePixmap",
181     "CreateGC",
182     "ChangeGC",
183     "CopyGC",
184     "SetDashes",
185     "SetClipRectangles",
186     "FreeGC",
187     "ClearArea",
188     "CopyArea",
189     "CopyPlane",
190     "PolyPoint",
191     "PolyLine",
192     "PolySegment",
193     "PolyRectangle",
194     "PolyArc",
195     "FillPoly",
196     "PolyFillRectangle",
197     "PolyFillArc",
198     "PutImage",
199     "GetImage",
200     "PolyText",
201     "PolyText",
202     "ImageText",
203     "ImageText",
204     "CreateColormap",
205     "FreeColormap",
206     "CopyColormapAndFree",
207     "InstallColormap",
208     "UninstallColormap",
209     "ListInstalledColormaps",
210     "AllocColor",
211     "AllocNamedColor",
212     "AllocColorCells",
213     "AllocColorPlanes",
214     "FreeColors",
215     "StoreColors",
216     "StoreNamedColor",
217     "QueryColors",
218     "LookupColor",
219     "CreateCursor",
220     "CreateGlyphCursor",
221     "FreeCursor",
222     "RecolorCursor",
223     "QueryBestSize",
224     "QueryExtension",
225     "ListExtensions",
226     "ChangeKeyboardMapping",
227     "GetKeyboardMapping",
228     "ChangeKeyboardControl",
229     "GetKeyboardControl",
230     "Bell",
231     "ChangePointerControl",
232     "GetPointerControl",
233     "SetScreenSaver",
234     "GetScreenSaver",
235     "ChangeHosts",
236     "ListHosts",
237     "SetAccessControl",
238     "SetCloseDownMode",
239     "KillClient",
240     "RotateProperties",
241     "ForceScreenSaver",
242     "SetPointerMapping",
243     "GetPointerMapping",
244     "SetModifierMapping",
245     "GetModifierMapping",
246     "major 120",
247     "major 121",
248     "major 122",
249     "major 123",
250     "major 124",
251     "major 125",
252     "major 126",
253     "NoOperation",
254 };
255
256 static const char *labelEvent[] = {
257     "error",
258     "reply",
259     "KeyPress",
260     "KeyRelease",
261     "ButtonPress",
262     "ButtonRelease",
263     "MotionNotify",
264     "EnterNotify",
265     "LeaveNotify",
266     "FocusIn",
267     "FocusOut",
268     "KeymapNotify",
269     "Expose",
270     "GraphicsExpose",
271     "NoExpose",
272     "VisibilityNotify",
273     "CreateNotify",
274     "DestroyNotify",
275     "UnmapNotify",
276     "MapNotify",
277     "MapRequest",
278     "ReparentNotify",
279     "ConfigureNotify",
280     "ConfigureRequest",
281     "GravityNotify",
282     "ResizeRequest",
283     "CirculateNotify",
284     "CirculateRequest",
285     "PropertyNotify",
286     "SelectionClear",
287     "SelectionRequest",
288     "SelectionNotify",
289     "ColormapNotify",
290     "ClientMessage",
291     "MappingNotify",
292 };
293
294 static const char *labelSendEvent[] = {
295     "",
296     " (from SendEvent)",
297 };
298
299 int formatEvent(xcb_generic_event_t *e)
300 {
301     uint8_t sendEvent;
302     uint16_t seqnum;
303
304     if(!e)
305     {
306         fprintf(stderr, "Error reading event from server.\n");
307         return 0;
308     }
309
310     sendEvent = (e->response_type & 0x80) ? 1 : 0;
311     e->response_type &= ~0x80;
312     seqnum = *((uint16_t *) e + 1);
313
314     switch(e->response_type)
315     {
316     case 0:
317         printf("Error %s on seqnum %d (%s).\n",
318             labelError[*((uint8_t *) e + 1)],
319             seqnum,
320             labelRequest[*((uint8_t *) e + 10)]);
321         break;
322     default:
323         printf("Event %s following seqnum %d%s.\n",
324             labelEvent[e->response_type],
325             seqnum,
326             labelSendEvent[sendEvent]);
327         break;
328     case XCB_KEYMAP_NOTIFY:
329         printf("Event %s%s.\n",
330             labelEvent[e->response_type],
331             labelSendEvent[sendEvent]);
332         break;
333     }
334
335     fflush(stdout);
336     return 1;
337 }