mirror of https://github.com/aseprite/aseprite.git
Remember exact window position (e.g. in which monitor it was closed)
It's working on alleg4 port on Windows only.
This commit is contained in:
parent
13736a49f4
commit
a088bf46a2
|
|
@ -90,7 +90,8 @@ static ui::Timer* defered_invalid_timer = nullptr;
|
|||
static gfx::Region defered_invalid_region;
|
||||
|
||||
// Load & save graphics configuration
|
||||
static void load_gui_config(int& w, int& h, bool& maximized);
|
||||
static void load_gui_config(int& w, int& h, bool& maximized,
|
||||
std::string& windowLayout);
|
||||
static void save_gui_config();
|
||||
|
||||
static int get_screen_scale()
|
||||
|
|
@ -106,7 +107,8 @@ static bool create_main_display(bool gpuAccel,
|
|||
{
|
||||
int w, h;
|
||||
int scale = get_screen_scale();
|
||||
load_gui_config(w, h, maximized);
|
||||
std::string windowLayout;
|
||||
load_gui_config(w, h, maximized, windowLayout);
|
||||
|
||||
she::instance()->setGpuAcceleration(gpuAccel);
|
||||
|
||||
|
|
@ -136,6 +138,9 @@ static bool create_main_display(bool gpuAccel,
|
|||
}
|
||||
}
|
||||
|
||||
if (main_display && !windowLayout.empty())
|
||||
main_display->setLayout(windowLayout);
|
||||
|
||||
return (main_display != nullptr);
|
||||
}
|
||||
|
||||
|
|
@ -201,11 +206,13 @@ void exit_module_gui()
|
|||
main_display->dispose();
|
||||
}
|
||||
|
||||
static void load_gui_config(int& w, int& h, bool& maximized)
|
||||
static void load_gui_config(int& w, int& h, bool& maximized,
|
||||
std::string& windowLayout)
|
||||
{
|
||||
w = get_config_int("GfxMode", "Width", 0);
|
||||
h = get_config_int("GfxMode", "Height", 0);
|
||||
maximized = get_config_bool("GfxMode", "Maximized", false);
|
||||
windowLayout = get_config_string("GfxMode", "WindowLayout", "");
|
||||
}
|
||||
|
||||
static void save_gui_config()
|
||||
|
|
@ -215,6 +222,10 @@ static void save_gui_config()
|
|||
set_config_bool("GfxMode", "Maximized", display->isMaximized());
|
||||
set_config_int("GfxMode", "Width", display->originalWidth());
|
||||
set_config_int("GfxMode", "Height", display->originalHeight());
|
||||
|
||||
std::string windowLayout = display->getLayout();
|
||||
if (!windowLayout.empty())
|
||||
set_config_string("GfxMode", "WindowLayout", windowLayout.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,9 +24,7 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
#include <winalleg.h>
|
||||
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <commctrl.h>
|
||||
|
||||
#if defined STRICT || defined __GNUC__
|
||||
|
|
@ -53,6 +51,7 @@
|
|||
|
||||
#include <cassert>
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include "she/alleg4/clock.h"
|
||||
|
|
@ -594,6 +593,63 @@ void Alleg4Display::releaseMouse()
|
|||
#endif
|
||||
}
|
||||
|
||||
std::string Alleg4Display::getLayout()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
WINDOWPLACEMENT wp;
|
||||
wp.length = sizeof(WINDOWPLACEMENT);
|
||||
if (GetWindowPlacement((HWND)nativeHandle(), &wp)) {
|
||||
std::ostringstream s;
|
||||
s << 1 << ' '
|
||||
<< wp.flags << ' '
|
||||
<< wp.showCmd << ' '
|
||||
<< wp.ptMinPosition.x << ' '
|
||||
<< wp.ptMinPosition.y << ' '
|
||||
<< wp.ptMaxPosition.x << ' '
|
||||
<< wp.ptMaxPosition.y << ' '
|
||||
<< wp.rcNormalPosition.left << ' '
|
||||
<< wp.rcNormalPosition.top << ' '
|
||||
<< wp.rcNormalPosition.right << ' '
|
||||
<< wp.rcNormalPosition.bottom;
|
||||
return s.str();
|
||||
}
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
void Alleg4Display::setLayout(const std::string& layout)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
WINDOWPLACEMENT wp;
|
||||
wp.length = sizeof(WINDOWPLACEMENT);
|
||||
|
||||
std::istringstream s(layout);
|
||||
int ver;
|
||||
s >> ver;
|
||||
if (ver == 1) {
|
||||
s >> wp.flags
|
||||
>> wp.showCmd
|
||||
>> wp.ptMinPosition.x
|
||||
>> wp.ptMinPosition.y
|
||||
>> wp.ptMaxPosition.x
|
||||
>> wp.ptMaxPosition.y
|
||||
>> wp.rcNormalPosition.left
|
||||
>> wp.rcNormalPosition.top
|
||||
>> wp.rcNormalPosition.right
|
||||
>> wp.rcNormalPosition.bottom;
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
if (SetWindowPlacement((HWND)nativeHandle(), &wp)) {
|
||||
// TODO use the return value
|
||||
}
|
||||
#else
|
||||
// Do nothing
|
||||
#endif
|
||||
}
|
||||
|
||||
void* Alleg4Display::nativeHandle()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ namespace she {
|
|||
void setMousePosition(const gfx::Point& position) override;
|
||||
void captureMouse() override;
|
||||
void releaseMouse() override;
|
||||
std::string getLayout() override;
|
||||
void setLayout(const std::string& layout) override;
|
||||
void* nativeHandle() override;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -62,6 +62,11 @@ namespace she {
|
|||
virtual void captureMouse() = 0;
|
||||
virtual void releaseMouse() = 0;
|
||||
|
||||
// Set/get the specific information to restore the exact same
|
||||
// window position (e.g. in the same monitor).
|
||||
virtual std::string getLayout() = 0;
|
||||
virtual void setLayout(const std::string& layout) = 0;
|
||||
|
||||
// Returns the HWND on Windows.
|
||||
virtual DisplayHandle nativeHandle() = 0;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue