1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-10-06 09:17:07 +02:00

Fix window position by setting it at the right time

This commit is contained in:
Elias Steurer 2023-10-29 11:29:52 +01:00
parent bbb1732120
commit 6972929d98
3 changed files with 17 additions and 8 deletions

View File

@ -82,8 +82,10 @@ bool ScreenPlayGodotWallpaper::init(int activeScreen)
ShowWindow(m_hook->windowHandle, SW_HIDE); ShowWindow(m_hook->windowHandle, SW_HIDE);
WindowsIntegration windowsIntegration; WindowsIntegration windowsIntegration;
std::optional<Monitor> monitor = windowsIntegration.setupWallpaperForOneScreen(activeScreen,m_hook->windowHandle,m_hook->windowHandleWorker); auto updateWindowSize = [this, &displayServer](const int width, const int height){
displayServer->window_set_size(godot::Vector2((real_t)monitor->size.cx, (real_t)monitor->size.cy)); displayServer->window_set_size(godot::Vector2((real_t)width, (real_t)height));
};
std::optional<Monitor> monitor = windowsIntegration.setupWallpaperForOneScreen(activeScreen,m_hook->windowHandle,m_hook->windowHandleWorker,updateWindowSize);
const std::string windowTitle = "ScreenPlayWallpaperGodot"; const std::string windowTitle = "ScreenPlayWallpaperGodot";
SetWindowText(hwnd, windowTitle.c_str()); SetWindowText(hwnd, windowTitle.c_str());

View File

@ -9,6 +9,7 @@
#include <shellscalingapi.h> #include <shellscalingapi.h>
#include <vector> #include <vector>
#include <optional> #include <optional>
#include <functional>
// Do not sort ! // Do not sort !
#include "WinUser.h" #include "WinUser.h"
@ -166,7 +167,7 @@ public:
* scale factors. * scale factors.
*/ */
std::optional<Monitor> setupWallpaperForOneScreen(const int activeScreen, HWND windowHwnd, HWND parentWindowHwnd) std::optional<Monitor> setupWallpaperForOneScreen(const int activeScreen, HWND windowHwnd, HWND parentWindowHwnd, std::function<void(int,int)>updateWindowSize)
{ {
std::vector<Monitor> monitors = GetAllMonitors(); std::vector<Monitor> monitors = GetAllMonitors();
for (const auto& monitor : monitors) { for (const auto& monitor : monitors) {
@ -179,6 +180,9 @@ public:
monitor.size.cx, monitor.size.cy, monitor.size.cx, monitor.size.cy,
SWP_NOZORDER | SWP_NOACTIVATE); SWP_NOZORDER | SWP_NOACTIVATE);
// Must be called here to fix window positions!
updateWindowSize(monitor.size.cx, monitor.size.cy);
RECT oldRect; RECT oldRect;
GetWindowRect(windowHwnd, &oldRect); GetWindowRect(windowHwnd, &oldRect);
std::cout << "Old Window Position: (" << oldRect.left << ", " << oldRect.top << ")" << std::endl; std::cout << "Old Window Position: (" << oldRect.left << ", " << oldRect.top << ")" << std::endl;

View File

@ -186,11 +186,14 @@ void WinWindow::destroyThis()
void WinWindow::setupWallpaperForOneScreen(int activeScreen) void WinWindow::setupWallpaperForOneScreen(int activeScreen)
{ {
WindowsIntegration windowsIntegration; WindowsIntegration windowsIntegration;
std::optional<Monitor> monitor = windowsIntegration.setupWallpaperForOneScreen(activeScreen,m_windowHandle,m_windowHandleWorker); auto updateWindowSize = [this](const int width, const int height){
setWidth(monitor->size.cx); setWidth(width);
setHeight(monitor->size.cy); setHeight(height);
m_window.setWidth(width()); m_window.setWidth(width);
m_window.setHeight(height()); m_window.setHeight(height);
};
std::optional<Monitor> monitor = windowsIntegration.setupWallpaperForOneScreen(activeScreen,m_windowHandle,m_windowHandleWorker,updateWindowSize);
} }
/*! /*!