comparison src/video/x11/SDL_x11modes.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 0e44c6f90b95
children
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
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
64 save_mode(_THIS)
62 { 65 {
63 SDL_memset(&saved_mode, 0, sizeof(saved_mode)); 66 SDL_memset(&saved_mode, 0, sizeof(saved_mode));
64 SDL_NAME(XF86VidModeGetModeInfo)(SDL_Display,SDL_Screen,&saved_mode); 67 SDL_NAME(XF86VidModeGetModeInfo) (SDL_Display, SDL_Screen, &saved_mode);
65 SDL_NAME(XF86VidModeGetViewPort)(SDL_Display,SDL_Screen,&saved_view.x,&saved_view.y); 68 SDL_NAME(XF86VidModeGetViewPort) (SDL_Display, SDL_Screen, &saved_view.x,
66 } 69 &saved_view.y);
67 #endif 70 }
68 71 #endif
69 #if SDL_VIDEO_DRIVER_X11_VIDMODE 72
70 static void restore_mode(_THIS) 73 #if SDL_VIDEO_DRIVER_X11_VIDMODE
74 static void
75 restore_mode(_THIS)
71 { 76 {
72 SDL_NAME(XF86VidModeModeLine) mode; 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) ) {
126 best = i;
127 }
128 }
129 }
130 if ( best >= 0 &&
131 ((modes[best]->hdisplay != mode.hdisplay) ||
132 (modes[best]->vdisplay != mode.vdisplay)) ) {
133 #ifdef X11MODES_DEBUG 138 #ifdef X11MODES_DEBUG
134 printf("Best Mode %d: %d x %d @ %d\n", best, 139 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,
144 SDL_Screen, modes[best]);
139 } 145 }
140 XFree(modes); 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: "
163 "XiGMiscChangeResolution: %d %d\n", mode.w, mode.h);
164 #endif
165 XiGMiscChangeResolution(SDL_Display, SDL_Screen, 0, /* view */
166 mode.w, mode.h, 0);
167 XSync(SDL_Display, False);
168 }
169 }
170 #endif /* SDL_VIDEO_DRIVER_X11_XME */
171
172 #if SDL_VIDEO_DRIVER_X11_XRANDR
173 if (use_xrandr) {
174 int i, nsizes;
175 XRRScreenSize *sizes;
176
177 /* find the smallest resolution that is at least as big as the user requested */
178 sizes = XRRConfigSizes(screen_config, &nsizes);
179 for (i = (nsizes - 1); i >= 0; i--) {
180 if ((mode.w >= width) && (mode.h >= height)) {
157 break; 181 break;
158 } 182 }
159 } 183 }
160 184
161 if ( SDL_modelist[i] ) { /* found one, lets try it */ 185 if (i >= 0) { /* found one, lets try it */
162 int w, h; 186 int w, h;
163 187
164 /* check current mode so we can avoid uneccessary mode changes */ 188 /* check current mode so we can avoid uneccessary mode changes */
165 get_real_resolution(this, &w, &h); 189 get_real_resolution(this, &w, &h);
166 190
167 if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) { 191 if ((mode.w != w) || (mode.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 }
182 }
183 #endif /* SDL_VIDEO_DRIVER_X11_XME */
184
185 #if SDL_VIDEO_DRIVER_X11_XRANDR
186 if ( use_xrandr && SDL_modelist ) {
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;
192 XRRScreenSize *sizes;
193
194 /* find the smallest resolution that is at least as big as the user requested */
195 sizes = XRRConfigSizes(screen_config, &nsizes);
196 for ( i = (nsizes-1); i >= 0; i-- ) {
197 if ( (SDL_modelist[i]->w >= width) &&
198 (SDL_modelist[i]->h >= height) ) {
199 break;
200 }
201 }
202
203 if ( i >= 0 && SDL_modelist[i] ) { /* found one, lets try it */
204 int w, h;
205
206 /* check current mode so we can avoid uneccessary mode changes */
207 get_real_resolution(this, &w, &h);
208
209 if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->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 */
242 &ractive, &modelist); 224 &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);
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
308 static void
309 move_cursor_to(_THIS, int x, int y)
320 { 310 {
321 XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y); 311 XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y);
322 } 312 }
323 313
324 static int add_visual(_THIS, int depth, int class) 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") == 0) {
430 FILE *metro_fp; 475 FILE *metro_fp;
431 476
432 metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r"); 477 metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
433 if ( metro_fp != NULL ) { 478 if (metro_fp != NULL) {
434 int major, minor, patch, version; 479 int major, minor, patch, version;
435 major = 0; minor = 0; patch = 0; 480 major = 0;
481 minor = 0;
482 patch = 0;
436 fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch); 483 fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch);
437 fclose(metro_fp); 484 fclose(metro_fp);
438 version = major*100+minor*10+patch; 485 version = major * 100 + minor * 10 + patch;
439 if ( version < 431 ) { 486 if (version < 431) {
440 return 0; 487 return 0;
441 } 488 }
442 } 489 }
443 } 490 }
444 491
445 /* Query the extension version */ 492 /* Query the extension version */
446 vm_error = -1; 493 vm_error = -1;
447 if ( !SDL_NAME(XF86VidModeQueryExtension)(SDL_Display, &vm_event, &vm_error) || 494 if (!SDL_NAME(XF86VidModeQueryExtension)
448 !SDL_NAME(XF86VidModeQueryVersion)(SDL_Display, major, minor) ) { 495 (SDL_Display, &vm_event, &vm_error)
496 || !SDL_NAME(XF86VidModeQueryVersion) (SDL_Display, major, minor)) {
449 return 0; 497 return 0;
450 } 498 }
451 return 1; 499 return 1;
452 } 500 }
453 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ 501 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
454 502
455 #if SDL_VIDEO_DRIVER_X11_XME 503 #if SDL_VIDEO_DRIVER_X11_XME
456 static int CheckXME(_THIS, int *major, int *minor) 504 static int
505 CheckXME(_THIS, int *major, int *minor)
457 { 506 {
458 const char *env; 507 const char *env;
459 508
460 /* Default the extension not available */ 509 /* Default the extension not available */
461 *major = *minor = 0; 510 *major = *minor = 0;
462 511
463 /* Allow environment override */ 512 /* Allow environment override */
464 env = getenv("SDL_VIDEO_X11_VIDMODE"); 513 env = getenv("SDL_VIDEO_X11_VIDMODE");
465 if ( env && !SDL_atoi(env) ) { 514 if (env && !SDL_atoi(env)) {
466 return 0; 515 return 0;
467 } 516 }
468 517
469 /* Query the extension version */ 518 /* Query the extension version */
470 if ( !XiGMiscQueryVersion(SDL_Display, major, minor) ) { 519 if (!XiGMiscQueryVersion(SDL_Display, major, minor)) {
471 return 0; 520 return 0;
472 } 521 }
473 return 1; 522 return 1;
474 } 523 }
475 #endif /* SDL_VIDEO_DRIVER_X11_XME */ 524 #endif /* SDL_VIDEO_DRIVER_X11_XME */
476 525
477 int X11_GetVideoModes(_THIS) 526 int
527 X11_GetVideoModes(_THIS)
478 { 528 {
479 #if SDL_VIDEO_DRIVER_X11_XINERAMA 529 #if SDL_VIDEO_DRIVER_X11_XINERAMA
480 int xinerama_major, xinerama_minor; 530 int xinerama_major, xinerama_minor;
481 #endif 531 #endif
482 #if SDL_VIDEO_DRIVER_X11_XRANDR 532 #if SDL_VIDEO_DRIVER_X11_XRANDR
483 int xrandr_major, xrandr_minor; 533 int xrandr_major, xrandr_minor;
484 int nsizes; 534 int nsizes;
485 XRRScreenSize *sizes; 535 XRRScreenSize *sizes;
536 int nrates;
537 short *rates;
486 #endif 538 #endif
487 #if SDL_VIDEO_DRIVER_X11_VIDMODE 539 #if SDL_VIDEO_DRIVER_X11_VIDMODE
488 int vm_major, vm_minor; 540 int vm_major, vm_minor;
489 int nmodes; 541 int nmodes;
490 SDL_NAME(XF86VidModeModeInfo) **modes; 542 SDL_NAME(XF86VidModeModeInfo) ** modes;
491 #endif 543 #endif
492 #if SDL_VIDEO_DRIVER_X11_XME 544 #if SDL_VIDEO_DRIVER_X11_XME
493 int xme_major, xme_minor; 545 int xme_major, xme_minor;
494 int ractive, nummodes; 546 int ractive, nummodes;
495 XiGMiscResolutionInfo *modelist; 547 XiGMiscResolutionInfo *modelist;
496 #endif 548 #endif
497 int i, n; 549 int i;
498 int screen_w; 550 int screen_w;
499 int screen_h; 551 int screen_h;
552 SDL_DisplayMode mode;
500 553
501 use_xinerama = 0; 554 use_xinerama = 0;
502 use_xrandr = 0; 555 use_xrandr = 0;
503 use_vidmode = 0; 556 use_vidmode = 0;
504 use_xme = 0; 557 use_xme = 0;
505 screen_w = DisplayWidth(SDL_Display, SDL_Screen); 558 screen_w = DisplayWidth(SDL_Display, SDL_Screen);
506 screen_h = DisplayHeight(SDL_Display, SDL_Screen); 559 screen_h = DisplayHeight(SDL_Display, SDL_Screen);
507 560
561 mode.format = this->displays[this->current_display].desktop_mode.format;
562 mode.w = screen_w;
563 mode.h = screen_h;
564 mode.refresh_rate = 0;
565 SDL_AddDisplayMode(0, &mode);
566
508 #if SDL_VIDEO_DRIVER_X11_XINERAMA 567 #if SDL_VIDEO_DRIVER_X11_XINERAMA
509 /* Query Xinerama extention */ 568 /* Query Xinerama extention */
510 if ( CheckXinerama(this, &xinerama_major, &xinerama_minor) ) { 569 if (CheckXinerama(this, &xinerama_major, &xinerama_minor)) {
511 /* Find out which screen is the desired one */
512 int desired = 0;
513 int screens; 570 int screens;
514 int w, h; 571
515 SDL_NAME(XineramaScreenInfo) *xinerama;
516
517 const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
518 if ( variable ) {
519 desired = SDL_atoi(variable);
520 }
521 #ifdef X11MODES_DEBUG 572 #ifdef X11MODES_DEBUG
522 printf("X11 detected Xinerama:\n"); 573 printf("X11 detected Xinerama:\n");
523 #endif 574 #endif
524 xinerama = SDL_NAME(XineramaQueryScreens)(SDL_Display, &screens); 575 xinerama = SDL_NAME(XineramaQueryScreens) (SDL_Display, &screens);
525 for ( i = 0; i < screens; i++ ) { 576 for (i = 0; i < screens; i++) {
526 #ifdef X11MODES_DEBUG 577 #ifdef X11MODES_DEBUG
527 printf("xinerama %d: %dx%d+%d+%d\n", 578 printf("xinerama %d: %dx%d+%d+%d\n",
528 xinerama[i].screen_number, 579 xinerama[i].screen_number,
529 xinerama[i].width, xinerama[i].height, 580 xinerama[i].width, xinerama[i].height,
530 xinerama[i].x_org, xinerama[i].y_org); 581 xinerama[i].x_org, xinerama[i].y_org);
531 #endif 582 #endif
532 if ( xinerama[i].screen_number == desired ) { 583 if (xinerama[i].screen_number != 0) {
533 use_xinerama = 1; 584 SDL_AddVideoDisplay(&mode);
534 xinerama_info = xinerama[i]; 585 }
535 } 586 mode.w = xinerama[i].width;
536 } 587 mode.h = xinerama[i].height;
537 XFree(xinerama); 588 SDL_AddDisplayMode(xinerama[i].screen_number, &mode);
538 589 }
539 if ( use_xinerama ) { 590 use_xinerama = 1;
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 } 591 }
573 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ 592 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
574 593
575 #if SDL_VIDEO_DRIVER_X11_XRANDR 594 #if SDL_VIDEO_DRIVER_X11_XRANDR
576 /* XRandR */ 595 /* XRandR */
577 /* require at least XRandR v1.0 (arbitrary) */ 596 /* require at least XRandR v1.0 (arbitrary) */
578 if ( CheckXRandR(this, &xrandr_major, &xrandr_minor) && (xrandr_major >= 1) ) 597 if (CheckXRandR(this, &xrandr_major, &xrandr_minor)
579 { 598 && (xrandr_major >= 1)) {
580 #ifdef X11MODES_DEBUG 599 #ifdef X11MODES_DEBUG
581 fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n", 600 fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n",
582 xrandr_major, xrandr_minor); 601 xrandr_major, xrandr_minor);
583 #endif 602 #endif
584 603
585 /* save the screen configuration since we must reference it 604 /* save the screen configuration since we must reference it
586 each time we toggle modes. 605 each time we toggle modes.
587 */ 606 */
588 screen_config = XRRGetScreenInfo(SDL_Display, SDL_Root); 607 screen_config = XRRGetScreenInfo(SDL_Display, SDL_Root);
589 608
590 /* retrieve the list of resolution */ 609 /* retrieve the list of resolution */
591 sizes = XRRConfigSizes(screen_config, &nsizes); 610 sizes = XRRConfigSizes(screen_config, &nsizes);
592 if (nsizes > 0) { 611 if (nsizes > 0) {
593 if ( SDL_modelist ) { 612 for (i = 0; i < nsizes; i++) {
594 for ( i = 0; SDL_modelist[i]; ++i ) { 613 mode.w = sizes[i].width;
595 SDL_free(SDL_modelist[i]); 614 mode.h = sizes[i].height;
596 } 615
597 SDL_free(SDL_modelist); 616 rates = XRRConfigRates(screen_config, i, &nrates);
598 } 617 if (nrates == 0) {
599 SDL_modelist = (SDL_Rect **)malloc((nsizes+1)*sizeof(SDL_Rect *)); 618 mode.refresh_rate = 0;
600 if ( !SDL_modelist ) { 619 SDL_AddDisplayMode(0, &mode);
601 SDL_OutOfMemory(); 620 } else {
602 return -1; 621 int j;
603 } 622 for (j = 0; j < nrates; ++j) {
604 for ( i=0; i < nsizes; i++ ) { 623 mode.refresh_rate = rates[j];
605 if ((SDL_modelist[i] = 624 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 #if SDL_VIDEO_DRIVER_X11_XINERAMA
633 (!use_xinerama || xinerama_info.screen_number == 0) &&
634 #endif
635 CheckVidMode(this, &vm_major, &vm_minor) &&
636 SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) )
637 {
638 #ifdef X11MODES_DEBUG
639 printf("VidMode modes: (unsorted)\n");
640 for ( i = 0; i < nmodes; ++i ) {
641 printf("Mode %d: %d x %d @ %d\n", i,
642 modes[i]->hdisplay, modes[i]->vdisplay,
643 (modes[i]->htotal && modes[i]->vtotal) ? (1000 * modes[i]->dotclock / (modes[i]->htotal * modes[i]->vtotal)) : 0 );
644 }
645 #endif
646 if ( SDL_modelist ) {
647 for ( i = 0; SDL_modelist[i]; ++i ) {
648 SDL_free(SDL_modelist[i]);
649 }
650 SDL_free(SDL_modelist);
651 }
652 SDL_modelist = (SDL_Rect **)SDL_malloc((nmodes+2)*sizeof(SDL_Rect *));
653 if ( !SDL_modelist ) {
654 SDL_OutOfMemory();
655 return -1;
656 }
657 SDL_qsort(modes, nmodes, sizeof *modes, cmpmodes);
658 n = 0;
659 for ( i=0; i<nmodes; ++i ) {
660 int w, h;
661
662 /* Eliminate duplicate modes with different refresh rates */
663 if ( i > 0 &&
664 modes[i]->hdisplay == modes[i-1]->hdisplay &&
665 modes[i]->vdisplay == modes[i-1]->vdisplay ) {
666 continue;
667 }
668
669 /* Check to see if we should add the screen size (Xinerama) */
670 w = modes[i]->hdisplay;
671 h = modes[i]->vdisplay;
672 if ( (screen_w * screen_h) >= (w * h) ) {
673 if ( (screen_w != w) || (screen_h != h) ) {
674 SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
675 if ( SDL_modelist[n] ) {
676 SDL_modelist[n]->x = 0;
677 SDL_modelist[n]->y = 0;
678 SDL_modelist[n]->w = screen_w;
679 SDL_modelist[n]->h = screen_h;
680 ++n;
681 } 625 }
682 } 626 }
683 screen_w = 0; 627 }
684 screen_h = 0; 628
685 } 629 use_xrandr = xrandr_major * 100 + xrandr_minor;
686 630 saved_size_id =
687 /* Add the size from the video mode list */ 631 XRRConfigCurrentConfiguration(screen_config, &saved_rotation);
688 SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); 632 }
689 if ( SDL_modelist[n] == NULL ) { 633 }
690 break; 634 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
691 } 635
692 SDL_modelist[n]->x = 0; 636 #if SDL_VIDEO_DRIVER_X11_VIDMODE
693 SDL_modelist[n]->y = 0; 637 /* XVidMode */
694 SDL_modelist[n]->w = w; 638 if (!use_xrandr &&
695 SDL_modelist[n]->h = h; 639 CheckVidMode(this, &vm_major, &vm_minor) &&
696 ++n; 640 SDL_NAME(XF86VidModeGetAllModeLines) (SDL_Display, SDL_Screen,
697 } 641 &nmodes, &modes)) {
698 SDL_modelist[n] = NULL; 642 #ifdef X11MODES_DEBUG
643 printf("VidMode modes: (unsorted)\n");
644 for (i = 0; i < nmodes; ++i) {
645 printf("Mode %d: %d x %d @ %d\n", i,
646 modes[i]->hdisplay, modes[i]->vdisplay,
647 vidmode_refreshrate(modes[i]));
648 }
649 #endif
650 for (i = 0; i < nmodes; ++i) {
651 mode.w = modes[i]->hdisplay;
652 mode.h = modes[i]->vdisplay;
653 mode.refresh_rate = vidmode_refreshrate(modes[i]);
654 SDL_AddDisplayMode(0, &mode);
655 }
699 XFree(modes); 656 XFree(modes);
700 657
701 use_vidmode = vm_major * 100 + vm_minor; 658 use_vidmode = vm_major * 100 + vm_minor;
702 save_mode(this); 659 save_mode(this);
703 } 660 }
705 662
706 #if SDL_VIDEO_DRIVER_X11_XME 663 #if SDL_VIDEO_DRIVER_X11_XME
707 /* XiG */ 664 /* XiG */
708 modelist = NULL; 665 modelist = NULL;
709 /* first lets make sure we have the extension, and it's at least v2.0 */ 666 /* first lets make sure we have the extension, and it's at least v2.0 */
710 if ( CheckXME(this, &xme_major, &xme_minor) && xme_major >= 2 && 667 if (CheckXME(this, &xme_major, &xme_minor) && xme_major >= 2 && (nummodes = XiGMiscQueryResolutions(SDL_Display, SDL_Screen, 0, /* view */
711 (nummodes = XiGMiscQueryResolutions(SDL_Display, SDL_Screen, 668 &ractive,
712 0, /* view */ 669 &modelist))
713 &ractive, &modelist)) > 1 ) 670 > 1) { /* then we actually have some */
714 { /* then we actually have some */
715 int j;
716
717 /* We get the list already sorted in descending order. 671 /* We get the list already sorted in descending order.
718 We'll copy it in reverse order so SDL is happy */ 672 We'll copy it in reverse order so SDL is happy */
719 #ifdef X11MODES_DEBUG 673 #ifdef X11MODES_DEBUG
720 fprintf(stderr, "XME: nummodes = %d, active mode = %d\n", 674 fprintf(stderr, "XME: nummodes = %d, active mode = %d\n",
721 nummodes, ractive); 675 nummodes, ractive);
722 #endif 676 #endif
723 if ( SDL_modelist ) { 677 mode.refresh_rate = 0;
724 for ( i = 0; SDL_modelist[i]; ++i ) { 678 for (i = 0; i < nummodes; ++i) {
725 SDL_free(SDL_modelist[i]);
726 }
727 SDL_free(SDL_modelist);
728 }
729 SDL_modelist = (SDL_Rect **)SDL_malloc((nummodes+1)*sizeof(SDL_Rect *));
730 if ( !SDL_modelist ) {
731 SDL_OutOfMemory();
732 return -1;
733 }
734 for ( i=0, j=nummodes-1; j>=0; i++, j-- ) {
735 if ((SDL_modelist[i] =
736 (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect))) == NULL)
737 break;
738 #ifdef X11MODES_DEBUG 679 #ifdef X11MODES_DEBUG
739 fprintf(stderr, "XME: mode = %4d, w = %4d, h = %4d\n", 680 fprintf(stderr, "XME: mode = %4d, w = %4d, h = %4d\n",
740 i, modelist[i].width, modelist[i].height); 681 i, modelist[i].width, modelist[i].height);
741 #endif 682 #endif
742 683 mode.w = modelist[i].width;
743 SDL_modelist[i]->x = 0; 684 mode.h = modelist[i].height;
744 SDL_modelist[i]->y = 0; 685 SDL_AddDisplayMode(0, &mode);
745 SDL_modelist[i]->w = modelist[j].width; 686 }
746 SDL_modelist[i]->h = modelist[j].height;
747
748 }
749 SDL_modelist[i] = NULL; /* terminator */
750 687
751 use_xme = xme_major * 100 + xme_minor; 688 use_xme = xme_major * 100 + xme_minor;
752 saved_res = modelist[ractive]; /* save the current resolution */ 689 saved_res = modelist[ractive]; /* save the current resolution */
753 } 690 }
754 if ( modelist ) { 691 if (modelist) {
755 XFree(modelist); 692 XFree(modelist);
756 } 693 }
757 #endif /* SDL_VIDEO_DRIVER_X11_XME */ 694 #endif /* SDL_VIDEO_DRIVER_X11_XME */
758 695
759 { 696 #ifdef X11MODES_DEBUG
760 /* It's interesting to note that if we allow 32 bit depths, 697 if (use_xinerama) {
761 we get a visual with an alpha mask on composite servers.
762 static int depth_list[] = { 32, 24, 16, 15, 8 };
763 */
764 static int depth_list[] = { 24, 16, 15, 8 };
765 int j, np;
766 int use_directcolor = 1;
767 XPixmapFormatValues *pf;
768
769 /* Search for the visuals in deepest-first order, so that the first
770 will be the richest one */
771 if ( SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) {
772 use_directcolor = 0;
773 }
774 this->hidden->nvisuals = 0;
775 if ( ! add_visual_byid(this, SDL_getenv("SDL_VIDEO_X11_VISUALID")) ) {
776 for ( i=0; i<SDL_arraysize(depth_list); ++i ) {
777 if ( depth_list[i] > 8 ) {
778 if ( use_directcolor ) {
779 add_visual(this, depth_list[i], DirectColor);
780 }
781 add_visual(this, depth_list[i], TrueColor);
782 } else {
783 add_visual(this, depth_list[i], PseudoColor);
784 add_visual(this, depth_list[i], StaticColor);
785 }
786 }
787 }
788 if ( this->hidden->nvisuals == 0 ) {
789 SDL_SetError("Found no sufficiently capable X11 visuals");
790 return -1;
791 }
792
793 /* look up the pixel quantum for each depth */
794 pf = XListPixmapFormats(SDL_Display, &np);
795 for(i = 0; i < this->hidden->nvisuals; i++) {
796 int d = this->hidden->visuals[i].depth;
797 for(j = 0; j < np; j++)
798 if(pf[j].depth == d)
799 break;
800 this->hidden->visuals[i].bpp = j < np ? pf[j].bits_per_pixel : d;
801 }
802
803 XFree(pf);
804 }
805
806 if ( SDL_modelist == NULL ) {
807 SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *));
808 if ( !SDL_modelist ) {
809 SDL_OutOfMemory();
810 return -1;
811 }
812 n = 0;
813 SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
814 if ( SDL_modelist[n] ) {
815 SDL_modelist[n]->x = 0;
816 SDL_modelist[n]->y = 0;
817 SDL_modelist[n]->w = screen_w;
818 SDL_modelist[n]->h = screen_h;
819 ++n;
820 }
821 SDL_modelist[n] = NULL;
822 }
823
824 #ifdef X11MODES_DEBUG
825 if ( use_xinerama ) {
826 printf("Xinerama is enabled\n"); 698 printf("Xinerama is enabled\n");
827 } 699 }
828 700
829 if ( use_xrandr ) { 701 if (use_xrandr) {
830 printf("XRandR is enabled\n"); 702 printf("XRandR is enabled\n");
831 } 703 }
832 704
833 if ( use_vidmode ) { 705 if (use_vidmode) {
834 printf("VidMode is enabled\n"); 706 printf("VidMode is enabled\n");
835 } 707 }
836 708
837 if ( use_xme ) { 709 if (use_xme) {
838 printf("Xi Graphics XME fullscreen is enabled\n"); 710 printf("Xi Graphics XME fullscreen is enabled\n");
839 } 711 }
840
841 if ( SDL_modelist ) {
842 printf("X11 video mode list:\n");
843 for ( i=0; SDL_modelist[i]; ++i ) {
844 printf("\t%dx%d\n", SDL_modelist[i]->w, SDL_modelist[i]->h);
845 }
846 }
847 #endif /* X11MODES_DEBUG */ 712 #endif /* X11MODES_DEBUG */
848 713
849 return 0; 714 return 0;
850 } 715 }
851 716
852 int X11_SupportedVisual(_THIS, SDL_PixelFormat *format) 717 void
853 { 718 X11_FreeVideoModes(_THIS)
854 int i; 719 {
855 for(i = 0; i < this->hidden->nvisuals; i++)
856 if(this->hidden->visuals[i].bpp == format->BitsPerPixel)
857 return 1;
858 return 0;
859 }
860
861 SDL_Rect **X11_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
862 {
863 if ( X11_SupportedVisual(this, format) ) {
864 if ( flags & SDL_FULLSCREEN ) {
865 return(SDL_modelist);
866 } else {
867 return((SDL_Rect **)-1);
868 }
869 } else {
870 return((SDL_Rect **)0);
871 }
872 }
873
874 void X11_FreeVideoModes(_THIS)
875 {
876 int i;
877
878 if ( SDL_modelist ) {
879 for ( i=0; SDL_modelist[i]; ++i ) {
880 SDL_free(SDL_modelist[i]);
881 }
882 SDL_free(SDL_modelist);
883 SDL_modelist = NULL;
884 }
885
886 #if SDL_VIDEO_DRIVER_X11_XRANDR 720 #if SDL_VIDEO_DRIVER_X11_XRANDR
887 /* Free the Xrandr screen configuration */ 721 /* Free the Xrandr screen configuration */
888 if ( screen_config ) { 722 if (screen_config) {
889 XRRFreeScreenConfigInfo(screen_config); 723 XRRFreeScreenConfigInfo(screen_config);
890 screen_config = NULL; 724 screen_config = NULL;
891 } 725 }
892 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ 726 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
893 } 727 }
894 728
895 int X11_ResizeFullScreen(_THIS) 729 int
730 X11_ResizeFullScreen(_THIS)
896 { 731 {
897 int x = 0, y = 0; 732 int x = 0, y = 0;
898 int real_w, real_h; 733 int real_w, real_h;
899 int screen_w; 734 int screen_w;
900 int screen_h; 735 int screen_h;
901 736
902 screen_w = DisplayWidth(SDL_Display, SDL_Screen); 737 screen_w = DisplayWidth(SDL_Display, SDL_Screen);
903 screen_h = DisplayHeight(SDL_Display, SDL_Screen); 738 screen_h = DisplayHeight(SDL_Display, SDL_Screen);
904 739
905 #if SDL_VIDEO_DRIVER_X11_XINERAMA 740 #if SDL_VIDEO_DRIVER_X11_XINERAMA
906 if ( use_xinerama && 741 if (use_xinerama &&
907 window_w <= xinerama_info.width && 742 window_w <= xinerama[this->current_display].width &&
908 window_h <= xinerama_info.height ) { 743 window_h <= xinerama[this->current_display].height) {
909 x = xinerama_info.x_org; 744 x = xinerama[this->current_display].x_org;
910 y = xinerama_info.y_org; 745 y = xinerama[this->current_display].y_org;
911 } 746 }
912 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ 747 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
913 748
914 if ( currently_fullscreen ) { 749 if (currently_fullscreen) {
915 /* Switch resolution and cover it with the FSwindow */ 750 /* Switch resolution and cover it with the FSwindow */
916 move_cursor_to(this, x, y); 751 move_cursor_to(this, x, y);
917 set_best_resolution(this, window_w, window_h); 752 set_best_resolution(this, window_w, window_h);
918 move_cursor_to(this, x, y); 753 move_cursor_to(this, x, y);
919 get_real_resolution(this, &real_w, &real_h); 754 get_real_resolution(this, &real_w, &real_h);
920 if ( window_w > real_w ) { 755 if (window_w > real_w) {
921 real_w = MAX(real_w, screen_w); 756 real_w = MAX(real_w, screen_w);
922 } 757 }
923 if ( window_h > real_h ) { 758 if (window_h > real_h) {
924 real_h = MAX(real_h, screen_h); 759 real_h = MAX(real_h, screen_h);
925 } 760 }
926 XMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h); 761 XMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h);
927 move_cursor_to(this, real_w/2, real_h/2); 762 move_cursor_to(this, real_w / 2, real_h / 2);
928 763
929 /* Center and reparent the drawing window */ 764 /* Center and reparent the drawing window */
930 x = (real_w - window_w)/2; 765 x = (real_w - window_w) / 2;
931 y = (real_h - window_h)/2; 766 y = (real_h - window_h) / 2;
932 XReparentWindow(SDL_Display, SDL_Window, FSwindow, x, y); 767 XReparentWindow(SDL_Display, SDL_Window, FSwindow, x, y);
933 /* FIXME: move the mouse to the old relative location */ 768 /* FIXME: move the mouse to the old relative location */
934 XSync(SDL_Display, True); /* Flush spurious mode change events */ 769 XSync(SDL_Display, True); /* Flush spurious mode change events */
935 } 770 }
936 return(1); 771 return (1);
937 } 772 }
938 773
939 void X11_QueueEnterFullScreen(_THIS) 774 void
775 X11_QueueEnterFullScreen(_THIS)
940 { 776 {
941 switch_waiting = 0x01 | SDL_FULLSCREEN; 777 switch_waiting = 0x01 | SDL_FULLSCREEN;
942 switch_time = SDL_GetTicks() + 1500; 778 switch_time = SDL_GetTicks() + 1500;
943 #if 0 /* This causes a BadMatch error if the window is iconified (not needed) */ 779 #if 0 /* This causes a BadMatch error if the window is iconified (not needed) */
944 XSetInputFocus(SDL_Display, WMwindow, RevertToNone, CurrentTime); 780 XSetInputFocus(SDL_Display, WMwindow, RevertToNone, CurrentTime);
945 #endif 781 #endif
946 } 782 }
947 783
948 int X11_EnterFullScreen(_THIS) 784 int
785 X11_EnterFullScreen(_THIS)
949 { 786 {
950 int okay; 787 int okay;
951 #if 0 788 #if 0
952 Window tmpwin, *windows; 789 Window tmpwin, *windows;
953 int i, nwindows; 790 int i, nwindows;
956 int real_w, real_h; 793 int real_w, real_h;
957 int screen_w; 794 int screen_w;
958 int screen_h; 795 int screen_h;
959 796
960 okay = 1; 797 okay = 1;
961 if ( currently_fullscreen ) { 798 if (currently_fullscreen) {
962 return(okay); 799 return (okay);
963 } 800 }
964 801
965 /* Ungrab the input so that we can move the mouse around */ 802 /* Ungrab the input so that we can move the mouse around */
966 X11_GrabInputNoLock(this, SDL_GRAB_OFF); 803 X11_GrabInputNoLock(this, SDL_GRAB_OFF);
967 804
968 #if SDL_VIDEO_DRIVER_X11_XINERAMA 805 #if SDL_VIDEO_DRIVER_X11_XINERAMA
969 if ( use_xinerama && 806 if (use_xinerama &&
970 window_w <= xinerama_info.width && 807 window_w <= xinerama[this->current_display].width &&
971 window_h <= xinerama_info.height ) { 808 window_h <= xinerama[this->current_display].height) {
972 x = xinerama_info.x_org; 809 x = xinerama[this->current_display].x_org;
973 y = xinerama_info.y_org; 810 y = xinerama[this->current_display].y_org;
974 } 811 }
975 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ 812 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
976 813
977 /* Map the fullscreen window to blank the screen */ 814 /* Map the fullscreen window to blank the screen */
978 screen_w = DisplayWidth(SDL_Display, SDL_Screen); 815 screen_w = DisplayWidth(SDL_Display, SDL_Screen);
979 screen_h = DisplayHeight(SDL_Display, SDL_Screen); 816 screen_h = DisplayHeight(SDL_Display, SDL_Screen);
980 get_real_resolution(this, &real_w, &real_h); 817 get_real_resolution(this, &real_w, &real_h);
981 if ( window_w > real_w ) { 818 if (window_w > real_w) {
982 real_w = MAX(real_w, screen_w); 819 real_w = MAX(real_w, screen_w);
983 } 820 }
984 if ( window_h > real_h ) { 821 if (window_h > real_h) {
985 real_h = MAX(real_h, screen_h); 822 real_h = MAX(real_h, screen_h);
986 } 823 }
987 XMoveResizeWindow(SDL_Display, FSwindow, 824 XMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h);
988 x, y, real_w, real_h);
989 XMapRaised(SDL_Display, FSwindow); 825 XMapRaised(SDL_Display, FSwindow);
990 X11_WaitMapped(this, FSwindow); 826 X11_WaitMapped(this, FSwindow);
991 827
992 #if 0 /* This seems to break WindowMaker in focus-follows-mouse mode */ 828 #if 0 /* This seems to break WindowMaker in focus-follows-mouse mode */
993 /* Make sure we got to the top of the window stack */ 829 /* Make sure we got to the top of the window stack */
994 if ( XQueryTree(SDL_Display, SDL_Root, &tmpwin, &tmpwin, 830 if (XQueryTree(SDL_Display, SDL_Root, &tmpwin, &tmpwin,
995 &windows, &nwindows) && windows ) { 831 &windows, &nwindows) && windows) {
996 /* If not, try to put us there - if fail... oh well */ 832 /* If not, try to put us there - if fail... oh well */
997 if ( windows[nwindows-1] != FSwindow ) { 833 if (windows[nwindows - 1] != FSwindow) {
998 tmpwin = windows[nwindows-1]; 834 tmpwin = windows[nwindows - 1];
999 for ( i=0; i<nwindows; ++i ) { 835 for (i = 0; i < nwindows; ++i) {
1000 if ( windows[i] == FSwindow ) { 836 if (windows[i] == FSwindow) {
1001 SDL_memcpy(&windows[i], &windows[i+1], 837 SDL_memcpy(&windows[i], &windows[i + 1],
1002 (nwindows-i-1)*sizeof(windows[i])); 838 (nwindows - i - 1) * sizeof(windows[i]));
1003 break; 839 break;
1004 } 840 }
1005 } 841 }
1006 windows[nwindows-1] = FSwindow; 842 windows[nwindows - 1] = FSwindow;
1007 XRestackWindows(SDL_Display, windows, nwindows); 843 XRestackWindows(SDL_Display, windows, nwindows);
1008 XSync(SDL_Display, False); 844 XSync(SDL_Display, False);
1009 } 845 }
1010 XFree(windows); 846 XFree(windows);
1011 } 847 }
1013 XRaiseWindow(SDL_Display, FSwindow); 849 XRaiseWindow(SDL_Display, FSwindow);
1014 #endif 850 #endif
1015 851
1016 #if SDL_VIDEO_DRIVER_X11_VIDMODE 852 #if SDL_VIDEO_DRIVER_X11_VIDMODE
1017 /* Save the current video mode */ 853 /* Save the current video mode */
1018 if ( use_vidmode ) { 854 if (use_vidmode) {
1019 SDL_NAME(XF86VidModeLockModeSwitch)(SDL_Display, SDL_Screen, True); 855 SDL_NAME(XF86VidModeLockModeSwitch) (SDL_Display, SDL_Screen, True);
1020 } 856 }
1021 #endif 857 #endif
1022 currently_fullscreen = 1; 858 currently_fullscreen = 1;
1023 859
1024 /* Set the new resolution */ 860 /* Set the new resolution */
1025 okay = X11_ResizeFullScreen(this); 861 okay = X11_ResizeFullScreen(this);
1026 if ( ! okay ) { 862 if (!okay) {
1027 X11_LeaveFullScreen(this); 863 X11_LeaveFullScreen(this);
1028 } 864 }
1029 /* Set the colormap */ 865 /* Set the colormap */
1030 if ( SDL_XColorMap ) { 866 if (SDL_XColorMap) {
1031 XInstallColormap(SDL_Display, SDL_XColorMap); 867 XInstallColormap(SDL_Display, SDL_XColorMap);
1032 } 868 }
1033 if ( okay ) { 869 if (okay) {
1034 X11_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN); 870 X11_GrabInputNoLock(this,
871 SDL_CurrentWindow.
872 input_grab | SDL_GRAB_FULLSCREEN);
1035 } 873 }
1036 874
1037 /* 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)
1038 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. */
1039 if ( this->screen ) { 877 if (SDL_VideoSurface) {
1040 if ( this->screen->flags & SDL_OPENGL ) { 878 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) {
1041 SDL_PrivateExpose(); 879 SDL_PrivateExpose();
1042 } else { 880 } else {
1043 X11_RefreshDisplay(this); 881 X11_RefreshDisplay(this);
1044 } 882 }
1045 } 883 }
1046 884
1047 return(okay); 885 return (okay);
1048 } 886 }
1049 887
1050 int X11_LeaveFullScreen(_THIS) 888 int
1051 { 889 X11_LeaveFullScreen(_THIS)
1052 if ( currently_fullscreen ) { 890 {
891 if (currently_fullscreen) {
1053 XReparentWindow(SDL_Display, SDL_Window, WMwindow, 0, 0); 892 XReparentWindow(SDL_Display, SDL_Window, WMwindow, 0, 0);
1054 #if SDL_VIDEO_DRIVER_X11_VIDMODE 893 #if SDL_VIDEO_DRIVER_X11_VIDMODE
1055 if ( use_vidmode ) { 894 if (use_vidmode) {
1056 restore_mode(this); 895 restore_mode(this);
1057 SDL_NAME(XF86VidModeLockModeSwitch)(SDL_Display, SDL_Screen, False); 896 SDL_NAME(XF86VidModeLockModeSwitch) (SDL_Display, SDL_Screen,
897 False);
1058 } 898 }
1059 #endif 899 #endif
1060 900
1061 #if SDL_VIDEO_DRIVER_X11_XME 901 #if SDL_VIDEO_DRIVER_X11_XME
1062 if ( use_xme ) { 902 if (use_xme) {
1063 int rw, rh; 903 int rw, rh;
1064 904
1065 /* check current mode so we can avoid uneccessary mode changes */ 905 /* check current mode so we can avoid uneccessary mode changes */
1066 get_real_resolution(this, &rw, &rh); 906 get_real_resolution(this, &rw, &rh);
1067 907
1068 if (rw != saved_res.width || rh != saved_res.height) { 908 if (rw != saved_res.width || rh != saved_res.height) {
1069 XiGMiscChangeResolution(SDL_Display, 909 XiGMiscChangeResolution(SDL_Display, SDL_Screen, 0, /* view */
1070 SDL_Screen, 910 saved_res.width, saved_res.height, 0);
1071 0, /* view */
1072 saved_res.width,
1073 saved_res.height,
1074 0);
1075 XSync(SDL_Display, False); 911 XSync(SDL_Display, False);
1076 } 912 }
1077 } 913 }
1078 #endif 914 #endif
1079 915
1080 #if SDL_VIDEO_DRIVER_X11_XRANDR 916 #if SDL_VIDEO_DRIVER_X11_XRANDR
1081 if ( use_xrandr ) { 917 if (use_xrandr) {
1082 XRRSetScreenConfig(SDL_Display, screen_config, SDL_Root, 918 XRRSetScreenConfig(SDL_Display, screen_config, SDL_Root,
1083 saved_size_id, saved_rotation, CurrentTime); 919 saved_size_id, saved_rotation, CurrentTime);
1084 } 920 }
1085 #endif 921 #endif
1086 922
1087 XUnmapWindow(SDL_Display, FSwindow); 923 XUnmapWindow(SDL_Display, FSwindow);
1088 X11_WaitUnmapped(this, FSwindow); 924 X11_WaitUnmapped(this, FSwindow);
1089 XSync(SDL_Display, True); /* Flush spurious mode change events */ 925 XSync(SDL_Display, True); /* Flush spurious mode change events */
1090 currently_fullscreen = 0; 926 currently_fullscreen = 0;
1091 } 927 }
1092 /* If we get popped out of fullscreen mode for some reason, input_grab 928 /* If we get popped out of fullscreen mode for some reason, input_grab
1093 will still have the SDL_GRAB_FULLSCREEN flag set, since this is only 929 will still have the SDL_GRAB_FULLSCREEN flag set, since this is only
1094 temporary. In this case, release the grab unless the input has been 930 temporary. In this case, release the grab unless the input has been
1095 explicitly grabbed. 931 explicitly grabbed.
1096 */ 932 */
1097 X11_GrabInputNoLock(this, this->input_grab & ~SDL_GRAB_FULLSCREEN); 933 X11_GrabInputNoLock(this,
934 SDL_CurrentWindow.input_grab & ~SDL_GRAB_FULLSCREEN);
1098 935
1099 /* We may need to refresh the screen at this point (no backing store) 936 /* We may need to refresh the screen at this point (no backing store)
1100 We also don't get an event, which is why we explicitly refresh. */ 937 We also don't get an event, which is why we explicitly refresh. */
1101 if ( this->screen ) { 938 if (SDL_VideoSurface) {
1102 if ( this->screen->flags & SDL_OPENGL ) { 939 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) {
1103 SDL_PrivateExpose(); 940 SDL_PrivateExpose();
1104 } else { 941 } else {
1105 X11_RefreshDisplay(this); 942 X11_RefreshDisplay(this);
1106 } 943 }
1107 } 944 }
1108 945
1109 return(0); 946 return (0);
1110 } 947 }
948
949 Uint32
950 X11_VisualToFormat(const Visual * visual, int depth, int bpp)
951 {
952 Uint32 Rmask = visual->red_mask;
953 Uint32 Gmask = visual->green_mask;
954 Uint32 Bmask = visual->blue_mask;
955 Uint32 Amask;
956
957 if (depth == 32) {
958 Amask = (0xFFFFFFFF & ~(Rmask | Gmask | Bmask));
959 } else {
960 Amask = 0;
961 }
962 return (SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask));
963 }
964
965 /* vi: set ts=4 sw=4 expandtab: */