diff --git a/src/app/modules/gui.cpp b/src/app/modules/gui.cpp index 692001bd7..32ebe1f9b 100644 --- a/src/app/modules/gui.cpp +++ b/src/app/modules/gui.cpp @@ -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()); } } diff --git a/src/she/alleg4/alleg_display.cpp b/src/she/alleg4/alleg_display.cpp index d798baf33..a42b9351d 100644 --- a/src/she/alleg4/alleg_display.cpp +++ b/src/she/alleg4/alleg_display.cpp @@ -24,9 +24,7 @@ #ifdef _WIN32 #include - #include - #include #if defined STRICT || defined __GNUC__ @@ -53,6 +51,7 @@ #include #include +#include #include #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 diff --git a/src/she/alleg4/alleg_display.h b/src/she/alleg4/alleg_display.h index 9b5a74894..51c2845ee 100644 --- a/src/she/alleg4/alleg_display.h +++ b/src/she/alleg4/alleg_display.h @@ -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: diff --git a/src/she/display.h b/src/she/display.h index bc2dec602..ae2e3b1ab 100644 --- a/src/she/display.h +++ b/src/she/display.h @@ -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; };