mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-08 08:04:08 +02:00
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"
|
#include "facades.h"
|
||||||
|
|
||||||
namespace Core {
|
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()
|
Settings::Settings()
|
||||||
: _sendSubmitWay(Ui::InputSubmitSettings::Enter)
|
: _sendSubmitWay(Ui::InputSubmitSettings::Enter)
|
||||||
|
@ -27,6 +73,8 @@ Settings::Settings()
|
||||||
|
|
||||||
QByteArray Settings::serialize() const {
|
QByteArray Settings::serialize() const {
|
||||||
const auto themesAccentColors = _themesAccentColors.serialize();
|
const auto themesAccentColors = _themesAccentColors.serialize();
|
||||||
|
const auto windowPosition = Serialize(_windowPosition);
|
||||||
|
|
||||||
auto size = Serialize::bytearraySize(themesAccentColors)
|
auto size = Serialize::bytearraySize(themesAccentColors)
|
||||||
+ sizeof(qint32) * 5
|
+ sizeof(qint32) * 5
|
||||||
+ Serialize::stringSize(_downloadPath.current())
|
+ Serialize::stringSize(_downloadPath.current())
|
||||||
|
@ -40,6 +88,7 @@ QByteArray Settings::serialize() const {
|
||||||
size += Serialize::stringSize(key) + Serialize::stringSize(value);
|
size += Serialize::stringSize(key) + Serialize::stringSize(value);
|
||||||
}
|
}
|
||||||
size += Serialize::bytearraySize(_videoPipGeometry);
|
size += Serialize::bytearraySize(_videoPipGeometry);
|
||||||
|
size += Serialize::bytearraySize(windowPosition);
|
||||||
|
|
||||||
auto result = QByteArray();
|
auto result = QByteArray();
|
||||||
result.reserve(size);
|
result.reserve(size);
|
||||||
|
@ -115,7 +164,8 @@ QByteArray Settings::serialize() const {
|
||||||
<< _groupCallPushToTalkShortcut
|
<< _groupCallPushToTalkShortcut
|
||||||
<< qint64(_groupCallPushToTalkDelay)
|
<< qint64(_groupCallPushToTalkDelay)
|
||||||
<< qint32(0) // Call audio backend
|
<< qint32(0) // Call audio backend
|
||||||
<< qint32(_disableCalls ? 1 : 0);
|
<< qint32(_disableCalls ? 1 : 0)
|
||||||
|
<< windowPosition;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -188,6 +238,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||||
qint64 groupCallPushToTalkDelay = _groupCallPushToTalkDelay;
|
qint64 groupCallPushToTalkDelay = _groupCallPushToTalkDelay;
|
||||||
qint32 callAudioBackend = 0;
|
qint32 callAudioBackend = 0;
|
||||||
qint32 disableCalls = _disableCalls ? 1 : 0;
|
qint32 disableCalls = _disableCalls ? 1 : 0;
|
||||||
|
QByteArray windowPosition;
|
||||||
|
|
||||||
stream >> themesAccentColors;
|
stream >> themesAccentColors;
|
||||||
if (!stream.atEnd()) {
|
if (!stream.atEnd()) {
|
||||||
|
@ -289,6 +340,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||||
if (!stream.atEnd()) {
|
if (!stream.atEnd()) {
|
||||||
stream >> disableCalls;
|
stream >> disableCalls;
|
||||||
}
|
}
|
||||||
|
if (!stream.atEnd()) {
|
||||||
|
stream >> windowPosition;
|
||||||
|
}
|
||||||
if (stream.status() != QDataStream::Ok) {
|
if (stream.status() != QDataStream::Ok) {
|
||||||
LOG(("App Error: "
|
LOG(("App Error: "
|
||||||
"Bad data for Core::Settings::constructFromSerialized()"));
|
"Bad data for Core::Settings::constructFromSerialized()"));
|
||||||
|
@ -389,6 +443,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||||
_groupCallPushToTalkShortcut = groupCallPushToTalkShortcut;
|
_groupCallPushToTalkShortcut = groupCallPushToTalkShortcut;
|
||||||
_groupCallPushToTalkDelay = groupCallPushToTalkDelay;
|
_groupCallPushToTalkDelay = groupCallPushToTalkDelay;
|
||||||
_disableCalls = (disableCalls == 1);
|
_disableCalls = (disableCalls == 1);
|
||||||
|
if (!windowPosition.isEmpty()) {
|
||||||
|
_windowPosition = Deserialize(windowPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::chatWide() const {
|
bool Settings::chatWide() const {
|
||||||
|
|
|
@ -28,6 +28,18 @@ enum class Backend;
|
||||||
|
|
||||||
namespace Core {
|
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 {
|
class Settings final {
|
||||||
public:
|
public:
|
||||||
enum class ScreenCorner {
|
enum class ScreenCorner {
|
||||||
|
@ -503,6 +515,12 @@ public:
|
||||||
[[nodiscard]] rpl::producer<Window::ControlsLayout> windowControlsLayoutChanges() const {
|
[[nodiscard]] rpl::producer<Window::ControlsLayout> windowControlsLayoutChanges() const {
|
||||||
return _windowControlsLayout.changes();
|
return _windowControlsLayout.changes();
|
||||||
}
|
}
|
||||||
|
[[nodiscard]] const WindowPosition &windowPosition() const {
|
||||||
|
return _windowPosition;
|
||||||
|
}
|
||||||
|
void setWindowPosition(const WindowPosition &position) {
|
||||||
|
_windowPosition = position;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] static bool ThirdColumnByDefault();
|
[[nodiscard]] static bool ThirdColumnByDefault();
|
||||||
[[nodiscard]] float64 DefaultDialogsWidthRatio();
|
[[nodiscard]] float64 DefaultDialogsWidthRatio();
|
||||||
|
@ -585,6 +603,7 @@ private:
|
||||||
rpl::variable<std::optional<bool>> _systemDarkMode = std::nullopt;
|
rpl::variable<std::optional<bool>> _systemDarkMode = std::nullopt;
|
||||||
rpl::variable<bool> _systemDarkModeEnabled = false;
|
rpl::variable<bool> _systemDarkModeEnabled = false;
|
||||||
rpl::variable<Window::ControlsLayout> _windowControlsLayout;
|
rpl::variable<Window::ControlsLayout> _windowControlsLayout;
|
||||||
|
WindowPosition _windowPosition; // per-window
|
||||||
|
|
||||||
bool _tabbedReplacedWithInfo = false; // per-window
|
bool _tabbedReplacedWithInfo = false; // per-window
|
||||||
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
|
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
|
||||||
|
|
|
@ -170,7 +170,7 @@ void MainWindow::createTrayIconMenu() {
|
||||||
void MainWindow::applyInitialWorkMode() {
|
void MainWindow::applyInitialWorkMode() {
|
||||||
Global::RefWorkMode().setForced(Global::WorkMode().value(), true);
|
Global::RefWorkMode().setForced(Global::WorkMode().value(), true);
|
||||||
|
|
||||||
if (cWindowPos().maximized) {
|
if (Core::App().settings().windowPosition().maximized) {
|
||||||
DEBUG_LOG(("Window Pos: First show, setting maximized."));
|
DEBUG_LOG(("Window Pos: First show, setting maximized."));
|
||||||
setWindowState(Qt::WindowMaximized);
|
setWindowState(Qt::WindowMaximized);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ bool gSendToMenu = false;
|
||||||
bool gUseExternalVideoPlayer = false;
|
bool gUseExternalVideoPlayer = false;
|
||||||
bool gUseFreeType = false;
|
bool gUseFreeType = false;
|
||||||
bool gAutoUpdate = true;
|
bool gAutoUpdate = true;
|
||||||
TWindowPos gWindowPos;
|
|
||||||
LaunchMode gLaunchMode = LaunchModeNormal;
|
LaunchMode gLaunchMode = LaunchModeNormal;
|
||||||
bool gSeenTrayTooltip = false;
|
bool gSeenTrayTooltip = false;
|
||||||
bool gRestartingUpdate = false, gRestarting = false, gRestartingToSettings = false, gWriteProtected = false;
|
bool gRestartingUpdate = false, gRestarting = false, gRestartingToSettings = false, gWriteProtected = false;
|
||||||
|
|
|
@ -68,18 +68,6 @@ inline const QString &cDialogHelperPathFinal() {
|
||||||
|
|
||||||
DeclareSetting(bool, AutoUpdate);
|
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, SeenTrayTooltip);
|
||||||
DeclareSetting(bool, RestartingUpdate);
|
DeclareSetting(bool, RestartingUpdate);
|
||||||
DeclareSetting(bool, Restarting);
|
DeclareSetting(bool, Restarting);
|
||||||
|
|
|
@ -721,16 +721,16 @@ bool ReadSetting(
|
||||||
context.legacyRead = true;
|
context.legacyRead = true;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case dbiWindowPosition: {
|
case dbiWindowPositionOld: {
|
||||||
auto position = TWindowPos();
|
auto position = Core::WindowPosition();
|
||||||
|
if (!CheckStreamStatus(stream)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
stream >> position.x >> position.y >> position.w >> position.h;
|
stream >> position.x >> position.y >> position.w >> position.h;
|
||||||
stream >> position.moncrc >> position.maximized;
|
stream >> position.moncrc >> position.maximized;
|
||||||
if (version >= 2005009) {
|
|
||||||
stream >> position.scale;
|
|
||||||
}
|
|
||||||
if (!CheckStreamStatus(stream)) return false;
|
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.x)
|
||||||
.arg(position.y)
|
.arg(position.y)
|
||||||
.arg(position.w)
|
.arg(position.w)
|
||||||
|
@ -738,7 +738,8 @@ bool ReadSetting(
|
||||||
.arg(position.scale)
|
.arg(position.scale)
|
||||||
.arg(Logs::b(position.maximized)));
|
.arg(Logs::b(position.maximized)));
|
||||||
|
|
||||||
cSetWindowPos(position);
|
Core::App().settings().setWindowPosition(position);
|
||||||
|
context.legacyRead = true;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case dbiLoggedPhoneNumberOld: { // deprecated
|
case dbiLoggedPhoneNumberOld: { // deprecated
|
||||||
|
|
|
@ -91,7 +91,7 @@ enum {
|
||||||
dbiDesktopNotifyOld = 0x0b,
|
dbiDesktopNotifyOld = 0x0b,
|
||||||
dbiAutoUpdate = 0x0c,
|
dbiAutoUpdate = 0x0c,
|
||||||
dbiLastUpdateCheck = 0x0d,
|
dbiLastUpdateCheck = 0x0d,
|
||||||
dbiWindowPosition = 0x0e,
|
dbiWindowPositionOld = 0x0e,
|
||||||
dbiConnectionTypeOld = 0x0f,
|
dbiConnectionTypeOld = 0x0f,
|
||||||
// 0x10 reserved
|
// 0x10 reserved
|
||||||
dbiDefaultAttach = 0x11,
|
dbiDefaultAttach = 0x11,
|
||||||
|
|
|
@ -529,19 +529,6 @@ void writeSettings() {
|
||||||
data.stream << quint32(dbiLanguagesKey) << quint64(_languagesKey);
|
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);
|
settings.writeEncrypted(data, SettingsKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -292,7 +292,7 @@ void MainWindow::handleVisibleChanged(bool visible) {
|
||||||
setWindowState(Qt::WindowMaximized);
|
setWindowState(Qt::WindowMaximized);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_maximizedBeforeHide = cWindowPos().maximized;
|
_maximizedBeforeHide = Core::App().settings().windowPosition().maximized;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleVisibleChangedHook(visible);
|
handleVisibleChangedHook(visible);
|
||||||
|
@ -424,8 +424,9 @@ void MainWindow::initSize() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto position = cWindowPos();
|
auto position = Core::App().settings().windowPosition();
|
||||||
DEBUG_LOG(("Window Pos: Initializing first %1, %2, %3, %4 (scale %5%, maximized %6)")
|
DEBUG_LOG(("Window Pos: Initializing first %1, %2, %3, %4 "
|
||||||
|
"(scale %5%, maximized %6)")
|
||||||
.arg(position.x)
|
.arg(position.x)
|
||||||
.arg(position.y)
|
.arg(position.y)
|
||||||
.arg(position.w)
|
.arg(position.w)
|
||||||
|
@ -625,7 +626,7 @@ void MainWindow::savePosition(Qt::WindowState state) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto savedPosition = cWindowPos();
|
const auto &savedPosition = Core::App().settings().windowPosition();
|
||||||
auto realPosition = savedPosition;
|
auto realPosition = savedPosition;
|
||||||
|
|
||||||
if (state == Qt::WindowMaximized) {
|
if (state == Qt::WindowMaximized) {
|
||||||
|
@ -657,7 +658,11 @@ void MainWindow::savePosition(Qt::WindowState state) {
|
||||||
}
|
}
|
||||||
if (chosen) {
|
if (chosen) {
|
||||||
auto screenGeometry = chosen->geometry();
|
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.x -= screenGeometry.x();
|
||||||
realPosition.y -= screenGeometry.y();
|
realPosition.y -= screenGeometry.y();
|
||||||
realPosition.moncrc = screenNameChecksum(chosen->name());
|
realPosition.moncrc = screenNameChecksum(chosen->name());
|
||||||
|
@ -678,8 +683,8 @@ void MainWindow::savePosition(Qt::WindowState state) {
|
||||||
.arg(realPosition.h)
|
.arg(realPosition.h)
|
||||||
.arg(realPosition.scale)
|
.arg(realPosition.scale)
|
||||||
.arg(Logs::b(realPosition.maximized)));
|
.arg(Logs::b(realPosition.maximized)));
|
||||||
cSetWindowPos(realPosition);
|
Core::App().settings().setWindowPosition(realPosition);
|
||||||
Local::writeSettings();
|
Core::App().saveSettingsDelayed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 77856c3a21870e656b6e9ae48bf9c9a19a2a86c3
|
Subproject commit e14bc4681d69c1b538b8c5af51501077ae5a8a86
|
Loading…
Add table
Reference in a new issue