mirror of https://github.com/stella-emu/stella.git
make Stella remember the last window position (now Center option makes a difference!)
This commit is contained in:
parent
d377d2a9a2
commit
6fc3863ef9
|
@ -31,7 +31,8 @@
|
||||||
FrameBufferSDL2::FrameBufferSDL2(OSystem& osystem)
|
FrameBufferSDL2::FrameBufferSDL2(OSystem& osystem)
|
||||||
: FrameBuffer(osystem),
|
: FrameBuffer(osystem),
|
||||||
myWindow(nullptr),
|
myWindow(nullptr),
|
||||||
myRenderer(nullptr)
|
myRenderer(nullptr),
|
||||||
|
myCenter(false)
|
||||||
{
|
{
|
||||||
ASSERT_MAIN_THREAD;
|
ASSERT_MAIN_THREAD;
|
||||||
|
|
||||||
|
@ -88,11 +89,11 @@ void FrameBufferSDL2::queryHardware(vector<Common::Size>& fullscreenRes,
|
||||||
ASSERT_MAIN_THREAD;
|
ASSERT_MAIN_THREAD;
|
||||||
|
|
||||||
// Get number of displays (for most systems, this will be '1')
|
// Get number of displays (for most systems, this will be '1')
|
||||||
int maxDisplays = SDL_GetNumVideoDisplays();
|
myNumDisplays = SDL_GetNumVideoDisplays();
|
||||||
|
|
||||||
// First get the maximum fullscreen desktop resolution
|
// First get the maximum fullscreen desktop resolution
|
||||||
SDL_DisplayMode display;
|
SDL_DisplayMode display;
|
||||||
for(int i = 0; i < maxDisplays; ++i)
|
for(int i = 0; i < myNumDisplays; ++i)
|
||||||
{
|
{
|
||||||
SDL_GetDesktopDisplayMode(i, &display);
|
SDL_GetDesktopDisplayMode(i, &display);
|
||||||
fullscreenRes.emplace_back(display.w, display.h);
|
fullscreenRes.emplace_back(display.w, display.h);
|
||||||
|
@ -102,14 +103,14 @@ void FrameBufferSDL2::queryHardware(vector<Common::Size>& fullscreenRes,
|
||||||
// Try to take into account taskbars, etc, if available
|
// Try to take into account taskbars, etc, if available
|
||||||
#if SDL_VERSION_ATLEAST(2,0,5)
|
#if SDL_VERSION_ATLEAST(2,0,5)
|
||||||
SDL_Rect r;
|
SDL_Rect r;
|
||||||
for(int i = 0; i < maxDisplays; ++i)
|
for(int i = 0; i < myNumDisplays; ++i)
|
||||||
{
|
{
|
||||||
// Display bounds minus dock
|
// Display bounds minus dock
|
||||||
SDL_GetDisplayUsableBounds(i, &r); // Requires SDL-2.0.5 or higher
|
SDL_GetDisplayUsableBounds(i, &r); // Requires SDL-2.0.5 or higher
|
||||||
windowedRes.emplace_back(r.w, r.h);
|
windowedRes.emplace_back(r.w, r.h);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
for(int i = 0; i < maxDisplays; ++i)
|
for(int i = 0; i < myNumDisplays; ++i)
|
||||||
{
|
{
|
||||||
SDL_GetDesktopDisplayMode(i, &display);
|
SDL_GetDesktopDisplayMode(i, &display);
|
||||||
windowedRes.emplace_back(display.w, display.h);
|
windowedRes.emplace_back(display.w, display.h);
|
||||||
|
@ -162,6 +163,27 @@ Int32 FrameBufferSDL2::getCurrentDisplayIndex()
|
||||||
return SDL_GetWindowDisplayIndex(myWindow);
|
return SDL_GetWindowDisplayIndex(myWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
void FrameBufferSDL2::getCurrentWindowPos(int& x, int&y)
|
||||||
|
{
|
||||||
|
ASSERT_MAIN_THREAD;
|
||||||
|
|
||||||
|
if (myCenter ||
|
||||||
|
!myWindow || (SDL_GetWindowFlags(myWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP))
|
||||||
|
{
|
||||||
|
// restore to last saved window position
|
||||||
|
x = myOSystem.settings().getInt("pos.x");
|
||||||
|
y = myOSystem.settings().getInt("pos.y");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// save current window position
|
||||||
|
SDL_GetWindowPosition(myWindow, &x, &y);
|
||||||
|
myOSystem.settings().setValue("pos.x", x);
|
||||||
|
myOSystem.settings().setValue("pos.y", y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode)
|
bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode)
|
||||||
{
|
{
|
||||||
|
@ -171,15 +193,8 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode)
|
||||||
if(SDL_WasInit(SDL_INIT_VIDEO) == 0)
|
if(SDL_WasInit(SDL_INIT_VIDEO) == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Always recreate renderer (some systems need this)
|
|
||||||
if(myRenderer)
|
|
||||||
{
|
|
||||||
SDL_DestroyRenderer(myRenderer);
|
|
||||||
myRenderer = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Int32 displayIndex = mode.fsIndex;
|
Int32 displayIndex = mode.fsIndex;
|
||||||
if(displayIndex == -1)
|
if (displayIndex == -1)
|
||||||
{
|
{
|
||||||
// windowed mode
|
// windowed mode
|
||||||
if (myWindow)
|
if (myWindow)
|
||||||
|
@ -187,16 +202,27 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode)
|
||||||
// Show it on same screen as the previous window
|
// Show it on same screen as the previous window
|
||||||
displayIndex = SDL_GetWindowDisplayIndex(myWindow);
|
displayIndex = SDL_GetWindowDisplayIndex(myWindow);
|
||||||
}
|
}
|
||||||
if(displayIndex < 0)
|
if (displayIndex < 0)
|
||||||
{
|
{
|
||||||
// fallback to the first screen
|
// fallback to the last used screen if still existing
|
||||||
displayIndex = 0;
|
displayIndex = std::min(myNumDisplays, myOSystem.settings().getInt("display"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uInt32 pos = myOSystem.settings().getBool("center")
|
// get current windows position
|
||||||
? SDL_WINDOWPOS_CENTERED_DISPLAY(displayIndex)
|
int posX, posY;
|
||||||
: SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex);
|
getCurrentWindowPos(posX, posY);
|
||||||
|
|
||||||
|
// Always recreate renderer (some systems need this)
|
||||||
|
if(myRenderer)
|
||||||
|
{
|
||||||
|
SDL_DestroyRenderer(myRenderer);
|
||||||
|
myRenderer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
myCenter = myOSystem.settings().getBool("center");
|
||||||
|
if (myCenter)
|
||||||
|
posX = posY = SDL_WINDOWPOS_CENTERED_DISPLAY(displayIndex);
|
||||||
uInt32 flags = mode.fsIndex != -1 ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
uInt32 flags = mode.fsIndex != -1 ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
||||||
|
|
||||||
// macOS seems to have issues with destroying the window, and wants to
|
// macOS seems to have issues with destroying the window, and wants to
|
||||||
|
@ -221,6 +247,7 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode)
|
||||||
{
|
{
|
||||||
// Even though window size stayed the same, the title may have changed
|
// Even though window size stayed the same, the title may have changed
|
||||||
SDL_SetWindowTitle(myWindow, title.c_str());
|
SDL_SetWindowTitle(myWindow, title.c_str());
|
||||||
|
SDL_SetWindowPosition(myWindow, posX, posY);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// macOS wants to *never* re-create the window
|
// macOS wants to *never* re-create the window
|
||||||
|
@ -236,7 +263,7 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode)
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
myWindow = SDL_CreateWindow(title.c_str(), pos, pos,
|
myWindow = SDL_CreateWindow(title.c_str(), posX, posY,
|
||||||
mode.screen.w, mode.screen.h, flags);
|
mode.screen.w, mode.screen.h, flags);
|
||||||
if(myWindow == nullptr)
|
if(myWindow == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -311,6 +338,7 @@ void FrameBufferSDL2::invalidate()
|
||||||
{
|
{
|
||||||
ASSERT_MAIN_THREAD;
|
ASSERT_MAIN_THREAD;
|
||||||
|
|
||||||
|
|
||||||
SDL_RenderClear(myRenderer);
|
SDL_RenderClear(myRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,23 @@ class FrameBufferSDL2 : public FrameBuffer
|
||||||
*/
|
*/
|
||||||
void readPixels(uInt8* buffer, uInt32 pitch, const Common::Rect& rect) const override;
|
void readPixels(uInt8* buffer, uInt32 pitch, const Common::Rect& rect) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
This method is called to query the video hardware for the index
|
||||||
|
of the display the current window is displayed on
|
||||||
|
|
||||||
|
@return the current display index or a negative value if no
|
||||||
|
window is displayed
|
||||||
|
*/
|
||||||
|
Int32 getCurrentDisplayIndex() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
This method is called to query the current window position.
|
||||||
|
|
||||||
|
@param x The x-position retrieved
|
||||||
|
@param y The y-position retrieved
|
||||||
|
*/
|
||||||
|
void getCurrentWindowPos(int& x, int& y) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Clear the frame buffer
|
Clear the frame buffer
|
||||||
*/
|
*/
|
||||||
|
@ -119,15 +136,6 @@ class FrameBufferSDL2 : public FrameBuffer
|
||||||
vector<Common::Size>& windowedRes,
|
vector<Common::Size>& windowedRes,
|
||||||
VariantList& renderers) override;
|
VariantList& renderers) override;
|
||||||
|
|
||||||
/**
|
|
||||||
This method is called to query the video hardware for the index
|
|
||||||
of the display the current window is displayed on
|
|
||||||
|
|
||||||
@return the current display index or a negative value if no
|
|
||||||
window is displayed
|
|
||||||
*/
|
|
||||||
Int32 getCurrentDisplayIndex() override;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This method is called to change to the given video mode.
|
This method is called to change to the given video mode.
|
||||||
|
|
||||||
|
@ -184,6 +192,9 @@ class FrameBufferSDL2 : public FrameBuffer
|
||||||
// Used by mapRGB (when palettes are created)
|
// Used by mapRGB (when palettes are created)
|
||||||
SDL_PixelFormat* myPixelFormat;
|
SDL_PixelFormat* myPixelFormat;
|
||||||
|
|
||||||
|
// center setting of curent window
|
||||||
|
bool myCenter;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Following constructors and assignment operators not supported
|
// Following constructors and assignment operators not supported
|
||||||
FrameBufferSDL2() = delete;
|
FrameBufferSDL2() = delete;
|
||||||
|
|
|
@ -55,7 +55,8 @@ FrameBuffer::FrameBuffer(OSystem& osystem)
|
||||||
myGrabMouse(false),
|
myGrabMouse(false),
|
||||||
myHiDPIAllowed(false),
|
myHiDPIAllowed(false),
|
||||||
myHiDPIEnabled(false),
|
myHiDPIEnabled(false),
|
||||||
myCurrentModeList(nullptr)
|
myCurrentModeList(nullptr),
|
||||||
|
myNumDisplays(1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -335,6 +335,23 @@ class FrameBuffer
|
||||||
*/
|
*/
|
||||||
virtual void readPixels(uInt8* buffer, uInt32 pitch, const Common::Rect& rect) const = 0;
|
virtual void readPixels(uInt8* buffer, uInt32 pitch, const Common::Rect& rect) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
This method is called to query the video hardware for the index
|
||||||
|
of the display the current window is displayed on
|
||||||
|
|
||||||
|
@return the current display index or a negative value if no
|
||||||
|
window is displayed
|
||||||
|
*/
|
||||||
|
virtual Int32 getCurrentDisplayIndex() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
This method is called to query the current window position.
|
||||||
|
|
||||||
|
@param x The x-position retrieved
|
||||||
|
@param y The y-position retrieved
|
||||||
|
*/
|
||||||
|
virtual void getCurrentWindowPos(int& x, int& y) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Clear the framebuffer.
|
Clear the framebuffer.
|
||||||
*/
|
*/
|
||||||
|
@ -354,8 +371,6 @@ class FrameBuffer
|
||||||
vector<Common::Size>& windowedRes,
|
vector<Common::Size>& windowedRes,
|
||||||
VariantList& renderers) = 0;
|
VariantList& renderers) = 0;
|
||||||
|
|
||||||
virtual Int32 getCurrentDisplayIndex() = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This method is called to change to the given video mode.
|
This method is called to change to the given video mode.
|
||||||
|
|
||||||
|
@ -497,6 +512,14 @@ class FrameBuffer
|
||||||
// Title of the main window/screen
|
// Title of the main window/screen
|
||||||
string myScreenTitle;
|
string myScreenTitle;
|
||||||
|
|
||||||
|
// Number of displays
|
||||||
|
int myNumDisplays;
|
||||||
|
|
||||||
|
// The resolution of the attached displays in fullscreen mode
|
||||||
|
// The primary display is typically the first in the array
|
||||||
|
// Windowed modes use myDesktopSize directly
|
||||||
|
vector<Common::Size> myFullscreenDisplays;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Draws the frame stats overlay
|
// Draws the frame stats overlay
|
||||||
void drawFrameStats(float framesPerSecond);
|
void drawFrameStats(float framesPerSecond);
|
||||||
|
@ -522,11 +545,6 @@ class FrameBuffer
|
||||||
// Maximum absolute dimensions of the desktop area
|
// Maximum absolute dimensions of the desktop area
|
||||||
Common::Size myAbsDesktopSize;
|
Common::Size myAbsDesktopSize;
|
||||||
|
|
||||||
// The resolution of the attached displays in fullscreen mode
|
|
||||||
// The primary display is typically the first in the array
|
|
||||||
// Windowed modes use myDesktopSize directly
|
|
||||||
vector<Common::Size> myFullscreenDisplays;
|
|
||||||
|
|
||||||
// Supported renderers
|
// Supported renderers
|
||||||
VariantList myRenderers;
|
VariantList myRenderers;
|
||||||
|
|
||||||
|
|
|
@ -233,6 +233,11 @@ void OSystem::loadConfig(const Settings::Options& options)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void OSystem::saveConfig()
|
void OSystem::saveConfig()
|
||||||
{
|
{
|
||||||
|
// Save the current window position and display on system shutdown
|
||||||
|
int x, y;
|
||||||
|
myFrameBuffer->getCurrentWindowPos(x, y);
|
||||||
|
settings().setValue("display", myFrameBuffer->getCurrentDisplayIndex());
|
||||||
|
|
||||||
// Ask all subsystems to save their settings
|
// Ask all subsystems to save their settings
|
||||||
if(myFrameBuffer)
|
if(myFrameBuffer)
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,7 +37,10 @@ Settings::Settings()
|
||||||
setPermanent("video", "");
|
setPermanent("video", "");
|
||||||
setPermanent("speed", "1.0");
|
setPermanent("speed", "1.0");
|
||||||
setPermanent("vsync", "true");
|
setPermanent("vsync", "true");
|
||||||
setPermanent("center", "false");
|
setPermanent("center", "true");
|
||||||
|
setPermanent("pos.x", 50);
|
||||||
|
setPermanent("pos.y", 50);
|
||||||
|
setPermanent("display", 0);
|
||||||
setPermanent("palette", "standard");
|
setPermanent("palette", "standard");
|
||||||
setPermanent("uimessages", "true");
|
setPermanent("uimessages", "true");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue