comparison src/video/x11/SDL_x11modes.c @ 1746:a0ddae8b43cf

Disable the XRandR extension by default, since KDE maximizes windows which are larger than the new resolution, and then doesn't restore their size and positition when the old resolution is restored. The extension can be enabled with the environment variable SDL_VIDEO_X11_XRANDR=1
author Sam Lantinga <slouken@libsdl.org>
date Sat, 29 Apr 2006 17:54:32 +0000
parents 5cf11b00b900
children e75d0cbcf3c8
comparison
equal deleted inserted replaced
1745:741dc4e89f3a 1746:a0ddae8b43cf
358 } 358 }
359 359
360 /* Global for the error handler */ 360 /* Global for the error handler */
361 int vm_event, vm_error = -1; 361 int vm_event, vm_error = -1;
362 362
363 #if SDL_VIDEO_DRIVER_X11_XRANDR
364 static int CheckXRandR(_THIS, int *major, int *minor)
365 {
366 char *env;
367
368 /* Default the extension not available */
369 *major = *minor = 0;
370
371 /* Allow environment override */
372 env = getenv("SDL_VIDEO_X11_XRANDR");
373 if ( env && !SDL_atoi(env) ) {
374 return 0;
375 }
376
377 /* This defaults off now, due to KDE window maximize problems */
378 if ( !env ) {
379 return 0;
380 }
381
382 if ( !SDL_X11_HAVE_XRANDR ) {
383 return 0;
384 }
385
386 /* Query the extension version */
387 if ( !XRRQueryVersion(SDL_Display, major, minor) ) {
388 return 0;
389 }
390 return 1;
391 }
392 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
393
394 #if SDL_VIDEO_DRIVER_X11_VIDMODE
395 static int CheckVidMode(_THIS, int *major, int *minor)
396 {
397 char *env;
398
399 /* Default the extension not available */
400 *major = *minor = 0;
401
402 /* Allow environment override */
403 env = getenv("SDL_VIDEO_X11_VIDMODE");
404 if ( env && !SDL_atoi(env) ) {
405 return 0;
406 }
407
408 /* Metro-X 4.3.0 and earlier has a broken implementation of
409 XF86VidModeGetAllModeLines() - it hangs the client.
410 */
411 if ( SDL_strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) {
412 FILE *metro_fp;
413
414 metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
415 if ( metro_fp != NULL ) {
416 int major, minor, patch, version;
417 major = 0; minor = 0; patch = 0;
418 fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch);
419 fclose(metro_fp);
420 version = major*100+minor*10+patch;
421 if ( version < 431 ) {
422 return 0;
423 }
424 }
425 }
426
427 /* Query the extension version */
428 if ( !SDL_NAME(XF86VidModeQueryExtension)(SDL_Display, &vm_event, &vm_error) ||
429 !SDL_NAME(XF86VidModeQueryVersion)(SDL_Display, major, minor) ) {
430 return 0;
431 }
432 return 1;
433 }
434 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
435
436 #if SDL_VIDEO_DRIVER_X11_XME
437 static int CheckXME(_THIS, int *major, int *minor)
438 {
439 char *env;
440
441 /* Default the extension not available */
442 *major = *minor = 0;
443
444 /* Allow environment override */
445 env = getenv("SDL_VIDEO_X11_VIDMODE");
446 if ( env && !SDL_atoi(env) ) {
447 return 0;
448 }
449
450 /* Query the extension version */
451 if ( !XiGMiscQueryVersion(SDL_Display, major, minor) ) {
452 return 0;
453 }
454 return 1;
455 }
456 #endif /* SDL_VIDEO_DRIVER_X11_XME */
457
363 int X11_GetVideoModes(_THIS) 458 int X11_GetVideoModes(_THIS)
364 { 459 {
460 #if SDL_VIDEO_DRIVER_X11_XRANDR
461 int xrandr_major, xrandr_minor;
462 int nsizes;
463 XRRScreenSize *sizes;
464 #endif
365 #if SDL_VIDEO_DRIVER_X11_VIDMODE 465 #if SDL_VIDEO_DRIVER_X11_VIDMODE
366 int buggy_X11;
367 int vm_major, vm_minor; 466 int vm_major, vm_minor;
368 int nmodes; 467 int nmodes;
369 SDL_NAME(XF86VidModeModeInfo) **modes; 468 SDL_NAME(XF86VidModeModeInfo) **modes;
370 #endif 469 #endif
371 #if SDL_VIDEO_DRIVER_X11_XME 470 #if SDL_VIDEO_DRIVER_X11_XME
372 int xme_major, xme_minor; 471 int xme_major, xme_minor;
373 int ractive, nummodes; 472 int ractive, nummodes;
374 XiGMiscResolutionInfo *modelist; 473 XiGMiscResolutionInfo *modelist;
375 #endif 474 #endif
376 #if SDL_VIDEO_DRIVER_X11_XRANDR
377 int xrandr_major, xrandr_minor;
378 int nsizes;
379 XRRScreenSize *sizes;
380 #endif
381 int i, n; 475 int i, n;
382 int screen_w; 476 int screen_w;
383 int screen_h; 477 int screen_h;
384 478
385 vm_error = -1;
386 use_vidmode = 0; 479 use_vidmode = 0;
387 use_xrandr = 0; 480 use_xrandr = 0;
388 screen_w = DisplayWidth(SDL_Display, SDL_Screen); 481 screen_w = DisplayWidth(SDL_Display, SDL_Screen);
389 screen_h = DisplayHeight(SDL_Display, SDL_Screen); 482 screen_h = DisplayHeight(SDL_Display, SDL_Screen);
390 483
484 #if SDL_VIDEO_DRIVER_X11_XRANDR
391 /* XRandR */ 485 /* XRandR */
392 #if SDL_VIDEO_DRIVER_X11_XRANDR
393 /* require at least XRandR v1.0 (arbitrary) */ 486 /* require at least XRandR v1.0 (arbitrary) */
394 if ( ( SDL_X11_HAVE_XRANDR ) && 487 if ( CheckXRandR(this, &xrandr_major, &xrandr_minor) && (xrandr_major >= 1) )
395 ( getenv("SDL_VIDEO_X11_NO_XRANDR") == NULL ) && 488 {
396 ( XRRQueryVersion(SDL_Display, &xrandr_major, &xrandr_minor) ) &&
397 ( xrandr_major >= 1 ) ) {
398
399 #ifdef XRANDR_DEBUG 489 #ifdef XRANDR_DEBUG
400 fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n", 490 fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n",
401 xrandr_major, xrandr_minor); 491 xrandr_major, xrandr_minor);
402 #endif 492 #endif
403 493
435 } 525 }
436 } 526 }
437 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */ 527 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
438 528
439 #if SDL_VIDEO_DRIVER_X11_VIDMODE 529 #if SDL_VIDEO_DRIVER_X11_VIDMODE
440 /* Metro-X 4.3.0 and earlier has a broken implementation of 530 /* XVidMode */
441 XF86VidModeGetAllModeLines() - it hangs the client. 531 if ( !use_xrandr && CheckVidMode(this, &vm_major, &vm_minor) &&
442 */ 532 SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) )
443 buggy_X11 = 0; 533 {
444 if ( SDL_strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) {
445 FILE *metro_fp;
446
447 metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
448 if ( metro_fp != NULL ) {
449 int major, minor, patch, version;
450 major = 0; minor = 0; patch = 0;
451 fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch);
452 version = major*100+minor*10+patch;
453 if ( version < 431 ) {
454 buggy_X11 = 1;
455 }
456 fclose(metro_fp);
457 }
458 }
459 #if 0 /* Let's try this again... hopefully X servers have improved... */
460 #if defined(__alpha__) || defined(__sparc64__) || defined(__powerpc__)
461 /* The alpha, sparc64 and PPC XFree86 servers are also buggy */
462 buggy_X11 = 1;
463 #endif
464 #endif
465 /* Enumerate the available fullscreen modes */
466 if ( ! buggy_X11 ) {
467 if ( SDL_NAME(XF86VidModeQueryExtension)(SDL_Display, &vm_event, &vm_error) &&
468 SDL_NAME(XF86VidModeQueryVersion)(SDL_Display, &vm_major, &vm_minor) ) {
469 #ifdef BROKEN_XFREE86_4001
470 #ifdef X_XF86VidModeGetDotClocks /* Compiled under XFree86 4.0 */
471 /* Earlier X servers hang when doing vidmode */
472 if ( vm_major < 2 ) {
473 #ifdef XFREE86_DEBUG
474 printf("Compiled under XFree86 4.0, server is XFree86 3.X\n");
475 #endif
476 buggy_X11 = 1;
477 }
478 #else
479 /* XFree86 3.X code works with XFree86 4.0 servers */;
480 #endif /* XFree86 4.0 */
481 #endif /* XFree86 4.02 and newer are fixed wrt backwards compatibility */
482 } else {
483 buggy_X11 = 1;
484 }
485 }
486 if ( ! buggy_X11 && ! use_xrandr &&
487 SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) ) {
488
489 #ifdef XFREE86_DEBUG 534 #ifdef XFREE86_DEBUG
490 printf("Available modes: (sorted)\n"); 535 printf("Available modes: (sorted)\n");
491 for ( i = 0; i < nmodes; ++i ) { 536 for ( i = 0; i < nmodes; ++i ) {
492 printf("Mode %d: %d x %d @ %d\n", i, 537 printf("Mode %d: %d x %d @ %d\n", i,
493 modes[i]->hdisplay, modes[i]->vdisplay, 538 modes[i]->hdisplay, modes[i]->vdisplay,
546 use_vidmode = vm_major * 100 + vm_minor; 591 use_vidmode = vm_major * 100 + vm_minor;
547 save_mode(this); 592 save_mode(this);
548 } 593 }
549 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */ 594 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
550 595
551 /* XiG */
552 #if SDL_VIDEO_DRIVER_X11_XME 596 #if SDL_VIDEO_DRIVER_X11_XME
597 /* XiG */
598 modelist = NULL;
553 /* first lets make sure we have the extension, and it's at least v2.0 */ 599 /* first lets make sure we have the extension, and it's at least v2.0 */
554 if (XiGMiscQueryVersion(SDL_Display, &xme_major, &xme_minor)) { 600 if ( CheckXME(this, &xme_major, &xme_minor) && xme_major >= 2 &&
555 #ifdef XIG_DEBUG 601 (nummodes = XiGMiscQueryResolutions(SDL_Display, SDL_Screen,
556 fprintf(stderr, "XME: XiGMiscQueryVersion: V%d.%d\n", 602 0, /* view */
557 xme_major, xme_minor); 603 &ractive, &modelist)) > 1 )
558 #endif
559 /* work around a XiGMisc bogosity in our version of libXext */
560 if (xme_major == 0 && xme_major == 0) {
561 /* Ideally libxme would spit this out, but the problem is that
562 the right Query func will never be called if using the bogus
563 libXext version.
564 */
565 fprintf(stderr,
566 "XME: If you are using Xi Graphics CDE and a Summit server, you need to\n"
567 "XME: get the libXext update from Xi's ftp site before fullscreen switching\n"
568 "XME: will work. Fullscreen switching is only supported on Summit Servers\n");
569 }
570 } else {
571 /* not there. Bummer. */
572 xme_major = xme_minor = 0;
573 }
574
575 modelist = NULL;
576 if (xme_major >= 2 && (nummodes = XiGMiscQueryResolutions(SDL_Display,
577 SDL_Screen,
578 0, /* view */
579 &ractive,
580 &modelist)) > 1)
581 { /* then we actually have some */ 604 { /* then we actually have some */
582 int j; 605 int j;
583 606
584 #ifdef XIG_DEBUG 607 #ifdef XIG_DEBUG
585 fprintf(stderr, "XME: nummodes = %d, active mode = %d\n", 608 fprintf(stderr, "XME: nummodes = %d, active mode = %d\n",
681 SDL_modelist[n] = NULL; 704 SDL_modelist[n] = NULL;
682 } 705 }
683 } 706 }
684 707
685 #if defined(XFREE86_DEBUG) || defined(XIG_DEBUG) 708 #if defined(XFREE86_DEBUG) || defined(XIG_DEBUG)
709 if ( use_xrandr ) {
710 printf("XRandR is enabled\n");
711 }
712
686 if ( use_vidmode ) { 713 if ( use_vidmode ) {
687 printf("XFree86 VidMode is enabled\n"); 714 printf("XFree86 VidMode is enabled\n");
688 } 715 }
689 716
690 #if SDL_VIDEO_DRIVER_X11_XME 717 #if SDL_VIDEO_DRIVER_X11_XME