comparison src/video/x11/SDL_x11modes.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 14717b52abc0
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
35 35
36 /*#define X11MODES_DEBUG*/ 36 /*#define X11MODES_DEBUG*/
37 37
38 #define MAX(a, b) (a > b ? a : b) 38 #define MAX(a, b) (a > b ? a : b)
39 39
40 #if SDL_VIDEO_DRIVER_X11_XRANDR 40 #if SDL_VIDEO_DRIVER_X11_VIDMODE
41 static int cmpmodelist(const void *va, const void *vb) 41 int
42 { 42 vidmode_refreshrate (SDL_NAME (XF86VidModeModeInfo) * mode)
43 const SDL_Rect *a = *(const SDL_Rect **)va; 43 {
44 const SDL_Rect *b = *(const SDL_Rect **)vb; 44 return (mode->htotal
45 if ( a->w == b->w ) 45 && mode->vtotal) ? (1000 * mode->dotclock / (mode->htotal *
46 return b->h - a->h; 46 mode->vtotal)) : 0;
47 else 47 }
48 return b->w - a->w; 48 #endif
49 } 49
50 #endif 50 #if SDL_VIDEO_DRIVER_X11_VIDMODE
51 51 Bool SDL_NAME (XF86VidModeGetModeInfo) (Display * dpy, int scr,
52 #if SDL_VIDEO_DRIVER_X11_VIDMODE 52 SDL_NAME (XF86VidModeModeInfo) * info)
53 Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info) 53 {
54 { 54 SDL_NAME (XF86VidModeModeLine) * l =
55 SDL_NAME(XF86VidModeModeLine) *l = (SDL_NAME(XF86VidModeModeLine)*)((char*)info + sizeof info->dotclock); 55 (SDL_NAME (XF86VidModeModeLine) *) ((char *) info +
56 return SDL_NAME(XF86VidModeGetModeLine)(dpy, scr, (int*)&info->dotclock, l); 56 sizeof info->dotclock);
57 return SDL_NAME (XF86VidModeGetModeLine) (dpy, scr,
58 (int *) &info->dotclock, l);
57 } 59 }
58 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ 60 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
59 61
60 #if SDL_VIDEO_DRIVER_X11_VIDMODE 62 #if SDL_VIDEO_DRIVER_X11_VIDMODE
61 static void save_mode(_THIS) 63 static void
62 { 64 save_mode (_THIS)
63 SDL_memset(&saved_mode, 0, sizeof(saved_mode)); 65 {
64 SDL_NAME(XF86VidModeGetModeInfo)(SDL_Display,SDL_Screen,&saved_mode); 66 SDL_memset (&saved_mode, 0, sizeof (saved_mode));
65 SDL_NAME(XF86VidModeGetViewPort)(SDL_Display,SDL_Screen,&saved_view.x,&saved_view.y); 67 SDL_NAME (XF86VidModeGetModeInfo) (SDL_Display, SDL_Screen, &saved_mode);
66 } 68 SDL_NAME (XF86VidModeGetViewPort) (SDL_Display, SDL_Screen, &saved_view.x,
67 #endif 69 &saved_view.y);
68 70 }
69 #if SDL_VIDEO_DRIVER_X11_VIDMODE 71 #endif
70 static void restore_mode(_THIS) 72
71 { 73 #if SDL_VIDEO_DRIVER_X11_VIDMODE
72 SDL_NAME(XF86VidModeModeLine) mode; 74 static void
75 restore_mode (_THIS)
76 {
77 SDL_NAME (XF86VidModeModeLine) mode;
73 int unused; 78 int unused;
74 79
75 if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &unused, &mode) ) { 80 if (SDL_NAME (XF86VidModeGetModeLine)
76 if ( (saved_mode.hdisplay != mode.hdisplay) || 81 (SDL_Display, SDL_Screen, &unused, &mode)) {
77 (saved_mode.vdisplay != mode.vdisplay) ) { 82 if ((saved_mode.hdisplay != mode.hdisplay) ||
78 SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, &saved_mode); 83 (saved_mode.vdisplay != mode.vdisplay)) {
79 } 84 SDL_NAME (XF86VidModeSwitchToMode) (SDL_Display, SDL_Screen,
80 } 85 &saved_mode);
81 if ( (saved_view.x != 0) || (saved_view.y != 0) ) { 86 }
82 SDL_NAME(XF86VidModeSetViewPort)(SDL_Display, SDL_Screen, saved_view.x, saved_view.y); 87 }
83 } 88 if ((saved_view.x != 0) || (saved_view.y != 0)) {
84 } 89 SDL_NAME (XF86VidModeSetViewPort) (SDL_Display, SDL_Screen,
85 #endif 90 saved_view.x, saved_view.y);
86 91 }
87 #if SDL_VIDEO_DRIVER_X11_VIDMODE 92 }
88 static int cmpmodes(const void *va, const void *vb) 93 #endif
89 { 94
90 const SDL_NAME(XF86VidModeModeInfo) *a = *(const SDL_NAME(XF86VidModeModeInfo)**)va; 95 static void get_real_resolution (_THIS, int *w, int *h);
91 const SDL_NAME(XF86VidModeModeInfo) *b = *(const SDL_NAME(XF86VidModeModeInfo)**)vb; 96
92 if ( a->hdisplay == b->hdisplay ) 97 static void
93 return b->vdisplay - a->vdisplay; 98 set_best_resolution (_THIS, int width, int height)
94 else 99 {
95 return b->hdisplay - a->hdisplay; 100 SDL_DisplayMode mode;
96 } 101
97 #endif 102 mode.format = 0;
98 103 mode.w = width;
99 static void get_real_resolution(_THIS, int* w, int* h); 104 mode.h = height;
100 105 mode.refresh_rate = 0;
101 static void set_best_resolution(_THIS, int width, int height) 106 SDL_GetClosestDisplayMode (&mode, &mode, SDL_FULLSCREEN);
102 { 107
103 #if SDL_VIDEO_DRIVER_X11_VIDMODE 108 #if SDL_VIDEO_DRIVER_X11_VIDMODE
104 if ( use_vidmode ) { 109 if (use_vidmode) {
105 SDL_NAME(XF86VidModeModeLine) mode; 110 SDL_NAME (XF86VidModeModeLine) vmode;
106 SDL_NAME(XF86VidModeModeInfo) **modes; 111 SDL_NAME (XF86VidModeModeInfo) vinfo;
107 int i; 112 SDL_NAME (XF86VidModeModeInfo) ** modes;
113 int i, dotclock;
108 int nmodes; 114 int nmodes;
109 int best = -1; 115 int best = -1;
110 116
111 if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) && 117 if (SDL_NAME (XF86VidModeGetModeLine)
112 SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes) ) { 118 (SDL_Display, SDL_Screen, &dotclock, &vmode)
113 for ( i = 0; i < nmodes ; i++ ) { 119 && SDL_NAME (XF86VidModeGetAllModeLines) (SDL_Display,
114 if ( (modes[i]->hdisplay == width) && 120 SDL_Screen, &nmodes,
115 (modes[i]->vdisplay == height) ) { 121 &modes)) {
122 vinfo.dotclock = dotclock;
123 SDL_memcpy (&vinfo.hdisplay, &vmode, sizeof (vmode));
124
125 for (i = 0; i < nmodes; i++) {
126 if ((modes[i]->hdisplay == mode.w) &&
127 (modes[i]->vdisplay == mode.h) &&
128 (vidmode_refreshrate (modes[i]) == mode.refresh_rate)) {
116 best = i; 129 best = i;
117 break; 130 break;
118 } 131 }
119 if ( modes[i]->hdisplay >= width && 132 }
120 modes[i]->vdisplay >= height ) { 133 if (best >= 0 &&
121 if ( best < 0 || 134 ((modes[best]->hdisplay != vmode.hdisplay) ||
122 (modes[i]->hdisplay < modes[best]->hdisplay && 135 (modes[best]->vdisplay != vmode.vdisplay) ||
123 modes[i]->vdisplay <= modes[best]->vdisplay) || 136 (vidmode_refreshrate (modes[best]) !=
124 (modes[i]->vdisplay < modes[best]->vdisplay && 137 vidmode_refreshrate (&vinfo)))) {
125 modes[i]->hdisplay <= modes[best]->hdisplay) ) { 138 #ifdef X11MODES_DEBUG
126 best = i; 139 printf ("Best Mode %d: %d x %d @ %d\n", best,
127 }
128 }
129 }
130 if ( best >= 0 &&
131 ((modes[best]->hdisplay != mode.hdisplay) ||
132 (modes[best]->vdisplay != mode.vdisplay)) ) {
133 #ifdef X11MODES_DEBUG
134 printf("Best Mode %d: %d x %d @ %d\n", best,
135 modes[best]->hdisplay, modes[best]->vdisplay, 140 modes[best]->hdisplay, modes[best]->vdisplay,
136 (modes[best]->htotal && modes[best]->vtotal) ? (1000 * modes[best]->dotclock / (modes[best]->htotal * modes[best]->vtotal)) : 0 ); 141 vidmode_refreshrate (modes[best]));
137 #endif 142 #endif
138 SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[best]); 143 SDL_NAME (XF86VidModeSwitchToMode) (SDL_Display,
139 } 144 SDL_Screen, modes[best]);
140 XFree(modes); 145 }
146 XFree (modes);
141 } 147 }
142 } 148 }
143 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ 149 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
144 150
145 /* XiG */ 151 /* XiG */
146 #if SDL_VIDEO_DRIVER_X11_XME 152 #if SDL_VIDEO_DRIVER_X11_XME
147 if ( use_xme && SDL_modelist ) { 153 if (use_xme) {
148 int i; 154 int i;
149 155 int w, h;
150 #ifdef X11MODES_DEBUG 156
151 fprintf(stderr, "XME: set_best_resolution(): w = %d, h = %d\n", 157 /* check current mode so we can avoid uneccessary mode changes */
152 width, height); 158 get_real_resolution (this, &w, &h);
153 #endif 159
154 for ( i=0; SDL_modelist[i]; ++i ) { 160 if ((mode.w != w) || (mode.h != h)) {
155 if ( (SDL_modelist[i]->w >= width) && 161 #ifdef X11MODES_DEBUG
156 (SDL_modelist[i]->h >= height) ) { 162 fprintf (stderr, "XME: set_best_resolution: "
157 break; 163 "XiGMiscChangeResolution: %d %d\n", mode.w, mode.h);
158 } 164 #endif
159 } 165 XiGMiscChangeResolution (SDL_Display, SDL_Screen, 0, /* view */
160 166 mode.w, mode.h, 0);
161 if ( SDL_modelist[i] ) { /* found one, lets try it */ 167 XSync (SDL_Display, False);
162 int w, h;
163
164 /* check current mode so we can avoid uneccessary mode changes */
165 get_real_resolution(this, &w, &h);
166
167 if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
168 #ifdef X11MODES_DEBUG
169 fprintf(stderr, "XME: set_best_resolution: "
170 "XiGMiscChangeResolution: %d %d\n",
171 SDL_modelist[i]->w, SDL_modelist[i]->h);
172 #endif
173 XiGMiscChangeResolution(SDL_Display,
174 SDL_Screen,
175 0, /* view */
176 SDL_modelist[i]->w,
177 SDL_modelist[i]->h,
178 0);
179 XSync(SDL_Display, False);
180 }
181 } 168 }
182 } 169 }
183 #endif /* SDL_VIDEO_DRIVER_X11_XME */ 170 #endif /* SDL_VIDEO_DRIVER_X11_XME */
184 171
185 #if SDL_VIDEO_DRIVER_X11_XRANDR 172 #if SDL_VIDEO_DRIVER_X11_XRANDR
186 if ( use_xrandr && SDL_modelist ) { 173 if (use_xrandr) {
187 #ifdef X11MODES_DEBUG
188 fprintf(stderr, "XRANDR: set_best_resolution(): w = %d, h = %d\n",
189 width, height);
190 #endif
191 int i, nsizes; 174 int i, nsizes;
192 XRRScreenSize *sizes; 175 XRRScreenSize *sizes;
193 176
194 /* find the smallest resolution that is at least as big as the user requested */ 177 /* find the smallest resolution that is at least as big as the user requested */
195 sizes = XRRConfigSizes(screen_config, &nsizes); 178 sizes = XRRConfigSizes (screen_config, &nsizes);
196 for ( i = (nsizes-1); i >= 0; i-- ) { 179 for (i = (nsizes - 1); i >= 0; i--) {
197 if ( (SDL_modelist[i]->w >= width) && 180 if ((mode.w >= width) && (mode.h >= height)) {
198 (SDL_modelist[i]->h >= height) ) {
199 break; 181 break;
200 } 182 }
201 } 183 }
202 184
203 if ( i >= 0 && SDL_modelist[i] ) { /* found one, lets try it */ 185 if (i >= 0) { /* found one, lets try it */
204 int w, h; 186 int w, h;
205 187
206 /* check current mode so we can avoid uneccessary mode changes */ 188 /* check current mode so we can avoid uneccessary mode changes */
207 get_real_resolution(this, &w, &h); 189 get_real_resolution (this, &w, &h);
208 190
209 if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) { 191 if ((mode.w != w) || (mode.h != h)) {
210 int size_id; 192 int size_id;
211 193
212 #ifdef X11MODES_DEBUG 194 #ifdef X11MODES_DEBUG
213 fprintf(stderr, "XRANDR: set_best_resolution: " 195 fprintf (stderr, "XRANDR: set_best_resolution: "
214 "XXRSetScreenConfig: %d %d\n", 196 "XXRSetScreenConfig: %d %d\n", mode.w, mode.h);
215 SDL_modelist[i]->w, SDL_modelist[i]->h);
216 #endif 197 #endif
217 198
218 /* find the matching size entry index */ 199 /* find the matching size entry index */
219 for ( size_id = 0; size_id < nsizes; ++size_id ) { 200 for (size_id = 0; size_id < nsizes; ++size_id) {
220 if ( (sizes[size_id].width == SDL_modelist[i]->w) && 201 if ((sizes[size_id].width == mode.w) &&
221 (sizes[size_id].height == SDL_modelist[i]->h) ) 202 (sizes[size_id].height == mode.h))
222 break; 203 break;
223 } 204 }
224 205
225 XRRSetScreenConfig(SDL_Display, screen_config, SDL_Root, 206 XRRSetScreenConfig (SDL_Display, screen_config,
226 size_id, saved_rotation, CurrentTime); 207 SDL_Root, size_id, saved_rotation,
208 CurrentTime);
227 } 209 }
228 } 210 }
229 } 211 }
230 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ 212 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
231 } 213 }
232 214
233 static void get_real_resolution(_THIS, int* w, int* h) 215 static void
216 get_real_resolution (_THIS, int *w, int *h)
234 { 217 {
235 #if SDL_VIDEO_DRIVER_X11_XME 218 #if SDL_VIDEO_DRIVER_X11_XME
236 if ( use_xme ) { 219 if (use_xme) {
237 int ractive; 220 int ractive;
238 XiGMiscResolutionInfo *modelist; 221 XiGMiscResolutionInfo *modelist;
239 222
240 XiGMiscQueryResolutions(SDL_Display, SDL_Screen, 223 XiGMiscQueryResolutions (SDL_Display, SDL_Screen, 0, /* view */
241 0, /* view */ 224 &ractive, &modelist);
242 &ractive, &modelist);
243 *w = modelist[ractive].width; 225 *w = modelist[ractive].width;
244 *h = modelist[ractive].height; 226 *h = modelist[ractive].height;
245 #ifdef X11MODES_DEBUG 227 #ifdef X11MODES_DEBUG
246 fprintf(stderr, "XME: get_real_resolution: w = %d h = %d\n", *w, *h); 228 fprintf (stderr, "XME: get_real_resolution: w = %d h = %d\n", *w, *h);
247 #endif 229 #endif
248 XFree(modelist); 230 XFree (modelist);
249 return; 231 return;
250 } 232 }
251 #endif /* SDL_VIDEO_DRIVER_X11_XME */ 233 #endif /* SDL_VIDEO_DRIVER_X11_XME */
252 234
253 #if SDL_VIDEO_DRIVER_X11_VIDMODE 235 #if SDL_VIDEO_DRIVER_X11_VIDMODE
254 if ( use_vidmode ) { 236 if (use_vidmode) {
255 SDL_NAME(XF86VidModeModeLine) mode; 237 SDL_NAME (XF86VidModeModeLine) mode;
256 int unused; 238 int unused;
257 239
258 if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &unused, &mode) ) { 240 if (SDL_NAME (XF86VidModeGetModeLine)
241 (SDL_Display, SDL_Screen, &unused, &mode)) {
259 *w = mode.hdisplay; 242 *w = mode.hdisplay;
260 *h = mode.vdisplay; 243 *h = mode.vdisplay;
261 return; 244 return;
262 } 245 }
263 } 246 }
264 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ 247 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
265 248
266 #if SDL_VIDEO_DRIVER_X11_XRANDR 249 #if SDL_VIDEO_DRIVER_X11_XRANDR
267 if ( use_xrandr ) { 250 if (use_xrandr) {
268 int nsizes; 251 int nsizes;
269 XRRScreenSize* sizes; 252 XRRScreenSize *sizes;
270 253
271 sizes = XRRConfigSizes(screen_config, &nsizes); 254 sizes = XRRConfigSizes (screen_config, &nsizes);
272 if ( nsizes > 0 ) { 255 if (nsizes > 0) {
273 int cur_size; 256 int cur_size;
274 Rotation cur_rotation; 257 Rotation cur_rotation;
275 258
276 cur_size = XRRConfigCurrentConfiguration(screen_config, &cur_rotation); 259 cur_size =
277 if ( cur_size >= 0 && cur_size < nsizes ) { 260 XRRConfigCurrentConfiguration (screen_config, &cur_rotation);
261 if (cur_size >= 0 && cur_size < nsizes) {
278 *w = sizes[cur_size].width; 262 *w = sizes[cur_size].width;
279 *h = sizes[cur_size].height; 263 *h = sizes[cur_size].height;
280 } 264 }
281 #ifdef X11MODES_DEBUG 265 #ifdef X11MODES_DEBUG
282 fprintf(stderr, "XRANDR: get_real_resolution: w = %d h = %d\n", *w, *h); 266 fprintf (stderr,
267 "XRANDR: get_real_resolution: w = %d h = %d\n", *w, *h);
283 #endif 268 #endif
284 return; 269 return;
285 } 270 }
286 } 271 }
287 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ 272 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
288 273
289 #if SDL_VIDEO_DRIVER_X11_XINERAMA 274 #if SDL_VIDEO_DRIVER_X11_XINERAMA
290 if ( use_xinerama ) { 275 if (use_xinerama) {
291 *w = xinerama_info.width; 276 *w = xinerama[this->current_display].width;
292 *h = xinerama_info.height; 277 *h = xinerama[this->current_display].height;
293 return; 278 return;
294 } 279 }
295 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ 280 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
296 281
297 *w = DisplayWidth(SDL_Display, SDL_Screen); 282 *w = DisplayWidth (SDL_Display, SDL_Screen);
298 *h = DisplayHeight(SDL_Display, SDL_Screen); 283 *h = DisplayHeight (SDL_Display, SDL_Screen);
299 } 284 }
300 285
301 /* Called after mapping a window - waits until the window is mapped */ 286 /* Called after mapping a window - waits until the window is mapped */
302 void X11_WaitMapped(_THIS, Window win) 287 void
288 X11_WaitMapped (_THIS, Window win)
303 { 289 {
304 XEvent event; 290 XEvent event;
305 do { 291 do {
306 XMaskEvent(SDL_Display, StructureNotifyMask, &event); 292 XMaskEvent (SDL_Display, StructureNotifyMask, &event);
307 } while ( (event.type != MapNotify) || (event.xmap.event != win) ); 293 }
294 while ((event.type != MapNotify) || (event.xmap.event != win));
308 } 295 }
309 296
310 /* Called after unmapping a window - waits until the window is unmapped */ 297 /* Called after unmapping a window - waits until the window is unmapped */
311 void X11_WaitUnmapped(_THIS, Window win) 298 void
299 X11_WaitUnmapped (_THIS, Window win)
312 { 300 {
313 XEvent event; 301 XEvent event;
314 do { 302 do {
315 XMaskEvent(SDL_Display, StructureNotifyMask, &event); 303 XMaskEvent (SDL_Display, StructureNotifyMask, &event);
316 } while ( (event.type != UnmapNotify) || (event.xunmap.event != win) ); 304 }
317 } 305 while ((event.type != UnmapNotify) || (event.xunmap.event != win));
318 306 }
319 static void move_cursor_to(_THIS, int x, int y) 307
320 { 308 static void
321 XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y); 309 move_cursor_to (_THIS, int x, int y)
322 } 310 {
323 311 XWarpPointer (SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y);
324 static int add_visual(_THIS, int depth, int class) 312 }
313
314 static int
315 add_visual (_THIS, int depth, int class)
325 { 316 {
326 XVisualInfo vi; 317 XVisualInfo vi;
327 if(XMatchVisualInfo(SDL_Display, SDL_Screen, depth, class, &vi)) { 318 if (XMatchVisualInfo (SDL_Display, SDL_Screen, depth, class, &vi)) {
328 int n = this->hidden->nvisuals; 319 int n = this->hidden->nvisuals;
329 this->hidden->visuals[n].depth = vi.depth; 320 this->hidden->visuals[n].depth = vi.depth;
330 this->hidden->visuals[n].visual = vi.visual; 321 this->hidden->visuals[n].visual = vi.visual;
331 this->hidden->nvisuals++; 322 this->hidden->nvisuals++;
332 } 323 }
333 return(this->hidden->nvisuals); 324 return (this->hidden->nvisuals);
334 } 325 }
335 static int add_visual_byid(_THIS, const char *visual_id) 326 static int
327 add_visual_byid (_THIS, const char *visual_id)
336 { 328 {
337 XVisualInfo *vi, template; 329 XVisualInfo *vi, template;
338 int nvis; 330 int nvis;
339 331
340 if ( visual_id ) { 332 if (visual_id) {
341 SDL_memset(&template, 0, (sizeof template)); 333 SDL_memset (&template, 0, (sizeof template));
342 template.visualid = SDL_strtol(visual_id, NULL, 0); 334 template.visualid = SDL_strtol (visual_id, NULL, 0);
343 vi = XGetVisualInfo(SDL_Display, VisualIDMask, &template, &nvis); 335 vi = XGetVisualInfo (SDL_Display, VisualIDMask, &template, &nvis);
344 if ( vi ) { 336 if (vi) {
345 int n = this->hidden->nvisuals; 337 int n = this->hidden->nvisuals;
346 this->hidden->visuals[n].depth = vi->depth; 338 this->hidden->visuals[n].depth = vi->depth;
347 this->hidden->visuals[n].visual = vi->visual; 339 this->hidden->visuals[n].visual = vi->visual;
348 this->hidden->nvisuals++; 340 this->hidden->nvisuals++;
349 XFree(vi); 341 XFree (vi);
350 } 342 }
351 } 343 }
352 return(this->hidden->nvisuals); 344 return (this->hidden->nvisuals);
345 }
346
347 int
348 X11_GetVisuals (_THIS)
349 {
350 /* It's interesting to note that if we allow 32 bit depths,
351 we get a visual with an alpha mask on composite servers.
352 static int depth_list[] = { 32, 24, 16, 15, 8 };
353 */
354 static int depth_list[] = { 24, 16, 15, 8 };
355 int i, j, np;
356 int use_directcolor = 1;
357 XPixmapFormatValues *pf;
358
359 /* Search for the visuals in deepest-first order, so that the first
360 will be the richest one */
361 if (SDL_getenv ("SDL_VIDEO_X11_NODIRECTCOLOR")) {
362 use_directcolor = 0;
363 }
364 this->hidden->nvisuals = 0;
365 if (!add_visual_byid (this, SDL_getenv ("SDL_VIDEO_X11_VISUALID"))) {
366 for (i = 0; i < SDL_arraysize (depth_list); ++i) {
367 if (depth_list[i] > 8) {
368 if (use_directcolor) {
369 add_visual (this, depth_list[i], DirectColor);
370 }
371 add_visual (this, depth_list[i], TrueColor);
372 } else {
373 add_visual (this, depth_list[i], PseudoColor);
374 add_visual (this, depth_list[i], StaticColor);
375 }
376 }
377 }
378 if (this->hidden->nvisuals == 0) {
379 SDL_SetError ("Found no sufficiently capable X11 visuals");
380 return -1;
381 }
382
383 /* look up the pixel quantum for each depth */
384 pf = XListPixmapFormats (SDL_Display, &np);
385 for (i = 0; i < this->hidden->nvisuals; i++) {
386 int d = this->hidden->visuals[i].depth;
387 for (j = 0; j < np; j++)
388 if (pf[j].depth == d)
389 break;
390 this->hidden->visuals[i].bpp = j < np ? pf[j].bits_per_pixel : d;
391 }
392
393 XFree (pf);
394 return 0;
353 } 395 }
354 396
355 /* Global for the error handler */ 397 /* Global for the error handler */
356 int vm_event, vm_error = -1; 398 int vm_event, vm_error = -1;
357 399
358 #if SDL_VIDEO_DRIVER_X11_XINERAMA 400 #if SDL_VIDEO_DRIVER_X11_XINERAMA
359 static int CheckXinerama(_THIS, int *major, int *minor) 401 static int
402 CheckXinerama (_THIS, int *major, int *minor)
360 { 403 {
361 const char *env; 404 const char *env;
362 405
363 /* Default the extension not available */ 406 /* Default the extension not available */
364 *major = *minor = 0; 407 *major = *minor = 0;
365 408
366 /* Allow environment override */ 409 /* Allow environment override */
367 env = getenv("SDL_VIDEO_X11_XINERAMA"); 410 env = getenv ("SDL_VIDEO_X11_XINERAMA");
368 if ( env && !SDL_atoi(env) ) { 411 if (env && !SDL_atoi (env)) {
369 return 0; 412 return 0;
370 } 413 }
371 414
372 /* Query the extension version */ 415 /* Query the extension version */
373 if ( !SDL_NAME(XineramaQueryExtension)(SDL_Display, major, minor) || 416 if (!SDL_NAME (XineramaQueryExtension) (SDL_Display, major, minor) ||
374 !SDL_NAME(XineramaIsActive)(SDL_Display) ) { 417 !SDL_NAME (XineramaIsActive) (SDL_Display)) {
375 return 0; 418 return 0;
376 } 419 }
377 return 1; 420 return 1;
378 } 421 }
379 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ 422 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
380 423
381 #if SDL_VIDEO_DRIVER_X11_XRANDR 424 #if SDL_VIDEO_DRIVER_X11_XRANDR
382 static int CheckXRandR(_THIS, int *major, int *minor) 425 static int
426 CheckXRandR (_THIS, int *major, int *minor)
383 { 427 {
384 const char *env; 428 const char *env;
385 429
386 /* Default the extension not available */ 430 /* Default the extension not available */
387 *major = *minor = 0; 431 *major = *minor = 0;
388 432
389 /* Allow environment override */ 433 /* Allow environment override */
390 env = getenv("SDL_VIDEO_X11_XRANDR"); 434 env = getenv ("SDL_VIDEO_X11_XRANDR");
391 if ( env && !SDL_atoi(env) ) { 435 if (env && !SDL_atoi (env)) {
392 return 0; 436 return 0;
393 } 437 }
394 438
395 /* This defaults off now, due to KDE window maximize problems */ 439 /* This defaults off now, due to KDE window maximize problems */
396 if ( !env ) { 440 if (!env) {
397 return 0; 441 return 0;
398 } 442 }
399 443
400 if ( !SDL_X11_HAVE_XRANDR ) { 444 if (!SDL_X11_HAVE_XRANDR) {
401 return 0; 445 return 0;
402 } 446 }
403 447
404 /* Query the extension version */ 448 /* Query the extension version */
405 if ( !XRRQueryVersion(SDL_Display, major, minor) ) { 449 if (!XRRQueryVersion (SDL_Display, major, minor)) {
406 return 0; 450 return 0;
407 } 451 }
408 return 1; 452 return 1;
409 } 453 }
410 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ 454 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
411 455
412 #if SDL_VIDEO_DRIVER_X11_VIDMODE 456 #if SDL_VIDEO_DRIVER_X11_VIDMODE
413 static int CheckVidMode(_THIS, int *major, int *minor) 457 static int
458 CheckVidMode (_THIS, int *major, int *minor)
414 { 459 {
415 const char *env; 460 const char *env;
416 461
417 /* Default the extension not available */ 462 /* Default the extension not available */
418 *major = *minor = 0; 463 *major = *minor = 0;
419 464
420 /* Allow environment override */ 465 /* Allow environment override */
421 env = getenv("SDL_VIDEO_X11_VIDMODE"); 466 env = getenv ("SDL_VIDEO_X11_VIDMODE");
422 if ( env && !SDL_atoi(env) ) { 467 if (env && !SDL_atoi (env)) {
423 return 0; 468 return 0;
424 } 469 }
425 470
426 /* Metro-X 4.3.0 and earlier has a broken implementation of 471 /* Metro-X 4.3.0 and earlier has a broken implementation of
427 XF86VidModeGetAllModeLines() - it hangs the client. 472 XF86VidModeGetAllModeLines() - it hangs the client.
428 */ 473 */
429 if ( SDL_strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) { 474 if (SDL_strcmp (ServerVendor (SDL_Display), "Metro Link Incorporated") ==
475 0) {
430 FILE *metro_fp; 476 FILE *metro_fp;
431 477
432 metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r"); 478 metro_fp = fopen ("/usr/X11R6/lib/X11/Metro/.version", "r");
433 if ( metro_fp != NULL ) { 479 if (metro_fp != NULL) {
434 int major, minor, patch, version; 480 int major, minor, patch, version;
435 major = 0; minor = 0; patch = 0; 481 major = 0;
436 fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch); 482 minor = 0;
437 fclose(metro_fp); 483 patch = 0;
438 version = major*100+minor*10+patch; 484 fscanf (metro_fp, "%d.%d.%d", &major, &minor, &patch);
439 if ( version < 431 ) { 485 fclose (metro_fp);
486 version = major * 100 + minor * 10 + patch;
487 if (version < 431) {
440 return 0; 488 return 0;
441 } 489 }
442 } 490 }
443 } 491 }
444 492
445 /* Query the extension version */ 493 /* Query the extension version */
446 vm_error = -1; 494 vm_error = -1;
447 if ( !SDL_NAME(XF86VidModeQueryExtension)(SDL_Display, &vm_event, &vm_error) || 495 if (!SDL_NAME (XF86VidModeQueryExtension)
448 !SDL_NAME(XF86VidModeQueryVersion)(SDL_Display, major, minor) ) { 496 (SDL_Display, &vm_event, &vm_error)
497 || !SDL_NAME (XF86VidModeQueryVersion) (SDL_Display, major, minor)) {
449 return 0; 498 return 0;
450 } 499 }
451 return 1; 500 return 1;
452 } 501 }
453 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ 502 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
454 503
455 #if SDL_VIDEO_DRIVER_X11_XME 504 #if SDL_VIDEO_DRIVER_X11_XME
456 static int CheckXME(_THIS, int *major, int *minor) 505 static int
506 CheckXME (_THIS, int *major, int *minor)
457 { 507 {
458 const char *env; 508 const char *env;
459 509
460 /* Default the extension not available */ 510 /* Default the extension not available */
461 *major = *minor = 0; 511 *major = *minor = 0;
462 512
463 /* Allow environment override */ 513 /* Allow environment override */
464 env = getenv("SDL_VIDEO_X11_VIDMODE"); 514 env = getenv ("SDL_VIDEO_X11_VIDMODE");
465 if ( env && !SDL_atoi(env) ) { 515 if (env && !SDL_atoi (env)) {
466 return 0; 516 return 0;
467 } 517 }
468 518
469 /* Query the extension version */ 519 /* Query the extension version */
470 if ( !XiGMiscQueryVersion(SDL_Display, major, minor) ) { 520 if (!XiGMiscQueryVersion (SDL_Display, major, minor)) {
471 return 0; 521 return 0;
472 } 522 }
473 return 1; 523 return 1;
474 } 524 }
475 #endif /* SDL_VIDEO_DRIVER_X11_XME */ 525 #endif /* SDL_VIDEO_DRIVER_X11_XME */
476 526
477 int X11_GetVideoModes(_THIS) 527 int
528 X11_GetVideoModes (_THIS)
478 { 529 {
479 #if SDL_VIDEO_DRIVER_X11_XINERAMA 530 #if SDL_VIDEO_DRIVER_X11_XINERAMA
480 int xinerama_major, xinerama_minor; 531 int xinerama_major, xinerama_minor;
481 #endif 532 #endif
482 #if SDL_VIDEO_DRIVER_X11_XRANDR 533 #if SDL_VIDEO_DRIVER_X11_XRANDR
483 int xrandr_major, xrandr_minor; 534 int xrandr_major, xrandr_minor;
484 int nsizes; 535 int nsizes;
485 XRRScreenSize *sizes; 536 XRRScreenSize *sizes;
537 int nrates;
538 short *rates;
486 #endif 539 #endif
487 #if SDL_VIDEO_DRIVER_X11_VIDMODE 540 #if SDL_VIDEO_DRIVER_X11_VIDMODE
488 int vm_major, vm_minor; 541 int vm_major, vm_minor;
489 int nmodes; 542 int nmodes;
490 SDL_NAME(XF86VidModeModeInfo) **modes; 543 SDL_NAME (XF86VidModeModeInfo) ** modes;
491 #endif 544 #endif
492 #if SDL_VIDEO_DRIVER_X11_XME 545 #if SDL_VIDEO_DRIVER_X11_XME
493 int xme_major, xme_minor; 546 int xme_major, xme_minor;
494 int ractive, nummodes; 547 int ractive, nummodes;
495 XiGMiscResolutionInfo *modelist; 548 XiGMiscResolutionInfo *modelist;
496 #endif 549 #endif
497 int i, n; 550 int i;
498 int screen_w; 551 int screen_w;
499 int screen_h; 552 int screen_h;
553 SDL_DisplayMode mode;
500 554
501 use_xinerama = 0; 555 use_xinerama = 0;
502 use_xrandr = 0; 556 use_xrandr = 0;
503 use_vidmode = 0; 557 use_vidmode = 0;
504 use_xme = 0; 558 use_xme = 0;
505 screen_w = DisplayWidth(SDL_Display, SDL_Screen); 559 screen_w = DisplayWidth (SDL_Display, SDL_Screen);
506 screen_h = DisplayHeight(SDL_Display, SDL_Screen); 560 screen_h = DisplayHeight (SDL_Display, SDL_Screen);
561
562 mode.format = this->displays[this->current_display].desktop_mode.format;
563 mode.w = screen_w;
564 mode.h = screen_h;
565 mode.refresh_rate = 0;
566 SDL_AddDisplayMode (0, &mode);
507 567
508 #if SDL_VIDEO_DRIVER_X11_XINERAMA 568 #if SDL_VIDEO_DRIVER_X11_XINERAMA
509 /* Query Xinerama extention */ 569 /* Query Xinerama extention */
510 if ( CheckXinerama(this, &xinerama_major, &xinerama_minor) ) { 570 if (CheckXinerama (this, &xinerama_major, &xinerama_minor)) {
511 /* Find out which screen is the desired one */
512 int desired = 0;
513 int screens; 571 int screens;
514 int w, h; 572
515 SDL_NAME(XineramaScreenInfo) *xinerama; 573 #ifdef X11MODES_DEBUG
516 574 printf ("X11 detected Xinerama:\n");
517 const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD"); 575 #endif
518 if ( variable ) { 576 xinerama = SDL_NAME (XineramaQueryScreens) (SDL_Display, &screens);
519 desired = SDL_atoi(variable); 577 for (i = 0; i < screens; i++) {
520 } 578 #ifdef X11MODES_DEBUG
521 #ifdef X11MODES_DEBUG 579 printf ("xinerama %d: %dx%d+%d+%d\n",
522 printf("X11 detected Xinerama:\n"); 580 xinerama[i].screen_number,
523 #endif 581 xinerama[i].width, xinerama[i].height,
524 xinerama = SDL_NAME(XineramaQueryScreens)(SDL_Display, &screens); 582 xinerama[i].x_org, xinerama[i].y_org);
525 for ( i = 0; i < screens; i++ ) { 583 #endif
526 #ifdef X11MODES_DEBUG 584 if (xinerama[i].screen_number != 0) {
527 printf("xinerama %d: %dx%d+%d+%d\n", 585 SDL_AddVideoDisplay (&mode);
528 xinerama[i].screen_number, 586 }
529 xinerama[i].width, xinerama[i].height, 587 mode.w = xinerama[i].width;
530 xinerama[i].x_org, xinerama[i].y_org); 588 mode.h = xinerama[i].height;
531 #endif 589 SDL_AddDisplayMode (xinerama[i].screen_number, &mode);
532 if ( xinerama[i].screen_number == desired ) { 590 }
533 use_xinerama = 1; 591 use_xinerama = 1;
534 xinerama_info = xinerama[i];
535 }
536 }
537 XFree(xinerama);
538
539 if ( use_xinerama ) {
540 SDL_modelist = (SDL_Rect **)SDL_malloc(3*sizeof(SDL_Rect *));
541 if ( !SDL_modelist ) {
542 SDL_OutOfMemory();
543 return -1;
544 }
545
546 /* Add the full xinerama mode */
547 n = 0;
548 w = xinerama_info.width;
549 h = xinerama_info.height;
550 if ( screen_w > w || screen_h > h) {
551 SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
552 if ( SDL_modelist[n] ) {
553 SDL_modelist[n]->x = 0;
554 SDL_modelist[n]->y = 0;
555 SDL_modelist[n]->w = screen_w;
556 SDL_modelist[n]->h = screen_h;
557 ++n;
558 }
559 }
560
561 /* Add the head xinerama mode */
562 SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
563 if ( SDL_modelist[n] ) {
564 SDL_modelist[n]->x = 0;
565 SDL_modelist[n]->y = 0;
566 SDL_modelist[n]->w = w;
567 SDL_modelist[n]->h = h;
568 ++n;
569 }
570 SDL_modelist[n] = NULL;
571 }
572 } 592 }
573 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ 593 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
574 594
575 #if SDL_VIDEO_DRIVER_X11_XRANDR 595 #if SDL_VIDEO_DRIVER_X11_XRANDR
576 /* XRandR */ 596 /* XRandR */
577 /* require at least XRandR v1.0 (arbitrary) */ 597 /* require at least XRandR v1.0 (arbitrary) */
578 if ( CheckXRandR(this, &xrandr_major, &xrandr_minor) && (xrandr_major >= 1) ) 598 if (CheckXRandR (this, &xrandr_major, &xrandr_minor)
579 { 599 && (xrandr_major >= 1)) {
580 #ifdef X11MODES_DEBUG 600 #ifdef X11MODES_DEBUG
581 fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n", 601 fprintf (stderr, "XRANDR: XRRQueryVersion: V%d.%d\n",
582 xrandr_major, xrandr_minor); 602 xrandr_major, xrandr_minor);
583 #endif 603 #endif
584 604
585 /* save the screen configuration since we must reference it 605 /* save the screen configuration since we must reference it
586 each time we toggle modes. 606 each time we toggle modes.
587 */ 607 */
588 screen_config = XRRGetScreenInfo(SDL_Display, SDL_Root); 608 screen_config = XRRGetScreenInfo (SDL_Display, SDL_Root);
589 609
590 /* retrieve the list of resolution */ 610 /* retrieve the list of resolution */
591 sizes = XRRConfigSizes(screen_config, &nsizes); 611 sizes = XRRConfigSizes (screen_config, &nsizes);
592 if (nsizes > 0) { 612 if (nsizes > 0) {
593 if ( SDL_modelist ) { 613 for (i = 0; i < nsizes; i++) {
594 for ( i = 0; SDL_modelist[i]; ++i ) { 614 mode.w = sizes[i].width;
595 SDL_free(SDL_modelist[i]); 615 mode.h = sizes[i].height;
596 } 616
597 SDL_free(SDL_modelist); 617 rates = XRRConfigRates (screen_config, i, &nrates);
598 } 618 if (nrates == 0) {
599 SDL_modelist = (SDL_Rect **)malloc((nsizes+1)*sizeof(SDL_Rect *)); 619 mode.refresh_rate = 0;
600 if ( !SDL_modelist ) { 620 SDL_AddDisplayMode (0, &mode);
601 SDL_OutOfMemory(); 621 } else {
602 return -1; 622 int j;
603 } 623 for (j = 0; j < nrates; ++j) {
604 for ( i=0; i < nsizes; i++ ) { 624 mode.refresh_rate = rates[j];
605 if ((SDL_modelist[i] = 625 SDL_AddDisplayMode (0, &mode);
606 (SDL_Rect *)malloc(sizeof(SDL_Rect))) == NULL)
607 break;
608 #ifdef X11MODES_DEBUG
609 fprintf(stderr, "XRANDR: mode = %4d, w = %4d, h = %4d\n",
610 i, sizes[i].width, sizes[i].height);
611 #endif
612
613 SDL_modelist[i]->x = 0;
614 SDL_modelist[i]->y = 0;
615 SDL_modelist[i]->w = sizes[i].width;
616 SDL_modelist[i]->h = sizes[i].height;
617
618 }
619 /* sort the mode list descending as SDL expects */
620 SDL_qsort(SDL_modelist, nsizes, sizeof *SDL_modelist, cmpmodelist);
621 SDL_modelist[i] = NULL; /* terminator */
622
623 use_xrandr = xrandr_major * 100 + xrandr_minor;
624 saved_size_id = XRRConfigCurrentConfiguration(screen_config, &saved_rotation);
625 }
626 }
627 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
628
629 #if SDL_VIDEO_DRIVER_X11_VIDMODE
630 /* XVidMode */
631 if ( !use_xrandr &&
632 (!use_xinerama || xinerama_info.screen_number == 0) &&
633 CheckVidMode(this, &vm_major, &vm_minor) &&
634 SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) )
635 {
636 #ifdef X11MODES_DEBUG
637 printf("VidMode modes: (unsorted)\n");
638 for ( i = 0; i < nmodes; ++i ) {
639 printf("Mode %d: %d x %d @ %d\n", i,
640 modes[i]->hdisplay, modes[i]->vdisplay,
641 (modes[i]->htotal && modes[i]->vtotal) ? (1000 * modes[i]->dotclock / (modes[i]->htotal * modes[i]->vtotal)) : 0 );
642 }
643 #endif
644 if ( SDL_modelist ) {
645 for ( i = 0; SDL_modelist[i]; ++i ) {
646 SDL_free(SDL_modelist[i]);
647 }
648 SDL_free(SDL_modelist);
649 }
650 SDL_modelist = (SDL_Rect **)SDL_malloc((nmodes+2)*sizeof(SDL_Rect *));
651 if ( !SDL_modelist ) {
652 SDL_OutOfMemory();
653 return -1;
654 }
655 SDL_qsort(modes, nmodes, sizeof *modes, cmpmodes);
656 n = 0;
657 for ( i=0; i<nmodes; ++i ) {
658 int w, h;
659
660 /* Eliminate duplicate modes with different refresh rates */
661 if ( i > 0 &&
662 modes[i]->hdisplay == modes[i-1]->hdisplay &&
663 modes[i]->vdisplay == modes[i-1]->vdisplay ) {
664 continue;
665 }
666
667 /* Check to see if we should add the screen size (Xinerama) */
668 w = modes[i]->hdisplay;
669 h = modes[i]->vdisplay;
670 if ( (screen_w * screen_h) >= (w * h) ) {
671 if ( (screen_w != w) || (screen_h != h) ) {
672 SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
673 if ( SDL_modelist[n] ) {
674 SDL_modelist[n]->x = 0;
675 SDL_modelist[n]->y = 0;
676 SDL_modelist[n]->w = screen_w;
677 SDL_modelist[n]->h = screen_h;
678 ++n;
679 } 626 }
680 } 627 }
681 screen_w = 0; 628 }
682 screen_h = 0; 629
683 } 630 use_xrandr = xrandr_major * 100 + xrandr_minor;
684 631 saved_size_id =
685 /* Add the size from the video mode list */ 632 XRRConfigCurrentConfiguration (screen_config,
686 SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); 633 &saved_rotation);
687 if ( SDL_modelist[n] == NULL ) { 634 }
688 break; 635 }
689 } 636 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
690 SDL_modelist[n]->x = 0; 637
691 SDL_modelist[n]->y = 0; 638 #if SDL_VIDEO_DRIVER_X11_VIDMODE
692 SDL_modelist[n]->w = w; 639 /* XVidMode */
693 SDL_modelist[n]->h = h; 640 if (!use_xrandr &&
694 ++n; 641 CheckVidMode (this, &vm_major, &vm_minor) &&
695 } 642 SDL_NAME (XF86VidModeGetAllModeLines) (SDL_Display, SDL_Screen,
696 SDL_modelist[n] = NULL; 643 &nmodes, &modes)) {
697 XFree(modes); 644 #ifdef X11MODES_DEBUG
645 printf ("VidMode modes: (unsorted)\n");
646 for (i = 0; i < nmodes; ++i) {
647 printf ("Mode %d: %d x %d @ %d\n", i,
648 modes[i]->hdisplay, modes[i]->vdisplay,
649 vidmode_refreshrate (modes[i]));
650 }
651 #endif
652 for (i = 0; i < nmodes; ++i) {
653 mode.w = modes[i]->hdisplay;
654 mode.h = modes[i]->vdisplay;
655 mode.refresh_rate = vidmode_refreshrate (modes[i]);
656 SDL_AddDisplayMode (0, &mode);
657 }
658 XFree (modes);
698 659
699 use_vidmode = vm_major * 100 + vm_minor; 660 use_vidmode = vm_major * 100 + vm_minor;
700 save_mode(this); 661 save_mode (this);
701 } 662 }
702 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ 663 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
703 664
704 #if SDL_VIDEO_DRIVER_X11_XME 665 #if SDL_VIDEO_DRIVER_X11_XME
705 /* XiG */ 666 /* XiG */
706 modelist = NULL; 667 modelist = NULL;
707 /* first lets make sure we have the extension, and it's at least v2.0 */ 668 /* first lets make sure we have the extension, and it's at least v2.0 */
708 if ( CheckXME(this, &xme_major, &xme_minor) && xme_major >= 2 && 669 if (CheckXME (this, &xme_major, &xme_minor) && xme_major >= 2 && (nummodes = XiGMiscQueryResolutions (SDL_Display, SDL_Screen, 0, /* view */
709 (nummodes = XiGMiscQueryResolutions(SDL_Display, SDL_Screen, 670 &ractive,
710 0, /* view */ 671 &modelist))
711 &ractive, &modelist)) > 1 ) 672 > 1) { /* then we actually have some */
712 { /* then we actually have some */
713 int j;
714
715 /* We get the list already sorted in descending order. 673 /* We get the list already sorted in descending order.
716 We'll copy it in reverse order so SDL is happy */ 674 We'll copy it in reverse order so SDL is happy */
717 #ifdef X11MODES_DEBUG 675 #ifdef X11MODES_DEBUG
718 fprintf(stderr, "XME: nummodes = %d, active mode = %d\n", 676 fprintf (stderr, "XME: nummodes = %d, active mode = %d\n",
719 nummodes, ractive); 677 nummodes, ractive);
720 #endif 678 #endif
721 if ( SDL_modelist ) { 679 mode.refresh_rate = 0;
722 for ( i = 0; SDL_modelist[i]; ++i ) { 680 for (i = 0; i < nummodes; ++i) {
723 SDL_free(SDL_modelist[i]); 681 #ifdef X11MODES_DEBUG
724 } 682 fprintf (stderr, "XME: mode = %4d, w = %4d, h = %4d\n",
725 SDL_free(SDL_modelist); 683 i, modelist[i].width, modelist[i].height);
726 } 684 #endif
727 SDL_modelist = (SDL_Rect **)SDL_malloc((nummodes+1)*sizeof(SDL_Rect *)); 685 mode.w = modelist[i].width;
728 if ( !SDL_modelist ) { 686 mode.h = modelist[i].height;
729 SDL_OutOfMemory(); 687 SDL_AddDisplayMode (0, &mode);
730 return -1; 688 }
731 }
732 for ( i=0, j=nummodes-1; j>=0; i++, j-- ) {
733 if ((SDL_modelist[i] =
734 (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect))) == NULL)
735 break;
736 #ifdef X11MODES_DEBUG
737 fprintf(stderr, "XME: mode = %4d, w = %4d, h = %4d\n",
738 i, modelist[i].width, modelist[i].height);
739 #endif
740
741 SDL_modelist[i]->x = 0;
742 SDL_modelist[i]->y = 0;
743 SDL_modelist[i]->w = modelist[j].width;
744 SDL_modelist[i]->h = modelist[j].height;
745
746 }
747 SDL_modelist[i] = NULL; /* terminator */
748 689
749 use_xme = xme_major * 100 + xme_minor; 690 use_xme = xme_major * 100 + xme_minor;
750 saved_res = modelist[ractive]; /* save the current resolution */ 691 saved_res = modelist[ractive]; /* save the current resolution */
751 } 692 }
752 if ( modelist ) { 693 if (modelist) {
753 XFree(modelist); 694 XFree (modelist);
754 } 695 }
755 #endif /* SDL_VIDEO_DRIVER_X11_XME */ 696 #endif /* SDL_VIDEO_DRIVER_X11_XME */
756 697
757 { 698 #ifdef X11MODES_DEBUG
758 /* It's interesting to note that if we allow 32 bit depths, 699 if (use_xinerama) {
759 we get a visual with an alpha mask on composite servers. 700 printf ("Xinerama is enabled\n");
760 static int depth_list[] = { 32, 24, 16, 15, 8 }; 701 }
761 */ 702
762 static int depth_list[] = { 24, 16, 15, 8 }; 703 if (use_xrandr) {
763 int j, np; 704 printf ("XRandR is enabled\n");
764 int use_directcolor = 1; 705 }
765 XPixmapFormatValues *pf; 706
766 707 if (use_vidmode) {
767 /* Search for the visuals in deepest-first order, so that the first 708 printf ("VidMode is enabled\n");
768 will be the richest one */ 709 }
769 if ( SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) { 710
770 use_directcolor = 0; 711 if (use_xme) {
771 } 712 printf ("Xi Graphics XME fullscreen is enabled\n");
772 this->hidden->nvisuals = 0;
773 if ( ! add_visual_byid(this, SDL_getenv("SDL_VIDEO_X11_VISUALID")) ) {
774 for ( i=0; i<SDL_arraysize(depth_list); ++i ) {
775 if ( depth_list[i] > 8 ) {
776 if ( use_directcolor ) {
777 add_visual(this, depth_list[i], DirectColor);
778 }
779 add_visual(this, depth_list[i], TrueColor);
780 } else {
781 add_visual(this, depth_list[i], PseudoColor);
782 add_visual(this, depth_list[i], StaticColor);
783 }
784 }
785 }
786 if ( this->hidden->nvisuals == 0 ) {
787 SDL_SetError("Found no sufficiently capable X11 visuals");
788 return -1;
789 }
790
791 /* look up the pixel quantum for each depth */
792 pf = XListPixmapFormats(SDL_Display, &np);
793 for(i = 0; i < this->hidden->nvisuals; i++) {
794 int d = this->hidden->visuals[i].depth;
795 for(j = 0; j < np; j++)
796 if(pf[j].depth == d)
797 break;
798 this->hidden->visuals[i].bpp = j < np ? pf[j].bits_per_pixel : d;
799 }
800
801 XFree(pf);
802 }
803
804 if ( SDL_modelist == NULL ) {
805 SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *));
806 if ( !SDL_modelist ) {
807 SDL_OutOfMemory();
808 return -1;
809 }
810 n = 0;
811 SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
812 if ( SDL_modelist[n] ) {
813 SDL_modelist[n]->x = 0;
814 SDL_modelist[n]->y = 0;
815 SDL_modelist[n]->w = screen_w;
816 SDL_modelist[n]->h = screen_h;
817 ++n;
818 }
819 SDL_modelist[n] = NULL;
820 }
821
822 #ifdef X11MODES_DEBUG
823 if ( use_xinerama ) {
824 printf("Xinerama is enabled\n");
825 }
826
827 if ( use_xrandr ) {
828 printf("XRandR is enabled\n");
829 }
830
831 if ( use_vidmode ) {
832 printf("VidMode is enabled\n");
833 }
834
835 if ( use_xme ) {
836 printf("Xi Graphics XME fullscreen is enabled\n");
837 }
838
839 if ( SDL_modelist ) {
840 printf("X11 video mode list:\n");
841 for ( i=0; SDL_modelist[i]; ++i ) {
842 printf("\t%dx%d\n", SDL_modelist[i]->w, SDL_modelist[i]->h);
843 }
844 } 713 }
845 #endif /* X11MODES_DEBUG */ 714 #endif /* X11MODES_DEBUG */
846 715
847 return 0; 716 return 0;
848 } 717 }
849 718
850 int X11_SupportedVisual(_THIS, SDL_PixelFormat *format) 719 void
851 { 720 X11_FreeVideoModes (_THIS)
852 int i; 721 {
853 for(i = 0; i < this->hidden->nvisuals; i++)
854 if(this->hidden->visuals[i].bpp == format->BitsPerPixel)
855 return 1;
856 return 0;
857 }
858
859 SDL_Rect **X11_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
860 {
861 if ( X11_SupportedVisual(this, format) ) {
862 if ( flags & SDL_FULLSCREEN ) {
863 return(SDL_modelist);
864 } else {
865 return((SDL_Rect **)-1);
866 }
867 } else {
868 return((SDL_Rect **)0);
869 }
870 }
871
872 void X11_FreeVideoModes(_THIS)
873 {
874 int i;
875
876 if ( SDL_modelist ) {
877 for ( i=0; SDL_modelist[i]; ++i ) {
878 SDL_free(SDL_modelist[i]);
879 }
880 SDL_free(SDL_modelist);
881 SDL_modelist = NULL;
882 }
883
884 #if SDL_VIDEO_DRIVER_X11_XRANDR 722 #if SDL_VIDEO_DRIVER_X11_XRANDR
885 /* Free the Xrandr screen configuration */ 723 /* Free the Xrandr screen configuration */
886 if ( screen_config ) { 724 if (screen_config) {
887 XRRFreeScreenConfigInfo(screen_config); 725 XRRFreeScreenConfigInfo (screen_config);
888 screen_config = NULL; 726 screen_config = NULL;
889 } 727 }
890 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ 728 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
891 } 729 }
892 730
893 int X11_ResizeFullScreen(_THIS) 731 int
732 X11_ResizeFullScreen (_THIS)
894 { 733 {
895 int x = 0, y = 0; 734 int x = 0, y = 0;
896 int real_w, real_h; 735 int real_w, real_h;
897 int screen_w; 736 int screen_w;
898 int screen_h; 737 int screen_h;
899 738
900 screen_w = DisplayWidth(SDL_Display, SDL_Screen); 739 screen_w = DisplayWidth (SDL_Display, SDL_Screen);
901 screen_h = DisplayHeight(SDL_Display, SDL_Screen); 740 screen_h = DisplayHeight (SDL_Display, SDL_Screen);
902 741
903 #if SDL_VIDEO_DRIVER_X11_VIDMODE 742 #if SDL_VIDEO_DRIVER_X11_VIDMODE
904 if ( use_xinerama && 743 if (use_xinerama &&
905 window_w <= xinerama_info.width && 744 window_w <= xinerama[this->current_display].width &&
906 window_h <= xinerama_info.height ) { 745 window_h <= xinerama[this->current_display].height) {
907 x = xinerama_info.x_org; 746 x = xinerama[this->current_display].x_org;
908 y = xinerama_info.y_org; 747 y = xinerama[this->current_display].y_org;
909 } 748 }
910 #endif 749 #endif
911 if ( currently_fullscreen ) { 750 if (currently_fullscreen) {
912 /* Switch resolution and cover it with the FSwindow */ 751 /* Switch resolution and cover it with the FSwindow */
913 move_cursor_to(this, x, y); 752 move_cursor_to (this, x, y);
914 set_best_resolution(this, window_w, window_h); 753 set_best_resolution (this, window_w, window_h);
915 move_cursor_to(this, x, y); 754 move_cursor_to (this, x, y);
916 get_real_resolution(this, &real_w, &real_h); 755 get_real_resolution (this, &real_w, &real_h);
917 if ( window_w > real_w ) { 756 if (window_w > real_w) {
918 real_w = MAX(real_w, screen_w); 757 real_w = MAX (real_w, screen_w);
919 } 758 }
920 if ( window_h > real_h ) { 759 if (window_h > real_h) {
921 real_h = MAX(real_h, screen_h); 760 real_h = MAX (real_h, screen_h);
922 } 761 }
923 XMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h); 762 XMoveResizeWindow (SDL_Display, FSwindow, x, y, real_w, real_h);
924 move_cursor_to(this, real_w/2, real_h/2); 763 move_cursor_to (this, real_w / 2, real_h / 2);
925 764
926 /* Center and reparent the drawing window */ 765 /* Center and reparent the drawing window */
927 x = (real_w - window_w)/2; 766 x = (real_w - window_w) / 2;
928 y = (real_h - window_h)/2; 767 y = (real_h - window_h) / 2;
929 XReparentWindow(SDL_Display, SDL_Window, FSwindow, x, y); 768 XReparentWindow (SDL_Display, SDL_Window, FSwindow, x, y);
930 /* FIXME: move the mouse to the old relative location */ 769 /* FIXME: move the mouse to the old relative location */
931 XSync(SDL_Display, True); /* Flush spurious mode change events */ 770 XSync (SDL_Display, True); /* Flush spurious mode change events */
932 } 771 }
933 return(1); 772 return (1);
934 } 773 }
935 774
936 void X11_QueueEnterFullScreen(_THIS) 775 void
776 X11_QueueEnterFullScreen (_THIS)
937 { 777 {
938 switch_waiting = 0x01 | SDL_FULLSCREEN; 778 switch_waiting = 0x01 | SDL_FULLSCREEN;
939 switch_time = SDL_GetTicks() + 1500; 779 switch_time = SDL_GetTicks () + 1500;
940 #if 0 /* This causes a BadMatch error if the window is iconified (not needed) */ 780 #if 0 /* This causes a BadMatch error if the window is iconified (not needed) */
941 XSetInputFocus(SDL_Display, WMwindow, RevertToNone, CurrentTime); 781 XSetInputFocus (SDL_Display, WMwindow, RevertToNone, CurrentTime);
942 #endif 782 #endif
943 } 783 }
944 784
945 int X11_EnterFullScreen(_THIS) 785 int
786 X11_EnterFullScreen (_THIS)
946 { 787 {
947 int okay; 788 int okay;
948 #if 0 789 #if 0
949 Window tmpwin, *windows; 790 Window tmpwin, *windows;
950 int i, nwindows; 791 int i, nwindows;
953 int real_w, real_h; 794 int real_w, real_h;
954 int screen_w; 795 int screen_w;
955 int screen_h; 796 int screen_h;
956 797
957 okay = 1; 798 okay = 1;
958 if ( currently_fullscreen ) { 799 if (currently_fullscreen) {
959 return(okay); 800 return (okay);
960 } 801 }
961 802
962 /* Ungrab the input so that we can move the mouse around */ 803 /* Ungrab the input so that we can move the mouse around */
963 X11_GrabInputNoLock(this, SDL_GRAB_OFF); 804 X11_GrabInputNoLock (this, SDL_GRAB_OFF);
964 805
965 #if SDL_VIDEO_DRIVER_X11_VIDMODE 806 #if SDL_VIDEO_DRIVER_X11_VIDMODE
966 if ( use_xinerama && 807 if (use_xinerama &&
967 window_w <= xinerama_info.width && 808 window_w <= xinerama[this->current_display].width &&
968 window_h <= xinerama_info.height ) { 809 window_h <= xinerama[this->current_display].height) {
969 x = xinerama_info.x_org; 810 x = xinerama[this->current_display].x_org;
970 y = xinerama_info.y_org; 811 y = xinerama[this->current_display].y_org;
971 } 812 }
972 #endif 813 #endif
973 /* Map the fullscreen window to blank the screen */ 814 /* Map the fullscreen window to blank the screen */
974 screen_w = DisplayWidth(SDL_Display, SDL_Screen); 815 screen_w = DisplayWidth (SDL_Display, SDL_Screen);
975 screen_h = DisplayHeight(SDL_Display, SDL_Screen); 816 screen_h = DisplayHeight (SDL_Display, SDL_Screen);
976 get_real_resolution(this, &real_w, &real_h); 817 get_real_resolution (this, &real_w, &real_h);
977 if ( window_w > real_w ) { 818 if (window_w > real_w) {
978 real_w = MAX(real_w, screen_w); 819 real_w = MAX (real_w, screen_w);
979 } 820 }
980 if ( window_h > real_h ) { 821 if (window_h > real_h) {
981 real_h = MAX(real_h, screen_h); 822 real_h = MAX (real_h, screen_h);
982 } 823 }
983 XMoveResizeWindow(SDL_Display, FSwindow, 824 XMoveResizeWindow (SDL_Display, FSwindow, x, y, real_w, real_h);
984 x, y, real_w, real_h); 825 XMapRaised (SDL_Display, FSwindow);
985 XMapRaised(SDL_Display, FSwindow); 826 X11_WaitMapped (this, FSwindow);
986 X11_WaitMapped(this, FSwindow); 827
987 828 #if 0 /* This seems to break WindowMaker in focus-follows-mouse mode */
988 #if 0 /* This seems to break WindowMaker in focus-follows-mouse mode */
989 /* Make sure we got to the top of the window stack */ 829 /* Make sure we got to the top of the window stack */
990 if ( XQueryTree(SDL_Display, SDL_Root, &tmpwin, &tmpwin, 830 if (XQueryTree (SDL_Display, SDL_Root, &tmpwin, &tmpwin,
991 &windows, &nwindows) && windows ) { 831 &windows, &nwindows) && windows) {
992 /* If not, try to put us there - if fail... oh well */ 832 /* If not, try to put us there - if fail... oh well */
993 if ( windows[nwindows-1] != FSwindow ) { 833 if (windows[nwindows - 1] != FSwindow) {
994 tmpwin = windows[nwindows-1]; 834 tmpwin = windows[nwindows - 1];
995 for ( i=0; i<nwindows; ++i ) { 835 for (i = 0; i < nwindows; ++i) {
996 if ( windows[i] == FSwindow ) { 836 if (windows[i] == FSwindow) {
997 SDL_memcpy(&windows[i], &windows[i+1], 837 SDL_memcpy (&windows[i], &windows[i + 1],
998 (nwindows-i-1)*sizeof(windows[i])); 838 (nwindows - i - 1) * sizeof (windows[i]));
999 break; 839 break;
1000 } 840 }
1001 } 841 }
1002 windows[nwindows-1] = FSwindow; 842 windows[nwindows - 1] = FSwindow;
1003 XRestackWindows(SDL_Display, windows, nwindows); 843 XRestackWindows (SDL_Display, windows, nwindows);
1004 XSync(SDL_Display, False); 844 XSync (SDL_Display, False);
1005 } 845 }
1006 XFree(windows); 846 XFree (windows);
1007 } 847 }
1008 #else 848 #else
1009 XRaiseWindow(SDL_Display, FSwindow); 849 XRaiseWindow (SDL_Display, FSwindow);
1010 #endif 850 #endif
1011 851
1012 #if SDL_VIDEO_DRIVER_X11_VIDMODE 852 #if SDL_VIDEO_DRIVER_X11_VIDMODE
1013 /* Save the current video mode */ 853 /* Save the current video mode */
1014 if ( use_vidmode ) { 854 if (use_vidmode) {
1015 SDL_NAME(XF86VidModeLockModeSwitch)(SDL_Display, SDL_Screen, True); 855 SDL_NAME (XF86VidModeLockModeSwitch) (SDL_Display, SDL_Screen, True);
1016 } 856 }
1017 #endif 857 #endif
1018 currently_fullscreen = 1; 858 currently_fullscreen = 1;
1019 859
1020 /* Set the new resolution */ 860 /* Set the new resolution */
1021 okay = X11_ResizeFullScreen(this); 861 okay = X11_ResizeFullScreen (this);
1022 if ( ! okay ) { 862 if (!okay) {
1023 X11_LeaveFullScreen(this); 863 X11_LeaveFullScreen (this);
1024 } 864 }
1025 /* Set the colormap */ 865 /* Set the colormap */
1026 if ( SDL_XColorMap ) { 866 if (SDL_XColorMap) {
1027 XInstallColormap(SDL_Display, SDL_XColorMap); 867 XInstallColormap (SDL_Display, SDL_XColorMap);
1028 } 868 }
1029 if ( okay ) { 869 if (okay) {
1030 X11_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN); 870 X11_GrabInputNoLock (this,
871 SDL_CurrentWindow.
872 input_grab | SDL_GRAB_FULLSCREEN);
1031 } 873 }
1032 874
1033 /* We may need to refresh the screen at this point (no backing store) 875 /* We may need to refresh the screen at this point (no backing store)
1034 We also don't get an event, which is why we explicitly refresh. */ 876 We also don't get an event, which is why we explicitly refresh. */
1035 if ( this->screen ) { 877 if (SDL_VideoSurface) {
1036 if ( this->screen->flags & SDL_INTERNALOPENGL ) { 878 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) {
1037 SDL_PrivateExpose(); 879 SDL_PrivateExpose ();
1038 } else { 880 } else {
1039 X11_RefreshDisplay(this); 881 X11_RefreshDisplay (this);
1040 } 882 }
1041 } 883 }
1042 884
1043 return(okay); 885 return (okay);
1044 } 886 }
1045 887
1046 int X11_LeaveFullScreen(_THIS) 888 int
1047 { 889 X11_LeaveFullScreen (_THIS)
1048 if ( currently_fullscreen ) { 890 {
1049 XReparentWindow(SDL_Display, SDL_Window, WMwindow, 0, 0); 891 if (currently_fullscreen) {
1050 #if SDL_VIDEO_DRIVER_X11_VIDMODE 892 XReparentWindow (SDL_Display, SDL_Window, WMwindow, 0, 0);
1051 if ( use_vidmode ) { 893 #if SDL_VIDEO_DRIVER_X11_VIDMODE
1052 restore_mode(this); 894 if (use_vidmode) {
1053 SDL_NAME(XF86VidModeLockModeSwitch)(SDL_Display, SDL_Screen, False); 895 restore_mode (this);
896 SDL_NAME (XF86VidModeLockModeSwitch) (SDL_Display, SDL_Screen,
897 False);
1054 } 898 }
1055 #endif 899 #endif
1056 900
1057 #if SDL_VIDEO_DRIVER_X11_XME 901 #if SDL_VIDEO_DRIVER_X11_XME
1058 if ( use_xme ) { 902 if (use_xme) {
1059 int rw, rh; 903 int rw, rh;
1060 904
1061 /* check current mode so we can avoid uneccessary mode changes */ 905 /* check current mode so we can avoid uneccessary mode changes */
1062 get_real_resolution(this, &rw, &rh); 906 get_real_resolution (this, &rw, &rh);
1063 907
1064 if (rw != saved_res.width || rh != saved_res.height) { 908 if (rw != saved_res.width || rh != saved_res.height) {
1065 XiGMiscChangeResolution(SDL_Display, 909 XiGMiscChangeResolution (SDL_Display, SDL_Screen, 0, /* view */
1066 SDL_Screen, 910 saved_res.width,
1067 0, /* view */ 911 saved_res.height, 0);
1068 saved_res.width, 912 XSync (SDL_Display, False);
1069 saved_res.height,
1070 0);
1071 XSync(SDL_Display, False);
1072 } 913 }
1073 } 914 }
1074 #endif 915 #endif
1075 916
1076 #if SDL_VIDEO_DRIVER_X11_XRANDR 917 #if SDL_VIDEO_DRIVER_X11_XRANDR
1077 if ( use_xrandr ) { 918 if (use_xrandr) {
1078 XRRSetScreenConfig(SDL_Display, screen_config, SDL_Root, 919 XRRSetScreenConfig (SDL_Display, screen_config, SDL_Root,
1079 saved_size_id, saved_rotation, CurrentTime); 920 saved_size_id, saved_rotation, CurrentTime);
1080 } 921 }
1081 #endif 922 #endif
1082 923
1083 XUnmapWindow(SDL_Display, FSwindow); 924 XUnmapWindow (SDL_Display, FSwindow);
1084 X11_WaitUnmapped(this, FSwindow); 925 X11_WaitUnmapped (this, FSwindow);
1085 XSync(SDL_Display, True); /* Flush spurious mode change events */ 926 XSync (SDL_Display, True); /* Flush spurious mode change events */
1086 currently_fullscreen = 0; 927 currently_fullscreen = 0;
1087 } 928 }
1088 /* If we get popped out of fullscreen mode for some reason, input_grab 929 /* If we get popped out of fullscreen mode for some reason, input_grab
1089 will still have the SDL_GRAB_FULLSCREEN flag set, since this is only 930 will still have the SDL_GRAB_FULLSCREEN flag set, since this is only
1090 temporary. In this case, release the grab unless the input has been 931 temporary. In this case, release the grab unless the input has been
1091 explicitly grabbed. 932 explicitly grabbed.
1092 */ 933 */
1093 X11_GrabInputNoLock(this, this->input_grab & ~SDL_GRAB_FULLSCREEN); 934 X11_GrabInputNoLock (this,
935 SDL_CurrentWindow.input_grab & ~SDL_GRAB_FULLSCREEN);
1094 936
1095 /* We may need to refresh the screen at this point (no backing store) 937 /* We may need to refresh the screen at this point (no backing store)
1096 We also don't get an event, which is why we explicitly refresh. */ 938 We also don't get an event, which is why we explicitly refresh. */
1097 if ( this->screen ) { 939 if (SDL_VideoSurface) {
1098 if ( this->screen->flags & SDL_INTERNALOPENGL ) { 940 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) {
1099 SDL_PrivateExpose(); 941 SDL_PrivateExpose ();
1100 } else { 942 } else {
1101 X11_RefreshDisplay(this); 943 X11_RefreshDisplay (this);
1102 } 944 }
1103 } 945 }
1104 946
1105 return(0); 947 return (0);
1106 } 948 }
949
950 Uint32
951 X11_VisualToFormat (const Visual * visual, int depth, int bpp)
952 {
953 Uint32 Rmask = visual->red_mask;
954 Uint32 Gmask = visual->green_mask;
955 Uint32 Bmask = visual->blue_mask;
956 Uint32 Amask;
957
958 if (depth == 32) {
959 Amask = (0xFFFFFFFF & ~(Rmask | Gmask | Bmask));
960 } else {
961 Amask = 0;
962 }
963 return (SDL_MasksToPixelFormatEnum (bpp, Rmask, Gmask, Bmask, Amask));
964 }
965
966 /* vi: set ts=4 sw=4 expandtab: */