comparison src/video/x11/SDL_x11modes.c @ 2874:36e312e0fac0

indent
author Sam Lantinga <slouken@libsdl.org>
date Tue, 16 Dec 2008 17:44:10 +0000
parents b33e38aaa027
children c4150600b3ae
comparison
equal deleted inserted replaced
2873:b33e38aaa027 2874:36e312e0fac0
60 } 60 }
61 return -1; 61 return -1;
62 } 62 }
63 63
64 static Uint32 64 static Uint32
65 X11_GetPixelFormatFromVisualInfo(Display *display, XVisualInfo *vinfo) 65 X11_GetPixelFormatFromVisualInfo(Display * display, XVisualInfo * vinfo)
66 { 66 {
67 if (vinfo->class == DirectColor || vinfo->class == TrueColor) { 67 if (vinfo->class == DirectColor || vinfo->class == TrueColor) {
68 int bpp; 68 int bpp;
69 Uint32 Rmask, Gmask, Bmask, Amask; 69 Uint32 Rmask, Gmask, Bmask, Amask;
70 70
160 /* Global for the error handler */ 160 /* Global for the error handler */
161 int vm_event, vm_error = -1; 161 int vm_event, vm_error = -1;
162 162
163 #if SDL_VIDEO_DRIVER_X11_XINERAMA 163 #if SDL_VIDEO_DRIVER_X11_XINERAMA
164 static SDL_bool 164 static SDL_bool
165 CheckXinerama(Display *display, int *major, int *minor) 165 CheckXinerama(Display * display, int *major, int *minor)
166 { 166 {
167 const char *env; 167 const char *env;
168 168
169 /* Default the extension not available */ 169 /* Default the extension not available */
170 *major = *minor = 0; 170 *major = *minor = 0;
174 if (env && !SDL_atoi(env)) { 174 if (env && !SDL_atoi(env)) {
175 return SDL_FALSE; 175 return SDL_FALSE;
176 } 176 }
177 177
178 /* Query the extension version */ 178 /* Query the extension version */
179 if (!SDL_NAME(XineramaQueryExtension)(display, major, minor) || 179 if (!SDL_NAME(XineramaQueryExtension) (display, major, minor) ||
180 !SDL_NAME(XineramaIsActive)(display)) { 180 !SDL_NAME(XineramaIsActive) (display)) {
181 return SDL_FALSE; 181 return SDL_FALSE;
182 } 182 }
183 return SDL_TRUE; 183 return SDL_TRUE;
184 } 184 }
185 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ 185 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
186 186
187 #if SDL_VIDEO_DRIVER_X11_XRANDR 187 #if SDL_VIDEO_DRIVER_X11_XRANDR
188 static SDL_bool 188 static SDL_bool
189 CheckXRandR(Display *display, int *major, int *minor) 189 CheckXRandR(Display * display, int *major, int *minor)
190 { 190 {
191 const char *env; 191 const char *env;
192 192
193 /* Default the extension not available */ 193 /* Default the extension not available */
194 *major = *minor = 0; 194 *major = *minor = 0;
211 } 211 }
212 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ 212 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
213 213
214 #if SDL_VIDEO_DRIVER_X11_VIDMODE 214 #if SDL_VIDEO_DRIVER_X11_VIDMODE
215 static SDL_bool 215 static SDL_bool
216 CheckVidMode(Display *display, int *major, int *minor) 216 CheckVidMode(Display * display, int *major, int *minor)
217 { 217 {
218 const char *env; 218 const char *env;
219 219
220 /* Default the extension not available */ 220 /* Default the extension not available */
221 *major = *minor = 0; 221 *major = *minor = 0;
223 /* Allow environment override */ 223 /* Allow environment override */
224 env = getenv("SDL_VIDEO_X11_VIDMODE"); 224 env = getenv("SDL_VIDEO_X11_VIDMODE");
225 if (env && !SDL_atoi(env)) { 225 if (env && !SDL_atoi(env)) {
226 return SDL_FALSE; 226 return SDL_FALSE;
227 } 227 }
228 228
229 /* Query the extension version */ 229 /* Query the extension version */
230 vm_error = -1; 230 vm_error = -1;
231 if (!SDL_NAME(XF86VidModeQueryExtension)(display, &vm_event, &vm_error) || 231 if (!SDL_NAME(XF86VidModeQueryExtension) (display, &vm_event, &vm_error)
232 !SDL_NAME(XF86VidModeQueryVersion)(display, major, minor)) { 232 || !SDL_NAME(XF86VidModeQueryVersion) (display, major, minor)) {
233 return SDL_FALSE; 233 return SDL_FALSE;
234 } 234 }
235 return SDL_TRUE; 235 return SDL_TRUE;
236 } 236 }
237 237
238 Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info) 238 Bool SDL_NAME(XF86VidModeGetModeInfo) (Display * dpy, int scr,
239 SDL_NAME(XF86VidModeModeInfo) * info)
239 { 240 {
240 Bool retval; 241 Bool retval;
241 int dotclock; 242 int dotclock;
242 SDL_NAME(XF86VidModeModeLine) l; 243 SDL_NAME(XF86VidModeModeLine) l;
243 SDL_zerop(info); 244 SDL_zerop(info);
244 SDL_zero(l); 245 SDL_zero(l);
245 retval = SDL_NAME(XF86VidModeGetModeLine)(dpy, scr, &dotclock, &l); 246 retval = SDL_NAME(XF86VidModeGetModeLine) (dpy, scr, &dotclock, &l);
246 info->dotclock = dotclock; 247 info->dotclock = dotclock;
247 info->hdisplay = l.hdisplay; 248 info->hdisplay = l.hdisplay;
248 info->hsyncstart = l.hsyncstart; 249 info->hsyncstart = l.hsyncstart;
249 info->hsyncend = l.hsyncend; 250 info->hsyncend = l.hsyncend;
250 info->htotal = l.htotal; 251 info->htotal = l.htotal;
258 info->private = l.private; 259 info->private = l.private;
259 return retval; 260 return retval;
260 } 261 }
261 262
262 static int 263 static int
263 calculate_rate(SDL_NAME(XF86VidModeModeInfo) *info) 264 calculate_rate(SDL_NAME(XF86VidModeModeInfo) * info)
264 { 265 {
265 return (info->htotal && info->vtotal) ? (1000 * info->dotclock / (info->htotal * info->vtotal)) : 0; 266 return (info->htotal
267 && info->vtotal) ? (1000 * info->dotclock / (info->htotal *
268 info->vtotal)) : 0;
266 } 269 }
267 270
268 static void 271 static void
269 save_mode(Display *display, SDL_DisplayData *data) 272 save_mode(Display * display, SDL_DisplayData * data)
270 { 273 {
271 SDL_NAME(XF86VidModeGetModeInfo)(display, data->screen, &data->saved_mode); 274 SDL_NAME(XF86VidModeGetModeInfo) (display, data->screen,
272 SDL_NAME(XF86VidModeGetViewPort)(display, data->screen, &data->saved_view.x,&data->saved_view.y); 275 &data->saved_mode);
276 SDL_NAME(XF86VidModeGetViewPort) (display, data->screen,
277 &data->saved_view.x,
278 &data->saved_view.y);
273 } 279 }
274 280
275 static void 281 static void
276 restore_mode(Display *display, SDL_DisplayData *data) 282 restore_mode(Display * display, SDL_DisplayData * data)
277 { 283 {
278 SDL_NAME(XF86VidModeModeInfo) mode; 284 SDL_NAME(XF86VidModeModeInfo) mode;
279 285
280 if (SDL_NAME(XF86VidModeGetModeInfo)(display, data->screen, &mode)) { 286 if (SDL_NAME(XF86VidModeGetModeInfo) (display, data->screen, &mode)) {
281 if (SDL_memcmp(&mode, &data->saved_mode, sizeof(mode)) != 0) { 287 if (SDL_memcmp(&mode, &data->saved_mode, sizeof(mode)) != 0) {
282 SDL_NAME(XF86VidModeSwitchToMode)(display, data->screen, &data->saved_mode); 288 SDL_NAME(XF86VidModeSwitchToMode) (display, data->screen,
289 &data->saved_mode);
283 } 290 }
284 } 291 }
285 if ((data->saved_view.x != 0) || (data->saved_view.y != 0)) { 292 if ((data->saved_view.x != 0) || (data->saved_view.y != 0)) {
286 SDL_NAME(XF86VidModeSetViewPort)(display, data->screen, data->saved_view.x, data->saved_view.y); 293 SDL_NAME(XF86VidModeSetViewPort) (display, data->screen,
294 data->saved_view.x,
295 data->saved_view.y);
287 } 296 }
288 } 297 }
289 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ 298 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
290 299
291 void 300 void
294 Display *display = ((SDL_VideoData *) _this->driverdata)->display; 303 Display *display = ((SDL_VideoData *) _this->driverdata)->display;
295 SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; 304 SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
296 #if SDL_VIDEO_DRIVER_X11_XINERAMA 305 #if SDL_VIDEO_DRIVER_X11_XINERAMA
297 int xinerama_major, xinerama_minor; 306 int xinerama_major, xinerama_minor;
298 int screens; 307 int screens;
299 SDL_NAME(XineramaScreenInfo) *xinerama; 308 SDL_NAME(XineramaScreenInfo) * xinerama;
300 #endif 309 #endif
301 #if SDL_VIDEO_DRIVER_X11_XRANDR 310 #if SDL_VIDEO_DRIVER_X11_XRANDR
302 int xrandr_major, xrandr_minor; 311 int xrandr_major, xrandr_minor;
303 int nsizes, nrates; 312 int nsizes, nrates;
304 XRRScreenSize *sizes; 313 XRRScreenSize *sizes;
305 short *rates; 314 short *rates;
306 #endif 315 #endif
307 #if SDL_VIDEO_DRIVER_X11_VIDMODE 316 #if SDL_VIDEO_DRIVER_X11_VIDMODE
308 int vm_major, vm_minor; 317 int vm_major, vm_minor;
309 int nmodes; 318 int nmodes;
310 SDL_NAME(XF86VidModeModeInfo) **modes; 319 SDL_NAME(XF86VidModeModeInfo) ** modes;
311 #endif 320 #endif
312 int screen_w; 321 int screen_w;
313 int screen_h; 322 int screen_h;
314 SDL_DisplayMode mode; 323 SDL_DisplayMode mode;
315 324
332 /* Query Xinerama extention */ 341 /* Query Xinerama extention */
333 if (CheckXinerama(display, &xinerama_major, &xinerama_minor)) { 342 if (CheckXinerama(display, &xinerama_major, &xinerama_minor)) {
334 #ifdef X11MODES_DEBUG 343 #ifdef X11MODES_DEBUG
335 printf("X11 detected Xinerama:\n"); 344 printf("X11 detected Xinerama:\n");
336 #endif 345 #endif
337 xinerama = SDL_NAME(XineramaQueryScreens)(display, &screens); 346 xinerama = SDL_NAME(XineramaQueryScreens) (display, &screens);
338 if (xinerama) { 347 if (xinerama) {
339 int i; 348 int i;
340 for (i = 0; i < screens; i++) { 349 for (i = 0; i < screens; i++) {
341 #ifdef X11MODES_DEBUG 350 #ifdef X11MODES_DEBUG
342 printf("xinerama %d: %dx%d+%d+%d\n", 351 printf("xinerama %d: %dx%d+%d+%d\n",
343 xinerama[i].screen_number, 352 xinerama[i].screen_number,
344 xinerama[i].width, xinerama[i].height, 353 xinerama[i].width, xinerama[i].height,
345 xinerama[i].x_org, xinerama[i].y_org); 354 xinerama[i].x_org, xinerama[i].y_org);
346 #endif 355 #endif
347 if (xinerama[i].screen_number == data->screen) { 356 if (xinerama[i].screen_number == data->screen) {
348 data->use_xinerama = xinerama_major * 100 + xinerama_minor; 357 data->use_xinerama =
358 xinerama_major * 100 + xinerama_minor;
349 data->xinerama_info = xinerama[i]; 359 data->xinerama_info = xinerama[i];
350 } 360 }
351 } 361 }
352 XFree(xinerama); 362 XFree(xinerama);
353 } 363 }
372 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */ 382 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
373 383
374 #if SDL_VIDEO_DRIVER_X11_XRANDR 384 #if SDL_VIDEO_DRIVER_X11_XRANDR
375 /* XRandR */ 385 /* XRandR */
376 /* require at least XRandR v1.0 (arbitrary) */ 386 /* require at least XRandR v1.0 (arbitrary) */
377 if (CheckXRandR(display, &xrandr_major, &xrandr_minor) && xrandr_major >= 1) { 387 if (CheckXRandR(display, &xrandr_major, &xrandr_minor)
388 && xrandr_major >= 1) {
378 #ifdef X11MODES_DEBUG 389 #ifdef X11MODES_DEBUG
379 fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n", 390 fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n",
380 xrandr_major, xrandr_minor); 391 xrandr_major, xrandr_minor);
381 #endif 392 #endif
382 393
383 /* save the screen configuration since we must reference it 394 /* save the screen configuration since we must reference it
384 each time we toggle modes. 395 each time we toggle modes.
385 */ 396 */
386 data->screen_config = XRRGetScreenInfo(display, RootWindow(display, data->screen)); 397 data->screen_config =
398 XRRGetScreenInfo(display, RootWindow(display, data->screen));
387 399
388 /* retrieve the list of resolution */ 400 /* retrieve the list of resolution */
389 sizes = XRRConfigSizes(data->screen_config, &nsizes); 401 sizes = XRRConfigSizes(data->screen_config, &nsizes);
390 if (nsizes > 0) { 402 if (nsizes > 0) {
391 int i, j; 403 int i, j;
392 for ( i=0; i < nsizes; i++) { 404 for (i = 0; i < nsizes; i++) {
393 mode.w = sizes[i].width; 405 mode.w = sizes[i].width;
394 mode.h = sizes[i].height; 406 mode.h = sizes[i].height;
395 407
396 rates = XRRConfigRates(data->screen_config, i, &nrates); 408 rates = XRRConfigRates(data->screen_config, i, &nrates);
397 for (j = 0; j < nrates; ++j) { 409 for (j = 0; j < nrates; ++j) {
398 mode.refresh_rate = rates[j]; 410 mode.refresh_rate = rates[j];
399 #ifdef X11MODES_DEBUG 411 #ifdef X11MODES_DEBUG
400 fprintf(stderr, "XRANDR: mode = %4d[%d], w = %4d, h = %4d, rate = %4d\n", 412 fprintf(stderr,
413 "XRANDR: mode = %4d[%d], w = %4d, h = %4d, rate = %4d\n",
401 i, j, mode.w, mode.h, mode.refresh_rate); 414 i, j, mode.w, mode.h, mode.refresh_rate);
402 #endif 415 #endif
403 SDL_AddDisplayMode(_this->current_display, &mode); 416 SDL_AddDisplayMode(_this->current_display, &mode);
404 } 417 }
405 } 418 }
406 419
407 data->use_xrandr = xrandr_major * 100 + xrandr_minor; 420 data->use_xrandr = xrandr_major * 100 + xrandr_minor;
408 data->saved_size = XRRConfigCurrentConfiguration(data->screen_config, &data->saved_rotation); 421 data->saved_size =
422 XRRConfigCurrentConfiguration(data->screen_config,
423 &data->saved_rotation);
409 data->saved_rate = XRRConfigCurrentRate(data->screen_config); 424 data->saved_rate = XRRConfigCurrentRate(data->screen_config);
410 } 425 }
411 } 426 }
412 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ 427 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
413 428
416 if (!data->use_xrandr && 431 if (!data->use_xrandr &&
417 #if SDL_VIDEO_DRIVER_X11_XINERAMA 432 #if SDL_VIDEO_DRIVER_X11_XINERAMA
418 (!data->use_xinerama || data->xinerama_info.screen_number == 0) && 433 (!data->use_xinerama || data->xinerama_info.screen_number == 0) &&
419 #endif 434 #endif
420 CheckVidMode(display, &vm_major, &vm_minor) && 435 CheckVidMode(display, &vm_major, &vm_minor) &&
421 SDL_NAME(XF86VidModeGetAllModeLines)(display, data->screen, &nmodes, &modes) ) 436 SDL_NAME(XF86VidModeGetAllModeLines) (display, data->screen, &nmodes,
422 { 437 &modes)) {
423 int i; 438 int i;
424 439
425 #ifdef X11MODES_DEBUG 440 #ifdef X11MODES_DEBUG
426 printf("VidMode modes: (unsorted)\n"); 441 printf("VidMode modes: (unsorted)\n");
427 for (i = 0; i < nmodes; ++i) { 442 for (i = 0; i < nmodes; ++i) {
428 printf("Mode %d: %d x %d @ %d\n", i, 443 printf("Mode %d: %d x %d @ %d\n", i,
429 modes[i]->hdisplay, modes[i]->vdisplay, 444 modes[i]->hdisplay, modes[i]->vdisplay,
430 calculate_rate(modes[i])); 445 calculate_rate(modes[i]));
431 } 446 }
432 #endif 447 #endif
433 for (i = 0; i < nmodes; ++i) { 448 for (i = 0; i < nmodes; ++i) {
434 mode.w = modes[i]->hdisplay; 449 mode.w = modes[i]->hdisplay;
435 mode.h = modes[i]->vdisplay; 450 mode.h = modes[i]->vdisplay;
446 if (!data->use_xrandr && !data->use_vidmode) { 461 if (!data->use_xrandr && !data->use_vidmode) {
447 mode.w = screen_w; 462 mode.w = screen_w;
448 mode.h = screen_h; 463 mode.h = screen_h;
449 mode.refresh_rate = 0; 464 mode.refresh_rate = 0;
450 SDL_AddDisplayMode(_this->current_display, &mode); 465 SDL_AddDisplayMode(_this->current_display, &mode);
451 } 466 }
452
453 #ifdef X11MODES_DEBUG 467 #ifdef X11MODES_DEBUG
454 if (data->use_xinerama) { 468 if (data->use_xinerama) {
455 printf("Xinerama is enabled\n"); 469 printf("Xinerama is enabled\n");
456 } 470 }
457 471
464 } 478 }
465 #endif /* X11MODES_DEBUG */ 479 #endif /* X11MODES_DEBUG */
466 } 480 }
467 481
468 static void 482 static void
469 get_real_resolution(Display *display, SDL_DisplayData *data, int *w, int *h, int *rate) 483 get_real_resolution(Display * display, SDL_DisplayData * data, int *w, int *h,
484 int *rate)
470 { 485 {
471 #if SDL_VIDEO_DRIVER_X11_XRANDR 486 #if SDL_VIDEO_DRIVER_X11_XRANDR
472 if (data->use_xrandr) { 487 if (data->use_xrandr) {
473 int nsizes; 488 int nsizes;
474 XRRScreenSize *sizes; 489 XRRScreenSize *sizes;
475 490
476 sizes = XRRConfigSizes(data->screen_config, &nsizes); 491 sizes = XRRConfigSizes(data->screen_config, &nsizes);
477 if (nsizes > 0) { 492 if (nsizes > 0) {
478 int cur_size; 493 int cur_size;
479 Rotation cur_rotation; 494 Rotation cur_rotation;
480 495
481 cur_size = XRRConfigCurrentConfiguration(data->screen_config, &cur_rotation); 496 cur_size =
497 XRRConfigCurrentConfiguration(data->screen_config,
498 &cur_rotation);
482 *w = sizes[cur_size].width; 499 *w = sizes[cur_size].width;
483 *h = sizes[cur_size].height; 500 *h = sizes[cur_size].height;
484 *rate = XRRConfigCurrentRate(data->screen_config); 501 *rate = XRRConfigCurrentRate(data->screen_config);
485 #ifdef X11MODES_DEBUG 502 #ifdef X11MODES_DEBUG
486 fprintf(stderr, "XRANDR: get_real_resolution: w = %d, h = %d, rate = %d\n", *w, *h, *rate); 503 fprintf(stderr,
504 "XRANDR: get_real_resolution: w = %d, h = %d, rate = %d\n",
505 *w, *h, *rate);
487 #endif 506 #endif
488 return; 507 return;
489 } 508 }
490 } 509 }
491 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ 510 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
492 511
493 #if SDL_VIDEO_DRIVER_X11_VIDMODE 512 #if SDL_VIDEO_DRIVER_X11_VIDMODE
494 if (data->use_vidmode) { 513 if (data->use_vidmode) {
495 SDL_NAME(XF86VidModeModeInfo) mode; 514 SDL_NAME(XF86VidModeModeInfo) mode;
496 515
497 if (SDL_NAME(XF86VidModeGetModeInfo)(display, data->screen, &mode)) { 516 if (SDL_NAME(XF86VidModeGetModeInfo) (display, data->screen, &mode)) {
498 *w = mode.hdisplay; 517 *w = mode.hdisplay;
499 *h = mode.vdisplay; 518 *h = mode.vdisplay;
500 *rate = calculate_rate(&mode); 519 *rate = calculate_rate(&mode);
501 return; 520 return;
502 } 521 }
516 *h = DisplayHeight(display, data->screen); 535 *h = DisplayHeight(display, data->screen);
517 *rate = 0; 536 *rate = 0;
518 } 537 }
519 538
520 static void 539 static void
521 set_best_resolution(Display *display, SDL_DisplayData *data, int w, int h, int rate) 540 set_best_resolution(Display * display, SDL_DisplayData * data, int w, int h,
541 int rate)
522 { 542 {
523 int real_w, real_h, real_rate; 543 int real_w, real_h, real_rate;
524 544
525 /* check current mode so we can avoid uneccessary mode changes */ 545 /* check current mode so we can avoid uneccessary mode changes */
526 get_real_resolution(display, data, &real_w, &real_h, &real_rate); 546 get_real_resolution(display, data, &real_w, &real_h, &real_rate);
527 if (w == real_w && h == real_h && (!rate || rate == real_rate)) { 547 if (w == real_w && h == real_h && (!rate || rate == real_rate)) {
528 return; 548 return;
529 } 549 }
530
531 #if SDL_VIDEO_DRIVER_X11_XRANDR 550 #if SDL_VIDEO_DRIVER_X11_XRANDR
532 if (data->use_xrandr) { 551 if (data->use_xrandr) {
533 #ifdef X11MODES_DEBUG 552 #ifdef X11MODES_DEBUG
534 fprintf(stderr, "XRANDR: set_best_resolution(): w = %d, h = %d\n", 553 fprintf(stderr, "XRANDR: set_best_resolution(): w = %d, h = %d\n",
535 w, h); 554 w, h);
551 best = i; 570 best = i;
552 break; 571 break;
553 } 572 }
554 if (best == -1 || 573 if (best == -1 ||
555 (sizes[i].width < sizes[best].width) || 574 (sizes[i].width < sizes[best].width) ||
556 (sizes[i].width == sizes[best].width && sizes[i].height < sizes[best].height)) { 575 (sizes[i].width == sizes[best].width
576 && sizes[i].height < sizes[best].height)) {
557 best = i; 577 best = i;
558 } 578 }
559 } 579 }
560 580
561 if (best >= 0) { 581 if (best >= 0) {
570 /* Higher is better, right? */ 590 /* Higher is better, right? */
571 if (rates[i] > best_rate) { 591 if (rates[i] > best_rate) {
572 best_rate = rates[i]; 592 best_rate = rates[i];
573 } 593 }
574 } else { 594 } else {
575 if (SDL_abs(rates[i]-rate) < SDL_abs(best_rate-rate)) { 595 if (SDL_abs(rates[i] - rate) < SDL_abs(best_rate - rate)) {
576 best_rate = rates[i]; 596 best_rate = rates[i];
577 } 597 }
578 } 598 }
579 } 599 }
580 XRRSetScreenConfigAndRate(display, data->screen_config, RootWindow(display, data->screen), best, data->saved_rotation, best_rate, CurrentTime); 600 XRRSetScreenConfigAndRate(display, data->screen_config,
601 RootWindow(display, data->screen), best,
602 data->saved_rotation, best_rate,
603 CurrentTime);
581 } 604 }
582 return; 605 return;
583 } 606 }
584 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ 607 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
585 608
586 #if SDL_VIDEO_DRIVER_X11_VIDMODE 609 #if SDL_VIDEO_DRIVER_X11_VIDMODE
587 if (data->use_vidmode) { 610 if (data->use_vidmode) {
588 SDL_NAME(XF86VidModeModeInfo) **modes; 611 SDL_NAME(XF86VidModeModeInfo) ** modes;
589 int i, nmodes; 612 int i, nmodes;
590 int best; 613 int best;
591 614
592 if (SDL_NAME(XF86VidModeGetAllModeLines)(display,data->screen,&nmodes,&modes)) { 615 if (SDL_NAME(XF86VidModeGetAllModeLines)
616 (display, data->screen, &nmodes, &modes)) {
593 best = -1; 617 best = -1;
594 for (i = 0; i < nmodes; ++i) { 618 for (i = 0; i < nmodes; ++i) {
595 if (modes[i]->hdisplay < w || modes[i]->vdisplay < h) { 619 if (modes[i]->hdisplay < w || modes[i]->vdisplay < h) {
596 continue; 620 continue;
597 } 621 }
598 if (best == -1 || 622 if (best == -1 ||
599 (modes[i]->hdisplay < modes[best]->hdisplay) || 623 (modes[i]->hdisplay < modes[best]->hdisplay) ||
600 (modes[i]->hdisplay == modes[best]->hdisplay && modes[i]->vdisplay < modes[best]->vdisplay)) { 624 (modes[i]->hdisplay == modes[best]->hdisplay
625 && modes[i]->vdisplay < modes[best]->vdisplay)) {
601 best = i; 626 best = i;
602 continue; 627 continue;
603 } 628 }
604 if ((modes[i]->hdisplay == modes[best]->hdisplay) && 629 if ((modes[i]->hdisplay == modes[best]->hdisplay) &&
605 (modes[i]->vdisplay == modes[best]->vdisplay)) { 630 (modes[i]->vdisplay == modes[best]->vdisplay)) {
606 if (!rate) { 631 if (!rate) {
607 /* Higher is better, right? */ 632 /* Higher is better, right? */
608 if (calculate_rate(modes[i]) > calculate_rate(modes[best])) { 633 if (calculate_rate(modes[i]) >
634 calculate_rate(modes[best])) {
609 best = i; 635 best = i;
610 } 636 }
611 } else { 637 } else {
612 if (SDL_abs(calculate_rate(modes[i])-rate) < SDL_abs(calculate_rate(modes[best])-rate)) { 638 if (SDL_abs(calculate_rate(modes[i]) - rate) <
639 SDL_abs(calculate_rate(modes[best]) - rate)) {
613 best = i; 640 best = i;
614 } 641 }
615 } 642 }
616 } 643 }
617 } 644 }
618 if (best >= 0) { 645 if (best >= 0) {
619 #ifdef X11MODES_DEBUG 646 #ifdef X11MODES_DEBUG
620 printf("Best Mode %d: %d x %d @ %d\n", best, 647 printf("Best Mode %d: %d x %d @ %d\n", best,
621 modes[best]->hdisplay, modes[best]->vdisplay, 648 modes[best]->hdisplay, modes[best]->vdisplay,
622 calculate_rate(modes[best])); 649 calculate_rate(modes[best]));
623 #endif 650 #endif
624 SDL_NAME(XF86VidModeSwitchToMode)(display, data->screen, modes[best]); 651 SDL_NAME(XF86VidModeSwitchToMode) (display, data->screen,
652 modes[best]);
625 } 653 }
626 XFree(modes); 654 XFree(modes);
627 } 655 }
628 return; 656 return;
629 } 657 }