diff --git a/ScreenPlayWallpaper/Godot/GDExtention/src/ScreenPlayGodotWallpaper.cpp b/ScreenPlayWallpaper/Godot/GDExtention/src/ScreenPlayGodotWallpaper.cpp index 8bc3ccda..530b3d48 100644 --- a/ScreenPlayWallpaper/Godot/GDExtention/src/ScreenPlayGodotWallpaper.cpp +++ b/ScreenPlayWallpaper/Godot/GDExtention/src/ScreenPlayGodotWallpaper.cpp @@ -82,8 +82,10 @@ bool ScreenPlayGodotWallpaper::init(int activeScreen) ShowWindow(m_hook->windowHandle, SW_HIDE); WindowsIntegration windowsIntegration; - std::optional monitor = windowsIntegration.setupWallpaperForOneScreen(activeScreen,m_hook->windowHandle,m_hook->windowHandleWorker); - displayServer->window_set_size(godot::Vector2((real_t)monitor->size.cx, (real_t)monitor->size.cy)); + auto updateWindowSize = [this, &displayServer](const int width, const int height){ + displayServer->window_set_size(godot::Vector2((real_t)width, (real_t)height)); + }; + std::optional monitor = windowsIntegration.setupWallpaperForOneScreen(activeScreen,m_hook->windowHandle,m_hook->windowHandleWorker,updateWindowSize); const std::string windowTitle = "ScreenPlayWallpaperGodot"; SetWindowText(hwnd, windowTitle.c_str()); diff --git a/ScreenPlayWallpaper/src/windowsintegration.h b/ScreenPlayWallpaper/src/windowsintegration.h index 75f93860..3c4d10c8 100644 --- a/ScreenPlayWallpaper/src/windowsintegration.h +++ b/ScreenPlayWallpaper/src/windowsintegration.h @@ -9,6 +9,7 @@ #include #include #include +#include // Do not sort ! #include "WinUser.h" @@ -166,7 +167,7 @@ public: * scale factors. */ - std::optional setupWallpaperForOneScreen(const int activeScreen, HWND windowHwnd, HWND parentWindowHwnd) + std::optional setupWallpaperForOneScreen(const int activeScreen, HWND windowHwnd, HWND parentWindowHwnd, std::functionupdateWindowSize) { std::vector monitors = GetAllMonitors(); for (const auto& monitor : monitors) { @@ -179,6 +180,9 @@ public: monitor.size.cx, monitor.size.cy, SWP_NOZORDER | SWP_NOACTIVATE); + // Must be called here to fix window positions! + updateWindowSize(monitor.size.cx, monitor.size.cy); + RECT oldRect; GetWindowRect(windowHwnd, &oldRect); std::cout << "Old Window Position: (" << oldRect.left << ", " << oldRect.top << ")" << std::endl; diff --git a/ScreenPlayWallpaper/src/winwindow.cpp b/ScreenPlayWallpaper/src/winwindow.cpp index 78fa8483..447146eb 100644 --- a/ScreenPlayWallpaper/src/winwindow.cpp +++ b/ScreenPlayWallpaper/src/winwindow.cpp @@ -186,11 +186,14 @@ void WinWindow::destroyThis() void WinWindow::setupWallpaperForOneScreen(int activeScreen) { WindowsIntegration windowsIntegration; - std::optional monitor = windowsIntegration.setupWallpaperForOneScreen(activeScreen,m_windowHandle,m_windowHandleWorker); - setWidth(monitor->size.cx); - setHeight(monitor->size.cy); - m_window.setWidth(width()); - m_window.setHeight(height()); + auto updateWindowSize = [this](const int width, const int height){ + setWidth(width); + setHeight(height); + m_window.setWidth(width); + m_window.setHeight(height); + }; + std::optional monitor = windowsIntegration.setupWallpaperForOneScreen(activeScreen,m_windowHandle,m_windowHandleWorker,updateWindowSize); + } /*!