2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Allow wide chats in empty window.

This commit is contained in:
John Preston
2024-05-16 13:35:21 +04:00
parent 4d4cf472c8
commit d91b75b8f8
9 changed files with 149 additions and 57 deletions

View File

@@ -123,7 +123,8 @@ Settings::Settings()
: _sendSubmitWay(Ui::InputSubmitSettings::Enter)
, _floatPlayerColumn(Window::Column::Second)
, _floatPlayerCorner(RectPart::TopRight)
, _dialogsWidthRatio(DefaultDialogsWidthRatio()) {
, _dialogsWithChatWidthRatio(DefaultDialogsWidthRatio())
, _dialogsNoChatWidthRatio(DefaultDialogsWidthRatio()) {
}
Settings::~Settings() = default;
@@ -218,7 +219,8 @@ QByteArray Settings::serialize() const {
+ Serialize::stringSize(_callCaptureDeviceId.current())
+ Serialize::bytearraySize(ivPosition)
+ Serialize::stringSize(noWarningExtensions)
+ Serialize::stringSize(_customFontFamily);
+ Serialize::stringSize(_customFontFamily)
+ sizeof(qint32);
auto result = QByteArray();
result.reserve(size);
@@ -280,7 +282,7 @@ QByteArray Settings::serialize() const {
<< qint32(_floatPlayerCorner)
<< qint32(_thirdSectionInfoEnabled ? 1 : 0)
<< qint32(std::clamp(
qRound(_dialogsWidthRatio.current() * 1000000),
qRound(_dialogsWithChatWidthRatio.current() * 1000000),
0,
1000000))
<< qint32(_thirdColumnWidth.current())
@@ -365,7 +367,11 @@ QByteArray Settings::serialize() const {
<< _callCaptureDeviceId.current()
<< ivPosition
<< noWarningExtensions
<< _customFontFamily;
<< _customFontFamily
<< qint32(std::clamp(
qRound(_dialogsNoChatWidthRatio.current() * 1000000),
0,
1000000));
}
Ensures(result.size() == size);
@@ -434,7 +440,8 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
qint32 floatPlayerColumn = static_cast<qint32>(Window::Column::Second);
qint32 floatPlayerCorner = static_cast<qint32>(RectPart::TopRight);
qint32 thirdSectionInfoEnabled = 0;
float64 dialogsWidthRatio = _dialogsWidthRatio.current();
float64 dialogsWithChatWidthRatio = _dialogsWithChatWidthRatio.current();
float64 dialogsNoChatWidthRatio = _dialogsNoChatWidthRatio.current();
qint32 thirdColumnWidth = _thirdColumnWidth.current();
qint32 thirdSectionExtendedBy = _thirdSectionExtendedBy;
qint32 notifyFromAll = _notifyFromAll ? 1 : 0;
@@ -546,18 +553,18 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
>> mainMenuAccountsShown;
}
if (!stream.atEnd()) {
auto dialogsWidthRatioInt = qint32();
auto dialogsWithChatWidthRatioInt = qint32();
stream
>> tabbedSelectorSectionEnabled
>> floatPlayerColumn
>> floatPlayerCorner
>> thirdSectionInfoEnabled
>> dialogsWidthRatioInt
>> dialogsWithChatWidthRatioInt
>> thirdColumnWidth
>> thirdSectionExtendedBy
>> notifyFromAll;
dialogsWidthRatio = std::clamp(
dialogsWidthRatioInt / 1000000.,
dialogsWithChatWidthRatio = std::clamp(
dialogsWithChatWidthRatioInt / 1000000.,
0.,
1.);
}
@@ -772,6 +779,15 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
if (!stream.atEnd()) {
stream >> customFontFamily;
}
if (!stream.atEnd()) {
auto dialogsNoChatWidthRatioInt = qint32();
stream
>> dialogsNoChatWidthRatioInt;
dialogsNoChatWidthRatio = std::clamp(
dialogsNoChatWidthRatioInt / 1000000.,
0.,
1.);
}
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: "
"Bad data for Core::Settings::constructFromSerialized()"));
@@ -872,7 +888,10 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
case RectPart::BottomRight: _floatPlayerCorner = uncheckedCorner; break;
}
_thirdSectionInfoEnabled = thirdSectionInfoEnabled;
_dialogsWidthRatio = dialogsWidthRatio;
_dialogsWithChatWidthRatio = dialogsWithChatWidthRatio;
_dialogsNoChatWidthRatio = (dialogsWithChatWidthRatio > 0)
? dialogsWithChatWidthRatio
: dialogsNoChatWidthRatio;
_thirdColumnWidth = thirdColumnWidth;
_thirdSectionExtendedBy = thirdSectionExtendedBy;
if (_thirdSectionInfoEnabled) {
@@ -1025,16 +1044,46 @@ void Settings::setTabbedReplacedWithInfo(bool enabled) {
}
}
void Settings::setDialogsWidthRatio(float64 ratio) {
_dialogsWidthRatio = ratio;
void Settings::updateDialogsWidthRatio(float64 ratio, bool nochat) {
const auto changeWithChat = !nochat
|| (dialogsWithChatWidthRatio() > 0)
|| _dialogsWidthSetToZeroWithoutChat;
const auto changedWithChat = changeWithChat
&& (dialogsWithChatWidthRatio() != ratio);
const auto changeNoChat = nochat
|| (dialogsWithChatWidthRatio() != ratio);
const auto changedNoChat = changeNoChat
&& (dialogsNoChatWidthRatio() != ratio);
if (changedWithChat) {
_dialogsWidthSetToZeroWithoutChat = nochat && !(ratio > 0);
_dialogsWithChatWidthRatio = ratio;
}
if (changedNoChat) {
_dialogsNoChatWidthRatio = ratio;
}
}
float64 Settings::dialogsWidthRatio() const {
return _dialogsWidthRatio.current();
float64 Settings::dialogsWidthRatio(bool nochat) const {
const auto withchat = dialogsWithChatWidthRatio();
return (!nochat || withchat > 0) ? withchat : dialogsNoChatWidthRatio();
}
rpl::producer<float64> Settings::dialogsWidthRatioChanges() const {
return _dialogsWidthRatio.changes();
float64 Settings::dialogsWithChatWidthRatio() const {
return _dialogsWithChatWidthRatio.current();
}
rpl::producer<float64> Settings::dialogsWithChatWidthRatioChanges() const {
return _dialogsWithChatWidthRatio.changes();
}
float64 Settings::dialogsNoChatWidthRatio() const {
return _dialogsNoChatWidthRatio.current();
}
rpl::producer<float64> Settings::dialogsNoChatWidthRatioChanges() const {
return _dialogsNoChatWidthRatio.changes();
}
void Settings::setThirdColumnWidth(int width) {
@@ -1326,7 +1375,8 @@ void Settings::resetOnLastLogout() {
_floatPlayerCorner = RectPart::TopRight; // per-window
_thirdSectionInfoEnabled = true; // per-window
_thirdSectionExtendedBy = -1; // per-window
_dialogsWidthRatio = DefaultDialogsWidthRatio(); // per-window
_dialogsWithChatWidthRatio = DefaultDialogsWidthRatio(); // per-window
_dialogsNoChatWidthRatio = DefaultDialogsWidthRatio(); // per-window
_thirdColumnWidth = kDefaultThirdColumnWidth; // p-w
_notifyFromAll = true;
_tabbedReplacedWithInfo = false; // per-window

View File

@@ -614,9 +614,15 @@ public:
[[nodiscard]] RectPart floatPlayerCorner() const {
return _floatPlayerCorner;
}
void setDialogsWidthRatio(float64 ratio);
[[nodiscard]] float64 dialogsWidthRatio() const;
[[nodiscard]] rpl::producer<float64> dialogsWidthRatioChanges() const;
void updateDialogsWidthRatio(float64 ratio, bool nochat);
[[nodiscard]] float64 dialogsWidthRatio(bool nochat) const;
[[nodiscard]] float64 dialogsWithChatWidthRatio() const;
[[nodiscard]] rpl::producer<float64> dialogsWithChatWidthRatioChanges() const;
[[nodiscard]] float64 dialogsNoChatWidthRatio() const;
[[nodiscard]] rpl::producer<float64> dialogsNoChatWidthRatioChanges() const;
void setThirdColumnWidth(int width);
[[nodiscard]] int thirdColumnWidth() const;
[[nodiscard]] rpl::producer<int> thirdColumnWidthChanges() const;
@@ -969,7 +975,8 @@ private:
bool _thirdSectionInfoEnabled = true; // per-window
rpl::event_stream<bool> _thirdSectionInfoEnabledValue; // per-window
int _thirdSectionExtendedBy = -1; // per-window
rpl::variable<float64> _dialogsWidthRatio; // per-window
rpl::variable<float64> _dialogsWithChatWidthRatio; // per-window
rpl::variable<float64> _dialogsNoChatWidthRatio; // per-window
rpl::variable<int> _thirdColumnWidth = kDefaultThirdColumnWidth; // p-w
bool _notifyFromAll = true;
rpl::variable<bool> _nativeWindowFrame = false;
@@ -1015,6 +1022,7 @@ private:
float64 _rememberedSongVolume = kDefaultVolume;
bool _rememberedSoundNotifyFromTray = false;
bool _rememberedFlashBounceNotifyFromTray = false;
bool _dialogsWidthSetToZeroWithoutChat = false;
QByteArray _photoEditorBrush;