1 /*****************************************************************
2 Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
3 Permission is hereby granted, free of charge, to any person obtaining a copy
4 of this software and associated documentation files (the "Software"), to deal
5 in the Software without restriction, including without limitation the rights
6 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 copies of the Software.
9 The above copyright notice and this permission notice shall be included in
10 all copies or substantial portions of the Software.
12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
16 BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
17 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
18 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 Except as contained in this notice, the name of Digital Equipment Corporation
21 shall not be used in advertising or otherwise to promote the sale, use or other
22 dealings in this Software without prior written authorization from Digital
23 Equipment Corporation.
24 ******************************************************************/
26 #include <X11/Xlibint.h>
27 #include <X11/Xutil.h>
28 #include <X11/extensions/Xext.h>
29 #include <X11/extensions/extutil.h>
30 #include <X11/extensions/panoramiXext.h>
31 #include <X11/extensions/panoramiXproto.h>
32 #include <X11/extensions/Xinerama.h>
35 static XExtensionInfo _panoramiX_ext_info_data;
36 static XExtensionInfo *panoramiX_ext_info = &_panoramiX_ext_info_data;
37 static const char *panoramiX_extension_name = PANORAMIX_PROTOCOL_NAME;
39 #define PanoramiXCheckExtension(dpy,i,val) \
40 XextCheckExtension (dpy, i, panoramiX_extension_name, val)
41 #define PanoramiXSimpleCheckExtension(dpy,i) \
42 XextSimpleCheckExtension (dpy, i, panoramiX_extension_name)
44 static int close_display(Display *dpy, XExtCodes *codes);
46 static /* const */ XExtensionHooks panoramiX_extension_hooks = {
51 NULL, /* create_font */
53 close_display, /* close_display */
54 NULL, /* wire_to_event */
55 NULL, /* event_to_wire */
57 NULL, /* error_string */
60 static XEXT_GENERATE_FIND_DISPLAY (find_display, panoramiX_ext_info,
61 panoramiX_extension_name,
62 &panoramiX_extension_hooks,
65 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, panoramiX_ext_info)
69 /****************************************************************************
71 * PanoramiX public interfaces *
73 ****************************************************************************/
75 Bool XPanoramiXQueryExtension (
77 int *event_base_return,
78 int *error_base_return
81 XExtDisplayInfo *info = find_display (dpy);
83 if (XextHasExtension(info)) {
84 *event_base_return = info->codes->first_event;
85 *error_base_return = info->codes->first_error;
93 Status XPanoramiXQueryVersion(
95 int *major_version_return,
96 int *minor_version_return
99 XExtDisplayInfo *info = find_display (dpy);
100 xPanoramiXQueryVersionReply rep;
101 register xPanoramiXQueryVersionReq *req;
103 PanoramiXCheckExtension (dpy, info, 0);
106 GetReq (PanoramiXQueryVersion, req);
107 req->reqType = info->codes->major_opcode;
108 req->panoramiXReqType = X_PanoramiXQueryVersion;
109 req->clientMajor = PANORAMIX_MAJOR_VERSION;
110 req->clientMinor = PANORAMIX_MINOR_VERSION;
111 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
116 *major_version_return = rep.majorVersion;
117 *minor_version_return = rep.minorVersion;
123 XPanoramiXInfo *XPanoramiXAllocInfo(void)
125 return (XPanoramiXInfo *) Xmalloc (sizeof (XPanoramiXInfo));
128 Status XPanoramiXGetState (
131 XPanoramiXInfo *panoramiX_info
134 XExtDisplayInfo *info = find_display (dpy);
135 xPanoramiXGetStateReply rep;
136 register xPanoramiXGetStateReq *req;
138 PanoramiXCheckExtension (dpy, info, 0);
141 GetReq (PanoramiXGetState, req);
142 req->reqType = info->codes->major_opcode;
143 req->panoramiXReqType = X_PanoramiXGetState;
144 req->window = drawable;
145 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
152 panoramiX_info->window = rep.window;
153 panoramiX_info->State = rep.state;
157 Status XPanoramiXGetScreenCount (
160 XPanoramiXInfo *panoramiX_info
163 XExtDisplayInfo *info = find_display (dpy);
164 xPanoramiXGetScreenCountReply rep;
165 register xPanoramiXGetScreenCountReq *req;
167 PanoramiXCheckExtension (dpy, info, 0);
170 GetReq (PanoramiXGetScreenCount, req);
171 req->reqType = info->codes->major_opcode;
172 req->panoramiXReqType = X_PanoramiXGetScreenCount;
173 req->window = drawable;
174 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
181 panoramiX_info->window = rep.window;
182 panoramiX_info->ScreenCount = rep.ScreenCount;
186 Status XPanoramiXGetScreenSize (
190 XPanoramiXInfo *panoramiX_info
193 XExtDisplayInfo *info = find_display (dpy);
194 xPanoramiXGetScreenSizeReply rep;
195 register xPanoramiXGetScreenSizeReq *req;
197 PanoramiXCheckExtension (dpy, info, 0);
200 GetReq (PanoramiXGetScreenSize, req);
201 req->reqType = info->codes->major_opcode;
202 req->panoramiXReqType = X_PanoramiXGetScreenSize;
203 req->window = drawable;
204 req->screen = screen_num; /* need to define */
205 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
212 panoramiX_info->window = rep.window;
213 panoramiX_info->screen = rep.screen;
214 panoramiX_info->width = rep.width;
215 panoramiX_info->height = rep.height;
219 /*******************************************************************\
220 Alternate interface to make up for shortcomings in the original,
221 namely, the omission of the screen origin. The new interface is
222 in the "Xinerama" namespace instead of "PanoramiX".
223 \*******************************************************************/
225 Bool XineramaQueryExtension (
227 int *event_base_return,
228 int *error_base_return
231 return XPanoramiXQueryExtension(dpy, event_base_return, error_base_return);
234 Status XineramaQueryVersion(
240 return XPanoramiXQueryVersion(dpy, major, minor);
243 Bool XineramaIsActive(Display *dpy)
245 xXineramaIsActiveReply rep;
246 xXineramaIsActiveReq *req;
247 XExtDisplayInfo *info = find_display (dpy);
249 if(!XextHasExtension(info))
250 return False; /* server doesn't even have the extension */
253 GetReq (XineramaIsActive, req);
254 req->reqType = info->codes->major_opcode;
255 req->panoramiXReqType = X_XineramaIsActive;
256 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
267 XineramaQueryScreens(
272 XExtDisplayInfo *info = find_display (dpy);
273 xXineramaQueryScreensReply rep;
274 xXineramaQueryScreensReq *req;
275 XineramaScreenInfo *scrnInfo = NULL;
277 PanoramiXCheckExtension (dpy, info, NULL);
280 GetReq (XineramaQueryScreens, req);
281 req->reqType = info->codes->major_opcode;
282 req->panoramiXReqType = X_XineramaQueryScreens;
283 if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
290 if((scrnInfo = Xmalloc(sizeof(XineramaScreenInfo) * rep.number))) {
291 xXineramaScreenInfo scratch;
294 for(i = 0; i < rep.number; i++) {
295 _XRead(dpy, (char*)(&scratch), sz_XineramaScreenInfo);
296 scrnInfo[i].screen_number = i;
297 scrnInfo[i].x_org = scratch.x_org;
298 scrnInfo[i].y_org = scratch.y_org;
299 scrnInfo[i].width = scratch.width;
300 scrnInfo[i].height = scratch.height;
303 *number = rep.number;
305 _XEatData(dpy, rep.length << 2);