comparison src/video/x11/SDL_x11video.c @ 497:bb2d68294e81

Cleaned up the SDL_VIDEO_WINDOW_POS variable support
author Sam Lantinga <slouken@libsdl.org>
date Mon, 16 Sep 2002 08:22:25 +0000
parents ffa4ca907c67
children f480ecd70499
comparison
equal deleted inserted replaced
496:864a66f028d8 497:bb2d68294e81
511 SDL_GC = 0; 511 SDL_GC = 0;
512 } 512 }
513 } 513 }
514 } 514 }
515 515
516 static SDL_bool X11_WindowPosition(_THIS, int *x, int *y, int w, int h)
517 {
518 const char *window = getenv("SDL_VIDEO_WINDOW_POS");
519 const char *center = getenv("SDL_VIDEO_CENTERED");
520 if ( window ) {
521 if ( sscanf(window, "%d,%d", x, y) == 2 ) {
522 return SDL_TRUE;
523 }
524 if ( strcmp(window, "center") == 0 ) {
525 center = window;
526 }
527 }
528 if ( center ) {
529 *x = (DisplayWidth(SDL_Display, SDL_Screen) - w)/2;
530 *y = (DisplayHeight(SDL_Display, SDL_Screen) - h)/2;
531 return SDL_TRUE;
532 }
533 return SDL_FALSE;
534 }
535
516 static void X11_SetSizeHints(_THIS, int w, int h, Uint32 flags) 536 static void X11_SetSizeHints(_THIS, int w, int h, Uint32 flags)
517 { 537 {
518 XSizeHints *hints; 538 XSizeHints *hints;
519 539
520 hints = XAllocSizeHints(); 540 hints = XAllocSizeHints();
533 hints->x = 0; 553 hints->x = 0;
534 hints->y = 0; 554 hints->y = 0;
535 hints->flags |= USPosition; 555 hints->flags |= USPosition;
536 } else 556 } else
537 /* Center it, if desired */ 557 /* Center it, if desired */
538 if ( getenv("SDL_VIDEO_CENTERED") ) { 558 if ( X11_WindowPosition(this, &hints->x, &hints->y, w, h) ) {
539 int display_w, display_h;
540
541 display_w = DisplayWidth(SDL_Display, SDL_Screen);
542 display_h = DisplayHeight(SDL_Display, SDL_Screen);
543 hints->x = (display_w - w)/2;
544 hints->y = (display_h - h)/2;
545 hints->flags |= USPosition; 559 hints->flags |= USPosition;
546 XMoveWindow(SDL_Display, WMwindow, hints->x, hints->y); 560 XMoveWindow(SDL_Display, WMwindow, hints->x, hints->y);
547 561
548 /* Flush the resize event so we don't catch it later */ 562 /* Flush the resize event so we don't catch it later */
549 XSync(SDL_Display, True); 563 XSync(SDL_Display, True);
868 X11_WaitMapped(this, WMwindow); 882 X11_WaitMapped(this, WMwindow);
869 if ( flags & SDL_FULLSCREEN ) { 883 if ( flags & SDL_FULLSCREEN ) {
870 screen->flags |= SDL_FULLSCREEN; 884 screen->flags |= SDL_FULLSCREEN;
871 X11_EnterFullScreen(this); 885 X11_EnterFullScreen(this);
872 } else { 886 } else {
873 /* Position standalone window based on user request. --ryan. */
874 const char *envr = getenv("SDL_WINDOW_POS");
875 if (envr != NULL) {
876 int xscreen = DefaultScreen(SDL_Display);
877 if (strcmp(envr, "center") == 0) {
878 int disw = DisplayWidth(SDL_Display, xscreen);
879 int dish = DisplayHeight(SDL_Display, xscreen);
880 int centerx = (disw - current_w) / 2;
881 int centery = (dish - current_h) / 2;
882 XMoveWindow(SDL_Display, WMwindow, centerx, centery);
883 }
884 }
885 screen->flags &= ~SDL_FULLSCREEN; 887 screen->flags &= ~SDL_FULLSCREEN;
886 } 888 }
887 } 889 }
888 return(0); 890 return(0);
889 } 891 }