diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index ace2fcd299..7e1ccb578d 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -17,6 +17,52 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "facades.h" namespace Core { +namespace { + +[[nodiscard]] WindowPosition Deserialize(const QByteArray &data) { + QDataStream stream(data); + stream.setVersion(QDataStream::Qt_5_1); + + auto result = WindowPosition(); + stream + >> result.x + >> result.y + >> result.w + >> result.h + >> result.moncrc + >> result.maximized + >> result.scale; + return result; +} + +[[nodiscard]] QByteArray Serialize(const WindowPosition &position) { + auto result = QByteArray(); + const auto size = 7 * sizeof(qint32); + result.reserve(size); + { + QDataStream stream(&result, QIODevice::WriteOnly); + stream.setVersion(QDataStream::Qt_5_1); + stream + << qint32(position.x) + << qint32(position.y) + << qint32(position.w) + << qint32(position.h) + << qint32(position.moncrc) + << qint32(position.maximized) + << qint32(position.scale); + } + DEBUG_LOG(("Window Pos: Writing to storage %1, %2, %3, %4" + " (scale %5%, maximized %6)") + .arg(position.x) + .arg(position.y) + .arg(position.w) + .arg(position.h) + .arg(position.scale) + .arg(Logs::b(position.maximized))); + return result; +} + +} // namespace Settings::Settings() : _sendSubmitWay(Ui::InputSubmitSettings::Enter) @@ -27,6 +73,8 @@ Settings::Settings() QByteArray Settings::serialize() const { const auto themesAccentColors = _themesAccentColors.serialize(); + const auto windowPosition = Serialize(_windowPosition); + auto size = Serialize::bytearraySize(themesAccentColors) + sizeof(qint32) * 5 + Serialize::stringSize(_downloadPath.current()) @@ -40,6 +88,7 @@ QByteArray Settings::serialize() const { size += Serialize::stringSize(key) + Serialize::stringSize(value); } size += Serialize::bytearraySize(_videoPipGeometry); + size += Serialize::bytearraySize(windowPosition); auto result = QByteArray(); result.reserve(size); @@ -115,7 +164,8 @@ QByteArray Settings::serialize() const { << _groupCallPushToTalkShortcut << qint64(_groupCallPushToTalkDelay) << qint32(0) // Call audio backend - << qint32(_disableCalls ? 1 : 0); + << qint32(_disableCalls ? 1 : 0) + << windowPosition; } return result; } @@ -188,6 +238,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { qint64 groupCallPushToTalkDelay = _groupCallPushToTalkDelay; qint32 callAudioBackend = 0; qint32 disableCalls = _disableCalls ? 1 : 0; + QByteArray windowPosition; stream >> themesAccentColors; if (!stream.atEnd()) { @@ -289,6 +340,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) { if (!stream.atEnd()) { stream >> disableCalls; } + if (!stream.atEnd()) { + stream >> windowPosition; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Core::Settings::constructFromSerialized()")); @@ -389,6 +443,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) { _groupCallPushToTalkShortcut = groupCallPushToTalkShortcut; _groupCallPushToTalkDelay = groupCallPushToTalkDelay; _disableCalls = (disableCalls == 1); + if (!windowPosition.isEmpty()) { + _windowPosition = Deserialize(windowPosition); + } } bool Settings::chatWide() const { diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index b3735451d7..76320ad9e0 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -28,6 +28,18 @@ enum class Backend; namespace Core { +struct WindowPosition { + WindowPosition() = default; + + int32 moncrc = 0; + int maximized = 0; + int scale = 0; + int x = 0; + int y = 0; + int w = 0; + int h = 0; +}; + class Settings final { public: enum class ScreenCorner { @@ -503,6 +515,12 @@ public: [[nodiscard]] rpl::producer windowControlsLayoutChanges() const { return _windowControlsLayout.changes(); } + [[nodiscard]] const WindowPosition &windowPosition() const { + return _windowPosition; + } + void setWindowPosition(const WindowPosition &position) { + _windowPosition = position; + } [[nodiscard]] static bool ThirdColumnByDefault(); [[nodiscard]] float64 DefaultDialogsWidthRatio(); @@ -585,6 +603,7 @@ private: rpl::variable> _systemDarkMode = std::nullopt; rpl::variable _systemDarkModeEnabled = false; rpl::variable _windowControlsLayout; + WindowPosition _windowPosition; // per-window bool _tabbedReplacedWithInfo = false; // per-window rpl::event_stream _tabbedReplacedWithInfoValue; // per-window diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 318f43e958..fdeaa0af86 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -170,7 +170,7 @@ void MainWindow::createTrayIconMenu() { void MainWindow::applyInitialWorkMode() { Global::RefWorkMode().setForced(Global::WorkMode().value(), true); - if (cWindowPos().maximized) { + if (Core::App().settings().windowPosition().maximized) { DEBUG_LOG(("Window Pos: First show, setting maximized.")); setWindowState(Qt::WindowMaximized); } diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index 09065ecb5c..c58e3b211b 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -40,7 +40,6 @@ bool gSendToMenu = false; bool gUseExternalVideoPlayer = false; bool gUseFreeType = false; bool gAutoUpdate = true; -TWindowPos gWindowPos; LaunchMode gLaunchMode = LaunchModeNormal; bool gSeenTrayTooltip = false; bool gRestartingUpdate = false, gRestarting = false, gRestartingToSettings = false, gWriteProtected = false; diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index 82a73b0ada..e8d7ab684a 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -68,18 +68,6 @@ inline const QString &cDialogHelperPathFinal() { DeclareSetting(bool, AutoUpdate); -struct TWindowPos { - TWindowPos() = default; - - int32 moncrc = 0; - int maximized = 0; - int scale = 0; - int x = 0; - int y = 0; - int w = 0; - int h = 0; -}; -DeclareSetting(TWindowPos, WindowPos); DeclareSetting(bool, SeenTrayTooltip); DeclareSetting(bool, RestartingUpdate); DeclareSetting(bool, Restarting); diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp index a703d96f3a..f41dcbd83a 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp @@ -721,16 +721,16 @@ bool ReadSetting( context.legacyRead = true; } break; - case dbiWindowPosition: { - auto position = TWindowPos(); + case dbiWindowPositionOld: { + auto position = Core::WindowPosition(); + if (!CheckStreamStatus(stream)) { + return false; + } stream >> position.x >> position.y >> position.w >> position.h; stream >> position.moncrc >> position.maximized; - if (version >= 2005009) { - stream >> position.scale; - } if (!CheckStreamStatus(stream)) return false; - DEBUG_LOG(("Window Pos: Read from storage %1, %2, %3, %4 (scale %5%, maximized %6)") + DEBUG_LOG(("Window Pos: Read from legacy storage %1, %2, %3, %4 (scale %5%, maximized %6)") .arg(position.x) .arg(position.y) .arg(position.w) @@ -738,7 +738,8 @@ bool ReadSetting( .arg(position.scale) .arg(Logs::b(position.maximized))); - cSetWindowPos(position); + Core::App().settings().setWindowPosition(position); + context.legacyRead = true; } break; case dbiLoggedPhoneNumberOld: { // deprecated diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.h b/Telegram/SourceFiles/storage/details/storage_settings_scheme.h index d5384f25e9..0dc94b817c 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.h +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.h @@ -91,7 +91,7 @@ enum { dbiDesktopNotifyOld = 0x0b, dbiAutoUpdate = 0x0c, dbiLastUpdateCheck = 0x0d, - dbiWindowPosition = 0x0e, + dbiWindowPositionOld = 0x0e, dbiConnectionTypeOld = 0x0f, // 0x10 reserved dbiDefaultAttach = 0x11, diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 73a32f7b95..4700a0ffa0 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -529,19 +529,6 @@ void writeSettings() { data.stream << quint32(dbiLanguagesKey) << quint64(_languagesKey); } - auto position = cWindowPos(); - data.stream << quint32(dbiWindowPosition) << qint32(position.x) << qint32(position.y) << qint32(position.w) << qint32(position.h); - data.stream << qint32(position.moncrc) << qint32(position.maximized); - data.stream << qint32(position.scale); - - DEBUG_LOG(("Window Pos: Writing to storage %1, %2, %3, %4 (scale %5%, maximized %6)") - .arg(position.x) - .arg(position.y) - .arg(position.w) - .arg(position.h) - .arg(position.scale) - .arg(Logs::b(position.maximized))); - settings.writeEncrypted(data, SettingsKey); } diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 05afa18fb6..6ed2698c3c 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -292,7 +292,7 @@ void MainWindow::handleVisibleChanged(bool visible) { setWindowState(Qt::WindowMaximized); } } else { - _maximizedBeforeHide = cWindowPos().maximized; + _maximizedBeforeHide = Core::App().settings().windowPosition().maximized; } handleVisibleChangedHook(visible); @@ -424,8 +424,9 @@ void MainWindow::initSize() { return; } - auto position = cWindowPos(); - DEBUG_LOG(("Window Pos: Initializing first %1, %2, %3, %4 (scale %5%, maximized %6)") + auto position = Core::App().settings().windowPosition(); + DEBUG_LOG(("Window Pos: Initializing first %1, %2, %3, %4 " + "(scale %5%, maximized %6)") .arg(position.x) .arg(position.y) .arg(position.w) @@ -625,7 +626,7 @@ void MainWindow::savePosition(Qt::WindowState state) { return; } - auto savedPosition = cWindowPos(); + const auto &savedPosition = Core::App().settings().windowPosition(); auto realPosition = savedPosition; if (state == Qt::WindowMaximized) { @@ -657,7 +658,11 @@ void MainWindow::savePosition(Qt::WindowState state) { } if (chosen) { auto screenGeometry = chosen->geometry(); - DEBUG_LOG(("Window Pos: Screen found, geometry: %1, %2, %3, %4").arg(screenGeometry.x()).arg(screenGeometry.y()).arg(screenGeometry.width()).arg(screenGeometry.height())); + DEBUG_LOG(("Window Pos: Screen found, geometry: %1, %2, %3, %4" + ).arg(screenGeometry.x() + ).arg(screenGeometry.y() + ).arg(screenGeometry.width() + ).arg(screenGeometry.height())); realPosition.x -= screenGeometry.x(); realPosition.y -= screenGeometry.y(); realPosition.moncrc = screenNameChecksum(chosen->name()); @@ -678,8 +683,8 @@ void MainWindow::savePosition(Qt::WindowState state) { .arg(realPosition.h) .arg(realPosition.scale) .arg(Logs::b(realPosition.maximized))); - cSetWindowPos(realPosition); - Local::writeSettings(); + Core::App().settings().setWindowPosition(realPosition); + Core::App().saveSettingsDelayed(); } } } diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 77856c3a21..e14bc4681d 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 77856c3a21870e656b6e9ae48bf9c9a19a2a86c3 +Subproject commit e14bc4681d69c1b538b8c5af51501077ae5a8a86