3 Copyright 1996, 1998 The Open Group
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
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
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.
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.
31 #include <X11/Xwindows.h>
34 #include <X11/Xlibint.h>
35 #include <X11/extensions/Xag.h>
36 #include <X11/extensions/agproto.h>
37 #include <X11/extensions/Xext.h>
38 #include <X11/extensions/extutil.h>
44 Bool app_group_leader;
48 Colormap default_colormap;
49 unsigned long black_pixel;
50 unsigned long white_pixel;
53 static XExtensionInfo _xag_info_data;
54 static XExtensionInfo *xag_info = &_xag_info_data;
55 static const char *xag_extension_name = XAGNAME;
57 #define XagCheckExtension(dpy,i,val) \
58 XextCheckExtension (dpy, i, xag_extension_name, val)
60 /*****************************************************************************
62 * private utility routines *
64 *****************************************************************************/
66 static int close_display(Display *dpy, XExtCodes *codes);
67 static /* const */ XExtensionHooks xag_extension_hooks = {
72 NULL, /* create_font */
74 close_display, /* close_display */
75 NULL, /* wire_to_event */
76 NULL, /* event_to_wire */
78 NULL, /* error_string */
81 static XEXT_GENERATE_FIND_DISPLAY (find_display, xag_info,
86 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xag_info)
89 /*****************************************************************************
91 * public Xag Extension routines *
93 *****************************************************************************/
98 int *major_version_return,
99 int *minor_version_return)
101 XExtDisplayInfo *info = find_display (dpy);
102 xXagQueryVersionReply rep;
103 xXagQueryVersionReq *req;
105 XagCheckExtension (dpy, info, False);
108 GetReq(XagQueryVersion, req);
109 req->reqType = info->codes->major_opcode;
110 req->xagReqType = X_XagQueryVersion;
111 req->client_major_version = XAG_MAJOR_VERSION;
112 req->client_minor_version = XAG_MINOR_VERSION;
113 if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
118 *major_version_return = rep.server_major_version;
119 *minor_version_return = rep.server_minor_version;
126 StuffToWire (Display *dpy, struct xagstuff *stuff, xXagCreateReq *req)
128 unsigned long values[8];
129 unsigned long* value = values;
130 unsigned int nvalues;
132 /* the order these are in is important */
133 if (stuff->attrib_mask & XagSingleScreenMask)
134 *value++ = stuff->single_screen;
136 if (stuff->attrib_mask & XagDefaultRootMask)
137 *value++ = stuff->default_root;
139 if (stuff->attrib_mask & XagRootVisualMask)
140 *value++ = stuff->root_visual;
142 if (stuff->attrib_mask & XagDefaultColormapMask)
143 *value++ = stuff->default_colormap;
145 if (stuff->attrib_mask & XagBlackPixelMask)
146 *value++ = stuff->black_pixel;
148 if (stuff->attrib_mask & XagWhitePixelMask)
149 *value++ = stuff->white_pixel;
151 if (stuff->attrib_mask & XagAppGroupLeaderMask)
152 *value++ = stuff->app_group_leader;
154 req->length += (nvalues = value - values);
157 Data32 (dpy, (long*) values, (long) nvalues);
161 XagCreateEmbeddedApplicationGroup(
163 VisualID root_visual,
164 Colormap default_colormap,
165 unsigned long black_pixel,
166 unsigned long white_pixel,
167 XAppGroup* app_group_return)
169 XExtDisplayInfo *info = find_display (dpy);
171 struct xagstuff stuff;
173 XagCheckExtension (dpy, info, False);
176 stuff.app_group_leader = True;
177 stuff.single_screen = True;
178 stuff.default_root = RootWindow (dpy, DefaultScreen(dpy));
179 stuff.root_visual = root_visual;
180 stuff.default_colormap = default_colormap;
182 XagAppGroupLeaderMask | XagSingleScreenMask | XagDefaultRootMask |
183 XagRootVisualMask | XagDefaultColormapMask;
184 if (default_colormap != None) {
185 stuff.black_pixel = black_pixel;
186 stuff.white_pixel = white_pixel;
187 stuff.attrib_mask |= XagBlackPixelMask | XagWhitePixelMask;
189 /* might do some validation here */
190 GetReq(XagCreate, req);
191 req->reqType = info->codes->major_opcode;
192 req->xagReqType = X_XagCreate;
193 *app_group_return = req->app_group = XAllocID(dpy);
194 req->attrib_mask = stuff.attrib_mask;
195 StuffToWire (dpy, &stuff, req);
202 XagCreateNonembeddedApplicationGroup(
204 XAppGroup* app_group_return)
206 XExtDisplayInfo *info = find_display (dpy);
208 struct xagstuff stuff;
210 XagCheckExtension (dpy, info, False);
213 stuff.app_group_leader = False;
214 stuff.single_screen = False;
215 stuff.attrib_mask = XagAppGroupLeaderMask | XagSingleScreenMask;
216 /* might do some validation here */
217 GetReq(XagCreate, req);
218 req->reqType = info->codes->major_opcode;
219 req->xagReqType = X_XagCreate;
220 *app_group_return = req->app_group = XAllocID(dpy);
221 req->attrib_mask = stuff.attrib_mask;
222 StuffToWire (dpy, &stuff, req);
228 Bool XagDestroyApplicationGroup(Display* dpy, XAppGroup app_group)
230 XExtDisplayInfo *info = find_display (dpy);
233 XagCheckExtension (dpy, info, False);
236 GetReq(XagDestroy, req);
237 req->reqType = info->codes->major_opcode;
238 req->xagReqType = X_XagDestroy;
239 req->app_group = app_group;
246 XagGetApplicationGroupAttributes(Display* dpy, XAppGroup app_group, ...)
249 XExtDisplayInfo *info = find_display (dpy);
251 xXagGetAttrReply rep;
254 XagCheckExtension (dpy, info, False);
257 GetReq(XagGetAttr, req);
258 req->reqType = info->codes->major_opcode;
259 req->xagReqType = X_XagGetAttr;
260 req->app_group = app_group;
261 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
266 va_start (var, app_group);
267 for (attr = va_arg(var, int); attr != 0; attr = va_arg(var, int)) {
271 case XagNappGroupLeader:
272 ptr = va_arg(var, void*);
273 *(Bool*)ptr = rep.app_group_leader;
275 case XagNsingleScreen:
276 ptr = va_arg(var, void*);
277 *(Bool*)ptr = rep.single_screen;
279 case XagNdefaultRoot:
280 ptr = va_arg(var, void*);
281 *(Window*)ptr = rep.default_root;
284 ptr = va_arg(var, void*);
285 *(VisualID*)ptr = rep.root_visual;
287 case XagNdefaultColormap:
288 ptr = va_arg(var, void*);
289 *(Colormap*)ptr = rep.default_colormap;
292 ptr = va_arg(var, void*);
293 *(unsigned long*)ptr = rep.black_pixel;
296 ptr = va_arg(var, void*);
297 *(unsigned long*)ptr = rep.white_pixel;
308 XagQueryApplicationGroup(
311 XAppGroup* app_group_return)
313 XExtDisplayInfo *info = find_display (dpy);
317 XagCheckExtension (dpy, info, False);
320 GetReq(XagQuery, req);
321 req->reqType = info->codes->major_opcode;
322 req->xagReqType = X_XagQuery;
323 req->resource = resource;
324 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
329 *app_group_return = rep.app_group;
337 XagCreateAssociation(Display* dpy, Window* window_return, void* system_window)
340 long tmp = *(HWND*) system_window;
341 XExtDisplayInfo *info = find_display (dpy);
342 xXagCreateAssocReq *req;
344 XagCheckExtension (dpy, info, False);
347 GetReq(XagCreateAssoc, req);
348 req->reqType = info->codes->major_opcode;
349 req->xagReqType = X_XagCreateAssoc;
350 *window_return = req->window = XAllocID(dpy);
351 req->window_type = XagWindowTypeWin32;
352 req->system_window_len = sizeof(HWND);
353 Data32 (dpy, (long*) tmp, 1L);
358 /* other platforms go here */
360 /* this whole thing could be arranged better, but since X need
361 * only short-circuit the protocol and WIN32 is the only other
362 * platform the XC supports, it will suffice for now.
364 *window_return = *(Window*)system_window;
370 XagDestroyAssociation(Display* dpy, Window window)
373 XExtDisplayInfo *info = find_display (dpy);
374 xXagDestroyAssocReq *req;
376 XagCheckExtension (dpy, info, False);
379 GetReq(XagDestroyAssoc, req);
380 req->reqType = info->codes->major_opcode;
381 req->xagReqType = X_XagDestroyAssoc;
382 req->window = window;