X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=vid_sdl.c;h=22fd13ebf975fa3a74145711e7b3a9095b415e41;hb=405615a2dfc40a4cdb151467c37e87cac13f333e;hp=ba5a6fd7662caa2fd90bd3fc4b40a8c6b6394eb1;hpb=0275b3fc9bbf9bea9dd5b7740ba34295a7514424;p=xonotic%2Fdarkplaces.git diff --git a/vid_sdl.c b/vid_sdl.c index ba5a6fd7..22fd13eb 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -87,7 +87,7 @@ static int video_bpp; static SDL_Surface *screen; static int video_flags; #else -static SDL_GLContext *context; +static SDL_GLContext context; static SDL_Window *window; static int window_flags; #endif @@ -2414,6 +2414,50 @@ static void VID_OutputVersion(void) version.major, version.minor, version.patch ); } +#ifdef WIN32 +static void AdjustWindowBounds(viddef_mode_t *mode, RECT *rect) +{ + LONG width = mode->width; // vid_width + LONG height = mode->height; // vid_height + + // adjust width and height for the space occupied by window decorators (title bar, borders) + rect->top = 0; + rect->left = 0; + rect->right = width; + rect->bottom = height; + AdjustWindowRectEx(rect, WS_CAPTION|WS_THICKFRAME, false, 0); + + RECT workArea; + SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0); + int workWidth = workArea.right - workArea.left; + int workHeight = workArea.bottom - workArea.top; + + // SDL forces the window height to be <= screen height - 27px (on Win8.1 - probably intended for the title bar) + // If the task bar is docked to the the left screen border and we move the window to negative y, + // there would be some part of the regular desktop visible on the bottom of the screen. + int titleBarPixels = 2; + int screenHeight = GetSystemMetrics(SM_CYSCREEN); + if (screenHeight == workHeight) + titleBarPixels = -rect->top; + + //Con_Printf("window mode: %dx%d, workArea: %d/%d-%d/%d (%dx%d), title: %d\n", width, height, workArea.left, workArea.top, workArea.right, workArea.bottom, workArea.right - workArea.left, workArea.bottom - workArea.top, titleBarPixels); + + // if height and width matches the physical or previously adjusted screen height and width, adjust it to available desktop area + if ((width == GetSystemMetrics(SM_CXSCREEN) || width == workWidth) && (height == screenHeight || height == workHeight - titleBarPixels)) + { + rect->left = workArea.left; + mode->width = workWidth; + rect->top = workArea.top + titleBarPixels; + mode->height = workHeight - titleBarPixels; + } + else + { + rect->left = workArea.left + max(0, (workWidth - width) / 2); + rect->top = workArea.top + max(0, (workHeight - height) / 2); + } +} +#endif + static qboolean VID_InitModeGL(viddef_mode_t *mode) { #if SDL_MAJOR_VERSION == 1 @@ -2421,6 +2465,8 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode) int flags = SDL_OPENGL; #else int windowflags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL; + int xPos = SDL_WINDOWPOS_UNDEFINED; + int yPos = SDL_WINDOWPOS_UNDEFINED; #endif #ifndef USE_GLES2 int i; @@ -2506,11 +2552,24 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode) { if (mode->fullscreen) { if (vid_desktopfullscreen.integer) + { + vid_mode_t *m = VID_GetDesktopMode(); + mode->width = m->width; + mode->height = m->height; windowflags |= SDL_WINDOW_FULLSCREEN_DESKTOP; + } else windowflags |= SDL_WINDOW_FULLSCREEN; vid_isfullscreen = true; } + else { +#ifdef WIN32 + RECT rect; + AdjustWindowBounds(mode, &rect); + xPos = rect.left; + yPos = rect.top; +#endif + } } #endif //flags |= SDL_HWSURFACE; @@ -2567,7 +2626,7 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode) mode->height = screen->h; #else window_flags = windowflags; - window = SDL_CreateWindow(gamename, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, mode->width, mode->height, windowflags); + window = SDL_CreateWindow(gamename, xPos, yPos, mode->width, mode->height, windowflags); if (window == NULL) { Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError()); @@ -2842,6 +2901,7 @@ void VID_Finish (void) vid_usevsync = (vid_vsync.integer && !cls.timedemo); if (vid_usingvsync != vid_usevsync) { + vid_usingvsync = vid_usevsync; if (SDL_GL_SetSwapInterval(vid_usevsync != 0) >= 0) Con_DPrintf("Vsync %s\n", vid_usevsync ? "activated" : "deactivated"); else