3 Copyright 1987, 1988, 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/Xcup.h>
36 #include <X11/extensions/cupproto.h>
37 #include <X11/extensions/Xext.h>
38 #include <X11/extensions/extutil.h>
40 static XExtensionInfo _xcup_info_data;
41 static XExtensionInfo *xcup_info = &_xcup_info_data;
42 static const char *xcup_extension_name = XCUPNAME;
44 /*****************************************************************************
46 * private utility routines *
48 *****************************************************************************/
50 static int close_display(Display *dpy, XExtCodes *codes);
51 static /* const */ XExtensionHooks xcup_extension_hooks = {
56 NULL, /* create_font */
58 close_display, /* close_display */
59 NULL, /* wire_to_event */
60 NULL, /* event_to_wire */
62 NULL, /* error_string */
65 static XEXT_GENERATE_FIND_DISPLAY (find_display, xcup_info,
67 &xcup_extension_hooks,
70 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xcup_info)
73 /*****************************************************************************
75 * public Xcup Extension routines *
77 *****************************************************************************/
82 int* major_version_return,
83 int* minor_version_return)
85 XExtDisplayInfo *info = find_display (dpy);
86 xXcupQueryVersionReply rep;
87 xXcupQueryVersionReq *req;
89 XextCheckExtension (dpy, info, xcup_extension_name, False);
92 GetReq(XcupQueryVersion, req);
93 req->reqType = info->codes->major_opcode;
94 req->xcupReqType = X_XcupQueryVersion;
95 req->client_major_version = XCUP_MAJOR_VERSION;
96 req->client_minor_version = XCUP_MINOR_VERSION;
97 if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
102 *major_version_return = rep.server_major_version;
103 *minor_version_return = rep.server_minor_version;
109 /* Win32 reserves 20 colormap entries for its desktop */
110 #ifndef TYP_RESERVED_ENTRIES
111 #define TYP_RESERVED_ENTRIES 20
115 XcupGetReservedColormapEntries(
121 XExtDisplayInfo *info = find_display (dpy);
122 xXcupGetReservedColormapEntriesReply rep;
123 xXcupGetReservedColormapEntriesReq *req;
124 xColorItem rbuf[TYP_RESERVED_ENTRIES];
128 XextCheckExtension (dpy, info, xcup_extension_name, False);
131 GetReq(XcupGetReservedColormapEntries, req);
132 req->reqType = info->codes->major_opcode;
133 req->xcupReqType = X_XcupGetReservedColormapEntries;
134 req->screen = screen;
135 if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
138 int nentries = rep.length / 3;
140 nbytes = nentries * SIZEOF (xColorItem);
141 if (nentries > TYP_RESERVED_ENTRIES)
142 rbufp = (xColorItem*) Xmalloc (nbytes);
147 _XEatData (dpy, (unsigned long) nbytes);
152 _XRead (dpy, (char*) rbufp, nbytes);
154 *colors_out = (XColor*) Xmalloc (nentries * sizeof (XColor));
156 xColorItem* cs = (xColorItem *) rbufp;
157 XColor* cd = *colors_out;
161 for (i = 0; i < *ncolors; i++, cd++) {
162 cd->pixel = cs->pixel;
164 cd->green = cs->green;
166 cs = (xColorItem*) (((char*) cs) + SIZEOF(xColorItem));
168 if (rbufp != rbuf) XFree ((char*) rbufp);
173 if (rbufp != rbuf) XFree ((char*) rbufp);
184 XColor* colors_in_out,
187 XExtDisplayInfo *info = find_display (dpy);
188 xXcupStoreColorsReply rep;
189 xXcupStoreColorsReq *req;
190 xColorItem rbuf[256];
195 XextCheckExtension (dpy, info, xcup_extension_name, False);
198 GetReq(XcupStoreColors, req);
199 req->reqType = info->codes->major_opcode;
200 req->xcupReqType = X_XcupStoreColors;
201 req->cmap = colormap;
202 req->length += (ncolors * SIZEOF(xColorItem)) >> 2;
204 for (i = 0, xcp = colors_in_out; i < ncolors; i++, xcp++) {
205 citem.pixel = xcp->pixel;
206 citem.red = xcp->red;
207 citem.green = xcp->green;
208 citem.blue = xcp->blue;
210 /* note that xColorItem doesn't contain all 16-bit quantities, so
211 we can't use Data16 */
212 Data(dpy, (char *)&citem, (long) SIZEOF(xColorItem));
215 if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
219 int nentries = rep.length / 3;
221 nbytes = nentries * SIZEOF (xColorItem);
223 if (nentries != ncolors) {
224 _XEatData (dpy, (unsigned long) nbytes);
231 rbufp = (xColorItem*) Xmalloc (nbytes);
236 _XEatData (dpy, (unsigned long) nbytes);
243 _XRead (dpy, (char*) rbufp, nbytes);
245 for (i = 0, xcp = colors_in_out, cs = rbufp; i < ncolors; i++, xcp++, cs++) {
246 xcp->pixel = cs->pixel;
248 xcp->green = cs->green;
249 xcp->blue = cs->blue;
250 xcp->flags = cs->flags;
252 if (rbufp != rbuf) XFree ((char*)rbufp);