mirror of
https://github.com/stenzek/duckstation.git
synced 2025-07-19 00:20:12 +00:00
Qt: Store window geometry in human-readable form
This commit is contained in:
parent
6b969a0b94
commit
b2ad193178
@ -731,10 +731,10 @@ bool MiniHost::GetSavedPlatformWindowGeometry(s32* x, s32* y, s32* width, s32* h
|
|||||||
{
|
{
|
||||||
const auto lock = Host::GetSettingsLock();
|
const auto lock = Host::GetSettingsLock();
|
||||||
|
|
||||||
bool result = s_state.base_settings_interface.GetIntValue("SimpleHost", "WindowX", x);
|
bool result = s_state.base_settings_interface.GetIntValue("UI", "MainWindowX", x);
|
||||||
result = result && s_state.base_settings_interface.GetIntValue("SimpleHost", "WindowY", y);
|
result = result && s_state.base_settings_interface.GetIntValue("UI", "MainWindowY", y);
|
||||||
result = result && s_state.base_settings_interface.GetIntValue("SimpleHost", "WindowWidth", width);
|
result = result && s_state.base_settings_interface.GetIntValue("UI", "MainWindowWidth", width);
|
||||||
result = result && s_state.base_settings_interface.GetIntValue("SimpleHost", "WindowHeight", height);
|
result = result && s_state.base_settings_interface.GetIntValue("UI", "MainWindowHeight", height);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -744,10 +744,10 @@ void MiniHost::SavePlatformWindowGeometry(s32 x, s32 y, s32 width, s32 height)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const auto lock = Host::GetSettingsLock();
|
const auto lock = Host::GetSettingsLock();
|
||||||
s_state.base_settings_interface.SetIntValue("SimpleHost", "WindowX", x);
|
s_state.base_settings_interface.SetIntValue("UI", "MainWindowX", x);
|
||||||
s_state.base_settings_interface.SetIntValue("SimpleHost", "WindowY", y);
|
s_state.base_settings_interface.SetIntValue("UI", "MainWindowY", y);
|
||||||
s_state.base_settings_interface.SetIntValue("SimpleHost", "WindowWidth", width);
|
s_state.base_settings_interface.SetIntValue("UI", "MainWindowWidth", width);
|
||||||
s_state.base_settings_interface.SetIntValue("SimpleHost", "WindowHeight", height);
|
s_state.base_settings_interface.SetIntValue("UI", "MainWindowHeight", height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MiniHost::UIThreadMainLoop()
|
void MiniHost::UIThreadMainLoop()
|
||||||
|
@ -46,6 +46,12 @@
|
|||||||
|
|
||||||
LOG_CHANNEL(Host);
|
LOG_CHANNEL(Host);
|
||||||
|
|
||||||
|
namespace QtUtils {
|
||||||
|
|
||||||
|
bool TryMigrateWindowGeometry(SettingsInterface* si, std::string_view window_name, QWidget* widget);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
QFrame* QtUtils::CreateHorizontalLine(QWidget* parent)
|
QFrame* QtUtils::CreateHorizontalLine(QWidget* parent)
|
||||||
{
|
{
|
||||||
QFrame* line = new QFrame(parent);
|
QFrame* line = new QFrame(parent);
|
||||||
@ -402,16 +408,41 @@ std::optional<WindowInfo> QtUtils::GetWindowInfoForWidget(QWidget* widget, Rende
|
|||||||
|
|
||||||
bool QtUtils::SaveWindowGeometry(std::string_view window_name, QWidget* widget, bool auto_commit_changes)
|
bool QtUtils::SaveWindowGeometry(std::string_view window_name, QWidget* widget, bool auto_commit_changes)
|
||||||
{
|
{
|
||||||
const TinyString config_key = TinyString::from_format("{}Geometry", window_name);
|
const QRect geometry = widget->geometry();
|
||||||
|
|
||||||
const QByteArray geometry = widget->saveGeometry();
|
const TinyString xkey = TinyString::from_format("{}X", window_name);
|
||||||
const QByteArray geometry_b64 = geometry.toBase64();
|
const TinyString ykey = TinyString::from_format("{}Y", window_name);
|
||||||
const std::string old_geometry_b64 = Host::GetBaseStringSettingValue("UI", config_key);
|
const TinyString wkey = TinyString::from_format("{}Width", window_name);
|
||||||
if (old_geometry_b64 == geometry_b64.constData())
|
const TinyString hkey = TinyString::from_format("{}Height", window_name);
|
||||||
return false;
|
|
||||||
|
|
||||||
Host::SetBaseStringSettingValue("UI", config_key, geometry_b64.constData());
|
const auto lock = Host::GetSettingsLock();
|
||||||
if (auto_commit_changes)
|
SettingsInterface* si = Host::Internal::GetBaseSettingsLayer();
|
||||||
|
bool changed = false;
|
||||||
|
if (si->GetIntValue("UI", xkey.c_str(), std::numeric_limits<s32>::min()) != geometry.x())
|
||||||
|
{
|
||||||
|
si->SetIntValue("UI", xkey.c_str(), geometry.x());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (si->GetIntValue("UI", ykey.c_str(), std::numeric_limits<s32>::min()) != geometry.y())
|
||||||
|
{
|
||||||
|
si->SetIntValue("UI", ykey.c_str(), geometry.y());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (si->GetIntValue("UI", wkey.c_str(), std::numeric_limits<s32>::min()) != geometry.width())
|
||||||
|
{
|
||||||
|
si->SetIntValue("UI", wkey.c_str(), geometry.width());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (si->GetIntValue("UI", hkey.c_str(), std::numeric_limits<s32>::min()) != geometry.height())
|
||||||
|
{
|
||||||
|
si->SetIntValue("UI", hkey.c_str(), geometry.height());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed && auto_commit_changes)
|
||||||
Host::CommitBaseSettingChanges();
|
Host::CommitBaseSettingChanges();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -419,15 +450,42 @@ bool QtUtils::SaveWindowGeometry(std::string_view window_name, QWidget* widget,
|
|||||||
|
|
||||||
bool QtUtils::RestoreWindowGeometry(std::string_view window_name, QWidget* widget)
|
bool QtUtils::RestoreWindowGeometry(std::string_view window_name, QWidget* widget)
|
||||||
{
|
{
|
||||||
|
const auto lock = Host::GetSettingsLock();
|
||||||
|
SettingsInterface* si = Host::Internal::GetBaseSettingsLayer();
|
||||||
|
|
||||||
|
s32 x = 0, y = 0, w = 0, h = 0;
|
||||||
|
if (!si->GetIntValue("UI", TinyString::from_format("{}X", window_name).c_str(), &x) ||
|
||||||
|
!si->GetIntValue("UI", TinyString::from_format("{}Y", window_name).c_str(), &y) ||
|
||||||
|
!si->GetIntValue("UI", TinyString::from_format("{}Width", window_name).c_str(), &w) ||
|
||||||
|
!si->GetIntValue("UI", TinyString::from_format("{}Height", window_name).c_str(), &h))
|
||||||
|
{
|
||||||
|
return TryMigrateWindowGeometry(si, window_name, widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
widget->setGeometry(x, y, w, h);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QtUtils::TryMigrateWindowGeometry(SettingsInterface* si, std::string_view window_name, QWidget* widget)
|
||||||
|
{
|
||||||
|
// can we migrate old configuration?
|
||||||
const TinyString config_key = TinyString::from_format("{}Geometry", window_name);
|
const TinyString config_key = TinyString::from_format("{}Geometry", window_name);
|
||||||
const std::string geometry_b64 = Host::GetBaseStringSettingValue("UI", config_key);
|
std::string config_value;
|
||||||
if (geometry_b64.empty())
|
if (!si->GetStringValue("UI", config_key.c_str(), &config_value))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QByteArray geometry = QByteArray::fromBase64(QByteArray::fromStdString(geometry_b64));
|
widget->restoreGeometry(QByteArray::fromBase64(QByteArray::fromStdString(config_value)));
|
||||||
widget->restoreGeometry(geometry);
|
|
||||||
|
|
||||||
// make sure we're not loading a dodgy config which had fullscreen set...
|
// make sure we're not loading a dodgy config which had fullscreen set...
|
||||||
widget->setWindowState(widget->windowState() & ~(Qt::WindowFullScreen | Qt::WindowActive));
|
widget->setWindowState(widget->windowState() & ~(Qt::WindowFullScreen | Qt::WindowActive));
|
||||||
|
|
||||||
|
// save the new values, delete the old key
|
||||||
|
const QRect geometry = widget->geometry();
|
||||||
|
si->SetIntValue("UI", TinyString::from_format("{}X", window_name).c_str(), geometry.x());
|
||||||
|
si->SetIntValue("UI", TinyString::from_format("{}Y", window_name).c_str(), geometry.y());
|
||||||
|
si->SetIntValue("UI", TinyString::from_format("{}Width", window_name).c_str(), geometry.width());
|
||||||
|
si->SetIntValue("UI", TinyString::from_format("{}Height", window_name).c_str(), geometry.height());
|
||||||
|
si->DeleteValue("UI", config_key.c_str());
|
||||||
|
Host::CommitBaseSettingChanges();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user