mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 12:09:36 +00:00
Fix display resolution desynchronizing with auto-position
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "DialogManager.h"
|
||||
#include "IconLoader.h"
|
||||
#include "IGpDisplayDriver.h"
|
||||
#include "IGpLogDriver.h"
|
||||
#include "IGpSystemServices.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "QDPixMap.h"
|
||||
@@ -830,8 +831,11 @@ namespace PortabilityLayer
|
||||
|
||||
void DialogManagerImpl::PositionWindow(Window *window, const Rect &rect) const
|
||||
{
|
||||
unsigned int displayWidth, displayHeight;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(&displayWidth, &displayHeight);
|
||||
IGpLogDriver *logger = PLDrivers::GetLogDriver();
|
||||
|
||||
Vec2i displayResolution = WindowManager::GetInstance()->GetDisplayResolution();
|
||||
unsigned int displayWidth = displayResolution.m_x;
|
||||
unsigned int displayHeight = displayResolution.m_y;
|
||||
|
||||
const unsigned int halfDisplayHeight = displayHeight / 2;
|
||||
const unsigned int quarterDisplayWidth = displayHeight / 4;
|
||||
@@ -840,6 +844,9 @@ namespace PortabilityLayer
|
||||
const uint16_t dialogWidth = rect.Width();
|
||||
const uint16_t dialogHeight = rect.Height();
|
||||
|
||||
if (logger)
|
||||
logger->Printf(IGpLogDriver::Category_Information, "Auto positioning window size %ix%i on display size %ix%i", static_cast<int>(dialogWidth), static_cast<int>(dialogHeight), static_cast<int>(displayWidth), static_cast<int>(displayHeight));
|
||||
|
||||
Vec2i newPosition;
|
||||
|
||||
newPosition.m_x = (static_cast<int32_t>(displayWidth) - static_cast<int32_t>(dialogWidth)) / 2;
|
||||
@@ -860,6 +867,9 @@ namespace PortabilityLayer
|
||||
else
|
||||
newPosition.m_y = (static_cast<int32_t>(displayHeight) - static_cast<int32_t>(dialogHeight)) / 2;
|
||||
|
||||
if (logger)
|
||||
logger->Printf(IGpLogDriver::Category_Information, "Positioned at %i,%i", static_cast<int>(newPosition.m_x), static_cast<int>(newPosition.m_y));
|
||||
|
||||
window->SetPosition(newPosition);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "RGBAColor.h"
|
||||
#include "ResolveCachingColor.h"
|
||||
#include "Vec2i.h"
|
||||
#include "WindowManager.h"
|
||||
|
||||
#include "PLBigEndian.h"
|
||||
#include "PLCore.h"
|
||||
@@ -840,8 +841,7 @@ namespace PortabilityLayer
|
||||
m_haveIcon = true;
|
||||
}
|
||||
|
||||
unsigned int width;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(&width, nullptr);
|
||||
unsigned int width = WindowManager::GetInstance()->GetDisplayResolution().m_x;
|
||||
|
||||
GpPixelFormat_t pixelFormat = DisplayDeviceManager::GetInstance()->GetPixelFormat();
|
||||
|
||||
@@ -1036,8 +1036,7 @@ namespace PortabilityLayer
|
||||
|
||||
if (m_isTouchScreen)
|
||||
{
|
||||
unsigned int displayHeight = 0;
|
||||
displayDriver->GetDisplayResolution(nullptr, &displayHeight);
|
||||
unsigned int displayHeight = WindowManager::GetInstance()->GetDisplayResolution().m_y;
|
||||
y = static_cast<int32_t>(displayHeight) - kTouchscreenMenuBarHeight;
|
||||
}
|
||||
|
||||
@@ -1307,8 +1306,7 @@ namespace PortabilityLayer
|
||||
{
|
||||
if (m_isTouchScreen)
|
||||
{
|
||||
unsigned int displayHeight = 0;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
|
||||
unsigned int displayHeight = WindowManager::GetInstance()->GetDisplayResolution().m_y;
|
||||
return y >= (static_cast<int32_t>(displayHeight - kTouchscreenMenuBarHeight)) && y < static_cast<int32_t>(displayHeight);
|
||||
}
|
||||
else
|
||||
@@ -1388,8 +1386,7 @@ namespace PortabilityLayer
|
||||
{
|
||||
int32_t popupBottom = static_cast<int32_t>(m_popupPosition.m_y + menu->layoutFinalHeight);
|
||||
|
||||
unsigned int displayHeight = 0;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
|
||||
unsigned int displayHeight = WindowManager::GetInstance()->GetDisplayResolution().m_y;
|
||||
if (popupBottom > static_cast<int32_t>(displayHeight))
|
||||
m_popupPosition.m_y -= popupBottom - static_cast<int32_t>(displayHeight);
|
||||
}
|
||||
|
||||
@@ -677,6 +677,7 @@ void PL_Init()
|
||||
PortabilityLayer::DisplayDeviceManager::GetInstance()->Init();
|
||||
PortabilityLayer::QDManager::GetInstance()->Init();
|
||||
PortabilityLayer::MenuManager::GetInstance()->Init();
|
||||
PortabilityLayer::WindowManager::GetInstance()->Init();
|
||||
|
||||
PLDrivers::GetFileSystem()->SetMainThreadRelay(PLMainThreadRelay::GetInstance());
|
||||
PLDrivers::GetFileSystem()->SetDelayCallback(PLSysCalls::Sleep);
|
||||
|
||||
@@ -171,6 +171,8 @@ namespace PortabilityLayer
|
||||
WindowManagerImpl();
|
||||
~WindowManagerImpl();
|
||||
|
||||
void Init() override;
|
||||
|
||||
Window *CreateWindow(const WindowDef &windowDef) override;
|
||||
void ResizeWindow(Window *window, int width, int height) override;
|
||||
void MoveWindow(Window *window, int x, int y) override;
|
||||
@@ -198,6 +200,8 @@ namespace PortabilityLayer
|
||||
|
||||
void HandleScreenResolutionChange(uint32_t prevWidth, uint32_t prevHeight, uint32_t newWidth, uint32_t newHeight) override;
|
||||
|
||||
Vec2i GetDisplayResolution() const override;
|
||||
|
||||
void SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
|
||||
Window *GetPutInFrontSentinel() const override;
|
||||
@@ -229,6 +233,8 @@ namespace PortabilityLayer
|
||||
DrawSurface m_resizeInProgressVerticalBar;
|
||||
bool m_isResizeInProgress;
|
||||
|
||||
Vec2i m_displayResolution;
|
||||
|
||||
static WindowManagerImpl ms_instance;
|
||||
|
||||
static uint8_t ms_putInFrontSentinel;
|
||||
@@ -1011,8 +1017,6 @@ namespace PortabilityLayer
|
||||
return m_effects;
|
||||
}
|
||||
|
||||
|
||||
|
||||
WindowManagerImpl::WindowManagerImpl()
|
||||
: m_windowStackTop(nullptr)
|
||||
, m_windowStackBottom(nullptr)
|
||||
@@ -1025,6 +1029,7 @@ namespace PortabilityLayer
|
||||
, m_flickerZoneSize(0)
|
||||
, m_flickerBasisCoordinateDistance(0)
|
||||
, m_flickerChromeDistanceOffset(0)
|
||||
, m_displayResolution(0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1032,6 +1037,14 @@ namespace PortabilityLayer
|
||||
{
|
||||
}
|
||||
|
||||
void WindowManagerImpl::Init()
|
||||
{
|
||||
unsigned int displayWidth, displayHeight;
|
||||
PLDrivers::GetDisplayDriver()->GetInitialDisplayResolution(&displayWidth, &displayHeight);
|
||||
|
||||
m_displayResolution = Vec2i(displayWidth, displayHeight);
|
||||
}
|
||||
|
||||
Window *WindowManagerImpl::CreateWindow(const WindowDef &windowDef)
|
||||
{
|
||||
void *windowMem = MemoryManager::GetInstance()->Alloc(sizeof(WindowImpl));
|
||||
@@ -1528,6 +1541,11 @@ namespace PortabilityLayer
|
||||
}
|
||||
}
|
||||
|
||||
Vec2i WindowManagerImpl::GetDisplayResolution() const
|
||||
{
|
||||
return m_displayResolution;
|
||||
}
|
||||
|
||||
void WindowManagerImpl::SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
PLDrivers::GetDisplayDriver()->SetBackgroundColor(r, g, b, 255);
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace PortabilityLayer
|
||||
class WindowManager
|
||||
{
|
||||
public:
|
||||
virtual void Init() = 0;
|
||||
virtual Window *GetPutInFrontSentinel() const = 0;
|
||||
virtual Window *CreateWindow(const WindowDef &windowDef) = 0;
|
||||
virtual void ResizeWindow(Window *window, int width, int height) = 0;
|
||||
@@ -52,6 +53,8 @@ namespace PortabilityLayer
|
||||
|
||||
virtual void SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b) = 0;
|
||||
|
||||
virtual Vec2i GetDisplayResolution() const = 0;
|
||||
|
||||
static WindowManager *GetInstance();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user