1 /*
2
3 Copyright 1986, 1998 The Open Group
4
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24
25 */
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30 #include "Xlibint.h"
31
32 typedef struct _WAttrsState {
33 uint64_t attr_seq;
34 uint64_t geom_seq;
35 XWindowAttributes *attr;
36 } _XWAttrsState;
37
38 static Bool
_XWAttrsHandler(register Display * dpy,register xReply * rep,char * buf,int len,XPointer data)39 _XWAttrsHandler(
40 register Display *dpy,
41 register xReply *rep,
42 char *buf,
43 int len,
44 XPointer data)
45 {
46 register _XWAttrsState *state;
47 xGetWindowAttributesReply replbuf;
48 register xGetWindowAttributesReply *repl;
49 register XWindowAttributes *attr;
50 uint64_t last_request_read = X_DPY_GET_LAST_REQUEST_READ(dpy);
51
52 state = (_XWAttrsState *)data;
53 if (last_request_read != state->attr_seq) {
54 if (last_request_read == state->geom_seq &&
55 !state->attr &&
56 rep->generic.type == X_Error &&
57 rep->error.errorCode == BadDrawable)
58 return True;
59 return False;
60 }
61 if (rep->generic.type == X_Error) {
62 state->attr = (XWindowAttributes *)NULL;
63 return False;
64 }
65 repl = (xGetWindowAttributesReply *)
66 _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len,
67 (SIZEOF(xGetWindowAttributesReply) - SIZEOF(xReply)) >> 2,
68 True);
69 attr = state->attr;
70 attr->class = repl->class;
71 attr->bit_gravity = repl->bitGravity;
72 attr->win_gravity = repl->winGravity;
73 attr->backing_store = repl->backingStore;
74 attr->backing_planes = repl->backingBitPlanes;
75 attr->backing_pixel = repl->backingPixel;
76 attr->save_under = repl->saveUnder;
77 attr->colormap = repl->colormap;
78 attr->map_installed = repl->mapInstalled;
79 attr->map_state = repl->mapState;
80 attr->all_event_masks = repl->allEventMasks;
81 attr->your_event_mask = repl->yourEventMask;
82 attr->do_not_propagate_mask = repl->doNotPropagateMask;
83 attr->override_redirect = repl->override;
84 attr->visual = _XVIDtoVisual (dpy, repl->visualID);
85 return True;
86 }
87
88 Status
_XGetWindowAttributes(Display * dpy,Window w,XWindowAttributes * attr)89 _XGetWindowAttributes(
90 Display *dpy,
91 Window w,
92 XWindowAttributes *attr)
93 {
94 xGetGeometryReply rep;
95 register xResourceReq *req;
96 register int i;
97 register Screen *sp;
98 _XAsyncHandler async;
99 _XWAttrsState async_state;
100
101 GetResReq(GetWindowAttributes, w, req);
102
103 async_state.attr_seq = X_DPY_GET_REQUEST(dpy);
104 async_state.geom_seq = 0;
105 async_state.attr = attr;
106 async.next = dpy->async_handlers;
107 async.handler = _XWAttrsHandler;
108 async.data = (XPointer)&async_state;
109 dpy->async_handlers = &async;
110
111 GetResReq(GetGeometry, w, req);
112
113 async_state.geom_seq = X_DPY_GET_REQUEST(dpy);
114
115 if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) {
116 DeqAsyncHandler(dpy, &async);
117 return (0);
118 }
119 DeqAsyncHandler(dpy, &async);
120 if (!async_state.attr) {
121 return (0);
122 }
123 attr->x = cvtINT16toInt (rep.x);
124 attr->y = cvtINT16toInt (rep.y);
125 attr->width = rep.width;
126 attr->height = rep.height;
127 attr->border_width = rep.borderWidth;
128 attr->depth = rep.depth;
129 attr->root = rep.root;
130 /* find correct screen so that applications find it easier.... */
131 for (i = 0; i < dpy->nscreens; i++) {
132 sp = &dpy->screens[i];
133 if (sp->root == attr->root) {
134 attr->screen = sp;
135 break;
136 }
137 }
138 return(1);
139 }
140
141 Status
XGetWindowAttributes(Display * dpy,Window w,XWindowAttributes * attr)142 XGetWindowAttributes(
143 Display *dpy,
144 Window w,
145 XWindowAttributes *attr)
146 {
147 Status ret;
148
149 LockDisplay(dpy);
150 ret = _XGetWindowAttributes(dpy, w, attr);
151 UnlockDisplay(dpy);
152 SyncHandle();
153
154 return ret;
155 }
156
157