From 3936e3018dd2b0948a1be69ac748abb798f9f208 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 23 Jun 2018 16:22:29 +0300 Subject: [PATCH] - added window position and size restoration to SDL backend --- src/posix/sdl/i_input.cpp | 18 ++---------- src/posix/sdl/sdlglvideo.cpp | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/posix/sdl/i_input.cpp b/src/posix/sdl/i_input.cpp index 88c43050c..2c8160e68 100644 --- a/src/posix/sdl/i_input.cpp +++ b/src/posix/sdl/i_input.cpp @@ -43,7 +43,6 @@ #include "c_console.h" #include "c_dispatch.h" #include "dikeys.h" -#include "s_sound.h" #include "events.h" static void I_CheckGUICapture (); @@ -57,7 +56,6 @@ extern int paused; CVAR (Bool, use_mouse, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Bool, m_noprescale, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Bool, m_filter, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -CVAR (Bool, i_soundinbackground, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) EXTERN_CVAR (Bool, fullscreen) @@ -305,20 +303,8 @@ void MessagePump (const SDL_Event &sev) exit (0); case SDL_WINDOWEVENT: - switch (sev.window.event) - { - extern bool AppActive; - - case SDL_WINDOWEVENT_FOCUS_GAINED: - S_SetSoundPaused(1); - AppActive = true; - break; - - case SDL_WINDOWEVENT_FOCUS_LOST: - S_SetSoundPaused(i_soundinbackground); - AppActive = false; - break; - } + extern void ProcessSDLWindowEvent(const SDL_WindowEvent &); + ProcessSDLWindowEvent(sev.window); break; case SDL_MOUSEBUTTONDOWN: diff --git a/src/posix/sdl/sdlglvideo.cpp b/src/posix/sdl/sdlglvideo.cpp index 4e7e0fbec..d6f495c6d 100644 --- a/src/posix/sdl/sdlglvideo.cpp +++ b/src/posix/sdl/sdlglvideo.cpp @@ -41,6 +41,7 @@ #include "v_video.h" #include "version.h" #include "c_console.h" +#include "s_sound.h" #include "videomodes.h" #include "hardware.h" @@ -84,6 +85,13 @@ CUSTOM_CVAR(Bool, gl_es, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCA Printf("This won't take effect until " GAMENAME " is restarted.\n"); } +CVAR(Int, win_x, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Int, win_y, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Int, win_w, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Int, win_h, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) + +CVAR(Bool, i_soundinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) + CVAR (Int, vid_adapter, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // PRIVATE DATA DEFINITIONS ------------------------------------------------ @@ -226,6 +234,20 @@ SystemFrameBuffer::SystemFrameBuffer (void *, bool fullscreen) m_supportsGamma = -1 != SDL_GetWindowGammaRamp(Screen, m_origGamma[0], m_origGamma[1], m_origGamma[2] ); + + if (!fullscreen) + { + if (win_x >= 0 && win_y >= 0) + { + SDL_SetWindowPosition(Screen, win_x, win_y); + } + + if (win_h > 320 && win_w > 200) + { + SDL_SetWindowSize(Screen, win_w, win_h); + } + } + return; } @@ -328,6 +350,41 @@ int SystemFrameBuffer::GetClientHeight() } +void ProcessSDLWindowEvent(const SDL_WindowEvent &event) +{ + switch (event.event) + { + extern bool AppActive; + + case SDL_WINDOWEVENT_FOCUS_GAINED: + S_SetSoundPaused(1); + AppActive = true; + break; + + case SDL_WINDOWEVENT_FOCUS_LOST: + S_SetSoundPaused(i_soundinbackground); + AppActive = false; + break; + + case SDL_WINDOWEVENT_MOVED: + if (!fullscreen) + { + win_x = event.data1; + win_y = event.data2; + } + break; + + case SDL_WINDOWEVENT_RESIZED: + if (!fullscreen) + { + win_w = event.data1; + win_h = event.data2; + } + break; + } +} + + // each platform has its own specific version of this function. void I_SetWindowTitle(const char* caption) {