Version 2.5.9: Move window position to Core::Settings.
This commit is contained in:
parent
70570e0987
commit
b3660f1ed8
10 changed files with 100 additions and 44 deletions
|
@ -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 {
|
||||
|
|
|
@ -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<Window::ControlsLayout> 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<std::optional<bool>> _systemDarkMode = std::nullopt;
|
||||
rpl::variable<bool> _systemDarkModeEnabled = false;
|
||||
rpl::variable<Window::ControlsLayout> _windowControlsLayout;
|
||||
WindowPosition _windowPosition; // per-window
|
||||
|
||||
bool _tabbedReplacedWithInfo = false; // per-window
|
||||
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -91,7 +91,7 @@ enum {
|
|||
dbiDesktopNotifyOld = 0x0b,
|
||||
dbiAutoUpdate = 0x0c,
|
||||
dbiLastUpdateCheck = 0x0d,
|
||||
dbiWindowPosition = 0x0e,
|
||||
dbiWindowPositionOld = 0x0e,
|
||||
dbiConnectionTypeOld = 0x0f,
|
||||
// 0x10 reserved
|
||||
dbiDefaultAttach = 0x11,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 77856c3a21870e656b6e9ae48bf9c9a19a2a86c3
|
||||
Subproject commit e14bc4681d69c1b538b8c5af51501077ae5a8a86
|
Loading…
Reference in a new issue