comparison src/video/Xext/Xinerama/Xinerama.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents ecba4bbaf9c2
children 81dde1b00bf1
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
29 #define NEED_REPLIES 29 #define NEED_REPLIES
30 30
31 #include <X11/Xlibint.h> 31 #include <X11/Xlibint.h>
32 #include <X11/Xutil.h> 32 #include <X11/Xutil.h>
33 #include "../extensions/Xext.h" 33 #include "../extensions/Xext.h"
34 #include "../extensions/extutil.h" /* in ../include */ 34 #include "../extensions/extutil.h" /* in ../include */
35 #include "../extensions/panoramiXext.h" 35 #include "../extensions/panoramiXext.h"
36 #include "../extensions/panoramiXproto.h" /* in ../include */ 36 #include "../extensions/panoramiXproto.h" /* in ../include */
37 #include "../extensions/Xinerama.h" 37 #include "../extensions/Xinerama.h"
38 38
39 static XExtensionInfo _panoramiX_ext_info_data; 39 static XExtensionInfo _panoramiX_ext_info_data;
40 static XExtensionInfo *panoramiX_ext_info = &_panoramiX_ext_info_data; 40 static XExtensionInfo *panoramiX_ext_info = &_panoramiX_ext_info_data;
41 static /* const */ char *panoramiX_extension_name = PANORAMIX_PROTOCOL_NAME; 41 static /* const */ char *panoramiX_extension_name = PANORAMIX_PROTOCOL_NAME;
45 #define PanoramiXSimpleCheckExtension(dpy,i) \ 45 #define PanoramiXSimpleCheckExtension(dpy,i) \
46 XextSimpleCheckExtension (dpy, i, panoramiX_extension_name) 46 XextSimpleCheckExtension (dpy, i, panoramiX_extension_name)
47 47
48 static int close_display(); 48 static int close_display();
49 static /* const */ XExtensionHooks panoramiX_extension_hooks = { 49 static /* const */ XExtensionHooks panoramiX_extension_hooks = {
50 NULL, /* create_gc */ 50 NULL, /* create_gc */
51 NULL, /* copy_gc */ 51 NULL, /* copy_gc */
52 NULL, /* flush_gc */ 52 NULL, /* flush_gc */
53 NULL, /* free_gc */ 53 NULL, /* free_gc */
54 NULL, /* create_font */ 54 NULL, /* create_font */
55 NULL, /* free_font */ 55 NULL, /* free_font */
56 close_display, /* close_display */ 56 close_display, /* close_display */
57 NULL, /* wire_to_event */ 57 NULL, /* wire_to_event */
58 NULL, /* event_to_wire */ 58 NULL, /* event_to_wire */
59 NULL, /* error */ 59 NULL, /* error */
60 NULL, /* error_string */ 60 NULL, /* error_string */
61 }; 61 };
62 62
63 static XEXT_GENERATE_FIND_DISPLAY (find_display, panoramiX_ext_info, 63 static
64 panoramiX_extension_name, 64 XEXT_GENERATE_FIND_DISPLAY(find_display, panoramiX_ext_info,
65 &panoramiX_extension_hooks, 65 panoramiX_extension_name,
66 0, NULL) 66 &panoramiX_extension_hooks, 0, NULL)
67 67 static XEXT_GENERATE_CLOSE_DISPLAY(close_display, panoramiX_ext_info)
68 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, panoramiX_ext_info)
69
70
71
72 /**************************************************************************** 68 /****************************************************************************
73 * * 69 * *
74 * PanoramiX public interfaces * 70 * PanoramiX public interfaces *
75 * * 71 * *
76 ****************************************************************************/ 72 ****************************************************************************/
77 73 Bool SDL_NAME(XPanoramiXQueryExtension) (Display * dpy,
78 Bool SDL_NAME(XPanoramiXQueryExtension) ( 74 int *event_basep,
79 Display *dpy, 75 int *error_basep)
80 int *event_basep, 76 {
81 int *error_basep 77 XExtDisplayInfo *info = find_display(dpy);
82 )
83 {
84 XExtDisplayInfo *info = find_display (dpy);
85 78
86 if (XextHasExtension(info)) { 79 if (XextHasExtension(info)) {
87 *event_basep = info->codes->first_event; 80 *event_basep = info->codes->first_event;
88 *error_basep = info->codes->first_error; 81 *error_basep = info->codes->first_error;
89 return True; 82 return True;
90 } else { 83 } else {
91 return False; 84 return False;
92 } 85 }
93 } 86 }
94 87
95 88
96 Status SDL_NAME(XPanoramiXQueryVersion)( 89 Status SDL_NAME(XPanoramiXQueryVersion) (Display * dpy,
97 Display *dpy, 90 int *major_versionp,
98 int *major_versionp, 91 int *minor_versionp)
99 int *minor_versionp 92 {
100 ) 93 XExtDisplayInfo *info = find_display(dpy);
101 { 94 xPanoramiXQueryVersionReply rep;
102 XExtDisplayInfo *info = find_display (dpy); 95 register xPanoramiXQueryVersionReq *req;
103 xPanoramiXQueryVersionReply rep; 96
104 register xPanoramiXQueryVersionReq *req; 97 PanoramiXCheckExtension(dpy, info, 0);
105 98
106 PanoramiXCheckExtension (dpy, info, 0); 99 LockDisplay(dpy);
107 100 GetReq(PanoramiXQueryVersion, req);
108 LockDisplay (dpy);
109 GetReq (PanoramiXQueryVersion, req);
110 req->reqType = info->codes->major_opcode; 101 req->reqType = info->codes->major_opcode;
111 req->panoramiXReqType = X_PanoramiXQueryVersion; 102 req->panoramiXReqType = X_PanoramiXQueryVersion;
112 req->clientMajor = PANORAMIX_MAJOR_VERSION; 103 req->clientMajor = PANORAMIX_MAJOR_VERSION;
113 req->clientMinor = PANORAMIX_MINOR_VERSION; 104 req->clientMinor = PANORAMIX_MINOR_VERSION;
114 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { 105 if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) {
115 UnlockDisplay (dpy); 106 UnlockDisplay(dpy);
116 SyncHandle (); 107 SyncHandle();
117 return 0; 108 return 0;
118 } 109 }
119 *major_versionp = rep.majorVersion; 110 *major_versionp = rep.majorVersion;
120 *minor_versionp = rep.minorVersion; 111 *minor_versionp = rep.minorVersion;
121 UnlockDisplay (dpy); 112 UnlockDisplay(dpy);
122 SyncHandle (); 113 SyncHandle();
123 return 1; 114 return 1;
124 } 115 }
125 116
126 SDL_NAME(XPanoramiXInfo) *SDL_NAME(XPanoramiXAllocInfo)(void) 117 SDL_NAME(XPanoramiXInfo) * SDL_NAME(XPanoramiXAllocInfo) (void)
127 { 118 {
128 return (SDL_NAME(XPanoramiXInfo) *) Xmalloc (sizeof (SDL_NAME(XPanoramiXInfo))); 119 return (SDL_NAME(XPanoramiXInfo) *)
129 } 120 Xmalloc(sizeof(SDL_NAME(XPanoramiXInfo)));
130 121 }
131 Status SDL_NAME(XPanoramiXGetState) ( 122
132 Display *dpy, 123 Status SDL_NAME(XPanoramiXGetState) (Display * dpy,
133 Drawable drawable, 124 Drawable drawable,
134 SDL_NAME(XPanoramiXInfo) *panoramiX_info 125 SDL_NAME(XPanoramiXInfo) *
135 ) 126 panoramiX_info)
136 { 127 {
137 XExtDisplayInfo *info = find_display (dpy); 128 XExtDisplayInfo *info = find_display(dpy);
138 xPanoramiXGetStateReply rep; 129 xPanoramiXGetStateReply rep;
139 register xPanoramiXGetStateReq *req; 130 register xPanoramiXGetStateReq *req;
140 131
141 PanoramiXCheckExtension (dpy, info, 0); 132 PanoramiXCheckExtension(dpy, info, 0);
142 133
143 LockDisplay (dpy); 134 LockDisplay(dpy);
144 GetReq (PanoramiXGetState, req); 135 GetReq(PanoramiXGetState, req);
145 req->reqType = info->codes->major_opcode; 136 req->reqType = info->codes->major_opcode;
146 req->panoramiXReqType = X_PanoramiXGetState; 137 req->panoramiXReqType = X_PanoramiXGetState;
147 req->window = drawable; 138 req->window = drawable;
148 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { 139 if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) {
149 UnlockDisplay (dpy); 140 UnlockDisplay(dpy);
150 SyncHandle (); 141 SyncHandle();
151 return 0; 142 return 0;
152 } 143 }
153 UnlockDisplay (dpy); 144 UnlockDisplay(dpy);
154 SyncHandle (); 145 SyncHandle();
155 panoramiX_info->window = rep.window; 146 panoramiX_info->window = rep.window;
156 panoramiX_info->State = rep.state; 147 panoramiX_info->State = rep.state;
157 return 1; 148 return 1;
158 } 149 }
159 150
160 Status SDL_NAME(XPanoramiXGetScreenCount) ( 151 Status SDL_NAME(XPanoramiXGetScreenCount) (Display * dpy,
161 Display *dpy, 152 Drawable drawable,
162 Drawable drawable, 153 SDL_NAME(XPanoramiXInfo) *
163 SDL_NAME(XPanoramiXInfo) *panoramiX_info 154 panoramiX_info)
164 ) 155 {
165 { 156 XExtDisplayInfo *info = find_display(dpy);
166 XExtDisplayInfo *info = find_display (dpy); 157 xPanoramiXGetScreenCountReply rep;
167 xPanoramiXGetScreenCountReply rep; 158 register xPanoramiXGetScreenCountReq *req;
168 register xPanoramiXGetScreenCountReq *req; 159
169 160 PanoramiXCheckExtension(dpy, info, 0);
170 PanoramiXCheckExtension (dpy, info, 0); 161
171 162 LockDisplay(dpy);
172 LockDisplay (dpy); 163 GetReq(PanoramiXGetScreenCount, req);
173 GetReq (PanoramiXGetScreenCount, req);
174 req->reqType = info->codes->major_opcode; 164 req->reqType = info->codes->major_opcode;
175 req->panoramiXReqType = X_PanoramiXGetScreenCount; 165 req->panoramiXReqType = X_PanoramiXGetScreenCount;
176 req->window = drawable; 166 req->window = drawable;
177 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { 167 if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) {
178 UnlockDisplay (dpy); 168 UnlockDisplay(dpy);
179 SyncHandle (); 169 SyncHandle();
180 return 0; 170 return 0;
181 } 171 }
182 UnlockDisplay (dpy); 172 UnlockDisplay(dpy);
183 SyncHandle (); 173 SyncHandle();
184 panoramiX_info->window = rep.window; 174 panoramiX_info->window = rep.window;
185 panoramiX_info->ScreenCount = rep.ScreenCount; 175 panoramiX_info->ScreenCount = rep.ScreenCount;
186 return 1; 176 return 1;
187 } 177 }
188 178
189 Status SDL_NAME(XPanoramiXGetScreenSize) ( 179 Status SDL_NAME(XPanoramiXGetScreenSize) (Display * dpy,
190 Display *dpy, 180 Drawable drawable,
191 Drawable drawable, 181 int screen_num,
192 int screen_num, 182 SDL_NAME(XPanoramiXInfo) *
193 SDL_NAME(XPanoramiXInfo) *panoramiX_info 183 panoramiX_info)
194 ) 184 {
195 { 185 XExtDisplayInfo *info = find_display(dpy);
196 XExtDisplayInfo *info = find_display (dpy); 186 xPanoramiXGetScreenSizeReply rep;
197 xPanoramiXGetScreenSizeReply rep; 187 register xPanoramiXGetScreenSizeReq *req;
198 register xPanoramiXGetScreenSizeReq *req; 188
199 189 PanoramiXCheckExtension(dpy, info, 0);
200 PanoramiXCheckExtension (dpy, info, 0); 190
201 191 LockDisplay(dpy);
202 LockDisplay (dpy); 192 GetReq(PanoramiXGetScreenSize, req);
203 GetReq (PanoramiXGetScreenSize, req);
204 req->reqType = info->codes->major_opcode; 193 req->reqType = info->codes->major_opcode;
205 req->panoramiXReqType = X_PanoramiXGetScreenSize; 194 req->panoramiXReqType = X_PanoramiXGetScreenSize;
206 req->window = drawable; 195 req->window = drawable;
207 req->screen = screen_num; /* need to define */ 196 req->screen = screen_num; /* need to define */
208 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { 197 if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) {
209 UnlockDisplay (dpy); 198 UnlockDisplay(dpy);
210 SyncHandle (); 199 SyncHandle();
211 return 0; 200 return 0;
212 } 201 }
213 UnlockDisplay (dpy); 202 UnlockDisplay(dpy);
214 SyncHandle (); 203 SyncHandle();
215 panoramiX_info->window = rep.window; 204 panoramiX_info->window = rep.window;
216 panoramiX_info->screen = rep.screen; 205 panoramiX_info->screen = rep.screen;
217 panoramiX_info->width = rep.width; 206 panoramiX_info->width = rep.width;
218 panoramiX_info->height = rep.height; 207 panoramiX_info->height = rep.height;
219 return 1; 208 return 1;
220 } 209 }
221 210
222 /*******************************************************************\ 211 /*******************************************************************\
223 Alternate interface to make up for shortcomings in the original, 212 Alternate interface to make up for shortcomings in the original,
224 namely, the omission of the screen origin. The new interface is 213 namely, the omission of the screen origin. The new interface is
225 in the "Xinerama" namespace instead of "PanoramiX". 214 in the "Xinerama" namespace instead of "PanoramiX".
226 \*******************************************************************/ 215 \*******************************************************************/
227 216
228 Bool SDL_NAME(XineramaQueryExtension) ( 217 Bool SDL_NAME(XineramaQueryExtension) (Display * dpy,
229 Display *dpy, 218 int *event_base, int *error_base)
230 int *event_base, 219 {
231 int *error_base 220 return SDL_NAME(XPanoramiXQueryExtension) (dpy, event_base, error_base);
232 ) 221 }
233 { 222
234 return SDL_NAME(XPanoramiXQueryExtension)(dpy, event_base, error_base); 223 Status SDL_NAME(XineramaQueryVersion) (Display * dpy, int *major, int *minor)
235 } 224 {
236 225 return SDL_NAME(XPanoramiXQueryVersion) (dpy, major, minor);
237 Status SDL_NAME(XineramaQueryVersion)( 226 }
238 Display *dpy, 227
239 int *major, 228 Bool SDL_NAME(XineramaIsActive) (Display * dpy)
240 int *minor 229 {
241 ) 230 xXineramaIsActiveReply rep;
242 { 231 xXineramaIsActiveReq *req;
243 return SDL_NAME(XPanoramiXQueryVersion)(dpy, major, minor); 232 XExtDisplayInfo *info = find_display(dpy);
244 } 233
245 234 if (!XextHasExtension(info))
246 Bool SDL_NAME(XineramaIsActive)(Display *dpy) 235 return False; /* server doesn't even have the extension */
247 { 236
248 xXineramaIsActiveReply rep; 237 LockDisplay(dpy);
249 xXineramaIsActiveReq *req; 238 GetReq(XineramaIsActive, req);
250 XExtDisplayInfo *info = find_display (dpy);
251
252 if(!XextHasExtension(info))
253 return False; /* server doesn't even have the extension */
254
255 LockDisplay (dpy);
256 GetReq (XineramaIsActive, req);
257 req->reqType = info->codes->major_opcode; 239 req->reqType = info->codes->major_opcode;
258 req->panoramiXReqType = X_XineramaIsActive; 240 req->panoramiXReqType = X_XineramaIsActive;
259 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { 241 if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) {
260 UnlockDisplay (dpy); 242 UnlockDisplay(dpy);
261 SyncHandle (); 243 SyncHandle();
262 return False; 244 return False;
263 } 245 }
264 UnlockDisplay (dpy); 246 UnlockDisplay(dpy);
265 SyncHandle (); 247 SyncHandle();
266 return rep.state; 248 return rep.state;
267 } 249 }
268 250
269 #include <stdio.h> 251 #include <stdio.h>
270 252
271 SDL_NAME(XineramaScreenInfo) * 253 SDL_NAME(XineramaScreenInfo) *
272 SDL_NAME(XineramaQueryScreens)( 254 SDL_NAME(XineramaQueryScreens) (Display * dpy, int *number)
273 Display *dpy, 255 {
274 int *number 256 XExtDisplayInfo *info = find_display(dpy);
275 ) 257 xXineramaQueryScreensReply rep;
276 { 258 xXineramaQueryScreensReq *req;
277 XExtDisplayInfo *info = find_display (dpy); 259 SDL_NAME(XineramaScreenInfo) * scrnInfo = NULL;
278 xXineramaQueryScreensReply rep; 260
279 xXineramaQueryScreensReq *req; 261 PanoramiXCheckExtension(dpy, info, 0);
280 SDL_NAME(XineramaScreenInfo) *scrnInfo = NULL; 262
281 263 LockDisplay(dpy);
282 PanoramiXCheckExtension (dpy, info, 0); 264 GetReq(XineramaQueryScreens, req);
283
284 LockDisplay (dpy);
285 GetReq (XineramaQueryScreens, req);
286 req->reqType = info->codes->major_opcode; 265 req->reqType = info->codes->major_opcode;
287 req->panoramiXReqType = X_XineramaQueryScreens; 266 req->panoramiXReqType = X_XineramaQueryScreens;
288 if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) { 267 if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
289 UnlockDisplay (dpy); 268 UnlockDisplay(dpy);
290 SyncHandle (); 269 SyncHandle();
291 return NULL; 270 return NULL;
292 } 271 }
293 272
294 if(rep.number) { 273 if (rep.number) {
295 if((scrnInfo = Xmalloc(sizeof(SDL_NAME(XineramaScreenInfo)) * rep.number))) { 274 if ((scrnInfo =
296 xXineramaScreenInfo scratch; 275 Xmalloc(sizeof(SDL_NAME(XineramaScreenInfo)) * rep.number))) {
297 int i; 276 xXineramaScreenInfo scratch;
298 277 int i;
299 for(i = 0; i < rep.number; i++) { 278
300 _XRead(dpy, (char*)(&scratch), sz_XineramaScreenInfo); 279 for (i = 0; i < rep.number; i++) {
301 scrnInfo[i].screen_number = i; 280 _XRead(dpy, (char *) (&scratch), sz_XineramaScreenInfo);
302 scrnInfo[i].x_org = scratch.x_org; 281 scrnInfo[i].screen_number = i;
303 scrnInfo[i].y_org = scratch.y_org; 282 scrnInfo[i].x_org = scratch.x_org;
304 scrnInfo[i].width = scratch.width; 283 scrnInfo[i].y_org = scratch.y_org;
305 scrnInfo[i].height = scratch.height; 284 scrnInfo[i].width = scratch.width;
306 } 285 scrnInfo[i].height = scratch.height;
307 286 }
308 *number = rep.number; 287
309 } else 288 *number = rep.number;
310 _XEatData(dpy, rep.length << 2); 289 } else
311 } 290 _XEatData(dpy, rep.length << 2);
312 291 }
313 UnlockDisplay (dpy); 292
314 SyncHandle (); 293 UnlockDisplay(dpy);
294 SyncHandle();
315 return scrnInfo; 295 return scrnInfo;
316 } 296 }
317 297
318 298 /* vi: set ts=4 sw=4 expandtab: */
319