diff --git a/src/app/modules/gui.cpp b/src/app/modules/gui.cpp index 0003ad5c8..ff0250bd3 100644 --- a/src/app/modules/gui.cpp +++ b/src/app/modules/gui.cpp @@ -212,8 +212,10 @@ void exit_module_gui() 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); + gfx::Size defSize = she::instance()->defaultNewDisplaySize(); + + w = get_config_int("GfxMode", "Width", defSize.w); + h = get_config_int("GfxMode", "Height", defSize.h); maximized = get_config_bool("GfxMode", "Maximized", false); windowLayout = get_config_string("GfxMode", "WindowLayout", ""); } diff --git a/src/she/alleg4/she.cpp b/src/she/alleg4/she.cpp index 2313b4294..1f9738f11 100644 --- a/src/she/alleg4/she.cpp +++ b/src/she/alleg4/she.cpp @@ -163,6 +163,10 @@ public: // Do nothing } + gfx::Size defaultNewDisplaySize() override { + return gfx::Size(0, 0); + } + Display* defaultDisplay() override { return unique_display; } diff --git a/src/she/skia/skia_system.h b/src/she/skia/skia_system.h index f5e5213db..c5dfea22a 100644 --- a/src/she/skia/skia_system.h +++ b/src/she/skia/skia_system.h @@ -67,6 +67,19 @@ public: m_gpuAcceleration = state; } + gfx::Size defaultNewDisplaySize() override { + gfx::Size sz; +#ifdef _WIN32 + sz.w = GetSystemMetrics(SM_CXMAXIMIZED); + sz.h = GetSystemMetrics(SM_CYMAXIMIZED); + sz.w -= GetSystemMetrics(SM_CXSIZEFRAME)*4; + sz.h -= GetSystemMetrics(SM_CYSIZEFRAME)*4; + sz.w = MAX(0, sz.w); + sz.h = MAX(0, sz.h); +#endif + return sz; + } + Display* defaultDisplay() override { return m_defaultDisplay; } diff --git a/src/she/system.h b/src/she/system.h index f73f949c9..14a198f8c 100644 --- a/src/she/system.h +++ b/src/she/system.h @@ -38,6 +38,7 @@ namespace she { virtual EventQueue* eventQueue() = 0; virtual bool gpuAcceleration() const = 0; virtual void setGpuAcceleration(bool state) = 0; + virtual gfx::Size defaultNewDisplaySize() = 0; virtual Display* defaultDisplay() = 0; virtual Display* createDisplay(int width, int height, int scale) = 0; virtual Surface* createSurface(int width, int height) = 0; diff --git a/src/she/win/window.h b/src/she/win/window.h index a402dae30..d447bacf1 100644 --- a/src/she/win/window.h +++ b/src/she/win/window.h @@ -598,6 +598,19 @@ namespace she { SetWindowLongPtr(hwnd, GWLP_USERDATA, LONG_PTR(self)); + // Center the window + RECT workarea; + if (SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)&workarea, 0)) { + SetWindowPos(hwnd, nullptr, + (workarea.right-workarea.left)/2-width/2, + (workarea.bottom-workarea.top)/2-height/2, 0, 0, + SWP_NOSIZE | + SWP_NOSENDCHANGING | + SWP_NOOWNERZORDER | + SWP_NOZORDER | + SWP_NOREDRAW); + } + // Set scroll info to receive WM_HSCROLL/VSCROLL events (events // generated by some trackpad drivers). SCROLLINFO si;