mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Save media viewer position to Settings.
This commit is contained in:
parent
783d1cd4c1
commit
832d47121f
12 changed files with 390 additions and 144 deletions
|
@ -38,6 +38,18 @@ namespace {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LogPosition(const WindowPosition &position, const QString &name) {
|
||||||
|
DEBUG_LOG(("%1 Pos: Writing to storage %2, %3, %4, %5"
|
||||||
|
" (scale %6%, maximized %7)")
|
||||||
|
.arg(name)
|
||||||
|
.arg(position.x)
|
||||||
|
.arg(position.y)
|
||||||
|
.arg(position.w)
|
||||||
|
.arg(position.h)
|
||||||
|
.arg(position.scale)
|
||||||
|
.arg(position.maximized));
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] QByteArray Serialize(const WindowPosition &position) {
|
[[nodiscard]] QByteArray Serialize(const WindowPosition &position) {
|
||||||
auto result = QByteArray();
|
auto result = QByteArray();
|
||||||
const auto size = 7 * sizeof(qint32);
|
const auto size = 7 * sizeof(qint32);
|
||||||
|
@ -54,14 +66,6 @@ namespace {
|
||||||
<< qint32(position.maximized)
|
<< qint32(position.maximized)
|
||||||
<< qint32(position.scale);
|
<< 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +89,35 @@ namespace {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
[[nodiscard]] WindowPosition AdjustToScale(
|
||||||
|
WindowPosition position,
|
||||||
|
const QString &name) {
|
||||||
|
DEBUG_LOG(("%1 Pos: Initializing first %2, %3, %4, %5 "
|
||||||
|
"(scale %6%, maximized %7)")
|
||||||
|
.arg(name)
|
||||||
|
.arg(position.x)
|
||||||
|
.arg(position.y)
|
||||||
|
.arg(position.w)
|
||||||
|
.arg(position.h)
|
||||||
|
.arg(position.scale)
|
||||||
|
.arg(position.maximized));
|
||||||
|
|
||||||
|
if (!position.scale) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
const auto scaleFactor = cScale() / float64(position.scale);
|
||||||
|
if (scaleFactor != 1.) {
|
||||||
|
// Change scale while keeping the position center in place.
|
||||||
|
position.x += position.w / 2;
|
||||||
|
position.y += position.h / 2;
|
||||||
|
position.w *= scaleFactor;
|
||||||
|
position.h *= scaleFactor;
|
||||||
|
position.x -= position.w / 2;
|
||||||
|
position.y -= position.h / 2;
|
||||||
|
}
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
: _sendSubmitWay(Ui::InputSubmitSettings::Enter)
|
: _sendSubmitWay(Ui::InputSubmitSettings::Enter)
|
||||||
, _floatPlayerColumn(Window::Column::Second)
|
, _floatPlayerColumn(Window::Column::Second)
|
||||||
|
@ -97,6 +130,9 @@ Settings::~Settings() = default;
|
||||||
QByteArray Settings::serialize() const {
|
QByteArray Settings::serialize() const {
|
||||||
const auto themesAccentColors = _themesAccentColors.serialize();
|
const auto themesAccentColors = _themesAccentColors.serialize();
|
||||||
const auto windowPosition = Serialize(_windowPosition);
|
const auto windowPosition = Serialize(_windowPosition);
|
||||||
|
LogPosition(_windowPosition, u"Window"_q);
|
||||||
|
const auto mediaViewPosition = Serialize(_mediaViewPosition);
|
||||||
|
LogPosition(_mediaViewPosition, u"Viewer"_q);
|
||||||
const auto proxy = _proxy.serialize();
|
const auto proxy = _proxy.serialize();
|
||||||
const auto skipLanguages = _skipTranslationLanguages.current();
|
const auto skipLanguages = _skipTranslationLanguages.current();
|
||||||
|
|
||||||
|
@ -160,7 +196,8 @@ QByteArray Settings::serialize() const {
|
||||||
+ (skipLanguages.size() * sizeof(quint64))
|
+ (skipLanguages.size() * sizeof(quint64))
|
||||||
+ sizeof(qint32)
|
+ sizeof(qint32)
|
||||||
+ sizeof(quint64)
|
+ sizeof(quint64)
|
||||||
+ sizeof(qint32) * 3;
|
+ sizeof(qint32) * 3
|
||||||
|
+ Serialize::bytearraySize(mediaViewPosition);
|
||||||
|
|
||||||
auto result = QByteArray();
|
auto result = QByteArray();
|
||||||
result.reserve(size);
|
result.reserve(size);
|
||||||
|
@ -291,7 +328,8 @@ QByteArray Settings::serialize() const {
|
||||||
<< quint64(QLocale::Language(_translateToRaw.current()))
|
<< quint64(QLocale::Language(_translateToRaw.current()))
|
||||||
<< qint32(_windowTitleContent.current().hideChatName ? 1 : 0)
|
<< qint32(_windowTitleContent.current().hideChatName ? 1 : 0)
|
||||||
<< qint32(_windowTitleContent.current().hideAccountName ? 1 : 0)
|
<< qint32(_windowTitleContent.current().hideAccountName ? 1 : 0)
|
||||||
<< qint32(_windowTitleContent.current().hideTotalUnread ? 1 : 0);
|
<< qint32(_windowTitleContent.current().hideTotalUnread ? 1 : 0)
|
||||||
|
<< mediaViewPosition;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -394,6 +432,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||||
qint32 hideChatName = _windowTitleContent.current().hideChatName ? 1 : 0;
|
qint32 hideChatName = _windowTitleContent.current().hideChatName ? 1 : 0;
|
||||||
qint32 hideAccountName = _windowTitleContent.current().hideAccountName ? 1 : 0;
|
qint32 hideAccountName = _windowTitleContent.current().hideAccountName ? 1 : 0;
|
||||||
qint32 hideTotalUnread = _windowTitleContent.current().hideTotalUnread ? 1 : 0;
|
qint32 hideTotalUnread = _windowTitleContent.current().hideTotalUnread ? 1 : 0;
|
||||||
|
QByteArray mediaViewPosition;
|
||||||
|
|
||||||
stream >> themesAccentColors;
|
stream >> themesAccentColors;
|
||||||
if (!stream.atEnd()) {
|
if (!stream.atEnd()) {
|
||||||
|
@ -619,6 +658,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||||
>> hideAccountName
|
>> hideAccountName
|
||||||
>> hideTotalUnread;
|
>> hideTotalUnread;
|
||||||
}
|
}
|
||||||
|
if (!stream.atEnd()) {
|
||||||
|
stream >> mediaViewPosition;
|
||||||
|
}
|
||||||
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()"));
|
||||||
|
@ -809,6 +851,12 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||||
.hideAccountName = (hideAccountName == 1),
|
.hideAccountName = (hideAccountName == 1),
|
||||||
.hideTotalUnread = (hideTotalUnread == 1),
|
.hideTotalUnread = (hideTotalUnread == 1),
|
||||||
};
|
};
|
||||||
|
if (!mediaViewPosition.isEmpty()) {
|
||||||
|
_mediaViewPosition = Deserialize(mediaViewPosition);
|
||||||
|
if (!_mediaViewPosition.w && !_mediaViewPosition.maximized) {
|
||||||
|
_mediaViewPosition = { .maximized = 2 };
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Settings::getSoundPath(const QString &key) const {
|
QString Settings::getSoundPath(const QString &key) const {
|
||||||
|
|
|
@ -52,8 +52,20 @@ struct WindowPosition {
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int w = 0;
|
int w = 0;
|
||||||
int h = 0;
|
int h = 0;
|
||||||
|
|
||||||
|
friend inline constexpr auto operator<=>(
|
||||||
|
WindowPosition,
|
||||||
|
WindowPosition) = default;
|
||||||
|
|
||||||
|
[[nodiscard]] QRect rect() const {
|
||||||
|
return QRect(x, y, w, h);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] WindowPosition AdjustToScale(
|
||||||
|
WindowPosition position,
|
||||||
|
const QString &name);
|
||||||
|
|
||||||
struct WindowTitleContent {
|
struct WindowTitleContent {
|
||||||
bool hideChatName : 1 = false;
|
bool hideChatName : 1 = false;
|
||||||
bool hideAccountName : 1 = false;
|
bool hideAccountName : 1 = false;
|
||||||
|
@ -759,6 +771,13 @@ public:
|
||||||
void setRememberedDeleteMessageOnlyForYou(bool value);
|
void setRememberedDeleteMessageOnlyForYou(bool value);
|
||||||
[[nodiscard]] bool rememberedDeleteMessageOnlyForYou() const;
|
[[nodiscard]] bool rememberedDeleteMessageOnlyForYou() const;
|
||||||
|
|
||||||
|
[[nodiscard]] const WindowPosition &mediaViewPosition() const {
|
||||||
|
return _mediaViewPosition;
|
||||||
|
}
|
||||||
|
void setMediaViewPosition(const WindowPosition &position) {
|
||||||
|
_mediaViewPosition = position;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] static bool ThirdColumnByDefault();
|
[[nodiscard]] static bool ThirdColumnByDefault();
|
||||||
[[nodiscard]] static float64 DefaultDialogsWidthRatio();
|
[[nodiscard]] static float64 DefaultDialogsWidthRatio();
|
||||||
[[nodiscard]] static qint32 SerializePlaybackSpeed(float64 speed) {
|
[[nodiscard]] static qint32 SerializePlaybackSpeed(float64 speed) {
|
||||||
|
@ -880,6 +899,7 @@ private:
|
||||||
rpl::variable<std::vector<LanguageId>> _skipTranslationLanguages;
|
rpl::variable<std::vector<LanguageId>> _skipTranslationLanguages;
|
||||||
rpl::event_stream<> _skipTranslationLanguagesChanges;
|
rpl::event_stream<> _skipTranslationLanguagesChanges;
|
||||||
bool _rememberedDeleteMessageOnlyForYou = false;
|
bool _rememberedDeleteMessageOnlyForYou = false;
|
||||||
|
WindowPosition _mediaViewPosition = { .maximized = 2 };
|
||||||
|
|
||||||
bool _tabbedReplacedWithInfo = false; // per-window
|
bool _tabbedReplacedWithInfo = false; // per-window
|
||||||
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
|
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
|
||||||
|
|
|
@ -262,6 +262,13 @@ mediaviewGroupWidthMax: 160px;
|
||||||
mediaviewGroupSkip: 3px;
|
mediaviewGroupSkip: 3px;
|
||||||
mediaviewGroupSkipCurrent: 12px;
|
mediaviewGroupSkipCurrent: 12px;
|
||||||
|
|
||||||
|
mediaviewMinWidth: 480px;
|
||||||
|
mediaviewMinHeight: 360px;
|
||||||
|
mediaviewDefaultLeft: 160px;
|
||||||
|
mediaviewDefaultTop: 120px;
|
||||||
|
mediaviewDefaultWidth: 800px;
|
||||||
|
mediaviewDefaultHeight: 600px;
|
||||||
|
|
||||||
themePreviewSize: size(903px, 584px);
|
themePreviewSize: size(903px, 584px);
|
||||||
themePreviewBg: windowBg;
|
themePreviewBg: windowBg;
|
||||||
themePreviewOverlayOpacity: 0.8;
|
themePreviewOverlayOpacity: 0.8;
|
||||||
|
|
|
@ -88,7 +88,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_media_view.h"
|
#include "styles/style_media_view.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
#include "styles/style_window.h" // windowDefaultWidth / windowDefaultHeight
|
|
||||||
#include "styles/style_calls.h"
|
#include "styles/style_calls.h"
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
|
@ -137,6 +136,26 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] Core::WindowPosition DefaultPosition() {
|
||||||
|
const auto moncrc = [&] {
|
||||||
|
if (const auto active = Core::App().activeWindow()) {
|
||||||
|
const auto widget = active->widget();
|
||||||
|
if (const auto screen = widget->screen()) {
|
||||||
|
return Platform::ScreenNameChecksum(screen->name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Core::App().settings().windowPosition().moncrc;
|
||||||
|
}();
|
||||||
|
return {
|
||||||
|
.moncrc = moncrc,
|
||||||
|
.scale = cScale(),
|
||||||
|
.x = st::mediaviewDefaultLeft,
|
||||||
|
.y = st::mediaviewDefaultTop,
|
||||||
|
.w = st::mediaviewDefaultWidth,
|
||||||
|
.h = st::mediaviewDefaultHeight,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
PipDelegate::PipDelegate(QWidget *parent, not_null<Main::Session*> session)
|
PipDelegate::PipDelegate(QWidget *parent, not_null<Main::Session*> session)
|
||||||
: _parent(parent)
|
: _parent(parent)
|
||||||
, _session(session) {
|
, _session(session) {
|
||||||
|
@ -299,8 +318,7 @@ OverlayWidget::PipWrap::PipWrap(
|
||||||
}
|
}
|
||||||
|
|
||||||
OverlayWidget::OverlayWidget()
|
OverlayWidget::OverlayWidget()
|
||||||
: _supportWindowMode(true)
|
: _wrap(std::make_unique<Ui::GL::Window>())
|
||||||
, _wrap(std::make_unique<Ui::GL::Window>())
|
|
||||||
, _window(_wrap->window())
|
, _window(_wrap->window())
|
||||||
, _helper(Platform::CreateOverlayWidgetHelper(_window.get(), [=](bool maximized) {
|
, _helper(Platform::CreateOverlayWidgetHelper(_window.get(), [=](bool maximized) {
|
||||||
toggleFullScreen(maximized);
|
toggleFullScreen(maximized);
|
||||||
|
@ -309,7 +327,8 @@ OverlayWidget::OverlayWidget()
|
||||||
, _surface(
|
, _surface(
|
||||||
Ui::GL::CreateSurface(_body, chooseRenderer(_wrap->backend())))
|
Ui::GL::CreateSurface(_body, chooseRenderer(_wrap->backend())))
|
||||||
, _widget(_surface->rpWidget())
|
, _widget(_surface->rpWidget())
|
||||||
, _fullscreen(true || !_supportWindowMode)
|
, _fullscreen(Core::App().settings().mediaViewPosition().maximized == 2)
|
||||||
|
, _windowed(Core::App().settings().mediaViewPosition().maximized == 0)
|
||||||
, _docDownload(_body, tr::lng_media_download(tr::now), st::mediaviewFileLink)
|
, _docDownload(_body, tr::lng_media_download(tr::now), st::mediaviewFileLink)
|
||||||
, _docSaveAs(_body, tr::lng_mediaview_save_as(tr::now), st::mediaviewFileLink)
|
, _docSaveAs(_body, tr::lng_mediaview_save_as(tr::now), st::mediaviewFileLink)
|
||||||
, _docCancel(_body, tr::lng_cancel(tr::now), st::mediaviewFileLink)
|
, _docCancel(_body, tr::lng_cancel(tr::now), st::mediaviewFileLink)
|
||||||
|
@ -365,6 +384,15 @@ OverlayWidget::OverlayWidget()
|
||||||
.arg(position.x())
|
.arg(position.x())
|
||||||
.arg(position.y()));
|
.arg(position.y()));
|
||||||
moveToScreen(true);
|
moveToScreen(true);
|
||||||
|
if (_windowed) {
|
||||||
|
savePosition();
|
||||||
|
} else {
|
||||||
|
moveToScreen(true);
|
||||||
|
}
|
||||||
|
} else if (type == QEvent::Resize) {
|
||||||
|
if (_windowed) {
|
||||||
|
savePosition();
|
||||||
|
}
|
||||||
} else if (type == QEvent::Close
|
} else if (type == QEvent::Close
|
||||||
&& !Core::Sandbox::Instance().isSavingSession()
|
&& !Core::Sandbox::Instance().isSavingSession()
|
||||||
&& !Core::Quitting()) {
|
&& !Core::Quitting()) {
|
||||||
|
@ -505,31 +533,34 @@ void OverlayWidget::setupWindow() {
|
||||||
return Flag::Move | Flag(0);
|
return Flag::Move | Flag(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (_supportWindowMode) {
|
const auto callback = [=](Qt::WindowState state) {
|
||||||
const auto callback = [=](Qt::WindowState state) {
|
if (state == Qt::WindowMinimized || Platform::IsMac()) {
|
||||||
if (state == Qt::WindowMinimized || Platform::IsMac()) {
|
return;
|
||||||
return;
|
} else if (state == Qt::WindowMaximized) {
|
||||||
} else if (state == Qt::WindowFullScreen) {
|
if (_fullscreen || _windowed) {
|
||||||
_fullscreen = true;
|
|
||||||
_windowed = false;
|
|
||||||
} else if (state == Qt::WindowMaximized) {
|
|
||||||
_fullscreen = _windowed = false;
|
_fullscreen = _windowed = false;
|
||||||
} else {
|
savePosition();
|
||||||
_fullscreen = false;
|
|
||||||
_windowed = true;
|
|
||||||
}
|
}
|
||||||
};
|
} else if (_fullscreen || _windowed) {
|
||||||
QObject::connect(
|
return;
|
||||||
_window->windowHandle(),
|
} else if (state == Qt::WindowFullScreen) {
|
||||||
&QWindow::windowStateChanged,
|
_fullscreen = true;
|
||||||
callback);
|
savePosition();
|
||||||
}
|
} else {
|
||||||
|
_windowed = true;
|
||||||
|
savePosition();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
QObject::connect(
|
||||||
|
_window->windowHandle(),
|
||||||
|
&QWindow::windowStateChanged,
|
||||||
|
callback);
|
||||||
|
|
||||||
_window->setAttribute(Qt::WA_NoSystemBackground, true);
|
_window->setAttribute(Qt::WA_NoSystemBackground, true);
|
||||||
_window->setAttribute(Qt::WA_TranslucentBackground, true);
|
_window->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||||
|
|
||||||
_window->setMinimumSize(
|
_window->setMinimumSize(
|
||||||
{ st::windowMinHeight, st::windowMinWidth });
|
{ st::mediaviewMinWidth, st::mediaviewMinHeight });
|
||||||
|
|
||||||
_window->shownValue(
|
_window->shownValue(
|
||||||
) | rpl::start_with_next([=](bool shown) {
|
) | rpl::start_with_next([=](bool shown) {
|
||||||
|
@ -555,7 +586,7 @@ void OverlayWidget::refreshLang() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::moveToScreen(bool inMove) {
|
void OverlayWidget::moveToScreen(bool inMove) {
|
||||||
if (!_fullscreen) {
|
if (!_fullscreen || _wasWindowedMode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto widgetScreen = [&](auto &&widget) -> QScreen* {
|
const auto widgetScreen = [&](auto &&widget) -> QScreen* {
|
||||||
|
@ -587,10 +618,111 @@ void OverlayWidget::moveToScreen(bool inMove) {
|
||||||
updateGeometry(inMove);
|
updateGeometry(inMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::updateGeometry(bool inMove) {
|
void OverlayWidget::initFullScreen() {
|
||||||
if (Platform::IsWayland() || Platform::IsWindows() || !_fullscreen) {
|
if (_fullscreenInited) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
_fullscreenInited = true;
|
||||||
|
switch (Core::App().settings().mediaViewPosition().maximized) {
|
||||||
|
case 2:
|
||||||
|
_fullscreen = true;
|
||||||
|
_windowed = false;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_fullscreen = Platform::IsMac();
|
||||||
|
_windowed = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OverlayWidget::initNormalGeometry() {
|
||||||
|
if (_normalGeometryInited) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_normalGeometryInited = true;
|
||||||
|
const auto saved = Core::App().settings().mediaViewPosition();
|
||||||
|
const auto adjusted = Core::AdjustToScale(saved, u"Viewer"_q);
|
||||||
|
const auto initial = DefaultPosition();
|
||||||
|
_normalGeometry = initial.rect();
|
||||||
|
if (const auto active = Core::App().activeWindow()) {
|
||||||
|
_normalGeometry = active->widget()->countInitialGeometry(
|
||||||
|
adjusted,
|
||||||
|
initial,
|
||||||
|
{ st::mediaviewMinWidth, st::mediaviewMinHeight });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OverlayWidget::savePosition() {
|
||||||
|
if (isHidden() || isMinimized() || !_normalGeometryInited) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto &savedPosition = Core::App().settings().mediaViewPosition();
|
||||||
|
auto realPosition = savedPosition;
|
||||||
|
if (_fullscreen) {
|
||||||
|
realPosition.maximized = 2;
|
||||||
|
realPosition.moncrc = 0;
|
||||||
|
DEBUG_LOG(("Viewer Pos: Saving fullscreen position."));
|
||||||
|
} else if (!_windowed) {
|
||||||
|
realPosition.maximized = 1;
|
||||||
|
realPosition.moncrc = 0;
|
||||||
|
DEBUG_LOG(("Viewer Pos: Saving maximized position."));
|
||||||
|
} else {
|
||||||
|
auto r = _window->geometry();
|
||||||
|
realPosition.x = r.x();
|
||||||
|
realPosition.y = r.y();
|
||||||
|
realPosition.w = r.width();
|
||||||
|
realPosition.h = r.height();
|
||||||
|
realPosition.scale = cScale();
|
||||||
|
realPosition.maximized = 0;
|
||||||
|
realPosition.moncrc = 0;
|
||||||
|
DEBUG_LOG(("Viewer Pos: "
|
||||||
|
"Saving non-maximized position: %1, %2, %3, %4"
|
||||||
|
).arg(realPosition.x
|
||||||
|
).arg(realPosition.y
|
||||||
|
).arg(realPosition.w
|
||||||
|
).arg(realPosition.h));
|
||||||
|
}
|
||||||
|
realPosition = Window::PositionWithScreen(
|
||||||
|
realPosition,
|
||||||
|
_window,
|
||||||
|
{ st::mediaviewMinWidth, st::mediaviewMinHeight });
|
||||||
|
if (realPosition.w >= st::mediaviewMinWidth
|
||||||
|
&& realPosition.h >= st::mediaviewMinHeight
|
||||||
|
&& realPosition != savedPosition) {
|
||||||
|
DEBUG_LOG(("Viewer Pos: "
|
||||||
|
"Writing: %1, %2, %3, %4 (scale %5%, maximized %6)")
|
||||||
|
.arg(realPosition.x)
|
||||||
|
.arg(realPosition.y)
|
||||||
|
.arg(realPosition.w)
|
||||||
|
.arg(realPosition.h)
|
||||||
|
.arg(realPosition.scale)
|
||||||
|
.arg(Logs::b(realPosition.maximized)));
|
||||||
|
Core::App().settings().setMediaViewPosition(realPosition);
|
||||||
|
Core::App().saveSettingsDelayed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OverlayWidget::updateGeometry(bool inMove) {
|
||||||
|
initFullScreen();
|
||||||
|
if (_fullscreen) {
|
||||||
|
updateGeometryToScreen(inMove);
|
||||||
|
} else if (_windowed && _normalGeometryInited) {
|
||||||
|
_window->setGeometry(_normalGeometry);
|
||||||
|
}
|
||||||
|
if constexpr (!Platform::IsMac()) {
|
||||||
|
if (_fullscreen) {
|
||||||
|
if (!isHidden() && !isMinimized()) {
|
||||||
|
_window->showFullScreen();
|
||||||
|
}
|
||||||
|
} else if (!_windowed) {
|
||||||
|
if (!isHidden() && !isMinimized()) {
|
||||||
|
_window->showMaximized();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OverlayWidget::updateGeometryToScreen(bool inMove) {
|
||||||
const auto available = _window->screen()->geometry();
|
const auto available = _window->screen()->geometry();
|
||||||
const auto openglWidget = _opengl
|
const auto openglWidget = _opengl
|
||||||
? static_cast<QOpenGLWidget*>(_widget.get())
|
? static_cast<QOpenGLWidget*>(_widget.get())
|
||||||
|
@ -624,9 +756,7 @@ void OverlayWidget::updateGeometry(bool inMove) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::updateControlsGeometry() {
|
void OverlayWidget::updateControlsGeometry() {
|
||||||
const auto navSkip = _supportWindowMode
|
const auto navSkip = st::mediaviewHeaderTop;
|
||||||
? st::mediaviewHeaderTop
|
|
||||||
: st::mediaviewControlSize;
|
|
||||||
_closeNav = QRect(width() - st::mediaviewControlSize, 0, st::mediaviewControlSize, st::mediaviewControlSize);
|
_closeNav = QRect(width() - st::mediaviewControlSize, 0, st::mediaviewControlSize, st::mediaviewControlSize);
|
||||||
_closeNavIcon = style::centerrect(_closeNav, st::mediaviewClose);
|
_closeNavIcon = style::centerrect(_closeNav, st::mediaviewClose);
|
||||||
_leftNav = QRect(0, navSkip, st::mediaviewControlSize, height() - 2 * navSkip);
|
_leftNav = QRect(0, navSkip, st::mediaviewControlSize, height() - 2 * navSkip);
|
||||||
|
@ -1617,19 +1747,22 @@ void OverlayWidget::minimize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::toggleFullScreen(bool fullscreen) {
|
void OverlayWidget::toggleFullScreen(bool fullscreen) {
|
||||||
|
_fullscreen = fullscreen;
|
||||||
|
_windowed = !fullscreen;
|
||||||
|
initNormalGeometry();
|
||||||
if constexpr (Platform::IsMac()) {
|
if constexpr (Platform::IsMac()) {
|
||||||
_fullscreen = fullscreen;
|
|
||||||
_windowed = !fullscreen;
|
|
||||||
_helper->beforeShow(_fullscreen);
|
_helper->beforeShow(_fullscreen);
|
||||||
if (_fullscreen) {
|
updateGeometry();
|
||||||
moveToScreen();
|
|
||||||
}
|
|
||||||
_helper->afterShow(_fullscreen);
|
_helper->afterShow(_fullscreen);
|
||||||
} else if (fullscreen) {
|
} else if (_fullscreen) {
|
||||||
|
updateGeometry();
|
||||||
_window->showFullScreen();
|
_window->showFullScreen();
|
||||||
} else {
|
} else {
|
||||||
_window->showNormal();
|
_window->showNormal();
|
||||||
|
updateGeometry();
|
||||||
|
_wasWindowedMode = true;
|
||||||
}
|
}
|
||||||
|
savePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::activateControls() {
|
void OverlayWidget::activateControls() {
|
||||||
|
@ -1707,7 +1840,9 @@ void OverlayWidget::subscribeToScreenGeometry() {
|
||||||
base::qt_signal_producer(
|
base::qt_signal_producer(
|
||||||
screen,
|
screen,
|
||||||
&QScreen::geometryChanged
|
&QScreen::geometryChanged
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::filter([=] {
|
||||||
|
return !isHidden() && !isMinimized() && _fullscreen;
|
||||||
|
}) | rpl::start_with_next([=] {
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
}, _screenGeometryLifetime);
|
}, _screenGeometryLifetime);
|
||||||
}
|
}
|
||||||
|
@ -2573,7 +2708,7 @@ void OverlayWidget::update(const QRegion ®ion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OverlayWidget::isActive() const {
|
bool OverlayWidget::isActive() const {
|
||||||
return !isHidden() && !isMinimized() && Ui::InFocusChain(_window);
|
return !isHidden() && !isMinimized() && _window->isActiveWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OverlayWidget::isHidden() const {
|
bool OverlayWidget::isHidden() const {
|
||||||
|
@ -2910,8 +3045,11 @@ void OverlayWidget::displayFinished() {
|
||||||
|
|
||||||
void OverlayWidget::showAndActivate() {
|
void OverlayWidget::showAndActivate() {
|
||||||
_body->show();
|
_body->show();
|
||||||
|
initNormalGeometry();
|
||||||
|
updateGeometry();
|
||||||
if (_windowed || Platform::IsMac()) {
|
if (_windowed || Platform::IsMac()) {
|
||||||
_window->showNormal();
|
_window->showNormal();
|
||||||
|
_wasWindowedMode = true;
|
||||||
} else if (_fullscreen) {
|
} else if (_fullscreen) {
|
||||||
_window->showFullScreen();
|
_window->showFullScreen();
|
||||||
} else {
|
} else {
|
||||||
|
@ -3995,7 +4133,7 @@ void OverlayWidget::paintControls(
|
||||||
st::mediaviewRight },
|
st::mediaviewRight },
|
||||||
{
|
{
|
||||||
OverClose,
|
OverClose,
|
||||||
!_supportWindowMode,
|
false,
|
||||||
_closeNav,
|
_closeNav,
|
||||||
_closeNavIcon,
|
_closeNavIcon,
|
||||||
st::mediaviewClose },
|
st::mediaviewClose },
|
||||||
|
@ -4702,8 +4840,10 @@ void OverlayWidget::updateOver(QPoint pos) {
|
||||||
updateOverState(OverIcon);
|
updateOverState(OverIcon);
|
||||||
} else if (_moreNav.contains(pos)) {
|
} else if (_moreNav.contains(pos)) {
|
||||||
updateOverState(OverMore);
|
updateOverState(OverMore);
|
||||||
} else if (!_supportWindowMode && _closeNav.contains(pos)) {
|
#if 0 // close
|
||||||
|
} else if (_closeNav.contains(pos)) {
|
||||||
updateOverState(OverClose);
|
updateOverState(OverClose);
|
||||||
|
#endif
|
||||||
} else if (documentContentShown() && finalContentRect().contains(pos)) {
|
} else if (documentContentShown() && finalContentRect().contains(pos)) {
|
||||||
if ((_document->isVideoFile() || _document->isVideoMessage()) && _streamed) {
|
if ((_document->isVideoFile() || _document->isVideoMessage()) && _streamed) {
|
||||||
updateOverState(OverVideo);
|
updateOverState(OverVideo);
|
||||||
|
|
|
@ -241,8 +241,12 @@ private:
|
||||||
void assignMediaPointer(not_null<PhotoData*> photo);
|
void assignMediaPointer(not_null<PhotoData*> photo);
|
||||||
|
|
||||||
void updateOver(QPoint mpos);
|
void updateOver(QPoint mpos);
|
||||||
|
void initFullScreen();
|
||||||
|
void initNormalGeometry();
|
||||||
|
void savePosition();
|
||||||
void moveToScreen(bool inMove = false);
|
void moveToScreen(bool inMove = false);
|
||||||
void updateGeometry(bool inMove = false);
|
void updateGeometry(bool inMove = false);
|
||||||
|
void updateGeometryToScreen(bool inMove = false);
|
||||||
bool moveToNext(int delta);
|
bool moveToNext(int delta);
|
||||||
void preloadData(int delta);
|
void preloadData(int delta);
|
||||||
|
|
||||||
|
@ -454,7 +458,6 @@ private:
|
||||||
|
|
||||||
Window::SessionController *findWindow(bool switchTo = true) const;
|
Window::SessionController *findWindow(bool switchTo = true) const;
|
||||||
|
|
||||||
const bool _supportWindowMode = false;
|
|
||||||
bool _opengl = false;
|
bool _opengl = false;
|
||||||
const std::unique_ptr<Ui::GL::Window> _wrap;
|
const std::unique_ptr<Ui::GL::Window> _wrap;
|
||||||
const not_null<Ui::RpWindow*> _window;
|
const not_null<Ui::RpWindow*> _window;
|
||||||
|
@ -462,6 +465,10 @@ private:
|
||||||
const not_null<Ui::RpWidget*> _body;
|
const not_null<Ui::RpWidget*> _body;
|
||||||
const std::unique_ptr<Ui::RpWidgetWrap> _surface;
|
const std::unique_ptr<Ui::RpWidgetWrap> _surface;
|
||||||
const not_null<QWidget*> _widget;
|
const not_null<QWidget*> _widget;
|
||||||
|
QRect _normalGeometry;
|
||||||
|
bool _wasWindowedMode = false;
|
||||||
|
bool _fullscreenInited = false;
|
||||||
|
bool _normalGeometryInited = false;
|
||||||
bool _fullscreen = true;
|
bool _fullscreen = true;
|
||||||
bool _windowed = false;
|
bool _windowed = false;
|
||||||
|
|
||||||
|
|
|
@ -65,4 +65,8 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] int32 ScreenNameChecksum(const QString &name) {
|
||||||
|
return Window::DefaultScreenNameChecksum(name);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
@ -85,4 +85,8 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] int32 ScreenNameChecksum(const QString &name) {
|
||||||
|
return Window::DefaultScreenNameChecksum(name);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
@ -412,17 +412,6 @@ void MainWindow::validateDwmPreviewColors() {
|
||||||
_dwmPreview.reset();
|
_dwmPreview.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 MainWindow::screenNameChecksum(const QString &name) const {
|
|
||||||
constexpr int DeviceNameSize = base::array_size(MONITORINFOEX().szDevice);
|
|
||||||
wchar_t buffer[DeviceNameSize] = { 0 };
|
|
||||||
if (name.size() < DeviceNameSize) {
|
|
||||||
name.toWCharArray(buffer);
|
|
||||||
} else {
|
|
||||||
memcpy(buffer, name.toStdWString().data(), sizeof(buffer));
|
|
||||||
}
|
|
||||||
return base::crc32(buffer, sizeof(buffer));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::forceIconRefresh() {
|
void MainWindow::forceIconRefresh() {
|
||||||
const auto refresher = std::make_unique<QWidget>(this);
|
const auto refresher = std::make_unique<QWidget>(this);
|
||||||
refresher->setWindowFlags(
|
refresher->setWindowFlags(
|
||||||
|
@ -483,10 +472,7 @@ bool MainWindow::hasTabletView() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::initGeometryFromSystem() {
|
bool MainWindow::initGeometryFromSystem() {
|
||||||
if (!hasTabletView()) {
|
if (!hasTabletView() || !screen()) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!screen()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Ui::RpWidget::setGeometry(screen()->availableGeometry());
|
Ui::RpWidget::setGeometry(screen()->availableGeometry());
|
||||||
|
@ -708,4 +694,15 @@ MainWindow::~MainWindow() {
|
||||||
destroyCachedIcons();
|
destroyCachedIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 ScreenNameChecksum(const QString &name) {
|
||||||
|
constexpr int DeviceNameSize = base::array_size(MONITORINFOEX().szDevice);
|
||||||
|
wchar_t buffer[DeviceNameSize] = { 0 };
|
||||||
|
if (name.size() < DeviceNameSize) {
|
||||||
|
name.toWCharArray(buffer);
|
||||||
|
} else {
|
||||||
|
memcpy(buffer, name.toStdWString().data(), sizeof(buffer));
|
||||||
|
}
|
||||||
|
return base::crc32(buffer, sizeof(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
@ -41,7 +41,6 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initHook() override;
|
void initHook() override;
|
||||||
int32 screenNameChecksum(const QString &name) const override;
|
|
||||||
void unreadCounterChangedHook() override;
|
void unreadCounterChangedHook() override;
|
||||||
|
|
||||||
void workmodeUpdated(Core::Settings::WorkMode mode) override;
|
void workmodeUpdated(Core::Settings::WorkMode mode) override;
|
||||||
|
@ -100,4 +99,6 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] int32 ScreenNameChecksum(const QString &name);
|
||||||
|
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
@ -56,32 +56,6 @@ constexpr auto kSaveWindowPositionTimeout = crl::time(1000);
|
||||||
|
|
||||||
using Core::WindowPosition;
|
using Core::WindowPosition;
|
||||||
|
|
||||||
[[nodiscard]] WindowPosition AdjustToScale(WindowPosition position) {
|
|
||||||
DEBUG_LOG(("Window Pos: Initializing first %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)));
|
|
||||||
|
|
||||||
if (!position.scale) {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
const auto scaleFactor = cScale() / float64(position.scale);
|
|
||||||
if (scaleFactor != 1.) {
|
|
||||||
// Change scale while keeping the position center in place.
|
|
||||||
position.x += position.w / 2;
|
|
||||||
position.y += position.h / 2;
|
|
||||||
position.w *= scaleFactor;
|
|
||||||
position.h *= scaleFactor;
|
|
||||||
position.x -= position.w / 2;
|
|
||||||
position.y -= position.h / 2;
|
|
||||||
}
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] QPoint ChildSkip() {
|
[[nodiscard]] QPoint ChildSkip() {
|
||||||
const auto skipx = st::defaultDialogRow.padding.left()
|
const auto skipx = st::defaultDialogRow.padding.left()
|
||||||
+ st::defaultDialogRow.photoSize
|
+ st::defaultDialogRow.photoSize
|
||||||
|
@ -629,7 +603,9 @@ void MainWindow::recountGeometryConstraints() {
|
||||||
WindowPosition MainWindow::initialPosition() const {
|
WindowPosition MainWindow::initialPosition() const {
|
||||||
const auto active = Core::App().activeWindow();
|
const auto active = Core::App().activeWindow();
|
||||||
return (!active || active == &controller())
|
return (!active || active == &controller())
|
||||||
? AdjustToScale(Core::App().settings().windowPosition())
|
? Core::AdjustToScale(
|
||||||
|
Core::App().settings().windowPosition(),
|
||||||
|
u"Window"_q)
|
||||||
: active->widget()->nextInitialChildPosition(isPrimary());
|
: active->widget()->nextInitialChildPosition(isPrimary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,28 +649,38 @@ QRect MainWindow::countInitialGeometry(WindowPosition position) {
|
||||||
const auto initialHeight = Core::Settings::ThirdColumnByDefault()
|
const auto initialHeight = Core::Settings::ThirdColumnByDefault()
|
||||||
? st::windowBigDefaultHeight
|
? st::windowBigDefaultHeight
|
||||||
: st::windowDefaultHeight;
|
: st::windowDefaultHeight;
|
||||||
const auto initial = QRect(
|
const auto initial = WindowPosition{
|
||||||
primaryAvailable.x() + std::max(
|
.x = (primaryAvailable.x()
|
||||||
(primaryAvailable.width() - initialWidth) / 2,
|
+ std::max((primaryAvailable.width() - initialWidth) / 2, 0)),
|
||||||
0),
|
.y = (primaryAvailable.y()
|
||||||
primaryAvailable.y() + std::max(
|
+ std::max((primaryAvailable.height() - initialHeight) / 2, 0)),
|
||||||
(primaryAvailable.height() - initialHeight) / 2,
|
.w = initialWidth,
|
||||||
0),
|
.h = initialHeight,
|
||||||
initialWidth,
|
};
|
||||||
initialHeight);
|
return countInitialGeometry(
|
||||||
|
position,
|
||||||
|
initial,
|
||||||
|
{ st::windowMinWidth, st::windowMinHeight });
|
||||||
|
}
|
||||||
|
|
||||||
|
QRect MainWindow::countInitialGeometry(
|
||||||
|
WindowPosition position,
|
||||||
|
WindowPosition initial,
|
||||||
|
QSize minSize) const {
|
||||||
if (!position.w || !position.h) {
|
if (!position.w || !position.h) {
|
||||||
return initial;
|
return initial.rect();
|
||||||
}
|
}
|
||||||
const auto screen = [&]() -> QScreen* {
|
const auto screen = [&]() -> QScreen* {
|
||||||
for (const auto screen : QGuiApplication::screens()) {
|
for (const auto screen : QGuiApplication::screens()) {
|
||||||
if (position.moncrc == screenNameChecksum(screen->name())) {
|
const auto sum = Platform::ScreenNameChecksum(screen->name());
|
||||||
|
if (position.moncrc == sum) {
|
||||||
return screen;
|
return screen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}();
|
}();
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
return initial;
|
return initial.rect();
|
||||||
}
|
}
|
||||||
const auto frame = frameMargins();
|
const auto frame = frameMargins();
|
||||||
const auto screenGeometry = screen->geometry();
|
const auto screenGeometry = screen->geometry();
|
||||||
|
@ -728,7 +714,7 @@ QRect MainWindow::countInitialGeometry(WindowPosition position) {
|
||||||
const auto w = spaceForInner.width();
|
const auto w = spaceForInner.width();
|
||||||
const auto h = spaceForInner.height();
|
const auto h = spaceForInner.height();
|
||||||
if (w < st::windowMinWidth || h < st::windowMinHeight) {
|
if (w < st::windowMinWidth || h < st::windowMinHeight) {
|
||||||
return initial;
|
return initial.rect();
|
||||||
}
|
}
|
||||||
if (position.x < x) position.x = x;
|
if (position.x < x) position.x = x;
|
||||||
if (position.y < y) position.y = y;
|
if (position.y < y) position.y = y;
|
||||||
|
@ -768,14 +754,14 @@ QRect MainWindow::countInitialGeometry(WindowPosition position) {
|
||||||
> screenGeometry.x() + screenGeometry.width())
|
> screenGeometry.x() + screenGeometry.width())
|
||||||
|| (position.y + st::windowMinHeight
|
|| (position.y + st::windowMinHeight
|
||||||
> screenGeometry.y() + screenGeometry.height())) {
|
> screenGeometry.y() + screenGeometry.height())) {
|
||||||
return initial;
|
return initial.rect();
|
||||||
}
|
}
|
||||||
DEBUG_LOG(("Window Pos: Resulting geometry is %1, %2, %3, %4"
|
DEBUG_LOG(("Window Pos: Resulting geometry is %1, %2, %3, %4"
|
||||||
).arg(position.x
|
).arg(position.x
|
||||||
).arg(position.y
|
).arg(position.y
|
||||||
).arg(position.w
|
).arg(position.w
|
||||||
).arg(position.h));
|
).arg(position.h));
|
||||||
return QRect(position.x, position.y, position.w, position.h);
|
return position.rect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::initGeometry() {
|
void MainWindow::initGeometry() {
|
||||||
|
@ -796,11 +782,6 @@ void MainWindow::positionUpdated() {
|
||||||
_positionUpdatedTimer.callOnce(kSaveWindowPositionTimeout);
|
_positionUpdatedTimer.callOnce(kSaveWindowPositionTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 MainWindow::screenNameChecksum(const QString &name) const {
|
|
||||||
const auto bytes = name.toUtf8();
|
|
||||||
return base::crc32(bytes.constData(), bytes.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::setPositionInited() {
|
void MainWindow::setPositionInited() {
|
||||||
_positionInited = true;
|
_positionInited = true;
|
||||||
}
|
}
|
||||||
|
@ -936,34 +917,10 @@ void MainWindow::savePosition(Qt::WindowState state) {
|
||||||
|
|
||||||
WindowPosition MainWindow::withScreenInPosition(
|
WindowPosition MainWindow::withScreenInPosition(
|
||||||
WindowPosition position) const {
|
WindowPosition position) const {
|
||||||
const auto my = screen();
|
return PositionWithScreen(
|
||||||
const auto chosen = my ? my : QGuiApplication::primaryScreen();
|
position,
|
||||||
if (!chosen) {
|
this,
|
||||||
return position;
|
{ st::windowMinWidth, st::windowMinHeight });
|
||||||
}
|
|
||||||
const auto available = chosen->availableGeometry();
|
|
||||||
if (available.width() < st::windowMinWidth
|
|
||||||
|| available.height() < st::windowMinHeight) {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
accumulate_min(position.w, available.width());
|
|
||||||
accumulate_min(position.h, available.height());
|
|
||||||
if (position.x + position.w > available.x() + available.width()) {
|
|
||||||
position.x = available.x() + available.width() - position.w;
|
|
||||||
}
|
|
||||||
if (position.y + position.h > available.y() + available.height()) {
|
|
||||||
position.y = available.y() + available.height() - position.h;
|
|
||||||
}
|
|
||||||
const auto geometry = chosen->geometry();
|
|
||||||
DEBUG_LOG(("Window Pos: Screen found, geometry: %1, %2, %3, %4"
|
|
||||||
).arg(geometry.x()
|
|
||||||
).arg(geometry.y()
|
|
||||||
).arg(geometry.width()
|
|
||||||
).arg(geometry.height()));
|
|
||||||
position.x -= geometry.x();
|
|
||||||
position.y -= geometry.y();
|
|
||||||
position.moncrc = screenNameChecksum(chosen->name());
|
|
||||||
return position;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::minimizeToTray() {
|
bool MainWindow::minimizeToTray() {
|
||||||
|
@ -1086,4 +1043,52 @@ MainWindow::~MainWindow() {
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 DefaultScreenNameChecksum(const QString &name) {
|
||||||
|
const auto bytes = name.toUtf8();
|
||||||
|
return base::crc32(bytes.constData(), bytes.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowPosition PositionWithScreen(
|
||||||
|
WindowPosition position,
|
||||||
|
const QScreen *chosen,
|
||||||
|
QSize minimal) {
|
||||||
|
if (!chosen) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
const auto available = chosen->availableGeometry();
|
||||||
|
if (available.width() < minimal.width()
|
||||||
|
|| available.height() < minimal.height()) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
accumulate_min(position.w, available.width());
|
||||||
|
accumulate_min(position.h, available.height());
|
||||||
|
if (position.x + position.w > available.x() + available.width()) {
|
||||||
|
position.x = available.x() + available.width() - position.w;
|
||||||
|
}
|
||||||
|
if (position.y + position.h > available.y() + available.height()) {
|
||||||
|
position.y = available.y() + available.height() - position.h;
|
||||||
|
}
|
||||||
|
const auto geometry = chosen->geometry();
|
||||||
|
DEBUG_LOG(("Window Pos: Screen found, geometry: %1, %2, %3, %4"
|
||||||
|
).arg(geometry.x()
|
||||||
|
).arg(geometry.y()
|
||||||
|
).arg(geometry.width()
|
||||||
|
).arg(geometry.height()));
|
||||||
|
position.x -= geometry.x();
|
||||||
|
position.y -= geometry.y();
|
||||||
|
position.moncrc = Platform::ScreenNameChecksum(chosen->name());
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowPosition PositionWithScreen(
|
||||||
|
WindowPosition position,
|
||||||
|
not_null<const QWidget*> widget,
|
||||||
|
QSize minimal) {
|
||||||
|
const auto screen = widget->screen();
|
||||||
|
return PositionWithScreen(
|
||||||
|
position,
|
||||||
|
screen ? screen : QGuiApplication::primaryScreen(),
|
||||||
|
minimal);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
|
|
@ -134,6 +134,11 @@ public:
|
||||||
updateGlobalMenuHook();
|
updateGlobalMenuHook();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QRect countInitialGeometry(
|
||||||
|
Core::WindowPosition position,
|
||||||
|
Core::WindowPosition initial,
|
||||||
|
QSize minSize) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void leaveEventHook(QEvent *e) override;
|
void leaveEventHook(QEvent *e) override;
|
||||||
|
|
||||||
|
@ -174,9 +179,6 @@ protected:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This one is overriden in Windows for historical reasons.
|
|
||||||
virtual int32 screenNameChecksum(const QString &name) const;
|
|
||||||
|
|
||||||
void setPositionInited();
|
void setPositionInited();
|
||||||
|
|
||||||
virtual QRect computeDesktopRect() const;
|
virtual QRect computeDesktopRect() const;
|
||||||
|
@ -218,4 +220,15 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] int32 DefaultScreenNameChecksum(const QString &name);
|
||||||
|
|
||||||
|
[[nodiscard]] Core::WindowPosition PositionWithScreen(
|
||||||
|
Core::WindowPosition position,
|
||||||
|
const QScreen *chosen,
|
||||||
|
QSize minimal);
|
||||||
|
[[nodiscard]] Core::WindowPosition PositionWithScreen(
|
||||||
|
Core::WindowPosition position,
|
||||||
|
not_null<const QWidget*> widget,
|
||||||
|
QSize minimal);
|
||||||
|
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 3b69ec499ccc7f4208a6413fbeb6f5ebe84f3f55
|
Subproject commit 74ab66cfa9c05745ca513504940e59f6fd68eff3
|
Loading…
Add table
Reference in a new issue