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.
7 #define TEST_GET_WINDOW_ATTRIBUTES
8 #define TEST_GET_GEOMETRY
9 #define TEST_QUERY_TREE
25 #include <X11/XCB/xcb.h>
26 #include <X11/XCB/xcb_aux.h>
27 #include "reply_formats.h"
33 void try_events(XCBConnection *c);
34 void wait_events(XCBConnection *c);
36 static XCBConnection *c;
37 static XCBWINDOW window;
39 int main(int argc, char **argv)
45 #ifdef TEST_GET_GEOMETRY
46 XCBGetGeometryCookie geom[3];
47 XCBGetGeometryRep *geomrep[3];
49 #ifdef TEST_QUERY_TREE
50 XCBQueryTreeCookie tree[3];
51 XCBQueryTreeRep *treerep[3];
53 #ifdef TEST_GET_WINDOW_ATTRIBUTES
54 XCBGetWindowAttributesCookie attr[1];
55 XCBGetWindowAttributesRep *attrrep[1];
58 XCBInternAtomCookie atom[2];
59 XCBInternAtomRep *atomrep[2];
62 pthread_t event_thread;
66 c = XCBConnect(0, &screen_num);
67 root = XCBAuxGetScreen(c, screen_num);
71 printf("main() thread ID: %ld\n", pthread_self());
73 /* don't do this cast. */
74 pthread_create(&event_thread, 0, (void *(*)(void *))wait_events, c);
78 window = XCBWINDOWNew(c);
80 window = 0; /* should be an invalid ID */
83 mask |= XCBCWBackPixel;
84 values[0] = root->white_pixel;
86 mask |= XCBCWBorderPixel;
87 values[1] = root->black_pixel;
89 mask |= XCBCWBackingStore;
92 mask |= XCBCWOverrideRedirect;
95 mask |= XCBCWEventMask;
96 values[4] = ButtonReleaseMask | ExposureMask | StructureNotifyMask
97 | EnterWindowMask | LeaveWindowMask;
99 mask |= XCBCWDontPropagate;
100 values[5] = ButtonPressMask;
102 XCBCreateWindow(c, /* depth */ 0,
104 /* x */ 20, /* y */ 200, /* width */ 150, /* height */ 150,
105 /* border_width */ 10, /* class */ InputOutput,
106 /* visual */ root->root_visual, mask, values);
108 atom[0] = XCBInternAtom(c, 0, sizeof("WM_PROTOCOLS")-1, "WM_PROTOCOLS");
109 atom[1] = XCBInternAtom(c, 0, sizeof("WM_DELETE_WINDOW")-1, "WM_DELETE_WINDOW");
110 atomrep[1] = XCBInternAtomReply(c, atom[1], 0);
111 atomrep[0] = XCBInternAtomReply(c, atom[0], 0);
113 XCBATOM XA_WM_NAME = { 39 };
114 XCBATOM XA_STRING = { 31 };
115 XCBChangeProperty(c, PropModeReplace, window, XA_WM_NAME, XA_STRING, 8, strlen(argv[0]), argv[0]);
117 if(atomrep[0] && atomrep[1])
119 XCBATOM WM_PROTOCOLS = atomrep[0]->atom;
120 XCBATOM WM_DELETE_WINDOW = atomrep[1]->atom;
121 XCBATOM XA_ATOM = { 4 };
122 XCBChangeProperty(c, PropModeReplace, window, WM_PROTOCOLS, XA_ATOM, 32, 1, &WM_DELETE_WINDOW);
129 XCBMapWindow(c, window);
132 /* Send off a collection of requests */
133 #ifdef TEST_GET_WINDOW_ATTRIBUTES
134 attr[0] = XCBGetWindowAttributes(c, window);
136 #ifdef TEST_GET_GEOMETRY
137 d.window = root->root;
138 geom[0] = XCBGetGeometry(c, d);
140 geom[1] = XCBGetGeometry(c, d);
142 #ifdef TEST_QUERY_TREE
143 # ifdef SUPERVERBOSE /* this produces a lot of output :) */
144 tree[0] = XCBQueryTree(c, root->root);
146 tree[1] = XCBQueryTree(c, window);
149 /* Start reading replies and possibly events */
150 #ifdef TEST_GET_GEOMETRY
151 geomrep[0] = XCBGetGeometryReply(c, geom[0], 0);
152 formatGetGeometryReply(root->root, geomrep[0]);
156 #ifdef TEST_QUERY_TREE
157 # ifdef SUPERVERBOSE /* this produces a lot of output :) */
158 treerep[0] = XCBQueryTreeReply(c, tree[0], 0);
159 formatQueryTreeReply(root->root, treerep[0]);
164 #ifdef TEST_GET_GEOMETRY
165 geomrep[1] = XCBGetGeometryReply(c, geom[1], 0);
166 formatGetGeometryReply(window, geomrep[1]);
172 /* Mix in some more requests */
173 #ifdef TEST_QUERY_TREE
174 treerep[1] = XCBQueryTreeReply(c, tree[1], 0);
175 formatQueryTreeReply(window, treerep[1]);
177 if(treerep[1] && treerep[1]->parent.xid && treerep[1]->parent.xid != root->root.xid)
179 tree[2] = XCBQueryTree(c, treerep[1]->parent);
181 # ifdef TEST_GET_GEOMETRY
182 d.window = treerep[1]->parent;
183 geom[2] = XCBGetGeometry(c, d);
184 geomrep[2] = XCBGetGeometryReply(c, geom[2], 0);
185 formatGetGeometryReply(treerep[1]->parent, geomrep[2]);
189 treerep[2] = XCBQueryTreeReply(c, tree[2], 0);
190 formatQueryTreeReply(treerep[1]->parent, treerep[2]);
199 /* Get the last reply of the first batch */
200 #if 1 /* if 0, leaves a reply in the reply queue */
201 #ifdef TEST_GET_WINDOW_ATTRIBUTES
202 attrrep[0] = XCBGetWindowAttributesReply(c, attr[0], 0);
203 formatGetWindowAttributesReply(window, attrrep[0]);
209 pthread_join(event_thread, 0);
218 int show_event(XCBGenericEvent *e)
224 if(e->response_type == XCBButtonRelease)
225 ret = 0; /* They clicked, therefore, we're done. */
230 void try_events(XCBConnection *c)
233 while((e = XCBPollForEvent(c, 0)) && show_event(e))
234 /* empty statement */ ;
237 void wait_events(XCBConnection *c)
242 printf("wait_events() thread ID: %ld\n", pthread_self());
245 while((e = XCBWaitForEvent(c)) && show_event(e))
246 /* empty statement */ ;